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 98 : struct ThemeTable_Impl
34 : {
35 98 : ThemeTable_Impl() :
36 : m_currentThemeFontId(0),
37 98 : 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 98 : ThemeTable::ThemeTable()
44 : : LoggedProperties(dmapper_logger, "ThemeTable")
45 : , LoggedTable(dmapper_logger, "ThemeTable")
46 98 : , m_pImpl( new ThemeTable_Impl )
47 : {
48 :
49 98 : }
50 :
51 294 : ThemeTable::~ThemeTable()
52 : {
53 98 : delete m_pImpl;
54 196 : }
55 :
56 686 : 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 686 : OUString sValue = val.getString();
64 686 : switch(Name)
65 : {
66 : case NS_ooxml::LN_CT_TextFont_typeface:
67 588 : if (!sValue.isEmpty())
68 196 : m_pImpl->m_currentFontThemeEntry[m_pImpl->m_currentThemeFontId] = sValue;
69 588 : break;
70 : default:
71 : {
72 : #ifdef DEBUG_DOMAINMAPPER
73 : dmapper_logger->element("unhandled");
74 : #endif
75 : }
76 686 : }
77 : #ifdef DEBUG_DOMAINMAPPER
78 : dmapper_logger->endElement();
79 : #endif
80 686 : }
81 :
82 6822 : 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 6822 : sal_uInt32 nSprmId = rSprm.getId();
90 :
91 6822 : switch(nSprmId)
92 : {
93 : case NS_ooxml::LN_CT_BaseStyles_fontScheme:
94 : {
95 98 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
96 98 : if( pProperties.get())
97 98 : pProperties->resolve(*this);
98 : }
99 98 : break;
100 : case NS_ooxml::LN_CT_FontScheme_majorFont:
101 : case NS_ooxml::LN_CT_FontScheme_minorFont:
102 : {
103 196 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
104 196 : m_pImpl->m_currentFontThemeEntry = std::map<sal_uInt32, OUString>();
105 196 : if( pProperties.get())
106 196 : pProperties->resolve(*this);
107 196 : m_pImpl->m_themeFontMap[nSprmId] = m_pImpl->m_currentFontThemeEntry;
108 : }
109 196 : 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 588 : m_pImpl->m_currentThemeFontId = nSprmId;
115 588 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
116 588 : if( pProperties.get())
117 588 : pProperties->resolve(*this);
118 : }
119 588 : 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 6822 : }
131 :
132 98 : 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 98 : ref->resolve(*this);
139 :
140 : #ifdef DEBUG_DOMAINMAPPER
141 : dmapper_logger->endElement();
142 : #endif
143 98 : }
144 :
145 592 : const OUString ThemeTable::getFontNameForTheme(const Id id) const
146 : {
147 592 : std::map<sal_uInt32, OUString> tmpThemeFontMap;
148 592 : 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 310 : tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_majorFont];
155 310 : 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 282 : tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_minorFont];
161 282 : break;
162 : default:
163 0 : return OUString();
164 : }
165 :
166 592 : 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 312 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_latin);
174 312 : if (Iter != tmpThemeFontMap.end())
175 312 : 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 162 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_cs);
182 162 : if (Iter != tmpThemeFontMap.end())
183 0 : return (Iter)->second;
184 162 : return OUString();
185 : }
186 : case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
187 : case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
188 : {
189 118 : std::map<sal_uInt32, OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_ea);
190 118 : if (Iter != tmpThemeFontMap.end())
191 0 : return (Iter)->second;
192 118 : return OUString();
193 : }
194 : default:
195 0 : return OUString();
196 592 : }
197 : }
198 :
199 : }//namespace dmapper
200 30 : } //namespace writerfilter
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|