add inheritable keys back into the copied pages node

keys suchs as resources, mediabox, cropbox, etc can be inherited. we now copy them if they are present on the parent pages node.
This commit is contained in:
Eliot Jones
2020-03-02 16:07:36 +00:00
parent c596bef024
commit 2effedd3c5

View File

@@ -234,13 +234,25 @@
pageReferences.Add(new IndirectReferenceToken(newEntry.Number));
}
var pagesDictionary = new DictionaryToken(new Dictionary<NameToken, IToken>
var newPagesNode = new Dictionary<NameToken, IToken>
{
{ NameToken.Type, NameToken.Pages },
{ NameToken.Kids, new ArrayToken(pageReferences) },
{ NameToken.Count, new NumericToken(pageReferences.Count) },
{ NameToken.Parent, treeParentReference }
});
};
foreach (var pair in treeNode.NodeDictionary.Data)
{
if (IgnoreKeyForPagesNode(pair))
{
continue;
}
newPagesNode[NameToken.Create(pair.Key)] = CopyToken(pair.Value, tokenScanner);
}
var pagesDictionary = new DictionaryToken(newPagesNode);
return context.WriteObject(memory, pagesDictionary, currentNodeReserved);
}
@@ -342,6 +354,14 @@
stream.Write(bytes, 0, bytes.Length);
stream.WriteNewLine();
}
private static bool IgnoreKeyForPagesNode(KeyValuePair<string, IToken> token)
{
return string.Equals(token.Key, NameToken.Type.Data, StringComparison.OrdinalIgnoreCase)
|| string.Equals(token.Key, NameToken.Kids.Data, StringComparison.OrdinalIgnoreCase)
|| string.Equals(token.Key, NameToken.Count.Data, StringComparison.OrdinalIgnoreCase)
|| string.Equals(token.Key, NameToken.Parent.Data, StringComparison.OrdinalIgnoreCase);
}
}
}
}