[poppler] 4 commits - glib/poppler-annot.cc poppler/Annot.cc poppler/Annot.h poppler/Form.cc poppler/Form.h qt5/src qt6/src
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Mar 24 15:54:48 UTC 2022
glib/poppler-annot.cc | 6 +-
poppler/Annot.cc | 113 +++++++++++++++++++++---------------------
poppler/Annot.h | 36 ++++++++-----
poppler/Form.cc | 12 ++--
poppler/Form.h | 7 --
qt5/src/poppler-annotation.cc | 4 -
qt5/src/poppler-form.cc | 6 +-
qt6/src/poppler-annotation.cc | 16 ++---
qt6/src/poppler-form.cc | 6 +-
9 files changed, 106 insertions(+), 100 deletions(-)
New commits:
commit 0f2d213debaed1d0671dd0086588848463e80046
Author: Albert Astals Cid <aacid at kde.org>
Date: Thu Mar 24 16:23:21 2022 +0100
Annot::drawText: Move combMaxLen to the end since it's only used once
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 06750018..9fd6c871 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4299,8 +4299,8 @@ void AnnotAppearanceBuilder::writeString(const std::string &str)
}
// Draw the variable text or caption for a field.
-bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int combMaxLen,
- const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags)
+bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
+ const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags, const int combMaxLen)
{
const bool forceZapfDingbats = flags & ForceZapfDingbatsDrawTextFlag;
@@ -5015,7 +5015,7 @@ bool AnnotAppearanceBuilder::drawFormFieldButton(const FormFieldButton *field, c
//~ Acrobat doesn't draw a caption if there is no AP dict (?)
if (appearState && appearState->cmp("Off") != 0 && field->getState(appearState->c_str())) {
if (caption) {
- return drawText(caption, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
+ return drawText(caption, da, resources, border, appearCharacs, rect, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
} else if (appearCharacs) {
const AnnotColor *aColor = appearCharacs->getBorderColor();
if (aColor) {
@@ -5030,16 +5030,16 @@ bool AnnotAppearanceBuilder::drawFormFieldButton(const FormFieldButton *field, c
} break;
case formButtonPush:
if (caption) {
- return drawText(caption, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict);
+ return drawText(caption, da, resources, border, appearCharacs, rect, VariableTextQuadding::centered, xref, resourcesDict);
}
break;
case formButtonCheck:
if (appearState && appearState->cmp("Off") != 0) {
if (!caption) {
GooString checkMark("3");
- return drawText(&checkMark, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
+ return drawText(&checkMark, da, resources, border, appearCharacs, rect, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
} else {
- return drawText(caption, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
+ return drawText(caption, da, resources, border, appearCharacs, rect, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
}
}
break;
@@ -5073,7 +5073,7 @@ bool AnnotAppearanceBuilder::drawFormFieldText(const FormFieldText *fieldText, c
if (fieldText->isPassword()) {
flags = flags | TurnTextToStarsDrawTextFlag;
}
- return drawText(contents, da, resources, border, appearCharacs, rect, combMaxLen, quadding, xref, resourcesDict, flags);
+ return drawText(contents, da, resources, border, appearCharacs, rect, quadding, xref, resourcesDict, flags, combMaxLen);
}
return true;
@@ -5213,7 +5213,7 @@ bool AnnotAppearanceBuilder::drawFormFieldChoice(const FormFieldChoice *fieldCho
if (fieldChoice->isCombo()) {
selected = fieldChoice->getSelectedChoice();
if (selected) {
- return drawText(selected, da, resources, border, appearCharacs, rect, 0, quadding, xref, resourcesDict, EmitMarkedContentDrawTextFlag);
+ return drawText(selected, da, resources, border, appearCharacs, rect, quadding, xref, resourcesDict, EmitMarkedContentDrawTextFlag);
//~ Acrobat draws a popup icon on the right side
}
// list box
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 3389de12..482bb33f 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -624,8 +624,8 @@ private:
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);
- bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int combMaxLen,
- const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags = NoDrawTextFlags);
+ bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const VariableTextQuadding quadding, XRef *xref,
+ Dict *resourcesDict, const int flags = NoDrawTextFlags, const int combMaxLen = 0);
void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);
GooString *appearBuf;
commit 8c09ef74a249044eccf0688b0d845067b1eaeb75
Author: Albert Astals Cid <aacid at kde.org>
Date: Thu Mar 24 16:19:46 2022 +0100
Rename comb to combMaxLen
Makes it clearer what it is
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index c06da8df..06750018 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4299,7 +4299,7 @@ void AnnotAppearanceBuilder::writeString(const std::string &str)
}
// Draw the variable text or caption for a field.
-bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int comb,
+bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int combMaxLen,
const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags)
{
const bool forceZapfDingbats = flags & ForceZapfDingbatsDrawTextFlag;
@@ -4435,7 +4435,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
appearBuf->append("BT\n");
// multi-line text
if (flags & MultilineDrawTextFlag) {
- // note: the comb flag is ignored in multiline mode
+ // note: comb is ignored in multiline mode as mentioned in the spec
wMax = dx - 2 * borderWidth - 4;
@@ -4520,11 +4520,11 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
//~ replace newlines with spaces? - what does Acrobat do?
// comb formatting
- if (comb > 0) {
+ if (combMaxLen > 0) {
int charCount;
// compute comb spacing
- w = (dx - 2 * borderWidth) / comb;
+ w = (dx - 2 * borderWidth) / combMaxLen;
// compute font autosize
if (fontSize == 0) {
@@ -4540,10 +4540,10 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
}
}
- int i = 0;
- Annot::layoutText(text, &convertedText, &i, *font, nullptr, 0.0, &charCount, forceZapfDingbats);
- if (charCount > comb) {
- charCount = comb;
+ int dummy = 0;
+ Annot::layoutText(text, &convertedText, &dummy, *font, nullptr, 0.0, &charCount, forceZapfDingbats);
+ if (charCount > combMaxLen) {
+ charCount = combMaxLen;
}
// compute starting text cell
@@ -4553,10 +4553,10 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
x = borderWidth;
break;
case VariableTextQuadding::centered:
- x = borderWidth + (comb - charCount) / 2.0 * w;
+ x = borderWidth + (combMaxLen - charCount) / 2.0 * w;
break;
case VariableTextQuadding::rightJustified:
- x = borderWidth + (comb - charCount) * w;
+ x = borderWidth + (combMaxLen - charCount) * w;
break;
}
y = 0.5 * dy - 0.4 * fontSize;
@@ -4572,8 +4572,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
}
// write the DA string
- for (i = 0; i < (int)daToks.size(); ++i) {
- appearBuf->append(daToks[i])->append(' ');
+ for (const GooString *daTok : daToks) {
+ appearBuf->append(daTok)->append(' ');
}
// write the font matrix (if not part of the DA string)
@@ -4584,9 +4584,9 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
// write the text string
const char *s = convertedText.c_str();
int len = convertedText.getLength();
- i = 0;
+ int i = 0;
xPrev = w; // so that first character is placed properly
- while (i < comb && len > 0) {
+ while (i < combMaxLen && len > 0) {
CharCode code;
const Unicode *uAux;
int uLen, n;
@@ -5064,10 +5064,7 @@ bool AnnotAppearanceBuilder::drawFormFieldText(const FormFieldText *fieldText, c
quadding = VariableTextQuadding::leftJustified;
}
- int comb = 0;
- if (fieldText->isComb()) {
- comb = fieldText->getMaxLen();
- }
+ const int combMaxLen = fieldText->isComb() ? fieldText->getMaxLen() : 0;
int flags = EmitMarkedContentDrawTextFlag;
if (fieldText->isMultiline()) {
@@ -5076,7 +5073,7 @@ bool AnnotAppearanceBuilder::drawFormFieldText(const FormFieldText *fieldText, c
if (fieldText->isPassword()) {
flags = flags | TurnTextToStarsDrawTextFlag;
}
- return drawText(contents, da, resources, border, appearCharacs, rect, comb, quadding, xref, resourcesDict, flags);
+ return drawText(contents, da, resources, border, appearCharacs, rect, combMaxLen, quadding, xref, resourcesDict, flags);
}
return true;
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 1ad22250..3389de12 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -624,7 +624,7 @@ private:
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);
- bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int comb,
+ bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int combMaxLen,
const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags = NoDrawTextFlags);
void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);
commit 99f3b11e8f91983d78054b3c5c5bcb8356035e29
Author: Albert Astals Cid <aacid at kde.org>
Date: Thu Mar 24 16:08:35 2022 +0100
Unify 2 enums and a set of defines into an enum
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index da225e33..2c9a7607 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -1587,11 +1587,11 @@ PopplerAnnotFreeTextQuadding poppler_annot_free_text_get_quadding(PopplerAnnotFr
annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT(poppler_annot)->annot);
switch (annot->getQuadding()) {
- case AnnotFreeText::quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
return POPPLER_ANNOT_FREE_TEXT_QUADDING_LEFT_JUSTIFIED;
- case AnnotFreeText::quaddingCentered:
+ case VariableTextQuadding::centered:
return POPPLER_ANNOT_FREE_TEXT_QUADDING_CENTERED;
- case AnnotFreeText::quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
return POPPLER_ANNOT_FREE_TEXT_QUADDING_RIGHT_JUSTIFIED;
default:
g_warning("Unsupported Annot Free Text Quadding");
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 72b2f10b..c06da8df 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -129,10 +129,6 @@
#define fieldFlagRadiosInUnison 0x02000000
#define fieldFlagCommitOnSelChange 0x04000000
-#define fieldQuadLeft 0
-#define fieldQuadCenter 1
-#define fieldQuadRight 2
-
// distance of Bezier control point from center for circle approximation
// = (4 * (sqrt(2) - 1) / 3) * r
#define bezierCircle 0.55228475
@@ -2868,9 +2864,9 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict)
obj1 = dict->lookup("Q");
if (obj1.isInt()) {
- quadding = (AnnotFreeTextQuadding)obj1.getInt();
+ quadding = (VariableTextQuadding)obj1.getInt();
} else {
- quadding = quaddingLeftJustified;
+ quadding = VariableTextQuadding::leftJustified;
}
obj1 = dict->lookup("DS");
@@ -2951,7 +2947,7 @@ void AnnotFreeText::setDefaultAppearance(const DefaultAppearance &da)
invalidateAppearance();
}
-void AnnotFreeText::setQuadding(AnnotFreeTextQuadding new_quadding)
+void AnnotFreeText::setQuadding(VariableTextQuadding new_quadding)
{
quadding = new_quadding;
update("Q", Object((int)quadding));
@@ -3146,13 +3142,13 @@ void AnnotFreeText::generateFreeTextAppearance()
layoutText(contents.get(), &out, &i, *font, &linewidth, textwidth / da.getFontPtSize(), nullptr, false);
linewidth *= da.getFontPtSize();
switch (quadding) {
- case quaddingCentered:
+ case VariableTextQuadding::centered:
xpos = (textwidth - linewidth) / 2;
break;
- case quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
xpos = textwidth - linewidth;
break;
- default: // quaddingLeftJustified:
+ default: // VariableTextQuadding::leftJustified:
xpos = 0;
break;
}
@@ -4304,7 +4300,7 @@ void AnnotAppearanceBuilder::writeString(const std::string &str)
// Draw the variable text or caption for a field.
bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int comb,
- const int quadding, XRef *xref, Dict *resourcesDict, const int flags)
+ const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags)
{
const bool forceZapfDingbats = flags & ForceZapfDingbatsDrawTextFlag;
@@ -4498,14 +4494,14 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
// compute text start position
switch (quadding) {
- case quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
default:
x = borderWidth + 2;
break;
- case quaddingCentered:
+ case VariableTextQuadding::centered:
x = (dx - w) / 2;
break;
- case quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
x = dx - borderWidth - 2 - w;
break;
}
@@ -4552,14 +4548,14 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
// compute starting text cell
switch (quadding) {
- case quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
default:
x = borderWidth;
break;
- case quaddingCentered:
+ case VariableTextQuadding::centered:
x = borderWidth + (comb - charCount) / 2.0 * w;
break;
- case quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
x = borderWidth + (comb - charCount) * w;
break;
}
@@ -4641,14 +4637,14 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
// compute text start position
w *= fontSize;
switch (quadding) {
- case quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
default:
x = borderWidth + 2;
break;
- case quaddingCentered:
+ case VariableTextQuadding::centered:
x = (dx - w) / 2;
break;
- case quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
x = dx - borderWidth - 2 - w;
break;
}
@@ -4696,7 +4692,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
}
// Draw the variable text or caption for a field.
-bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, int quadding, XRef *xref, Dict *resourcesDict)
+bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, VariableTextQuadding quadding, XRef *xref,
+ Dict *resourcesDict)
{
std::vector<GooString *> daToks;
GooString *tok;
@@ -4821,14 +4818,14 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
Annot::layoutText(fieldChoice->getChoice(i), &convertedText, &j, *font, &w, 0.0, nullptr, false);
w *= fontSize;
switch (quadding) {
- case quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
default:
x = borderWidth + 2;
break;
- case quaddingCentered:
+ case VariableTextQuadding::centered:
x = (rect->x2 - rect->x1 - w) / 2;
break;
- case quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
x = rect->x2 - rect->x1 - borderWidth - 2 - w;
break;
}
@@ -5018,7 +5015,7 @@ bool AnnotAppearanceBuilder::drawFormFieldButton(const FormFieldButton *field, c
//~ Acrobat doesn't draw a caption if there is no AP dict (?)
if (appearState && appearState->cmp("Off") != 0 && field->getState(appearState->c_str())) {
if (caption) {
- return drawText(caption, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
+ return drawText(caption, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
} else if (appearCharacs) {
const AnnotColor *aColor = appearCharacs->getBorderColor();
if (aColor) {
@@ -5033,16 +5030,16 @@ bool AnnotAppearanceBuilder::drawFormFieldButton(const FormFieldButton *field, c
} break;
case formButtonPush:
if (caption) {
- return drawText(caption, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict);
+ return drawText(caption, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict);
}
break;
case formButtonCheck:
if (appearState && appearState->cmp("Off") != 0) {
if (!caption) {
GooString checkMark("3");
- return drawText(&checkMark, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
+ return drawText(&checkMark, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
} else {
- return drawText(caption, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
+ return drawText(caption, da, resources, border, appearCharacs, rect, 0, VariableTextQuadding::centered, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
}
}
break;
@@ -5064,7 +5061,7 @@ bool AnnotAppearanceBuilder::drawFormFieldText(const FormFieldText *fieldText, c
} else if (form) {
quadding = form->getTextQuadding();
} else {
- quadding = quaddingLeftJustified;
+ quadding = VariableTextQuadding::leftJustified;
}
int comb = 0;
@@ -5213,7 +5210,7 @@ bool AnnotAppearanceBuilder::drawFormFieldChoice(const FormFieldChoice *fieldCho
} else if (form) {
quadding = form->getTextQuadding();
} else {
- quadding = quaddingLeftJustified;
+ quadding = VariableTextQuadding::leftJustified;
}
if (fieldChoice->isCombo()) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 31353aa7..1ad22250 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -100,6 +100,13 @@ enum AnnotExternalDataType
annotExternalDataMarkup3D // Markup3D
};
+enum class VariableTextQuadding
+{
+ leftJustified,
+ centered,
+ rightJustified
+};
+
//------------------------------------------------------------------------
// AnnotCoord
//------------------------------------------------------------------------
@@ -562,6 +569,7 @@ private:
// AnnotAppearanceBuilder
//------------------------------------------------------------------------
class Matrix;
+
class AnnotAppearanceBuilder
{
public:
@@ -606,7 +614,7 @@ private:
TurnTextToStarsDrawTextFlag = 8
};
- bool drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, int quadding, XRef *xref, Dict *resourcesDict);
+ bool drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict);
bool drawFormFieldButton(const FormFieldButton *field, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const GooString *appearState,
XRef *xref, Dict *resourcesDict);
bool drawFormFieldText(const FormFieldText *fieldText, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, XRef *xref,
@@ -616,8 +624,8 @@ private:
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);
- bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int comb, const int quadding, XRef *xref,
- Dict *resourcesDict, const int flags = NoDrawTextFlags);
+ bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int comb,
+ const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags = NoDrawTextFlags);
void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);
GooString *appearBuf;
@@ -1038,13 +1046,6 @@ protected:
class POPPLER_PRIVATE_EXPORT AnnotFreeText : public AnnotMarkup
{
public:
- enum AnnotFreeTextQuadding
- {
- quaddingLeftJustified, // 0
- quaddingCentered, // 1
- quaddingRightJustified // 2
- };
-
enum AnnotFreeTextIntent
{
intentFreeText, // FreeText
@@ -1063,14 +1064,14 @@ public:
void setContents(std::unique_ptr<GooString> &&new_content) override;
void setDefaultAppearance(const DefaultAppearance &da);
- void setQuadding(AnnotFreeTextQuadding new_quadding);
+ void setQuadding(VariableTextQuadding new_quadding);
void setStyleString(GooString *new_string);
void setCalloutLine(AnnotCalloutLine *line);
void setIntent(AnnotFreeTextIntent new_intent);
// getters
std::unique_ptr<DefaultAppearance> getDefaultAppearance() const;
- AnnotFreeTextQuadding getQuadding() const { return quadding; }
+ VariableTextQuadding getQuadding() const { return quadding; }
// return rc
const GooString *getStyleString() const { return styleString.get(); }
AnnotCalloutLine *getCalloutLine() const { return calloutLine.get(); }
@@ -1087,7 +1088,7 @@ protected:
std::unique_ptr<GooString> appearanceString; // DA
// optional
- AnnotFreeTextQuadding quadding; // Q (Default 0)
+ VariableTextQuadding quadding; // Q (Default 0)
// RC
std::unique_ptr<GooString> styleString; // DS
std::unique_ptr<AnnotCalloutLine> calloutLine; // CL
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 44e4e394..97b5be0e 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -915,7 +915,7 @@ FormField::FormField(PDFDoc *docA, Object &&aobj, const Ref aref, FormField *par
readOnly = false;
defaultAppearance = nullptr;
fullyQualifiedName = nullptr;
- quadding = quaddingLeftJustified;
+ quadding = VariableTextQuadding::leftJustified;
hasQuadding = false;
standAlone = false;
@@ -998,8 +998,8 @@ FormField::FormField(PDFDoc *docA, Object &&aobj, const Ref aref, FormField *par
obj1 = Form::fieldLookup(dict, "Q");
if (obj1.isInt()) {
- const int aux = obj1.getInt();
- hasQuadding = aux == quaddingLeftJustified || aux == quaddingCentered || aux == quaddingRightJustified;
+ const VariableTextQuadding aux = static_cast<VariableTextQuadding>(obj1.getInt());
+ hasQuadding = aux == VariableTextQuadding::leftJustified || aux == VariableTextQuadding::centered || aux == VariableTextQuadding::rightJustified;
if (likely(hasQuadding)) {
quadding = static_cast<VariableTextQuadding>(aux);
}
@@ -2498,7 +2498,7 @@ Form::Form(PDFDoc *doc)
size = 0;
numFields = 0;
rootFields = nullptr;
- quadding = quaddingLeftJustified;
+ quadding = VariableTextQuadding::leftJustified;
defaultAppearance = nullptr;
defaultResources = nullptr;
@@ -2513,8 +2513,8 @@ Form::Form(PDFDoc *doc)
obj1 = acroForm->dictLookup("Q");
if (obj1.isInt()) {
- const int aux = obj1.getInt();
- if (aux == quaddingLeftJustified || aux == quaddingCentered || aux == quaddingRightJustified) {
+ const VariableTextQuadding aux = static_cast<VariableTextQuadding>(obj1.getInt());
+ if (aux == VariableTextQuadding::leftJustified || aux == VariableTextQuadding::centered || aux == VariableTextQuadding::rightJustified) {
quadding = static_cast<VariableTextQuadding>(aux);
}
}
diff --git a/poppler/Form.h b/poppler/Form.h
index 9cc35e03..c48ae83f 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -71,13 +71,6 @@ enum FormButtonType
formButtonRadio
};
-enum VariableTextQuadding
-{
- quaddingLeftJustified,
- quaddingCentered,
- quaddingRightJustified
-};
-
enum FormSignatureType
{
adbe_pkcs7_sha1,
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index c46cf732..ab456734 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -2238,7 +2238,7 @@ int TextAnnotation::inplaceAlign() const
if (d->pdfAnnot->getType() == Annot::typeFreeText) {
const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot);
- return ftextann->getQuadding();
+ return static_cast<int>(ftextann->getQuadding());
}
return 0;
@@ -2255,7 +2255,7 @@ void TextAnnotation::setInplaceAlign(int align)
if (d->pdfAnnot->getType() == Annot::typeFreeText) {
AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot);
- ftextann->setQuadding((AnnotFreeText::AnnotFreeTextQuadding)align);
+ ftextann->setQuadding((VariableTextQuadding)align);
}
}
diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc
index 08ed4ce7..665fb5f4 100644
--- a/qt5/src/poppler-form.cc
+++ b/qt5/src/poppler-form.cc
@@ -64,13 +64,13 @@ Qt::Alignment formTextAlignment(::FormWidget *fm)
{
Qt::Alignment qtalign = Qt::AlignLeft;
switch (fm->getField()->getTextQuadding()) {
- case quaddingCentered:
+ case VariableTextQuadding::centered:
qtalign = Qt::AlignHCenter;
break;
- case quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
qtalign = Qt::AlignRight;
break;
- case quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
qtalign = Qt::AlignLeft;
}
return qtalign;
diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc
index 2d875e39..b92b76ba 100644
--- a/qt6/src/poppler-annotation.cc
+++ b/qt6/src/poppler-annotation.cc
@@ -1775,11 +1775,11 @@ TextAnnotation::InplaceAlignPosition TextAnnotation::inplaceAlign() const
if (d->pdfAnnot->getType() == Annot::typeFreeText) {
const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot);
switch (ftextann->getQuadding()) {
- case AnnotFreeText::quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
return InplaceAlignLeft;
- case AnnotFreeText::quaddingCentered:
+ case VariableTextQuadding::centered:
return InplaceAlignCenter;
- case AnnotFreeText::quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
return InplaceAlignRight;
}
}
@@ -1787,17 +1787,17 @@ TextAnnotation::InplaceAlignPosition TextAnnotation::inplaceAlign() const
return InplaceAlignLeft;
}
-static AnnotFreeText::AnnotFreeTextQuadding alignToQuadding(TextAnnotation::InplaceAlignPosition align)
+static VariableTextQuadding alignToQuadding(TextAnnotation::InplaceAlignPosition align)
{
switch (align) {
case TextAnnotation::InplaceAlignLeft:
- return AnnotFreeText::quaddingLeftJustified;
+ return VariableTextQuadding::leftJustified;
case TextAnnotation::InplaceAlignCenter:
- return AnnotFreeText::quaddingCentered;
+ return VariableTextQuadding::centered;
case TextAnnotation::InplaceAlignRight:
- return AnnotFreeText::quaddingRightJustified;
+ return VariableTextQuadding::rightJustified;
}
- return AnnotFreeText::quaddingLeftJustified;
+ return VariableTextQuadding::leftJustified;
}
void TextAnnotation::setInplaceAlign(InplaceAlignPosition align)
diff --git a/qt6/src/poppler-form.cc b/qt6/src/poppler-form.cc
index 2fb7bcb3..7e963f0f 100644
--- a/qt6/src/poppler-form.cc
+++ b/qt6/src/poppler-form.cc
@@ -64,13 +64,13 @@ Qt::Alignment formTextAlignment(::FormWidget *fm)
{
Qt::Alignment qtalign = Qt::AlignLeft;
switch (fm->getField()->getTextQuadding()) {
- case quaddingCentered:
+ case VariableTextQuadding::centered:
qtalign = Qt::AlignHCenter;
break;
- case quaddingRightJustified:
+ case VariableTextQuadding::rightJustified:
qtalign = Qt::AlignRight;
break;
- case quaddingLeftJustified:
+ case VariableTextQuadding::leftJustified:
qtalign = Qt::AlignLeft;
}
return qtalign;
commit 8848c8f1498a290410c31622aee808021c624bb0
Author: Albert Astals Cid <aacid at kde.org>
Date: Thu Mar 24 15:50:07 2022 +0100
AnnotAppearanceBuilder::drawText: Merge 4 bools into a flags variable
Makes for much easier reading on the calling side
Also drop the defaultFallback variable, it was ever only used to pass
ZapfDingbats when also passing the forceZapfDingbats variable
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index c49ec898..72b2f10b 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4303,9 +4303,11 @@ void AnnotAppearanceBuilder::writeString(const std::string &str)
}
// Draw the variable text or caption for a field.
-bool AnnotAppearanceBuilder::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)
+bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int comb,
+ const int quadding, XRef *xref, Dict *resourcesDict, const int flags)
{
+ const bool forceZapfDingbats = flags & ForceZapfDingbatsDrawTextFlag;
+
std::vector<GooString *> daToks;
GooString *tok;
GooString convertedText;
@@ -4361,7 +4363,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
if (tok->getLength() >= 1 && tok->getChar(0) == '/') {
if (!resources || !(font = resources->lookupFont(tok->c_str() + 1).get())) {
if (xref != nullptr && resourcesDict != nullptr) {
- const char *fallback = determineFallbackFont(tok->toStr(), defaultFallback);
+ const char *fallback = determineFallbackFont(tok->toStr(), forceZapfDingbats ? "ZapfDingbats" : "Helvetica");
// The font variable sometimes points to an object that needs to be deleted
// and sometimes not, depending on whether the call to lookupFont above fails.
// When the code path right here is taken, the destructor of fontToFree
@@ -4391,7 +4393,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
borderWidth = border ? border->getWidth() : 0;
// for a password field, replace all characters with asterisks
- if (password) {
+ if (flags & TurnTextToStarsDrawTextFlag) {
int len;
if (text->hasUnicodeMarker()) {
len = (text->getLength() - 2) / 2;
@@ -4408,7 +4410,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
}
// setup
- if (txField) {
+ if (flags & EmitMarkedContentDrawTextFlag) {
appearBuf->append("/Tx BMC\n");
}
appearBuf->append("q\n");
@@ -4436,7 +4438,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
}
appearBuf->append("BT\n");
// multi-line text
- if (multiline) {
+ if (flags & MultilineDrawTextFlag) {
// note: the comb flag is ignored in multiline mode
wMax = dx - 2 * borderWidth - 4;
@@ -4680,7 +4682,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
// cleanup
appearBuf->append("ET\n");
appearBuf->append("Q\n");
- if (txField) {
+ if (flags & EmitMarkedContentDrawTextFlag) {
appearBuf->append("EMC\n");
}
for (auto entry : daToks) {
@@ -5016,7 +5018,7 @@ bool AnnotAppearanceBuilder::drawFormFieldButton(const FormFieldButton *field, c
//~ Acrobat doesn't draw a caption if there is no AP dict (?)
if (appearState && appearState->cmp("Off") != 0 && field->getState(appearState->c_str())) {
if (caption) {
- return drawText(caption, da, resources, border, appearCharacs, rect, false, 0, fieldQuadCenter, false, true, xref, false, resourcesDict, "ZapfDingbats");
+ return drawText(caption, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
} else if (appearCharacs) {
const AnnotColor *aColor = appearCharacs->getBorderColor();
if (aColor) {
@@ -5031,16 +5033,16 @@ bool AnnotAppearanceBuilder::drawFormFieldButton(const FormFieldButton *field, c
} break;
case formButtonPush:
if (caption) {
- return drawText(caption, da, resources, border, appearCharacs, rect, false, 0, fieldQuadCenter, false, false, xref, false, resourcesDict);
+ return drawText(caption, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict);
}
break;
case formButtonCheck:
if (appearState && appearState->cmp("Off") != 0) {
if (!caption) {
GooString checkMark("3");
- return drawText(&checkMark, da, resources, border, appearCharacs, rect, false, 0, fieldQuadCenter, false, true, xref, false, resourcesDict, "ZapfDingbats");
+ return drawText(&checkMark, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
} else {
- return drawText(caption, da, resources, border, appearCharacs, rect, false, 0, fieldQuadCenter, false, true, xref, false, resourcesDict, "ZapfDingbats");
+ return drawText(caption, da, resources, border, appearCharacs, rect, 0, fieldQuadCenter, xref, resourcesDict, ForceZapfDingbatsDrawTextFlag);
}
}
break;
@@ -5070,7 +5072,14 @@ bool AnnotAppearanceBuilder::drawFormFieldText(const FormFieldText *fieldText, c
comb = fieldText->getMaxLen();
}
- return drawText(contents, da, resources, border, appearCharacs, rect, fieldText->isMultiline(), comb, quadding, true, false, xref, fieldText->isPassword(), resourcesDict);
+ int flags = EmitMarkedContentDrawTextFlag;
+ if (fieldText->isMultiline()) {
+ flags = flags | MultilineDrawTextFlag;
+ }
+ if (fieldText->isPassword()) {
+ flags = flags | TurnTextToStarsDrawTextFlag;
+ }
+ return drawText(contents, da, resources, border, appearCharacs, rect, comb, quadding, xref, resourcesDict, flags);
}
return true;
@@ -5210,7 +5219,7 @@ bool AnnotAppearanceBuilder::drawFormFieldChoice(const FormFieldChoice *fieldCho
if (fieldChoice->isCombo()) {
selected = fieldChoice->getSelectedChoice();
if (selected) {
- return drawText(selected, da, resources, border, appearCharacs, rect, false, 0, quadding, true, false, xref, false, resourcesDict);
+ return drawText(selected, da, resources, border, appearCharacs, rect, 0, quadding, xref, resourcesDict, EmitMarkedContentDrawTextFlag);
//~ Acrobat draws a popup icon on the right side
}
// list box
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 196327c2..31353aa7 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -597,6 +597,15 @@ public:
const GooString *buffer() const;
private:
+ enum DrawTextFlags
+ {
+ NoDrawTextFlags = 0,
+ MultilineDrawTextFlag = 1,
+ EmitMarkedContentDrawTextFlag = 2,
+ ForceZapfDingbatsDrawTextFlag = 4,
+ TurnTextToStarsDrawTextFlag = 8
+ };
+
bool drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, int quadding, XRef *xref, Dict *resourcesDict);
bool drawFormFieldButton(const FormFieldButton *field, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const GooString *appearState,
XRef *xref, Dict *resourcesDict);
@@ -607,8 +616,8 @@ private:
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);
- 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");
+ bool drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const int comb, const int quadding, XRef *xref,
+ Dict *resourcesDict, const int flags = NoDrawTextFlags);
void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);
GooString *appearBuf;
More information about the poppler
mailing list