Subversion Repositories Scribus

Rev

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