Subversion Repositories Scribus

Rev

Rev 12340 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6733 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
*   This program is free software; you can redistribute it and/or modify  *
10
*   it under the terms of the GNU General Public License as published by  *
11
*   the Free Software Foundation; either version 2 of the License, or     *
12
*   (at your option) any later version.                                   *
13
*                                                                         *
14
***************************************************************************/
6443 avox 15
 
12283 cbradney 16
#include "commonstrings.h"
8382 avox 17
#include "styles/style.h"
8337 avox 18
#include "paragraphstyle.h"
8455 avox 19
#include "resourcecollection.h"
8193 avox 20
#include "desaxe/saxiohelper.h"
8266 avox 21
#include "desaxe/simple_actions.h"
12337 pierre 22
#include "styleslibrary.h"
6733 avox 23
 
8193 avox 24
 
12340 pierre 25
ParagraphStyle::ParagraphStyle() : Style()
6443 avox 26
{
6805 avox 27
        setParent("");
12337 pierre 28
        CharStyle *csP(new CharStyle);
12340 pierre 29
        csP->setName( "CSTYLE" + name() );
12337 pierre 30
        cstyle = csP->uuid();
8134 avox 31
//      qDebug(QString("ParagraphStyle() %1 pcontext %2 ccontext %3").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(context())).arg(reinterpret_cast<uint>(defaultStyle()->context())));
6443 avox 32
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
33
        m_##attr_NAME = attr_DEFAULT; \
34
        inh_##attr_NAME = true;
35
#include "paragraphstyle.attrdefs.cxx"
36
#undef ATTRDEF
12283 cbradney 37
 
38
        m_isDefaultStyle=false;
6443 avox 39
}
40
 
41
 
12340 pierre 42
ParagraphStyle::ParagraphStyle(const ParagraphStyle& other) : Style(other), cstyle(other.charStyle())
6443 avox 43
{
7003 avox 44
        other.validate();
6733 avox 45
 
6443 avox 46
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
47
        m_##attr_NAME = other.m_##attr_NAME; \
48
        inh_##attr_NAME = other.inh_##attr_NAME;
49
#include "paragraphstyle.attrdefs.cxx"
50
#undef ATTRDEF
51
}
52
 
6765 avox 53
ParagraphStyle::~ParagraphStyle()
54
{
55
//      qDebug(QString("~ParagraphStyle %1").arg(reinterpret_cast<uint>(this)));
56
}
57
 
8193 avox 58
 
12314 pierre 59
// QString ParagraphStyle::displayName() const
60
// {
61
//      if ( isDefaultStyle() )
62
//              return CommonStrings::trDefaultParagraphStyle;
63
//      if ( hasName() || !hasParent() || !m_context)
64
//              return name();
65
//      //      else if ( inheritsAll() )
66
//      //              return parent()->displayName();
67
//      else 
68
//              return parentStyle()->displayName() + "+";
69
// }
70
// 
6443 avox 71
 
