Scribus
Open source desktop publishing at your fingertips
stylereader.h
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  * 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., *
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25  ***************************************************************************/
26 
27 #ifndef STYLEREADER_H
28 #define STYLEREADER_H
29 
30 #include "scconfig.h"
31 
32 #ifdef HAVE_XML26
33  #include <libxml/SAX2.h>
34 #else
35  #include <libxml/SAX.h>
36 #endif
37 #include <QMap>
38 #include <QXmlAttributes>
39 #include <gtstyle.h>
40 #include <gtwriter.h>
41 
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, 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  uint m_currentLevel;
110  uint m_count;
111  ListLevel* levels[11];
112 };
113 
114 typedef QMap<QString, gtStyle*> StyleMap;
115 typedef QMap<QString, QString> FontMap;
116 typedef QMap<QString, int> CounterMap;
117 typedef QMap<QString, ListStyle*> ListMap;
118 
120 {
121 private:
122  static StyleReader *sreader;
123  gtWriter *writer;
124  bool importTextOnly;
125  bool usePrefix;
126  bool packStyles;
127  bool readProperties;
128  QString docname;
129  StyleMap styles;
130  StyleMap listParents;
131  StyleMap attrsStyles;
132  CounterMap pstyleCounts;
133  FontMap fonts;
134  ListMap lists;
135  gtStyle* currentStyle;
136  gtStyle* parentStyle;
137  bool inList;
138  QString currentList;
139  ListStyle *currentListStyle;
140  bool defaultStyleCreated;
141  double getSize(QString s, double parentSize = -1);
142  void styleProperties(const QXmlAttributes& attrs);
143  void defaultStyle(const QXmlAttributes& attrs);
144  void styleStyle(const QXmlAttributes& attrs);
145  void tabStop(const QXmlAttributes& attrs);
146  void setupFrameStyle();
147 public:
148  StyleReader(QString documentName, gtWriter *wr, bool textOnly, bool prefix, bool combineStyles = true);
149  ~StyleReader();
150  bool updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value);
151  static void startElement(void *user_data, const xmlChar * fullname, const xmlChar ** atts);
152  static void endElement(void *user_data, const xmlChar * name);
153  bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
154  bool endElement(const QString&, const QString&, const QString &name);
155  void parse(QString fileName);
156  gtStyle* getDefaultStyle(void);
157  gtStyle* getStyle(const QString& name);
158  void setStyle(const QString& name, gtStyle* style);
159  QString getFont(const QString& key);
160  ListStyle *getList(const QString &name);
161 };
162 
163 #endif
Definition: gtwriter.h:38
Definition: gtstyle.h:34
Definition: stylereader.h:119
Definition: stylereader.h:53
Definition: stylereader.h:96
Definition: scribusstructs.h:150