From 9d161857f1d4afcb772b477455797a2da0e47a9b Mon Sep 17 00:00:00 2001 From: "Armin Le Grand (Allotropia)" Date: Tue, 16 Feb 2021 18:20:32 +0100 Subject: tdf#127471 correct EMF/WMF im/export for scaled font If FontScaling is used, system-dependent data is held at vcl::Font Width(). Already if not scaled, we have three definitions: Width is zero, Width is equal to Height (unx) or - on Windows - Width equals avgFontWidth. If used it is W!=H where on unx Width equals Height multiplied with the scale factor. On Windows, this is Width multiplied with the only there existing avgFontWidth. Unfortunately that is ex/imported (since ever) undetected to EMF/WMF thus making EMF/WMF files containing FontScaling system-dependent - on which system was LO running when creating the file? The error can be seen when loading such a EMF/WMF on the vice-versa system, the FontScale is very ugly and wrong. Since EMF/WMF *are* Windows-specific formats the Windows-like definition is the correct one. This change makes all other systems export that now, and adapt on import to their system- specific definition (assuming coming from Windows). As can be seen, the difficulty is that these adaptions are necessary on non-Windows plattforms, but these do not have that avgFontWidth available. Thus I made a deep-dive investigation and multiple experiments to create a as similar as possible value to apply the needed calculations. For details and discussion refer to the bug description. Change-Id: I983fb6d882e2e8fccf9c8460f01509201d8157f9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111000 Tested-by: Jenkins Reviewed-by: Armin Le Grand --- vcl/inc/impfont.hxx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'vcl/inc') diff --git a/vcl/inc/impfont.hxx b/vcl/inc/impfont.hxx index ba1ea3683926..14a2189d3921 100644 --- a/vcl/inc/impfont.hxx +++ b/vcl/inc/impfont.hxx @@ -62,7 +62,18 @@ public: void SetWidthType( const FontWidth eWidthType ) { meWidthType = eWidthType; } void SetAlignment( const TextAlign eAlignment ) { meAlign = eAlignment; } void SetCharSet( const rtl_TextEncoding eCharSet ) { meCharSet = eCharSet; } - void SetFontSize( const Size& rSize ) { maAverageFontSize = rSize; } + void SetFontSize( const Size& rSize ) + { +#ifndef _WIN32 + if(rSize.Height() != maAverageFontSize.Height()) + { + // reset evtl. buffered calculated AverageFontSize, it depends + // on Font::Height + mnCalculatedAverageFontWidth = 0; + } +#endif + maAverageFontSize = rSize; + } void SetSymbolFlag( const bool bSymbolFlag ) { mbSymbolFlag = bSymbolFlag; } @@ -80,6 +91,11 @@ public: void IncreaseQualityBy( int nQualityAmount ) { mnQuality += nQualityAmount; } void DecreaseQualityBy( int nQualityAmount ) { mnQuality -= nQualityAmount; } +#ifndef _WIN32 + tools::Long GetCalculatedAverageFontWidth() const { return mnCalculatedAverageFontWidth; } + void SetCalculatedAverageFontWidth(tools::Long nNew) { mnCalculatedAverageFontWidth = nNew; } +#endif + bool operator==( const ImplFont& ) const; private: @@ -130,6 +146,9 @@ private: int mnQuality; +#ifndef _WIN32 + tools::Long mnCalculatedAverageFontWidth; +#endif }; #endif // INCLUDED_VCL_INC_IMPFONT_HXX -- cgit