diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-04-18 09:46:34 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-04-18 11:44:12 +0200 |
commit | 84854917835b13851d4855fa5eb30036a38b9166 (patch) | |
tree | 2964c7fa5728974a6fef2169c135c4d58727e266 /sw | |
parent | ab8bf5533f8de9bb1aa9dc83e650e4eccf0fcac3 (diff) |
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@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/htmlimport/data/image-size.html | 25 | ||||
-rw-r--r-- | sw/qa/extras/htmlimport/data/libreoffice.jpg | bin | 0 -> 6065 bytes | |||
-rw-r--r-- | sw/qa/extras/htmlimport/htmlimport.cxx | 13 | ||||
-rw-r--r-- | sw/source/filter/html/htmlgrin.cxx | 14 |
4 files changed, 52 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 000000000000..14af080b147f --- /dev/null +++ b/sw/qa/extras/htmlimport/data/libreoffice.jpg 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, |