Subversion Repositories Scribus

Rev

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

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