text-tag.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * Gnome Chemistry Utils
00005  * gccv/text-tag.h 
00006  *
00007  * Copyright (C) 2008-2009 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 #ifndef GCCV_TEXT_TAG_H
00026 #define GCCV_TEXT_TAG_H
00027 
00028 #include "structs.h"
00029 #include <gcu/macros.h>
00030 #include <list>
00031 #include <string>
00032 
00034 namespace gccv {
00035 
00036 // Text attributes support
00037 typedef enum
00038 {
00039         Invalid,
00040         Family,
00041         Size,
00042         Style,
00043         Weight,
00044         Variant,
00045         Stretch,
00046         Underline,
00047         Overline,
00048         Strikethrough,
00049         Foreground,
00050         Background,
00051         Rise,
00052         Position,
00053         NewLine,
00054         MaxTag
00055 } Tag;
00056 
00057 typedef enum
00058 {
00059         TagPriorityFirst,
00060         TagPriorityLast,
00061 } TagPriority;
00062 
00063 class TextTag
00064 {
00065 public:
00066         TextTag (Tag tag, TagPriority priority = TagPriorityFirst);
00067         virtual ~TextTag ();
00068 
00069         virtual void Filter (PangoAttrList *l, unsigned start, unsigned end) = 0;
00070         virtual bool operator== (TextTag const& tag) const = 0;
00071         virtual TextTag *Duplicate () const = 0;
00072         virtual bool NeedsNewRun () {return false;}
00073         virtual TextTag *Restrict (TextTag *tag);
00074 
00075         static Tag RegisterTagType ();
00076         static Tag MaxTag;
00077         static bool Order (TextTag *first, TextTag *last);
00078 
00079 GCU_RO_PROP (Tag, Tag)
00080 GCU_RO_PROP (TagPriority, Priority)
00081 GCU_PROP (unsigned, StartIndex)
00082 GCU_PROP (unsigned, EndIndex)
00083 GCU_PROT_PROP (bool, Stacked)
00084 GCU_PROT_PROP (bool, NewLine)
00085 };
00086 
00087 class FamilyTextTag: public TextTag
00088 {
00089 public:
00090         FamilyTextTag (std::string const &family);
00091         FamilyTextTag (char const *family);
00092         virtual ~FamilyTextTag ();
00093 
00094         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00095         bool operator== (TextTag const& tag) const;
00096         TextTag *Duplicate () const;
00097         std::string const &GetFamily () const {return m_Family;}
00098 
00099 private:
00100         std::string m_Family;
00101 };
00102 
00103 class SizeTextTag: public TextTag
00104 {
00105 public:
00106         SizeTextTag (double size);
00107         virtual ~SizeTextTag ();
00108 
00109         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00110         bool operator== (TextTag const& tag) const;
00111         TextTag *Duplicate () const;
00112         double GetSize () const {return m_Size;}
00113 
00114 private:
00115         double m_Size;
00116 };
00117 
00118 class StyleTextTag: public TextTag
00119 {
00120 public:
00121         StyleTextTag (PangoStyle style);
00122         virtual ~StyleTextTag ();
00123 
00124         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00125         bool operator== (TextTag const& tag) const;
00126         TextTag *Duplicate () const;
00127         PangoStyle GetStyle () const {return m_Style;}
00128 
00129 private:
00130         PangoStyle m_Style;
00131 };
00132 
00133 class WeightTextTag: public TextTag
00134 {
00135 public:
00136         WeightTextTag (PangoWeight weight);
00137         virtual ~WeightTextTag ();
00138 
00139         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00140         bool operator== (TextTag const& tag) const;
00141         TextTag *Duplicate () const;
00142         PangoWeight GetWeight () const {return m_Weight;}
00143 
00144 private:
00145         PangoWeight m_Weight;
00146 };
00147 
00148 class VariantTextTag: public TextTag
00149 {
00150 public:
00151         VariantTextTag (PangoVariant variant);
00152         virtual ~VariantTextTag ();
00153 
00154         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00155         bool operator== (TextTag const& tag) const;
00156         TextTag *Duplicate () const;
00157         PangoVariant GetVariant () const {return m_Variant;}
00158 
00159 private:
00160         PangoVariant m_Variant;
00161 };
00162 
00163 class StretchTextTag: public TextTag
00164 {
00165 public:
00166         StretchTextTag (PangoStretch stretch);
00167         virtual ~StretchTextTag ();
00168 
00169         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00170         bool operator== (TextTag const& tag) const;
00171         TextTag *Duplicate () const;
00172         PangoStretch GetStretch () const {return m_Stretch;}
00173 
00174 private:
00175         PangoStretch m_Stretch;
00176 };
00177 
00178 class UnderlineTextTag: public TextTag
00179 {
00180 public:
00181         UnderlineTextTag (TextDecoration underline, GOColor color = 0xff);
00182         virtual ~UnderlineTextTag ();
00183 
00184         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00185         bool operator== (TextTag const& tag) const;
00186         TextTag *Duplicate () const;
00187         TextDecoration GetUnderline () const {return m_Underline;}
00188 
00189 private:
00190         TextDecoration m_Underline;
00191 
00192 GCU_PROP (GOColor, Color)
00193 };
00194 
00195 class OverlineTextTag: public TextTag
00196 {
00197 public:
00198         OverlineTextTag (TextDecoration overline, GOColor color = 0xff);
00199         virtual ~OverlineTextTag ();
00200 
00201         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00202         bool operator== (TextTag const& tag) const;
00203         TextTag *Duplicate () const;
00204         TextDecoration GetOverline () const {return m_Overline;}
00205 
00206 private:
00207         TextDecoration m_Overline;
00208 
00209 GCU_PROP (GOColor, Color)
00210 };
00211 
00212 class StrikethroughTextTag: public TextTag
00213 {
00214 public:
00215         StrikethroughTextTag (TextDecoration strikethrough, GOColor color = 0xff);
00216         virtual ~StrikethroughTextTag ();
00217 
00218         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00219         bool operator== (TextTag const& tag) const;
00220         TextTag *Duplicate () const;
00221         TextDecoration GetStrikethrough () const {return m_Strikethrough;}
00222 
00223 private:
00224         TextDecoration m_Strikethrough;
00225 
00226 GCU_PROP (GOColor, Color)
00227 };
00228 
00229 class ForegroundTextTag: public TextTag
00230 {
00231 public:
00232         ForegroundTextTag (GOColor m_Color);
00233         virtual ~ForegroundTextTag ();
00234 
00235         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00236         bool operator== (TextTag const& tag) const;
00237         TextTag *Duplicate () const;
00238         GOColor GetColor () const {return m_Color;}
00239 
00240 private:
00241         GOColor m_Color;
00242 };
00243 
00244 class BackgroundTextTag: public TextTag
00245 {
00246 public:
00247         BackgroundTextTag (GOColor m_Color);
00248         virtual ~BackgroundTextTag ();
00249 
00250         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00251         bool operator== (TextTag const& tag) const;
00252         TextTag *Duplicate () const;
00253         GOColor GetColor () const {return m_Color;}
00254 
00255 private:
00256         GOColor m_Color;
00257 };
00258 
00259 class RiseTextTag: public TextTag
00260 {
00261 public:
00262         RiseTextTag (double size);
00263         virtual ~RiseTextTag ();
00264 
00265         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00266         bool operator== (TextTag const& tag) const;
00267         TextTag *Duplicate () const;
00268         double GetRise () const {return m_Rise;}
00269 
00270 private:
00271         double m_Rise;
00272 };
00273 
00274 class PositionTextTag: public TextTag
00275 {
00276 public:
00277         PositionTextTag (TextPosition position, double size, bool stacked = false, Tag tag = Position);
00278         virtual ~PositionTextTag ();
00279 
00280         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00281         bool operator== (TextTag const& tag) const;
00282         TextTag *Duplicate () const;
00283         TextPosition GetPosition (bool &stacked, double &size) const {stacked = m_Stacked; size = m_Size; return m_Position;}
00284         bool NeedsNewRun () {return m_Stacked;}
00285         TextTag *Restrict (G_GNUC_UNUSED TextTag *tag) {return NULL;}
00286 
00287 private:
00288         TextPosition m_Position;
00289         double m_Size; // default size
00290 };
00291 
00292 class NewLineTextTag: public TextTag
00293 {
00294 public:
00295         NewLineTextTag ();
00296         virtual ~NewLineTextTag ();
00297         
00298         void Filter (PangoAttrList *l, unsigned start, unsigned end);
00299         bool operator== (TextTag const& tag) const;
00300         TextTag *Duplicate () const;
00301 };
00302 
00303 class TextTagList:public std::list <TextTag *>
00304 {
00305 public:
00306         TextTagList ();
00307         ~TextTagList ();
00308 };
00309 
00310 }   //  namespace gccv
00311 
00312 #endif  //      GCCV_TEXT_TAG_H
Generated by  doxygen 1.6.2-20100208