TextRunStyle.cpp
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., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 *
24 * For further information visit http://libwpd.sourceforge.net
25 *
26 */
27
28/* "This product is not manufactured, approved, or supported by
29 * Corel Corporation or Corel Corporation Limited."
30 */
31#include "FilterInternal.h"
32#include "TextRunStyle.h"
33#include "WriterProperties.h"
34#include "DocumentElement.h"
35
36#include <cstring>
37
38#ifdef _MSC_VER
39#include <minmax.h>
40#endif
41
42ParagraphStyle::ParagraphStyle(_SH_PropertyList *pPropList, const _SH_PropertyListVector &xTabStops, const _SH_String &sName) :
43 mpPropList(pPropList),
44 mxTabStops(xTabStops),
45 msName(sName)
46{
47}
48
49ParagraphStyle::~ParagraphStyle()
50{
51 delete mpPropList;
52}
53
54void ParagraphStyle::write(DocumentHandler &xHandler) const
55{
56 WRITER_DEBUG_MSG(("Writing a paragraph style..\n"));
57
58 _SH_PropertyList propList;
59 propList.insert("style:name", msName.cstr());
60 propList.insert("style:family", "paragraph");
61 propList.insert("style:parent-style-name", (*mpPropList)["style:parent-style-name"]->getStr());
62 if ((*mpPropList)["style:master-page-name"])
63 propList.insert("style:master-page-name", (*mpPropList)["style:master-page-name"]->getStr());
64 xHandler.startElement("style:style", propList);
65
66 propList.clear();
67 _SH_PropertyList::Iter i((*mpPropList));
68 for (i.rewind(); i.next(); )
69 {
70 if (strcmp(i.key(), "style:list-style-name") == 0)
71 propList.insert("style:list-style-name", i()->getStr());
72 if (strcmp(i.key(), "fo:margin-left") == 0)
73 propList.insert("fo:margin-left", i()->getStr());
74 if (strcmp(i.key(), "fo:margin-right") == 0)
75 propList.insert("fo:margin-right", i()->getStr());
76 if (strcmp(i.key(), "fo:text-indent") == 0)
77 propList.insert("fo:text-indent", i()->getStr());
78 if (strcmp(i.key(), "fo:margin-top") == 0)
79 propList.insert("fo:margin-top", i()->getStr());
80 if (strcmp(i.key(), "fo:margin-bottom") == 0)
81 propList.insert("fo:margin-bottom", i()->getStr());
82 if (strcmp(i.key(), "fo:line-height") == 0)
83 propList.insert("fo:line-height", i()->getStr());
84 if (strcmp(i.key(), "fo:break-before") == 0)
85 propList.insert("fo:break-before", i()->getStr());
86 if (strcmp(i.key(), "fo:text-align") == 0)
87 propList.insert("fo:text-align", i()->getStr());
88 if (strcmp(i.key(), "fo:text-align-last") == 0)
89 propList.insert("fo:text-align-last", i()->getStr());
90 }
91
92 propList.insert("style:justify-single-word", "false");
93 xHandler.startElement("style:properties", propList);
94
95 if (mxTabStops.count() > 0)
96 {
97 TagOpenElement tabListOpen("style:tab-stops");
98 tabListOpen.write(xHandler);
99 _SH_PropertyListVector::Iter i(mxTabStops);
100 for (i.rewind(); i.next();)
101 {
102 TagOpenElement tabStopOpen("style:tab-stop");
103
104 _SH_PropertyList::Iter j(i());
105 for (j.rewind(); j.next(); )
106 {
107 tabStopOpen.addAttribute(j.key(), j()->getStr().cstr());
108 }
109 tabStopOpen.write(xHandler);
110 xHandler.endElement("style:tab-stop");
111 }
112 xHandler.endElement("style:tab-stops");
113 }
114
115 xHandler.endElement("style:properties");
116 xHandler.endElement("style:style");
117}
118
119SpanStyle::SpanStyle(const char *psName, const _SH_PropertyList &xPropList) :
120 Style(psName),
121 mPropList(xPropList)
122{
123}
124
125void SpanStyle::write(DocumentHandler &xHandler) const
126{
127 WRITER_DEBUG_MSG(("Writing a span style..\n"));
128 _SH_PropertyList styleOpenList;
129 styleOpenList.insert("style:name", getName());
130 styleOpenList.insert("style:family", "text");
131 xHandler.startElement("style:style", styleOpenList);
132
133 _SH_PropertyList propList(mPropList);
134
135 if (mPropList["style:font-name"])
136 {
137 propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr());
138 propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr());
139 }
140
141 if (mPropList["fo:font-size"])
142 {
143 propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr());
144 propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr());
145 }
146
147 if (mPropList["fo:font-weight"])
148 {
149 propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr());
150 propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr());
151 }
152
153 if (mPropList["fo:font-style"])
154 {
155 propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr());
156 propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr());
157 }
158
159 xHandler.startElement("style:properties", propList);
160
161 xHandler.endElement("style:properties");
162 xHandler.endElement("style:style");
163}