mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 10:55:04 +08:00
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:
@@ -234,13 +234,25 @@
|
|||||||
pageReferences.Add(new IndirectReferenceToken(newEntry.Number));
|
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.Type, NameToken.Pages },
|
||||||
{ NameToken.Kids, new ArrayToken(pageReferences) },
|
{ NameToken.Kids, new ArrayToken(pageReferences) },
|
||||||
{ NameToken.Count, new NumericToken(pageReferences.Count) },
|
{ NameToken.Count, new NumericToken(pageReferences.Count) },
|
||||||
{ NameToken.Parent, treeParentReference }
|
{ 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);
|
return context.WriteObject(memory, pagesDictionary, currentNodeReserved);
|
||||||
}
|
}
|
||||||
@@ -342,6 +354,14 @@
|
|||||||
stream.Write(bytes, 0, bytes.Length);
|
stream.Write(bytes, 0, bytes.Length);
|
||||||
stream.WriteNewLine();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user