Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /**
57 : * @file
58 : * For LWP filter architecture prototype - table cell numerics format
59 : */
60 : /*************************************************************************
61 : * Change History
62 : Mar 2005 Created
63 : ************************************************************************/
64 :
65 : #include "lwpnumericfmt.hxx"
66 :
67 4 : LwpCurrencyPool LwpNumericFormat::m_aCurrencyInfo;
68 :
69 : /**
70 : *
71 : * @date 03/26/2005
72 : * @param
73 : * @param
74 : * @return
75 : */
76 0 : OUString LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat)
77 : {
78 0 : return m_aCurrencyInfo[nFormat].sSymbol;
79 : }
80 :
81 : /**
82 : *
83 : * @date 03/26/2005
84 : * @param
85 : * @param
86 : * @return sal_Bool.
87 : */
88 0 : bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat)
89 : {
90 0 : return m_aCurrencyInfo[nFormat].bPost;
91 : }
92 :
93 : /**
94 : *
95 : * @date 03/26/2005
96 : * @param
97 : * @param
98 : * @return sal_Bool.
99 : */
100 0 : bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat)
101 : {
102 0 : return m_aCurrencyInfo[nFormat].bShowSpace;
103 : }
104 :
105 : /**
106 : *
107 : * @date 03/26/2005
108 : * @param
109 : * @param
110 : * @return
111 : */
112 24 : XFStyle* LwpLayoutNumerics::Convert()
113 : {
114 24 : return cNumerics.Convert();
115 : }
116 :
117 : /**
118 : *
119 : * @date 03/26/2005
120 : * @param
121 : * @param
122 : * @return sal_Bool.
123 : */
124 6 : void LwpLayoutNumerics::Read()
125 : {
126 6 : LwpVirtualPiece::Read();
127 :
128 6 : if(LwpFileHeader::m_nFileRevision >= 0x000b)
129 : {
130 6 : cNumerics.Read();
131 6 : m_pObjStrm->SkipExtra();
132 : }
133 6 : }
134 :
135 : /**
136 : *
137 : * @date 03/26/2005
138 : * @param
139 : * @param
140 : * @return sal_Bool.
141 : */
142 18 : void LwpNumericFormatSubset::QuickRead(LwpObjectStream* pStrm)
143 : {
144 18 : cColor.Read(pStrm);
145 18 : cPrefix.Read(pStrm);
146 18 : cSuffix.Read(pStrm);
147 18 : cSubFlags = pStrm->QuickReaduInt16();
148 :
149 18 : pStrm->SkipExtra();
150 18 : }
151 : /**
152 : *
153 : * @date 03/26/2005
154 : * @param
155 : * @param
156 : * @return.
157 : */
158 24 : LwpColor LwpNumericFormatSubset::GetColor()
159 : {
160 24 : if (cSubFlags&0x04)
161 : {
162 0 : return cColor;
163 : }
164 : else
165 : {
166 24 : return LwpColor();
167 : }
168 : }
169 18 : LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
170 : {
171 18 : }
172 18 : LwpNumericFormatSubset::~LwpNumericFormatSubset()
173 : {
174 18 : }
175 :
176 6 : LwpNumericFormat::LwpNumericFormat(LwpObjectStream * pStrm)
177 : : m_pObjStrm(pStrm)
178 : , cFlags(0)
179 : , cFormat(FMT_DEFAULT)
180 6 : , cDecimalPlaces(0)
181 : {
182 : assert(pStrm);
183 6 : }
184 : /**
185 : * Read number format from wordpro file
186 : * @date 03/26/2005
187 : * @param
188 : * @param
189 : * @return
190 : */
191 6 : void LwpNumericFormat::Read()
192 : {
193 6 : LwpObjectStream* pStrm = m_pObjStrm;
194 :
195 6 : if(LwpFileHeader::m_nFileRevision >= 0x000b)
196 : {
197 6 : cFlags = pStrm->QuickReaduInt16();
198 6 : cDecimalPlaces = pStrm->QuickReaduInt16();
199 6 : cFormat = pStrm->QuickReaduInt16();
200 :
201 6 : cAnyNumber.QuickRead(pStrm);
202 6 : cZero.QuickRead(pStrm);
203 6 : cNegative.QuickRead(pStrm);
204 :
205 6 : pStrm->SkipExtra();
206 : }
207 6 : }
208 : /**
209 : *
210 : * @date 03/26/2005
211 : * @param
212 : * @param
213 : * @return sal_Bool.
214 : */
215 24 : bool LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format)
216 : {
217 24 : switch (Format)
218 : {
219 : case FMT_ARGENTINEANPESO:
220 : case FMT_AUSTRALIANDOLLAR:
221 : case FMT_AUSTRIANSCHILLING:
222 : case FMT_BELGIANFRANC:
223 : case FMT_BRAZILIANCRUZEIRO:
224 : case FMT_BRITISHPOUND:
225 : case FMT_CANADIANDOLLAR:
226 : case FMT_CHINESEYUAN:
227 : case FMT_CZECHKORUNA:
228 : case FMT_DANISHKRONE:
229 : case FMT_ECU:
230 : case FMT_FINNISHMARKKA:
231 : case FMT_FRENCHFRANC:
232 : case FMT_GREEKDRACHMA:
233 : case FMT_HONGKONGDOLLAR:
234 : case FMT_HUNGARIANFORINT:
235 : case FMT_INDIANRUPEE:
236 : case FMT_INDONESIANRUPIAH:
237 : case FMT_IRISHPUNT:
238 : case FMT_LUXEMBOURGFRANC:
239 : case FMT_MALAYSIANRINGGIT:
240 : case FMT_MEXICANPESO:
241 : case FMT_NETHERLANDSGUILDER:
242 : case FMT_NEWZEALANDDOLLAR:
243 : case FMT_NORWEGIANKRONE:
244 : case FMT_POLISHZLOTY:
245 : case FMT_PORTUGUESEESCUDO:
246 : case FMT_ROMANIANLEI:
247 : case FMT_RUSSIANRUBLE:
248 : case FMT_SINGAPOREDOLLAR:
249 : case FMT_SLOVAKIANKORUNA:
250 : case FMT_SLOVENIANTHOLAR:
251 : case FMT_SOUTHAFRICANRAND:
252 : case FMT_SOUTHKOREANWON:
253 : case FMT_SWEDISHKRONA:
254 : case FMT_SWISSFRANC:
255 : case FMT_TAIWANDOLLAR:
256 : case FMT_THAIBAHT:
257 : case FMT_USDOLLAR:
258 : case FMT_OTHERCURRENCY:
259 : case FMT_GERMANMARK:
260 : case FMT_ITALIANLIRA:
261 : case FMT_JAPANESEYEN:
262 : case FMT_SPANISHPESETA:
263 : case FMT_EURO:
264 0 : return true;
265 :
266 : default:
267 24 : return false;
268 : }
269 : }
270 : /**
271 : *
272 : * @date 03/26/2005
273 : * @param
274 : * @param
275 : * @return.
276 : */
277 : sal_uInt16
278 24 : LwpNumericFormat::GetDecimalPlaces()
279 : {
280 24 : if (IsDecimalPlacesOverridden())
281 8 : return cDecimalPlaces;
282 16 : return GetDefaultDecimalPlaces(cFormat);
283 : }
284 : /**
285 : * Make the currency string.
286 : * @date 03/26/2005
287 : * @param
288 : * @param
289 : * @return
290 : */
291 0 : void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber, OUString& aPrefix, OUString& aSuffix, bool bNegtive)
292 : {
293 0 : aPrefix = aNumber.GetPrefix();
294 0 : aSuffix = aNumber.GetSuffix();
295 :
296 : //Make the default prefix and suffix
297 0 : OUString aSymbol = m_aCurrencyInfo.GetCurrencySymbol(cFormat);
298 0 : bool bPost = m_aCurrencyInfo.IsSymbolPost(cFormat);
299 0 : bool bShowSpace = m_aCurrencyInfo.IsShowSpace(cFormat);
300 0 : if ( aNumber.IsDefaultPrefix())
301 : {
302 0 : if (bNegtive)
303 : {
304 0 : aPrefix = "(";
305 : }
306 0 : if (!bPost)
307 : {
308 0 : aPrefix += aSymbol;
309 0 : if (bShowSpace)
310 : {
311 0 : aPrefix += " ";
312 : }
313 : }
314 : }
315 0 : if ( aNumber.IsDefaultSuffix())
316 : {
317 0 : if (bPost)
318 : {
319 0 : aSuffix = aSymbol;
320 0 : if (bShowSpace)
321 : {
322 0 : aSuffix = " " + aSuffix;
323 : }
324 :
325 : }
326 :
327 0 : if (bNegtive)
328 : {
329 0 : aSuffix += ")";
330 : }
331 0 : }
332 0 : }
333 : /**
334 : *
335 : * @date 03/26/2005
336 : * @param
337 : * @param
338 : * @return
339 : */
340 24 : void LwpNumericFormat::SetNumberType(XFNumberStyle* pStyle)
341 : {
342 24 : switch(cFormat)
343 : {
344 : case FMT_PERCENT:
345 : {
346 0 : pStyle->SetNumberType(enumXFNumberPercent);
347 : }
348 0 : break;
349 :
350 : case FMT_COMMA:
351 : {
352 0 : pStyle->SetNumberType(enumXFNumberNumber);
353 0 : pStyle->SetGroup();
354 : }
355 0 : break;
356 : case FMT_SCIENTIFIC:
357 : {
358 0 : pStyle->SetNumberType(enumXFNumberScientific);
359 : }
360 0 : break;
361 : case FMT_FIXED:
362 : case FMT_GENERAL:
363 : {
364 0 : pStyle->SetNumberType(enumXFNumberNumber);
365 : }
366 0 : break;
367 : default://including text type, which is not a style of number format in SODC
368 : {
369 24 : pStyle->SetNumberType(enumXFText);
370 : }
371 24 : break;
372 : }
373 24 : }
374 : /**
375 : * Make the xml content of number format
376 : * @date 03/26/2005
377 : * @param
378 : * @param
379 : * @return XFStyle*
380 : */
381 24 : XFStyle* LwpNumericFormat::Convert()
382 : {
383 24 : XFNumberStyle* pStyle = new XFNumberStyle;
384 48 : OUString aPrefix, aSuffix,aNegPrefix,aNegSuffix;
385 48 : LwpColor aColor, aNegativeColor;
386 :
387 24 : if (IsCurrencyFormat(cFormat))
388 : {
389 0 : pStyle->SetNumberType(enuMXFNumberCurrency);
390 0 : pStyle->SetGroup();
391 0 : GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
392 0 : GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,true);
393 : }
394 : else
395 : {
396 24 : SetNumberType(pStyle);
397 : {//Anynumber
398 24 : aPrefix = cAnyNumber.GetPrefix();
399 : //Set suffix
400 24 : aSuffix = cAnyNumber.GetSuffix();
401 : //Set color
402 24 : aColor = cAnyNumber.GetColor();
403 : }
404 :
405 24 : if (!IsNegativeOverridden())
406 : {
407 24 : aNegPrefix = aPrefix;
408 24 : aNegSuffix = aSuffix;
409 24 : aNegativeColor = aColor;
410 : }
411 : else
412 : {//negative
413 0 : aNegPrefix = cNegative.GetPrefix();
414 0 : aNegSuffix = cNegative.GetSuffix();
415 0 : aNegativeColor = cNegative.GetColor();
416 : }
417 24 : if (FMT_COMMA==cFormat)
418 : {
419 0 : if (cNegative.IsDefaultPrefix() && aNegPrefix.isEmpty())
420 : {
421 0 : aNegPrefix = "(";
422 : }
423 0 : if (cNegative.IsDefaultSuffix() && aNegSuffix.isEmpty())
424 : {
425 0 : aNegSuffix = ")";
426 : }
427 : }
428 :
429 : }
430 :
431 24 : pStyle->SetDecimalDigits(GetDecimalPlaces());
432 :
433 24 : aPrefix = reencode(aPrefix);
434 24 : aSuffix = reencode(aSuffix);
435 24 : aNegPrefix = reencode(aNegPrefix);
436 24 : aNegSuffix = reencode(aNegSuffix);
437 :
438 : {//Anynumber
439 : //Set prefix
440 24 : pStyle->SetPrefix(aPrefix);
441 : //Set suffix
442 24 : pStyle->SetSurfix(aSuffix);
443 24 : pStyle->SetColor( XFColor( (sal_uInt8)aColor.GetRed(),
444 24 : (sal_uInt8)aColor.GetGreen(),
445 72 : (sal_uInt8)aColor.GetBlue()) );
446 : }
447 : {//Negtive
448 24 : pStyle->SetNegativeStyle( aNegPrefix, aNegSuffix, XFColor((sal_uInt8)aNegativeColor.GetRed(),
449 24 : (sal_uInt8)aNegativeColor.GetGreen(),
450 72 : (sal_uInt8)aNegativeColor.GetBlue()) );
451 : }
452 :
453 48 : return pStyle;
454 : }
455 : /**
456 : *
457 : * @descrption for SODC_2754
458 : * @date 04/04/2006
459 : * @param
460 : * @param
461 : * @return fix wrong encoding of POUND symbol
462 : */
463 96 : OUString LwpNumericFormat::reencode(const OUString& sCode)
464 : {
465 96 : const sal_Unicode * pString = sCode.getStr();
466 96 : sal_uInt16 nLen = sCode.getLength();
467 96 : bool bFound = false;
468 : sal_uInt16 i;
469 96 : sal_Unicode *pBuff = new sal_Unicode[sCode.getLength()];
470 :
471 96 : for (i=0; i< sCode.getLength() - 1; i++)
472 : {
473 0 : if ( (pString[i] == 0x00a1) && (pString[i+1] == 0x00ea))
474 : {
475 0 : bFound = true;
476 0 : break;
477 : }
478 0 : pBuff[i] = pString[i];
479 : }
480 96 : if (bFound)
481 : {
482 0 : pBuff[i] = 0xffe1;
483 0 : for (sal_Int32 j=i+1; j < sCode.getLength() - 1; ++j)
484 : {
485 0 : pBuff[j] = pString[j+1];
486 : }
487 0 : OUString sRet(pBuff, nLen - 1);
488 0 : delete [] pBuff;
489 0 : return sRet;
490 : }
491 :
492 96 : delete [] pBuff;
493 96 : return sCode;
494 : }
495 :
496 : /**
497 : *
498 : * @date 03/26/2005
499 : * @param
500 : * @param
501 : * @return
502 : */
503 : sal_uInt16
504 16 : LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format)
505 : {
506 16 : switch (Format)
507 : {
508 : case FMT_ARGENTINEANPESO:
509 : case FMT_AUSTRALIANDOLLAR:
510 : case FMT_AUSTRIANSCHILLING:
511 : case FMT_BELGIANFRANC:
512 : case FMT_BRAZILIANCRUZEIRO:
513 : case FMT_BRITISHPOUND:
514 : case FMT_CANADIANDOLLAR:
515 : case FMT_CHINESEYUAN:
516 : case FMT_CZECHKORUNA:
517 : case FMT_DANISHKRONE:
518 : case FMT_ECU:
519 : case FMT_FINNISHMARKKA:
520 : case FMT_FRENCHFRANC:
521 : case FMT_GERMANMARK:
522 : case FMT_HONGKONGDOLLAR:
523 : case FMT_HUNGARIANFORINT:
524 : case FMT_INDIANRUPEE:
525 : case FMT_INDONESIANRUPIAH:
526 : case FMT_IRISHPUNT:
527 : case FMT_LUXEMBOURGFRANC:
528 : case FMT_MALAYSIANRINGGIT:
529 : case FMT_MEXICANPESO:
530 : case FMT_NETHERLANDSGUILDER:
531 : case FMT_NEWZEALANDDOLLAR:
532 : case FMT_NORWEGIANKRONE:
533 : case FMT_POLISHZLOTY:
534 : case FMT_PORTUGUESEESCUDO:
535 : case FMT_ROMANIANLEI:
536 : case FMT_RUSSIANRUBLE:
537 : case FMT_SINGAPOREDOLLAR:
538 : case FMT_SLOVAKIANKORUNA:
539 : case FMT_SLOVENIANTHOLAR:
540 : case FMT_SOUTHAFRICANRAND:
541 : case FMT_SOUTHKOREANWON:
542 : case FMT_SWEDISHKRONA:
543 : case FMT_SWISSFRANC:
544 : case FMT_TAIWANDOLLAR:
545 : case FMT_THAIBAHT:
546 : case FMT_USDOLLAR:
547 : case FMT_OTHERCURRENCY:
548 : case FMT_EURO:
549 0 : return 2;
550 :
551 : case FMT_GREEKDRACHMA:
552 : case FMT_ITALIANLIRA:
553 : case FMT_JAPANESEYEN:
554 : case FMT_SPANISHPESETA:
555 0 : return 0;
556 :
557 : case FMT_DEFAULT:
558 : case FMT_GENERAL:
559 : case FMT_FIXED:
560 : case FMT_COMMA:
561 : case FMT_PERCENT:
562 : case FMT_SCIENTIFIC:
563 : default:
564 16 : return 2;
565 : }
566 12 : }
567 :
568 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|