1 /* TextRunStyle: Stores (and writes) paragraph/span-style-based information
2 * (e.g.: a paragraph might be bold) that is needed at the head of an OO
3 * document.
4 *
5 * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca)
6 * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com)
7 * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * For further information visit http://libwpd.sourceforge.net
24 *
25 */
26
27 /* "This product is not manufactured, approved, or supported by
28 * Corel Corporation or Corel Corporation Limited."
29 */
30 #include "FilterInternal.hxx"
31 #include "TextRunStyle.hxx"
32 #include "WriterProperties.hxx"
33 #include "DocumentElement.hxx"
34
35 #ifdef _MSC_VER
36 #include <minmax.h>
37 #endif
38
39 #include <string.h>
40
ParagraphStyle(WPXPropertyList * pPropList,const WPXPropertyListVector & xTabStops,const WPXString & sName)41 ParagraphStyle::ParagraphStyle(WPXPropertyList *pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
42 mpPropList(pPropList),
43 mxTabStops(xTabStops),
44 msName(sName)
45 {
46 }
47
~ParagraphStyle()48 ParagraphStyle::~ParagraphStyle()
49 {
50 delete mpPropList;
51 }
52
write(DocumentHandler * pHandler) const53 void ParagraphStyle::write(DocumentHandler *pHandler) const
54 {
55 WRITER_DEBUG_MSG(("Writing a paragraph style..\n"));
56
57 WPXPropertyList propList;
58 propList.insert("style:name", msName.cstr());
59 propList.insert("style:family", "paragraph");
60 propList.insert("style:parent-style-name", (*mpPropList)["style:parent-style-name"]->getStr());
61 if ((*mpPropList)["style:master-page-name"])
62 propList.insert("style:master-page-name", (*mpPropList)["style:master-page-name"]->getStr());
63 pHandler->startElement("style:style", propList);
64
65 propList.clear();
66 WPXPropertyList::Iter k((*mpPropList));
67 for (k.rewind(); k.next(); )
68 {
69 if (strcmp(k.key(), "style:list-style-name") == 0)
70 propList.insert("style:list-style-name", k()->getStr());
71 if (strcmp(k.key(), "fo:margin-left") == 0)
72 propList.insert("fo:margin-left", k()->getStr());
73 if (strcmp(k.key(), "fo:margin-right") == 0)
74 propList.insert("fo:margin-right", k()->getStr());
75 if (strcmp(k.key(), "fo:text-indent") == 0)
76 propList.insert("fo:text-indent", k()->getStr());
77 if (strcmp(k.key(), "fo:margin-top") == 0)
78 propList.insert("fo:margin-top", k()->getStr());
79 if (strcmp(k.key(), "fo:margin-bottom") == 0)
80 propList.insert("fo:margin-bottom", k()->getStr());
81 if (strcmp(k.key(), "fo:line-height") == 0)
82 propList.insert("fo:line-height", k()->getStr());
83 if (strcmp(k.key(), "fo:break-before") == 0)
84 propList.insert("fo:break-before", k()->getStr());
85 if (strcmp(k.key(), "fo:text-align") == 0)
86 propList.insert("fo:text-align", k()->getStr());
87 if (strcmp(k.key(), "fo:text-align-last") == 0)
88 propList.insert("fo:text-align-last", k()->getStr());
89 }
90
91 propList.insert("style:justify-single-word", "false");
92 pHandler->startElement("style:properties", propList);
93
94 if (mxTabStops.count() > 0)
95 {
96 TagOpenElement tabListOpen("style:tab-stops");
97 tabListOpen.write(pHandler);
98 WPXPropertyListVector::Iter i(mxTabStops);
99 for (i.rewind(); i.next();)
100 {
101 TagOpenElement tabStopOpen("style:tab-stop");
102
103 WPXPropertyList::Iter j(i());
104 for (j.rewind(); j.next(); )
105 {
106 tabStopOpen.addAttribute(j.key(), j()->getStr().cstr());
107 }
108 tabStopOpen.write(pHandler);
109 pHandler->endElement("style:tab-stop");
110 }
111 pHandler->endElement("style:tab-stops");
112 }
113
114 pHandler->endElement("style:properties");
115 pHandler->endElement("style:style");
116 }
117
SpanStyle(const char * psName,const WPXPropertyList & xPropList)118 SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) :
119 Style(psName),
120 mPropList(xPropList)
121 {
122 }
123
write(DocumentHandler * pHandler) const124 void SpanStyle::write(DocumentHandler *pHandler) const
125 {
126 WRITER_DEBUG_MSG(("Writing a span style..\n"));
127 WPXPropertyList styleOpenList;
128 styleOpenList.insert("style:name", getName());
129 styleOpenList.insert("style:family", "text");
130 pHandler->startElement("style:style", styleOpenList);
131
132 WPXPropertyList propList(mPropList);
133
134 if (mPropList["style:font-name"])
135 {
136 propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr());
137 propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr());
138 }
139
140 if (mPropList["fo:font-size"])
141 {
142 propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr());
143 propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr());
144 }
145
146 if (mPropList["fo:font-weight"])
147 {
148 propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr());
149 propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr());
150 }
151
152 if (mPropList["fo:font-style"])
153 {
154 propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr());
155 propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr());
156 }
157
158 pHandler->startElement("style:properties", propList);
159
160 pHandler->endElement("style:properties");
161 pHandler->endElement("style:style");
162 }
163