summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2011-10-10 18:24:34 +0200
committerMichael Stahl <mst@openoffice.org>2011-10-11 17:56:59 +0200
commit02c32e0f0e75a9df80888051d1ec189fa14129bd (patch)
treeff10eb4e7a06e1285a80809b8d177f9203b3ec1b /sax
parente0c72547ce57c25db61ec3da6c2f2f2792348c7d (diff)
Diffstat (limited to 'sax')
-rw-r--r--sax/source/tools/converter.cxx187
1 files changed, 187 insertions, 0 deletions
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index 7ce607ea47c3..94faa49e257c 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -275,6 +275,193 @@ void Converter::convertMeasure( OUStringBuffer& rBuffer,
(void)nMeasure;
(void)nSourceUnit;
(void)nTargetUnit;
+#if 0
+ if( nSourceUnit == MeasureUnit::PERCENT )
+ {
+ OSL_ENSURE( nTargetUnit == MeasureUnit::PERCENT,
+ "MeasureUnit::PERCENT only maps to MeasureUnit::PERCENT!" );
+
+ rBuffer.append( nMeasure );
+ rBuffer.append( sal_Unicode('%' ) );
+ }
+ else
+ {
+ // the sign is processed seperatly
+ if( nMeasure < 0 )
+ {
+ nMeasure = -nMeasure;
+ rBuffer.append( sal_Unicode('-') );
+ }
+
+ // The new length is (nVal * nMul)/(nDiv*nFac*10)
+ long nMul = 1000;
+ long nDiv = 1;
+ long nFac = 100;
+ const sal_Char* psUnit = 0;
+ switch( nSourceUnit )
+ {
+ case MeasureUnit::TWIP:
+ switch( nTargetUnit )
+ {
+ case MeasureUnit::MM_100TH:
+ case MeasureUnit::MM_10TH:
+ OSL_ENSURE( MeasureUnit::INCH == nTargetUnit,"output unit not supported for twip values" );
+ case MeasureUnit::MM:
+ // 0.01mm = 0.57twip (exactly)
+ nMul = 25400; // 25.4 * 1000
+ nDiv = 1440; // 72 * 20;
+ nFac = 100;
+ psUnit = gpsMM;
+ break;
+
+ case MeasureUnit::CM:
+ // 0.001cm = 0.57twip (exactly)
+ nMul = 25400; // 2.54 * 10000
+ nDiv = 1440; // 72 * 20;
+ nFac = 1000;
+ psUnit = gpsCM;
+ break;
+
+ case MeasureUnit::POINT:
+ // 0.01pt = 0.2twip (exactly)
+ nMul = 1000;
+ nDiv = 20;
+ nFac = 100;
+ psUnit = gpsPT;
+ break;
+
+ case MeasureUnit::INCH:
+ default:
+ OSL_ENSURE( MeasureUnit::INCH == nTargetUnit,
+ "output unit not supported for twip values" );
+ // 0.0001in = 0.144twip (exactly)
+ nMul = 100000;
+ nDiv = 1440; // 72 * 20;
+ nFac = 10000;
+ psUnit = gpsINCH;
+ break;
+ }
+ break;
+
+ case MeasureUnit::POINT:
+ // 1pt = 1pt (exactly)
+ OSL_ENSURE( MeasureUnit::POINT == nTargetUnit,
+ "output unit not supported for pt values" );
+ nMul = 10;
+ nDiv = 1;
+ nFac = 1;
+ psUnit = gpsPT;
+ break;
+ case MeasureUnit::MM_10TH:
+ case MeasureUnit::MM_100TH:
+ {
+ long nFac2 = (MeasureUnit::MM_100TH == nSourceUnit) ? 100 : 10;
+ switch( nTargetUnit )
+ {
+ case MeasureUnit::MM_100TH:
+ case MeasureUnit::MM_10TH:
+ OSL_ENSURE( MeasureUnit::INCH == nTargetUnit,
+ "output unit not supported for 1/100mm values" );
+ case MeasureUnit::MM:
+ // 0.01mm = 1 mm/100 (exactly)
+ nMul = 10;
+ nDiv = 1;
+ nFac = nFac2;
+ psUnit = gpsMM;
+ break;
+
+ case MeasureUnit::CM:
+ // 0.001mm = 1 mm/100 (exactly)
+ nMul = 10;
+ nDiv = 1; // 72 * 20;
+ nFac = 10*nFac2;
+ psUnit = gpsCM;
+ break;
+
+ case MeasureUnit::POINT:
+ // 0.01pt = 0.35 mm/100 (exactly)
+ nMul = 72000;
+ nDiv = 2540;
+ nFac = nFac2;
+ psUnit = gpsPT;
+ break;
+
+ case MeasureUnit::INCH:
+ default:
+ OSL_ENSURE( MeasureUnit::INCH == nTargetUnit,
+ "output unit not supported for 1/100mm values" );
+ // 0.0001in = 0.254 mm/100 (exactly)
+ nMul = 100000;
+ nDiv = 2540;
+ nFac = 100*nFac2;
+ psUnit = gpsINCH;
+ break;
+ }
+ break;
+ }
+ }
+
+ long nLongVal = 0;
+ bool bOutLongVal = true;
+ if( nMeasure > SAL_INT32_MAX / nMul )
+ {
+ // A big int is required for calculation
+ BigInt nBigVal( nMeasure );
+ BigInt nBigFac( nFac );
+ nBigVal *= nMul;
+ nBigVal /= nDiv;
+ nBigVal += 5;
+ nBigVal /= 10;
+
+ if( nBigVal.IsLong() )
+ {
+ // To convert the value into a string a long is sufficient
+ nLongVal = (long)nBigVal;
+ }
+ else
+ {
+ BigInt nBigFac2( nFac );
+ BigInt nBig10( 10 );
+ rBuffer.append( (sal_Int32)(nBigVal / nBigFac2) );
+ if( !(nBigVal % nBigFac2).IsZero() )
+ {
+ rBuffer.append( sal_Unicode('.') );
+ while( nFac > 1 && !(nBigVal % nBigFac2).IsZero() )
+ {
+ nFac /= 10;
+ nBigFac2 = nFac;
+ rBuffer.append( (sal_Int32)((nBigVal / nBigFac2) % nBig10 ) );
+ }
+ }
+ bOutLongVal = false;
+ }
+ }
+ else
+ {
+ nLongVal = nMeasure * nMul;
+ nLongVal /= nDiv;
+ nLongVal += 5;
+ nLongVal /= 10;
+ }
+
+ if( bOutLongVal )
+ {
+ rBuffer.append( (sal_Int32)(nLongVal / nFac) );
+ if( nFac > 1 && (nLongVal % nFac) != 0 )
+ {
+ rBuffer.append( sal_Unicode('.') );
+ while( nFac > 1 && (nLongVal % nFac) != 0 )
+ {
+ nFac /= 10;
+ rBuffer.append( (sal_Int32)((nLongVal / nFac) % 10) );
+ }
+ }
+ }
+
+ if( psUnit )
+ rBuffer.appendAscii( psUnit );
+ }
+#endif
}
static const OUString& getTrueString()