merge the formfield patch from ooo-build
[ooovba.git] / writerperfect / source / filter / TextRunStyle.cxx
blobc28998a40e2a893059ae3bb0b05938785a7e05cc
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.
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)
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.
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.
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
23 * For further information visit http://libwpd.sourceforge.net
27 /* "This product is not manufactured, approved, or supported by
28 * Corel Corporation or Corel Corporation Limited."
30 #include "FilterInternal.hxx"
31 #include "TextRunStyle.hxx"
32 #include "WriterProperties.hxx"
33 #include "DocumentElement.hxx"
35 #ifdef _MSC_VER
36 #include <minmax.h>
37 #endif
39 #include <string.h>
41 ParagraphStyle::ParagraphStyle(WPXPropertyList *pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
42 mpPropList(pPropList),
43 mxTabStops(xTabStops),
44 msName(sName)
48 ParagraphStyle::~ParagraphStyle()
50 delete mpPropList;
53 void ParagraphStyle::write(DocumentHandler *pHandler) const
55 WRITER_DEBUG_MSG(("Writing a paragraph style..\n"));
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);
65 propList.clear();
66 WPXPropertyList::Iter k((*mpPropList));
67 for (k.rewind(); k.next(); )
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)
81 if (k()->getFloat() > 0.0f)
82 propList.insert("fo:margin-bottom", k()->getStr());
83 else
84 propList.insert("fo:margin-bottom", 0.0f);
86 if (strcmp(k.key(), "fo:line-height") == 0)
87 propList.insert("fo:line-height", k()->getStr());
88 if (strcmp(k.key(), "fo:break-before") == 0)
89 propList.insert("fo:break-before", k()->getStr());
90 if (strcmp(k.key(), "fo:text-align") == 0)
91 propList.insert("fo:text-align", k()->getStr());
92 if (strcmp(k.key(), "fo:text-align-last") == 0)
93 propList.insert("fo:text-align-last", k()->getStr());
96 propList.insert("style:justify-single-word", "false");
97 pHandler->startElement("style:properties", propList);
99 if (mxTabStops.count() > 0)
101 TagOpenElement tabListOpen("style:tab-stops");
102 tabListOpen.write(pHandler);
103 WPXPropertyListVector::Iter i(mxTabStops);
104 for (i.rewind(); i.next();)
106 TagOpenElement tabStopOpen("style:tab-stop");
108 WPXPropertyList::Iter j(i());
109 for (j.rewind(); j.next(); )
111 tabStopOpen.addAttribute(j.key(), j()->getStr().cstr());
113 tabStopOpen.write(pHandler);
114 pHandler->endElement("style:tab-stop");
116 pHandler->endElement("style:tab-stops");
119 pHandler->endElement("style:properties");
120 pHandler->endElement("style:style");
123 SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) :
124 Style(psName),
125 mPropList(xPropList)
129 void SpanStyle::write(DocumentHandler *pHandler) const
131 WRITER_DEBUG_MSG(("Writing a span style..\n"));
132 WPXPropertyList styleOpenList;
133 styleOpenList.insert("style:name", getName());
134 styleOpenList.insert("style:family", "text");
135 pHandler->startElement("style:style", styleOpenList);
137 WPXPropertyList propList(mPropList);
139 if (mPropList["style:font-name"])
141 propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr());
142 propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr());
145 if (mPropList["fo:font-size"])
147 propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr());
148 propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr());
151 if (mPropList["fo:font-weight"])
153 propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr());
154 propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr());
157 if (mPropList["fo:font-style"])
159 propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr());
160 propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr());
163 pHandler->startElement("style:properties", propList);
165 pHandler->endElement("style:properties");
166 pHandler->endElement("style:style");