Update page resources Font dictionary when applying license information (#5)

* Make PdfObjectDictionary Merge method chainable
* Update page resources Font dictionary when applying license information
* Add license font to the page resources only when it does not exist
* Update hash for split test after verification
This commit is contained in:
Adrian-George Bostan 2019-05-30 13:52:05 +03:00 committed by Gunnsteinn Hall
parent bc0edcb8dd
commit 8425bf7c8f
3 changed files with 13 additions and 8 deletions

View File

@ -605,13 +605,16 @@ func (array *PdfObjectArray) GetAsFloat64Slice() ([]float64, error) {
}
// Merge merges in key/values from another dictionary. Overwriting if has same keys.
func (d *PdfObjectDictionary) Merge(another *PdfObjectDictionary) {
// The mutated dictionary (d) is returned in order to allow method chaining.
func (d *PdfObjectDictionary) Merge(another *PdfObjectDictionary) *PdfObjectDictionary {
if another != nil {
for _, key := range another.Keys() {
val := another.Get(key)
d.Set(key, val)
}
}
return d
}
// String returns a string describing `d`.

View File

@ -30,8 +30,8 @@ var (
// knownHashes defines a list of known output hashes to ensure that the output is constant.
// If there is a change in hash need to find out why and update only if the change is accepted.
var knownHashes = map[string]string{
"bf7c9d5dabc7e7ec2fc0cf9db2d9c8e7aa456fca.pdf": "f7891d491fa9f20ed2975dd28961c205",
"371dce2c2720581a3eef3f123e5741dd3566ef87.pdf": "4a25934226b6b64e5d95d571260b1f01",
"bf7c9d5dabc7e7ec2fc0cf9db2d9c8e7aa456fca.pdf": "fdd638603c6f655babbc90358de66107",
"371dce2c2720581a3eef3f123e5741dd3566ef87.pdf": "4c5356ac623a96004d80315f24613fff",
"e815311526b50036db6e89c54af2b9626edecf30.pdf": "97dcfdde59a2f3a6eb105d0c31ebd3fb",
"3bf64014e0c9e4a56f1a9363f1b34fd707bd9fa0.pdf": "6f310c9fdd44d49766d3cc32d3053b89",
"004feecd47e2da4f2ed5cdbbf4791a77dd59ce20.pdf": "309a072a97d0566aa3f85edae504bb53",

View File

@ -532,11 +532,11 @@ func (w *PdfWriter) addObjects(obj core.PdfObject) error {
// AddPage adds a page to the PDF file. The new page should be an indirect object.
func (w *PdfWriter) AddPage(page *PdfPage) error {
procPage(page)
obj := page.ToPdfObject()
common.Log.Trace("==========")
common.Log.Trace("Appending to page list %T", obj)
procPage(page)
pageObj, ok := obj.(*core.PdfIndirectObject)
if !ok {
@ -627,14 +627,16 @@ func procPage(p *PdfPage) {
return
}
// Add font as needed.
f := DefaultFont()
p.Resources.SetFontByName("UF1", f.ToPdfObject())
// Add font, if needed.
fontName := core.PdfObjectName("UF1")
if !p.Resources.HasFontByName(fontName) {
p.Resources.SetFontByName(fontName, DefaultFont().ToPdfObject())
}
var ops []string
ops = append(ops, "q")
ops = append(ops, "BT")
ops = append(ops, "/UF1 14 Tf")
ops = append(ops, fmt.Sprintf("/%s 14 Tf", fontName.String()))
ops = append(ops, "1 0 0 rg")
ops = append(ops, "10 10 Td")
s := "Unlicensed UniDoc - Get a license on https://unidoc.io"