summaryrefslogtreecommitdiff
path: root/emfio
diff options
context:
space:
mode:
authorArmin Le Grand (Allotropia) <armin.le.grand@me.com>2021-02-16 18:20:32 +0100
committerArmin Le Grand <Armin.Le.Grand@me.com>2021-03-10 09:41:39 +0100
commit125efab4d8573fda1882a542f6fb669c7fc12b56 (patch)
tree8659bc4e9f637e269986c5e2b6f96c1e9d9146fe /emfio
parentc4dddad19640dfefde52d04c3a7cf7064afe05b5 (diff)
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 <Armin.Le.Grand@me.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112089
Diffstat (limited to 'emfio')
-rw-r--r--emfio/source/reader/mtftools.cxx20
1 files changed, 19 insertions, 1 deletions
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 778adeb429ba..7a462cc659dd 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -277,8 +277,26 @@ namespace emfio
// Convert height to positive
aFontSize.setHeight( std::abs(aFontSize.Height()) );
-
aFont.SetFontSize(aFontSize);
+
+ // tdf#127471 adapt nFontWidth from Windows-like notation to
+ // NormedFontScaling if used for text scaling
+#ifndef _WIN32
+ const bool bFontScaledHorizontally(aFontSize.Width() != 0 && aFontSize.Width() != aFontSize.Height());
+
+ if(bFontScaledHorizontally)
+ {
+ // tdf#127471 nFontWidth is the Windows FontScaling, need to convert to
+ // Non-Windowslike notation relative to FontHeight.
+ const tools::Long nAverageFontWidth(aFont.GetOrCalculateAverageFontWidth());
+
+ if(nAverageFontWidth > 0)
+ {
+ const double fScaleFactor(static_cast<double>(aFontSize.Height()) / static_cast<double>(nAverageFontWidth));
+ aFont.SetAverageFontWidth(static_cast<tools::Long>(static_cast<double>(aFontSize.Width()) * fScaleFactor));
+ }
+ }
+#endif
};
Color MtfTools::ReadColor()