build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwpnumericfmt.cxx
blob54a186fd1676ab5d6c5e03a0f9349152c8cebcd2
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
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)
91 cNumerics.Read();
92 m_pObjStrm->SkipExtra();
96 void LwpNumericFormatSubset::QuickRead(LwpObjectStream* pStrm)
98 cColor.Read(pStrm);
99 cPrefix.Read(pStrm);
100 cSuffix.Read(pStrm);
101 cSubFlags = pStrm->QuickReaduInt16();
103 pStrm->SkipExtra();
105 LwpColor LwpNumericFormatSubset::GetColor()
107 if (cSubFlags&0x04)
109 return cColor;
111 else
113 return LwpColor();
116 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
119 LwpNumericFormatSubset::~LwpNumericFormatSubset()
123 LwpNumericFormat::LwpNumericFormat(LwpObjectStream * pStrm)
124 : m_pObjStrm(pStrm)
125 , cFlags(0)
126 , cFormat(FMT_DEFAULT)
127 , cDecimalPlaces(0)
129 assert(pStrm);
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);
148 pStrm->SkipExtra();
151 bool LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format)
153 switch (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:
165 case FMT_ECU:
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:
173 case FMT_IRISHPUNT:
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:
190 case FMT_SWISSFRANC:
191 case FMT_TAIWANDOLLAR:
192 case FMT_THAIBAHT:
193 case FMT_USDOLLAR:
194 case FMT_OTHERCURRENCY:
195 case FMT_GERMANMARK:
196 case FMT_ITALIANLIRA:
197 case FMT_JAPANESEYEN:
198 case FMT_SPANISHPESETA:
199 case FMT_EURO:
200 return true;
202 default:
203 return false;
206 sal_uInt16
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())
224 if (bNegtive)
226 aPrefix = "(";
228 if (!bPost)
230 aPrefix += aSymbol;
231 if (bShowSpace)
233 aPrefix += " ";
237 if ( aNumber.IsDefaultSuffix())
239 if (bPost)
241 aSuffix = aSymbol;
242 if (bShowSpace)
244 aSuffix = " " + aSuffix;
249 if (bNegtive)
251 aSuffix += ")";
255 void LwpNumericFormat::SetNumberType(XFNumberStyle* pStyle)
257 switch(cFormat)
259 case FMT_PERCENT:
261 pStyle->SetNumberType(enumXFNumberPercent);
263 break;
265 case FMT_COMMA:
267 pStyle->SetNumberType(enumXFNumberNumber);
268 pStyle->SetGroup();
270 break;
271 case FMT_SCIENTIFIC:
273 pStyle->SetNumberType(enumXFNumberScientific);
275 break;
276 case FMT_FIXED:
277 case FMT_GENERAL:
279 pStyle->SetNumberType(enumXFNumberNumber);
281 break;
282 default://including text type, which is not a style of number format in SODC
284 pStyle->SetNumberType(enumXFText);
286 break;
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);
301 pStyle->SetGroup();
302 GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
303 GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,true);
305 else
307 SetNumberType(pStyle);
308 {//Anynumber
309 aPrefix = cAnyNumber.GetPrefix();
310 //Set suffix
311 aSuffix = cAnyNumber.GetSuffix();
312 //Set color
313 aColor = cAnyNumber.GetColor();
316 if (!IsNegativeOverridden())
318 aNegPrefix = aPrefix;
319 aNegSuffix = aSuffix;
320 aNegativeColor = aColor;
322 else
323 {//negative
324 aNegPrefix = cNegative.GetPrefix();
325 aNegSuffix = cNegative.GetSuffix();
326 aNegativeColor = cNegative.GetColor();
328 if (FMT_COMMA==cFormat)
330 if (cNegative.IsDefaultPrefix() && aNegPrefix.isEmpty())
332 aNegPrefix = "(";
334 if (cNegative.IsDefaultSuffix() && aNegSuffix.isEmpty())
336 aNegSuffix = ")";
342 pStyle->SetDecimalDigits(GetDecimalPlaces());
344 aPrefix = reencode(aPrefix);
345 aSuffix = reencode(aSuffix);
346 aNegPrefix = reencode(aNegPrefix);
347 aNegSuffix = reencode(aNegSuffix);
349 {//Anynumber
350 //Set prefix
351 pStyle->SetPrefix(aPrefix);
352 //Set suffix
353 pStyle->SetSurfix(aSuffix);
354 pStyle->SetColor( XFColor( (sal_uInt8)aColor.GetRed(),
355 (sal_uInt8)aColor.GetGreen(),
356 (sal_uInt8)aColor.GetBlue()) );
358 {//Negtive
359 pStyle->SetNegativeStyle( aNegPrefix, aNegSuffix, XFColor((sal_uInt8)aNegativeColor.GetRed(),
360 (sal_uInt8)aNegativeColor.GetGreen(),
361 (sal_uInt8)aNegativeColor.GetBlue()) );
364 return pStyle;
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();
375 bool bFound = false;
376 sal_uInt16 i;
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))
383 bFound = true;
384 break;
386 pBuff[i] = pString[i];
388 if (bFound)
390 pBuff[i] = 0xffe1;
391 for (sal_Int32 j=i+1; j < sCode.getLength() - 1; ++j)
393 pBuff[j] = pString[j+1];
395 OUString sRet(pBuff, nLen - 1);
396 delete [] pBuff;
397 return sRet;
400 delete [] pBuff;
401 return sCode;
404 sal_uInt16
405 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format)
407 switch (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:
419 case FMT_ECU:
420 case FMT_FINNISHMARKKA:
421 case FMT_FRENCHFRANC:
422 case FMT_GERMANMARK:
423 case FMT_HONGKONGDOLLAR:
424 case FMT_HUNGARIANFORINT:
425 case FMT_INDIANRUPEE:
426 case FMT_INDONESIANRUPIAH:
427 case FMT_IRISHPUNT:
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:
444 case FMT_SWISSFRANC:
445 case FMT_TAIWANDOLLAR:
446 case FMT_THAIBAHT:
447 case FMT_USDOLLAR:
448 case FMT_OTHERCURRENCY:
449 case FMT_EURO:
450 return 2;
452 case FMT_GREEKDRACHMA:
453 case FMT_ITALIANLIRA:
454 case FMT_JAPANESEYEN:
455 case FMT_SPANISHPESETA:
456 return 0;
458 case FMT_DEFAULT:
459 case FMT_GENERAL:
460 case FMT_FIXED:
461 case FMT_COMMA:
462 case FMT_PERCENT:
463 case FMT_SCIENTIFIC:
464 default:
465 return 2;
469 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */