[poppler] qt5/src qt6/src
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Feb 22 15:14:45 UTC 2022
qt5/src/poppler-annotation.cc | 18 +++++++++++++-----
qt6/src/poppler-annotation.cc | 18 +++++++++++++-----
2 files changed, 26 insertions(+), 10 deletions(-)
New commits:
commit 5b2a4b46f642acc0db97910045475d340be57466
Author: Albert Astals Cid <aacid at kde.org>
Date: Tue Feb 22 16:07:50 2022 +0100
qt: Store QFont as an optional
This way we can know whether the font has been set externally or not
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index 4e0caeae..20a4a534 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -1835,7 +1835,7 @@ public:
// data fields
TextAnnotation::TextType textType;
QString textIcon;
- QFont textFont;
+ std::optional<QFont> textFont;
QColor textColor;
int inplaceAlign; // 0:left, 1:center, 2:right
QVector<QPointF> inplaceCallout;
@@ -1863,7 +1863,11 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *
if (textType == TextAnnotation::Linked) {
pdfAnnot = new AnnotText { destPage->getDoc(), &rect };
} else {
- DefaultAppearance da { { objName, "Invalid_font" }, static_cast<double>(textFont.pointSize()), convertQColor(textColor) };
+ const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize;
+ if (pointSize < 0) {
+ qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0";
+ }
+ DefaultAppearance da { { objName, "Invalid_font" }, pointSize, convertQColor(textColor) };
pdfAnnot = new AnnotFreeText { destPage->getDoc(), &rect, da };
}
@@ -1885,7 +1889,11 @@ void TextAnnotationPrivate::setDefaultAppearanceToNative()
{
if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) {
AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot);
- DefaultAppearance da { { objName, "Invalid_font" }, static_cast<double>(textFont.pointSize()), convertQColor(textColor) };
+ const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize;
+ if (pointSize < 0) {
+ qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0";
+ }
+ DefaultAppearance da { { objName, "Invalid_font" }, pointSize, convertQColor(textColor) };
ftextann->setDefaultAppearance(da);
}
}
@@ -2066,8 +2074,8 @@ QFont TextAnnotation::textFont() const
{
Q_D(const TextAnnotation);
- if (!d->pdfAnnot)
- return d->textFont;
+ if (d->textFont)
+ return *d->textFont;
double fontSize { AnnotFreeText::undefinedFontPtSize };
if (d->pdfAnnot->getType() == Annot::typeFreeText) {
diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc
index 60a9b9be..748749cd 100644
--- a/qt6/src/poppler-annotation.cc
+++ b/qt6/src/poppler-annotation.cc
@@ -1500,7 +1500,7 @@ public:
// data fields
TextAnnotation::TextType textType;
QString textIcon;
- QFont textFont;
+ std::optional<QFont> textFont;
QColor textColor;
TextAnnotation::InplaceAlignPosition inplaceAlign;
QVector<QPointF> inplaceCallout;
@@ -1528,7 +1528,11 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *
if (textType == TextAnnotation::Linked) {
pdfAnnot = new AnnotText { destPage->getDoc(), &rect };
} else {
- DefaultAppearance da { { objName, "Invalid_font" }, static_cast<double>(textFont.pointSize()), convertQColor(textColor) };
+ const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize;
+ if (pointSize < 0) {
+ qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0";
+ }
+ DefaultAppearance da { { objName, "Invalid_font" }, pointSize, convertQColor(textColor) };
pdfAnnot = new AnnotFreeText { destPage->getDoc(), &rect, da };
}
@@ -1550,7 +1554,11 @@ void TextAnnotationPrivate::setDefaultAppearanceToNative()
{
if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) {
AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot);
- DefaultAppearance da { { objName, "Invalid_font" }, static_cast<double>(textFont.pointSize()), convertQColor(textColor) };
+ const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize;
+ if (pointSize < 0) {
+ qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0";
+ }
+ DefaultAppearance da { { objName, "Invalid_font" }, pointSize, convertQColor(textColor) };
ftextann->setDefaultAppearance(da);
}
}
@@ -1637,8 +1645,8 @@ QFont TextAnnotation::textFont() const
{
Q_D(const TextAnnotation);
- if (!d->pdfAnnot)
- return d->textFont;
+ if (d->textFont)
+ return *d->textFont;
double fontSize { AnnotFreeText::undefinedFontPtSize };
if (d->pdfAnnot->getType() == Annot::typeFreeText) {
More information about the poppler
mailing list