From a2ba23509f21e2934f5cc0a58ee78e5314c19884 Mon Sep 17 00:00:00 2001 From: Marek Kasik Date: Tue, 29 Nov 2022 17:25:53 +0100 Subject: [PATCH] Update font after restore in Cairo Provide Unicode marker when ensuring fonts --- poppler-22.08.0-provide-unicode-marker.patch | 44 +++++++++ ...er-22.08.0-update-font-after-restore.patch | 94 +++++++++++++++++++ poppler.spec | 9 +- 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 poppler-22.08.0-provide-unicode-marker.patch create mode 100644 poppler-22.08.0-update-font-after-restore.patch diff --git a/poppler-22.08.0-provide-unicode-marker.patch b/poppler-22.08.0-provide-unicode-marker.patch new file mode 100644 index 0000000..3f4c04b --- /dev/null +++ b/poppler-22.08.0-provide-unicode-marker.patch @@ -0,0 +1,44 @@ +From bc4a0d9a2abfcd75d9b0ee4be3f7600905fe6001 Mon Sep 17 00:00:00 2001 +From: Marek Kasik +Date: Fri, 24 Jun 2022 22:01:27 +0200 +Subject: [PATCH 2/2] Form: Provide Unicode marker when ensuring fonts + +Form::ensureFontsForAllCharacters() needs input text with Unicode marker. +Provide such in FormFieldText::setContentCopy(). +--- + poppler/Form.cc | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/poppler/Form.cc b/poppler/Form.cc +index d33160b3..9407b6c5 100644 +--- a/poppler/Form.cc ++++ b/poppler/Form.cc +@@ -27,7 +27,7 @@ + // Copyright 2019, 2020 Oliver Sander + // Copyright 2019 Tomoyuki Kubota + // Copyright 2019 João Netto +-// Copyright 2020, 2021 Marek Kasik ++// Copyright 2020-2022 Marek Kasik + // Copyright 2020 Thorsten Behrens + // Copyright 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, . Work sponsored by Technische Universität Dresden + // Copyright 2021 Georgiy Sgibnev . Work sponsored by lab50.net. +@@ -1674,14 +1674,14 @@ void FormFieldText::setContentCopy(const GooString *new_content) + Object fieldResourcesDictObj = obj.dictLookup("DR"); + if (fieldResourcesDictObj.isDict()) { + GfxResources fieldResources(doc->getXRef(), fieldResourcesDictObj.getDict(), form->getDefaultResources()); +- const std::vector newFonts = form->ensureFontsForAllCharacters(new_content, fontName, &fieldResources); ++ const std::vector newFonts = form->ensureFontsForAllCharacters(content, fontName, &fieldResources); + // If we added new fonts to the Form object default resuources we also need to add them (we only add the ref so this is cheap) + // to the field DR dictionary + for (const Form::AddFontResult &afr : newFonts) { + fieldResourcesDictObj.dictLookup("Font").dictAdd(afr.fontName.c_str(), Object(afr.ref)); + } + } else { +- form->ensureFontsForAllCharacters(new_content, fontName); ++ form->ensureFontsForAllCharacters(content, fontName); + } + } + } else { +-- +2.38.1 + diff --git a/poppler-22.08.0-update-font-after-restore.patch b/poppler-22.08.0-update-font-after-restore.patch new file mode 100644 index 0000000..c3008fe --- /dev/null +++ b/poppler-22.08.0-update-font-after-restore.patch @@ -0,0 +1,94 @@ +From 111f38a722eedddd94faa52dda8c5e0da561fb41 Mon Sep 17 00:00:00 2001 +From: Marek Kasik +Date: Fri, 24 Jun 2022 22:00:09 +0200 +Subject: [PATCH 1/2] Cairo: Update font after restore + +Update font after restore (Q operator) if font has changed. +This is important when entering text into forms if there +are characters shown by default font after characters +which needed new font. + +New method getRef() where added to CairoFont class to +be able to easily compare fonts. +--- + poppler/CairoFontEngine.h | 3 +++ + poppler/CairoOutputDev.cc | 7 ++++++- + poppler/CairoOutputDev.h | 2 ++ + 3 files changed, 11 insertions(+), 1 deletion(-) + +diff --git a/poppler/CairoFontEngine.h b/poppler/CairoFontEngine.h +index 56cc8825..c97e0ea4 100644 +--- a/poppler/CairoFontEngine.h ++++ b/poppler/CairoFontEngine.h +@@ -22,6 +22,7 @@ + // Copyright (C) 2013 Thomas Freitag + // Copyright (C) 2018 Adam Reichold + // Copyright (C) 2022 Oliver Sander ++// Copyright (C) 2022 Marek Kasik + // + // To see a description of the changes please see the Changelog file that + // came with your tarball or type make ChangeLog if you are building from git +@@ -59,6 +60,8 @@ public: + + bool isSubstitute() { return substitute; } + ++ Ref getRef() { return ref; } ++ + protected: + Ref ref; + cairo_font_face_t *cairo_font_face; +diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc +index b402cc8b..a72c218a 100644 +--- a/poppler/CairoOutputDev.cc ++++ b/poppler/CairoOutputDev.cc +@@ -31,7 +31,7 @@ + // Copyright (C) 2015 Suzuki Toshiya + // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, . Work sponsored by the LiMux project of the city of Munich + // Copyright (C) 2018, 2020 Adam Reichold +-// Copyright (C) 2019, 2020 Marek Kasik ++// Copyright (C) 2019, 2020, 2022 Marek Kasik + // Copyright (C) 2020 Michal + // Copyright (C) 2020, 2022 Oliver Sander + // Copyright (C) 2021 Uli Schlachter +@@ -357,6 +357,7 @@ void CairoOutputDev::saveState(GfxState *state) + elem.stroke_opacity = stroke_opacity; + elem.mask = mask ? cairo_pattern_reference(mask) : nullptr; + elem.mask_matrix = mask_matrix; ++ elem.fontRef = currentFont ? currentFont->getRef() : Ref::INVALID(); + saveStateStack.push_back(elem); + + if (strokePathClip) { +@@ -384,6 +385,10 @@ void CairoOutputDev::restoreState(GfxState *state) + stroke_color = {}; + stroke_opacity = saveStateStack.back().stroke_opacity; + ++ if (saveStateStack.back().fontRef != (currentFont ? currentFont->getRef() : Ref::INVALID())) { ++ needFontUpdate = true; ++ } ++ + /* This isn't restored by cairo_restore() since we keep it in the + * output device. */ + updateBlendMode(state); +diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h +index c287bf5c..5ce877d2 100644 +--- a/poppler/CairoOutputDev.h ++++ b/poppler/CairoOutputDev.h +@@ -27,6 +27,7 @@ + // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, . Work sponsored by the LiMux project of the city of Munich + // Copyright (C) 2020 Michal + // Copyright (C) 2021 Christian Persch ++// Copyright (C) 2022 Marek Kasik + // + // To see a description of the changes please see the Changelog file that + // came with your tarball or type make ChangeLog if you are building from git +@@ -381,6 +382,7 @@ protected: + double stroke_opacity; + cairo_pattern_t *mask; // can be null + cairo_matrix_t mask_matrix; ++ Ref fontRef; + }; + std::vector saveStateStack; + }; +-- +2.38.1 + diff --git a/poppler.spec b/poppler.spec index a4fd4c6..1854aea 100644 --- a/poppler.spec +++ b/poppler.spec @@ -15,7 +15,7 @@ Summary: PDF rendering library Name: poppler Version: 22.08.0 -Release: 3%{?dist} +Release: 4%{?dist} License: (GPLv2 or GPLv3) and GPLv2+ and LGPLv2+ and MIT URL: http://poppler.freedesktop.org/ Source0: http://poppler.freedesktop.org/poppler-%{version}.tar.xz @@ -29,6 +29,9 @@ Patch3: poppler-21.01.0-glib-introspection.patch # https://bugzilla.redhat.com/show_bug.cgi?id=2124527 Patch4: poppler-22.08.0-jbig-symbol-overflow.patch +Patch5: poppler-22.08.0-update-font-after-restore.patch +Patch6: poppler-22.08.0-provide-unicode-marker.patch + BuildRequires: make BuildRequires: cmake BuildRequires: gcc-c++ @@ -279,6 +282,10 @@ test "$(pkg-config --modversion poppler-qt6)" = "%{version}" %{_mandir}/man1/* %changelog +* Tue Nov 29 2022 Marek Kasik - 22.08.0-4 +- Update font after restore in Cairo +- Provide Unicode marker when ensuring fonts + * Wed Oct 05 2022 Marek Kasik - 22.08.0-3 - Check for overflow when computing number of symbols - in JBIG2 text region