ufont.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  ufont.hpp
00004  *  Ubit Project
00005  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006  *  (C) 1999-2006 / Eric Lecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007  *
00008  * ***********************************************************************
00009  * COPYRIGHT NOTICE : 
00010  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00011  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00012  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00013  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00014  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016  * ***********************************************************************
00017  * ==================================================== [(c)Elc] ======= *
00018  * ==================================================== ======== ======= */
00019 
00020 #ifndef _ufont_hpp_
00021 #define _ufont_hpp_
00022 //pragma ident  "@(#)ufont.hpp  ubit:05.05.00"
00023 #include <ubit/uprop.hpp>
00024 #include <ubit/ustr.hpp>
00025 namespace ubit {
00026 
00027 /* ==================================================== ===== ======= */
00035 class UFont : public UProp {
00036 public:
00037   UBIT_ATTR_CLASS(UFont,UProp)
00038 
00039   enum Style {
00040     PLAIN         = 0,
00041     BOLD          = 1<<0,       // DON'T CHANGE VALUE!
00042     ITALIC        = 1<<1,       // DON'T CHANGE VALUE!
00043     FILL          = 1<<2,
00044     UNDERLINE     = 1<<3,
00045     OVERLINE      = 1<<4,
00046     STRIKETHROUGH = 1<<5
00047   };
00049 
00050   static UFont sans_serif, serif, monospace;
00052 
00053   static UFont xx_small, x_small, small, medium, large, x_large, xx_large;
00055 
00056   static UFont plain, bold, italic, fill, underline, overline, strikethrough;
00063   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00064 
00065   UFont();
00066   UFont(const UFont&);
00067   UFont(const UFont&, int style, int point_size);
00068   UFont(const UFontFamily&, int style, int point_size);
00077   friend UFont& ufont(const UFont& _f) {return *new UFont(_f);}
00079 
00080   UFont& operator=(const UFont& f) {set(f); return *this;}
00082 
00083   virtual void set(const UFont&);
00085 
00086   bool operator==(const UFont& f) const {return equals(f);}
00087   bool operator!=(const UFont& f) const {return !equals(f);}
00088   virtual bool equals(const UFont&) const;
00090   
00091   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00092 
00093   const UFontFamily& getFamily() const {return *family;}
00094   UFont& setFamily(const UFontFamily&);
00095   UFont& setFamily(const UFont&);
00096 
00097   int getPointSize() const {return size;}
00098   UFont& setPointSize(int point_size);
00099   UFont& setPointSize(const UFont&);
00101   
00102   bool isPlain() const;
00103   bool isBold() const;
00104   bool isItalic() const;
00105   bool isFilled() const;
00106   bool isUnderlined() const;
00107   bool isOverlined() const;
00108   bool isStrikethrough() const;
00109 
00110   UFont& setBold(bool = true);
00111   UFont& setItalic(bool = true);
00112   UFont& setFilled(bool = true);
00113   UFont& setUnderlined(bool = true);
00114   UFont& setOverlined(bool = true);
00115   UFont& setStrikethrough(bool = true);
00116   
00117   int getStyle() const {return on_styles;}
00118   UFont& setStyle(const UFont&);
00119   UFont& setStyle(int styles);
00120   UFont& changeStyle(int style, bool add);
00126   void merge(const UFont&);
00131   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00132 
00133   virtual void update();
00135 
00136   virtual void realize(UDisp*);
00144   virtual void putProp(UContext*, UControl*);
00145   
00146 private:
00147   friend class UDisp;
00148   friend class UNatDisp;
00149   friend class UFontDesc;
00150   const class UFontFamily* family;
00151   short size;
00152   short on_styles, off_styles;  // activated and disactivated styles
00153   UFont(const UFontFamily*, int style, int point_size, UMask);
00154 };
00155 
00156 /* ==================================================== ===== ======= */
00162 struct UFontFamilyConf {
00163   const char *family, 
00164   *normal_style, *italic_style,
00165   *normal_weight, *bold_weight,
00166   *compression, *encoding,  
00167   *sizes;
00168   const char *truetype_regular, *truetype_bold, *truetype_italic, *truetype_bold_italic;
00169 };
00170 
00171 class UFontFamily {
00172 public:
00173   static UFontFamily sans_serif, serif, monospace;
00175 
00176   UFontFamily(const char* name);
00177   UFontFamily(const char* name, const UFontFamilyConf*);
00178 
00179   const UStr& getName() const {return name;}
00180   void configure(const UFontFamilyConf&);
00181 
00182   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00183 
00184 private:
00185   friend class UDisp;
00186   friend class UNatDisp;
00187   friend class UFont;  
00188   friend class UFontDesc;  
00189   friend class UNatFont;  
00190   static int family_count;
00191   unsigned int index;
00192   const UFontFamilyConf* conf;
00193   UStr name;
00194   //UStr font_names[4], truetype_font_names[4];
00195   std::vector<int> sizes;
00196 
00197   void initSizes(const char*);
00198   int sizeToIndex(float size) const;
00199 };
00200 
00201 }
00202 #endif
00203 /* ==================================================== [TheEnd] ======= */
00204 /* ==================================================== [(c)Elc] ======= */
00205 

Generated on Mon Jan 29 00:20:38 2007 for Ubit by  doxygen 1.4.7