emfio/qa/cppunit/wmf/data/EOF.wmf      |binary
 emfio/qa/cppunit/wmf/wmfimporttest.cxx |   27 +++++++++++++++++++++++++++
 emfio/source/reader/wmfreader.cxx      |   24 ++++++++++++------------
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |    8 ++++----
 vcl/skia/salbmp.cxx                    |    1 +
 vcl/source/bitmap/alpha.cxx            |    7 ++++++-
 6 files changed, 50 insertions(+), 17 deletions(-)

New commits:
commit c75cac85230d3899fe9f5f5086c117e4e1e5d330
Author:     Bartosz Kosiorek <gan...@poczta.onet.pl>
AuthorDate: Sat Jun 17 02:57:42 2023 +0200
Commit:     Bartosz Kosiorek <gan...@poczta.onet.pl>
CommitDate: Sun Oct 29 11:18:33 2023 +0100

    tdf#155887 WMF Fix displaying images with size of EOF other that 3
    
    The size of W_META_EOF (record indicates the end of the WMF metafile)
    could be different than 3 (e.g. 6).
    The MS Office is allowing different sizes of EOF,
    and just properly finalizine parsing WMF file, and display its content.
    
    Original bug report:
    https://bz.apache.org/ooo/show_bug.cgi?id=42090
    
    Change-Id: I21b72615c7f45fdca145e6240c6451d7d264d238
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153204
    Tested-by: Jenkins
    Reviewed-by: Bartosz Kosiorek <gan...@poczta.onet.pl>

diff --git a/emfio/qa/cppunit/wmf/data/EOF.wmf 
b/emfio/qa/cppunit/wmf/data/EOF.wmf
new file mode 100644
index 000000000000..5e6af7850546
Binary files /dev/null and b/emfio/qa/cppunit/wmf/data/EOF.wmf differ
diff --git a/emfio/qa/cppunit/wmf/wmfimporttest.cxx 
b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
index a42e7f0dd7c3..84154f47d046 100644
--- a/emfio/qa/cppunit/wmf/wmfimporttest.cxx
+++ b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
@@ -45,6 +45,7 @@ public:
     {
     }
 
+    void testEOFWmf();
     void testNonPlaceableWmf();
     void testTdf88163NonPlaceableWmf();
     void testTdf88163PlaceableWmf();
@@ -63,6 +64,7 @@ public:
     void testStockObject();
 
     CPPUNIT_TEST_SUITE(WmfTest);
+    CPPUNIT_TEST(testEOFWmf);
     CPPUNIT_TEST(testNonPlaceableWmf);
     CPPUNIT_TEST(testTdf88163NonPlaceableWmf);
     CPPUNIT_TEST(testTdf88163PlaceableWmf);
@@ -82,6 +84,31 @@ public:
     CPPUNIT_TEST_SUITE_END();
 };
 
