diff options
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/misc/unitconv.cxx | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/svtools/source/misc/unitconv.cxx b/svtools/source/misc/unitconv.cxx index f99b2806076c..64d1acb75330 100644 --- a/svtools/source/misc/unitconv.cxx +++ b/svtools/source/misc/unitconv.cxx @@ -132,7 +132,6 @@ void SetFieldUnit( MetricField& rField, FieldUnit eUnit, bool bAll ) } } - void SetFieldUnit( MetricBox& rBox, FieldUnit eUnit ) { sal_Int64 nMin = rBox.Denormalize( rBox.GetMin( FUNIT_TWIP ) ); @@ -162,6 +161,12 @@ void SetFieldUnit( MetricBox& rBox, FieldUnit eUnit ) rBox.SetMax( rBox.Normalize( nMax ), FUNIT_TWIP ); } +void SetMetricValue(weld::MetricSpinButton& rField, int nCoreValue, MapUnit eUnit) +{ + auto nVal = OutputDevice::LogicToLogic(nCoreValue, eUnit, MapUnit::Map100thMM); + nVal = rField.normalize(nVal); + rField.set_value(nVal, FUNIT_100TH_MM); +} void SetMetricValue( MetricField& rField, long nCoreValue, MapUnit eUnit ) { @@ -171,6 +176,29 @@ void SetMetricValue( MetricField& rField, long nCoreValue, MapUnit eUnit ) } +int GetCoreValue(const weld::MetricSpinButton& rField, MapUnit eUnit) +{ + int nVal = rField.get_value(FUNIT_100TH_MM); + // avoid rounding issues + const int nSizeMask = 0xff000000; + bool bRoundBefore = true; + if( nVal >= 0 ) + { + if( (nVal & nSizeMask) == 0 ) + bRoundBefore = false; + } + else + { + if( ((-nVal) & nSizeMask ) == 0 ) + bRoundBefore = false; + } + if( bRoundBefore ) + nVal = rField.denormalize( nVal ); + auto nUnitVal = OutputDevice::LogicToLogic(nVal, MapUnit::Map100thMM, eUnit); + if (!bRoundBefore) + nUnitVal = rField.denormalize(nUnitVal); + return nUnitVal; +} long GetCoreValue( const MetricField& rField, MapUnit eUnit ) { @@ -196,7 +224,6 @@ long GetCoreValue( const MetricField& rField, MapUnit eUnit ) return static_cast<long>(nUnitVal); } - long CalcToUnit( float nIn, MapUnit eUnit ) { // nIn is in Points |