Draft: Fix Form issue reported in #1549
1st commit - Fix Form fields with unexistant fonts with '/' in font name
This is really the same commit from !1698 because Gitlab Community version lacks feature of marking a MR dependent on another MR, so as this MR touches the same code of the other MR, I'm including its commit here but marking this MR as Draft to prevent merging, when !1698 is merged I will remove said commit from this MR and remove the Draft status.
2nd commit - Mark updated indirect objects inside Resources as such
In AnnotWidget::generateFieldAppearance()
we create an
Appearance stream with a Resources dict that is the
result of merging with the Form default Resources dict.
But in that merged Resources dict, if an indirect object (eg. a font) was updated with a new property obtained from the Form default Resources dict, we were not marking that indirect object as "updated", which would cause that if the user "saved the pdf" that updated object won't be copied over i.e. the old version would be used.
In the issue #1549 that caused the problematic pdf to
not save the indirect object (319 0)
which was the /Helv
font
with a merged /Encoding
dict from Form Default resources.
Fixes #1549
3rd commit - Avoid adding superflous popplerfont
PDF file of issue #1549 made Form::ensureFontsForAllCharacters()
to add a new popplerfont just to handle a character like eg. ñ
, that is
not necessary and was caused by the fact that 'Resources' passed
to it had an incomplete /Font
dictionary which lacked the /Encoding
dict thus provoking ñ
to not be decoded and so thinking it needed
a custom popplerfont for that.
ñ
shows fine after typing it because the Appearance stream
created by AnnotWidget::generateFieldAppearance()
merges the /Font
dictionary from Form default resources to the one in Field's
resources. So because the /Encoding
dict is in the Form
default resources and gets merged to the Field's one and then this
combined /Font
is the one used in the AP Resources that's why
it displays fine the ñ
character.
On the contrary, inside FormFieldText::setContentCopy()
we
call Form::ensureFontsForAllCharacters()
and currently pass it
the different existant Resources (Field, Form and AP) and the
looked up font is found in the Field's one, but that one lacks
the /Encoding
dict.
So the solution is to do same as generateFieldAppearance()
and merge Field and Form Resources dict prior to pass it to
ensureFontsForAllCharacters()
so that when looking up the font
it finds it with the /Encoding
dict in it.
As part of that solution we moved the recursiveMergeDicts()
function from Annot.cc to a static method in Dict class so
we can call it from FormFieldText::setContentCopy()
in Form.cc
Improves #1549 by not adding unneeded popplerfont