diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-04-20 18:36:16 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-04-20 20:54:28 +0200 |
commit | 62a0b2405798a3be6a4e38652f1da7a685c84bfc (patch) | |
tree | 2250fb2a7976b9ca3e82b5cd6a900fa8212a2900 /sax | |
parent | fdo#48969: switch units in Converter::convertDouble (diff) | |
download | core-62a0b2405798a3be6a4e38652f1da7a685c84bfc.tar.gz core-62a0b2405798a3be6a4e38652f1da7a685c84bfc.zip |
fdo#48969: GetConversionFactor: add inch as source unit
Also, add whole bunch of missing cases while at it.
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/tools/converter.cxx | 152 |
1 files changed, 142 insertions, 10 deletions
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index 4fe6d7fbd35d..e8fe38e50143 100644 --- a/sax/source/tools/converter.cxx +++ b/sax/source/tools/converter.cxx @@ -1788,9 +1788,16 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS switch(nTargetUnit) { case MeasureUnit::MM_100TH: + { + // 0.01mm = 0.57twip (exactly) + fRetval = ((25400.0 / 1440.0) / 10.0); + break; + } case MeasureUnit::MM_10TH: { - OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for twip values"); + // 0.01mm = 0.57twip (exactly) + fRetval = ((25400.0 / 1440.0) / 100.0); + break; } case MeasureUnit::MM: { @@ -1829,31 +1836,49 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS { switch(nTargetUnit) { + case MeasureUnit::MM_100TH: + { + // 1mm = 72 / 25.4 pt (exactly) + fRetval = ( 2540.0 / 72.0 ); + break; + } + case MeasureUnit::MM_10TH: + { + // 1mm = 72 / 25.4 pt (exactly) + fRetval = ( 254.0 / 72.0 ); + break; + } case MeasureUnit::MM: + { // 1mm = 72 / 25.4 pt (exactly) fRetval = ( 25.4 / 72.0 ); psUnit = gpsMM; break; + } case MeasureUnit::CM: + { // 1cm = 72 / 2.54 pt (exactly) fRetval = ( 2.54 / 72.0 ); psUnit = gpsCM; break; - + } case MeasureUnit::TWIP: + { // 1twip = 72 / 1440 pt (exactly) fRetval = 20.0; // 1440.0 / 72.0 psUnit = gpsPC; break; - + } case MeasureUnit::INCH: default: + { OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for pt values"); // 1in = 72 pt (exactly) fRetval = ( 1.0 / 72.0 ); psUnit = gpsINCH; break; + } } break; } @@ -1862,9 +1887,9 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS switch(nTargetUnit) { case MeasureUnit::MM_100TH: - case MeasureUnit::MM_10TH: { - OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/100mm values"); + fRetval = 10.0; + break; } case MeasureUnit::MM: { @@ -1875,7 +1900,6 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS } case MeasureUnit::CM: { - // 0.001mm = 1 mm/100 (exactly) fRetval = ((10.0 / 1.0) / 1000.0); psUnit = gpsCM; break; @@ -1887,10 +1911,16 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS psUnit = gpsPT; break; } + case MeasureUnit::TWIP: + { + fRetval = ((20.0 * 72000.0 / 2540.0) / 100.0); + psUnit = gpsPC; + break; + } case MeasureUnit::INCH: default: { - OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/100mm values"); + OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/10mm values"); // 0.0001in = 0.254 mm/100 (exactly) fRetval = ((100000.0 / 2540.0) / 10000.0); psUnit = gpsINCH; @@ -1903,10 +1933,10 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS { switch(nTargetUnit) { - case MeasureUnit::MM_100TH: case MeasureUnit::MM_10TH: { - OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for 1/100mm values"); + fRetval = ((10.0 / 1.0) / 100.0); + break; } case MeasureUnit::MM: { @@ -1917,7 +1947,6 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS } case MeasureUnit::CM: { - // 0.001mm = 1 mm/100 (exactly) fRetval = ((10.0 / 1.0) / 10000.0); psUnit = gpsCM; break; @@ -1929,6 +1958,12 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS psUnit = gpsPT; break; } + case MeasureUnit::TWIP: + { + fRetval = ((20.0 * 72000.0 / 2540.0) / 1000.0); + psUnit = gpsPC; + break; + } case MeasureUnit::INCH: default: { @@ -1941,6 +1976,49 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS } break; } + case MeasureUnit::MM: + { + switch(nTargetUnit) + { + case MeasureUnit::MM_100TH: + { + fRetval = 100.0; + break; + } + case MeasureUnit::MM_10TH: + { + fRetval = 10.0; + break; + } + case MeasureUnit::CM: + { + fRetval = 0.1; + psUnit = gpsCM; + break; + } + case MeasureUnit::POINT: + { + fRetval = 72.0 / (2.54 * 10); + psUnit = gpsPT; + break; + } + case MeasureUnit::TWIP: + { + fRetval = (20.0 * 72.0) / (2.54 * 10); + psUnit = gpsPC; + break; + } + case MeasureUnit::INCH: + default: + { + OSL_ENSURE( MeasureUnit::INCH == nTargetUnit, "output unit not supported for cm values"); + fRetval = 1 / (2.54 * 10); + psUnit = gpsINCH; + break; + } + } + break; + } case MeasureUnit::CM: { switch(nTargetUnit) @@ -1971,6 +2049,12 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS psUnit = gpsPT; break; } + case MeasureUnit::TWIP: + { + fRetval = (20.0 * 72.0) / 2.54; + psUnit = gpsPC; + break; + } case MeasureUnit::INCH: default: { @@ -1982,6 +2066,54 @@ double Converter::GetConversionFactor(::rtl::OUStringBuffer& rUnit, sal_Int16 nS } break; } + case MeasureUnit::INCH: + { + switch (nTargetUnit) + { + case MeasureUnit::MM_100TH: + { + fRetval = 2540; + break; + } + case MeasureUnit::MM_10TH: + { + fRetval = 254; + break; + } + case MeasureUnit::MM: + { + fRetval = 25.4; + psUnit = gpsMM; + break; + } + case MeasureUnit::CM: + { + fRetval = 2.54; + psUnit = gpsCM; + break; + } + case MeasureUnit::POINT: + { + fRetval = 72.0; + psUnit = gpsPT; + break; + } + case MeasureUnit::TWIP: + { + fRetval = 72.0 * 20.0; + psUnit = gpsPC; + break; + } + default: + { + OSL_FAIL("output unit not supported for in values"); + fRetval = 1; + psUnit = gpsINCH; + break; + } + } + break; + } default: OSL_ENSURE(false, "sax::Converter::GetConversionFactor(): " "source unit not supported"); |