00001 /* 00002 libwt - Vassilis Virvilis Toolkit - a widget library 00003 Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the 00017 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, SA. 00019 */ 00020 00021 #ifndef WT_FONT_H 00022 #define WT_FONT_H 00023 00024 #include <SDL/SDL_ttf.h> 00025 00026 #include <string> 00027 #include <map> 00028 00029 #include <boost/shared_ptr.hpp> 00030 00031 #include <wt/size.h> 00032 #include <wt/rect.h> 00033 #include <wt/color.h> 00034 #include <wt/pixmap.h> 00035 00036 namespace Wt { 00037 00038 class Font { 00039 public: 00040 friend class Painter; 00041 00042 Font(const std::string& filename, int ptsize, int style = Normal, int index = 0); 00043 Font(); 00044 Font(const std::string& desc); 00045 00046 std::string description() const; 00047 std::string family() const; 00048 void setFont(std::string& filename); 00049 int pointSize() const; 00050 void setPointSize(int ptsize); 00051 bool bold() const; 00052 void setBold(bool enable); 00053 bool italic() const; 00054 void setItalic(bool enable); 00055 bool underline() const; 00056 void setUnderline(bool enable); 00057 00058 // FontInfo 00059 // FontMetrics 00060 int ascent() const; 00061 int descent() const; 00062 int height() const; 00063 int lineSpacing() const; 00064 int leading() const; 00065 int leftBearing(Uint16 ch) const; 00066 int rightBearing(Uint16 ch) const; 00067 int width(Uint16 ch) const; 00068 Size size(const Uint16 ch) const; 00069 Rect boundingRect(const Uint16 ch) const; 00070 Rect boundingRect(const std::string& str, int len = -1) const; 00071 Size size(const std::string& text) const; 00072 Size size(const Uint16 *text) const; 00073 00074 typedef enum { 00075 Normal = TTF_STYLE_NORMAL, 00076 Bold = TTF_STYLE_BOLD, 00077 Italic = TTF_STYLE_ITALIC, 00078 Underline = TTF_STYLE_UNDERLINE 00079 } FaceStyle; 00080 00081 protected: 00082 void detach(); 00083 00084 typedef enum { 00085 ASCII, 00086 UTF8 00087 } Encoding; 00088 00089 typedef enum { 00090 Solid, 00091 Shaded, 00092 Blended 00093 } Rendering; 00094 00095 bool style() const; 00096 bool styleFlag(int flag) const; 00097 void setStyleFlag(int flag, bool enable); 00098 00099 void setRendering(int rendering); 00100 int rendering() const; 00101 void setEncoding(int encoding); 00102 int encoding() const; 00103 void setBackgroundColor(const Color& bg_color); 00104 const Color& backgroundColor() const; 00105 void setForegroundColor(const Color& fg_color); 00106 const Color& foregroundColor() const; 00107 00108 // higher level Wt functions 00109 Pixmap blitText(const std::string& text) const; 00110 Pixmap blitText(const Uint16 *text) const; 00111 00112 // SDL_ttf unused functionality 00113 int faces() const; 00114 std::string faceStyleName() const; 00115 bool monoSpace() const; 00116 00117 public: 00118 //static functions 00119 static void init(); 00120 static void quit(); 00121 00122 static int defaultFontSize(int ptsize = 0); 00123 static Font& defaultFont(); 00124 00125 private: 00126 class Deleter { 00127 public: 00128 void operator()(TTF_Font* f); 00129 }; 00130 00131 typedef boost::shared_ptr<TTF_Font> Ptr; 00132 Ptr ttf_font; 00133 std::string filename_; 00134 int ptsize_; 00135 int index_; 00136 int rendering_; 00137 int encoding_; 00138 Color bg_color_; 00139 Color fg_color_; 00140 00141 //provided for convenience only and for in class usage 00142 operator const Ptr () const { 00143 return ttf_font; 00144 } 00145 00146 operator Ptr () { 00147 return ttf_font; 00148 } 00149 00150 operator const TTF_Font* () const { 00151 return ttf_font.get(); 00152 } 00153 00154 operator TTF_Font* () { 00155 return ttf_font.get(); 00156 } 00157 00158 TTF_Font *deconst() const; 00159 00160 static Font* default_font; 00161 00162 static Ptr open_default_font(int ptsize); 00163 static Ptr open_font(const std::string& filename, 00164 int ptsize, int style, int index = 0); 00165 public: 00166 00167 typedef std::map<std::string, Font> Map; 00168 static Map map; 00169 }; 00170 00171 /// Operator for output streams 00172 std::ostream& operator<<(std::ostream& s, const Font& f); 00173 00174 } // namespace Wt 00175 00176 #endif // WT_FONT_H
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.