Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

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_XML26
00033  #include <libxml/SAX2.h>
00034 #else
00035  #include <libxml/SAX.h>
00036 #endif
00037 #include <QMap>
00038 #include <QXmlAttributes>
00039 #include <gtstyle.h>
00040 #include <gtwriter.h>
00041 
00042 
00043 enum BulletType {
00044     Bullet,
00045     Number,
00046     LowerRoman,
00047     UpperRoman,
00048     LowerAlpha,
00049     UpperAlpha,
00050     Graphic
00051 };
00052 
00053 class ListLevel
00054 {
00055 public:
00056     ListLevel(uint level,
00057               BulletType btype,
00058               const QString &prefix,
00059               const QString &suffix,
00060               const QString &bullet,
00061               uint displayLevels = 1,
00062               uint startValue = 0);
00063     ~ListLevel();
00064     QString bulletString();
00065     QString bullet();
00066     QString prefix();
00067     QString suffix();
00068     void advance();
00069     void reset();
00070     uint level();
00071     uint displayLevels();
00072 private:
00073     uint m_level;
00074     BulletType m_btype;
00075     QString m_prefix;
00076     QString m_suffix;
00077     QString m_bullet;
00078     uint m_displayLevels;
00079     uint m_next;
00080     static const QString lowerUnits[10];
00081     static const QString lowerTens[10];
00082     static const QString lowerHundreds[10];
00083     static const QString lowerThousands[4];
00084     static const QString upperUnits[10];
00085     static const QString upperTens[10];
00086     static const QString upperHundreds[10];
00087     static const QString upperThousands[4];
00088     static const QString lowerAlphabets[27];
00089     static const QString upperAlphabets[27];
00090     QString lowerRoman(uint n);
00091     QString upperRoman(uint n);
00092     QString lowerAlpha(uint n);
00093     QString upperAlpha(uint n);
00094 };
00095 
00096 class ListStyle
00097 {
00098 public:
00099     ListStyle(const QString &name, bool consecutiveNumbering = false, uint currentLevel = 1);
00100     ~ListStyle();
00101     void addLevel(uint level, ListLevel *llevel);
00102     QString bullet();
00103     void advance();
00104     void setLevel(uint level);
00105     void resetLevel();
00106     QString& name();
00107 private:
00108     QString m_name;
00109     bool m_consecutiveNumbering;
00110     uint m_currentLevel;
00111     uint m_count;
00112     ListLevel* levels[11];
00113 };
00114 
00115 typedef QMap<QString, gtStyle*> StyleMap;
00116 typedef QMap<QString, QString> FontMap;
00117 typedef QMap<QString, int> CounterMap;
00118 typedef QMap<QString, ListStyle*> ListMap;
00119 
00120 class StyleReader
00121 {
00122 private:
00123     static StyleReader *sreader;
00124     gtWriter *writer;
00125     bool importTextOnly;
00126     bool usePrefix;
00127     bool packStyles;
00128     bool readProperties;
00129     QString docname;
00130     StyleMap styles;
00131     StyleMap listParents;
00132     StyleMap attrsStyles;
00133     CounterMap pstyleCounts;
00134     FontMap fonts;
00135     ListMap lists;
00136     gtStyle* currentStyle;
00137     gtStyle* parentStyle;
00138     bool inList;
00139     QString currentList;
00140     ListStyle *currentListStyle;
00141     bool defaultStyleCreated;
00142     double getSize(QString s, double parentSize = -1);
00143     void styleProperties(const QXmlAttributes& attrs);
00144     void defaultStyle(const QXmlAttributes& attrs);
00145     void styleStyle(const QXmlAttributes& attrs);
00146     void tabStop(const QXmlAttributes& attrs);
00147     void setupFrameStyle();
00148 public:
00149     StyleReader(QString documentName, gtWriter *wr, bool textOnly, bool prefix, bool combineStyles = true);
00150     ~StyleReader();
00151     bool updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value);
00152     static void startElement(void *user_data, const xmlChar * fullname, const xmlChar ** atts);
00153     static void endElement(void *user_data, const xmlChar * name);
00154     bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
00155     bool endElement(const QString&, const QString&, const QString &name);
00156     void parse(QString fileName);
00157     gtStyle* getDefaultStyle(void);
00158     gtStyle* getStyle(const QString& name);
00159     void setStyle(const QString& name, gtStyle* style);
00160     QString getFont(const QString& key);
00161     ListStyle *getList(const QString &name);
00162 };
00163 
00164 #endif
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.