Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / dmapper / ThemeTable.cxx
blobbd89130ca5a7b20fde09999d66fb63945a562b0b
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 <doctok/resourceids.hxx>
22 #include <ooxml/resourceids.hxx>
23 #include "dmapperLoggers.hxx"
25 #ifdef DEBUG_DOMAINMAPPER
26 #include <resourcemodel/QNameToString.hxx>
27 #endif
29 namespace writerfilter {
30 namespace dmapper
33 struct ThemeTable_Impl
35 ThemeTable_Impl() :
36 m_currentThemeFontId(0),
37 m_currentFontThemeEntry() {}
38 std::map<sal_uInt32, std::map<sal_uInt32, OUString> > m_themeFontMap;
39 sal_uInt32 m_currentThemeFontId;
40 std::map<sal_uInt32, OUString> m_currentFontThemeEntry;
43 ThemeTable::ThemeTable()
44 : LoggedProperties(dmapper_logger, "ThemeTable")
45 , LoggedTable(dmapper_logger, "ThemeTable")
46 , m_pImpl( new ThemeTable_Impl )
51 ThemeTable::~ThemeTable()
53 delete m_pImpl;
56 void ThemeTable::lcl_attribute(Id Name, Value & val)
58 #ifdef DEBUG_DOMAINMAPPER
59 dmapper_logger->startElement("ThemeTable.attribute");
60 dmapper_logger->attribute("name", (*QNameToString::Instance())(Name));
61 dmapper_logger->attribute("value", val.toString());
62 #endif
63 OUString sValue = val.getString();
64 switch(Name)
66 case NS_ooxml::LN_CT_TextFont_typeface:
67 if (!sValue.isEmpty())
68 m_pImpl->m_currentFontThemeEntry[m_pImpl->m_currentThemeFontId] = sValue;
69 break;
70 default:
72 #ifdef DEBUG_DOMAINMAPPER
73 dmapper_logger->element("unhandled");
74 #endif
77 #ifdef DEBUG_DOMAINMAPPER
78 dmapper_logger->endElement();
79 #endif
82 void ThemeTable::lcl_sprm(Sprm& rSprm)
84 #ifdef DEBUG_DOMAINMAPPER
85 dmapper_logger->startElement("ThemeTable.sprm");
86 dmapper_logger->chars(rSprm.toString());
87 #endif
89 sal_uInt32 nSprmId = rSprm.getId();
91 switch(nSprmId)
93 case NS_ooxml::LN_CT_BaseStyles_fontScheme:
95 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
96 if( pProperties.get())
97 pProperties->resolve(*this);
99 break;
100 case NS_ooxml::LN_CT_FontScheme_majorFont:
101 case NS_ooxml::LN_CT_FontScheme_minorFont:
103 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
104 m_pImpl->m_currentFontThemeEntry = std::map<sal_uInt32, OUString>();
105 if( pProperties.get())
106 pProperties->resolve(*this);
107 m_pImpl->m_themeFontMap[nSprmId] = m_pImpl->m_currentFontThemeEntry;
109 break;
110 case NS_ooxml::LN_CT_FontCollection_latin:
111 case NS_ooxml::LN_CT_FontCollection_ea:
112 case NS_ooxml::LN_CT_FontCollection_cs:
114 m_pImpl->m_currentThemeFontId = nSprmId;
115 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
116 if( pProperties.get())
117 pProperties->resolve(*this);
119 break;
120 default:
122 #ifdef DEBUG_DOMAINMAPPER
123 dmapper_logger->element("unhandled");
124 #endif
127 #ifdef DEBUG_DOMAINMAPPER
128 dmapper_logger->endElement();
129 #endif
132 void ThemeTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
134 #ifdef DEBUG_DOMAINMAPPER
135 dmapper_logger->startElement("ThemeTable.entry");
136 #endif
138 ref->resolve(*this);
140 #ifdef DEBUG_DOMAINMAPPER
141 dmapper_logger->endElement();
142 #endif
145 const OUString ThemeTable::getFontNameForTheme(const Id id) const
147 std::map<sal_uInt32, OUString> tmpThemeFontMap;
148 switch (id)
150 case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
151 case NS_ooxml::LN_Value_ST_Theme_majorBidi:
152 case NS_ooxml::LN_Value_ST_Theme_majorAscii:
153 case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
154 tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_majorFont];
155 break;
156 case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
157 case NS_ooxml::LN_Value_ST_Theme_minorBidi:
158 case NS_ooxml::LN_Value_ST_Theme_minorAscii:
159 case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
160 tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_minorFont];
161 break;
162 default:
163 return OUString();
166 switch (id)
168 case NS_ooxml::LN_Value_ST_Theme_majorAscii:
169 case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
170 case NS_ooxml::LN_Value_ST_Theme_minorAscii:
171 case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
173 std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_latin);
174 if (Iter != tmpThemeFontMap.end())
175 return (Iter)->second;
176 return OUString();
178 case NS_ooxml::LN_Value_ST_Theme_majorBidi:
179 case NS_ooxml::LN_Value_ST_Theme_minorBidi:
181 std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_cs);
182 if (Iter != tmpThemeFontMap.end())
183 return (Iter)->second;
184 return OUString();
186 case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
187 case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
189 std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_ea);
190 if (Iter != tmpThemeFontMap.end())
191 return (Iter)->second;
192 return OUString();
194 default:
195 return OUString();
199 }//namespace dmapper
200 } //namespace writerfilter
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */