Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /* TextRunStyle: Stores (and writes) paragraph/span-style-based information
3 : : * (e.g.: a paragraph might be bold) that is needed at the head of an OO
4 : : * document.
5 : : *
6 : : * This Source Code Form is subject to the terms of the Mozilla Public
7 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
8 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 : : *
10 : : * For further information visit http://libwpd.sourceforge.net
11 : : */
12 : :
13 : : /* "This product is not manufactured, approved, or supported by
14 : : * Corel Corporation or Corel Corporation Limited."
15 : : */
16 : : #include "FilterInternal.hxx"
17 : : #include "TextRunStyle.hxx"
18 : : #include "DocumentElement.hxx"
19 : :
20 : : #ifdef _MSC_VER
21 : : #include <minmax.h>
22 : : #endif
23 : :
24 : : #include <string.h>
25 : :
26 : 0 : ParagraphStyle::ParagraphStyle(const WPXPropertyList &pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
27 : : mpPropList(pPropList),
28 : : mxTabStops(xTabStops),
29 [ # # ][ # # ]: 0 : msName(sName)
30 : : {
31 : 0 : }
32 : :
33 [ # # ][ # # ]: 0 : ParagraphStyle::~ParagraphStyle()
34 : : {
35 [ # # ]: 0 : }
36 : :
37 : 0 : void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
38 : : {
39 : : WRITER_DEBUG_MSG(("Writing a paragraph style..\n"));
40 : :
41 [ # # ]: 0 : WPXPropertyList propList;
42 [ # # ][ # # ]: 0 : propList.insert("style:name", msName.cstr());
43 [ # # ]: 0 : propList.insert("style:family", "paragraph");
44 [ # # ][ # # ]: 0 : if (mpPropList["style:parent-style-name"])
45 [ # # ][ # # ]: 0 : propList.insert("style:parent-style-name", mpPropList["style:parent-style-name"]->getStr());
[ # # ][ # # ]
46 [ # # ][ # # ]: 0 : if (mpPropList["style:master-page-name"])
47 [ # # ][ # # ]: 0 : propList.insert("style:master-page-name", mpPropList["style:master-page-name"]->getStr());
[ # # ][ # # ]
48 [ # # ]: 0 : pHandler->startElement("style:style", propList);
49 : :
50 [ # # ]: 0 : propList.clear();
51 [ # # ]: 0 : WPXPropertyList::Iter i(mpPropList);
52 [ # # ][ # # ]: 0 : for (i.rewind(); i.next(); )
[ # # ]
53 : : {
54 : : #if 0
55 : : if (strcmp(i.key(), "style:list-style-name") == 0)
56 : : propList.insert("style:list-style-name", i()->getStr());
57 : : #endif
58 [ # # ][ # # ]: 0 : if (strncmp(i.key(), "fo:margin-",10) == 0)
59 : : {
60 [ # # ][ # # ]: 0 : if (strcmp(i.key(), "fo:margin-left") == 0 ||
[ # # ][ # # ]
[ # # ]
61 [ # # ]: 0 : strcmp(i.key(), "fo:margin-right") == 0 ||
62 [ # # ]: 0 : strcmp(i.key(), "fo:margin-top") == 0)
63 [ # # ][ # # ]: 0 : propList.insert(i.key(), i()->getStr());
[ # # ][ # # ]
[ # # ]
64 [ # # ][ # # ]: 0 : else if (strcmp(i.key(), "fo:margin-bottom") == 0)
65 : : {
66 [ # # ][ # # ]: 0 : if (i()->getDouble() > 0.0)
[ # # ]
67 [ # # ][ # # ]: 0 : propList.insert("fo:margin-bottom", i()->getStr());
[ # # ][ # # ]
68 : : else
69 [ # # ]: 0 : propList.insert("fo:margin-bottom", 0.0);
70 : : }
71 : : }
72 [ # # ][ # # ]: 0 : else if (strcmp(i.key(), "fo:text-indent") == 0)
73 [ # # ][ # # ]: 0 : propList.insert("fo:text-indent", i()->getStr());
[ # # ][ # # ]
74 [ # # ][ # # ]: 0 : else if (strcmp(i.key(), "fo:line-height") == 0)
75 [ # # ][ # # ]: 0 : propList.insert("fo:line-height", i()->getStr());
[ # # ][ # # ]
76 [ # # ][ # # ]: 0 : else if (strcmp(i.key(), "fo:break-before") == 0)
77 [ # # ][ # # ]: 0 : propList.insert("fo:break-before", i()->getStr());
[ # # ][ # # ]
78 [ # # ][ # # ]: 0 : else if (strcmp(i.key(), "fo:text-align") == 0)
79 [ # # ][ # # ]: 0 : propList.insert("fo:text-align", i()->getStr());
[ # # ][ # # ]
80 [ # # ][ # # ]: 0 : else if (strcmp(i.key(), "fo:text-align-last") == 0)
81 [ # # ][ # # ]: 0 : propList.insert("fo:text-align-last", i()->getStr());
[ # # ][ # # ]
82 [ # # ][ # # ]: 0 : else if (strcmp(i.key(), "style:page-number") == 0)
83 [ # # ][ # # ]: 0 : propList.insert("style:page-number", i()->getStr());
[ # # ][ # # ]
84 [ # # ][ # # ]: 0 : else if (strncmp(i.key(), "fo:border", 9) == 0)
85 : : {
86 [ # # ][ # # ]: 0 : if (strcmp(i.key(), "fo:border") == 0 ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
87 [ # # ]: 0 : strcmp(i.key(), "fo:border-left") == 0 ||
88 [ # # ]: 0 : strcmp(i.key(), "fo:border-right") == 0 ||
89 [ # # ]: 0 : strcmp(i.key(), "fo:border-top") == 0 ||
90 [ # # ]: 0 : strcmp(i.key(), "fo:border-bottom") == 0)
91 [ # # ][ # # ]: 0 : propList.insert(i.key(), i()->getStr());
[ # # ][ # # ]
[ # # ]
92 : : }
93 : : }
94 : :
95 [ # # ]: 0 : propList.insert("style:justify-single-word", "false");
96 [ # # ]: 0 : pHandler->startElement("style:paragraph-properties", propList);
97 : :
98 [ # # ][ # # ]: 0 : if (mxTabStops.count() > 0)
99 : : {
100 [ # # ][ # # ]: 0 : TagOpenElement tabListOpen("style:tab-stops");
[ # # ]
101 [ # # ]: 0 : tabListOpen.write(pHandler);
102 [ # # ]: 0 : WPXPropertyListVector::Iter k(mxTabStops);
103 [ # # ][ # # ]: 0 : for (k.rewind(); k.next();)
[ # # ]
104 : : {
105 [ # # ][ # # ]: 0 : if (k()["style:position"] && k()["style:position"]->getDouble() < 0.0)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
106 : 0 : continue;
107 [ # # ][ # # ]: 0 : TagOpenElement tabStopOpen("style:tab-stop");
[ # # ]
108 : :
109 [ # # ][ # # ]: 0 : WPXPropertyList::Iter j(k());
110 [ # # ][ # # ]: 0 : for (j.rewind(); j.next(); )
[ # # ]
111 : : {
112 [ # # ][ # # ]: 0 : tabStopOpen.addAttribute(j.key(), j()->getStr().cstr());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
113 : : }
114 [ # # ]: 0 : tabStopOpen.write(pHandler);
115 [ # # ]: 0 : pHandler->endElement("style:tab-stop");
116 [ # # ][ # # ]: 0 : }
117 [ # # ][ # # ]: 0 : pHandler->endElement("style:tab-stops");
[ # # ]
118 : : }
119 : :
120 [ # # ]: 0 : pHandler->endElement("style:paragraph-properties");
121 [ # # ][ # # ]: 0 : pHandler->endElement("style:style");
[ # # ]
122 : 0 : }
123 : :
124 : 0 : SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) :
125 : : Style(psName),
126 [ # # ][ # # ]: 0 : mPropList(xPropList)
127 : : {
128 : 0 : }
129 : :
130 : 0 : void SpanStyle::write(OdfDocumentHandler *pHandler) const
131 : : {
132 : : WRITER_DEBUG_MSG(("Writing a span style..\n"));
133 [ # # ]: 0 : WPXPropertyList styleOpenList;
134 [ # # ]: 0 : styleOpenList.insert("style:name", getName());
135 [ # # ]: 0 : styleOpenList.insert("style:family", "text");
136 [ # # ]: 0 : pHandler->startElement("style:style", styleOpenList);
137 : :
138 [ # # ]: 0 : WPXPropertyList propList(mPropList);
139 : :
140 [ # # ][ # # ]: 0 : if (mPropList["style:font-name"])
141 : : {
142 [ # # ][ # # ]: 0 : propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr());
[ # # ][ # # ]
143 [ # # ][ # # ]: 0 : propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr());
[ # # ][ # # ]
144 : : }
145 : :
146 [ # # ][ # # ]: 0 : if (mPropList["fo:font-size"])
147 : : {
148 [ # # ][ # # ]: 0 : if (mPropList["fo:font-size"]->getDouble() > 0.0)
[ # # ]
149 : : {
150 [ # # ][ # # ]: 0 : propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr());
[ # # ][ # # ]
151 [ # # ][ # # ]: 0 : propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr());
[ # # ][ # # ]
152 : : }
153 : : else
154 [ # # ]: 0 : propList.remove("fo:font-size");
155 : : }
156 : :
157 [ # # ][ # # ]: 0 : if (mPropList["fo:font-weight"])
158 : : {
159 [ # # ][ # # ]: 0 : propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr());
[ # # ][ # # ]
160 [ # # ][ # # ]: 0 : propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr());
[ # # ][ # # ]
161 : : }
162 : :
163 [ # # ][ # # ]: 0 : if (mPropList["fo:font-style"])
164 : : {
165 [ # # ][ # # ]: 0 : propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr());
[ # # ][ # # ]
166 [ # # ][ # # ]: 0 : propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr());
[ # # ][ # # ]
167 : : }
168 : :
169 [ # # ]: 0 : pHandler->startElement("style:text-properties", propList);
170 : :
171 [ # # ]: 0 : pHandler->endElement("style:text-properties");
172 [ # # ][ # # ]: 0 : pHandler->endElement("style:style");
[ # # ]
173 : 0 : }
174 : :
175 : 0 : void ParagraphStyleManager::clean()
176 : : {
177 : 0 : mNameHash.clear();
178 : 0 : mStyleHash.clear();
179 : 0 : }
180 : :
181 : 0 : void ParagraphStyleManager::write(OdfDocumentHandler *pHandler) const
182 : : {
183 [ # # ]: 0 : for (std::map<WPXString, shared_ptr<ParagraphStyle>, ltstr>::const_iterator iter = mStyleHash.begin();
184 : 0 : iter != mStyleHash.end(); ++iter)
185 : : {
186 [ # # ][ # # ]: 0 : if (strcmp(iter->second->getName().cstr(), "Standard") == 0)
[ # # ][ # # ]
187 : 0 : continue;
188 [ # # ]: 0 : (iter->second)->write(pHandler);
189 : : }
190 : 0 : }
191 : :
192 : 0 : WPXString ParagraphStyleManager::getKey(const WPXPropertyList &xPropList, const WPXPropertyListVector &tabStops) const
193 : : {
194 [ # # ]: 0 : WPXString sKey = propListToStyleKey(xPropList);
195 : :
196 [ # # ]: 0 : WPXString sTabStops;
197 [ # # ][ # # ]: 0 : sTabStops.sprintf("[num-tab-stops:%i]", tabStops.count());
198 [ # # ]: 0 : WPXPropertyListVector::Iter i(tabStops);
199 [ # # ][ # # ]: 0 : for (i.rewind(); i.next();)
[ # # ]
200 : : {
201 [ # # ][ # # ]: 0 : sTabStops.append(propListToStyleKey(i()));
[ # # ][ # # ]
202 : : }
203 [ # # ]: 0 : sKey.append(sTabStops);
204 : :
205 [ # # ][ # # ]: 0 : return sKey;
206 : : }
207 : :
208 : 0 : WPXString ParagraphStyleManager::findOrAdd(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops)
209 : : {
210 [ # # ]: 0 : WPXString hashKey = getKey(propList, tabStops);
211 : : std::map<WPXString, WPXString, ltstr>::const_iterator iter =
212 [ # # ]: 0 : mNameHash.find(hashKey);
213 [ # # ][ # # ]: 0 : if (iter!=mNameHash.end()) return iter->second;
214 : :
215 : : // ok create a new list
216 : : WRITER_DEBUG_MSG(("ParagraphStyleManager::findOrAdd: Paragraph Hash Key: %s\n", hashKey.cstr()));
217 : :
218 [ # # ]: 0 : WPXString sName;
219 [ # # ]: 0 : sName.sprintf("S%i", mStyleHash.size());
220 [ # # ][ # # ]: 0 : shared_ptr<ParagraphStyle> parag(new ParagraphStyle(propList, tabStops, sName));
[ # # ]
221 [ # # ][ # # ]: 0 : mStyleHash[sName] =parag;
222 [ # # ][ # # ]: 0 : mNameHash[hashKey] = sName;
223 [ # # ][ # # ]: 0 : return sName;
[ # # ][ # # ]
224 : : }
225 : :
226 : 0 : shared_ptr<ParagraphStyle> const ParagraphStyleManager::get(const WPXString &name) const
227 : : {
228 : : std::map<WPXString, shared_ptr<ParagraphStyle>, ltstr>::const_iterator iter
229 [ # # ]: 0 : = mStyleHash.find(name);
230 [ # # ][ # # ]: 0 : if (iter == mStyleHash.end()) return shared_ptr<ParagraphStyle>();
231 [ # # ]: 0 : return iter->second;
232 : : }
233 : :
234 : 0 : void SpanStyleManager::clean()
235 : : {
236 : 0 : mNameHash.clear();
237 : 0 : mStyleHash.clear();
238 : 0 : }
239 : :
240 : 0 : void SpanStyleManager::write(OdfDocumentHandler *pHandler) const
241 : : {
242 [ # # ]: 0 : for (std::map<WPXString, shared_ptr<SpanStyle>, ltstr>::const_iterator iter = mStyleHash.begin();
243 : 0 : iter != mStyleHash.end(); ++iter)
244 : : {
245 [ # # ]: 0 : (iter->second)->write(pHandler);
246 : : }
247 : 0 : }
248 : :
249 : 0 : WPXString SpanStyleManager::findOrAdd(const WPXPropertyList &propList)
250 : : {
251 [ # # ]: 0 : WPXString hashKey = propListToStyleKey(propList);
252 : : std::map<WPXString, WPXString, ltstr>::const_iterator iter =
253 [ # # ]: 0 : mNameHash.find(hashKey);
254 [ # # ][ # # ]: 0 : if (iter!=mNameHash.end()) return iter->second;
255 : :
256 : : // ok create a new list
257 : : WRITER_DEBUG_MSG(("SpanStyleManager::findOrAdd: Span Hash Key: %s\n", hashKey.cstr()));
258 : :
259 [ # # ]: 0 : WPXString sName;
260 [ # # ]: 0 : sName.sprintf("Span%i", mStyleHash.size());
261 [ # # ][ # # ]: 0 : shared_ptr<SpanStyle> span(new SpanStyle(sName.cstr(), propList));
[ # # ][ # # ]
262 [ # # ][ # # ]: 0 : mStyleHash[sName] = span;
263 [ # # ][ # # ]: 0 : mNameHash[hashKey] = sName;
264 [ # # ][ # # ]: 0 : return sName;
[ # # ][ # # ]
265 : : }
266 : :
267 : 0 : shared_ptr<SpanStyle> const SpanStyleManager::get(const WPXString &name) const
268 : : {
269 : : std::map<WPXString, shared_ptr<SpanStyle>, ltstr>::const_iterator iter
270 [ # # ]: 0 : = mStyleHash.find(name);
271 [ # # ][ # # ]: 0 : if (iter == mStyleHash.end()) return shared_ptr<SpanStyle>();
272 [ # # ]: 0 : return iter->second;
273 : : }
274 : :
275 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|