Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <ThemeTable.hxx>
21 : : #include <doctok/resourceids.hxx>
22 : : #include <ooxml/resourceids.hxx>
23 : : #include "dmapperLoggers.hxx"
24 : :
25 : : #if DEBUG_DOMAINMAPPER
26 : : #include <resourcemodel/QNameToString.hxx>
27 : : #endif
28 : :
29 : : namespace writerfilter {
30 : : namespace dmapper
31 : : {
32 : :
33 : 83 : struct ThemeTable_Impl
34 : : {
35 : 83 : ThemeTable_Impl() :
36 : : m_currentThemeFontId(0),
37 [ + - ]: 83 : 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;
41 : : };
42 : :
43 : 83 : ThemeTable::ThemeTable()
44 : : : LoggedProperties(dmapper_logger, "ThemeTable")
45 : : , LoggedTable(dmapper_logger, "ThemeTable")
46 [ + - ][ + - ]: 83 : , m_pImpl( new ThemeTable_Impl )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
47 : : {
48 : :
49 : 83 : }
50 : :
51 [ + - ]: 83 : ThemeTable::~ThemeTable()
52 : : {
53 [ + - ]: 83 : delete m_pImpl;
54 [ - + ]: 166 : }
55 : :
56 : 581 : void ThemeTable::lcl_attribute(Id Name, Value & val)
57 : : {
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 [ + - ]: 581 : OUString sValue = val.getString();
64 [ + + ]: 581 : switch(Name)
65 : : {
66 : : case NS_ooxml::LN_CT_TextFont_typeface:
67 [ + + ]: 498 : if (!sValue.isEmpty())
68 [ + - ]: 166 : m_pImpl->m_currentFontThemeEntry[m_pImpl->m_currentThemeFontId] = sValue;
69 : 498 : break;
70 : : default:
71 : : {
72 : : #ifdef DEBUG_DOMAINMAPPER
73 : : dmapper_logger->element("unhandled");
74 : : #endif
75 : : }
76 : 581 : }
77 : : #ifdef DEBUG_DOMAINMAPPER
78 : : dmapper_logger->endElement();
79 : : #endif
80 : 581 : }
81 : :
82 : 5751 : void ThemeTable::lcl_sprm(Sprm& rSprm)
83 : : {
84 : : #ifdef DEBUG_DOMAINMAPPER
85 : : dmapper_logger->startElement("ThemeTable.sprm");
86 : : dmapper_logger->chars(rSprm.toString());
87 : : #endif
88 : :
89 [ + - ]: 5751 : sal_uInt32 nSprmId = rSprm.getId();
90 : : (void)nSprmId;
91 : :
92 [ + - ][ + - ]: 5751 : Value::Pointer_t pValue = rSprm.getValue();
93 [ + - ]: 5751 : sal_Int32 nIntValue = pValue->getInt();
94 : : (void)nIntValue;
95 [ + - ]: 5751 : OUString sStringValue = pValue->getString();
96 : :
97 [ + + + + ]: 5751 : switch(nSprmId)
98 : : {
99 : : case NS_ooxml::LN_CT_BaseStyles_fontScheme:
100 : : {
101 [ + - ]: 83 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
102 [ + - ]: 83 : if( pProperties.get())
103 [ + - ][ + - ]: 83 : pProperties->resolve(*this);
104 : : }
105 : 83 : break;
106 : : case NS_ooxml::LN_CT_FontScheme_majorFont:
107 : : case NS_ooxml::LN_CT_FontScheme_minorFont:
108 : : {
109 [ + - ]: 166 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
110 [ + - ][ + - ]: 166 : m_pImpl->m_currentFontThemeEntry = std::map<sal_uInt32, OUString>();
111 [ + - ]: 166 : if( pProperties.get())
112 [ + - ]: 166 : pProperties->resolve(*this);
113 [ + - ][ + - ]: 166 : m_pImpl->m_themeFontMap[nSprmId] = m_pImpl->m_currentFontThemeEntry;
[ + - ]
114 : : }
115 : 166 : break;
116 : : case NS_ooxml::LN_CT_FontCollection_latin:
117 : : case NS_ooxml::LN_CT_FontCollection_ea:
118 : : case NS_ooxml::LN_CT_FontCollection_cs:
119 : : {
120 : 498 : m_pImpl->m_currentThemeFontId = nSprmId;
121 [ + - ]: 498 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
122 [ + - ]: 498 : if( pProperties.get())
123 [ + - ][ + - ]: 498 : pProperties->resolve(*this);
124 : : }
125 : 498 : break;
126 : : default:
127 : : {
128 : : #ifdef DEBUG_DOMAINMAPPER
129 : : dmapper_logger->element("unhandled");
130 : : #endif
131 : : }
132 [ + - ]: 5751 : }
133 : : #ifdef DEBUG_DOMAINMAPPER
134 : : dmapper_logger->endElement();
135 : : #endif
136 : 5751 : }
137 : :
138 : 83 : void ThemeTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
139 : : {
140 : : #ifdef DEBUG_DOMAINMAPPER
141 : : dmapper_logger->startElement("ThemeTable.entry");
142 : : #endif
143 : :
144 : 83 : ref->resolve(*this);
145 : :
146 : : #ifdef DEBUG_DOMAINMAPPER
147 : : dmapper_logger->endElement();
148 : : #endif
149 : 83 : }
150 : :
151 : 366 : const OUString ThemeTable::getFontNameForTheme(const Id id) const
152 : : {
153 [ + - ]: 366 : std::map<sal_uInt32, OUString> tmpThemeFontMap;
154 [ + + - ]: 366 : switch (id)
155 : : {
156 : : case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
157 : : case NS_ooxml::LN_Value_ST_Theme_majorBidi:
158 : : case NS_ooxml::LN_Value_ST_Theme_majorAscii:
159 : : case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
160 [ + - ][ + - ]: 162 : tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_majorFont];
161 : 162 : break;
162 : : case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
163 : : case NS_ooxml::LN_Value_ST_Theme_minorBidi:
164 : : case NS_ooxml::LN_Value_ST_Theme_minorAscii:
165 : : case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
166 [ + - ][ + - ]: 204 : tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_minorFont];
167 : 204 : break;
168 : : default:
169 : 0 : return OUString();
170 : : }
171 : :
172 [ + + + - ]: 366 : switch (id)
173 : : {
174 : : case NS_ooxml::LN_Value_ST_Theme_majorAscii:
175 : : case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
176 : : case NS_ooxml::LN_Value_ST_Theme_minorAscii:
177 : : case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
178 : : {
179 [ + - ]: 156 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_latin);
180 [ + - ]: 156 : if (Iter != tmpThemeFontMap.end())
181 : 156 : return (Iter)->second;
182 : 156 : return OUString();
183 : : }
184 : : case NS_ooxml::LN_Value_ST_Theme_majorBidi:
185 : : case NS_ooxml::LN_Value_ST_Theme_minorBidi:
186 : : {
187 [ + - ]: 114 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_cs);
188 [ - + ]: 114 : if (Iter != tmpThemeFontMap.end())
189 : 0 : return (Iter)->second;
190 : 114 : return OUString();
191 : : }
192 : : case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
193 : : case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
194 : : {
195 [ + - ]: 96 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_ea);
196 [ - + ]: 96 : if (Iter != tmpThemeFontMap.end())
197 : 0 : return (Iter)->second;
198 : 96 : return OUString();
199 : : }
200 : : default:
201 : 0 : return OUString();
202 : 366 : }
203 : : }
204 : :
205 : : }//namespace dmapper
206 [ + - ][ + - ]: 60 : } //namespace writerfilter
207 : :
208 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|