tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / lotuswordpro / source / filter / lwpnumericfmt.cxx
blobc2dc4d4e76a6adbeba7739dc81a434e484699b7e
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 <memory>
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)
93 cNumerics.Read();
94 m_pObjStrm->SkipExtra();
98 void LwpNumericFormatSubset::QuickRead(LwpObjectStream* pStrm)
100 cColor.Read(pStrm);
101 cPrefix.Read(pStrm);
102 cSuffix.Read(pStrm);
103 cSubFlags = pStrm->QuickReaduInt16();
105 pStrm->SkipExtra();
107 LwpColor LwpNumericFormatSubset::GetColor() const
109 if (cSubFlags&0x04)
111 return cColor;
113 else
115 return LwpColor();
118 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
122 LwpNumericFormat::LwpNumericFormat(LwpObjectStream * pStrm)
123 : m_pObjStrm(pStrm)
124 , cFlags(0)
125 , cFormat(FMT_DEFAULT)
126 , cDecimalPlaces(0)
128 assert(pStrm);
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);
147 pStrm->SkipExtra();
150 bool LwpNumericFormat::IsCurrencyFormat(sal_uInt16 Format)
152 switch (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:
164 case FMT_ECU:
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:
172 case FMT_IRISHPUNT:
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:
189 case FMT_SWISSFRANC:
190 case FMT_TAIWANDOLLAR:
191 case FMT_THAIBAHT:
192 case FMT_USDOLLAR:
193 case FMT_OTHERCURRENCY:
194 case FMT_GERMANMARK:
195 case FMT_ITALIANLIRA:
196 case FMT_JAPANESEYEN:
197 case FMT_SPANISHPESETA:
198 case FMT_EURO:
199 return true;
201 default:
202 return false;
205 sal_uInt16
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())
223 if (bNegative)
225 aPrefix = "(";
227 if (!bPost)
229 aPrefix += aSymbol;
230 if (bShowSpace)
232 aPrefix += " ";
236 if ( !aNumber.IsDefaultSuffix())
237 return;
239 if (bPost)
241 aSuffix = aSymbol;
242 if (bShowSpace)
244 aSuffix = " " + aSuffix;
249 if (bNegative)
251 aSuffix += ")";
254 void LwpNumericFormat::SetNumberType(XFNumberStyle* pStyle)
256 switch(cFormat)
258 case FMT_PERCENT:
260 pStyle->SetNumberType(enumXFNumberPercent);
262 break;
264 case FMT_COMMA:
266 pStyle->SetNumberType(enumXFNumberNumber);
267 pStyle->SetGroup();
269 break;
270 case FMT_SCIENTIFIC:
272 pStyle->SetNumberType(enumXFNumberScientific);
274 break;
275 case FMT_FIXED:
276 case FMT_GENERAL:
278 pStyle->SetNumberType(enumXFNumberNumber);
280 break;
281 default://including text type, which is not a style of number format in SODC
283 pStyle->SetNumberType(enumXFText);
285 break;
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);
300 pStyle->SetGroup();
301 GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
302 GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,true);
304 else
306 SetNumberType(pStyle);
307 {//Anynumber
308 aPrefix = cAnyNumber.GetPrefix();
309 //Set suffix
310 aSuffix = cAnyNumber.GetSuffix();
311 //Set color
312 aColor = cAnyNumber.GetColor();
315 if (!IsNegativeOverridden())
317 aNegPrefix = aPrefix;
318 aNegSuffix = aSuffix;
319 aNegativeColor = aColor;
321 else
322 {//negative
323 aNegPrefix = cNegative.GetPrefix();
324 aNegSuffix = cNegative.GetSuffix();
325 aNegativeColor = cNegative.GetColor();
327 if (FMT_COMMA==cFormat)
329 if (cNegative.IsDefaultPrefix() && aNegPrefix.isEmpty())
331 aNegPrefix = "(";
333 if (cNegative.IsDefaultSuffix() && aNegSuffix.isEmpty())
335 aNegSuffix = ")";
341 pStyle->SetDecimalDigits(GetDecimalPlaces());
343 aPrefix = reencode(aPrefix);
344 aSuffix = reencode(aSuffix);
345 aNegPrefix = reencode(aNegPrefix);
346 aNegSuffix = reencode(aNegSuffix);
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())) );
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())) );
363 return pStyle;
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();
374 bool bFound = false;
375 sal_Int32 i;
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))
382 bFound = true;
383 break;
385 pBuff[i] = pString[i];
387 if (bFound)
389 pBuff[i] = 0xffe1;
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);
395 return sRet;
398 return sCode;
401 sal_uInt16
402 LwpNumericFormat::GetDefaultDecimalPlaces(sal_uInt16 Format)
404 switch (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:
416 case FMT_ECU:
417 case FMT_FINNISHMARKKA:
418 case FMT_FRENCHFRANC:
419 case FMT_GERMANMARK:
420 case FMT_HONGKONGDOLLAR:
421 case FMT_HUNGARIANFORINT:
422 case FMT_INDIANRUPEE:
423 case FMT_INDONESIANRUPIAH:
424 case FMT_IRISHPUNT:
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:
441 case FMT_SWISSFRANC:
442 case FMT_TAIWANDOLLAR:
443 case FMT_THAIBAHT:
444 case FMT_USDOLLAR:
445 case FMT_OTHERCURRENCY:
446 case FMT_EURO:
447 return 2;
449 case FMT_GREEKDRACHMA:
450 case FMT_ITALIANLIRA:
451 case FMT_JAPANESEYEN:
452 case FMT_SPANISHPESETA:
453 return 0;
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;
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */