Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <vcl/outdev.hxx>
21 : #include <editeng/editrids.hrc>
22 : #include <unotools/intlwrapper.hxx>
23 : #include <unotools/localedatawrapper.hxx>
24 : #include <editeng/itemtype.hxx>
25 : #include <editeng/eerdll.hxx>
26 : #include <rtl/ustrbuf.hxx>
27 :
28 :
29 :
30 0 : OUString GetMetricText( long nVal, SfxMapUnit eSrcUnit, SfxMapUnit eDestUnit, const IntlWrapper* pIntl )
31 : {
32 0 : bool bNeg = false;
33 0 : sal_Int32 nRet = 0;
34 :
35 0 : if ( nVal < 0 )
36 : {
37 0 : bNeg = true;
38 0 : nVal *= -1;
39 : }
40 :
41 0 : switch ( eDestUnit )
42 : {
43 : case SFX_MAPUNIT_100TH_MM:
44 : case SFX_MAPUNIT_10TH_MM:
45 : case SFX_MAPUNIT_MM:
46 : case SFX_MAPUNIT_CM:
47 : {
48 : nRet = (long)OutputDevice::LogicToLogic(
49 0 : nVal, (MapUnit)eSrcUnit, (MapUnit)SFX_MAPUNIT_100TH_MM );
50 :
51 0 : switch ( eDestUnit )
52 : {
53 0 : case SFX_MAPUNIT_100TH_MM: nRet *= 1000; break;
54 0 : case SFX_MAPUNIT_10TH_MM: nRet *= 100; break;
55 0 : case SFX_MAPUNIT_MM: nRet *= 10; break;
56 : default: ;//prevent warning
57 : }
58 0 : break;
59 : }
60 :
61 : case SFX_MAPUNIT_1000TH_INCH:
62 : case SFX_MAPUNIT_100TH_INCH:
63 : case SFX_MAPUNIT_10TH_INCH:
64 : case SFX_MAPUNIT_INCH:
65 : {
66 : nRet = OutputDevice::LogicToLogic(
67 0 : nVal, (MapUnit)eSrcUnit, (MapUnit)SFX_MAPUNIT_1000TH_INCH );
68 :
69 0 : switch ( eDestUnit )
70 : {
71 0 : case SFX_MAPUNIT_1000TH_INCH: nRet *= 1000; break;
72 0 : case SFX_MAPUNIT_100TH_INCH: nRet *= 100; break;
73 0 : case SFX_MAPUNIT_10TH_INCH: nRet *= 10; break;
74 : default: ;//prevent warning
75 : }
76 0 : break;
77 : }
78 :
79 : case SFX_MAPUNIT_POINT:
80 : case SFX_MAPUNIT_TWIP:
81 : case SFX_MAPUNIT_PIXEL:
82 : return OUString::number( (long)OutputDevice::LogicToLogic(
83 0 : nVal, (MapUnit)eSrcUnit, (MapUnit)eDestUnit ));
84 :
85 : default:
86 : OSL_FAIL( "not supported mapunit" );
87 0 : return OUString();
88 : }
89 :
90 0 : if ( SFX_MAPUNIT_CM == eDestUnit || SFX_MAPUNIT_INCH == eDestUnit )
91 : {
92 0 : sal_Int32 nMod = nRet % 10;
93 :
94 0 : if ( nMod > 4 )
95 0 : nRet += 10 - nMod;
96 0 : else if ( nMod > 0 )
97 0 : nRet -= nMod;
98 : }
99 :
100 0 : OUStringBuffer sRet;
101 :
102 0 : if ( bNeg )
103 0 : sRet.append('-');
104 :
105 0 : long nDiff = 1000;
106 0 : for( int nDigits = 4; nDigits; --nDigits, nDiff /= 10 )
107 : {
108 0 : if ( nRet < nDiff )
109 0 : sRet.append('0');
110 : else
111 0 : sRet.append(nRet / nDiff);
112 0 : nRet %= nDiff;
113 0 : if( 4 == nDigits )
114 : {
115 0 : if(pIntl)
116 0 : sRet.append(pIntl->getLocaleData()->getNumDecimalSep());
117 : else
118 0 : sRet.append(',');
119 0 : if( !nRet )
120 : {
121 0 : sRet.append('0');
122 0 : break;
123 : }
124 : }
125 0 : else if( !nRet )
126 0 : break;
127 : }
128 0 : return sRet.makeStringAndClear();
129 : }
130 :
131 :
132 :
133 0 : OUString GetSvxString( sal_uInt16 nId )
134 : {
135 0 : return EE_RESSTR( nId );
136 : }
137 :
138 :
139 :
140 0 : OUString GetColorString( const Color& rCol )
141 : {
142 0 : OUString sStr;
143 :
144 : ColorData nColData =
145 0 : RGB_COLORDATA( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
146 0 : sal_uInt16 nColor = 0;
147 :
148 : static const ColorData aColAry[] = {
149 : COL_BLACK, COL_BLUE, COL_GREEN, COL_CYAN,
150 : COL_RED, COL_MAGENTA, COL_BROWN, COL_GRAY,
151 : COL_LIGHTGRAY, COL_LIGHTBLUE, COL_LIGHTGREEN, COL_LIGHTCYAN,
152 : COL_LIGHTRED, COL_LIGHTMAGENTA, COL_YELLOW, COL_WHITE };
153 :
154 0 : while ( nColor < SAL_N_ELEMENTS(aColAry) &&
155 0 : aColAry[nColor] != nColData )
156 : {
157 0 : nColor += 1;
158 : }
159 :
160 0 : if ( nColor < SAL_N_ELEMENTS(aColAry) )
161 0 : sStr = EE_RESSTR( RID_SVXITEMS_COLOR_BEGIN + nColor + 1 );
162 :
163 0 : if ( sStr.isEmpty() )
164 : {
165 0 : sStr += "RGB(" +
166 0 : OUString::number( rCol.GetRed() ) + OUString(cpDelim) +
167 0 : OUString::number( rCol.GetGreen() ) + OUString(cpDelim) +
168 0 : OUString::number( rCol.GetBlue() ) + ")";
169 : }
170 0 : return sStr;
171 : }
172 :
173 :
174 :
175 0 : sal_uInt16 GetMetricId( SfxMapUnit eUnit )
176 : {
177 0 : sal_uInt16 nId = RID_SVXITEMS_METRIC_MM;
178 :
179 0 : switch ( eUnit )
180 : {
181 : case SFX_MAPUNIT_100TH_MM:
182 : case SFX_MAPUNIT_10TH_MM:
183 : case SFX_MAPUNIT_MM:
184 0 : nId = RID_SVXITEMS_METRIC_MM;
185 0 : break;
186 :
187 : case SFX_MAPUNIT_CM:
188 0 : nId = RID_SVXITEMS_METRIC_CM;
189 0 : break;
190 :
191 : case SFX_MAPUNIT_1000TH_INCH:
192 : case SFX_MAPUNIT_100TH_INCH:
193 : case SFX_MAPUNIT_10TH_INCH:
194 : case SFX_MAPUNIT_INCH:
195 0 : nId = RID_SVXITEMS_METRIC_INCH;
196 0 : break;
197 :
198 : case SFX_MAPUNIT_POINT:
199 0 : nId = RID_SVXITEMS_METRIC_POINT;
200 0 : break;
201 :
202 : case SFX_MAPUNIT_TWIP:
203 0 : nId = RID_SVXITEMS_METRIC_TWIP;
204 0 : break;
205 :
206 : case SFX_MAPUNIT_PIXEL:
207 0 : nId = RID_SVXITEMS_METRIC_PIXEL;
208 0 : break;
209 :
210 : default:
211 : OSL_FAIL( "not supported mapunit" );
212 : }
213 0 : return nId;
214 : }
215 :
216 :
217 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|