summaryrefslogtreecommitdiff
path: root/writerperfect/source/filter/TextRunStyle.cxx
blob: c4fdd3c6996c0207f617ec492b941b6f6f88c2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* TextRunStyle: Stores (and writes) paragraph/span-style-based information
 * (e.g.: a paragraph might be bold) that is needed at the head of an OO
 * document.
 *
 * Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com)
 * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com)
 * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * For further information visit http://libwpd.sourceforge.net
 *
 */

/* "This product is not manufactured, approved, or supported by
 * Corel Corporation or Corel Corporation Limited."
 */
#include "FilterInternal.hxx"
#include "TextRunStyle.hxx"
#include "WriterProperties.hxx"
#include "DocumentElement.hxx"

#ifdef _MSC_VER
#include <minmax.h>
#endif

#include <string.h>

ParagraphStyle::ParagraphStyle(WPXPropertyList *pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
    mpPropList(pPropList),
    mxTabStops(xTabStops),
    msName(sName)
{
}

ParagraphStyle::~ParagraphStyle()
{
    delete mpPropList;
}

void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
{
    WRITER_DEBUG_MSG(("Writing a paragraph style..\n"));

    WPXPropertyList propList;
    propList.insert("style:name", msName.cstr());
    propList.insert("style:family", "paragraph");
   if ((*mpPropList)["style:parent-style-name"])
      propList.insert("style:parent-style-name", (*mpPropList)["style:parent-style-name"]->getStr());
    if ((*mpPropList)["style:master-page-name"])
        propList.insert("style:master-page-name", (*mpPropList)["style:master-page-name"]->getStr());
    pHandler->startElement("style:style", propList);

    propList.clear();
    WPXPropertyList::Iter i((*mpPropList));
    for (i.rewind(); i.next(); )
    {
#if 0
        if (strcmp(i.key(), "style:list-style-name") == 0)
            propList.insert("style:list-style-name", i()->getStr());
#endif
        if (strcmp(i.key(), "fo:margin-left") == 0)
            propList.insert("fo:margin-left", i()->getStr());
        if (strcmp(i.key(), "fo:margin-right") == 0)
            propList.insert("fo:margin-right", i()->getStr());
        if (strcmp(i.key(), "fo:text-indent") == 0)
            propList.insert("fo:text-indent", i()->getStr());
        if (strcmp(i.key(), "fo:margin-top") == 0)
            propList.insert("fo:margin-top", i()->getStr());
        if (strcmp(i.key(), "fo:margin-bottom") == 0)
        {
            if (i()->getDouble() > 0.0)
                propList.insert("fo:margin-bottom", i()->getStr());
            else
                propList.insert("fo:margin-bottom", 0.0);
        }
        if (strcmp(i.key(), "fo:line-height") == 0)
            propList.insert("fo:line-height", i()->getStr());
        if (strcmp(i.key(), "fo:break-before") == 0)
            propList.insert("fo:break-before", i()->getStr());
        if (strcmp(i.key(), "fo:text-align") == 0)
            propList.insert("fo:text-align", i()->getStr());
        if (strcmp(i.key(), "fo:text-align-last") == 0)
            propList.insert("fo:text-align-last", i()->getStr());
        if (strcmp(i.key(), "style:page-number") == 0)
            propList.insert("style:page-number", i()->getStr());

    }

    propList.insert("style:justify-single-word", "false");
    pHandler->startElement("style:paragraph-properties", propList);

    if (mxTabStops.count() > 0)
    {
        TagOpenElement tabListOpen("style:tab-stops");
        tabListOpen.write(pHandler);
        WPXPropertyListVector::Iter k(mxTabStops);
        for (k.rewind(); k.next();)
        {
            if (k()["style:position"] && k()["style:position"]->getDouble() < 0.0)
                continue;
            TagOpenElement tabStopOpen("style:tab-stop");

            WPXPropertyList::Iter j(k());
            for (j.rewind(); j.next(); )
            {
                tabStopOpen.addAttribute(j.key(), j()->getStr().cstr());
            }
            tabStopOpen.write(pHandler);
            pHandler->endElement("style:tab-stop");
        }
        pHandler->endElement("style:tab-stops");
    }

    pHandler->endElement("style:paragraph-properties");
    pHandler->endElement("style:style");
}

SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) :
    Style(psName),
    mPropList(xPropList)
{
}

void SpanStyle::write(OdfDocumentHandler *pHandler) const
{
    WRITER_DEBUG_MSG(("Writing a span style..\n"));
    WPXPropertyList styleOpenList;
    styleOpenList.insert("style:name", getName());
    styleOpenList.insert("style:family", "text");
    pHandler->startElement("style:style", styleOpenList);

    WPXPropertyList propList(mPropList);

    if (mPropList["style:font-name"])
    {
        propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr());
        propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr());
    }

    if (mPropList["fo:font-size"])
    {
        if (mPropList["fo:font-size"]->getDouble() > 0.0)
        {
            propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr());
            propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr());
        }
        else
            propList.remove("fo:font-size");
    }

    if (mPropList["fo:font-weight"])
    {
        propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr());
        propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr());
    }

    if (mPropList["fo:font-style"])
    {
        propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr());
        propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr());
    }

    pHandler->startElement("style:text-properties", propList);

    pHandler->endElement("style:text-properties");
    pHandler->endElement("style:style");
}

WPXString propListToStyleKey(const WPXPropertyList & xPropList)
{
   WPXString sKey;
   WPXPropertyList::Iter i(xPropList);
   for (i.rewind(); i.next(); )
   {
      WPXString sProp;
      sProp.sprintf("[%s:%s]", i.key(), i()->getStr().cstr());
      sKey.append(sProp);
   }

   return sKey;
}