12340 pierre 72
bool ParagraphStyle::equiv(const QString& other) const
6443 avox 73
{
12340 pierre 74
        const ParagraphStyle* oth = StylesLibrary::Paragraph( other );
6443 avox 75
        return  oth &&
12340 pierre 76
                parent() == oth->parent() && (cstyle == oth->charStyle() )
6443 avox 77
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 78
                && (inh_##attr_NAME == oth->inh_##attr_NAME) \
79
                && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
6443 avox 80
#include "paragraphstyle.attrdefs.cxx"
81
#undef ATTRDEF
82
                ;
83
}      
84
 
85
 
9607 avox 86
/* hm... av
87
static void updateAutoLinespacing(ParagraphStyle& that)
88
{
89
        switch (that.lineSpacingMode())
90
        {
91
                case 0:
92
                        that.setLineSpacing(((that.charStyle().fontSize() / 10.0) * static_cast<double>(typographicSettings.autoLineSpacing) / 100) + (size / 10.0));
93
                        break;
94
                case 1:
95
                        that.setLineSpacing(that.charStyle().font().height(size));
96
                        break;
97
                case 2:
98
                        that.setLineSpacing(typographicSettings.valueBaseGrid-1);
99
                        break;
100
        }
101
}
102
*/
6443 avox 103
 
12343 pierre 104
// ParagraphStyle& ParagraphStyle::operator=(const ParagraphStyle& other) 
105
// {
106
//      static_cast<Style&>(*this) = static_cast<const Style&>(other);
107
// 
108
//      other.validate();
109
//      cstyle = other.charStyle() ;
110
// 
111
// //   // we dont want cstyleContext to point to other's charstyle...
112
// //   cstyleContext.setDefaultStyle( StylesLibrary::Char( cstyle ) );
113
// //   
114
// //   if (cstyleContextIsInh)
115
// //   {
116
// //           const ParagraphStyle * parent = dynamic_cast<const ParagraphStyle*> ( parentStyle() );
117
// //           cstyle.setContext(parent ? parent->charStyleContext() : NULL);
118
// //   }
119
// //   else
120
// //   {
121
// //           cstyle.setContext(other.charStyle().context());
122
// //   }
123
// //   
124
/*
6443 avox 125
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 126
        m_##attr_NAME = other.m_##attr_NAME; \
127
        inh_##attr_NAME = other.inh_##attr_NAME;
6443 avox 128
#include "paragraphstyle.attrdefs.cxx"
129
#undef ATTRDEF
12343 pierre 130
*/
131
//      return *this;
132
// }
6443 avox 133
 
134
 
135
 
8058 avox 136
 
137
 
12340 pierre 138
void ParagraphStyle::applyStyle(const QString& other)
6443 avox 139
{
12340 pierre 140
        ParagraphStyle *pOther = StylesLibrary::Paragraph(other);
6443 avox 141
        Style::applyStyle(other);
12340 pierre 142
        StylesLibrary::Char(cstyle)->applyCharStyle(pOther->charStyle());
6443 avox 143
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
12340 pierre 144
        if (! pOther->inh_##attr_NAME) \
145
        set##attr_NAME(pOther->m_##attr_NAME);
6443 avox 146
#include "paragraphstyle.attrdefs.cxx"
147
#undef ATTRDEF
148
}
149
 
150
 
12340 pierre 151
void ParagraphStyle::eraseStyle(const QString& other)
6443 avox 152
{
12340 pierre 153
        ParagraphStyle *pOther = StylesLibrary::Paragraph(other);
154
        pOther->validate();
6443 avox 155
        Style::eraseStyle(other);
12340 pierre 156
        StylesLibrary::Char(cstyle)->eraseCharStyle(pOther->charStyle());
6443 avox 157
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
12340 pierre 158
        if (!inh_##attr_NAME && m_##attr_NAME == pOther->m_##attr_NAME) \
6443 avox 159
                reset##attr_NAME();
160
#include "paragraphstyle.attrdefs.cxx"
161
#undef ATTRDEF
162
}
163
 
12340 pierre 164
void ParagraphStyle::setStyle(const QString& other)
7242 avox 165
{
12340 pierre 166
        ParagraphStyle *pOther = StylesLibrary::Paragraph(other);
167
        pOther->validate();
168
        setParent(pOther->parent());
169
        StylesLibrary::Char(cstyle)->setStyle(pOther->charStyle());
7242 avox 170
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
12340 pierre 171
        inh_##attr_NAME = pOther->inh_##attr_NAME; \
172
        m_##attr_NAME = pOther->m_##attr_NAME;
7242 avox 173
#include "paragraphstyle.attrdefs.cxx"
174
#undef ATTRDEF
175
}
176
 
8266 avox 177
 
8455 avox 178
void ParagraphStyle::getNamedResources(ResourceCollection& lists) const
179
{
8858 cbradney 180
        for (const Style *sty = parentStyle(); sty != NULL; sty = sty->parentStyle())
12314 pierre 181
                lists.collectStyle(sty->uuid());
12340 pierre 182
        StylesLibrary::Char( cstyle )->getNamedResources(lists);
8455 avox 183
}
184
 
185
 
186
void ParagraphStyle::replaceNamedResources(ResourceCollection& newNames)
187
{
8775 cbradney 188
        QMap<QString,QString>::ConstIterator it;
8455 avox 189
 
8814 cbradney 190
        if (hasParent() && (it = (newNames.styles().find(parent()))) != newNames.styles().end())
8455 avox 191
        {
10394 cbradney 192
                setParent(it.value());
8455 avox 193
        }
12337 pierre 194
        StylesLibrary::Char(cstyle)->replaceNamedResources(newNames);
8455 avox 195
}
196
 
197
 
8266 avox 198
static QString toXMLString(ParagraphStyle::AlignmentType val)
199
{
200
        return QString::number(static_cast<int>(val));
201
}
202
 
203
 
9797 avox 204
static QString toXMLString(const QList<ParagraphStyle::TabRecord> & )
8266 avox 205
{
206
        return "dummy";
207
}
208
 
8800 jghali 209
void ParagraphStyle::saxx(SaxHandler& handler, const Xml_string& elemtag) const
8266 avox 210
{
211
        Xml_attr att;
8337 avox 212
        Style::saxxAttributes(att);
8266 avox 213
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
8348 avox 214
        if (!inh_##attr_NAME && strcmp(# attr_NAME, "TabValues") != 0) \
8266 avox 215
                att.insert(# attr_NAME, toXMLString(m_##attr_NAME)); 
216
#include "paragraphstyle.attrdefs.cxx"
217
#undef ATTRDEF
12343 pierre 218
//      if (!uuid().isEmpty())
12314 pierre 219
                att["id"] = mkXMLName(elemtag + uuid());
8266 avox 220
        handler.begin(elemtag, att);
8455 avox 221
//      if (parentStyle() && hasParent())
222
//              parentStyle()->saxx(handler);
9797 avox 223
        QList<ParagraphStyle::TabRecord>::const_iterator it;
8266 avox 224
        for (it=m_TabValues.begin(); it != m_TabValues.end(); ++it)
225
        {
226
                const ParagraphStyle::TabRecord& tb(*it);
227
                Xml_attr tab;
228
                tab.insert("pos", toXMLString(tb.tabPosition));
229
                tab.insert("fillChar", toXMLString(tb.tabFillChar.unicode()));
230
                tab.insert("type", toXMLString(tb.tabType));
231
                handler.beginEnd("tabstop", tab);
232
        }
12337 pierre 233
//      if (charStyle() != CharStyle())
234
//              charStyle().saxx(handler);
8266 avox 235
        handler.end(elemtag);
236
}
237
 
238
///   PageItem StoryText -> PageItem StoryText
239
class SetCharStyle_body : public desaxe::Action_body
240
{
8834 cbradney 241
        void end (const Xml_string& /*tagname*/)
8266 avox 242
        {
243
                ParagraphStyle* pstyle = this->dig->top<ParagraphStyle>(1);
244
                CharStyle* cstyle = this->dig->top<CharStyle>(0);
245
                pstyle->charStyle() = *cstyle;
246
        }
247
};
248
 
249
class SetCharStyle : public desaxe::MakeAction<SetCharStyle_body>
250
{};
251
 
252
 
253
 
8289 avox 254
class SetTabStop_body : public desaxe::Action_body
255
{
8834 cbradney 256
        void begin (const Xml_string& /*tagname*/, Xml_attr attr)
8289 avox 257
        {
258
                ParagraphStyle* pstyle = this->dig->top<ParagraphStyle>();
259
                ParagraphStyle::TabRecord tb;
260
                tb.tabPosition = parseDouble(attr["pos"]);
261
                tb.tabFillChar = QChar(parseInt(attr["fillChar"]));
262
                tb.tabType = parseInt(attr["type"]);
9797 avox 263
                QList<ParagraphStyle::TabRecord> tabs = pstyle->tabValues();
8289 avox 264
                tabs.append(tb);
265
                pstyle->setTabValues(tabs);
266
        }
267
};
8266 avox 268
 
8289 avox 269
class SetTabStop : public desaxe::MakeAction<SetTabStop_body>
270
{};
271
 
272
 
273
 
274
 
8266 avox 275
template<>
8800 jghali 276
ParagraphStyle::AlignmentType parse<ParagraphStyle::AlignmentType>(const Xml_string& str)
8266 avox 277
{
278
        return parseEnum<ParagraphStyle::AlignmentType>(str);
279
}
280
 
281
 
282
template<>
8800 jghali 283
ParagraphStyle::LineSpacingMode parse<ParagraphStyle::LineSpacingMode>(const Xml_string& str)
8266 avox 284
{
285
        return parseEnum<ParagraphStyle::LineSpacingMode>(str);
286
}
287
 
288
 
9797 avox 289
typedef QList<ParagraphStyle::TabRecord> Tablist;
8266 avox 290
 
291
template<>
8800 jghali 292
Tablist parse<Tablist>(const Xml_string& str)
8266 avox 293
{
294
        return Tablist();
295
}
296
 
297
 
298
using namespace desaxe;
299
 
300
const Xml_string ParagraphStyle::saxxDefaultElem("style");
301
 
8834 cbradney 302
void ParagraphStyle::desaxeRules(const Xml_string& prefixPattern, Digester& ruleset, Xml_string elemtag)
8266 avox 303
{
304
        typedef ParagraphStyle::TabRecord TabRecord;
305
 
306
        Xml_string stylePrefix(Digester::concat(prefixPattern, elemtag));
307
        ruleset.addRule(stylePrefix, Factory<ParagraphStyle>());
8382 avox 308
        ruleset.addRule(stylePrefix, IdRef<ParagraphStyle>());
309
        Style::desaxeRules<ParagraphStyle>(prefixPattern, ruleset, elemtag);
8266 avox 310
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
8348 avox 311
        if ( strcmp(# attr_NAME, "TabValues") != 0) \
8266 avox 312
                ruleset.addRule(stylePrefix, SetAttributeWithConversion<ParagraphStyle, attr_TYPE> ( & ParagraphStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> ));
313
#include "paragraphstyle.attrdefs.cxx"
314
#undef ATTRDEF
315
        Xml_string charstylePrefix(Digester::concat(stylePrefix, CharStyle::saxxDefaultElem));
316
        CharStyle::desaxeRules(stylePrefix, ruleset);
317
        ruleset.addRule(charstylePrefix, SetCharStyle());
8289 avox 318
 
319
        Xml_string tabPrefix(Digester::concat(stylePrefix, "tabstop"));
320
        ruleset.addRule(tabPrefix, SetTabStop());
8266 avox 321
}