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

Miklos Vajna vmiklos at collabora.co.uk
Wed Apr 18 09:45:32 UTC 2018


 sw/qa/extras/htmlimport/data/image-size.html |   25 +++++++++++++++++++++++++
 sw/qa/extras/htmlimport/data/libreoffice.jpg |binary
 sw/qa/extras/htmlimport/htmlimport.cxx       |   13 +++++++++++++
 sw/source/filter/html/htmlgrin.cxx           |   14 ++++++++++++++
 4 files changed, 52 insertions(+)

New commits:
commit 84854917835b13851d4855fa5eb30036a38b9166
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Apr 18 09:46:34 2018 +0200

    sw HTML import: use GraphicDescriptor to determine default size
    
    Rather than the hardcoded HTML_DFLT_IMG_WIDTH / HTML_DFLT_IMG_HEIGHT
    defines.
    
    Change-Id: I4ed2207ce3fdcd247054941d91eb67a679fb370c
    Reviewed-on: https://gerrit.libreoffice.org/53081
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sw/qa/extras/htmlimport/data/image-size.html b/sw/qa/extras/htmlimport/data/image-size.html
new file mode 100644
index 000000000000..a26c606100cf
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/image-size.html
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+	<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+	<title></title>
+	<style type="text/css">
+		@page { size: 21.59cm 27.94cm; margin: 2cm }
+		p { margin-bottom: 0.25cm; line-height: 115%; background: transparent }
+	</style>
+</head>
+<body lang="en-US" link="#000080" vlink="#800000" dir="ltr"><p style="margin-bottom: 0cm; line-height: 100%">
+<br/>
+
+</p>
+<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
+<br/>
+
+</p>
+<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
+<img src="libreoffice.jpg" name="Image1" align="left" border="0"/>
+<br/>
+
+</p>
+</body>
+</html>
diff --git a/sw/qa/extras/htmlimport/data/libreoffice.jpg b/sw/qa/extras/htmlimport/data/libreoffice.jpg
new file mode 100644
index 000000000000..14af080b147f
Binary files /dev/null and b/sw/qa/extras/htmlimport/data/libreoffice.jpg differ
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index fa06d7a1a64c..5829cdcd4d31 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -313,6 +313,19 @@ DECLARE_HTMLIMPORT_TEST(testReqIfBr, "reqif-br.xhtml")
     CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("aaa\nbbb"));
 }
 
+DECLARE_HTMLIMPORT_TEST(testImageSize, "image-size.html")
+{
+    awt::Size aSize = getShape(1)->getSize();
+    OutputDevice* pDevice = Application::GetDefaultDevice();
+    Size aPixelSize(200, 400);
+    Size aExpected = pDevice->PixelToLogic(aPixelSize, MapMode(MapUnit::Map100thMM));
+
+    // This was 1997, i.e. a hardcoded default, we did not look at the image
+    // header when the HTML markup declared no size.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aExpected.getWidth()), aSize.Width);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aExpected.getHeight()), aSize.Height);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index dfda37fd0dc3..869d92c3c435 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -620,6 +620,20 @@ IMAGE_SETEVENT:
     bool bSetScaleImageMap = false;
     sal_uInt8 nPrcWidth = 0, nPrcHeight = 0;
 
+    if (!nWidth || !nHeight)
+    {
+        GraphicDescriptor aDescriptor(aGraphicURL);
+        if (aDescriptor.Detect(/*bExtendedInfo=*/true))
+        {
+            // Try to use size info from the image header before defaulting to
+            // HTML_DFLT_IMG_WIDTH/HEIGHT.
+            aTwipSz = Application::GetDefaultDevice()->PixelToLogic(aDescriptor.GetSizePixel(),
+                                                                    MapMode(MapUnit::MapTwip));
+            nWidth = aTwipSz.getWidth();
+            nHeight = aTwipSz.getHeight();
+        }
+    }
+
     if( !nWidth || !nHeight )
     {
         // When the graphic is in a table, it will be requested immediately,


More information about the Libreoffice-commits mailing list