Branch data 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 : : ///////////////////////////////////////////////////////////////////
68 : 9 : LwpCurrencyPool LwpNumericFormat::m_aCurrencyInfo;
69 : :
70 : : /**
71 : : *
72 : : * @date 03/26/2005
73 : : * @param
74 : : * @param
75 : : * @return
76 : : */
77 : 0 : String LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat)
78 : : {
79 : 0 : return m_aCurrencyInfo[nFormat].sSymbol;
80 : : }
81 : :
82 : : /**
83 : : *
84 : : * @date 03/26/2005
85 : : * @param
86 : : * @param
87 : : * @return sal_Bool.
88 : : */
89 : 0 : sal_Bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat)
90 : : {
91 : 0 : return m_aCurrencyInfo[nFormat].bPost;
92 : : }
93 : :
94 : : /**
95 : : *
96 : : * @date 03/26/2005
97 : : * @param
98 : : * @param
99 : : * @return sal_Bool.
100 : : */
101 : 0 : sal_Bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat)
102 : : {
103 : 0 : return m_aCurrencyInfo[nFormat].bShowSpace;
104 : : }
105 : : //////////////////////////////////////////////////////////////////////
106 : : /**
107 : : *
108 : : * @date 03/26/2005
109 : : * @param
110 : : * @param
111 : : * @return
112 : : */
113 : 81 : XFStyle* LwpLayoutNumerics::Convert()
114 : : {
115 : 81 : return cNumerics.Convert();
116 : : }
117 : :
118 : : /**
119 : : *
120 : : * @date 03/26/2005
121 : : * @param
122 : : * @param
123 : : * @return sal_Bool.
124 : : */
125 : 18 : void LwpLayoutNumerics::Read()
126 : : {
127 : 18 : LwpVirtualPiece::Read();
128 : :
129 [ + - ]: 18 : if(LwpFileHeader::m_nFileRevision >= 0x000b)
130 : : {
131 : 18 : cNumerics.Read();
132 : 18 : m_pObjStrm->SkipExtra();
133 : : }
134 : 18 : }
135 : : ///////////////////////////////////////////////////////////////////
136 : :
137 : : /**
138 : : *
139 : : * @date 03/26/2005
140 : : * @param
141 : : * @param
142 : : * @return sal_Bool.
143 : : */
144 : 54 : void LwpNumericFormatSubset::QuickRead(LwpObjectStream* pStrm)
145 : : {
146 : 54 : cColor.Read(pStrm);
147 : 54 : cPrefix.Read(pStrm);
148 : 54 : cSuffix.Read(pStrm);
149 : 54 : cSubFlags = pStrm->QuickReaduInt16();
150 : :
151 : 54 : pStrm->SkipExtra();
152 : 54 : }
153 : : /**
154 : : *
155 : : * @date 03/26/2005
156 : : * @param
157 : : * @param
158 : : * @return.
159 : : */
160 : 81 : LwpColor LwpNumericFormatSubset::GetColor()
161 : : {
162 [ - + ]: 81 : if (cSubFlags&0x04)
163 : : {
164 : 0 : return cColor;
165 : : }
166 : : else
167 : : {
168 : 81 : return LwpColor();
169 : : }
170 : : }
171 [ + - ][ + - ]: 54 : LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
172 : : {
173 : 54 : }
174 [ + - ][ + - ]: 54 : LwpNumericFormatSubset::~LwpNumericFormatSubset()
175 : : {
176 : 54 : }
177 : :
178 : : ///////////////////////////////////////////////////////////////////////////////////
179 : 18 : LwpNumericFormat::LwpNumericFormat(LwpObjectStream * pStrm)
180 : : : cFormat(FMT_DEFAULT)
181 [ + - ][ + - ]: 18 : , cDecimalPlaces(0)
182 : : {
183 : : assert(pStrm);
184 : 18 : m_pObjStrm = pStrm;
185 : 18 : }
186 : : /**
187 : : * Read number format from wordpro file
188 : : * @date 03/26/2005
189 : : * @param
190 : : * @param
191 : : * @return
192 : : */
193 : 18 : void LwpNumericFormat::Read()
194 : : {
195 : 18 : LwpObjectStream* pStrm = m_pObjStrm;
196 : :
197 [ + - ]: 18 : if(LwpFileHeader::m_nFileRevision >= 0x000b)
198 : : {
199 : 18 : cFlags = pStrm->QuickReaduInt16();
200 : 18 : cDecimalPlaces = pStrm->QuickReaduInt16();
201 : 18 : cFormat = pStrm->QuickReaduInt16();
202 : :
203 : 18 : cAnyNumber.QuickRead(pStrm);
204 : 18 : cZero.QuickRead(pStrm);
205 : 18 : cNegative.QuickRead(pStrm);
206 : :
207 : 18 : pStrm->SkipExtra();
208 : : }
209 : 18 : }
210 : : /**
211 : : *
212 : : * @date 03/26/2005
213 : : * @param
214 : : * @param
215 : : * @return sal_Bool.
216 : : */
217 : : sal_Bool
218 : 81 : LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format)
219 : : {
220 [ - + ]: 81 : switch (Format)
221 : : {
222 : : case FMT_ARGENTINEANPESO:
223 : : case FMT_AUSTRALIANDOLLAR:
224 : : case FMT_AUSTRIANSCHILLING:
225 : : case FMT_BELGIANFRANC:
226 : : case FMT_BRAZILIANCRUZEIRO:
227 : : case FMT_BRITISHPOUND:
228 : : case FMT_CANADIANDOLLAR:
229 : : case FMT_CHINESEYUAN:
230 : : case FMT_CZECHKORUNA:
231 : : case FMT_DANISHKRONE:
232 : : case FMT_ECU:
233 : : case FMT_FINNISHMARKKA:
234 : : case FMT_FRENCHFRANC:
235 : : case FMT_GREEKDRACHMA:
236 : : case FMT_HONGKONGDOLLAR:
237 : : case FMT_HUNGARIANFORINT:
238 : : case FMT_INDIANRUPEE:
239 : : case FMT_INDONESIANRUPIAH:
240 : : case FMT_IRISHPUNT:
241 : : case FMT_LUXEMBOURGFRANC:
242 : : case FMT_MALAYSIANRINGGIT:
243 : : case FMT_MEXICANPESO:
244 : : case FMT_NETHERLANDSGUILDER:
245 : : case FMT_NEWZEALANDDOLLAR:
246 : : case FMT_NORWEGIANKRONE:
247 : : case FMT_POLISHZLOTY:
248 : : case FMT_PORTUGUESEESCUDO:
249 : : case FMT_ROMANIANLEI:
250 : : case FMT_RUSSIANRUBLE:
251 : : case FMT_SINGAPOREDOLLAR:
252 : : case FMT_SLOVAKIANKORUNA:
253 : : case FMT_SLOVENIANTHOLAR:
254 : : case FMT_SOUTHAFRICANRAND:
255 : : case FMT_SOUTHKOREANWON:
256 : : case FMT_SWEDISHKRONA:
257 : : case FMT_SWISSFRANC:
258 : : case FMT_TAIWANDOLLAR:
259 : : case FMT_THAIBAHT:
260 : : case FMT_USDOLLAR:
261 : : case FMT_OTHERCURRENCY:
262 : : case FMT_GERMANMARK:
263 : : case FMT_ITALIANLIRA:
264 : : case FMT_JAPANESEYEN:
265 : : case FMT_SPANISHPESETA:
266 : : case FMT_EURO:
267 : 0 : return sal_True;
268 : :
269 : : default:
270 : 81 : return sal_False;
271 : : }
272 : : }
273 : : /**
274 : : *
275 : : * @date 03/26/2005
276 : : * @param
277 : : * @param
278 : : * @return.
279 : : */
280 : : sal_uInt16
281 : 81 : LwpNumericFormat::GetDecimalPlaces(void)
282 : : {
283 [ + + ]: 81 : if (IsDecimalPlacesOverridden())
284 : 24 : return cDecimalPlaces;
285 : 81 : return GetDefaultDecimalPlaces(cFormat);
286 : : }
287 : : /**
288 : : * Make the currency string.
289 : : * @date 03/26/2005
290 : : * @param
291 : : * @param
292 : : * @return
293 : : */
294 : 0 : void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber, String& aPrefix, String& aSuffix, sal_Bool bNegtive)
295 : : {
296 [ # # ][ # # ]: 0 : aPrefix = aNumber.GetPrefix();
[ # # ]
297 [ # # ][ # # ]: 0 : aSuffix = aNumber.GetSuffix();
[ # # ]
298 : :
299 : : //Make the default prefix and suffix
300 [ # # ]: 0 : String aSymbol = m_aCurrencyInfo.GetCurrencySymbol(cFormat);
301 [ # # ]: 0 : sal_Bool bPost = m_aCurrencyInfo.IsSymbolPost(cFormat);
302 [ # # ]: 0 : sal_Bool bShowSpace = m_aCurrencyInfo.IsShowSpace(cFormat);
303 [ # # ]: 0 : if ( aNumber.IsDefaultPrefix())
304 : : {
305 [ # # ]: 0 : if (bNegtive)
306 : : {
307 [ # # ]: 0 : aPrefix = rtl::OUString("(");
308 : : }
309 [ # # ]: 0 : if (!bPost)
310 : : {
311 [ # # ]: 0 : aPrefix += aSymbol;
312 [ # # ]: 0 : if (bShowSpace)
313 : : {
314 [ # # ]: 0 : aPrefix += rtl::OUString(" ");
315 : : }
316 : : }
317 : : }
318 [ # # ]: 0 : if ( aNumber.IsDefaultSuffix())
319 : : {
320 [ # # ]: 0 : if (bPost)
321 : : {
322 [ # # ]: 0 : aSuffix = aSymbol;
323 [ # # ]: 0 : if (bShowSpace)
324 : : {
325 [ # # ][ # # ]: 0 : aSuffix.Insert(rtl::OUString(" "),0);
[ # # ]
326 : : }
327 : :
328 : : }
329 : :
330 [ # # ]: 0 : if (bNegtive)
331 : : {
332 [ # # ]: 0 : aSuffix += rtl::OUString(")");
333 : : }
334 [ # # ]: 0 : }
335 : 0 : }
336 : : /**
337 : : *
338 : : * @date 03/26/2005
339 : : * @param
340 : : * @param
341 : : * @return
342 : : */
343 : 81 : void LwpNumericFormat::SetNumberType(XFNumberStyle* pStyle)
344 : : {
345 [ - - - - : 81 : switch(cFormat)
+ ]
346 : : {
347 : : case FMT_PERCENT:
348 : : {
349 : 0 : pStyle->SetNumberType(enumXFNumberPercent);
350 : : }
351 : 0 : break;
352 : :
353 : : case FMT_COMMA:
354 : : {
355 : 0 : pStyle->SetNumberType(enumXFNumberNumber);
356 : 0 : pStyle->SetGroup();
357 : : }
358 : 0 : break;
359 : : case FMT_SCIENTIFIC:
360 : : {
361 : 0 : pStyle->SetNumberType(enumXFNumberScientific);
362 : : }
363 : 0 : break;
364 : : case FMT_FIXED:
365 : : case FMT_GENERAL:
366 : : {
367 : 0 : pStyle->SetNumberType(enumXFNumberNumber);
368 : : }
369 : 0 : break;
370 : : default://including text type, which is not a style of number format in SODC
371 : : {
372 : 81 : pStyle->SetNumberType(enumXFText);
373 : : }
374 : 81 : break;
375 : : }
376 : 81 : }
377 : : /**
378 : : * Make the xml content of number format
379 : : * @date 03/26/2005
380 : : * @param
381 : : * @param
382 : : * @return XFStyle*
383 : : */
384 : 81 : XFStyle* LwpNumericFormat::Convert()
385 : : {
386 [ + - ][ + - ]: 81 : XFNumberStyle* pStyle = new XFNumberStyle;
387 [ + - ][ + - ]: 81 : String aPrefix, aSuffix,aNegPrefix,aNegSuffix;
[ + - ][ + - ]
388 : 81 : LwpColor aColor, aNegativeColor;
389 : :
390 [ - + ]: 81 : if (IsCurrencyFormat(cFormat))
391 : : {
392 : 0 : pStyle->SetNumberType(enuMXFNumberCurrency);
393 : 0 : pStyle->SetGroup();
394 [ # # ][ # # ]: 0 : GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
[ # # ]
395 [ # # ][ # # ]: 0 : GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,sal_True);
[ # # ]
396 : : }
397 : : else
398 : : {
399 : 81 : SetNumberType(pStyle);
400 : : {//Anynumber
401 [ + - ][ + - ]: 81 : aPrefix = cAnyNumber.GetPrefix();
[ + - ]
402 : : //Set suffix
403 [ + - ][ + - ]: 81 : aSuffix = cAnyNumber.GetSuffix();
[ + - ]
404 : : //Set color
405 [ + - ]: 81 : aColor = cAnyNumber.GetColor();
406 : : }
407 : :
408 [ + - ]: 81 : if (!IsNegativeOverridden())
409 : : {
410 [ + - ]: 81 : aNegPrefix = aPrefix;
411 [ + - ]: 81 : aNegSuffix = aSuffix;
412 [ + - ]: 81 : aNegativeColor = aColor;
413 : : }
414 : : else
415 : : {//negative
416 [ # # ][ # # ]: 0 : aNegPrefix = cNegative.GetPrefix();
[ # # ]
417 [ # # ][ # # ]: 0 : aNegSuffix = cNegative.GetSuffix();
[ # # ]
418 [ # # ]: 0 : aNegativeColor = cNegative.GetColor();
419 : : }
420 [ - + ]: 81 : if (FMT_COMMA==cFormat)
421 : : {
422 [ # # ][ # # ]: 0 : if (cNegative.IsDefaultPrefix() && aNegPrefix.Len() == 0)
[ # # ]
423 : : {
424 [ # # ]: 0 : aNegPrefix = rtl::OUString("(");
425 : : }
426 [ # # ][ # # ]: 0 : if (cNegative.IsDefaultSuffix() && aNegSuffix.Len() == 0)
[ # # ]
427 : : {
428 [ # # ]: 0 : aNegSuffix = rtl::OUString(")");
429 : : }
430 : : }
431 : :
432 : : }
433 : :
434 [ + - ]: 81 : pStyle->SetDecimalDigits(GetDecimalPlaces());
435 : :
436 [ + - ][ + - ]: 81 : aPrefix = reencode(aPrefix);
[ + - ]
437 [ + - ][ + - ]: 81 : aSuffix = reencode(aSuffix);
[ + - ]
438 [ + - ][ + - ]: 81 : aNegPrefix = reencode(aNegPrefix);
[ + - ]
439 [ + - ][ + - ]: 81 : aNegSuffix = reencode(aNegSuffix);
[ + - ]
440 : :
441 : : {//Anynumber
442 : : //Set prefix
443 [ + - ]: 81 : pStyle->SetPrefix(aPrefix);
444 : : //Set suffix
445 [ + - ]: 81 : pStyle->SetSurfix(aSuffix);
446 : 81 : pStyle->SetColor( XFColor( (sal_uInt8)aColor.GetRed(),
447 : 81 : (sal_uInt8)aColor.GetGreen(),
448 : 162 : (sal_uInt8)aColor.GetBlue()) );
449 : : }
450 : : {//Negtive
451 : 81 : pStyle->SetNegativeStyle( aNegPrefix, aNegSuffix, XFColor((sal_uInt8)aNegativeColor.GetRed(),
452 : 81 : (sal_uInt8)aNegativeColor.GetGreen(),
453 [ + - ][ + - ]: 162 : (sal_uInt8)aNegativeColor.GetBlue()) );
454 : : }
455 : :
456 [ + - ][ + - ]: 81 : return pStyle;
[ + - ][ + - ]
457 : : }
458 : : /**
459 : : *
460 : : * @descrption for SODC_2754
461 : : * @date 04/04/2006
462 : : * @param
463 : : * @param
464 : : * @return fix wrong encoding of POUND symbol
465 : : */
466 : 324 : OUString LwpNumericFormat::reencode(OUString sCode)
467 : : {
468 : 324 : const sal_Unicode * pString = sCode.getStr();
469 : 324 : sal_uInt16 nLen = sCode.getLength();
470 : 324 : sal_Bool bFound = sal_False;
471 : : sal_uInt16 i;
472 : 324 : sal_Unicode *pBuff = new sal_Unicode[sCode.getLength()];
473 : :
474 [ - + ]: 324 : for (i=0; i< sCode.getLength() - 1; i++)
475 : : {
476 [ # # ][ # # ]: 0 : if ( (pString[i] == 0x00a1) && (pString[i+1] == 0x00ea))
477 : : {
478 : 0 : bFound = sal_True;
479 : 0 : break;
480 : : }
481 : 0 : pBuff[i] = pString[i];
482 : : }
483 [ - + ]: 324 : if (bFound)
484 : : {
485 : 0 : pBuff[i] = 0xffe1;
486 [ # # ]: 0 : for (sal_Int32 j=i+1; j < sCode.getLength() - 1; ++j)
487 : : {
488 : 0 : pBuff[j] = pString[j+1];
489 : : }
490 : 0 : OUString sRet(pBuff, nLen - 1);
491 [ # # ]: 0 : delete [] pBuff;
492 : 0 : return sRet;
493 : : }
494 : :
495 [ + - ]: 324 : delete [] pBuff;
496 : 324 : return sCode;
497 : : }
498 : :
499 : : /**
500 : : *
501 : : * @date 03/26/2005
502 : : * @param
503 : : * @param
504 : : * @return
505 : : */
506 : : sal_uInt16
507 : 57 : LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format)
508 : : {
509 [ - - + ]: 57 : switch (Format)
510 : : {
511 : : case FMT_ARGENTINEANPESO:
512 : : case FMT_AUSTRALIANDOLLAR:
513 : : case FMT_AUSTRIANSCHILLING:
514 : : case FMT_BELGIANFRANC:
515 : : case FMT_BRAZILIANCRUZEIRO:
516 : : case FMT_BRITISHPOUND:
517 : : case FMT_CANADIANDOLLAR:
518 : : case FMT_CHINESEYUAN:
519 : : case FMT_CZECHKORUNA:
520 : : case FMT_DANISHKRONE:
521 : : case FMT_ECU:
522 : : case FMT_FINNISHMARKKA:
523 : : case FMT_FRENCHFRANC:
524 : : case FMT_GERMANMARK:
525 : : case FMT_HONGKONGDOLLAR:
526 : : case FMT_HUNGARIANFORINT:
527 : : case FMT_INDIANRUPEE:
528 : : case FMT_INDONESIANRUPIAH:
529 : : case FMT_IRISHPUNT:
530 : : case FMT_LUXEMBOURGFRANC:
531 : : case FMT_MALAYSIANRINGGIT:
532 : : case FMT_MEXICANPESO:
533 : : case FMT_NETHERLANDSGUILDER:
534 : : case FMT_NEWZEALANDDOLLAR:
535 : : case FMT_NORWEGIANKRONE:
536 : : case FMT_POLISHZLOTY:
537 : : case FMT_PORTUGUESEESCUDO:
538 : : case FMT_ROMANIANLEI:
539 : : case FMT_RUSSIANRUBLE:
540 : : case FMT_SINGAPOREDOLLAR:
541 : : case FMT_SLOVAKIANKORUNA:
542 : : case FMT_SLOVENIANTHOLAR:
543 : : case FMT_SOUTHAFRICANRAND:
544 : : case FMT_SOUTHKOREANWON:
545 : : case FMT_SWEDISHKRONA:
546 : : case FMT_SWISSFRANC:
547 : : case FMT_TAIWANDOLLAR:
548 : : case FMT_THAIBAHT:
549 : : case FMT_USDOLLAR:
550 : : case FMT_OTHERCURRENCY:
551 : : case FMT_EURO:
552 : 0 : return 2;
553 : :
554 : : case FMT_GREEKDRACHMA:
555 : : case FMT_ITALIANLIRA:
556 : : case FMT_JAPANESEYEN:
557 : : case FMT_SPANISHPESETA:
558 : 0 : return 0;
559 : :
560 : : case FMT_DEFAULT:
561 : : case FMT_GENERAL:
562 : : case FMT_FIXED:
563 : : case FMT_COMMA:
564 : : case FMT_PERCENT:
565 : : case FMT_SCIENTIFIC:
566 : : default:
567 : 57 : return 2;
568 : : }
569 [ + - ][ + - ]: 27 : }
570 : :
571 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|