[Libreoffice-commits] core.git: sw/CppunitTest_sw_htmlimport.mk sw/qa sw/source

Katarina Behrens Katarina.Behrens at cib.de
Thu Apr 5 19:40:44 UTC 2018


 sw/CppunitTest_sw_htmlimport.mk                    |    2 +
 sw/qa/extras/htmlimport/data/image-width-auto.html |   40 +++++++++++++++++++++
 sw/qa/extras/htmlimport/htmlimport.cxx             |   16 ++++++++
 sw/source/filter/html/htmlgrin.cxx                 |   26 +++++++++++--
 4 files changed, 79 insertions(+), 5 deletions(-)

New commits:
commit a174caa53b4bee9627cd7403ef03c474b758c602
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Wed Apr 4 18:33:08 2018 +0200

    Html import: use loaded image width/height if width|height ="auto"
    
    "auto" means viewing application decides what the size/dimension
    is going to be i.e. act as if no particular size was provided
    
    Also use metric dimensions from bitmaps if available.
    
    Change-Id: Ic3860ecad0c4e1c2b7f6131c03c6612241a20c7c
    Reviewed-on: https://gerrit.libreoffice.org/52404
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/sw/CppunitTest_sw_htmlimport.mk b/sw/CppunitTest_sw_htmlimport.mk
index 0382c5844021..f1cf2fd24d67 100644
--- a/sw/CppunitTest_sw_htmlimport.mk
+++ b/sw/CppunitTest_sw_htmlimport.mk
@@ -19,9 +19,11 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_htmlimport, \
 	comphelper \
 	cppu \
 	cppuhelper \
+	editeng \
 	i18nlangtag \
 	sal \
 	sfx \
+	svl \
 	svt \
 	sw \
 	test \
diff --git a/sw/qa/extras/htmlimport/data/image-width-auto.html b/sw/qa/extras/htmlimport/data/image-width-auto.html
new file mode 100644
index 000000000000..878be07cee04
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/image-width-auto.html
@@ -0,0 +1,40 @@
+<html><meta http-equiv="content-type" content="text/html; charset=utf-8"><head></head>
+<body>
+ <p><img id="pasted_img_43b9f3043ba35043b46c043bddb043bf" src="data:image/png;base64,
+       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
+       SUVORK5CYII=
+" alt="" width="auto" height="auto"></p>
+</body></html>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 5a45e92d3698..fa06d7a1a64c 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -25,6 +25,10 @@
 #include <docsh.hxx>
 #include <editsh.hxx>
 #include <ndgrf.hxx>
+#include <ndtxt.hxx>
+#include <txatbase.hxx>
+#include <fmtflcnt.hxx>
+#include <fmtfsize.hxx>
 
 class HtmlImportTest : public SwModelTestBase
 {
@@ -208,6 +212,18 @@ DECLARE_HTMLIMPORT_TEST(testMetaIsoDates, "meta-ISO8601-dates.html")
     CPPUNIT_ASSERT_EQUAL(DateTime(Date(8, 5, 2017), tools::Time(12, 47, 0, 386000000)), aModified);
 }
 
+DECLARE_HTMLIMPORT_TEST(testImageWidthAuto, "image-width-auto.html")
+{
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwTextAttr const*const pAttr(pTextDoc->GetDocShell()->GetDoc()->GetEditShell()->
+        GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(0, RES_TXTATR_FLYCNT));
+    CPPUNIT_ASSERT(pAttr);
+    SwFrameFormat const*const pFmt(pAttr->GetFlyCnt().GetFrameFormat());
+    SwFormatFrameSize const& rSize(pFmt->GetFormatAttr(RES_FRM_SIZE));
+    CPPUNIT_ASSERT_EQUAL(Size(1835, 560), rSize.GetSize());
+}
+
 DECLARE_HTMLIMPORT_TEST(testChangedby, "meta-changedby.html")
 {
     SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index dfa5f63976a4..dfda37fd0dc3 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -317,6 +317,7 @@ void SwHTMLParser::InsertImage()
     bool bIsMap = false;
     bool bPrcWidth = false;
     bool bPrcHeight = false;
+    OUString sWidthAsString, sHeightAsString;
     SvxMacroItem aMacroItem(RES_FRMMACRO);
 
     ScriptType eDfltScriptType;
@@ -360,18 +361,23 @@ void SwHTMLParser::InsertImage()
             case HtmlOptionId::WIDTH:
                 // for now only store as pixel value!
                 nWidth = rOption.GetNumber();
-                bPrcWidth = (rOption.GetString().indexOf('%') != -1);
+                sWidthAsString = rOption.GetString();
+                bPrcWidth = (sWidthAsString.indexOf('%') != -1);
                 if( bPrcWidth && nWidth>100 )
                     nWidth = 100;
-                bWidthProvided = true;
+                // width|height = "auto" means viewing app decides the size
+                // i.e. proceed as if no particular size was provided
+                bWidthProvided = (sWidthAsString != "auto");
                 break;
             case HtmlOptionId::HEIGHT:
                 // for now only store as pixel value!
                 nHeight = rOption.GetNumber();
-                bPrcHeight = (rOption.GetString().indexOf('%') != -1);
+                sHeightAsString = rOption.GetString();
+                bPrcHeight = (sHeightAsString.indexOf('%') != -1);
                 if( bPrcHeight && nHeight>100 )
                     nHeight = 100;
-                bHeightProvided = true;
+                // the same as above w/ HtmlOptionId::WIDTH
+                bHeightProvided = (sHeightAsString != "auto");
                 break;
             case HtmlOptionId::VSPACE:
                 nVSpace = rOption.GetNumber();
@@ -561,8 +567,18 @@ IMAGE_SETEVENT:
     Size aTwipSz( bPrcWidth ? 0 : nWidth, bPrcHeight ? 0 : nHeight );
     if( (aTwipSz.Width() || aTwipSz.Height()) && Application::GetDefaultDevice() )
     {
-        aTwipSz = Application::GetDefaultDevice()
+        if (bWidthProvided || bHeightProvided || // attributes imply pixel!
+            aGraphic.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel)
+        {
+            aTwipSz = Application::GetDefaultDevice()
                     ->PixelToLogic( aTwipSz, MapMode( MapUnit::MapTwip ) );
+        }
+        else
+        {   // some bitmaps may have a size in metric units (e.g. PNG); use that
+            assert(aGraphic.GetPrefMapMode().GetMapUnit() < MapUnit::MapPixel);
+            aTwipSz = OutputDevice::LogicToLogic(aGraphic.GetPrefSize(),
+                    aGraphic.GetPrefMapMode(), MapMode(MapUnit::MapTwip));
+        }
     }
 
     // convert CSS1 size to "normal" size


More information about the Libreoffice-commits mailing list