+void WmfTest::testEOFWmf()
+{
+    // tdf#155887 Test META_EOF with size different than 3
+    // It should be properly displayed as MS Office do
+    SvFileStream aFileStream(getFullUrl(u"EOF.wmf"), StreamMode::READ);
+    GDIMetaFile aGDIMetaFile;
+    ReadWindowMetafile(aFileStream, aGDIMetaFile);
+
+    MetafileXmlDump dumper;
+    xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
+
+    CPPUNIT_ASSERT(pDoc);
+    assertXPath(pDoc, "/metafile/push", 2);
+    assertXPath(pDoc, "/metafile/push[2]", "flags", "PushClipRegion");
+    assertXPath(pDoc, "/metafile/push[2]/fillcolor", 2);
+    assertXPath(pDoc, "/metafile/push[2]/fillcolor[1]", "color", "#000000");
+    assertXPath(pDoc, "/metafile/push[2]/fillcolor[2]", "color", "#d0d0d0");
+    assertXPath(pDoc, "/metafile/push[2]/linecolor", 60);
+    assertXPath(pDoc, "/metafile/push[2]/polyline", 209);
+    assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point", 5);
+    assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point[3]", "x", "16906");
+    assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point[3]", "y", "12673");
+    assertXPath(pDoc, "/metafile/push[2]/textarray", 307);
+}
+
 void WmfTest::testNonPlaceableWmf()
 {
     SvFileStream aFileStream(getFullUrl(u"visio_import_source.wmf"), 
StreamMode::READ);
diff --git a/emfio/source/reader/wmfreader.cxx 
b/emfio/source/reader/wmfreader.cxx
index fd954e960c49..b419fb3e5745 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -156,6 +156,7 @@ namespace
     #else
         switch( nRecType )
         {
+        case W_META_EOF: return "W_META_EOF";
         case W_META_SETBKCOLOR: return "META_SETBKCOLOR";
         case W_META_SETBKMODE: return "META_SETBKMODE";
         case W_META_SETMAPMODE: return "META_SETMAPMODE";
@@ -1523,10 +1524,10 @@ namespace emfio
                     // changing mnUnitsPerInch as a tool to scale wmf
                     mnUnitsPerInch *= fRatio;
 
-                    SAL_INFO("emfio", "Placeable bounds "
-                        " left: " << aPlaceableBound.Left() << " top: " << 
aPlaceableBound.Top()
-                        << " right: " << aPlaceableBound.Right() << " bottom: 
" << aPlaceableBound.Bottom());
                 }
+                SAL_INFO("emfio", "Placeable bounds "
+                                  " left: " << aPlaceableBound.Left() << " 
top: " << aPlaceableBound.Top() <<
+                                  " right: " << aPlaceableBound.Right() << " 
bottom: " << aPlaceableBound.Bottom());
             }
 
             mpInputStream->Seek( nStrmPos );
@@ -1606,14 +1607,10 @@ namespace emfio
                 {
                     mpInputStream->ReadUInt32(mnRecSize).ReadUInt16( nFunction 
);
 
-                    if (
-                         !mpInputStream->good() ||
-                         (mnRecSize < 3) ||
-                         (mnRecSize == 3 && nFunction == W_META_EOF)
-                       )
+                    if (!mpInputStream->good() || (mnRecSize < 3) || 
(nFunction == W_META_EOF))
                     {
-                        if( mpInputStream->eof() )
-                            mpInputStream->SetError( SVSTREAM_FILEFORMAT_ERROR 
);
+                        if (mpInputStream->eof())
+                            mpInputStream->SetError(SVSTREAM_FILEFORMAT_ERROR);
 
                         break;
                     }
@@ -1727,10 +1724,11 @@ namespace emfio
                     bRet = false;
                     break;
                 }
-                else if ( nRSize == 3 && nFunction == W_META_EOF )
+                else if (nFunction == W_META_EOF)
                 {
                     break;
                 }
+
                 switch( nFunction )
                 {
                     case W_META_EOF:
@@ -2043,9 +2041,11 @@ namespace emfio
             pStm->SetError( SVSTREAM_GENERALERROR );
             bRet = false;
         }
-
         if (!bRet)
+        {
+            SAL_WARN("emfio", "Unable to calculate Placeable Bounds");
             return;
+        }
 
         if (aWinExt)
         {
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 10881186be42..89e2f4990973 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -5949,14 +5949,14 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf145873)
     CPPUNIT_ASSERT_MESSAGE("no object", pObject != nullptr);
 
     // tdf#145873: Without the fix #2 in place, this test would have failed 
with
-    // - Expected: 13.23
+    // - Expected: 13.40
     // - Actual  : 3.57...
     // - Delta   : 0.1
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(13.23, pObject->getBounds().getWidth(), 0.1);
-    // - Expected: 13.49
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(13.40, pObject->getBounds().getWidth(), 0.1);
+    // - Expected: 13.79
     // - Actual  : 3.74...
     // - Delta   : 0.1
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(13.49, pObject->getBounds().getHeight(), 0.1);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(13.79, pObject->getBounds().getHeight(), 0.1);
 }
 
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageHyperlink)
commit c4699cef5c26d726273cf2305bed235edcf49ad7
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sun Oct 29 09:21:04 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Oct 29 11:18:22 2023 +0100

    simplify calculation in AlphaMask::BlendWith
    
    spotted by mkaganski
    
    Change-Id: If009be48a10ee5c7066a19b969212d10b9f6a83c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158607
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 13cf8aa5a4b9..ea5430abdf53 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -628,6 +628,7 @@ bool SkiaSalBitmap::AlphaBlendWith(const SalBitmap& rSalBmp)
     {
         const sal_uInt16 nGrey1 = mEraseColor.GetRed();
         const sal_uInt16 nGrey2 = otherBitmap->mEraseColor.GetRed();
+        // See comment in AlphaMask::BlendWith for how this calculation was 
derived
         const sal_uInt8 nGrey = static_cast<sal_uInt8>(nGrey1 * nGrey2 / 255);
         mEraseColor = Color(nGrey, nGrey, nGrey);
         DataChanged();
diff --git a/vcl/source/bitmap/alpha.cxx b/vcl/source/bitmap/alpha.cxx
index 005edbea20de..b250f4170a74 100644
--- a/vcl/source/bitmap/alpha.cxx
+++ b/vcl/source/bitmap/alpha.cxx
@@ -132,7 +132,12 @@ void AlphaMask::BlendWith(const AlphaMask& rOther)
             // Awkward calculation because the original used transparency, and 
to replicate
             // the logic we need to translate into transparency, perform the 
original logic,
             // then translate back to alpha.
-            auto tmp = 255 - ((255 - nGrey1) + (255 - nGrey2) - (255 - nGrey1) 
* (255 - nGrey2) / 255);
+            // The original looked like:
+            //   auto tmp = nGrey1 + nGrey2 - (nGrey1 * nGrey2 / 255)
+            // which, when converted to using alpha looks like
+            //   auto tmp = 255 - ((255 - nGrey1) + (255 - nGrey2) - (255 - 
nGrey1) * (255 - nGrey2) / 255);
+            // which then simplifies to:
+            auto tmp = nGrey1 * nGrey2 / 255;
             *scanline = static_cast<sal_uInt8>(tmp);
             ++scanline;
             ++otherScanline;

Reply via email to