[Libreoffice-commits] core.git: drawinglayer/source include/vcl svx/source sw/qa sw/source vcl/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Jun 4 12:55:23 UTC 2021


 drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx |   16 ++++++--
 include/vcl/vectorgraphicdata.hxx                            |    3 +
 svx/source/svdraw/svdxcgv.cxx                                |   11 +++++
 sw/qa/extras/htmlexport/htmlexport.cxx                       |    9 ++++
 sw/source/filter/html/htmlflywriter.cxx                      |   22 +++++++++--
 vcl/source/gdi/vectorgraphicdata.cxx                         |    7 ++-
 6 files changed, 58 insertions(+), 10 deletions(-)

New commits:
commit 26d2b19d4e9388072b8dae574efdf00d7f7a0f2f
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jun 4 14:02:52 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jun 4 14:54:45 2021 +0200

    sw HTML export: fix pixel size of shapes
    
    - the twips logic size was set, but it was consumed as mm100 logic size,
      so the pixel size was about half of the correct one
    
    - the HTML export didn't write a logic size ("CSS pixels size") for
      shapes
    
    Change-Id: I37f6b4acde9d1298fae81f9975e9db95485631ee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116691
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx b/drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx
index 2f750e73af65..63b4ffd6986d 100644
--- a/drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx
+++ b/drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx
@@ -34,6 +34,7 @@
 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
 
 #include <drawinglayer/converters.hxx>
+#include <comphelper/sequenceashashmap.hxx>
 
 using namespace ::com::sun::star;
 
@@ -81,6 +82,16 @@ namespace drawinglayer::unorenderer
             const css::geometry::RealRectangle2D& Range,
             ::sal_uInt32 MaximumQuadraticPixels)
         {
+            o3tl::Length eRangeUnit = o3tl::Length::mm100;
+            comphelper::SequenceAsHashMap aViewInformationMap(aViewInformationSequence);
+            auto it = aViewInformationMap.find("RangeUnit");
+            if (it != aViewInformationMap.end())
+            {
+                sal_Int32 nVal{};
+                it->second >>= nVal;
+                eRangeUnit = static_cast<o3tl::Length>(nVal);
+            }
+
             uno::Reference< rendering::XBitmap > XBitmap;
 
             if(aPrimitive2DSequence.hasElements())
@@ -107,9 +118,8 @@ namespace drawinglayer::unorenderer
                     }
 
                     const geometry::ViewInformation2D aViewInformation2D(aViewInformationSequence);
-                    const double fFactor100th_mmToInch(1.0 / (2.54 * 1000.0));
-                    const sal_uInt32 nDiscreteWidth(basegfx::fround((fWidth * fFactor100th_mmToInch) * DPI_X));
-                    const sal_uInt32 nDiscreteHeight(basegfx::fround((fHeight * fFactor100th_mmToInch) * DPI_Y));
+                    const sal_uInt32 nDiscreteWidth(basegfx::fround(o3tl::convert(fWidth, eRangeUnit, o3tl::Length::in) * DPI_X));
+                    const sal_uInt32 nDiscreteHeight(basegfx::fround(o3tl::convert(fHeight, eRangeUnit, o3tl::Length::in) * DPI_Y));
 
                     basegfx::B2DHomMatrix aEmbedding(
                         basegfx::utils::createTranslateB2DHomMatrix(
diff --git a/include/vcl/vectorgraphicdata.hxx b/include/vcl/vectorgraphicdata.hxx
index 90b92411dfab..3057ea82b8b8 100644
--- a/include/vcl/vectorgraphicdata.hxx
+++ b/include/vcl/vectorgraphicdata.hxx
@@ -41,7 +41,8 @@ typedef css::uno::Sequence<sal_Int8> VectorGraphicDataArray;
 BitmapEx VCL_DLLPUBLIC convertPrimitive2DSequenceToBitmapEx(
     const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > >& rSequence,
     const basegfx::B2DRange& rTargetRange,
-    const sal_uInt32 nMaximumQuadraticPixels = 500000);
+    const sal_uInt32 nMaximumQuadraticPixels = 500000,
+    const o3tl::Length eTargetUnit = o3tl::Length::mm100);
 
 
 enum class VectorGraphicDataType
diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx
index 1cf15c720a31..7d52431cd2b7 100644
--- a/svx/source/svdraw/svdxcgv.cxx
+++ b/svx/source/svdraw/svdxcgv.cxx
@@ -490,11 +490,20 @@ BitmapEx SdrExchangeView::GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked) const
 
                 if(!aRange.isEmpty())
                 {
+                    o3tl::Length eRangeUnit = o3tl::Length::mm100;
+
+                    if (GetModel()->IsWriter())
+                    {
+                        eRangeUnit = o3tl::Length::twip;
+                    }
+
                     // if we have geometry and it has a range, convert to BitmapEx using
                     // common tooling
                     aBmp = convertPrimitive2DSequenceToBitmapEx(
                         xPrimitives,
-                        aRange);
+                        aRange,
+                        /*nMaximumQuadraticPixels=*/ 500000,
+                        eRangeUnit);
                 }
             }
         }
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index b97cf7968640..1f5182ac6e4c 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1723,6 +1723,15 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedShapeAsPNG)
     // - Actual  : image/x-vclgraphic
     // i.e. the result was invalid ReqIF.
     assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object", "type", "image/png");
