1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <osl/diagnose.h>
23 #include <vcl/outdev.hxx>
24 #include <editeng/editrids.hrc>
25 #include <unotools/intlwrapper.hxx>
26 #include <unotools/localedatawrapper.hxx>
27 #include <editeng/itemtype.hxx>
28 #include <editeng/eerdll.hxx>
29 #include <rtl/ustrbuf.hxx>
32 OUString
GetMetricText( long nVal
, MapUnit eSrcUnit
, MapUnit eDestUnit
, const IntlWrapper
* pIntl
)
35 bool bShowAtLeastOneDecimalDigit
= true;
46 case MapUnit::Map100thMM
:
47 case MapUnit::Map10thMM
:
51 nRet
= OutputDevice::LogicToLogic( nVal
, eSrcUnit
, MapUnit::Map100thMM
);
55 case MapUnit::Map100thMM
: nRet
*= 1000; break;
56 case MapUnit::Map10thMM
: nRet
*= 100; break;
57 case MapUnit::MapMM
: nRet
*= 10; break;
58 default: ;//prevent warning
63 case MapUnit::Map1000thInch
:
64 case MapUnit::Map100thInch
:
65 case MapUnit::Map10thInch
:
66 case MapUnit::MapInch
:
68 nRet
= OutputDevice::LogicToLogic( nVal
, eSrcUnit
, MapUnit::Map1000thInch
);
72 case MapUnit::Map1000thInch
: nRet
*= 1000; break;
73 case MapUnit::Map100thInch
: nRet
*= 100; break;
74 case MapUnit::Map10thInch
: nRet
*= 10; break;
75 default: ;//prevent warning
80 case MapUnit::MapPoint
:
81 // fractions of a point are used, e.g., for font size
82 nRet
= OutputDevice::LogicToLogic(nVal
, eSrcUnit
, MapUnit::MapTwip
) * 50;
83 bShowAtLeastOneDecimalDigit
= false;
86 case MapUnit::MapTwip
:
87 case MapUnit::MapPixel
:
88 return OUString::number( OutputDevice::LogicToLogic(
89 nVal
, eSrcUnit
, eDestUnit
));
92 OSL_FAIL( "not supported mapunit" );
96 if ( MapUnit::MapCM
== eDestUnit
|| MapUnit::MapInch
== eDestUnit
)
98 sal_Int32 nMod
= nRet
% 10;
112 for( int nDigits
= 4; nDigits
; --nDigits
, nDiff
/= 10 )
117 sRet
.append(nRet
/ nDiff
);
119 if( 4 == nDigits
&& (bShowAtLeastOneDecimalDigit
|| nRet
) )
122 sRet
.append(pIntl
->getLocaleData()->getNumDecimalSep());
134 return sRet
.makeStringAndClear();
137 OUString
GetColorString( const Color
& rCol
)
139 if (rCol
== COL_AUTO
)
140 return EditResId(RID_SVXSTR_AUTOMATIC
);
142 static const Color aColAry
[] = {
143 COL_BLACK
, COL_BLUE
, COL_GREEN
, COL_CYAN
,
144 COL_RED
, COL_MAGENTA
, COL_BROWN
, COL_GRAY
,
145 COL_LIGHTGRAY
, COL_LIGHTBLUE
, COL_LIGHTGREEN
, COL_LIGHTCYAN
,
146 COL_LIGHTRED
, COL_LIGHTMAGENTA
, COL_YELLOW
, COL_WHITE
};
148 sal_uInt16 nColor
= 0;
149 while ( nColor
< SAL_N_ELEMENTS(aColAry
) &&
150 aColAry
[nColor
] != rCol
.GetRGBColor() )
155 static const char* RID_SVXITEMS_COLORS
[] =
157 RID_SVXITEMS_COLOR_BLACK
,
158 RID_SVXITEMS_COLOR_BLUE
,
159 RID_SVXITEMS_COLOR_GREEN
,
160 RID_SVXITEMS_COLOR_CYAN
,
161 RID_SVXITEMS_COLOR_RED
,
162 RID_SVXITEMS_COLOR_MAGENTA
,
163 RID_SVXITEMS_COLOR_BROWN
,
164 RID_SVXITEMS_COLOR_GRAY
,
165 RID_SVXITEMS_COLOR_LIGHTGRAY
,
166 RID_SVXITEMS_COLOR_LIGHTBLUE
,
167 RID_SVXITEMS_COLOR_LIGHTGREEN
,
168 RID_SVXITEMS_COLOR_LIGHTCYAN
,
169 RID_SVXITEMS_COLOR_LIGHTRED
,
170 RID_SVXITEMS_COLOR_LIGHTMAGENTA
,
171 RID_SVXITEMS_COLOR_YELLOW
,
172 RID_SVXITEMS_COLOR_WHITE
175 static_assert(SAL_N_ELEMENTS(aColAry
) == SAL_N_ELEMENTS(RID_SVXITEMS_COLORS
), "must match");
178 if ( nColor
< SAL_N_ELEMENTS(aColAry
) )
179 sStr
= EditResId(RID_SVXITEMS_COLORS
[nColor
]);
181 if ( sStr
.isEmpty() )
184 OUString::number( rCol
.GetRed() ) + cpDelim
+
185 OUString::number( rCol
.GetGreen() ) + cpDelim
+
186 OUString::number( rCol
.GetBlue() ) + ")";
191 const char* GetMetricId( MapUnit eUnit
)
193 const char* pId
= RID_SVXITEMS_METRIC_MM
;
197 case MapUnit::Map100thMM
:
198 case MapUnit::Map10thMM
:
200 pId
= RID_SVXITEMS_METRIC_MM
;
204 pId
= RID_SVXITEMS_METRIC_CM
;
207 case MapUnit::Map1000thInch
:
208 case MapUnit::Map100thInch
:
209 case MapUnit::Map10thInch
:
210 case MapUnit::MapInch
:
211 pId
= RID_SVXITEMS_METRIC_INCH
;
214 case MapUnit::MapPoint
:
215 pId
= RID_SVXITEMS_METRIC_POINT
;
218 case MapUnit::MapTwip
:
219 pId
= RID_SVXITEMS_METRIC_TWIP
;
222 case MapUnit::MapPixel
:
223 pId
= RID_SVXITEMS_METRIC_PIXEL
;
227 OSL_FAIL( "not supported mapunit" );
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */