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 LwpCurrencyPool
LwpNumericFormat::m_aCurrencyInfo
;
76 OUString
LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat
)
78 return m_aCurrencyInfo
[nFormat
].sSymbol
;
88 bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat
)
90 return m_aCurrencyInfo
[nFormat
].bPost
;
100 bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat
)
102 return m_aCurrencyInfo
[nFormat
].bShowSpace
;
112 XFStyle
* LwpLayoutNumerics::Convert()
114 return cNumerics
.Convert();
124 void LwpLayoutNumerics::Read()
126 LwpVirtualPiece::Read();
128 if(LwpFileHeader::m_nFileRevision
>= 0x000b)
131 m_pObjStrm
->SkipExtra();
142 void LwpNumericFormatSubset::QuickRead(LwpObjectStream
* pStrm
)
147 cSubFlags
= pStrm
->QuickReaduInt16();
158 LwpColor
LwpNumericFormatSubset::GetColor()
169 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
172 LwpNumericFormatSubset::~LwpNumericFormatSubset()
176 LwpNumericFormat::LwpNumericFormat(LwpObjectStream
* pStrm
)
179 , cFormat(FMT_DEFAULT
)
185 * Read number format from wordpro file
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
);
215 bool LwpNumericFormat::IsCurrencyFormat(sal_uInt16 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
:
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
:
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
:
255 case FMT_TAIWANDOLLAR
:
258 case FMT_OTHERCURRENCY
:
260 case FMT_ITALIANLIRA
:
261 case FMT_JAPANESEYEN
:
262 case FMT_SPANISHPESETA
:
278 LwpNumericFormat::GetDecimalPlaces()
280 if (IsDecimalPlacesOverridden())
281 return cDecimalPlaces
;
282 return GetDefaultDecimalPlaces(cFormat
);
285 * Make the currency string.
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())
315 if ( aNumber
.IsDefaultSuffix())
322 aSuffix
= " " + aSuffix
;
340 void LwpNumericFormat::SetNumberType(XFNumberStyle
* pStyle
)
346 pStyle
->SetNumberType(enumXFNumberPercent
);
352 pStyle
->SetNumberType(enumXFNumberNumber
);
358 pStyle
->SetNumberType(enumXFNumberScientific
);
364 pStyle
->SetNumberType(enumXFNumberNumber
);
367 default://including text type, which is not a style of number format in SODC
369 pStyle
->SetNumberType(enumXFText
);
375 * Make the xml content of number format
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
);
391 GetCurrencyStr(cAnyNumber
, aPrefix
, aSuffix
);
392 GetCurrencyStr(cNegative
, aNegPrefix
, aNegSuffix
,true);
396 SetNumberType(pStyle
);
398 aPrefix
= cAnyNumber
.GetPrefix();
400 aSuffix
= cAnyNumber
.GetSuffix();
402 aColor
= cAnyNumber
.GetColor();
405 if (!IsNegativeOverridden())
407 aNegPrefix
= aPrefix
;
408 aNegSuffix
= aSuffix
;
409 aNegativeColor
= aColor
;
413 aNegPrefix
= cNegative
.GetPrefix();
414 aNegSuffix
= cNegative
.GetSuffix();
415 aNegativeColor
= cNegative
.GetColor();
417 if (FMT_COMMA
==cFormat
)
419 if (cNegative
.IsDefaultPrefix() && aNegPrefix
.isEmpty())
423 if (cNegative
.IsDefaultSuffix() && aNegSuffix
.isEmpty())
431 pStyle
->SetDecimalDigits(GetDecimalPlaces());
433 aPrefix
= reencode(aPrefix
);
434 aSuffix
= reencode(aSuffix
);
435 aNegPrefix
= reencode(aNegPrefix
);
436 aNegSuffix
= reencode(aNegSuffix
);
440 pStyle
->SetPrefix(aPrefix
);
442 pStyle
->SetSurfix(aSuffix
);
443 pStyle
->SetColor( XFColor( (sal_uInt8
)aColor
.GetRed(),
444 (sal_uInt8
)aColor
.GetGreen(),
445 (sal_uInt8
)aColor
.GetBlue()) );
448 pStyle
->SetNegativeStyle( aNegPrefix
, aNegSuffix
, XFColor((sal_uInt8
)aNegativeColor
.GetRed(),
449 (sal_uInt8
)aNegativeColor
.GetGreen(),
450 (sal_uInt8
)aNegativeColor
.GetBlue()) );
457 * @descrption for SODC_2754
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();
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))
478 pBuff
[i
] = pString
[i
];
483 for (sal_Int32 j
=i
+1; j
< sCode
.getLength() - 1; ++j
)
485 pBuff
[j
] = pString
[j
+1];
487 OUString
sRet(pBuff
, nLen
- 1);
504 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 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
:
519 case FMT_FINNISHMARKKA
:
520 case FMT_FRENCHFRANC
:
522 case FMT_HONGKONGDOLLAR
:
523 case FMT_HUNGARIANFORINT
:
524 case FMT_INDIANRUPEE
:
525 case FMT_INDONESIANRUPIAH
:
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
:
544 case FMT_TAIWANDOLLAR
:
547 case FMT_OTHERCURRENCY
:
551 case FMT_GREEKDRACHMA
:
552 case FMT_ITALIANLIRA
:
553 case FMT_JAPANESEYEN
:
554 case FMT_SPANISHPESETA
:
568 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */