include/vcl/filter/PDFiumLibrary.hxx | 1 + sd/qa/unit/data/pdf/differentfonts.pdf |binary sd/qa/unit/export-tests.cxx | 23 +++++++++++++++++++++++ svx/source/svdraw/svdpdf.cxx | 17 +++++++++-------- vcl/source/pdf/PDFiumLibrary.cxx | 9 +++++++++ 5 files changed, 42 insertions(+), 8 deletions(-)
New commits: commit f8268381f594d3248ab6bce941a6b1e1ca958f66 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Tue Aug 12 12:51:23 2025 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Sep 18 14:06:36 2025 +0200 extract italic/oblique info about font Change-Id: Idf9943cede5b63e98e13265f99fcde9d649987ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190994 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 6dbc1cfece70..86c071d13e3e 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -154,6 +154,7 @@ public: virtual basegfx::B2DRectangle getBounds() = 0; virtual double getFontSize() = 0; virtual OUString getFontName() = 0; + virtual int getFontAngle() = 0; virtual PDFTextRenderMode getTextRenderMode() = 0; virtual Color getFillColor() = 0; virtual Color getStrokeColor() = 0; diff --git a/sd/qa/unit/data/pdf/differentfonts.pdf b/sd/qa/unit/data/pdf/differentfonts.pdf new file mode 100644 index 000000000000..9b5582716328 Binary files /dev/null and b/sd/qa/unit/data/pdf/differentfonts.pdf differ diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index fd2fe86f7b5b..e731e0a95186 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -1065,6 +1065,29 @@ CPPUNIT_TEST_FIXTURE(SdExportTest, testExplodedPdfTextPos) CPPUNIT_ASSERT_DOUBLES_EQUAL(3063, y, 0); } +CPPUNIT_TEST_FIXTURE(SdExportTest, testExplodedPdfFont) +{ + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); + if (!pPdfium) + return; + UsePdfium aGuard; + + loadFromFile(u"pdf/differentfonts.pdf"); + + setFilterOptions("{\"DecomposePDF\":{\"type\":\"boolean\",\"value\":\"true\"}}"); + saveAndReload(u"OpenDocument Drawing Flat XML"_ustr); + + xmlDocUniquePtr pXml = parseLayout(); + OUString sItalic = getXPath(pXml, "//font[2]", "italic"); + // was "none" before + CPPUNIT_ASSERT_EQUAL(u"normal"_ustr, sItalic); + // check that the others remain as expected + OUString sFontName = getXPath(pXml, "//font[2]", "name"); + CPPUNIT_ASSERT_EQUAL(u"Liberation Serif"_ustr, sFontName); + sal_Int32 nFontHeight = getXPath(pXml, "//font[2]", "height").toInt32(); + CPPUNIT_ASSERT_EQUAL(494, nFontHeight); +} + CPPUNIT_TEST_FIXTURE(SdExportTest, testEmbeddedText) { createSdDrawDoc("objectwithtext.fodg"); diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index f343bb8ac4c2..d2bc83dd594b 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -730,17 +730,18 @@ void ImpSdrPdfImport::ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> con const Size aFontSize(dFontSizeH, dFontSizeV); vcl::Font aFnt = mpVD->GetFont(); - if (aFontSize != aFnt.GetFontSize()) - { - aFnt.SetFontSize(aFontSize); - mpVD->SetFont(aFnt); - mbFntDirty = true; - } + aFnt.SetFontSize(aFontSize); OUString sFontName = pPageObject->getFontName(); - if (!sFontName.isEmpty() && sFontName != aFnt.GetFamilyName()) - { + if (!sFontName.isEmpty()) aFnt.SetFamilyName(sFontName); + + const int italicAngle = pPageObject->getFontAngle(); + aFnt.SetItalic(italicAngle == 0 ? ITALIC_NONE + : (italicAngle < 0 ? ITALIC_NORMAL : ITALIC_OBLIQUE)); + + if (aFnt != mpVD->GetFont()) + { mpVD->SetFont(aFnt); mbFntDirty = true; } diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 65e26e04d717..1fbabdc793c4 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -415,6 +415,7 @@ public: basegfx::B2DRectangle getBounds() override; double getFontSize() override; OUString getFontName() override; + int getFontAngle() override; PDFTextRenderMode getTextRenderMode() override; Color getFillColor() override; Color getStrokeColor() override; @@ -1137,6 +1138,14 @@ OUString PDFiumPageObjectImpl::getFontName() return sFamilyName; } +int PDFiumPageObjectImpl::getFontAngle() +{ + int nFontAngle(0); + FPDF_FONT pFontObject = FPDFTextObj_GetFont(mpPageObject); + FPDFFont_GetItalicAngle(pFontObject, &nFontAngle); + return nFontAngle; +} + PDFTextRenderMode PDFiumPageObjectImpl::getTextRenderMode() { return static_cast<PDFTextRenderMode>(FPDFTextObj_GetTextRenderMode(mpPageObject));