Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
6443 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"
6733 avox 13
#include "style.h"
6443 avox 14
 
15
 
16
StyleFlag& operator&= (StyleFlag& left, StyleFlag right){        
17
        int result = static_cast<int>(left) & static_cast<int>(right);        
18
        left = static_cast<StyleFlag>(result);
19
        return left;
20
}
21
 
22
StyleFlag& operator|= (StyleFlag& left, StyleFlag right)
23
{
24
        int result = static_cast<int>(left) | static_cast<int>(right);
25
        left = static_cast<StyleFlag>(result);
26
        return left;
27
}
28
 
29
StyleFlag operator& (StyleFlag left, StyleFlag right)
30
{
31
        int result = static_cast<int>(left) & static_cast<int>(right);        
32
        return static_cast<StyleFlag>(result);
33
}
34
 
35
StyleFlag operator| (StyleFlag left, StyleFlag right)
36
{        
37
        int result = static_cast<int>(left) | static_cast<int>(right);
38
        return static_cast<StyleFlag>(result);
39
}
40
 
41
StyleFlag operator^ (StyleFlag left, StyleFlag right){
42
        int result = static_cast<int>(left) ^ static_cast<int>(right);
43
        return static_cast<StyleFlag>(result);
44
}
45
 
46
StyleFlag operator~ (StyleFlag arg)
47
{
48
        int result = ~ static_cast<int>(arg);
49
        return static_cast<StyleFlag>(result);
50
}
51
 
7017 avox 52
bool operator== (StyleFlag left, StyleFlag right)
53
{        
54
        int result = static_cast<int>( (left ^ right) & ScStyle_UserStyles);
55
        return result == 0;
56
}
6443 avox 57
 
7017 avox 58
bool operator!= (StyleFlag left, StyleFlag right)
59
{
60
        return !(left==right);
61
}
62
 
6443 avox 63
void CharStyle::applyCharStyle(const CharStyle & other)
64
{
6805 avox 65
        other.validate();
6443 avox 66
        Style::applyStyle(other);
67
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
68
        if (! other.inh_##attr_NAME) \
69
                set##attr_NAME(other.m_##attr_NAME);
70
#include "charstyle.attrdefs.cxx"
71
#undef ATTRDEF
72
}
73
 
74
 
75
void CharStyle::eraseCharStyle(const CharStyle & other)
76
{
6805 avox 77
        other.validate();
6443 avox 78
        Style::eraseStyle(other);
79
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6936 avox 80
        if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
6443 avox 81
                reset##attr_NAME();
82
#include "charstyle.attrdefs.cxx"
83
#undef ATTRDEF
84
}
85
 
86
bool CharStyle::equiv(const Style & other) const
87
{
6805 avox 88
        other.validate();
6443 avox 89
        const CharStyle * oth = dynamic_cast<const CharStyle*> ( & other );
90
        return  oth &&
6733 avox 91
                parent() == oth->parent()
6443 avox 92
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 93
                && (inh_##attr_NAME == oth->inh_##attr_NAME) \
94
                && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
6443 avox 95
#include "charstyle.attrdefs.cxx"
96
#undef ATTRDEF
97
                ;      
98
}
99
 
100
 
101
QString CharStyle::displayName() const
102
{
103
        if ( hasName() || !hasParent() || ! m_base)
104
                return name();
105
//      else if ( inheritsAll() )
106
//              return parent()->displayName();
107
        else
108
                return parentStyle()->displayName() + "+";
109
}
110
 
111
 
112
 
113
QString CharStyle::asString() const
114
{
115
        QString result;
116
        if ( !inh_Font )
117
                result += QObject::tr("font %1 ").arg(font().scName());
118
        if ( !inh_FontSize )
119
                result += QObject::tr("size %1 ").arg(fontSize());
120
        if ( !inh_Effects )
121
                result += QObject::tr("+style ");
122
        if ( !inh_StrokeColor  ||  !inh_StrokeShade  ||  !inh_FillColor || !inh_FillShade )
123
                result += QObject::tr("+color ");
124
        if ( !inh_UnderlineWidth  ||  !inh_UnderlineOffset )
125
                result += underlineWidth() > 0 ? QObject::tr("+underline ") : QObject::tr("-underline ");
6733 avox 126
        if ( !inh_StrikethruWidth || !inh_StrikethruOffset )
6443 avox 127
                result += strikethruWidth() > 0 ? QObject::tr("+strikeout ") : QObject::tr("-strikeout ");
128
        if ( !inh_ShadowXOffset || !inh_ShadowYOffset )
6733 avox 129
                result += shadowXOffset() != 0 || shadowYOffset() != 0 ? QObject::tr("+shadow ") : QObject::tr("-shadow ");
6443 avox 130
        if ( !inh_OutlineWidth )
131
                result += outlineWidth() > 0 ? QObject::tr("+outline ") : QObject::tr("-outline ");
132
        if ( !inh_Tracking )
133
                result += tracking() > 0 ? QObject::tr("+tracking %1 ").arg(tracking()) : QObject::tr("-tracking ");
134
        if ( !inh_BaselineOffset )
135
                result += QObject::tr("+baseline %1 ").arg(baselineOffset());
136
        if ( !inh_ScaleH || !inh_ScaleV )
137
                result += QObject::tr("+stretch ");
138
        if ( hasParent() )
139
                result += QObject::tr("parent= %1").arg(parent());
140
        return result.stripWhiteSpace();
141
}
142
 
143
 
6805 avox 144
void CharStyle::update(const StyleBase* base)
6443 avox 145
{
146
        Style::update(base);
147
        const CharStyle * oth = dynamic_cast<const CharStyle*> ( parentStyle() );
148
        if (oth) {
149
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
150
                if (inh_##attr_NAME) \
6733 avox 151
                        m_##attr_NAME = oth->attr_GETTER();
6443 avox 152
#include "charstyle.attrdefs.cxx"
153
#undef ATTRDEF
154
        }
155
}
156
 
157
 
158
 
159
 
160
/*
161
bool CharStyle::definesAll() const
162
{
163
        return definesLineSpacing() &&
164
        definesLeftMargin() &&
165
        definesRightMargin() &&
166
        definesFirstIndent() &&
167
        definesAlignment() &&
168
        definesGapBefore()  &&
169
        definesLineSpacingMode()  &&
170
        definesGapAfter()  &&
171
        definesHasDropCap() &&
172
        definesDropCapOffset() &&
173
        definesDropCapLines() &&
174
        definesUseBaselineGrid() &&
175
        charStyle().definesAll() ;
176
 
177
}
178
 
179
bool CharStyle::inheritsAll() const
180
{
181
        return inheritsLineSpacing() &&
182
        inheritsLeftMargin() &&
183
        inheritsRightMargin() &&
184
        inheritsFirstIndent() &&
185
        inheritsAlignment() &&
186
        inheritsGapBefore()  &&
187
        inheritsLineSpacingMode()  &&
188
        inheritsGapAfter()  &&
189
        inheritsHasDropCap() &&
190
        inheritsDropCapOffset() &&
191
        inheritsDropCapLines() &&
192
        inheritsUseBaselineGrid() &&
193
        charStyle().inheritsAll() ;
194
}
195
*/
196