lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / writerfilter / source / dmapper / ThemeTable.cxx
blob5f9cfc0414502413da47378b2b74e3905ef05a71
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ThemeTable.hxx"
21 #include <i18nlangtag/languagetag.hxx>
22 #include <ooxml/resourceids.hxx>
24 using namespace com::sun::star;
26 namespace writerfilter {
27 namespace dmapper
30 struct ThemeTable_Impl
32 ThemeTable_Impl() :
33 m_currentThemeFontId(0),
34 m_currentFontThemeEntry(),
35 m_supplementalFontId(0)
37 std::map<sal_uInt32, std::map<sal_uInt32, OUString> > m_themeFontMap;
38 sal_uInt32 m_currentThemeFontId;
39 std::map<sal_uInt32, OUString> m_currentFontThemeEntry;
40 OUString m_supplementalFontName;
41 sal_uInt32 m_supplementalFontId;
42 OUString m_themeFontLangEastAsia;
43 OUString m_themeFontLangBidi;
46 ThemeTable::ThemeTable()
47 : LoggedProperties("ThemeTable")
48 , LoggedTable("ThemeTable")
49 , m_pImpl( new ThemeTable_Impl )
54 ThemeTable::~ThemeTable()
58 void ThemeTable::lcl_attribute(Id Name, Value & val)
60 OUString sValue = val.getString();
61 switch(Name)
63 case NS_ooxml::LN_CT_TextFont_typeface:
64 if (!sValue.isEmpty())
65 m_pImpl->m_currentFontThemeEntry[m_pImpl->m_currentThemeFontId] = sValue;
66 break;
67 case NS_ooxml::LN_CT_SupplementalFont_script:
68 if (!sValue.isEmpty())
70 if (sValue == m_pImpl->m_themeFontLangBidi)
71 m_pImpl->m_supplementalFontId = NS_ooxml::LN_CT_FontCollection_cs;
72 else if (sValue == m_pImpl->m_themeFontLangEastAsia)
73 m_pImpl->m_supplementalFontId = NS_ooxml::LN_CT_FontCollection_ea;
75 break;
76 case NS_ooxml::LN_CT_SupplementalFont_typeface:
77 if (!sValue.isEmpty())
78 m_pImpl->m_supplementalFontName = sValue;
79 break;
80 default:
82 #ifdef DEBUG_WRITERFILTER
83 TagLogger::getInstance().element("unhandled");
84 #endif
87 if(m_pImpl->m_supplementalFontId && m_pImpl->m_supplementalFontName.getLength() > 0)
89 m_pImpl->m_currentFontThemeEntry[m_pImpl->m_supplementalFontId] = m_pImpl->m_supplementalFontName;
90 m_pImpl->m_supplementalFontName.clear();
91 m_pImpl->m_supplementalFontId = 0;
95 void ThemeTable::lcl_sprm(Sprm& rSprm)
97 #ifdef DEBUG_WRITERFILTER
98 TagLogger::getInstance().startElement("ThemeTable.sprm");
99 TagLogger::getInstance().chars(rSprm.toString());
100 #endif
102 m_pImpl->m_supplementalFontName.clear();
103 m_pImpl->m_supplementalFontId = 0;
105 sal_uInt32 nSprmId = rSprm.getId();
106 switch(nSprmId)
108 case NS_ooxml::LN_CT_BaseStyles_fontScheme:
110 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
111 if( pProperties.get())
112 pProperties->resolve(*this);
114 break;
115 case NS_ooxml::LN_CT_FontScheme_majorFont:
116 case NS_ooxml::LN_CT_FontScheme_minorFont:
118 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
119 m_pImpl->m_currentFontThemeEntry = std::map<sal_uInt32, OUString>();
120 if( pProperties.get())
121 pProperties->resolve(*this);
122 m_pImpl->m_themeFontMap[nSprmId] = m_pImpl->m_currentFontThemeEntry;
124 break;
125 case NS_ooxml::LN_CT_FontCollection_latin:
126 case NS_ooxml::LN_CT_FontCollection_ea:
127 case NS_ooxml::LN_CT_FontCollection_cs:
129 m_pImpl->m_currentThemeFontId = nSprmId;
130 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
131 if( pProperties.get())
132 pProperties->resolve(*this);
134 break;
135 case NS_ooxml::LN_CT_FontCollection_font:
137 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
138 if (pProperties.get())
139 pProperties->resolve(*this);
141 break;
142 default:
144 #ifdef DEBUG_WRITERFILTER
145 TagLogger::getInstance().element("unhandled");
146 #endif
149 #ifdef DEBUG_WRITERFILTER
150 TagLogger::getInstance().endElement();
151 #endif
154 void ThemeTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
156 #ifdef DEBUG_WRITERFILTER
157 TagLogger::getInstance().startElement("ThemeTable.entry");
158 #endif
160 ref->resolve(*this);
162 #ifdef DEBUG_WRITERFILTER
163 TagLogger::getInstance().endElement();
164 #endif
167 OUString ThemeTable::getStringForTheme(const Id id)
169 switch (id)
171 case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
172 return OUString("majorEastAsia");
173 case NS_ooxml::LN_Value_ST_Theme_majorBidi:
174 return OUString("majorBidi");
175 case NS_ooxml::LN_Value_ST_Theme_majorAscii:
176 return OUString("majorAscii");
177 case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
178 return OUString("majorHAnsi");
179 case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
180 return OUString("minorEastAsia");
181 case NS_ooxml::LN_Value_ST_Theme_minorBidi:
182 return OUString("minorBidi");
183 case NS_ooxml::LN_Value_ST_Theme_minorAscii:
184 return OUString("minorAscii");
185 case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
186 return OUString("minorHAnsi");
188 return OUString();
190 const OUString ThemeTable::getFontNameForTheme(const Id id) const
192 std::map<sal_uInt32, OUString> tmpThemeFontMap;
193 switch (id)
195 case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
196 case NS_ooxml::LN_Value_ST_Theme_majorBidi:
197 case NS_ooxml::LN_Value_ST_Theme_majorAscii:
198 case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
199 tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_majorFont];
200 break;
201 case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
202 case NS_ooxml::LN_Value_ST_Theme_minorBidi:
203 case NS_ooxml::LN_Value_ST_Theme_minorAscii:
204 case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
205 tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_minorFont];
206 break;
207 default:
208 return OUString();
211 switch (id)
213 case NS_ooxml::LN_Value_ST_Theme_majorAscii:
214 case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
215 case NS_ooxml::LN_Value_ST_Theme_minorAscii:
216 case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
218 std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_latin);
219 if (Iter != tmpThemeFontMap.end())
220 return Iter->second;
221 return OUString();
223 case NS_ooxml::LN_Value_ST_Theme_majorBidi:
224 case NS_ooxml::LN_Value_ST_Theme_minorBidi:
226 std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_cs);
227 if (Iter != tmpThemeFontMap.end())
228 return Iter->second;
229 return OUString();
231 case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
232 case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
234 std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_ea);
235 if (Iter != tmpThemeFontMap.end())
236 return Iter->second;
237 return OUString();
239 default:
240 return OUString();
244 void ThemeTable::setThemeFontLangProperties(const uno::Sequence<beans::PropertyValue>& aPropSeq)
246 for (sal_Int32 i = 0 ; i < aPropSeq.getLength() ; i ++)
248 OUString sLocaleName;
249 aPropSeq.getConstArray()[i].Value >>= sLocaleName;
250 if (aPropSeq.getConstArray()[i].Name == "eastAsia")
251 m_pImpl->m_themeFontLangEastAsia = fromLocaleToScriptTag(sLocaleName);
252 if (aPropSeq.getConstArray()[i].Name == "bidi")
253 m_pImpl->m_themeFontLangBidi = fromLocaleToScriptTag(sLocaleName);
258 OUString ThemeTable::fromLocaleToScriptTag(const OUString& sLocale)
260 return fromLCIDToScriptTag(LanguageTag::convertToLanguageType(sLocale));
263 OUString ThemeTable::fromLCIDToScriptTag(LanguageType lang)
265 // conversion list from:
266 // http://blogs.msdn.com/b/officeinteroperability/archive/2013/04/22/office-open-xml-themes-schemes-and-fonts.aspx
267 switch (static_cast<sal_uInt16>(lang))
269 case 0x429 : // lidFarsi
270 case 0x401 : // lidArabic
271 case 0x801 : // lidIraq
272 case 0xc01 : // lidEgyptian
273 case 0x1001 : // lidLibya
274 case 0x1401 : // lidAlgerian
275 case 0x1801 : // lidMorocco
276 case 0x1c01 : // lidTunisia
277 case 0x2001 : // lidOman
278 case 0x2401 : // lidYemen
279 case 0x2801 : // lidSyria
280 case 0x2c01 : // lidJordan
281 case 0x3001 : // lidLebanon
282 case 0x3401 : // lidKuwait
283 case 0x3801 : // lidUAE
284 case 0x3c01 : // lidBahrain
285 case 0x4001 : // lidQatar
286 case 0x420 : // lidUrdu
287 case 0x846 : // lidPunjabiPakistan
288 case 0x859 : // lidSindhiPakistan
289 case 0x45f : // lidTamazight
290 case 0x460 : // lidKashmiri
291 case 0x463 : // lidPashto
292 case 0x48c : // lidDari
293 return OUString("Arab");
294 case 0x42b : // lidArmenian
295 return OUString("Armn");
296 case 0x445 : // lidBengali
297 case 0x845 : // lidBengaliBangladesh
298 case 0x44d : // lidAssamese
299 case 0x458 : // lidManipuri
300 return OUString("Beng");
301 case 0x45d : // lidInuktitut
302 return OUString("Cans");
303 case 0x45c : // lidCherokee
304 return OUString("Cher");
305 case 0x419 : // lidRussian
306 case 0x402 : // lidBulgarian
307 case 0x281a : // lidSerbianCyrillic
308 case 0x422 : // lidUkranian
309 case 0x819 : // lidRussianMoldavia
310 case 0xc1a : // lidSerbianCyrillicSerbMont
311 case 0x1c1a : // lidSerbianBosniaHerzegovinaCyrillic
312 case 0x201a : // lidBosnianBosniaHerzegovinaCyrillic
313 case 0x301a : // lidSerbianMontenegroCyrillic
314 case 0x423 : // lidByelorussian
315 case 0x428 : // lidTajik
316 case 0x82c : // lidAzeriCyrillic
317 case 0x42f : // lidMacedonian
318 case 0x43f : // lidKazakh
319 case 0x440 : // lidKyrgyz
320 case 0x843 : // lidUzbekCyrillic
321 case 0x444 : // lidTatar
322 case 0x450 : // lidMongolian
323 case 0x46d : // lidBashkir
324 case 0x485 : // lidSakha
325 return OUString("Cyrl");
326 case 0x439 : // lidHindi
327 case 0x44e : // lidMarathi
328 case 0x44f : // lidSanskrit
329 case 0x457 : // lidKonkani
330 case 0x459 : // lidSindhi
331 case 0x860 : // lidKashmiriIndia
332 case 0x461 : // lidNepali
333 case 0x861 : // lidNepaliIndia
334 return OUString("Deva");
335 case 0x45e : // lidAmharic
336 case 0x473 : // lidTigrignaEthiopic
337 case 0x873 : // lidTigrignaEritrea
338 return OUString("Ethi");
339 case 0x437 : // lidGeorgian
340 return OUString("Geor");
341 case 0x408 : // lidGreek
342 return OUString("Grek");
343 case 0x447 : // lidGujarati
344 return OUString("Gujr");
345 case 0x446 : // lidPunjabi
346 return OUString("Guru");
347 case 0x412 : // lidKoreanExtWansung
348 return OUString("Hang");
349 case 0x804 : // lidChineseSimp
350 case 0x1004 : // lidSingapore
351 return OUString("Hans");
352 case 0x404 : // lidChineseTrad
353 case 0xc04 : // lidHongkong
354 case 0x1404 : // lidMacau
355 return OUString("Hant");
356 case 0x40d : // lidHebrew
357 case 0x43d : // lidYiddish
358 return OUString("Hebr");
359 case 0x411 : // lidJapanese
360 return OUString("Jpan");
361 case 0x453 : // lidKhmer
362 return OUString("Khmr");
363 case 0x44b : // lidKannada
364 return OUString("Knda");
365 case 0x454 : // lidLao
366 return OUString("Laoo");
367 case 0x409 : // lidAmerican
368 case 0xc09 : // lidAustralian
369 case 0x809 : // lidBritish
370 case 0x1009 : // lidEnglishCanadian
371 case 0x403 : // lidCatalan
372 case 0x406 : // lidDanish
373 case 0x413 : // lidDutch
374 case 0x813 : // lidDutchBelgian
375 case 0x479 : // lidPapiamentu
376 case 0x40b : // lidFinnish
377 case 0x40c : // lidFrench
378 case 0xc0c : // lidFrenchCanadian
379 case 0x407 : // lidGerman
380 case 0x807 : // lidSwissGerman
381 case 0xc07 : // lidAustrianGerman
382 case 0x1007 : // lidGermanLuxembourg
383 case 0x1407 : // lidGermanLiechtenstein
384 case 0x410 : // lidItalian
385 case 0x414 : // lidNorskBokmal
386 case 0x814 : // lidNorskNynorsk
387 case 0x416 : // lidPortBrazil
388 case 0x816 : // lidPortIberian
389 case 0x40a : // lidSpanish
390 case 0x41d : // lidSwedish
391 case 0x405 : // lidCzech
392 case 0x40e : // lidHungarian
393 case 0x415 : // lidPolish
394 case 0x41f : // lidTurkish
395 case 0x42d : // lidBasque
396 case 0x424 : // lidSlovenian
397 case 0x426 : // lidLatvian
398 case 0x427 : // lidLithuanian
399 case 0x418 : // lidRomanian
400 case 0x818 : // lidRomanianMoldavia
401 case 0x241a : // lidSerbianLatin
402 case 0x41a : // lidCroatian, lidCroat
403 case 0x491 : // lidGaelicScots
404 case 0x83c : // lidGaelicIrish
405 case 0x430 : // lidSutu
406 case 0x431 : // lidTsonga
407 case 0x432 : // lidTswana
408 case 0x433 : // lidVenda
409 case 0x434 : // lidXhosa
410 case 0x435 : // lidZulu
411 case 0x436 : // lidAfrikaans
412 case 0x425 : // lidEstonian
413 case 0x456 : // lidGalician
414 case 0x41b : // lidSlovak
415 case 0x1409 : // lidEnglishNewZealand
416 case 0x1809 : // lidEnglishIreland
417 case 0x1c09 : // lidEnglishSouthAfrica
418 case 0x2009 : // lidEnglishJamaica
419 case 0x2409 : // lidEnglishCaribbean
420 case 0x2809 : // lidEnglishBelize
421 case 0x2c09 : // lidEnglishTrinidad
422 case 0x3009 : // lidEnglishZimbabwe
423 case 0x3409 : // lidEnglishPhilippines
424 case 0x3809 : // lidEnglishIndonesia
425 case 0x3c09 : // lidEnglishHongKong
426 case 0x4009 : // lidEnglishIndia
427 case 0x4409 : // lidEnglishMalaysia
428 case 0x4809 : // lidEnglishSingapore
429 case 0x80a : // lidSpanishMexican, lidMexican
430 case 0xc0a : // lidSpanishModern
431 case 0x100a : // lidGuatemala
432 case 0x140a : // lidCostaRica
433 case 0x180a : // lidPanama
434 case 0x1c0a : // lidDominicanRepublic
435 case 0x200a : // lidSpanishSA, lidVenezuela
436 case 0x240a : // lidColombia
437 case 0x280a : // lidPeru
438 case 0x2c0a : // lidArgentina
439 case 0x300a : // lidEcuador
440 case 0x340a : // lidChile
441 case 0x380a : // lidUruguay
442 case 0x3c0a : // lidParguay
443 case 0x400a : // lidBolivia
444 case 0x440a : // lidElSalvador
445 case 0x480a : // lidHonduras
446 case 0x4c0a : // lidNicaragua
447 case 0x500a : // lidPuertoRico
448 case 0x540a : // lidSpanishUS
449 case 0x80c : // lidFrenchBelgian
450 case 0x100c : // lidFrenchSwiss
451 case 0x140c : // lidFrenchLuxembourg
452 case 0x180c : // lidFrenchMonaco
453 case 0x1c0c : // lidFrenchWestIndies
454 case 0x200c : // lidFrenchReunion
455 case 0x240c : // lidFrenchCongoDRC, lidFrenchZaire
456 case 0x280c : // lidFrenchSenegal
457 case 0x2c0c : // lidFrenchCameroon
458 case 0x300c : // lidFrenchCotedIvoire
459 case 0x340c : // lidFrenchMali
460 case 0x3c0c : // lidFrenchHaiti
461 case 0x380c : // lidFrenchMorocco
462 case 0x40f : // lidIcelandic
463 case 0x810 : // lidItalianSwiss
464 case 0x417 : // lidRhaetoRomanic, lidRomanic
465 case 0x81a : // lidSerbianLatinSerbMont, lidCroatSerbo
466 case 0x101a : // lidBosniaHerzegovina
467 case 0x141a : // lidBosnianBosniaHerzegovinaLatin
468 case 0x181a : // lidSerbianBosniaHerzegovinaLatin
469 case 0x2c1a : // lidSerbianMontenegroLatin
470 case 0x41c : // lidAlbanian
471 case 0x81d : // lidSwedishFinland
472 case 0x421 : // lidBahasa, lidIndonesian
473 case 0x42c : // lidAzeriLatin
474 case 0x42e : // lidSorbian
475 case 0x82e : // lidLowerSorbian
476 case 0x438 : // lidFaeroese
477 case 0x43a : // lidMaltese
478 case 0x43b : // lidSamiLappish
479 case 0x83b : // lidNorthSamiSwe
480 case 0xc3b : // lidNorthernSamiFi
481 case 0x103b : // lidLuleSamiNor
482 case 0x143b : // lidLuleSamiSwe
483 case 0x183b : // lidSouthSamiNor
484 case 0x1c3b : // lidSouthSamiSwe
485 case 0x203b : // lidSkoltSami
486 case 0x243b : // lidInariSami
487 case 0x43e : // lidMalaysian
488 case 0x83e : // lidMalayBrunei
489 case 0x441 : // lidSwahili
490 case 0x442 : // lidTurkmen
491 case 0x443 : // lidUzbekLatin
492 case 0x452 : // lidWelsh
493 case 0x85d : // lidInuktitutLatin
494 case 0x85f : // lidTamazightLatin
495 case 0x462 : // lidFrisian
496 case 0x464 : // lidFilipino
497 case 0x466 : // lidEdo
498 case 0x467 : // lidFulfulde
499 case 0x468 : // lidHausa
500 case 0x469 : // lidIbibio
501 case 0x46a : // lidYoruba
502 case 0x46b : // lidQuechuaBol
503 case 0x86b : // lidQuechuaEcu
504 case 0xc6b : // lidQuechuaPe
505 case 0x46c : // lidSesothoSaLeboa
506 case 0x46e : // lidLuxembourgish
507 case 0x46f : // lidGreenlandic
508 case 0x470 : // lidIgbo
509 case 0x471 : // lidKanuri
510 case 0x472 : // lidOromo
511 case 0x474 : // lidGuarani
512 case 0x475 : // lidHawaiian
513 case 0x476 : // lidLatin
514 case 0x477 : // lidSomali
515 case 0x47a : // lidMapudungun
516 case 0x47c : // lidMohawk
517 case 0x47e : // lidBreton
518 case 0x481 : // lidMaori
519 case 0x482 : // lidOccitan
520 case 0x483 : // lidCorsican
521 case 0x484 : // lidAlsatian
522 case 0x486 : // lidKiche
523 case 0x487 : // lidKinyarwanda
524 case 0x488 : // lidWolof
525 return OUString("Latn");
526 case 0x44c : // lidMalayalam
527 return OUString("Mlym");
528 case 0x850 : // lidMongolianMongo
529 return OUString("Mong");
530 case 0x455 : // lidBurmese
531 return OUString("Mymr");
532 case 0x448 : // lidOriya
533 return OUString("Orya");
534 case 0x45b : // lidSinhalese
535 return OUString("Sinh");
536 case 0x45a : // lidSyriac
537 return OUString("Syrc");
538 case 0x449 : // lidTamil
539 return OUString("Taml");
540 case 0x44a : // lidTelugu
541 return OUString("Telu");
542 case 0x465 : // lidMaldivian
543 return OUString("Thaa");
544 case 0x41e : // lidThai
545 return OUString("Thai");
546 case 0x451 : // lidTibetan
547 case 0x851 : // lidBhutanese
548 return OUString("Tibt");
549 case 0x480 : // lidUighur
550 return OUString("Uigh");
551 case 0x42a : // lidVietnamese
552 return OUString("Viet");
553 case 0x478 : // lidYi
554 return OUString("Yiii");
555 default:
556 return OUString();
560 }//namespace dmapper
561 } //namespace writerfilter
563 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */