xref: /aoo41x/main/svtools/source/misc/unitconv.cxx (revision c82f2877)
1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c82f2877SAndrew Rist  * distributed with this work for additional information
6*c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c82f2877SAndrew Rist  *
11*c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c82f2877SAndrew Rist  *
13*c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c82f2877SAndrew Rist  * specific language governing permissions and limitations
18*c82f2877SAndrew Rist  * under the License.
19*c82f2877SAndrew Rist  *
20*c82f2877SAndrew Rist  *************************************************************/
21*c82f2877SAndrew Rist 
22*c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svtools/unitconv.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // -----------------------------------------------------------------------
32cdf0e10cSrcweir 
SetFieldUnit(MetricField & rField,FieldUnit eUnit,sal_Bool bAll)33cdf0e10cSrcweir void SetFieldUnit( MetricField& rField, FieldUnit eUnit, sal_Bool bAll )
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 	sal_Int64 nFirst	= rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) );
36cdf0e10cSrcweir 	sal_Int64 nLast = rField.Denormalize( rField.GetLast( FUNIT_TWIP ) );
37cdf0e10cSrcweir 	sal_Int64 nMin = rField.Denormalize( rField.GetMin( FUNIT_TWIP ) );
38cdf0e10cSrcweir 	sal_Int64 nMax = rField.Denormalize( rField.GetMax( FUNIT_TWIP ) );
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 	if ( !bAll )
41cdf0e10cSrcweir 	{
42cdf0e10cSrcweir 		switch ( eUnit )
43cdf0e10cSrcweir 		{
44cdf0e10cSrcweir 			case FUNIT_M:
45cdf0e10cSrcweir 			case FUNIT_KM:
46cdf0e10cSrcweir 				eUnit = FUNIT_CM;
47cdf0e10cSrcweir 				break;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 			case FUNIT_FOOT:
50cdf0e10cSrcweir 			case FUNIT_MILE:
51cdf0e10cSrcweir 				eUnit = FUNIT_INCH;
52cdf0e10cSrcweir 				break;
53cdf0e10cSrcweir             default: ;//prevent warning
54cdf0e10cSrcweir 		}
55cdf0e10cSrcweir 	}
56cdf0e10cSrcweir 	rField.SetUnit( eUnit );
57cdf0e10cSrcweir 	switch( eUnit )
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 		case FUNIT_MM:
60cdf0e10cSrcweir 			rField.SetSpinSize( 50 );
61cdf0e10cSrcweir 			break;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 		case FUNIT_INCH:
64cdf0e10cSrcweir 			rField.SetSpinSize( 2 );
65cdf0e10cSrcweir 			break;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 		default:
68cdf0e10cSrcweir 			rField.SetSpinSize( 10 );
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	if ( FUNIT_POINT == eUnit )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         if( rField.GetDecimalDigits() > 1 )
74cdf0e10cSrcweir 		    rField.SetDecimalDigits( 1 );
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 	else
77cdf0e10cSrcweir 		rField.SetDecimalDigits( 2 );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	if ( !bAll )
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
82cdf0e10cSrcweir 		rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
83cdf0e10cSrcweir 		rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
84cdf0e10cSrcweir 		rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir // -----------------------------------------------------------------------
89cdf0e10cSrcweir 
SetFieldUnit(MetricBox & rBox,FieldUnit eUnit,sal_Bool bAll)90cdf0e10cSrcweir void SetFieldUnit( MetricBox& rBox, FieldUnit eUnit, sal_Bool bAll )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	sal_Int64 nMin = rBox.Denormalize( rBox.GetMin( FUNIT_TWIP ) );
93cdf0e10cSrcweir 	sal_Int64 nMax = rBox.Denormalize( rBox.GetMax( FUNIT_TWIP ) );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	if ( !bAll )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		switch ( eUnit )
98cdf0e10cSrcweir 		{
99cdf0e10cSrcweir 			case FUNIT_M:
100cdf0e10cSrcweir 			case FUNIT_KM:
101cdf0e10cSrcweir 				eUnit = FUNIT_CM;
102cdf0e10cSrcweir 				break;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 			case FUNIT_FOOT:
105cdf0e10cSrcweir 			case FUNIT_MILE:
106cdf0e10cSrcweir 				eUnit = FUNIT_INCH;
107cdf0e10cSrcweir 				break;
108cdf0e10cSrcweir             default: ;//prevent warning
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir 	}
111cdf0e10cSrcweir 	rBox.SetUnit( eUnit );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	if ( FUNIT_POINT == eUnit && rBox.GetDecimalDigits() > 1 )
114cdf0e10cSrcweir 		rBox.SetDecimalDigits( 1 );
115cdf0e10cSrcweir 	else
116cdf0e10cSrcweir 		rBox.SetDecimalDigits( 2 );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	if ( !bAll )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		rBox.SetMin( rBox.Normalize( nMin ), FUNIT_TWIP );
121cdf0e10cSrcweir 		rBox.SetMax( rBox.Normalize( nMax ), FUNIT_TWIP );
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir // -----------------------------------------------------------------------
SetMetricValue(MetricField & rField,long nCoreValue,SfxMapUnit eUnit)126cdf0e10cSrcweir void SetMetricValue( MetricField& rField, long nCoreValue, SfxMapUnit eUnit )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	sal_Int64 nVal = OutputDevice::LogicToLogic( nCoreValue, (MapUnit)eUnit, MAP_100TH_MM );
129cdf0e10cSrcweir 	nVal = rField.Normalize( nVal );
130cdf0e10cSrcweir 	rField.SetValue( nVal, FUNIT_100TH_MM );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // -----------------------------------------------------------------------
135cdf0e10cSrcweir 
GetCoreValue(const MetricField & rField,SfxMapUnit eUnit)136cdf0e10cSrcweir long GetCoreValue( const MetricField& rField, SfxMapUnit eUnit )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	sal_Int64 nVal = rField.GetValue( FUNIT_100TH_MM );
139cdf0e10cSrcweir     // avoid rounding issues
140cdf0e10cSrcweir     const sal_Int64 nSizeMask = 0xffffffffff000000LL;
141cdf0e10cSrcweir     bool bRoundBefore = true;
142cdf0e10cSrcweir     if( nVal >= 0 )
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         if( (nVal & nSizeMask) == 0 )
145cdf0e10cSrcweir             bRoundBefore = false;
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir     else
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         if( ((-nVal) & nSizeMask ) == 0 )
150cdf0e10cSrcweir             bRoundBefore = false;
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir     if( bRoundBefore )
153cdf0e10cSrcweir         nVal = rField.Denormalize( nVal );
154cdf0e10cSrcweir 	sal_Int64 nUnitVal = OutputDevice::LogicToLogic( static_cast<long>(nVal), MAP_100TH_MM, (MapUnit)eUnit );
155cdf0e10cSrcweir     if( ! bRoundBefore )
156cdf0e10cSrcweir         nUnitVal = rField.Denormalize( nUnitVal );
157cdf0e10cSrcweir 	return static_cast<long>(nUnitVal);
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir // -----------------------------------------------------------------------
161cdf0e10cSrcweir 
CalcToUnit(float nIn,SfxMapUnit eUnit)162cdf0e10cSrcweir long CalcToUnit( float nIn, SfxMapUnit eUnit )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	// nIn ist in Points
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	DBG_ASSERT( eUnit == SFX_MAPUNIT_TWIP 		||
167cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_100TH_MM 	||
168cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_10TH_MM 	||
169cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_MM 		||
170cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_CM, "this unit is not implemented" );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	float nTmp = nIn;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	if ( SFX_MAPUNIT_TWIP != eUnit )
175cdf0e10cSrcweir 		nTmp = nIn * 10 / 567;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	switch ( eUnit )
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_MM:	nTmp *= 100; break;
180cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_MM:	nTmp *= 10;	 break;
181cdf0e10cSrcweir 		case SFX_MAPUNIT_MM:					 break;
182cdf0e10cSrcweir 		case SFX_MAPUNIT_CM:		nTmp /= 10;	 break;
183cdf0e10cSrcweir         default: ;//prevent warning
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	nTmp *= 20;
187cdf0e10cSrcweir 	long nRet = (long)nTmp;
188cdf0e10cSrcweir 	return nRet;
189cdf0e10cSrcweir //!	return (long)(nTmp * 20);
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir // -----------------------------------------------------------------------
193cdf0e10cSrcweir 
ItemToControl(long nIn,SfxMapUnit eItem,SfxFieldUnit eCtrl)194cdf0e10cSrcweir long ItemToControl( long nIn, SfxMapUnit eItem, SfxFieldUnit eCtrl )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	long nOut = 0;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	switch ( eItem )
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_MM:
201cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_MM:
202cdf0e10cSrcweir 		case SFX_MAPUNIT_MM:
203cdf0e10cSrcweir 		{
204cdf0e10cSrcweir 			if ( eItem == SFX_MAPUNIT_10TH_MM )
205cdf0e10cSrcweir 				nIn /= 10;
206cdf0e10cSrcweir 			else if ( eItem == SFX_MAPUNIT_100TH_MM )
207cdf0e10cSrcweir 				nIn /= 100;
208cdf0e10cSrcweir 			nOut = TransformMetric( nIn, FUNIT_MM, (FieldUnit)eCtrl );
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 		break;
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 		case SFX_MAPUNIT_CM:
213cdf0e10cSrcweir 		{
214cdf0e10cSrcweir 			nOut = TransformMetric( nIn, FUNIT_CM, (FieldUnit)eCtrl );
215cdf0e10cSrcweir 		}
216cdf0e10cSrcweir 		break;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 		case SFX_MAPUNIT_1000TH_INCH:
219cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_INCH:
220cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_INCH:
221cdf0e10cSrcweir 		case SFX_MAPUNIT_INCH:
222cdf0e10cSrcweir 		{
223cdf0e10cSrcweir 			if ( eItem == SFX_MAPUNIT_10TH_INCH )
224cdf0e10cSrcweir 				nIn /= 10;
225cdf0e10cSrcweir 			else if ( eItem == SFX_MAPUNIT_100TH_INCH )
226cdf0e10cSrcweir 				nIn /= 100;
227cdf0e10cSrcweir 			else if ( eItem == SFX_MAPUNIT_1000TH_INCH )
228cdf0e10cSrcweir 				nIn /= 1000;
229cdf0e10cSrcweir 			nOut = TransformMetric( nIn, FUNIT_INCH, (FieldUnit)eCtrl );
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 		break;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 		case SFX_MAPUNIT_POINT:
234cdf0e10cSrcweir 		{
235cdf0e10cSrcweir 			nOut = TransformMetric( nIn, FUNIT_POINT, (FieldUnit)eCtrl );
236cdf0e10cSrcweir 		}
237cdf0e10cSrcweir 		break;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 		case SFX_MAPUNIT_TWIP:
240cdf0e10cSrcweir 		{
241cdf0e10cSrcweir 			nOut = TransformMetric( nIn, FUNIT_TWIP, (FieldUnit)eCtrl );
242cdf0e10cSrcweir 		}
243cdf0e10cSrcweir 		break;
244cdf0e10cSrcweir         default: ;//prevent warning
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir 	return nOut;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir // -----------------------------------------------------------------------
250cdf0e10cSrcweir 
ControlToItem(long nIn,SfxFieldUnit eCtrl,SfxMapUnit eItem)251cdf0e10cSrcweir long ControlToItem( long nIn, SfxFieldUnit eCtrl, SfxMapUnit eItem )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir 	return ItemToControl( nIn, eItem, eCtrl );
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir // -----------------------------------------------------------------------
257cdf0e10cSrcweir 
MapToFieldUnit(const SfxMapUnit eUnit)258cdf0e10cSrcweir FieldUnit MapToFieldUnit( const SfxMapUnit eUnit )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir 	switch ( eUnit )
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_MM:
263cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_MM:
264cdf0e10cSrcweir 		case SFX_MAPUNIT_MM:
265cdf0e10cSrcweir 			return FUNIT_MM;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 		case SFX_MAPUNIT_CM:
268cdf0e10cSrcweir 			return FUNIT_CM;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 		case SFX_MAPUNIT_1000TH_INCH:
271cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_INCH:
272cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_INCH:
273cdf0e10cSrcweir 		case SFX_MAPUNIT_INCH:
274cdf0e10cSrcweir 			return FUNIT_INCH;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 		case SFX_MAPUNIT_POINT:
277cdf0e10cSrcweir 			return FUNIT_POINT;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 		case SFX_MAPUNIT_TWIP:
280cdf0e10cSrcweir 			return FUNIT_TWIP;
281cdf0e10cSrcweir         default: ;//prevent warning
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir 	return FUNIT_NONE;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir // -----------------------------------------------------------------------
287cdf0e10cSrcweir 
FieldToMapUnit(const SfxFieldUnit)288cdf0e10cSrcweir MapUnit FieldToMapUnit( const SfxFieldUnit /*eUnit*/ )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir 	return MAP_APPFONT;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir // -----------------------------------------------------------------------
294cdf0e10cSrcweir 
ConvertValueToMap(long nVal,SfxMapUnit eUnit)295cdf0e10cSrcweir long ConvertValueToMap( long nVal, SfxMapUnit eUnit )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	long nNew = nVal;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	switch ( eUnit )
300cdf0e10cSrcweir 	{
301cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_MM:
302cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_INCH:
303cdf0e10cSrcweir 			nNew *= 10;
304cdf0e10cSrcweir 			break;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_MM:
307cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_INCH:
308cdf0e10cSrcweir 			nNew *= 100;
309cdf0e10cSrcweir 			break;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 		case SFX_MAPUNIT_1000TH_INCH:
312cdf0e10cSrcweir 			nNew *= 1000;
313cdf0e10cSrcweir         default: ;//prevent warning
314cdf0e10cSrcweir     }
315cdf0e10cSrcweir 	return nNew;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir // -----------------------------------------------------------------------
319cdf0e10cSrcweir 
ConvertValueToUnit(long nVal,SfxMapUnit eUnit)320cdf0e10cSrcweir long ConvertValueToUnit( long nVal, SfxMapUnit eUnit )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir 	long nNew = nVal;
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 	switch ( eUnit )
325cdf0e10cSrcweir 	{
326cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_MM:
327cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_INCH:
328cdf0e10cSrcweir 			nNew /= 10;
329cdf0e10cSrcweir 			break;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_MM:
332cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_INCH:
333cdf0e10cSrcweir 			nNew /= 100;
334cdf0e10cSrcweir 			break;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 		case SFX_MAPUNIT_1000TH_INCH:
337cdf0e10cSrcweir 			nNew /= 1000;
338cdf0e10cSrcweir         break;
339cdf0e10cSrcweir         default: ;//prevent warning
340cdf0e10cSrcweir 	}
341cdf0e10cSrcweir 	return nNew;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir // -----------------------------------------------------------------------
345cdf0e10cSrcweir 
CalcToPoint(long nIn,SfxMapUnit eUnit,sal_uInt16 nFaktor)346cdf0e10cSrcweir long CalcToPoint( long nIn, SfxMapUnit eUnit, sal_uInt16 nFaktor )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir 	DBG_ASSERT( eUnit == SFX_MAPUNIT_TWIP 		||
349cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_100TH_MM 	||
350cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_10TH_MM 	||
351cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_MM 		||
352cdf0e10cSrcweir 				eUnit == SFX_MAPUNIT_CM, "this unit is not implemented" );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 	long nRet = 0;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	if ( SFX_MAPUNIT_TWIP == eUnit )
357cdf0e10cSrcweir 		nRet = nIn;
358cdf0e10cSrcweir 	else
359cdf0e10cSrcweir 		nRet = nIn * 567;
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 	switch ( eUnit )
362cdf0e10cSrcweir 	{
363cdf0e10cSrcweir 		case SFX_MAPUNIT_100TH_MM:	nRet /= 100; break;
364cdf0e10cSrcweir 		case SFX_MAPUNIT_10TH_MM:	nRet /= 10;	 break;
365cdf0e10cSrcweir 		case SFX_MAPUNIT_MM:					 break;
366cdf0e10cSrcweir 		case SFX_MAPUNIT_CM:		nRet *= 10;	 break;
367cdf0e10cSrcweir         default: ;//prevent warning
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	// ggf. aufrunden
371cdf0e10cSrcweir 	if ( SFX_MAPUNIT_TWIP != eUnit )
372cdf0e10cSrcweir 	{
373cdf0e10cSrcweir 		long nMod = 10;
374cdf0e10cSrcweir 		long nTmp = nRet % nMod;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 		if ( nTmp >= 4 )
377cdf0e10cSrcweir 			nRet += 10 - nTmp;
378cdf0e10cSrcweir 		nRet /= 10;
379cdf0e10cSrcweir 	}
380cdf0e10cSrcweir 	return nRet * nFaktor / 20;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir // -----------------------------------------------------------------------
384cdf0e10cSrcweir 
CMToTwips(long nIn)385cdf0e10cSrcweir long CMToTwips( long nIn )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir 	long nRet = 0;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
390cdf0e10cSrcweir 		nRet = nIn * 567;
391cdf0e10cSrcweir 	return nRet;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir // -----------------------------------------------------------------------
395cdf0e10cSrcweir 
MMToTwips(long nIn)396cdf0e10cSrcweir long MMToTwips( long nIn )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir 	long nRet = 0;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
401cdf0e10cSrcweir 		nRet = nIn * 567 / 10;
402cdf0e10cSrcweir 	return nRet;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir // -----------------------------------------------------------------------
406cdf0e10cSrcweir 
InchToTwips(long nIn)407cdf0e10cSrcweir long InchToTwips( long nIn )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir 	long nRet = 0;
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 1440 ) && nIn >= ( LONG_MIN / 1440 ) )
412cdf0e10cSrcweir 		nRet = nIn * 1440;
413cdf0e10cSrcweir 	return nRet;
414cdf0e10cSrcweir }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir // -----------------------------------------------------------------------
417cdf0e10cSrcweir 
PointToTwips(long nIn)418cdf0e10cSrcweir long PointToTwips( long nIn )
419cdf0e10cSrcweir {
420cdf0e10cSrcweir 	long nRet = 0;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 20 ) && nIn >= ( LONG_MIN / 20 ) )
423cdf0e10cSrcweir 		nRet = nIn * 20;
424cdf0e10cSrcweir 	return nRet;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir // -----------------------------------------------------------------------
428cdf0e10cSrcweir 
PicaToTwips(long nIn)429cdf0e10cSrcweir long PicaToTwips( long nIn )
430cdf0e10cSrcweir {
431cdf0e10cSrcweir 	long nRet = 0;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 240 ) && nIn >= ( LONG_MIN / 240 ) )
434cdf0e10cSrcweir 		nRet = nIn * 240;
435cdf0e10cSrcweir 	return nRet;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir // -----------------------------------------------------------------------
439cdf0e10cSrcweir 
TwipsToCM(long nIn)440cdf0e10cSrcweir long TwipsToCM( long nIn )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir 	long nRet = nIn / 567;
443cdf0e10cSrcweir 	return nRet;
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir // -----------------------------------------------------------------------
447cdf0e10cSrcweir 
InchToCM(long nIn)448cdf0e10cSrcweir long InchToCM( long nIn )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	long nRet = 0;
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 254 ) && nIn >= ( LONG_MIN / 254 ) )
453cdf0e10cSrcweir 		nRet = nIn * 254 / 100;
454cdf0e10cSrcweir 	return nRet;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir // -----------------------------------------------------------------------
458cdf0e10cSrcweir 
MMToCM(long nIn)459cdf0e10cSrcweir long MMToCM( long nIn )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir 	long nRet = nIn / 10;
462cdf0e10cSrcweir 	return nRet;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir // -----------------------------------------------------------------------
466cdf0e10cSrcweir 
PointToCM(long nIn)467cdf0e10cSrcweir long PointToCM( long nIn )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	long nRet = 0;
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 20 ) && nIn >= ( LONG_MIN / 20 ) )
472cdf0e10cSrcweir 		nRet = nIn * 20 / 567;
473cdf0e10cSrcweir 	return nRet;
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir // -----------------------------------------------------------------------
477cdf0e10cSrcweir 
PicaToCM(long nIn)478cdf0e10cSrcweir long PicaToCM( long nIn)
479cdf0e10cSrcweir {
480cdf0e10cSrcweir 	long nRet = 0;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 12 / 20 ) && nIn >= ( LONG_MIN / 12 / 20 ) )
483cdf0e10cSrcweir 		nRet = nIn * 12 * 20 / 567;
484cdf0e10cSrcweir 	return nRet;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir // -----------------------------------------------------------------------
488cdf0e10cSrcweir 
TwipsToMM(long nIn)489cdf0e10cSrcweir long TwipsToMM( long nIn )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir 	long nRet = 0;
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
494cdf0e10cSrcweir 		nRet = nIn * 10 / 566;
495cdf0e10cSrcweir 	return nRet;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir // -----------------------------------------------------------------------
499cdf0e10cSrcweir 
CMToMM(long nIn)500cdf0e10cSrcweir long CMToMM( long nIn )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir 	long nRet = 0;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
505cdf0e10cSrcweir 		nRet = nIn * 10;
506cdf0e10cSrcweir 	return nRet;
507cdf0e10cSrcweir }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir // -----------------------------------------------------------------------
510cdf0e10cSrcweir 
InchToMM(long nIn)511cdf0e10cSrcweir long InchToMM( long nIn )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir 	long nRet = 0;
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 254 ) && nIn >= ( LONG_MIN / 254 ) )
516cdf0e10cSrcweir 		nRet = nIn * 254 / 10;
517cdf0e10cSrcweir 	return nRet;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir // -----------------------------------------------------------------------
521cdf0e10cSrcweir 
PointToMM(long nIn)522cdf0e10cSrcweir long PointToMM( long nIn )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir 	long nRet = 0;
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 200 ) && nIn >= ( LONG_MIN / 200 ) )
527cdf0e10cSrcweir 		nRet = nIn * 200 / 567;
528cdf0e10cSrcweir 	return nRet;
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir // -----------------------------------------------------------------------
532cdf0e10cSrcweir 
PicaToMM(long nIn)533cdf0e10cSrcweir long PicaToMM( long nIn )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir 	long nRet = 0;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 12 / 200 ) && nIn >= ( LONG_MIN / 12 / 200 ) )
538cdf0e10cSrcweir 		nRet = nIn * 12 * 200 / 567;
539cdf0e10cSrcweir 	return nRet;
540cdf0e10cSrcweir }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir // -----------------------------------------------------------------------
543cdf0e10cSrcweir 
TwipsToInch(long nIn)544cdf0e10cSrcweir long TwipsToInch( long nIn )
545cdf0e10cSrcweir {
546cdf0e10cSrcweir 	long nRet = nIn / 1440;
547cdf0e10cSrcweir 	return nRet;
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir // -----------------------------------------------------------------------
551cdf0e10cSrcweir 
CMToInch(long nIn)552cdf0e10cSrcweir long CMToInch( long nIn )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir 	long nRet = 0;
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 100 ) && nIn >= ( LONG_MIN / 100 ) )
557cdf0e10cSrcweir 		nRet = nIn * 100 / 254;
558cdf0e10cSrcweir 	return nRet;
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // -----------------------------------------------------------------------
562cdf0e10cSrcweir 
MMToInch(long nIn)563cdf0e10cSrcweir long MMToInch( long nIn )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir 	long nRet = 0;
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
568cdf0e10cSrcweir 		nRet = nIn * 10 / 254;
569cdf0e10cSrcweir 	return nRet;
570cdf0e10cSrcweir }
571cdf0e10cSrcweir 
572cdf0e10cSrcweir // -----------------------------------------------------------------------
573cdf0e10cSrcweir 
PointToInch(long nIn)574cdf0e10cSrcweir long PointToInch( long nIn )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir 	long nRet = nIn / 72;
577cdf0e10cSrcweir 	return nRet;
578cdf0e10cSrcweir }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir // -----------------------------------------------------------------------
581cdf0e10cSrcweir 
PicaToInch(long nIn)582cdf0e10cSrcweir long PicaToInch( long nIn )
583cdf0e10cSrcweir {
584cdf0e10cSrcweir 	long nRet = nIn / 6;
585cdf0e10cSrcweir 	return nRet;
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir // -----------------------------------------------------------------------
589cdf0e10cSrcweir 
TwipsToPoint(long nIn)590cdf0e10cSrcweir long TwipsToPoint( long nIn )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir 	long nRet = nIn / 20;
593cdf0e10cSrcweir 	return nRet;
594cdf0e10cSrcweir }
595cdf0e10cSrcweir 
596cdf0e10cSrcweir // -----------------------------------------------------------------------
597cdf0e10cSrcweir 
InchToPoint(long nIn)598cdf0e10cSrcweir long InchToPoint( long nIn )
599cdf0e10cSrcweir {
600cdf0e10cSrcweir 	long nRet = 0;
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 72 ) && nIn >= ( LONG_MIN / 72 ) )
603cdf0e10cSrcweir 		nRet = nIn * 72;
604cdf0e10cSrcweir 	return nRet;
605cdf0e10cSrcweir }
606cdf0e10cSrcweir 
607cdf0e10cSrcweir // -----------------------------------------------------------------------
608cdf0e10cSrcweir 
CMToPoint(long nIn)609cdf0e10cSrcweir long CMToPoint( long nIn )
610cdf0e10cSrcweir {
611cdf0e10cSrcweir 	long nRet = 0;
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
614cdf0e10cSrcweir 		nRet = nIn * 567 / 20;
615cdf0e10cSrcweir 	return nRet;
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir // -----------------------------------------------------------------------
619cdf0e10cSrcweir 
MMToPoint(long nIn)620cdf0e10cSrcweir long MMToPoint( long nIn )
621cdf0e10cSrcweir {
622cdf0e10cSrcweir 	long nRet = 0;
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
625cdf0e10cSrcweir 		nRet = nIn * 567 / 200;
626cdf0e10cSrcweir 	return nRet;
627cdf0e10cSrcweir }
628cdf0e10cSrcweir 
629cdf0e10cSrcweir // -----------------------------------------------------------------------
630cdf0e10cSrcweir 
PicaToPoint(long nIn)631cdf0e10cSrcweir long PicaToPoint( long nIn )
632cdf0e10cSrcweir {
633cdf0e10cSrcweir 	long nRet = nIn / 12;
634cdf0e10cSrcweir 	return nRet;
635cdf0e10cSrcweir }
636cdf0e10cSrcweir 
637cdf0e10cSrcweir // -----------------------------------------------------------------------
638cdf0e10cSrcweir 
TwipsToPica(long nIn)639cdf0e10cSrcweir long TwipsToPica( long nIn )
640cdf0e10cSrcweir {
641cdf0e10cSrcweir 	long nRet = nIn / 240;
642cdf0e10cSrcweir 	return nRet;
643cdf0e10cSrcweir }
644cdf0e10cSrcweir 
645cdf0e10cSrcweir // -----------------------------------------------------------------------
646cdf0e10cSrcweir 
InchToPica(long nIn)647cdf0e10cSrcweir long InchToPica( long nIn )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir 	long nRet = 0;
650cdf0e10cSrcweir 
651cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 6 ) && nIn >= ( LONG_MIN / 6 ) )
652cdf0e10cSrcweir 		nRet = nIn * 6;
653cdf0e10cSrcweir 	return nRet;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir // -----------------------------------------------------------------------
657cdf0e10cSrcweir 
PointToPica(long nIn)658cdf0e10cSrcweir long PointToPica( long nIn )
659cdf0e10cSrcweir {
660cdf0e10cSrcweir 	long nRet = 0;
661cdf0e10cSrcweir 
662cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 12 ) && nIn >= ( LONG_MIN / 12 ) )
663cdf0e10cSrcweir 		nRet = nIn * 12;
664cdf0e10cSrcweir 	return nRet;
665cdf0e10cSrcweir }
666cdf0e10cSrcweir 
667cdf0e10cSrcweir // -----------------------------------------------------------------------
668cdf0e10cSrcweir 
CMToPica(long nIn)669cdf0e10cSrcweir long CMToPica( long nIn )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir 	long nRet = 0;
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
674cdf0e10cSrcweir 		nRet = nIn * 567 / 20 / 12;
675cdf0e10cSrcweir 	return nRet;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir // -----------------------------------------------------------------------
679cdf0e10cSrcweir 
MMToPica(long nIn)680cdf0e10cSrcweir long MMToPica( long nIn )
681cdf0e10cSrcweir {
682cdf0e10cSrcweir 	long nRet = 0;
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 	if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
685cdf0e10cSrcweir 		nRet = nIn * 567 / 200 / 12;
686cdf0e10cSrcweir 	return nRet;
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir // -----------------------------------------------------------------------
690cdf0e10cSrcweir 
Nothing(long nIn)691cdf0e10cSrcweir long Nothing( long nIn )
692cdf0e10cSrcweir {
693cdf0e10cSrcweir 	long nRet = nIn;
694cdf0e10cSrcweir 	return nRet;
695cdf0e10cSrcweir }
696cdf0e10cSrcweir 
697cdf0e10cSrcweir FUNC_CONVERT ConvertTable[6][6] =
698cdf0e10cSrcweir {
699cdf0e10cSrcweir //  CM,			MM			INCH		 POINT		  PICAS=32	   TWIPS
700cdf0e10cSrcweir 	{ Nothing, 	CMToMM, 	CMToInch,    CMToPoint,   CMToPica,    CMToTwips },
701cdf0e10cSrcweir 	{ MMToCM,		Nothing,	MMToInch,	 MMToPoint,   MMToPica,    MMToTwips },
702cdf0e10cSrcweir 	{ InchToCM,	InchToMM,	Nothing,	 InchToPoint, InchToPica,  InchToTwips },
703cdf0e10cSrcweir 	{ PointToCM,	PointToMM,  PointToInch, Nothing,	  PointToPica, PointToTwips },
704cdf0e10cSrcweir 	{ PicaToCM,	PicaToMM,   PicaToInch,  PicaToPoint, Nothing,	   PicaToTwips },
705cdf0e10cSrcweir 	{ TwipsToCM,	TwipsToMM,  TwipsToInch, TwipsToPoint,TwipsToPica, Nothing }
706cdf0e10cSrcweir };
707cdf0e10cSrcweir 
708cdf0e10cSrcweir // -----------------------------------------------------------------------
709cdf0e10cSrcweir 
TransformMetric(long nVal,FieldUnit aOld,FieldUnit aNew)710cdf0e10cSrcweir long TransformMetric( long nVal, FieldUnit aOld, FieldUnit aNew )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir 	if ( aOld == FUNIT_NONE	  || aNew == FUNIT_NONE ||
713cdf0e10cSrcweir 		 aOld == FUNIT_CUSTOM || aNew == FUNIT_CUSTOM )
714cdf0e10cSrcweir 	{
715cdf0e10cSrcweir 		return nVal;
716cdf0e10cSrcweir 	}
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 	sal_uInt16 nOld = 0;
719cdf0e10cSrcweir 	sal_uInt16 nNew = 0;
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 	switch ( aOld )
722cdf0e10cSrcweir 	{
723cdf0e10cSrcweir 		case FUNIT_CM:
724cdf0e10cSrcweir 			nOld = 0; break;
725cdf0e10cSrcweir 		case FUNIT_MM:
726cdf0e10cSrcweir 			nOld = 1; break;
727cdf0e10cSrcweir 		case FUNIT_INCH:
728cdf0e10cSrcweir 			nOld = 2; break;
729cdf0e10cSrcweir 		case FUNIT_POINT:
730cdf0e10cSrcweir 			nOld = 3; break;
731cdf0e10cSrcweir 		case FUNIT_PICA:
732cdf0e10cSrcweir 			nOld = 4; break;
733cdf0e10cSrcweir 		case FUNIT_TWIP:
734cdf0e10cSrcweir 			nOld = 5; break;
735cdf0e10cSrcweir         default: ;//prevent warning
736cdf0e10cSrcweir     }
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 	switch ( aNew )
739cdf0e10cSrcweir 	{
740cdf0e10cSrcweir 		case FUNIT_CM:
741cdf0e10cSrcweir 			nNew = 0; break;
742cdf0e10cSrcweir 		case FUNIT_MM:
743cdf0e10cSrcweir 			nNew = 1; break;
744cdf0e10cSrcweir 		case FUNIT_INCH:
745cdf0e10cSrcweir 			nNew = 2; break;
746cdf0e10cSrcweir 		case FUNIT_POINT:
747cdf0e10cSrcweir 			nNew = 3; break;
748cdf0e10cSrcweir 		case FUNIT_PICA:
749cdf0e10cSrcweir 			nNew = 4; break;
750cdf0e10cSrcweir 		case FUNIT_TWIP:
751cdf0e10cSrcweir 			nNew = 5; break;
752cdf0e10cSrcweir         default: ;//prevent warning
753cdf0e10cSrcweir     }
754cdf0e10cSrcweir 	return ConvertTable[nOld][nNew]( nVal );
755cdf0e10cSrcweir }
756cdf0e10cSrcweir 
757