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
61 #include "lwpnumericfmt.hxx"
63 LwpCurrencyPool
LwpNumericFormat::m_aCurrencyInfo
;
65 OUString
LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat
)
67 return m_aCurrencyInfo
[nFormat
].sSymbol
;
70 bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat
)
72 return m_aCurrencyInfo
[nFormat
].bPost
;
75 bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat
)
77 return m_aCurrencyInfo
[nFormat
].bShowSpace
;
80 XFStyle
* LwpLayoutNumerics::Convert()
82 return cNumerics
.Convert();
85 void LwpLayoutNumerics::Read()
87 LwpVirtualPiece::Read();
89 if(LwpFileHeader::m_nFileRevision
>= 0x000b)
92 m_pObjStrm
->SkipExtra();
96 void LwpNumericFormatSubset::QuickRead(LwpObjectStream
* pStrm
)
101 cSubFlags
= pStrm
->QuickReaduInt16();
105 LwpColor
LwpNumericFormatSubset::GetColor()
116 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
119 LwpNumericFormatSubset::~LwpNumericFormatSubset()
123 LwpNumericFormat::LwpNumericFormat(LwpObjectStream
* pStrm
)
126 , cFormat(FMT_DEFAULT
)
132 * Read number format from wordpro file
134 void LwpNumericFormat::Read()
136 LwpObjectStream
* pStrm
= m_pObjStrm
;
138 if(LwpFileHeader::m_nFileRevision
>= 0x000b)
140 cFlags
= pStrm
->QuickReaduInt16();
141 cDecimalPlaces
= pStrm
->QuickReaduInt16();
142 cFormat
= pStrm
->QuickReaduInt16();
144 cAnyNumber
.QuickRead(pStrm
);
145 cZero
.QuickRead(pStrm
);
146 cNegative
.QuickRead(pStrm
);
151 bool LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format
)
155 case FMT_ARGENTINEANPESO
:
156 case FMT_AUSTRALIANDOLLAR
:
157 case FMT_AUSTRIANSCHILLING
:
158 case FMT_BELGIANFRANC
:
159 case FMT_BRAZILIANCRUZEIRO
:
160 case FMT_BRITISHPOUND
:
161 case FMT_CANADIANDOLLAR
:
162 case FMT_CHINESEYUAN
:
163 case FMT_CZECHKORUNA
:
164 case FMT_DANISHKRONE
:
166 case FMT_FINNISHMARKKA
:
167 case FMT_FRENCHFRANC
:
168 case FMT_GREEKDRACHMA
:
169 case FMT_HONGKONGDOLLAR
:
170 case FMT_HUNGARIANFORINT
:
171 case FMT_INDIANRUPEE
:
172 case FMT_INDONESIANRUPIAH
:
174 case FMT_LUXEMBOURGFRANC
:
175 case FMT_MALAYSIANRINGGIT
:
176 case FMT_MEXICANPESO
:
177 case FMT_NETHERLANDSGUILDER
:
178 case FMT_NEWZEALANDDOLLAR
:
179 case FMT_NORWEGIANKRONE
:
180 case FMT_POLISHZLOTY
:
181 case FMT_PORTUGUESEESCUDO
:
182 case FMT_ROMANIANLEI
:
183 case FMT_RUSSIANRUBLE
:
184 case FMT_SINGAPOREDOLLAR
:
185 case FMT_SLOVAKIANKORUNA
:
186 case FMT_SLOVENIANTHOLAR
:
187 case FMT_SOUTHAFRICANRAND
:
188 case FMT_SOUTHKOREANWON
:
189 case FMT_SWEDISHKRONA
:
191 case FMT_TAIWANDOLLAR
:
194 case FMT_OTHERCURRENCY
:
196 case FMT_ITALIANLIRA
:
197 case FMT_JAPANESEYEN
:
198 case FMT_SPANISHPESETA
:
207 LwpNumericFormat::GetDecimalPlaces()
209 if (IsDecimalPlacesOverridden())
210 return cDecimalPlaces
;
211 return GetDefaultDecimalPlaces(cFormat
);
213 void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber
, OUString
& aPrefix
, OUString
& aSuffix
, bool bNegtive
)
215 aPrefix
= aNumber
.GetPrefix();
216 aSuffix
= aNumber
.GetSuffix();
218 //Make the default prefix and suffix
219 OUString aSymbol
= m_aCurrencyInfo
.GetCurrencySymbol(cFormat
);
220 bool bPost
= m_aCurrencyInfo
.IsSymbolPost(cFormat
);
221 bool bShowSpace
= m_aCurrencyInfo
.IsShowSpace(cFormat
);
222 if ( aNumber
.IsDefaultPrefix())
237 if ( aNumber
.IsDefaultSuffix())
244 aSuffix
= " " + aSuffix
;
255 void LwpNumericFormat::SetNumberType(XFNumberStyle
* pStyle
)
261 pStyle
->SetNumberType(enumXFNumberPercent
);
267 pStyle
->SetNumberType(enumXFNumberNumber
);
273 pStyle
->SetNumberType(enumXFNumberScientific
);
279 pStyle
->SetNumberType(enumXFNumberNumber
);
282 default://including text type, which is not a style of number format in SODC
284 pStyle
->SetNumberType(enumXFText
);
290 * Make the xml content of number format
292 XFStyle
* LwpNumericFormat::Convert()
294 XFNumberStyle
* pStyle
= new XFNumberStyle
;
295 OUString aPrefix
, aSuffix
,aNegPrefix
,aNegSuffix
;
296 LwpColor aColor
, aNegativeColor
;
298 if (IsCurrencyFormat(cFormat
))
300 pStyle
->SetNumberType(enuMXFNumberCurrency
);
302 GetCurrencyStr(cAnyNumber
, aPrefix
, aSuffix
);
303 GetCurrencyStr(cNegative
, aNegPrefix
, aNegSuffix
,true);
307 SetNumberType(pStyle
);
309 aPrefix
= cAnyNumber
.GetPrefix();
311 aSuffix
= cAnyNumber
.GetSuffix();
313 aColor
= cAnyNumber
.GetColor();
316 if (!IsNegativeOverridden())
318 aNegPrefix
= aPrefix
;
319 aNegSuffix
= aSuffix
;
320 aNegativeColor
= aColor
;
324 aNegPrefix
= cNegative
.GetPrefix();
325 aNegSuffix
= cNegative
.GetSuffix();
326 aNegativeColor
= cNegative
.GetColor();
328 if (FMT_COMMA
==cFormat
)
330 if (cNegative
.IsDefaultPrefix() && aNegPrefix
.isEmpty())
334 if (cNegative
.IsDefaultSuffix() && aNegSuffix
.isEmpty())
342 pStyle
->SetDecimalDigits(GetDecimalPlaces());
344 aPrefix
= reencode(aPrefix
);
345 aSuffix
= reencode(aSuffix
);
346 aNegPrefix
= reencode(aNegPrefix
);
347 aNegSuffix
= reencode(aNegSuffix
);
351 pStyle
->SetPrefix(aPrefix
);
353 pStyle
->SetSurfix(aSuffix
);
354 pStyle
->SetColor( XFColor( (sal_uInt8
)aColor
.GetRed(),
355 (sal_uInt8
)aColor
.GetGreen(),
356 (sal_uInt8
)aColor
.GetBlue()) );
359 pStyle
->SetNegativeStyle( aNegPrefix
, aNegSuffix
, XFColor((sal_uInt8
)aNegativeColor
.GetRed(),
360 (sal_uInt8
)aNegativeColor
.GetGreen(),
361 (sal_uInt8
)aNegativeColor
.GetBlue()) );
368 * @description for SODC_2754
369 * @return fix wrong encoding of POUND symbol
371 OUString
LwpNumericFormat::reencode(const OUString
& sCode
)
373 const sal_Unicode
* pString
= sCode
.getStr();
374 sal_uInt16 nLen
= sCode
.getLength();
377 sal_Unicode
*pBuff
= new sal_Unicode
[sCode
.getLength()];
379 for (i
=0; i
< sCode
.getLength() - 1; i
++)
381 if ( (pString
[i
] == 0x00a1) && (pString
[i
+1] == 0x00ea))
386 pBuff
[i
] = pString
[i
];
391 for (sal_Int32 j
=i
+1; j
< sCode
.getLength() - 1; ++j
)
393 pBuff
[j
] = pString
[j
+1];
395 OUString
sRet(pBuff
, nLen
- 1);
405 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format
)
409 case FMT_ARGENTINEANPESO
:
410 case FMT_AUSTRALIANDOLLAR
:
411 case FMT_AUSTRIANSCHILLING
:
412 case FMT_BELGIANFRANC
:
413 case FMT_BRAZILIANCRUZEIRO
:
414 case FMT_BRITISHPOUND
:
415 case FMT_CANADIANDOLLAR
:
416 case FMT_CHINESEYUAN
:
417 case FMT_CZECHKORUNA
:
418 case FMT_DANISHKRONE
:
420 case FMT_FINNISHMARKKA
:
421 case FMT_FRENCHFRANC
:
423 case FMT_HONGKONGDOLLAR
:
424 case FMT_HUNGARIANFORINT
:
425 case FMT_INDIANRUPEE
:
426 case FMT_INDONESIANRUPIAH
:
428 case FMT_LUXEMBOURGFRANC
:
429 case FMT_MALAYSIANRINGGIT
:
430 case FMT_MEXICANPESO
:
431 case FMT_NETHERLANDSGUILDER
:
432 case FMT_NEWZEALANDDOLLAR
:
433 case FMT_NORWEGIANKRONE
:
434 case FMT_POLISHZLOTY
:
435 case FMT_PORTUGUESEESCUDO
:
436 case FMT_ROMANIANLEI
:
437 case FMT_RUSSIANRUBLE
:
438 case FMT_SINGAPOREDOLLAR
:
439 case FMT_SLOVAKIANKORUNA
:
440 case FMT_SLOVENIANTHOLAR
:
441 case FMT_SOUTHAFRICANRAND
:
442 case FMT_SOUTHKOREANWON
:
443 case FMT_SWEDISHKRONA
:
445 case FMT_TAIWANDOLLAR
:
448 case FMT_OTHERCURRENCY
:
452 case FMT_GREEKDRACHMA
:
453 case FMT_ITALIANLIRA
:
454 case FMT_JAPANESEYEN
:
455 case FMT_SPANISHPESETA
:
469 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */