sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf |binary
 sd/qa/unit/export-tests.cxx                              |   47 +++++++++++++++
 svx/source/inc/svdpdf.hxx                                |    3 
 svx/source/svdraw/svdpdf.cxx                             |   23 ++++++-
 4 files changed, 69 insertions(+), 4 deletions(-)

New commits:
commit e2e1f57d7cdc934093c4b5d20ed9702e7c1c30a6
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Oct 1 14:56:19 2025 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Oct 15 15:27:43 2025 +0200

    hide text shapes whose content was rendered as Invisible
    
    Change-Id: I9d4c3418ba4e1960d33d443518d25ed6ff7ecebd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191748
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    (cherry picked from commit 35a1641154d20278beff4cc1e5a7aba052d70ed8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192358
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins

diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 485e402157dc..74194758fc5a 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -1174,6 +1174,16 @@ CPPUNIT_TEST_FIXTURE(SdExportTest, 
testExplodedPdfGrayscaleImageUnderInvisibleTe
     // - Expected: rgba[ffffffff]
     // - Actual  : rgba[000000ff]
     CPPUNIT_ASSERT_EQUAL(aExpectedColor, aBitmap.GetPixelColor(5, 5));
+
+    // All the other shape in the group are text in front of that picture
+    // but with their pdf text mode as Invisible so it is the picture that
+    // is seen and the text is hidden. Test a sample text shape here. Without
+    // the fix this test would fail as these shapes were visible.
+    uno::Reference<beans::XPropertySet> 
xTextShape(xGroupShape->getByIndex(10), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xTextShape.is());
+    bool bVisible(true);
+    xTextShape->getPropertyValue(u"Visible"_ustr) >>= bVisible;
+    CPPUNIT_ASSERT_MESSAGE("Shape should be Invisible", !bVisible);
 }
 
 CPPUNIT_TEST_FIXTURE(SdExportTest, testEmbeddedText)
diff --git a/svx/source/inc/svdpdf.hxx b/svx/source/inc/svdpdf.hxx
index bb97c4b5ebf5..a634542730cc 100644
--- a/svx/source/inc/svdpdf.hxx
+++ b/svx/source/inc/svdpdf.hxx
@@ -160,7 +160,8 @@ class ImpSdrPdfImport final
     void ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& 
pPageObject,
                     std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
                     int nPageObjectIndex);
-    void InsertTextObject(const Point& rPos, const Size& rSize, const 
OUString& rStr);
+    void InsertTextObject(const Point& rPos, const Size& rSize, const 
OUString& rStr,
+                          bool bInvisible);
 
     void SetupPageScale(const double dPageWidth, const double dPageHeight);
     void SetAttributes(SdrObject* pObj, bool bForceTextAttr = false);
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index b3eaf298b8a3..261aacfabfd8 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1732,6 +1732,7 @@ void 
ImpSdrPdfImport::ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> con
     Color aTextColor(COL_TRANSPARENT);
     bool bFill = false;
     bool bUse = true;
+    bool bInvisible = false;
     switch (pPageObject->getTextRenderMode())
     {
         case vcl::pdf::PDFTextRenderMode::Fill:
@@ -1745,6 +1746,9 @@ void 
ImpSdrPdfImport::ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> con
         case vcl::pdf::PDFTextRenderMode::Unknown:
             break;
         case vcl::pdf::PDFTextRenderMode::Invisible:
+            bInvisible = true;
+            bUse = false;
+            break;
         case vcl::pdf::PDFTextRenderMode::Clip:
             bUse = false;
             break;
@@ -1762,11 +1766,11 @@ void 
ImpSdrPdfImport::ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> con
         mbFntDirty = true;
     }
 
