Back to index

scribus-ng  1.3.4.dfsg+svn20071115
stylereader.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2004 by Riku Leino                                      *
00009  *   tsoots@gmail.com                                                      *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #ifndef STYLEREADER_H
00028 #define STYLEREADER_H
00029 
00030 #include "scconfig.h"
00031 
00032 #ifdef HAVE_XML
00033 
00034 #ifdef HAVE_XML26
00035  #include <libxml/SAX2.h>
00036 #else
00037  #include <libxml/SAX.h>
00038 #endif
00039 #include <qmap.h>
00040 #include <qxml.h>
00041 #include <gtstyle.h>
00042 #include <gtwriter.h>
00043 
00044 
00045 enum BulletType {
00046        Bullet,
00047        Number,
00048        LowerRoman,
00049        UpperRoman,
00050        LowerAlpha,
00051        UpperAlpha,
00052        Graphic
00053 };
00054 
00055 class ListLevel
00056 {
00057 public:
00058        ListLevel(uint level,
00059                  BulletType btype,
00060                  const QString &prefix,
00061                  const QString &suffix,
00062                  const QString &bullet,
00063                  uint displayLevels = 1,
00064                  uint startValue = 0);
00065        ~ListLevel();
00066        QString bulletString();
00067        QString bullet();
00068        QString prefix();
00069        QString suffix();
00070        void advance();
00071        void reset();
00072        uint level();
00073        uint displayLevels();
00074 private:
00075        uint m_level;
00076        BulletType m_btype;
00077        QString m_prefix;
00078        QString m_suffix;
00079        QString m_bullet;
00080        uint m_displayLevels;
00081        uint m_next;
00082        static const QString lowerUnits[10];
00083        static const QString lowerTens[10];
00084        static const QString lowerHundreds[10];
00085        static const QString lowerThousands[4];
00086        static const QString upperUnits[10];
00087        static const QString upperTens[10];
00088        static const QString upperHundreds[10];
00089        static const QString upperThousands[4];
00090        static const QString lowerAlphabets[27];
00091        static const QString upperAlphabets[27];
00092        QString lowerRoman(uint n);
00093        QString upperRoman(uint n);
00094        QString lowerAlpha(uint n);
00095        QString upperAlpha(uint n);
00096 };
00097 
00098 class ListStyle
00099 {
00100 public:
00101        ListStyle(const QString &name, bool consecutiveNumbering = false, uint currentLevel = 1);
00102        ~ListStyle();
00103        void addLevel(uint level, ListLevel *llevel);
00104        QString bullet();
00105        void advance();
00106        void setLevel(uint level);
00107        void resetLevel();
00108        QString& name();
00109 private:
00110        QString m_name;
00111        bool m_consecutiveNumbering;
00112        uint m_currentLevel;
00113        uint m_count;
00114        ListLevel* levels[11];
00115 };
00116 
00117 typedef QMap<QString, gtStyle*> StyleMap;
00118 typedef QMap<QString, QString> FontMap;
00119 typedef QMap<QString, int> CounterMap;
00120 typedef QMap<QString, ListStyle*> ListMap;
00121 
00122 class StyleReader
00123 {
00124 private:
00125        static StyleReader *sreader;
00126        gtWriter *writer;
00127        bool importTextOnly;
00128        bool usePrefix;
00129        bool packStyles;
00130        bool readProperties;
00131        QString docname;
00132        StyleMap styles;
00133        StyleMap listParents;
00134        StyleMap attrsStyles;
00135        CounterMap pstyleCounts;
00136        FontMap fonts;
00137        ListMap lists;
00138        gtStyle* currentStyle;
00139        gtStyle* parentStyle;
00140        bool inList;
00141        QString currentList;
00142        ListStyle *currentListStyle;
00143        bool defaultStyleCreated;
00144        double getSize(QString s, double parentSize = -1);
00145        void styleProperties(const QXmlAttributes& attrs);
00146        void defaultStyle(const QXmlAttributes& attrs);
00147        void styleStyle(const QXmlAttributes& attrs);
00148        void tabStop(const QXmlAttributes& attrs);
00149        void setupFrameStyle();
00150 public:
00151        StyleReader(QString documentName, gtWriter *wr, bool textOnly, bool prefix, bool combineStyles = true);
00152        ~StyleReader();
00153        bool updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value);
00154        static void startElement(void *user_data, const xmlChar * fullname, const xmlChar ** atts);
00155        static void endElement(void *user_data, const xmlChar * name);
00156        bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
00157        bool endElement(const QString&, const QString&, const QString &name);
00158        void parse(QString fileName);
00159        gtStyle* getStyle(const QString& name);
00160        void setStyle(const QString& name, gtStyle* style);
00161        QString getFont(const QString& key);
00162        ListStyle *getList(const QString &name);
00163 };
00164 
00165 #endif // HAVE_XML
00166 
00167 #endif