Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
4430 cbradney 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
*/
1579 tsoots 7
/***************************************************************************
8
 *   Copyright (C) 2004 by Riku Leino                                      *
9
 *   tsoots@gmail.com                                                      *
10
 *                                                                         *
11
 *   This program is free software; you can redistribute it and/or modify  *
12
 *   it under the terms of the GNU General Public License as published by  *
13
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 *   (at your option) any later version.                                   *
15
 *                                                                         *
16
 *   This program is distributed in the hope that it will be useful,       *
17
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19
 *   GNU General Public License for more details.                          *
20
 *                                                                         *
21
 *   You should have received a copy of the GNU General Public License     *
22
 *   along with this program; if not, write to the                         *
23
 *   Free Software Foundation, Inc.,                                       *
18122 mrdocs 24
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
1579 tsoots 25
 ***************************************************************************/
26
 
27
#ifndef STYLEREADER_H
28
#define STYLEREADER_H
29
 
2688 craig 30
#include "scconfig.h"
1579 tsoots 31
 
32
#ifdef HAVE_XML26
33
 #include <libxml/SAX2.h>
34
#else
35
 #include <libxml/SAX.h>
36
#endif
10223 cbradney 37
#include <QMap>
38
#include <QXmlAttributes>
1579 tsoots 39
#include <gtstyle.h>
40
#include <gtwriter.h>
41
 
2212 tsoots 42
 
43
enum BulletType {
44
        Bullet,
45
        Number,
46
        LowerRoman,
47
        UpperRoman,
48
        LowerAlpha,
49
        UpperAlpha,
50
        Graphic
51
};
52
 
53
class ListLevel
54
{
55
public:
56
        ListLevel(uint level,
57
                  BulletType btype,
58
                  const QString &prefix,
59
                  const QString &suffix,
60
                  const QString &bullet,
61
                  uint displayLevels = 1,
62
                  uint startValue = 0);
63
        ~ListLevel();
64
        QString bulletString();
65
        QString bullet();
66
        QString prefix();
67
        QString suffix();
68
        void advance();
69
        void reset();
70
        uint level();
71
        uint displayLevels();
72
private:
73
        uint m_level;
74
        BulletType m_btype;
75
        QString m_prefix;
76
        QString m_suffix;
77
        QString m_bullet;
78
        uint m_displayLevels;
79
        uint m_next;
80
        static const QString lowerUnits[10];
81
        static const QString lowerTens[10];
82
        static const QString lowerHundreds[10];
83
        static const QString lowerThousands[4];
84
        static const QString upperUnits[10];
85
        static const QString upperTens[10];
86
        static const QString upperHundreds[10];
87
        static const QString upperThousands[4];
88
        static const QString lowerAlphabets[27];
89
        static const QString upperAlphabets[27];
90
        QString lowerRoman(uint n);
91
        QString upperRoman(uint n);
92
        QString lowerAlpha(uint n);
93
        QString upperAlpha(uint n);
94
};
95
 
96
class ListStyle
97
{
98
public:
99
        ListStyle(const QString &name, bool consecutiveNumbering = false, uint currentLevel = 1);
100
        ~ListStyle();
101
        void addLevel(uint level, ListLevel *llevel);
102
        QString bullet();
103
        void advance();
104
        void setLevel(uint level);
105
        void resetLevel();
106
        QString& name();
107
private:
108
        QString m_name;
109
        bool m_consecutiveNumbering;
110
        uint m_currentLevel;
111
        uint m_count;
112
        ListLevel* levels[11];
113
};
114
 
1579 tsoots 115
typedef QMap<QString, gtStyle*> StyleMap;
116
typedef QMap<QString, QString> FontMap;
117
typedef QMap<QString, int> CounterMap;
2212 tsoots 118
typedef QMap<QString, ListStyle*> ListMap;
1579 tsoots 119
 
120
class StyleReader
121
{
122
private:
123
        static StyleReader *sreader;
124
        gtWriter *writer;
125
        bool importTextOnly;
126
        bool usePrefix;
127
        bool packStyles;
128
        bool readProperties;
129
        QString docname;
130
        StyleMap styles;
131
        StyleMap listParents;
132
        StyleMap attrsStyles;
133
        CounterMap pstyleCounts;
134
        FontMap fonts;
2212 tsoots 135
        ListMap lists;
1579 tsoots 136
        gtStyle* currentStyle;
137
        gtStyle* parentStyle;
138
        bool inList;
139
        QString currentList;
2212 tsoots 140
        ListStyle *currentListStyle;
1579 tsoots 141
        bool defaultStyleCreated;
142
        double getSize(QString s, double parentSize = -1);
143
        void styleProperties(const QXmlAttributes& attrs);
144
        void defaultStyle(const QXmlAttributes& attrs);
145
        void styleStyle(const QXmlAttributes& attrs);
146
        void tabStop(const QXmlAttributes& attrs);
147
        void setupFrameStyle();
148
public:
149
        StyleReader(QString documentName, gtWriter *wr, bool textOnly, bool prefix, bool combineStyles = true);
150
        ~StyleReader();
151
        bool updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value);
152
        static void startElement(void *user_data, const xmlChar * fullname, const xmlChar ** atts);
153
        static void endElement(void *user_data, const xmlChar * name);
154
        bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
155
        bool endElement(const QString&, const QString&, const QString &name);
156
        void parse(QString fileName);
10111 jghali 157
        gtStyle* getDefaultStyle(void);
1579 tsoots 158
        gtStyle* getStyle(const QString& name);
159
        void setStyle(const QString& name, gtStyle* style);
160
        QString getFont(const QString& key);
2212 tsoots 161
        ListStyle *getList(const QString &name);
1579 tsoots 162
};
163
 
164
#endif