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