-    InsertTextObject(aRect.TopLeft(), aRect.GetSize(), sText);
+    InsertTextObject(aRect.TopLeft(), aRect.GetSize(), sText, bInvisible);
 }
 
 void ImpSdrPdfImport::InsertTextObject(const Point& rPos, const Size& 
/*rSize*/,
-                                       const OUString& rStr)
+                                       const OUString& rStr, bool bInvisible)
 {
     FontMetric aFontMetric(mpVD->GetFontMetric());
     vcl::Font aFont(mpVD->GetFont());
@@ -1807,6 +1811,9 @@ void ImpSdrPdfImport::InsertTextObject(const Point& rPos, 
const Size& /*rSize*/,
 
     pText->SetMergedItem(makeSdrTextAutoGrowHeightItem(false));
 
+    if (bInvisible)
+        pText->SetVisible(false);
+
     pText->SetLayer(mnLayer);
     pText->NbcSetText(rStr);
     SetAttributes(pText.get(), true);
commit de3ba5c2d82bdeebe81a3b6f44777fef04d0cdda
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Oct 1 12:00:14 2025 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Oct 15 15:27:36 2025 +0200

    support 8 bit grayscale pdf images too
    
    resolves mystery black rectangle in source pdf
    
    Change-Id: I9abd0c1698b54133cefc710a18197ace1ba6436a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191721
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    (cherry picked from commit cd9d62d3c90ef28112eca71c5d8c51c0adefc5d7)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192357
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf 
b/sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf
new file mode 100644
index 000000000000..acaf227710c0
Binary files /dev/null and 
b/sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf differ
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index c938c657f1ea..485e402157dc 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -1139,6 +1139,43 @@ CPPUNIT_TEST_FIXTURE(SdExportTest, testExplodedPdfHindi)
                          
"style:text-properties[@fo:font-family='AcademyEngravedLetPlain']");
 }
 
+CPPUNIT_TEST_FIXTURE(SdExportTest, 
testExplodedPdfGrayscaleImageUnderInvisibleTest)
+{
+    auto pPdfium = vcl::pdf::PDFiumLibrary::get();
+    if (!pPdfium)
+        return;
+    UsePdfium aGuard;
+
+    loadFromFile(u"pdf/GrayscaleImageUnderInvisibleTest.pdf");
+
+    
setFilterOptions("{\"DecomposePDF\":{\"type\":\"boolean\",\"value\":\"true\"}}");
+    setImportFilterName(u"OpenDocument Drawing Flat XML"_ustr);
+    saveAndReload(u"OpenDocument Drawing Flat XML"_ustr);
+
+    uno::Reference<drawing::XShapes> xGroupShape(getShapeFromPage(0, 0), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xGroupShape.is());
+
+    // first shape in the group is the picture
+    uno::Reference<beans::XPropertySet> xShape(xGroupShape->getByIndex(0), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xShape.is());
+
+    uno::Reference<graphic::XGraphic> xGraphic;
+    xShape->getPropertyValue(u"Graphic"_ustr) >>= xGraphic;
+    CPPUNIT_ASSERT(xGraphic.is());
+
+    Graphic aGraphic(xGraphic);
+    Bitmap aBitmap(aGraphic.GetBitmap());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(2582), aBitmap.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(3325), aBitmap.GetSizePixel().Height());
+
+    Color aExpectedColor(ColorAlphaTag::ColorAlpha, 0xFFFFFFFF);
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: rgba[ffffffff]
+    // - Actual  : rgba[000000ff]
+    CPPUNIT_ASSERT_EQUAL(aExpectedColor, aBitmap.GetPixelColor(5, 5));
+}
+
 CPPUNIT_TEST_FIXTURE(SdExportTest, testEmbeddedText)
 {
     createSdDrawDoc("objectwithtext.fodg");
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 69e196b2779f..b3eaf298b8a3 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1846,6 +1846,13 @@ void ImpSdrPdfImport::MapScaling()
     mnMapScalingOfs = nCount;
 }
 
+static Bitmap createBitmap(const Size& rSize, bool bGrayScale)
+{
+    if (bGrayScale)
+        return Bitmap(rSize, vcl::PixelFormat::N8_BPP, 
&Bitmap::GetGreyPalette(256));
+    return Bitmap(rSize, vcl::PixelFormat::N24_BPP);
+}
+
 void ImpSdrPdfImport::ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> 
const& pPageObject,
                                   int /*nPageObjectIndex*/)
 {
@@ -1867,10 +1874,13 @@ void 
ImpSdrPdfImport::ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> co
     const int nWidth = bitmap->getWidth();
     const int nHeight = bitmap->getHeight();
     const int nStride = bitmap->getStride();
-    Bitmap aBitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP);
+    Bitmap aBitmap(createBitmap(Size(nWidth, nHeight), format == 
vcl::pdf::PDFBitmapType::Gray));
 
     switch (format)
     {
+        case vcl::pdf::PDFBitmapType::Gray:
+            ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N8BitPal, nHeight, 
nStride);
+            break;
         case vcl::pdf::PDFBitmapType::BGR:
             ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N24BitTcBgr, nHeight, 
nStride);
             break;

Reply via email to