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 50 : struct ThemeTable_Impl
34 : {
35 50 : ThemeTable_Impl() :
36 : m_currentThemeFontId(0),
37 50 : 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 50 : ThemeTable::ThemeTable()
44 : : LoggedProperties(dmapper_logger, "ThemeTable")
45 : , LoggedTable(dmapper_logger, "ThemeTable")
46 50 : , m_pImpl( new ThemeTable_Impl )
47 : {
48 :
49 50 : }
50 :
51 150 : ThemeTable::~ThemeTable()
52 : {
53 50 : delete m_pImpl;
54 100 : }
55 :
56 350 : 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 350 : OUString sValue = val.getString();
64 350 : switch(Name)
65 : {
66 : case NS_ooxml::LN_CT_TextFont_typeface:
67 300 : if (!sValue.isEmpty())
68 100 : m_pImpl->m_currentFontThemeEntry[m_pImpl->m_currentThemeFontId] = sValue;
69 300 : break;
70 : default:
71 : {
72 : #ifdef DEBUG_DOMAINMAPPER
73 : dmapper_logger->element("unhandled");
74 : #endif
75 : }
76 350 : }
77 : #ifdef DEBUG_DOMAINMAPPER
78 : dmapper_logger->endElement();
79 : #endif
80 350 : }
81 :
82 3480 : 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 3480 : sal_uInt32 nSprmId = rSprm.getId();
90 :
91 3480 : switch(nSprmId)
92 : {
93 : case NS_ooxml::LN_CT_BaseStyles_fontScheme:
94 : {
95 50 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
96 50 : if( pProperties.get())
97 50 : pProperties->resolve(*this);
98 : }
99 50 : break;
100 : case NS_ooxml::LN_CT_FontScheme_majorFont:
101 : case NS_ooxml::LN_CT_FontScheme_minorFont:
102 : {
103 100 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
104 100 : m_pImpl->m_currentFontThemeEntry = std::map<sal_uInt32, OUString>();
105 100 : if( pProperties.get())
106 100 : pProperties->resolve(*this);
107 100 : m_pImpl->m_themeFontMap[nSprmId] = m_pImpl->m_currentFontThemeEntry;
108 : }
109 100 : 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:
113 : {
114 300 : m_pImpl->m_currentThemeFontId = nSprmId;
115 300 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
116 300 : if( pProperties.get())
117 300 : pProperties->resolve(*this);
118 : }
119 300 : break;
120 : default:
121 : {
122 : #ifdef DEBUG_DOMAINMAPPER
123 : dmapper_logger->element("unhandled");
124 : #endif
125 : }
126 : }
127 : #ifdef DEBUG_DOMAINMAPPER
128 : dmapper_logger->endElement();
129 : #endif
130 3480 : }
131 :
132 50 : void ThemeTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
133 : {
134 : #ifdef DEBUG_DOMAINMAPPER
135 : dmapper_logger->startElement("ThemeTable.entry");
136 : #endif
137 :
138 50 : ref->resolve(*this);
139 :
140 : #ifdef DEBUG_DOMAINMAPPER
141 : dmapper_logger->endElement();
142 : #endif
143 50 : }
144 :
145 299 : const OUString ThemeTable::getFontNameForTheme(const Id id) const
146 : {
147 299 : std::map<sal_uInt32, OUString> tmpThemeFontMap;
148 299 : switch (id)
149 : {
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 155 : tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_majorFont];
155 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 144 : tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_minorFont];
161 144 : break;
162 : default:
163 0 : return OUString();
164 : }
165 :
166 299 : switch (id)
167 : {
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:
172 : {
173 157 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_latin);
174 157 : if (Iter != tmpThemeFontMap.end())
175 157 : return (Iter)->second;
176 0 : return OUString();
177 : }
178 : case NS_ooxml::LN_Value_ST_Theme_majorBidi:
179 : case NS_ooxml::LN_Value_ST_Theme_minorBidi:
180 : {
181 82 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_cs);
182 82 : if (Iter != tmpThemeFontMap.end())
183 0 : return (Iter)->second;
184 82 : return OUString();
185 : }
186 : case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
187 : case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
188 : {
189 60 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_ea);
190 60 : if (Iter != tmpThemeFontMap.end())
191 0 : return (Iter)->second;
192 60 : return OUString();
193 : }
194 : default:
195 0 : return OUString();
196 299 : }
197 : }
198 :
199 : }//namespace dmapper
200 15 : } //namespace writerfilter
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|