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
62 #include <lwpfilehdr.hxx>
63 #include "lwpnumericfmt.hxx"
65 LwpCurrencyPool
LwpNumericFormat::m_aCurrencyInfo
;
67 OUString
LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat
)
69 return m_aCurrencyInfo
[nFormat
].sSymbol
;
72 bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat
)
74 return m_aCurrencyInfo
[nFormat
].bPost
;
77 bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat
)
79 return m_aCurrencyInfo
[nFormat
].bShowSpace
;
82 XFStyle
* LwpLayoutNumerics::Convert()
84 return cNumerics
.Convert();
87 void LwpLayoutNumerics::Read()
89 LwpVirtualPiece::Read();
91 if(LwpFileHeader::m_nFileRevision
>= 0x000b)
94 m_pObjStrm
->SkipExtra();
98 void LwpNumericFormatSubset::QuickRead(LwpObjectStream
* pStrm
)
103 cSubFlags
= pStrm
->QuickReaduInt16();
107 LwpColor
LwpNumericFormatSubset::GetColor() const
118 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
122 LwpNumericFormat::LwpNumericFormat(LwpObjectStream
* pStrm
)
125 , cFormat(FMT_DEFAULT
)
131 * Read number format from wordpro file
133 void LwpNumericFormat::Read()
135 LwpObjectStream
* pStrm
= m_pObjStrm
;
137 if(LwpFileHeader::m_nFileRevision
>= 0x000b)
139 cFlags
= pStrm
->QuickReaduInt16();
140 cDecimalPlaces
= pStrm
->QuickReaduInt16();
141 cFormat
= pStrm
->QuickReaduInt16();
143 cAnyNumber
.QuickRead(pStrm
);
144 cZero
.QuickRead(pStrm
);
145 cNegative
.QuickRead(pStrm
);
150 bool LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format
)
154 case FMT_ARGENTINEANPESO
:
155 case FMT_AUSTRALIANDOLLAR
:
156 case FMT_AUSTRIANSCHILLING
:
157 case FMT_BELGIANFRANC
:
158 case FMT_BRAZILIANCRUZEIRO
:
159 case FMT_BRITISHPOUND
:
160 case FMT_CANADIANDOLLAR
:
161 case FMT_CHINESEYUAN
:
162 case FMT_CZECHKORUNA
:
163 case FMT_DANISHKRONE
:
165 case FMT_FINNISHMARKKA
:
166 case FMT_FRENCHFRANC
:
167 case FMT_GREEKDRACHMA
:
168 case FMT_HONGKONGDOLLAR
:
169 case FMT_HUNGARIANFORINT
:
170 case FMT_INDIANRUPEE
:
171 case FMT_INDONESIANRUPIAH
:
173 case FMT_LUXEMBOURGFRANC
:
174 case FMT_MALAYSIANRINGGIT
:
175 case FMT_MEXICANPESO
:
176 case FMT_NETHERLANDSGUILDER
:
177 case FMT_NEWZEALANDDOLLAR
:
178 case FMT_NORWEGIANKRONE
:
179 case FMT_POLISHZLOTY
:
180 case FMT_PORTUGUESEESCUDO
:
181 case FMT_ROMANIANLEI
:
182 case FMT_RUSSIANRUBLE
:
183 case FMT_SINGAPOREDOLLAR
:
184 case FMT_SLOVAKIANKORUNA
:
185 case FMT_SLOVENIANTHOLAR
:
186 case FMT_SOUTHAFRICANRAND
:
187 case FMT_SOUTHKOREANWON
:
188 case FMT_SWEDISHKRONA
:
190 case FMT_TAIWANDOLLAR
:
193 case FMT_OTHERCURRENCY
:
195 case FMT_ITALIANLIRA
:
196 case FMT_JAPANESEYEN
:
197 case FMT_SPANISHPESETA
:
206 LwpNumericFormat::GetDecimalPlaces()
208 if (IsDecimalPlacesOverridden())
209 return cDecimalPlaces
;
210 return GetDefaultDecimalPlaces(cFormat
);
212 void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber
, OUString
& aPrefix
, OUString
& aSuffix
, bool bNegative
)
214 aPrefix
= aNumber
.GetPrefix();
215 aSuffix
= aNumber
.GetSuffix();
217 //Make the default prefix and suffix
218 OUString aSymbol
= m_aCurrencyInfo
.GetCurrencySymbol(cFormat
);
219 bool bPost
= m_aCurrencyInfo
.IsSymbolPost(cFormat
);
220 bool bShowSpace
= m_aCurrencyInfo
.IsShowSpace(cFormat
);
221 if ( aNumber
.IsDefaultPrefix())
236 if ( !aNumber
.IsDefaultSuffix())
244 aSuffix
= " " + aSuffix
;
254 void LwpNumericFormat::SetNumberType(XFNumberStyle
* pStyle
)
260 pStyle
->SetNumberType(enumXFNumberPercent
);
266 pStyle
->SetNumberType(enumXFNumberNumber
);
272 pStyle
->SetNumberType(enumXFNumberScientific
);
278 pStyle
->SetNumberType(enumXFNumberNumber
);
281 default://including text type, which is not a style of number format in SODC
283 pStyle
->SetNumberType(enumXFText
);
289 * Make the xml content of number format
291 XFStyle
* LwpNumericFormat::Convert()
293 XFNumberStyle
* pStyle
= new XFNumberStyle
;
294 OUString aPrefix
, aSuffix
,aNegPrefix
,aNegSuffix
;
295 LwpColor aColor
, aNegativeColor
;
297 if (IsCurrencyFormat(cFormat
))
299 pStyle
->SetNumberType(enuMXFNumberCurrency
);
301 GetCurrencyStr(cAnyNumber
, aPrefix
, aSuffix
);
302 GetCurrencyStr(cNegative
, aNegPrefix
, aNegSuffix
,true);
306 SetNumberType(pStyle
);
308 aPrefix
= cAnyNumber
.GetPrefix();
310 aSuffix
= cAnyNumber
.GetSuffix();
312 aColor
= cAnyNumber
.GetColor();
315 if (!IsNegativeOverridden())
317 aNegPrefix
= aPrefix
;
318 aNegSuffix
= aSuffix
;
319 aNegativeColor
= aColor
;
323 aNegPrefix
= cNegative
.GetPrefix();
324 aNegSuffix
= cNegative
.GetSuffix();
325 aNegativeColor
= cNegative
.GetColor();
327 if (FMT_COMMA
==cFormat
)
329 if (cNegative
.IsDefaultPrefix() && aNegPrefix
.isEmpty())
333 if (cNegative
.IsDefaultSuffix() && aNegSuffix
.isEmpty())
341 pStyle
->SetDecimalDigits(GetDecimalPlaces());
343 aPrefix
= reencode(aPrefix
);
344 aSuffix
= reencode(aSuffix
);
345 aNegPrefix
= reencode(aNegPrefix
);
346 aNegSuffix
= reencode(aNegSuffix
);
350 pStyle
->SetPrefix(aPrefix
);
352 pStyle
->SetSurfix(aSuffix
);
353 pStyle
->SetColor( XFColor( static_cast<sal_uInt8
>(aColor
.GetRed()),
354 static_cast<sal_uInt8
>(aColor
.GetGreen()),
355 static_cast<sal_uInt8
>(aColor
.GetBlue())) );
358 pStyle
->SetNegativeStyle( aNegPrefix
, aNegSuffix
, XFColor(static_cast<sal_uInt8
>(aNegativeColor
.GetRed()),
359 static_cast<sal_uInt8
>(aNegativeColor
.GetGreen()),
360 static_cast<sal_uInt8
>(aNegativeColor
.GetBlue())) );
367 * @description for SODC_2754
368 * @return fix wrong encoding of POUND symbol
370 OUString
LwpNumericFormat::reencode(const OUString
& sCode
)
372 const sal_Unicode
* pString
= sCode
.getStr();
373 sal_uInt16 nLen
= sCode
.getLength();
376 std::unique_ptr
<sal_Unicode
[]> pBuff( new sal_Unicode
[sCode
.getLength()] );
378 for (i
=0; i
< sCode
.getLength() - 1; i
++)
380 if ( (pString
[i
] == 0x00a1) && (pString
[i
+1] == 0x00ea))
385 pBuff
[i
] = pString
[i
];
390 for (sal_Int32 j
=i
+1; j
< sCode
.getLength() - 1; ++j
)
392 pBuff
[j
] = pString
[j
+1];
394 OUString
sRet(pBuff
.get(), nLen
- 1);
402 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format
)
406 case FMT_ARGENTINEANPESO
:
407 case FMT_AUSTRALIANDOLLAR
:
408 case FMT_AUSTRIANSCHILLING
:
409 case FMT_BELGIANFRANC
:
410 case FMT_BRAZILIANCRUZEIRO
:
411 case FMT_BRITISHPOUND
:
412 case FMT_CANADIANDOLLAR
:
413 case FMT_CHINESEYUAN
:
414 case FMT_CZECHKORUNA
:
415 case FMT_DANISHKRONE
:
417 case FMT_FINNISHMARKKA
:
418 case FMT_FRENCHFRANC
:
420 case FMT_HONGKONGDOLLAR
:
421 case FMT_HUNGARIANFORINT
:
422 case FMT_INDIANRUPEE
:
423 case FMT_INDONESIANRUPIAH
:
425 case FMT_LUXEMBOURGFRANC
:
426 case FMT_MALAYSIANRINGGIT
:
427 case FMT_MEXICANPESO
:
428 case FMT_NETHERLANDSGUILDER
:
429 case FMT_NEWZEALANDDOLLAR
:
430 case FMT_NORWEGIANKRONE
:
431 case FMT_POLISHZLOTY
:
432 case FMT_PORTUGUESEESCUDO
:
433 case FMT_ROMANIANLEI
:
434 case FMT_RUSSIANRUBLE
:
435 case FMT_SINGAPOREDOLLAR
:
436 case FMT_SLOVAKIANKORUNA
:
437 case FMT_SLOVENIANTHOLAR
:
438 case FMT_SOUTHAFRICANRAND
:
439 case FMT_SOUTHKOREANWON
:
440 case FMT_SWEDISHKRONA
:
442 case FMT_TAIWANDOLLAR
:
445 case FMT_OTHERCURRENCY
:
449 case FMT_GREEKDRACHMA
:
450 case FMT_ITALIANLIRA
:
451 case FMT_JAPANESEYEN
:
452 case FMT_SPANISHPESETA
:
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */