Bump version to 4.3-4
[LibreOffice.git] / lotuswordpro / source / filter / lwpnumericfmt.cxx
blob9d54213d8724510de5f42b40f901cef3b295722c
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 LwpCurrencyPool LwpNumericFormat::m_aCurrencyInfo;
69 /**
71 * @date 03/26/2005
72 * @param
73 * @param
74 * @return
76 OUString LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat)
78 return m_aCurrencyInfo[nFormat].sSymbol;
81 /**
83 * @date 03/26/2005
84 * @param
85 * @param
86 * @return sal_Bool.
88 bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat)
90 return m_aCurrencyInfo[nFormat].bPost;
93 /**
95 * @date 03/26/2005
96 * @param
97 * @param
98 * @return sal_Bool.
100 bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat)
102 return m_aCurrencyInfo[nFormat].bShowSpace;
107 * @date 03/26/2005
108 * @param
109 * @param
110 * @return
112 XFStyle* LwpLayoutNumerics::Convert()
114 return cNumerics.Convert();
119 * @date 03/26/2005
120 * @param
121 * @param
122 * @return sal_Bool.
124 void LwpLayoutNumerics::Read()
126 LwpVirtualPiece::Read();
128 if(LwpFileHeader::m_nFileRevision >= 0x000b)
130 cNumerics.Read();
131 m_pObjStrm->SkipExtra();
137 * @date 03/26/2005
138 * @param
139 * @param
140 * @return sal_Bool.
142 void LwpNumericFormatSubset::QuickRead(LwpObjectStream* pStrm)
144 cColor.Read(pStrm);
145 cPrefix.Read(pStrm);
146 cSuffix.Read(pStrm);
147 cSubFlags = pStrm->QuickReaduInt16();
149 pStrm->SkipExtra();
153 * @date 03/26/2005
154 * @param
155 * @param
156 * @return.
158 LwpColor LwpNumericFormatSubset::GetColor()
160 if (cSubFlags&0x04)
162 return cColor;
164 else
166 return LwpColor();
169 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
172 LwpNumericFormatSubset::~LwpNumericFormatSubset()
176 LwpNumericFormat::LwpNumericFormat(LwpObjectStream * pStrm)
177 : m_pObjStrm(pStrm)
178 , cFlags(0)
179 , cFormat(FMT_DEFAULT)
180 , cDecimalPlaces(0)
182 assert(pStrm);
185 * Read number format from wordpro file
186 * @date 03/26/2005
187 * @param
188 * @param
189 * @return
191 void LwpNumericFormat::Read()
193 LwpObjectStream* pStrm = m_pObjStrm;
195 if(LwpFileHeader::m_nFileRevision >= 0x000b)
197 cFlags = pStrm->QuickReaduInt16();
198 cDecimalPlaces = pStrm->QuickReaduInt16();
199 cFormat = pStrm->QuickReaduInt16();
201 cAnyNumber.QuickRead(pStrm);
202 cZero.QuickRead(pStrm);
203 cNegative.QuickRead(pStrm);
205 pStrm->SkipExtra();
210 * @date 03/26/2005
211 * @param
212 * @param
213 * @return sal_Bool.
215 bool LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format)
217 switch (Format)
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 return true;
266 default:
267 return false;
272 * @date 03/26/2005
273 * @param
274 * @param
275 * @return.
277 sal_uInt16
278 LwpNumericFormat::GetDecimalPlaces(void)
280 if (IsDecimalPlacesOverridden())
281 return cDecimalPlaces;
282 return GetDefaultDecimalPlaces(cFormat);
285 * Make the currency string.
286 * @date 03/26/2005
287 * @param
288 * @param
289 * @return
291 void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber, OUString& aPrefix, OUString& aSuffix, bool bNegtive)
293 aPrefix = aNumber.GetPrefix();
294 aSuffix = aNumber.GetSuffix();
296 //Make the default prefix and suffix
297 OUString aSymbol = m_aCurrencyInfo.GetCurrencySymbol(cFormat);
298 bool bPost = m_aCurrencyInfo.IsSymbolPost(cFormat);
299 bool bShowSpace = m_aCurrencyInfo.IsShowSpace(cFormat);
300 if ( aNumber.IsDefaultPrefix())
302 if (bNegtive)
304 aPrefix = "(";
306 if (!bPost)
308 aPrefix += aSymbol;
309 if (bShowSpace)
311 aPrefix += " ";
315 if ( aNumber.IsDefaultSuffix())
317 if (bPost)
319 aSuffix = aSymbol;
320 if (bShowSpace)
322 aSuffix = " " + aSuffix;
327 if (bNegtive)
329 aSuffix += ")";
335 * @date 03/26/2005
336 * @param
337 * @param
338 * @return
340 void LwpNumericFormat::SetNumberType(XFNumberStyle* pStyle)
342 switch(cFormat)
344 case FMT_PERCENT:
346 pStyle->SetNumberType(enumXFNumberPercent);
348 break;
350 case FMT_COMMA:
352 pStyle->SetNumberType(enumXFNumberNumber);
353 pStyle->SetGroup();
355 break;
356 case FMT_SCIENTIFIC:
358 pStyle->SetNumberType(enumXFNumberScientific);
360 break;
361 case FMT_FIXED:
362 case FMT_GENERAL:
364 pStyle->SetNumberType(enumXFNumberNumber);
366 break;
367 default://including text type, which is not a style of number format in SODC
369 pStyle->SetNumberType(enumXFText);
371 break;
375 * Make the xml content of number format
376 * @date 03/26/2005
377 * @param
378 * @param
379 * @return XFStyle*
381 XFStyle* LwpNumericFormat::Convert()
383 XFNumberStyle* pStyle = new XFNumberStyle;
384 OUString aPrefix, aSuffix,aNegPrefix,aNegSuffix;
385 LwpColor aColor, aNegativeColor;
387 if (IsCurrencyFormat(cFormat))
389 pStyle->SetNumberType(enuMXFNumberCurrency);
390 pStyle->SetGroup();
391 GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
392 GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,true);
394 else
396 SetNumberType(pStyle);
397 {//Anynumber
398 aPrefix = cAnyNumber.GetPrefix();
399 //Set suffix
400 aSuffix = cAnyNumber.GetSuffix();
401 //Set color
402 aColor = cAnyNumber.GetColor();
405 if (!IsNegativeOverridden())
407 aNegPrefix = aPrefix;
408 aNegSuffix = aSuffix;
409 aNegativeColor = aColor;
411 else
412 {//negative
413 aNegPrefix = cNegative.GetPrefix();
414 aNegSuffix = cNegative.GetSuffix();
415 aNegativeColor = cNegative.GetColor();
417 if (FMT_COMMA==cFormat)
419 if (cNegative.IsDefaultPrefix() && aNegPrefix.isEmpty())
421 aNegPrefix = "(";
423 if (cNegative.IsDefaultSuffix() && aNegSuffix.isEmpty())
425 aNegSuffix = ")";
431 pStyle->SetDecimalDigits(GetDecimalPlaces());
433 aPrefix = reencode(aPrefix);
434 aSuffix = reencode(aSuffix);
435 aNegPrefix = reencode(aNegPrefix);
436 aNegSuffix = reencode(aNegSuffix);
438 {//Anynumber
439 //Set prefix
440 pStyle->SetPrefix(aPrefix);
441 //Set suffix
442 pStyle->SetSurfix(aSuffix);
443 pStyle->SetColor( XFColor( (sal_uInt8)aColor.GetRed(),
444 (sal_uInt8)aColor.GetGreen(),
445 (sal_uInt8)aColor.GetBlue()) );
447 {//Negtive
448 pStyle->SetNegativeStyle( aNegPrefix, aNegSuffix, XFColor((sal_uInt8)aNegativeColor.GetRed(),
449 (sal_uInt8)aNegativeColor.GetGreen(),
450 (sal_uInt8)aNegativeColor.GetBlue()) );
453 return pStyle;
457 * @descrption for SODC_2754
458 * @date 04/04/2006
459 * @param
460 * @param
461 * @return fix wrong encoding of POUND symbol
463 OUString LwpNumericFormat::reencode(const OUString& sCode)
465 const sal_Unicode * pString = sCode.getStr();
466 sal_uInt16 nLen = sCode.getLength();
467 bool bFound = false;
468 sal_uInt16 i;
469 sal_Unicode *pBuff = new sal_Unicode[sCode.getLength()];
471 for (i=0; i< sCode.getLength() - 1; i++)
473 if ( (pString[i] == 0x00a1) && (pString[i+1] == 0x00ea))
475 bFound = true;
476 break;
478 pBuff[i] = pString[i];
480 if (bFound)
482 pBuff[i] = 0xffe1;
483 for (sal_Int32 j=i+1; j < sCode.getLength() - 1; ++j)
485 pBuff[j] = pString[j+1];
487 OUString sRet(pBuff, nLen - 1);
488 delete [] pBuff;
489 return sRet;
492 delete [] pBuff;
493 return sCode;
498 * @date 03/26/2005
499 * @param
500 * @param
501 * @return
503 sal_uInt16
504 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format)
506 switch (Format)
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 return 2;
551 case FMT_GREEKDRACHMA:
552 case FMT_ITALIANLIRA:
553 case FMT_JAPANESEYEN:
554 case FMT_SPANISHPESETA:
555 return 0;
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 return 2;
568 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */