Subversion Repositories Scribus

Rev

Rev 8382 | Rev 8807 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8337 avox 1
/*
2
 For general Scribus (>=1.3.2) copyright and licensing information please refer
3
 to the COPYING file provided with the program. Following this notice may exist
4
 a copyright and/or license notice that predates the release of Scribus 1.3.2
5
 for which a new license (GPL+exception) is in place.
6
 */
7
 
8
 
9
#include <qvaluelist.h>
10
#include <qobject.h>
11
#include "sctextstruct.h"
12
#include "scfonts.h"
8382 avox 13
#include "styles/style.h"
8337 avox 14
#include "linestyle.h"
15
#include "desaxe/saxiohelper.h"
16
#include "desaxe/simple_actions.h"
17
#include "prefsmanager.h"
18
 
19
 
20
void LineStyle::applyLineStyle(const LineStyle & other)
21
{
22
        Style::applyStyle(other);
23
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
24
        if (! other.inh_##attr_NAME) \
25
                set##attr_NAME(other.m_##attr_NAME);
26
#include "linestyle.attrdefs.cxx"
27
#undef ATTRDEF
28
}
29
 
30
 
31
void LineStyle::eraseLineStyle(const LineStyle & other)
32
{
33
        other.validate();
34
        Style::eraseStyle(other);
35
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
36
        if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
37
                reset##attr_NAME();
38
#include "linestyle.attrdefs.cxx"
39
#undef ATTRDEF
40
}
41
 
42
bool LineStyle::equiv(const Style & other) const
43
{
44
        other.validate();
45
        const LineStyle * oth = dynamic_cast<const LineStyle*> ( & other );
46
        return  oth &&
47
                parent() == oth->parent()
48
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
49
                && (inh_##attr_NAME == oth->inh_##attr_NAME) \
50
                && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
51
#include "linestyle.attrdefs.cxx"
52
#undef ATTRDEF
53
                ;      
54
}
55
 
56
 
57
QString LineStyle::displayName() const
58
{
59
        if ( hasName() || !hasParent() || ! m_context)
60
                return name();
61
//      else if ( inheritsAll() )
62
//              return parent()->displayName();
63
        else
64
                return parentStyle()->displayName() + "+";
65
}
66
 
67
 
68
 
69
QString LineStyle::asString() const
70
{
71
        QString result;
72
/*      if ( !inh_Font )
73
                result += QObject::tr("font %1 ").arg(font().scName());
74
        if ( !inh_FontSize )
75
                result += QObject::tr("size %1 ").arg(fontSize());
76
        if ( !inh_Effects )
77
                result += QObject::tr("+style ");
78
        if ( !inh_StrokeColor  ||  !inh_StrokeShade  ||  !inh_FillColor || !inh_FillShade )
79
                result += QObject::tr("+color ");
80
        if ( !inh_UnderlineWidth  ||  !inh_UnderlineOffset )
81
                result += underlineWidth() > 0 ? QObject::tr("+underline ") : QObject::tr("-underline ");
82
        if ( !inh_StrikethruWidth || !inh_StrikethruOffset )
83
                result += strikethruWidth() > 0 ? QObject::tr("+strikeout ") : QObject::tr("-strikeout ");
84
        if ( !inh_ShadowXOffset || !inh_ShadowYOffset )
85
                result += shadowXOffset() != 0 || shadowYOffset() != 0 ? QObject::tr("+shadow ") : QObject::tr("-shadow ");
86
        if ( !inh_OutlineWidth )
87
                result += outlineWidth() > 0 ? QObject::tr("+outline ") : QObject::tr("-outline ");
88
        if ( !inh_Tracking )
89
                result += tracking() > 0 ? QObject::tr("+tracking %1 ").arg(tracking()) : QObject::tr("-tracking ");
90
        if ( !inh_BaselineOffset )
91
                result += QObject::tr("+baseline %1 ").arg(baselineOffset());
92
        if ( !inh_ScaleH || !inh_ScaleV )
93
                result += QObject::tr("+stretch ");
94
        if ( hasParent() )
95
                result += QObject::tr("parent= %1").arg(parent());
96
*/      return result.stripWhiteSpace();
97
}
98
 
99
 
100
void LineStyle::update(const StyleContext* context)
101
{
102
        Style::update(context);
103
        const LineStyle * oth = dynamic_cast<const LineStyle*> ( parentStyle() );
104
        if (oth) {
105
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
106
                if (inh_##attr_NAME) \
107
                        m_##attr_NAME = oth->attr_GETTER();
108
#include "linestyle.attrdefs.cxx"
109
#undef ATTRDEF
110
        }
111
}
112
 
113
 
114
void LineStyle::setStyle(const LineStyle& other)
115
{
116
        other.validate();
117
        setParent(other.parent());
118
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
119
        inh_##attr_NAME = other.inh_##attr_NAME; \
120
        m_##attr_NAME = other.m_##attr_NAME;
121
#include "linestyle.attrdefs.cxx"
122
#undef ATTRDEF
123
}
124
 
125
 
126
 
127
/*
128
bool LineStyle::definesAll() const
129
{
130
        return definesLineSpacing() &&
131
        definesLeftMargin() &&
132
        definesRightMargin() &&
133
        definesFirstIndent() &&
134
        definesAlignment() &&
135
        definesGapBefore()  &&
136
        definesLineSpacingMode()  &&
137
        definesGapAfter()  &&
138
        definesHasDropCap() &&
139
        definesDropCapOffset() &&
140
        definesDropCapLines() &&
141
        definesUseBaselineGrid() &&
142
        lineStyle().definesAll() ;
143
 
144
}
145
 
146
// equiv. to "*this == LineStyle()"
147
bool LineStyle::inheritsAll() const
148
{
149
        return inheritsLineSpacing() &&
150
        inheritsLeftMargin() &&
151
        inheritsRightMargin() &&
152
        inheritsFirstIndent() &&
153
        inheritsAlignment() &&
154
        inheritsGapBefore()  &&
155
        inheritsLineSpacingMode()  &&
156
        inheritsGapAfter()  &&
157
        inheritsHasDropCap() &&
158
        inheritsDropCapOffset() &&
159
        inheritsDropCapLines() &&
160
        inheritsUseBaselineGrid() &&
161
        lineStyle().inheritsAll() ;
162
}
163
*/
164
 
165
typedef QValueList<LineStyle> Sublist;
166
 
167
static QString toXMLString(const Sublist & )
168
{
169
        return "dummy";
170
}
171
 
172
 
8349 jghali 173
void LineStyle::saxx(SaxHandler& handler, const Xml_string elemtag) const
8337 avox 174
{
175
        Xml_attr att;
176
        Style::saxxAttributes(att);
177
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
8348 avox 178
        if (!inh_##attr_NAME && strcmp(# attr_NAME, "Sublines") != 0 ) \
8337 avox 179
                att.insert(# attr_NAME, toXMLString(m_##attr_NAME));
180
#include "linestyle.attrdefs.cxx"
181
#undef ATTRDEF
8382 avox 182
        if (!name().isEmpty())
8390 avox 183
                att["id"] = mkXMLName(elemtag + name());
8337 avox 184
        handler.begin(elemtag, att);
8382 avox 185
        if (parentStyle())
186
                parentStyle()->saxx(handler);  
8337 avox 187
        Sublist::const_iterator it;
188
        for (it=m_Sublines.begin(); it != m_Sublines.end(); ++it)
189
        {
190
                (*it).saxx(handler, "subline");
191
        }
192
        handler.end(elemtag);
193
}
194
 
195
 
196
 
197
 
198
template<>
199
Sublist parse<Sublist>(Xml_string str)
200
{
201
        return Sublist();
202
}
203
 
204
template<>
205
Qt::PenStyle parse<Qt::PenStyle>(Xml_string str)
206
{
207
        return parseEnum<Qt::PenStyle>(str);
208
}
209
 
210
template<>
211
Qt::PenCapStyle parse<Qt::PenCapStyle>(Xml_string str)
212
{
213
        return parseEnum<Qt::PenCapStyle>(str);
214
}
215
 
216
template<>
217
Qt::PenJoinStyle parse<Qt::PenJoinStyle>(Xml_string str)
218
{
219
        return parseEnum<Qt::PenJoinStyle>(str);
220
}
221
 
222
 
223
 
224
using namespace desaxe;
225
 
226
 
227
const Xml_string LineStyle::saxxDefaultElem("linestyle");
228
 
229
void LineStyle::desaxeRules(Xml_string prefixPattern, Digester& ruleset, Xml_string elemtag)
230
{
231
        Xml_string stylePrefix(Digester::concat(prefixPattern, elemtag));
232
        ruleset.addRule(stylePrefix, Factory<LineStyle>());
8382 avox 233
        ruleset.addRule(stylePrefix, IdRef<LineStyle>());
234
        Style::desaxeRules<LineStyle>(prefixPattern, ruleset, elemtag);
235
 
236
//  "**" doesnt work yet - av
237
//      Xml_string stylePrefixRec(Digester::concat(stylePrefix, "**"));
238
        const Xml_string& stylePrefixRec(stylePrefix);
239
        Xml_string subPrefix(Digester::concat(stylePrefixRec, "subline"));
8337 avox 240
        ruleset.addRule(subPrefix, Factory<LineStyle>());
8382 avox 241
        Style::desaxeRules<LineStyle>(stylePrefixRec, ruleset, "subline");
8337 avox 242
 
243
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
8348 avox 244
        if ( strcmp(# attr_NAME, "Sublines") != 0 ) { \
8337 avox 245
                ruleset.addRule(stylePrefix, SetAttributeWithConversion<LineStyle, attr_TYPE> ( & LineStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> )); \
246
                ruleset.addRule(subPrefix, SetAttributeWithConversion<LineStyle, attr_TYPE> ( & LineStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> )); \
247
        }
248
#include "linestyle.attrdefs.cxx"
249
#undef ATTRDEF
250
        ruleset.addRule(subPrefix, SetterWithConversion<LineStyle, const LineStyle&, LineStyle>( & LineStyle::appendSubline ));
251
}