+
+    // Then check the pixel size of the shape:
+    Size aPixelSize(Application::GetDefaultDevice()->LogicToPixel(Size(10000, 10000),
+                                                                  MapMode(MapUnit::Map100thMM)));
+    // Without the accompanying fix in place, this test would have failed with:
+    // - no attribute 'width' exist
+    // i.e. shapes had no width.
+    assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object", "width",
+                OUString::number(aPixelSize.getWidth()));
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index ed6d646594ee..8f6608097f07 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -933,12 +933,28 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma
 
     // "width" and/or "height"
     // Only output SwFrameSize::Variable/SwFrameSize::Minimum if ANYSIZE is set
+    const SwFormatFrameSize* pFSItem = nullptr;
+    std::optional<SwFormatFrameSize> aFrameSize;
+    if (SfxItemState::SET == rItemSet.GetItemState( RES_FRM_SIZE, true, &pItem ))
+    {
+        pFSItem = static_cast<const SwFormatFrameSize *>(pItem);
+    }
+    else if (const SdrObject* pObject = rFrameFormat.FindSdrObject())
+    {
+        // Write size for Draw shapes as well.
+        const tools::Rectangle& rSnapRect = pObject->GetSnapRect();
+        aFrameSize.emplace();
+        aFrameSize->SetWidthSizeType(SwFrameSize::Fixed);
+        aFrameSize->SetWidth(rSnapRect.getWidth());
+        aFrameSize->SetHeightSizeType(SwFrameSize::Fixed);
+        aFrameSize->SetHeight(rSnapRect.getHeight());
+        pFSItem = &*aFrameSize;
+    }
     if( (nFrameOptions & HtmlFrmOpts::Size) &&
-        SfxItemState::SET == rItemSet.GetItemState( RES_FRM_SIZE, true, &pItem ) &&
+        pFSItem &&
         ( (nFrameOptions & HtmlFrmOpts::AnySize) ||
-          SwFrameSize::Fixed == static_cast<const SwFormatFrameSize *>(pItem)->GetHeightSizeType()) )
+          SwFrameSize::Fixed == pFSItem->GetHeightSizeType()) )
     {
-        const SwFormatFrameSize *pFSItem = static_cast<const SwFormatFrameSize *>(pItem);
         sal_uInt8 nPercentWidth = pFSItem->GetWidthPercent();
         sal_uInt8 nPercentHeight = pFSItem->GetHeightPercent();
 
diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx
index 8430ebe2b289..b424d4dcd503 100644
--- a/vcl/source/gdi/vectorgraphicdata.cxx
+++ b/vcl/source/gdi/vectorgraphicdata.cxx
@@ -48,7 +48,8 @@ using namespace ::com::sun::star;
 BitmapEx convertPrimitive2DSequenceToBitmapEx(
     const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > >& rSequence,
     const basegfx::B2DRange& rTargetRange,
-    const sal_uInt32 nMaximumQuadraticPixels)
+    const sal_uInt32 nMaximumQuadraticPixels,
+    const o3tl::Length eTargetUnit)
 {
     BitmapEx aRetval;
 
@@ -61,7 +62,9 @@ BitmapEx convertPrimitive2DSequenceToBitmapEx(
             uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
             const uno::Reference< graphic::XPrimitive2DRenderer > xPrimitive2DRenderer = graphic::Primitive2DTools::create(xContext);
 
-            uno::Sequence< beans::PropertyValue > aViewParameters;
+            uno::Sequence< beans::PropertyValue > aViewParameters = {
+                comphelper::makePropertyValue("RangeUnit", static_cast<sal_Int32>(eTargetUnit)),
+            };
             geometry::RealRectangle2D aRealRect;
 
             aRealRect.X1 = rTargetRange.getMinX();


More information about the Libreoffice-commits mailing list