poppler/Annot.cc | 50 +++++++++++++++++++++++++------------------------- poppler/Annot.h | 3 +-- 2 files changed, 26 insertions(+), 27 deletions(-)
New commits: commit 95fe93b32e740c48c9c8eac3ec59a72dcf3f6f41 Author: Martin <martin...@gmx.net> Date: Mon Jan 10 23:09:08 2022 +0000 AnnotAppearanceBuilder: Also use the image when there is left signature text diff --git a/poppler/Annot.cc b/poppler/Annot.cc index c62cdd49..506a5fe8 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -4925,6 +4925,16 @@ bool AnnotAppearanceBuilder::drawFormFieldText(const FormFieldText *fieldText, c return true; } +static void setChildDictEntryValue(Dict *parentDict, const char *childDictName, const char *childDictEntryName, const Ref childDictEntryValue, XRef *xref) +{ + Object childDictionaryObj = parentDict->lookup(childDictName); + if (!childDictionaryObj.isDict()) { + childDictionaryObj = Object(new Dict(xref)); + parentDict->set(childDictName, childDictionaryObj.copy()); + } + childDictionaryObj.dictSet(childDictEntryName, Object(childDictEntryValue)); +} + bool AnnotAppearanceBuilder::drawSignatureFieldText(const FormFieldSignature *field, const Form *form, const GfxResources *resources, const GooString *_da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, XRef *xref, Dict *resourcesDict) { @@ -4932,9 +4942,22 @@ bool AnnotAppearanceBuilder::drawSignatureFieldText(const FormFieldSignature *fi if (contents.toStr().empty()) return false; + if (field->getImageResource() != Ref::INVALID()) { + const double width = rect->x2 - rect->x1; + const double height = rect->y2 - rect->y1; + static const char *imageResourceId = "SigImg"; + setChildDictEntryValue(resourcesDict, "XObject", imageResourceId, field->getImageResource(), xref); + Matrix matrix = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }; + matrix.scale(width, height); + static const char *IMG_TMPL = "\nq {0:.1g} {1:.1g} {2:.1g} {3:.1g} {4:.1g} {5:.1g} cm /{6:s} Do Q\n"; + const GooString *imgBuffer = GooString::format(IMG_TMPL, matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3], matrix.m[4], matrix.m[5], imageResourceId); + append(imgBuffer->c_str()); + delete imgBuffer; + } + const GooString &leftText = field->getCustomAppearanceLeftContent(); if (leftText.toStr().empty()) { - drawSignatureFieldText(contents, DefaultAppearance(_da), border, rect, xref, resourcesDict, 0, false /* don't center vertically */, false /* don't center horizontally */, field->getImageResource()); + drawSignatureFieldText(contents, DefaultAppearance(_da), border, rect, xref, resourcesDict, 0, false /* don't center vertically */, false /* don't center horizontally */); } else { DefaultAppearance daLeft(_da); daLeft.setFontPtSize(field->getCustomAppearanceLeftFontSize()); @@ -4949,18 +4972,8 @@ bool AnnotAppearanceBuilder::drawSignatureFieldText(const FormFieldSignature *fi return true; } -static void setChildDictEntryValue(Dict *parentDict, const char *childDictName, const char *childDictEntryName, const Ref childDictEntryValue, XRef *xref) -{ - Object childDictionaryObj = parentDict->lookup(childDictName); - if (!childDictionaryObj.isDict()) { - childDictionaryObj = Object(new Dict(xref)); - parentDict->set(childDictName, childDictionaryObj.copy()); - } - childDictionaryObj.dictSet(childDictEntryName, Object(childDictEntryValue)); -} - void AnnotAppearanceBuilder::drawSignatureFieldText(const GooString &text, const DefaultAppearance &da, const AnnotBorder *border, const PDFRectangle *rect, XRef *xref, Dict *resourcesDict, double leftMargin, bool centerVertically, - bool centerHorizontally, const Ref imageResourceRef) + bool centerHorizontally) { double borderWidth = 0; append("q\n"); @@ -4977,19 +4990,6 @@ void AnnotAppearanceBuilder::drawSignatureFieldText(const GooString &text, const const double textmargin = borderWidth * 2; const double textwidth = width - 2 * textmargin; - // Print a background image. - if (imageResourceRef != Ref::INVALID()) { - static const char *imageResourceId = "SigImg"; - setChildDictEntryValue(resourcesDict, "XObject", imageResourceId, imageResourceRef, xref); - - Matrix matrix = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }; - matrix.scale(width, height); - static const char *IMG_TMPL = "\nq {0:.1g} {1:.1g} {2:.1g} {3:.1g} {4:.1g} {5:.1g} cm /{6:s} Do Q\n"; - const GooString *imgBuffer = GooString::format(IMG_TMPL, matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3], matrix.m[4], matrix.m[5], imageResourceId); - append(imgBuffer->c_str()); - delete imgBuffer; - } - // create a Helvetica fake font GfxFont *font = createAnnotDrawFont(xref, resourcesDict, da.getFontName().getName()); diff --git a/poppler/Annot.h b/poppler/Annot.h index 13ccc58b..d25f24fd 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -598,8 +598,7 @@ private: XRef *xref, Dict *resourcesDict); bool drawSignatureFieldText(const FormFieldSignature *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, XRef *xref, Dict *resourcesDict); - void drawSignatureFieldText(const GooString &text, const DefaultAppearance &da, const AnnotBorder *border, const PDFRectangle *rect, XRef *xref, Dict *resourcesDict, double leftMargin, bool centerVertically, bool centerHorizontally, - const Ref imageResourceRef = Ref::INVALID()); + void drawSignatureFieldText(const GooString &text, const DefaultAppearance &da, const AnnotBorder *border, const PDFRectangle *rect, XRef *xref, Dict *resourcesDict, double leftMargin, bool centerVertically, bool centerHorizontally); bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, bool multiline, int comb, int quadding, bool txField, bool forceZapfDingbats, XRef *xref, bool password, Dict *resourcesDict, const char *defaultFallback = "Helvetica"); void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);