Back to index

scribus-ng  1.3.4.dfsg+svn20071115
charstyle.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 *                                                                         *
00009 *   This program is free software; you can redistribute it and/or modify  *
00010 *   it under the terms of the GNU General Public License as published by  *
00011 *   the Free Software Foundation; either version 2 of the License, or     *
00012 *   (at your option) any later version.                                   *
00013 *                                                                         *
00014 ***************************************************************************/
00015 
00016 #ifndef CHARSTYLE_H
00017 #define CHARSTYLE_H
00018 
00019 
00020 #include "style.h"
00021 
00022 class ResourceCollection;
00023 
00024 enum StyleFlagValue {
00025        ScStyle_Default       = 0,
00026     ScStyle_Superscript   = 1,
00027     ScStyle_Subscript     = 2,
00028     ScStyle_Outline       = 4,
00029     ScStyle_Underline     = 8,
00030     ScStyle_Strikethrough = 16,
00031     ScStyle_AllCaps       = 32,
00032     ScStyle_SmallCaps     = 64,
00033     ScStyle_HyphenationPossible=128, //Hyphenation possible here (Smart Hyphen)
00034     ScStyle_Shadowed      = 256,
00035     ScStyle_UnderlineWords= 512,
00036     ScStyle_Reserved01    = 1024, //free, not used in the moment
00037     ScStyle_DropCap       = 2048,
00038     ScStyle_SuppressSpace = 4096,//internal use in PageItem (Suppresses spaces when in Block alignment)
00039     ScStyle_SmartHyphenVisible=8192, //Smart Hyphen visible at line end
00040     ScStyle_StartOfLine   = 16384,
00041        ScStyle_UserStyles    = 1919, // == 1024 + 512 + 256 + 64 + 32 + 16 + 8 + 4 + 2 + 1
00042        ScStyle_None          = 65535
00043 };
00044 
00045 class SCRIBUS_API StyleFlag
00046 {
00047 public:
00048 
00049        StyleFlagValue value;
00050 
00051        StyleFlag(void) { value = ScStyle_Default; }
00052        StyleFlag(StyleFlagValue val) { value = val; }
00053        StyleFlag(int val) { value = static_cast<StyleFlagValue>(val); }
00054 
00055        operator StyleFlagValue() const { return value; }
00056 
00057        QStringList featureList() const; 
00058        
00059        StyleFlag& operator=  (StyleFlagValue val) { value = val; return *this;}
00060        StyleFlag& operator&= (const StyleFlag& right);
00061        StyleFlag& operator|= (const StyleFlag& right);
00062        StyleFlag  operator&  (const StyleFlag& right);
00063        StyleFlag  operator&  (int right);
00064        StyleFlag  operator|  (const StyleFlag& right);
00065        StyleFlag  operator^  (const StyleFlag& right);
00066        StyleFlag  operator^  (int right);
00067        StyleFlag  operator~  ();
00068 
00069        bool operator== (const StyleFlag& right) const;
00070        bool operator== (const StyleFlagValue right) const;
00071        bool operator== (int right) const;
00072        bool operator!= (const StyleFlag& right) const;
00073        bool operator!= (const StyleFlagValue right) const;
00074 };
00075 
00076 class SCRIBUS_API CharStyle : public Style {
00077 public:
00078 
00079        static const QString INHERIT;
00080        static const QString BOLD;
00081        static const QString ITALIC;
00082        static const QString UNDERLINE;
00083        static const QString UNDERLINEWORDS;
00084        static const QString STRIKETHROUGH;
00085        static const QString SUPERSCRIPT;
00086        static const QString SUBSCRIPT;
00087        static const QString OUTLINE;
00088        static const QString SHADOWED;
00089        static const QString ALLCAPS;
00090        static const QString SMALLCAPS;
00091 
00092     CharStyle() : Style() {
00093 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00094               m_##attr_NAME = attr_DEFAULT; \
00095               inh_##attr_NAME = true;
00096 #include "charstyle.attrdefs.cxx"
00097 #undef ATTRDEF
00098     };
00099        
00100     CharStyle(const ScFace& font, int size, StyleFlag style = ScStyle_Default) : Style() {
00101 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00102               m_##attr_NAME = attr_DEFAULT; \
00103               inh_##attr_NAME = true;
00104 #include "charstyle.attrdefs.cxx"
00105 #undef ATTRDEF
00106               setFont(font);
00107         setFontSize(size);
00108               setEffects(style);
00109     };
00110        
00111        CharStyle(const CharStyle & other);
00112        
00113        CharStyle & operator=(const CharStyle & other);
00114        
00115        static const Xml_string saxxDefaultElem;
00116        static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
00117        
00118        virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
00119        virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
00120        
00121 
00122        void getNamedResources(ResourceCollection& lists) const;
00123        void replaceNamedResources(ResourceCollection& newNames);
00124 
00125        QString displayName() const;
00126 
00127        void update(const StyleContext * b);
00128        
00131        void updateFeatures();
00132        
00133        bool equiv(const Style& other) const;     
00134        
00135        void applyCharStyle(const CharStyle & other);
00136        void eraseCharStyle(const CharStyle & other);
00137        void setStyle(const CharStyle & other);
00138        void erase() { eraseCharStyle(*this); }
00139        
00140        QString asString() const;
00141        
00143        const StyleFlag effects() const { validate(); return m_Effects; }
00144        void setEffects(StyleFlag flags) { m_Effects = flags; }
00145        
00146        
00149 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00150        const attr_TYPE attr_GETTER() const { validate(); return m_##attr_NAME; }
00151 #include "charstyle.attrdefs.cxx"
00152 #undef ATTRDEF
00153        
00156 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00157        void set##attr_NAME(attr_TYPE v) { m_##attr_NAME = v; inh_##attr_NAME = false; }
00158 #include "charstyle.attrdefs.cxx"
00159 #undef ATTRDEF
00160        
00163 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00164        void reset##attr_NAME() { m_##attr_NAME = attr_DEFAULT; inh_##attr_NAME = true; }
00165 #include "charstyle.attrdefs.cxx"
00166 #undef ATTRDEF
00167        
00169 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00170        bool isInh##attr_NAME() const { return inh_##attr_NAME; }
00171 #include "charstyle.attrdefs.cxx"
00172 #undef ATTRDEF
00173        
00174        
00176 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00177        bool isDef##attr_NAME() const { \
00178               if ( !inh_##attr_NAME ) return true; \
00179               const CharStyle * par = dynamic_cast<const CharStyle*>(parentStyle()); \
00180               return par && par->isDef##attr_NAME(); \
00181        }
00182 #include "charstyle.attrdefs.cxx"
00183 #undef ATTRDEF
00184        
00185        
00186 private:
00187 
00188        void runFeatures(const QStringList& featurelist, const CharStyle* parent);
00189        
00190        StyleFlag m_Effects;
00191        // member declarations:
00192               
00193 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00194        attr_TYPE m_##attr_NAME; \
00195        bool inh_##attr_NAME;
00196 #include "charstyle.attrdefs.cxx"
00197 #undef ATTRDEF
00198 };
00199 
00200 
00201 inline CharStyle & CharStyle::operator=(const CharStyle & other)
00202 {
00203        static_cast<Style&>(*this) = static_cast<const Style&>(other);
00204 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00205        m_##attr_NAME = other.m_##attr_NAME; \
00206        inh_##attr_NAME = other.inh_##attr_NAME;
00207 #include "charstyle.attrdefs.cxx"
00208 #undef ATTRDEF
00209        m_Effects = other.m_Effects;
00210 //     m_context = NULL;
00211        m_contextversion = -1;
00212        return *this;
00213 }
00214 
00215 inline CharStyle::CharStyle(const CharStyle & other) : Style(other) 
00216 {
00217 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00218        m_##attr_NAME = other.m_##attr_NAME; \
00219        inh_##attr_NAME = other.inh_##attr_NAME;
00220 #include "charstyle.attrdefs.cxx"
00221 #undef ATTRDEF
00222        m_Effects = other.m_Effects;
00223 //     m_context = NULL;
00224        m_contextversion = -1;
00225 }
00226 
00227 #endif