update credits
[LibreOffice.git] / lotuswordpro / source / filter / lwpnumericfmt.cxx
blob4956575ec1ba30f75b758ebbb88301a73f874e58
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
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
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.
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.
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
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.
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.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /**
57 * @file
58 * For LWP filter architecture prototype - table cell numerics format
60 /*************************************************************************
61 * Change History
62 Mar 2005 Created
63 ************************************************************************/
65 #include "lwpnumericfmt.hxx"
67 ///////////////////////////////////////////////////////////////////
68 LwpCurrencyPool LwpNumericFormat::m_aCurrencyInfo;
70 /**
72 * @date 03/26/2005
73 * @param
74 * @param
75 * @return
77 String LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat)
79 return m_aCurrencyInfo[nFormat].sSymbol;
82 /**
84 * @date 03/26/2005
85 * @param
86 * @param
87 * @return sal_Bool.
89 sal_Bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat)
91 return m_aCurrencyInfo[nFormat].bPost;
94 /**
96 * @date 03/26/2005
97 * @param
98 * @param
99 * @return sal_Bool.
101 sal_Bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat)
103 return m_aCurrencyInfo[nFormat].bShowSpace;
105 //////////////////////////////////////////////////////////////////////
108 * @date 03/26/2005
109 * @param
110 * @param
111 * @return
113 XFStyle* LwpLayoutNumerics::Convert()
115 return cNumerics.Convert();
120 * @date 03/26/2005
121 * @param
122 * @param
123 * @return sal_Bool.
125 void LwpLayoutNumerics::Read()
127 LwpVirtualPiece::Read();
129 if(LwpFileHeader::m_nFileRevision >= 0x000b)
131 cNumerics.Read();
132 m_pObjStrm->SkipExtra();
135 ///////////////////////////////////////////////////////////////////
139 * @date 03/26/2005
140 * @param
141 * @param
142 * @return sal_Bool.
144 void LwpNumericFormatSubset::QuickRead(LwpObjectStream* pStrm)
146 cColor.Read(pStrm);
147 cPrefix.Read(pStrm);
148 cSuffix.Read(pStrm);
149 cSubFlags = pStrm->QuickReaduInt16();
151 pStrm->SkipExtra();
155 * @date 03/26/2005
156 * @param
157 * @param
158 * @return.
160 LwpColor LwpNumericFormatSubset::GetColor()
162 if (cSubFlags&0x04)
164 return cColor;
166 else
168 return LwpColor();
171 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
174 LwpNumericFormatSubset::~LwpNumericFormatSubset()
178 ///////////////////////////////////////////////////////////////////////////////////
179 LwpNumericFormat::LwpNumericFormat(LwpObjectStream * pStrm)
180 : cFormat(FMT_DEFAULT)
181 , cDecimalPlaces(0)
183 assert(pStrm);
184 m_pObjStrm = pStrm;
187 * Read number format from wordpro file
188 * @date 03/26/2005
189 * @param
190 * @param
191 * @return
193 void LwpNumericFormat::Read()
195 LwpObjectStream* pStrm = m_pObjStrm;
197 if(LwpFileHeader::m_nFileRevision >= 0x000b)
199 cFlags = pStrm->QuickReaduInt16();
200 cDecimalPlaces = pStrm->QuickReaduInt16();
201 cFormat = pStrm->QuickReaduInt16();
203 cAnyNumber.QuickRead(pStrm);
204 cZero.QuickRead(pStrm);
205 cNegative.QuickRead(pStrm);
207 pStrm->SkipExtra();
212 * @date 03/26/2005
213 * @param
214 * @param
215 * @return sal_Bool.
217 sal_Bool
218 LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format)
220 switch (Format)
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 return sal_True;
269 default:
270 return sal_False;
275 * @date 03/26/2005
276 * @param
277 * @param
278 * @return.
280 sal_uInt16
281 LwpNumericFormat::GetDecimalPlaces(void)
283 if (IsDecimalPlacesOverridden())
284 return cDecimalPlaces;
285 return GetDefaultDecimalPlaces(cFormat);
288 * Make the currency string.
289 * @date 03/26/2005
290 * @param
291 * @param
292 * @return
294 void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber, String& aPrefix, String& aSuffix, sal_Bool bNegtive)
296 aPrefix = aNumber.GetPrefix();
297 aSuffix = aNumber.GetSuffix();
299 //Make the default prefix and suffix
300 String aSymbol = m_aCurrencyInfo.GetCurrencySymbol(cFormat);
301 sal_Bool bPost = m_aCurrencyInfo.IsSymbolPost(cFormat);
302 sal_Bool bShowSpace = m_aCurrencyInfo.IsShowSpace(cFormat);
303 if ( aNumber.IsDefaultPrefix())
305 if (bNegtive)
307 aPrefix = OUString("(");
309 if (!bPost)
311 aPrefix += aSymbol;
312 if (bShowSpace)
314 aPrefix += OUString(" ");
318 if ( aNumber.IsDefaultSuffix())
320 if (bPost)
322 aSuffix = aSymbol;
323 if (bShowSpace)
325 aSuffix.Insert(OUString(" "),0);
330 if (bNegtive)
332 aSuffix += OUString(")");
338 * @date 03/26/2005
339 * @param
340 * @param
341 * @return
343 void LwpNumericFormat::SetNumberType(XFNumberStyle* pStyle)
345 switch(cFormat)
347 case FMT_PERCENT:
349 pStyle->SetNumberType(enumXFNumberPercent);
351 break;
353 case FMT_COMMA:
355 pStyle->SetNumberType(enumXFNumberNumber);
356 pStyle->SetGroup();
358 break;
359 case FMT_SCIENTIFIC:
361 pStyle->SetNumberType(enumXFNumberScientific);
363 break;
364 case FMT_FIXED:
365 case FMT_GENERAL:
367 pStyle->SetNumberType(enumXFNumberNumber);
369 break;
370 default://including text type, which is not a style of number format in SODC
372 pStyle->SetNumberType(enumXFText);
374 break;
378 * Make the xml content of number format
379 * @date 03/26/2005
380 * @param
381 * @param
382 * @return XFStyle*
384 XFStyle* LwpNumericFormat::Convert()
386 XFNumberStyle* pStyle = new XFNumberStyle;
387 String aPrefix, aSuffix,aNegPrefix,aNegSuffix;
388 LwpColor aColor, aNegativeColor;
390 if (IsCurrencyFormat(cFormat))
392 pStyle->SetNumberType(enuMXFNumberCurrency);
393 pStyle->SetGroup();
394 GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
395 GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,sal_True);
397 else
399 SetNumberType(pStyle);
400 {//Anynumber
401 aPrefix = cAnyNumber.GetPrefix();
402 //Set suffix
403 aSuffix = cAnyNumber.GetSuffix();
404 //Set color
405 aColor = cAnyNumber.GetColor();
408 if (!IsNegativeOverridden())
410 aNegPrefix = aPrefix;
411 aNegSuffix = aSuffix;
412 aNegativeColor = aColor;
414 else
415 {//negative
416 aNegPrefix = cNegative.GetPrefix();
417 aNegSuffix = cNegative.GetSuffix();
418 aNegativeColor = cNegative.GetColor();
420 if (FMT_COMMA==cFormat)
422 if (cNegative.IsDefaultPrefix() && aNegPrefix.Len() == 0)
424 aNegPrefix = OUString("(");
426 if (cNegative.IsDefaultSuffix() && aNegSuffix.Len() == 0)
428 aNegSuffix = OUString(")");
434 pStyle->SetDecimalDigits(GetDecimalPlaces());
436 aPrefix = reencode(aPrefix);
437 aSuffix = reencode(aSuffix);
438 aNegPrefix = reencode(aNegPrefix);
439 aNegSuffix = reencode(aNegSuffix);
441 {//Anynumber
442 //Set prefix
443 pStyle->SetPrefix(aPrefix);
444 //Set suffix
445 pStyle->SetSurfix(aSuffix);
446 pStyle->SetColor( XFColor( (sal_uInt8)aColor.GetRed(),
447 (sal_uInt8)aColor.GetGreen(),
448 (sal_uInt8)aColor.GetBlue()) );
450 {//Negtive
451 pStyle->SetNegativeStyle( aNegPrefix, aNegSuffix, XFColor((sal_uInt8)aNegativeColor.GetRed(),
452 (sal_uInt8)aNegativeColor.GetGreen(),
453 (sal_uInt8)aNegativeColor.GetBlue()) );
456 return pStyle;
460 * @descrption for SODC_2754
461 * @date 04/04/2006
462 * @param
463 * @param
464 * @return fix wrong encoding of POUND symbol
466 OUString LwpNumericFormat::reencode(OUString sCode)
468 const sal_Unicode * pString = sCode.getStr();
469 sal_uInt16 nLen = sCode.getLength();
470 sal_Bool bFound = sal_False;
471 sal_uInt16 i;
472 sal_Unicode *pBuff = new sal_Unicode[sCode.getLength()];
474 for (i=0; i< sCode.getLength() - 1; i++)
476 if ( (pString[i] == 0x00a1) && (pString[i+1] == 0x00ea))
478 bFound = sal_True;
479 break;
481 pBuff[i] = pString[i];
483 if (bFound)
485 pBuff[i] = 0xffe1;
486 for (sal_Int32 j=i+1; j < sCode.getLength() - 1; ++j)
488 pBuff[j] = pString[j+1];
490 OUString sRet(pBuff, nLen - 1);
491 delete [] pBuff;
492 return sRet;
495 delete [] pBuff;
496 return sCode;
501 * @date 03/26/2005
502 * @param
503 * @param
504 * @return
506 sal_uInt16
507 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format)
509 switch (Format)
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 return 2;
554 case FMT_GREEKDRACHMA:
555 case FMT_ITALIANLIRA:
556 case FMT_JAPANESEYEN:
557 case FMT_SPANISHPESETA:
558 return 0;
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 return 2;
571 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */