1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <ThemeTable.hxx>
25 #ifndef INCLUDED_RESOURCESIDS
26 #include <doctok/resourceids.hxx>
27 #include <ooxml/resourceids.hxx>
28 #endif
29 #ifdef DEBUG_DMAPPER_THEME_TABLE
30 #include <resourcemodel/QNameToString.hxx>
31 #endif
32 #include "dmapperLoggers.hxx"
33 
34 #ifdef DEBUG_DOMAINMAPPER
35 #include <resourcemodel/QNameToString.hxx>
36 #endif
37 
38 namespace writerfilter {
39 namespace dmapper
40 {
41 
42 struct ThemeTable_Impl
43 {
ThemeTable_Implwriterfilter::dmapper::ThemeTable_Impl44     ThemeTable_Impl() :
45         m_currentThemeFontId(0),
46         m_currentFontThemeEntry() {}
47     std::map<sal_uInt32, std::map<sal_uInt32, ::rtl::OUString> > m_themeFontMap;
48     sal_uInt32 m_currentThemeFontId;
49     std::map<sal_uInt32, ::rtl::OUString> m_currentFontThemeEntry;
50 };
51 
ThemeTable()52 ThemeTable::ThemeTable()
53 : LoggedProperties(dmapper_logger, "ThemeTable")
54 , LoggedTable(dmapper_logger, "ThemeTable")
55 , m_pImpl( new ThemeTable_Impl )
56 {
57 }
58 
~ThemeTable()59 ThemeTable::~ThemeTable()
60 {
61     delete m_pImpl;
62 }
63 
lcl_attribute(Id Name,Value & val)64 void ThemeTable::lcl_attribute(Id Name, Value & val)
65 {
66 #ifdef DEBUG_DMAPPER_THEME_TABLE
67     dmapper_logger->startElement("ThemeTable.attribute");
68     dmapper_logger->attribute("name", (*QNameToString::Instance())(Name));
69     dmapper_logger->attribute("value", val.toString());
70 #endif
71     // int nIntValue = val.getInt();
72     ::rtl::OUString sValue = val.getString();
73     /* WRITERFILTERSTATUS: table: ThemeTable_attributedata */
74     switch(Name)
75     {
76         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
77     	case NS_ooxml::LN_CT_TextFont_typeface:
78 	     if (sValue.getLength())
79 	         m_pImpl->m_currentFontThemeEntry[m_pImpl->m_currentThemeFontId] = sValue;
80 	     break;
81         default:
82         {
83 #ifdef DEBUG_DOMAINMAPPER
84             dmapper_logger->element("ThemeTable.unhandled");
85 #endif
86         }
87     }
88 #ifdef DEBUG_DMAPPER_THEME_TABLE
89     dmapper_logger->endElement("ThemeTable.attribute");
90 #endif
91 }
92 
lcl_sprm(Sprm & rSprm)93 void ThemeTable::lcl_sprm(Sprm& rSprm)
94 {
95 #ifdef DEBUG_DMAPPER_THEME_TABLE
96     dmapper_logger->startElement("ThemeTable.sprm");
97     dmapper_logger->chars(rSprm.toString());
98 #endif
99 
100     sal_uInt32 nSprmId = rSprm.getId();
101     (void)nSprmId;
102 
103     Value::Pointer_t pValue = rSprm.getValue();
104     sal_Int32 nIntValue = pValue->getInt();
105     (void)nIntValue;
106     rtl::OUString sStringValue = pValue->getString();
107 
108     /* WRITERFILTERSTATUS: table: ThemeTable_sprm */
109     switch(nSprmId)
110     {
111         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
112     case NS_ooxml::LN_CT_BaseStyles_fontScheme:
113         {
114     	    writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
115             if( pProperties.get())
116                 pProperties->resolve(*this);
117 	}
118 	break;
119         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
120     case NS_ooxml::LN_CT_FontScheme_majorFont:
121         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
122     case NS_ooxml::LN_CT_FontScheme_minorFont:
123         {
124     	    writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
125 	    m_pImpl->m_currentFontThemeEntry = std::map<sal_uInt32, rtl::OUString>();
126             if( pProperties.get())
127                 pProperties->resolve(*this);
128             m_pImpl->m_themeFontMap[nSprmId] = m_pImpl->m_currentFontThemeEntry;
129 	}
130 	break;
131         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
132     case NS_ooxml::LN_CT_FontCollection_latin:
133         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
134     case NS_ooxml::LN_CT_FontCollection_ea:
135         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
136     case NS_ooxml::LN_CT_FontCollection_cs:
137         {
138 	    m_pImpl->m_currentThemeFontId = nSprmId;
139     	    writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
140             if( pProperties.get())
141                 pProperties->resolve(*this);
142 	}
143 	break;
144     default:
145         {
146 #ifdef DEBUG_DMAPPER_THEME_TABLE
147             dmapper_logger->element("ThemeTable.unhandled");
148 #endif
149         }
150     }
151 #ifdef DEBUG_DMAPPER_THEME_TABLE
152     dmapper_logger->endElement("ThemeTable.sprm");
153 #endif
154 }
155 
lcl_entry(int,writerfilter::Reference<Properties>::Pointer_t ref)156 void ThemeTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
157 {
158 #ifdef DEBUG_DMAPPER_THEME_TABLE
159     dmapper_logger->startElement("ThemeTable.entry");
160 #endif
161 
162     ref->resolve(*this);
163 
164 #ifdef DEBUG_DMAPPER_THEME_TABLE
165     dmapper_logger->endElement("ThemeTable.entry");
166 #endif
167 }
168 
getFontNameForTheme(const Id id) const169 const ::rtl::OUString ThemeTable::getFontNameForTheme(const Id id) const
170 {
171     std::map<sal_uInt32, ::rtl::OUString> tmpThemeFontMap;
172     switch (id)
173     {
174     case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
175     case NS_ooxml::LN_Value_ST_Theme_majorBidi:
176     case NS_ooxml::LN_Value_ST_Theme_majorAscii:
177     case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
178         tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_majorFont];
179 	break;
180     case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
181     case NS_ooxml::LN_Value_ST_Theme_minorBidi:
182     case NS_ooxml::LN_Value_ST_Theme_minorAscii:
183     case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
184         tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_minorFont];
185 	break;
186     default:
187         return ::rtl::OUString();
188     }
189 
190     switch (id)
191     {
192     case NS_ooxml::LN_Value_ST_Theme_majorAscii:
193     case NS_ooxml::LN_Value_ST_Theme_majorHAnsi:
194     case NS_ooxml::LN_Value_ST_Theme_minorAscii:
195     case NS_ooxml::LN_Value_ST_Theme_minorHAnsi:
196 	{
197 	     std::map<sal_uInt32, ::rtl::OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_latin);
198              if (Iter != tmpThemeFontMap.end())
199                   return (Iter)->second;
200              return ::rtl::OUString();
201         }
202     case NS_ooxml::LN_Value_ST_Theme_majorBidi:
203     case NS_ooxml::LN_Value_ST_Theme_minorBidi:
204         {
205              std::map<sal_uInt32, ::rtl::OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_cs);
206              if (Iter != tmpThemeFontMap.end())
207                  return (Iter)->second;
208              return ::rtl::OUString();
209         }
210     case NS_ooxml::LN_Value_ST_Theme_majorEastAsia:
211     case NS_ooxml::LN_Value_ST_Theme_minorEastAsia:
212         {
213              std::map<sal_uInt32, ::rtl::OUString>::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_ea);
214              if (Iter != tmpThemeFontMap.end())
215                  return (Iter)->second;
216              return ::rtl::OUString();
217         }
218     default:
219 	return ::rtl::OUString();
220     }
221 }
222 
223 }//namespace dmapper
224 } //namespace writerfilter
225