LibreOffice Module lotuswordpro (master) 1
lwpnumericfmt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
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
16 *
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.
20 *
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.
25 *
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
30 *
31 *
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.
38 *
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.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
61#include <memory>
62#include <lwpfilehdr.hxx>
63#include "lwpnumericfmt.hxx"
64
66
67OUString LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat)
68{
69 return m_aCurrencyInfo[nFormat].sSymbol;
70}
71
72bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat)
73{
74 return m_aCurrencyInfo[nFormat].bPost;
75}
76
77bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat)
78{
79 return m_aCurrencyInfo[nFormat].bShowSpace;
80}
81
83{
84 return cNumerics.Convert();
85}
86
88{
90
92 {
94 m_pObjStrm->SkipExtra();
95 }
96}
97
99{
100 cColor.Read(pStrm);
101 cPrefix.Read(pStrm);
102 cSuffix.Read(pStrm);
103 cSubFlags = pStrm->QuickReaduInt16();
104
105 pStrm->SkipExtra();
106}
108{
109 if (cSubFlags&0x04)
110 {
111 return cColor;
112 }
113 else
114 {
115 return LwpColor();
116 }
117}
119{
120}
121
123 : m_pObjStrm(pStrm)
124 , cFlags(0)
125 , cFormat(FMT_DEFAULT)
126 , cDecimalPlaces(0)
127{
128 assert(pStrm);
129}
134{
136
138 {
139 cFlags = pStrm->QuickReaduInt16();
141 cFormat = pStrm->QuickReaduInt16();
142
143 cAnyNumber.QuickRead(pStrm);
144 cZero.QuickRead(pStrm);
145 cNegative.QuickRead(pStrm);
146
147 pStrm->SkipExtra();
148 }
149}
151{
152 switch (Format)
153 {
157 case FMT_BELGIANFRANC:
159 case FMT_BRITISHPOUND:
161 case FMT_CHINESEYUAN:
162 case FMT_CZECHKORUNA:
163 case FMT_DANISHKRONE:
164 case FMT_ECU:
166 case FMT_FRENCHFRANC:
167 case FMT_GREEKDRACHMA:
170 case FMT_INDIANRUPEE:
172 case FMT_IRISHPUNT:
175 case FMT_MEXICANPESO:
179 case FMT_POLISHZLOTY:
181 case FMT_ROMANIANLEI:
182 case FMT_RUSSIANRUBLE:
188 case FMT_SWEDISHKRONA:
189 case FMT_SWISSFRANC:
190 case FMT_TAIWANDOLLAR:
191 case FMT_THAIBAHT:
192 case FMT_USDOLLAR:
194 case FMT_GERMANMARK:
195 case FMT_ITALIANLIRA:
196 case FMT_JAPANESEYEN:
198 case FMT_EURO:
199 return true;
200
201 default:
202 return false;
203 }
204}
205sal_uInt16
207{
209 return cDecimalPlaces;
211}
212void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber, OUString& aPrefix, OUString& aSuffix, bool bNegative)
213{
214 aPrefix = aNumber.GetPrefix();
215 aSuffix = aNumber.GetSuffix();
216
217 //Make the default prefix and suffix
218 OUString aSymbol = m_aCurrencyInfo.GetCurrencySymbol(cFormat);
220 bool bShowSpace = m_aCurrencyInfo.IsShowSpace(cFormat);
221 if ( aNumber.IsDefaultPrefix())
222 {
223 if (bNegative)
224 {
225 aPrefix = "(";
226 }
227 if (!bPost)
228 {
229 aPrefix += aSymbol;
230 if (bShowSpace)
231 {
232 aPrefix += " ";
233 }
234 }
235 }
236 if ( !aNumber.IsDefaultSuffix())
237 return;
238
239 if (bPost)
240 {
241 aSuffix = aSymbol;
242 if (bShowSpace)
243 {
244 aSuffix = " " + aSuffix;
245 }
246
247 }
248
249 if (bNegative)
250 {
251 aSuffix += ")";
252 }
253}
255{
256 switch(cFormat)
257 {
258 case FMT_PERCENT:
259 {
261 }
262 break;
263
264 case FMT_COMMA:
265 {
267 pStyle->SetGroup();
268 }
269 break;
270 case FMT_SCIENTIFIC:
271 {
273 }
274 break;
275 case FMT_FIXED:
276 case FMT_GENERAL:
277 {
279 }
280 break;
281 default://including text type, which is not a style of number format in SODC
282 {
283 pStyle->SetNumberType(enumXFText);
284 }
285 break;
286 }
287}
292{
293 XFNumberStyle* pStyle = new XFNumberStyle;
294 OUString aPrefix, aSuffix,aNegPrefix,aNegSuffix;
295 LwpColor aColor, aNegativeColor;
296
298 {
300 pStyle->SetGroup();
301 GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
302 GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,true);
303 }
304 else
305 {
306 SetNumberType(pStyle);
307 {//Anynumber
308 aPrefix = cAnyNumber.GetPrefix();
309 //Set suffix
310 aSuffix = cAnyNumber.GetSuffix();
311 //Set color
312 aColor = cAnyNumber.GetColor();
313 }
314
316 {
317 aNegPrefix = aPrefix;
318 aNegSuffix = aSuffix;
319 aNegativeColor = aColor;
320 }
321 else
322 {//negative
323 aNegPrefix = cNegative.GetPrefix();
324 aNegSuffix = cNegative.GetSuffix();
325 aNegativeColor = cNegative.GetColor();
326 }
327 if (FMT_COMMA==cFormat)
328 {
329 if (cNegative.IsDefaultPrefix() && aNegPrefix.isEmpty())
330 {
331 aNegPrefix = "(";
332 }
333 if (cNegative.IsDefaultSuffix() && aNegSuffix.isEmpty())
334 {
335 aNegSuffix = ")";
336 }
337 }
338
339 }
340
342
343 aPrefix = reencode(aPrefix);
344 aSuffix = reencode(aSuffix);
345 aNegPrefix = reencode(aNegPrefix);
346 aNegSuffix = reencode(aNegSuffix);
347
348 {//Anynumber
349 //Set prefix
350 pStyle->SetPrefix(aPrefix);
351 //Set suffix
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())) );
356 }
357 {//Negative
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())) );
361 }
362
363 return pStyle;
364}
370OUString LwpNumericFormat::reencode(const OUString& sCode)
371{
372 const sal_Unicode * pString = sCode.getStr();
373 sal_uInt16 nLen = sCode.getLength();
374 bool bFound = false;
375 sal_Int32 i;
376 std::unique_ptr<sal_Unicode[]> pBuff( new sal_Unicode[sCode.getLength()] );
377
378 for (i=0; i< sCode.getLength() - 1; i++)
379 {
380 if ( (pString[i] == 0x00a1) && (pString[i+1] == 0x00ea))
381 {
382 bFound = true;
383 break;
384 }
385 pBuff[i] = pString[i];
386 }
387 if (bFound)
388 {
389 pBuff[i] = 0xffe1;
390 for (sal_Int32 j=i+1; j < sCode.getLength() - 1; ++j)
391 {
392 pBuff[j] = pString[j+1];
393 }
394 OUString sRet(pBuff.get(), nLen - 1);
395 return sRet;
396 }
397
398 return sCode;
399}
400
401sal_uInt16
403{
404 switch (Format)
405 {
409 case FMT_BELGIANFRANC:
411 case FMT_BRITISHPOUND:
413 case FMT_CHINESEYUAN:
414 case FMT_CZECHKORUNA:
415 case FMT_DANISHKRONE:
416 case FMT_ECU:
418 case FMT_FRENCHFRANC:
419 case FMT_GERMANMARK:
422 case FMT_INDIANRUPEE:
424 case FMT_IRISHPUNT:
427 case FMT_MEXICANPESO:
431 case FMT_POLISHZLOTY:
433 case FMT_ROMANIANLEI:
434 case FMT_RUSSIANRUBLE:
440 case FMT_SWEDISHKRONA:
441 case FMT_SWISSFRANC:
442 case FMT_TAIWANDOLLAR:
443 case FMT_THAIBAHT:
444 case FMT_USDOLLAR:
446 case FMT_EURO:
447 return 2;
448
449 case FMT_GREEKDRACHMA:
450 case FMT_ITALIANLIRA:
451 case FMT_JAPANESEYEN:
453 return 0;
454
455 case FMT_DEFAULT:
456 case FMT_GENERAL:
457 case FMT_FIXED:
458 case FMT_COMMA:
459 case FMT_PERCENT:
460 case FMT_SCIENTIFIC:
461 default:
462 return 2;
463 }
464}
465
466/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Read(LwpObjectStream *pStrm)
@descr read atomholder from object stream the default encoding used in Word Pro is 1252
lwpcolor class (red, green, blue, extra)
Definition: lwpcolor.hxx:71
sal_uInt16 GetGreen() const
Definition: lwpcolor.hxx:106
void Read(LwpObjectStream *pStrm)
@descr read color and then resolve the RGB values
Definition: lwpcolor.cxx:74
sal_uInt16 GetBlue() const
Definition: lwpcolor.hxx:110
sal_uInt16 GetRed() const
Definition: lwpcolor.hxx:102
bool IsSymbolPost(sal_uInt16 nFormat)
std::map< sal_uInt16, LwpCurrencyInfo > m_aCurrencyInfo
bool IsShowSpace(sal_uInt16 nFormat)
OUString GetCurrencySymbol(sal_uInt16 nFormat)
static sal_uInt16 m_nFileRevision
Definition: lwpfilehdr.hxx:77
LwpNumericFormat cNumerics
XFStyle * Convert()
virtual void Read() override
@descr Read LwpDLVList data from object stream
OUString const & GetPrefix() const
LwpColor GetColor() const
OUString const & GetSuffix() const
void QuickRead(LwpObjectStream *pStrm)
bool IsDefaultSuffix() const
bool IsDefaultPrefix() const
sal_uInt16 GetDecimalPlaces()
static OUString reencode(const OUString &sCode)
@description for SODC_2754
LwpNumericFormat(LwpObjectStream *pStrm)
LwpNumericFormatSubset cAnyNumber
XFStyle * Convert()
Make the xml content of number format.
static LwpCurrencyPool m_aCurrencyInfo
sal_uInt16 cDecimalPlaces
LwpNumericFormatSubset cZero
LwpObjectStream * m_pObjStrm
static bool IsCurrencyFormat(sal_uInt16 Format)
static sal_uInt16 GetDefaultDecimalPlaces(sal_uInt16 Format)
void SetNumberType(XFNumberStyle *pStyle)
bool IsDecimalPlacesOverridden() const
void Read()
Read number format from wordpro file.
bool IsNegativeOverridden() const
void GetCurrencyStr(LwpNumericFormatSubset aNumber, OUString &aPrefix, OUString &aSuffix, bool bNegative=false)
LwpNumericFormatSubset cNegative
stream class for LwpObject body data provide stream like interface to read object data
Definition: lwpobjstrm.hxx:77
sal_uInt16 QuickReaduInt16(bool *pFailure=nullptr)
@descr Quick read sal_uInt32
Definition: lwpobjstrm.cxx:200
void SkipExtra()
@descr skip extra bytes
Definition: lwpobjstrm.cxx:258
std::unique_ptr< LwpObjectStream > m_pObjStrm
Definition: lwpobj.hxx:90
virtual void Read() override
@descr Read LwpDLVList data from object stream
Definition: lwppiece.hxx:83
Color object.
Definition: xfcolor.hxx:70
void SetDecimalDigits(sal_Int32 decimal)
void SetPrefix(const OUString &prefix)
void SetSurfix(const OUString &surfix)
void SetNegativeStyle(const OUString &prefix, const OUString &suffix, const XFColor &color)
void SetNumberType(enumXFNumberType type)
void SetColor(const XFColor &color)
implements ixfstyle interface.
Definition: xfstyle.hxx:70
For LWP filter architecture prototype - table object.
@ FMT_POLISHZLOTY
@ FMT_LUXEMBOURGFRANC
@ FMT_AUSTRALIANDOLLAR
@ FMT_JAPANESEYEN
@ FMT_GENERAL
@ FMT_DEFAULT
@ FMT_CHINESEYUAN
@ FMT_INDONESIANRUPIAH
@ FMT_AUSTRIANSCHILLING
@ FMT_COMMA
@ FMT_SWEDISHKRONA
@ FMT_BELGIANFRANC
@ FMT_IRISHPUNT
@ FMT_INDIANRUPEE
@ FMT_ARGENTINEANPESO
@ FMT_PERCENT
@ FMT_FRENCHFRANC
@ FMT_SPANISHPESETA
@ FMT_SWISSFRANC
@ FMT_SOUTHAFRICANRAND
@ FMT_ECU
@ FMT_GREEKDRACHMA
@ FMT_NEWZEALANDDOLLAR
@ FMT_FIXED
@ FMT_SOUTHKOREANWON
@ FMT_GERMANMARK
@ FMT_EURO
@ FMT_SLOVAKIANKORUNA
@ FMT_ITALIANLIRA
@ FMT_OTHERCURRENCY
@ FMT_PORTUGUESEESCUDO
@ FMT_SCIENTIFIC
@ FMT_THAIBAHT
@ FMT_HUNGARIANFORINT
@ FMT_BRITISHPOUND
@ FMT_FINNISHMARKKA
@ FMT_MALAYSIANRINGGIT
@ FMT_SLOVENIANTHOLAR
@ FMT_MEXICANPESO
@ FMT_USDOLLAR
@ FMT_NETHERLANDSGUILDER
@ FMT_NORWEGIANKRONE
@ FMT_DANISHKRONE
@ FMT_SINGAPOREDOLLAR
@ FMT_RUSSIANRUBLE
@ FMT_CANADIANDOLLAR
@ FMT_ROMANIANLEI
@ FMT_CZECHKORUNA
@ FMT_BRAZILIANCRUZEIRO
@ FMT_HONGKONGDOLLAR
@ FMT_TAIWANDOLLAR
int i
unsigned char sal_uInt8
sal_uInt16 sal_Unicode
@ enumXFNumberPercent
Definition: xfdefs.hxx:419
@ enumXFNumberNumber
Definition: xfdefs.hxx:418
@ enumXFNumberScientific
Definition: xfdefs.hxx:421
@ enuMXFNumberCurrency
Definition: xfdefs.hxx:420
@ enumXFText
Definition: xfdefs.hxx:422