diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-04-18 09:46:34 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-06-08 22:25:21 +0200 |
commit | 195c70008f6fc9c9b4ac0568b04e3eaf3a034181 (patch) | |
tree | b185aba360ae8f9736dbc76bfbbd36e04be362e5 | |
parent | a1be462f92b41a560fce61e160d42801f847e6c1 (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>
Conflicts:
sw/qa/extras/htmlimport/htmlimport.cxx
-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 4f8ec0e227b0..4303a31c0d29 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -126,6 +126,19 @@ DECLARE_HTMLIMPORT_TEST(testInlinedImagesPageAndParagraph, "PageAndParagraphFill } } +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(MAP_100TH_MM)); + + // 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 c83eafe5d36c..30a6fb8dc082 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -595,6 +595,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 ) { // Es fehlt die Breite oder die Hoehe |