summaryrefslogtreecommitdiff
path: root/oox/source/vml
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-02-13 13:55:22 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-02-14 12:50:01 +0100
commitcfff893b9c82843a90aac4ecdb3a3936721b74a0 (patch)
tree2859340e329ea6dbffe5ae9c7eba0f67a88c57af /oox/source/vml
parent20305894243e24eb383ab9feefebf4a0e9f2644f (diff)
Move unit conversion code to o3tl, and unify on that in more places
This also allows to easily add more units, both of length and for other unit categories. The conversion for "Line" unit (312 twip) is questionable. Corresponding entries in aImplFactor in vcl/source/control/field.cxx were inconsistent (45/11 in; 10/13 pc; 156/10 pt). They were added without explanation in commit c85db626029fd8a5e0dfcb312937279df32339a0. I haven't found a spec of the unit (https://en.wikipedia.org/wiki/Line_(unit) is not specific). I used the definition based on "by pt", "by mm/100", "by char" (they all were consistent); "by pc" seems inverted; "by twip" was half as much. This accepted conversion makes unit test for tdf#79236 pass. Change-Id: Iae5a21d915fa8e934a1f47f8ba9f6df03b79a9fd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110839 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'oox/source/vml')
-rw-r--r--oox/source/vml/vmlformatting.cxx28
1 files changed, 14 insertions, 14 deletions
diff --git a/oox/source/vml/vmlformatting.cxx b/oox/source/vml/vmlformatting.cxx
index 60ef7f900d15..96d26efe8ff8 100644
--- a/oox/source/vml/vmlformatting.cxx
+++ b/oox/source/vml/vmlformatting.cxx
@@ -29,6 +29,7 @@
#include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp>
#include <com/sun/star/table/ShadowFormat.hpp>
#include <com/sun/star/text/XTextRange.hpp>
+#include <o3tl/unit_conversion.hxx>
#include <rtl/strbuf.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
@@ -174,21 +175,20 @@ sal_Int64 ConversionHelper::decodeMeasureToEmu( const GraphicHelper& rGraphicHel
{
sal_Unicode cChar1 = aUnit[ 0 ];
sal_Unicode cChar2 = aUnit[ 1 ];
- if( (cChar1 == 'i') && (cChar2 == 'n') ) // 1 inch = 914,400 EMU
- fValue *= 914400.0;
- else if( (cChar1 == 'c') && (cChar2 == 'm') ) // 1 cm = 360,000 EMU
- fValue *= 360000.0;
- else if( (cChar1 == 'm') && (cChar2 == 'm') ) // 1 mm = 36,000 EMU
- fValue *= 36000.0;
- else if( (cChar1 == 'p') && (cChar2 == 't') ) // 1 point = 1/72 inch = 12,700 EMU
- fValue *= 12700.0;
- else if( (cChar1 == 'p') && (cChar2 == 'c') ) // 1 pica = 1/6 inch = 152,400 EMU
- fValue *= 152400.0;
+ if ((cChar1 == 'i') && (cChar2 == 'n'))
+ fValue = o3tl::convert(fValue, o3tl::Length::in, o3tl::Length::emu);
+ else if ((cChar1 == 'c') && (cChar2 == 'm'))
+ fValue = o3tl::convert(fValue, o3tl::Length::cm, o3tl::Length::emu);
+ else if ((cChar1 == 'm') && (cChar2 == 'm'))
+ fValue = o3tl::convert(fValue, o3tl::Length::mm, o3tl::Length::emu);
+ else if ((cChar1 == 'p') && (cChar2 == 't'))
+ fValue = o3tl::convert(fValue, o3tl::Length::pt, o3tl::Length::emu);
+ else if ((cChar1 == 'p') && (cChar2 == 'c'))
+ fValue = o3tl::convert(fValue, o3tl::Length::pc, o3tl::Length::emu);
else if( (cChar1 == 'p') && (cChar2 == 'x') ) // 1 pixel, dependent on output device
- fValue = static_cast< double >( ::oox::drawingml::convertHmmToEmu(
- bPixelX ?
- rGraphicHelper.convertScreenPixelXToHmm( fValue ) :
- rGraphicHelper.convertScreenPixelYToHmm( fValue ) ) );
+ fValue = o3tl::convert(bPixelX ? rGraphicHelper.convertScreenPixelXToHmm(fValue)
+ : rGraphicHelper.convertScreenPixelYToHmm(fValue),
+ o3tl::Length::mm100, o3tl::Length::emu);
}
else if( (aUnit.getLength() == 1) && (aUnit[ 0 ] == '%') )
{