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,
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 ************************************************************************/
58 * For LWP filter architecture prototype - table cell numerics format
60 /*************************************************************************
63 ************************************************************************/
65 #include "lwpnumericfmt.hxx"
67 ///////////////////////////////////////////////////////////////////
68 LwpCurrencyPool
LwpNumericFormat::m_aCurrencyInfo
;
77 String
LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat
)
79 return m_aCurrencyInfo
[nFormat
].sSymbol
;
89 sal_Bool
LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat
)
91 return m_aCurrencyInfo
[nFormat
].bPost
;
101 sal_Bool
LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat
)
103 return m_aCurrencyInfo
[nFormat
].bShowSpace
;
105 //////////////////////////////////////////////////////////////////////
113 XFStyle
* LwpLayoutNumerics::Convert()
115 return cNumerics
.Convert();
125 void LwpLayoutNumerics::Read()
127 LwpVirtualPiece::Read();
129 if(LwpFileHeader::m_nFileRevision
>= 0x000b)
132 m_pObjStrm
->SkipExtra();
135 ///////////////////////////////////////////////////////////////////
144 void LwpNumericFormatSubset::QuickRead(LwpObjectStream
* pStrm
)
149 cSubFlags
= pStrm
->QuickReaduInt16();
160 LwpColor
LwpNumericFormatSubset::GetColor()
171 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
174 LwpNumericFormatSubset::~LwpNumericFormatSubset()
178 ///////////////////////////////////////////////////////////////////////////////////
179 LwpNumericFormat::LwpNumericFormat(LwpObjectStream
* pStrm
)
180 : cFormat(FMT_DEFAULT
)
187 * Read number format from wordpro file
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
);
218 LwpNumericFormat::IsCurrencyFormat(sal_uInt16 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
:
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
:
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
:
258 case FMT_TAIWANDOLLAR
:
261 case FMT_OTHERCURRENCY
:
263 case FMT_ITALIANLIRA
:
264 case FMT_JAPANESEYEN
:
265 case FMT_SPANISHPESETA
:
281 LwpNumericFormat::GetDecimalPlaces(void)
283 if (IsDecimalPlacesOverridden())
284 return cDecimalPlaces
;
285 return GetDefaultDecimalPlaces(cFormat
);
288 * Make the currency string.
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())
307 aPrefix
= OUString("(");
314 aPrefix
+= OUString(" ");
318 if ( aNumber
.IsDefaultSuffix())
325 aSuffix
.Insert(OUString(" "),0);
332 aSuffix
+= OUString(")");
343 void LwpNumericFormat::SetNumberType(XFNumberStyle
* pStyle
)
349 pStyle
->SetNumberType(enumXFNumberPercent
);
355 pStyle
->SetNumberType(enumXFNumberNumber
);
361 pStyle
->SetNumberType(enumXFNumberScientific
);
367 pStyle
->SetNumberType(enumXFNumberNumber
);
370 default://including text type, which is not a style of number format in SODC
372 pStyle
->SetNumberType(enumXFText
);
378 * Make the xml content of number format
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
);
394 GetCurrencyStr(cAnyNumber
, aPrefix
, aSuffix
);
395 GetCurrencyStr(cNegative
, aNegPrefix
, aNegSuffix
,sal_True
);
399 SetNumberType(pStyle
);
401 aPrefix
= cAnyNumber
.GetPrefix();
403 aSuffix
= cAnyNumber
.GetSuffix();
405 aColor
= cAnyNumber
.GetColor();
408 if (!IsNegativeOverridden())
410 aNegPrefix
= aPrefix
;
411 aNegSuffix
= aSuffix
;
412 aNegativeColor
= aColor
;
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
);
443 pStyle
->SetPrefix(aPrefix
);
445 pStyle
->SetSurfix(aSuffix
);
446 pStyle
->SetColor( XFColor( (sal_uInt8
)aColor
.GetRed(),
447 (sal_uInt8
)aColor
.GetGreen(),
448 (sal_uInt8
)aColor
.GetBlue()) );
451 pStyle
->SetNegativeStyle( aNegPrefix
, aNegSuffix
, XFColor((sal_uInt8
)aNegativeColor
.GetRed(),
452 (sal_uInt8
)aNegativeColor
.GetGreen(),
453 (sal_uInt8
)aNegativeColor
.GetBlue()) );
460 * @descrption for SODC_2754
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
;
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))
481 pBuff
[i
] = pString
[i
];
486 for (sal_Int32 j
=i
+1; j
< sCode
.getLength() - 1; ++j
)
488 pBuff
[j
] = pString
[j
+1];
490 OUString
sRet(pBuff
, nLen
- 1);
507 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 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
:
522 case FMT_FINNISHMARKKA
:
523 case FMT_FRENCHFRANC
:
525 case FMT_HONGKONGDOLLAR
:
526 case FMT_HUNGARIANFORINT
:
527 case FMT_INDIANRUPEE
:
528 case FMT_INDONESIANRUPIAH
:
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
:
547 case FMT_TAIWANDOLLAR
:
550 case FMT_OTHERCURRENCY
:
554 case FMT_GREEKDRACHMA
:
555 case FMT_ITALIANLIRA
:
556 case FMT_JAPANESEYEN
:
557 case FMT_SPANISHPESETA
:
571 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */