diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-21 15:21:10 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-21 17:13:30 +0100 |
commit | f19599c929ac6ae2708b19b9eff62ff70b44ee75 (patch) | |
tree | 6ed489ee28db5b89c6f26ddc068197bf0fd94b6d /emfio | |
parent | e519d7465f38367205b37bc80f0244029e352306 (diff) |
loplugin:flatten in editeng..extensions
Change-Id: Ica8f0a6e3d30dba3b5a083e3c04522073de8303f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127233
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'emfio')
-rw-r--r-- | emfio/source/reader/mtftools.cxx | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx index 8e38e4e5b286..e12c98c66372 100644 --- a/emfio/source/reader/mtftools.cxx +++ b/emfio/source/reader/mtftools.cxx @@ -388,61 +388,61 @@ namespace emfio nMeasuredTextLength = nImportedTextLength; // compare expected and imported TextLengths - if (nImportedTextLength != nMeasuredTextLength) - { - const double fFactorText(static_cast<double>(nImportedTextLength) / static_cast<double>(nMeasuredTextLength)); - const double fFactorTextPercent(fabs(1.0 - fFactorText) * 100.0); + if (nImportedTextLength == nMeasuredTextLength) + return; - // if we assume that loaded file was written on old linux, we have to - // back-convert the scale value depending on which system we run + const double fFactorText(static_cast<double>(nImportedTextLength) / static_cast<double>(nMeasuredTextLength)); + const double fFactorTextPercent(fabs(1.0 - fFactorText) * 100.0); + + // if we assume that loaded file was written on old linux, we have to + // back-convert the scale value depending on which system we run #ifdef _WIN32 - // When running on Windows the value was not adapted at font import (see WinMtfFontStyle - // constructor), so it is still NormedFontScaling and we need to convert to Windows-style - // scaling + // When running on Windows the value was not adapted at font import (see WinMtfFontStyle + // constructor), so it is still NormedFontScaling and we need to convert to Windows-style + // scaling #else - // When running on unx (non-Windows) the value was already adapted at font import (see WinMtfFontStyle - // constructor). It was wrongly assumed to be Windows-style FontScaling, so we need to revert that - // to get back to the needed unx-style FontScale + // When running on unx (non-Windows) the value was already adapted at font import (see WinMtfFontStyle + // constructor). It was wrongly assumed to be Windows-style FontScaling, so we need to revert that + // to get back to the needed unx-style FontScale #endif - // Interestingly this leads to the *same* correction, so no need to make this - // system-dependent (!) - const tools::Long nUnscaledAverageFontWidth(rFontCandidate.GetOrCalculateAverageFontWidth()); - const tools::Long nScaledAverageFontWidth(rFontCandidate.GetAverageFontWidth()); - const double fScaleFactor(static_cast<double>(nUnscaledAverageFontWidth) / static_cast<double>(rFontCandidate.GetFontHeight())); - const double fCorrectedAverageFontWidth(static_cast<double>(nScaledAverageFontWidth) * fScaleFactor); - tools::Long nCorrectedTextLength(0); - - { // do in own scope, only need nUnscaledAverageFontWidth - vcl::Font rFontCandidate2(rFontCandidate); - rFontCandidate2.SetAverageFontWidth(static_cast<tools::Long>(fCorrectedAverageFontWidth)); - pTempVirtualDevice->SetFont(rFontCandidate2); - nCorrectedTextLength = pTempVirtualDevice->GetTextWidth(rText); - // on failure, use original length - if (!nCorrectedTextLength) - nCorrectedTextLength = nImportedTextLength; - } - - const double fFactorCorrectedText(static_cast<double>(nImportedTextLength) / static_cast<double>(nCorrectedTextLength)); - const double fFactorCorrectedTextPercent(fabs(1.0 - fFactorCorrectedText) * 100.0); - - // If FactorCorrectedText fits better than FactorText this is probably - // an import of an old EMF/WMF written by LibreOffice on a non-Windows (unx) system - // and should be corrected. - // Usually in tested cases this lies inside 5% of range, so detecting this just using - // fFactorTextPercent inside 5% -> no old file - // fFactorCorrectedTextPercent inside 5% -> is old file - // works not too bad, but there are some strange not so often used fonts where that - // values do deviate, so better just compare if old corrected would fit better than - // the uncorrected case, that is usually safe. - if(fFactorCorrectedTextPercent < fFactorTextPercent) - { - maAlternativeFontScales.push_back(fCorrectedAverageFontWidth); - } - else - { - // also push, but negative to remember non-fitting case - maAlternativeFontScales.push_back(-fCorrectedAverageFontWidth); - } + // Interestingly this leads to the *same* correction, so no need to make this + // system-dependent (!) + const tools::Long nUnscaledAverageFontWidth(rFontCandidate.GetOrCalculateAverageFontWidth()); + const tools::Long nScaledAverageFontWidth(rFontCandidate.GetAverageFontWidth()); + const double fScaleFactor(static_cast<double>(nUnscaledAverageFontWidth) / static_cast<double>(rFontCandidate.GetFontHeight())); + const double fCorrectedAverageFontWidth(static_cast<double>(nScaledAverageFontWidth) * fScaleFactor); + tools::Long nCorrectedTextLength(0); + + { // do in own scope, only need nUnscaledAverageFontWidth + vcl::Font rFontCandidate2(rFontCandidate); + rFontCandidate2.SetAverageFontWidth(static_cast<tools::Long>(fCorrectedAverageFontWidth)); + pTempVirtualDevice->SetFont(rFontCandidate2); + nCorrectedTextLength = pTempVirtualDevice->GetTextWidth(rText); + // on failure, use original length + if (!nCorrectedTextLength) + nCorrectedTextLength = nImportedTextLength; + } + + const double fFactorCorrectedText(static_cast<double>(nImportedTextLength) / static_cast<double>(nCorrectedTextLength)); + const double fFactorCorrectedTextPercent(fabs(1.0 - fFactorCorrectedText) * 100.0); + + // If FactorCorrectedText fits better than FactorText this is probably + // an import of an old EMF/WMF written by LibreOffice on a non-Windows (unx) system + // and should be corrected. + // Usually in tested cases this lies inside 5% of range, so detecting this just using + // fFactorTextPercent inside 5% -> no old file + // fFactorCorrectedTextPercent inside 5% -> is old file + // works not too bad, but there are some strange not so often used fonts where that + // values do deviate, so better just compare if old corrected would fit better than + // the uncorrected case, that is usually safe. + if(fFactorCorrectedTextPercent < fFactorTextPercent) + { + maAlternativeFontScales.push_back(fCorrectedAverageFontWidth); + } + else + { + // also push, but negative to remember non-fitting case + maAlternativeFontScales.push_back(-fCorrectedAverageFontWidth); } } |