summaryrefslogtreecommitdiff
path: root/sw/source/filter/html/htmlplug.cxx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-09-06 16:14:47 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-09-06 17:19:23 +0200
commit456abae730a787693c3ad98f7e57eba5f6163a76 (patch)
treeda49445fd858e4329821cd47e5b591d38126ae0b /sw/source/filter/html/htmlplug.cxx
parent1fb2b68d89d80ccc1b546685ea26a72796060f0b (diff)
sw HTML import: fix height of OLE objs when it is missing and width is relative
In case an OLE object's fallback bitmap had a width=100% size but no explicit height, we used to set the OLE object's size to a fixed value, based on the bitmap's pixel size. Falling back to the pixel size based on the current DPI is sensible if there is no height specified, but browsers keep the aspect ratio when only width or height is specified and we didn't. Fix the problem by explicitly checking for the "one axis has percent size, the other is unset" scenario in SwHTMLParser::InsertEmbed() and then handling the new SwFormatFrameSize::SYNCED value in SwHTMLParser::SetFixSize(). Note that SetFixSize() is not used for bitmaps (only for OLE objects), so that codepath may still need a similar fix. Change-Id: I9f70307edbfbb06e228494fb5c04e7381ed8e5cc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139526 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source/filter/html/htmlplug.cxx')
-rw-r--r--sw/source/filter/html/htmlplug.cxx18
1 files changed, 16 insertions, 2 deletions
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 83b8e8d16e0f..04b5f8e90cc7 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -192,7 +192,7 @@ void SwHTMLParser::SetFixSize( const Size& rPixSize,
else if( bPercentWidth && rPixSize.Width() )
{
nPercentWidth = static_cast<sal_uInt8>(rPixSize.Width());
- if( nPercentWidth > 100 )
+ if (nPercentWidth > 100 && nPercentWidth != SwFormatFrameSize::SYNCED)
nPercentWidth = 100;
aTwipSz.setWidth( rTwipDfltSize.Width() );
@@ -219,7 +219,7 @@ void SwHTMLParser::SetFixSize( const Size& rPixSize,
else if( bPercentHeight && rPixSize.Height() )
{
nPercentHeight = static_cast<sal_uInt8>(rPixSize.Height());
- if( nPercentHeight > 100 )
+ if (nPercentHeight > 100 && nPercentHeight != SwFormatFrameSize::SYNCED)
nPercentHeight = 100;
aTwipSz.setHeight( rTwipDfltSize.Height() );
@@ -524,6 +524,20 @@ bool SwHTMLParser::InsertEmbed()
aAttrSet.ClearItem(RES_CNTNT);
OutputDevice* pDevice = Application::GetDefaultDevice();
Size aDefaultTwipSize(pDevice->PixelToLogic(aGraphic.GetSizePixel(pDevice), MapMode(MapUnit::MapTwip)));
+
+ if (aSize.Width() == USHRT_MAX && bPercentHeight)
+ {
+ // Height is relative, width is not set: keep aspect ratio.
+ aSize.setWidth(SwFormatFrameSize::SYNCED);
+ bPercentWidth = true;
+ }
+ if (aSize.Height() == USHRT_MAX && bPercentWidth)
+ {
+ // Width is relative, height is not set: keep aspect ratio.
+ aSize.setHeight(SwFormatFrameSize::SYNCED);
+ bPercentHeight = true;
+ }
+
SetFixSize(aSize, aDefaultTwipSize, bPercentWidth, bPercentHeight, aPropInfo, aAttrSet);
pOLENode->GetDoc().SetFlyFrameAttr(*pFormat, aAttrSet);
return true;