#include <font.h>
Collaboration diagram for Wt::Font:
Public Types | |
typedef std::map< std::string, Font > | Map |
Normal = TTF_STYLE_NORMAL | |
Bold = TTF_STYLE_BOLD | |
Italic = TTF_STYLE_ITALIC | |
Underline = TTF_STYLE_UNDERLINE | |
enum | FaceStyle { Normal = TTF_STYLE_NORMAL, Bold = TTF_STYLE_BOLD, Italic = TTF_STYLE_ITALIC, Underline = TTF_STYLE_UNDERLINE } |
Public Member Functions | |
Font (const std::string &filename, int ptsize, int style=Normal, int index=0) | |
Font () | |
Font (const std::string &desc) | |
std::string | description () const |
std::string | family () const |
void | setFont (std::string &filename) |
int | pointSize () const |
void | setPointSize (int ptsize) |
bool | bold () const |
void | setBold (bool enable) |
bool | italic () const |
void | setItalic (bool enable) |
bool | underline () const |
void | setUnderline (bool enable) |
int | ascent () const |
int | descent () const |
int | height () const |
int | lineSpacing () const |
int | leading () const |
int | leftBearing (Uint16 ch) const |
int | rightBearing (Uint16 ch) const |
int | width (Uint16 ch) const |
Size | size (const Uint16 ch) const |
Rect | boundingRect (const Uint16 ch) const |
Rect | boundingRect (const std::string &str, int len=-1) const |
Size | size (const std::string &text) const |
Size | size (const Uint16 *text) const |
Static Public Member Functions | |
static void | init () |
static void | quit () |
static int | defaultFontSize (int ptsize=0) |
static Font & | defaultFont () |
Static Public Attributes | |
static Map | map |
Protected Types | |
ASCII | |
UTF8 | |
Solid | |
Shaded | |
Blended | |
enum | Encoding { ASCII, UTF8 } |
enum | Rendering { Solid, Shaded, Blended } |
Protected Member Functions | |
void | detach () |
bool | style () const |
bool | styleFlag (int flag) const |
void | setStyleFlag (int flag, bool enable) |
void | setRendering (int rendering) |
int | rendering () const |
void | setEncoding (int encoding) |
int | encoding () const |
void | setBackgroundColor (const Color &bg_color) |
const Color & | backgroundColor () const |
void | setForegroundColor (const Color &fg_color) |
const Color & | foregroundColor () const |
Pixmap | blitText (const std::string &text) const |
Pixmap | blitText (const Uint16 *text) const |
int | faces () const |
std::string | faceStyleName () const |
bool | monoSpace () const |
Private Types | |
typedef boost::shared_ptr< TTF_Font > | Ptr |
Private Member Functions | |
operator const Ptr () const | |
operator Ptr () | |
operator const TTF_Font * () const | |
operator TTF_Font * () | |
TTF_Font * | deconst () const |
Static Private Member Functions | |
static Ptr | open_default_font (int ptsize) |
static Ptr | open_font (const std::string &filename, int ptsize, int style, int index=0) |
Private Attributes | |
Ptr | ttf_font |
std::string | filename_ |
int | ptsize_ |
int | index_ |
int | rendering_ |
int | encoding_ |
Color | bg_color_ |
Color | fg_color_ |
Static Private Attributes | |
static Font * | default_font = 0 |
Friends | |
class | Painter |
Classes | |
class | Deleter |
Definition at line 38 of file font.h.
typedef std::map<std::string, Font> Wt::Font::Map |
typedef boost::shared_ptr<TTF_Font> Wt::Font::Ptr [private] |
enum Wt::Font::Encoding [protected] |
enum Wt::Font::FaceStyle |
enum Wt::Font::Rendering [protected] |
Definition at line 65 of file font.cpp.
References description(), filename_, trace, and ttf_font.
00065 : 00066 ttf_font(open_font(filename, defaultFontSize(ptsize), style, index)), 00067 filename_(filename), 00068 ptsize_(defaultFontSize(ptsize)), 00069 index_(index), 00070 rendering_(DEFAULT_RENDERING), 00071 encoding_(DEFAULT_ENCODING), 00072 bg_color_(DEFAULT_BACKGROUNDCOLOR), 00073 fg_color_(DEFAULT_FOREGROUNDCOLOR) { 00074 trace("font", "Creating font %p (%p) (%s)\n", this, ttf_font.get(), filename_.c_str()); 00075 trace("font") << "Adding to Font::Map " << *this << 00076 " use count: " << ttf_font.use_count() << std::endl; 00077 map[this->description()] = *this; 00078 }
Here is the call graph for this function:
Wt::Font::Font | ( | ) |
Definition at line 80 of file font.cpp.
References trace, and ttf_font.
Referenced by Font(), and init().
00080 : 00081 ttf_font(open_default_font(defaultFontSize())), 00082 filename_("*"), 00083 ptsize_(defaultFontSize()), 00084 index_(0), 00085 rendering_(DEFAULT_RENDERING), 00086 encoding_(DEFAULT_ENCODING), 00087 bg_color_(DEFAULT_BACKGROUNDCOLOR), 00088 fg_color_(DEFAULT_FOREGROUNDCOLOR) { 00089 trace("font", "Creating font %p (%p) (default)\n", this, ttf_font.get()); 00090 trace("font") << "Adding to Font::Map " << *this << 00091 " use count: " << ttf_font.use_count() << std::endl; 00092 }
Wt::Font::Font | ( | const std::string & | desc | ) |
Definition at line 94 of file font.cpp.
References Bold, Font(), Italic, Normal, trace, ttf_font, Underline, and Warn.
00094 { 00095 Map::iterator it = map.find(desc); 00096 trace("font", "Looking in Font::Map for '%s'\n", desc.c_str()); 00097 00098 // if it is in cache return it 00099 if (it != map.end()) { 00100 *this = it->second; 00101 trace("font") << "Found in Font::Map " << *this << 00102 " use count: " << ttf_font.use_count() << std::endl; 00103 return; 00104 } 00105 00106 // let's parse the description and load it in cache 00107 boost::char_separator<char> sep(", "); 00108 typedef boost::tokenizer<boost::char_separator<char> > Tokenizer; 00109 Tokenizer tokens(desc, sep); 00110 Tokenizer::iterator token = tokens.begin(); 00111 00112 std::string filename; 00113 if (token != tokens.end()) { 00114 filename = *token; 00115 ++token; 00116 } 00117 00118 int point_size = 0; 00119 if (token != tokens.end()) { 00120 point_size = boost::lexical_cast<int>(*token); 00121 ++token; 00122 } 00123 00124 int st = Normal; 00125 if (token != tokens.end()) { 00126 std::string flags = *token; 00127 for (std::string::iterator ct = flags.begin(), 00128 ctend = flags.end(); ct != ctend; ++ct) { 00129 switch (*ct) { 00130 case 'b': 00131 st |= Bold; 00132 break; 00133 case 'i': 00134 st |= Italic; 00135 break; 00136 case 'u': 00137 st |= Underline; 00138 break; 00139 default: 00140 Warn("Unknown specifier '%c' in font " 00141 "attibute desctrition '%s'\n", *ct, flags.c_str()); 00142 break; 00143 } 00144 } 00145 } 00146 00147 trace("font", "Parsing font description as '%s, %d, %d'\n", 00148 filename.c_str(), point_size, st); 00149 00150 *this = Font(filename, point_size, st); 00151 trace("font") << "Added to Font::Map " << *this << 00152 " use count: " << ttf_font.use_count() << std::endl; 00153 }
Here is the call graph for this function:
int Wt::Font::ascent | ( | ) | const |
Definition at line 373 of file font.cpp.
References deconst().
Referenced by Wt::PushButton::drawButtonLabel(), and Wt::Painter::drawText().
00373 { 00374 return TTF_FontAscent(deconst()); 00375 }
Here is the call graph for this function:
const Color & Wt::Font::backgroundColor | ( | ) | const [protected] |
Pixmap Wt::Font::blitText | ( | const Uint16 * | text | ) | const [protected] |
Definition at line 354 of file font.cpp.
References bg_color_, Blended, deconst(), fg_color_, rendering_, Shaded, and Solid.
00354 { 00355 SDL_Surface *s = 0; 00356 switch (rendering_) { 00357 case Solid: 00358 s = TTF_RenderUNICODE_Solid(deconst(), text, fg_color_); 00359 break; 00360 case Shaded: 00361 s = TTF_RenderUNICODE_Shaded(deconst(), text, fg_color_, bg_color_); 00362 break; 00363 case Blended: 00364 s = TTF_RenderUNICODE_Blended(deconst(), text, fg_color_); 00365 break; 00366 default: 00367 break; 00368 } 00369 00370 return Pixmap(s); 00371 }
Here is the call graph for this function:
Pixmap Wt::Font::blitText | ( | const std::string & | text | ) | const [protected] |
Definition at line 322 of file font.cpp.
References ASCII, bg_color_, Blended, deconst(), encoding_, fg_color_, rendering_, Shaded, Solid, and UTF8.
Referenced by Wt::Painter::drawText().
00322 { 00323 SDL_Surface *s = 0; 00324 switch (rendering_) { 00325 case Solid: 00326 if (encoding_ == ASCII) { 00327 s = TTF_RenderText_Solid(deconst(), text.c_str(), fg_color_); 00328 } else if (encoding_ == UTF8) { 00329 s = TTF_RenderUTF8_Solid(deconst(), text.c_str(), fg_color_); 00330 } 00331 break; 00332 case Shaded: 00333 if (encoding_ == ASCII) { 00334 s = TTF_RenderText_Shaded(deconst(), 00335 text.c_str(), fg_color_, bg_color_); 00336 } else if (encoding_ == UTF8) { 00337 s = TTF_RenderUTF8_Shaded(deconst(), text.c_str(),fg_color_, bg_color_); 00338 } 00339 break; 00340 case Blended: 00341 if (encoding_ == ASCII) { 00342 s = TTF_RenderText_Blended(deconst(), text.c_str(), fg_color_); 00343 } else if (encoding_ == UTF8) { 00344 s = TTF_RenderUTF8_Blended(deconst(), text.c_str(), fg_color_); 00345 } 00346 break; 00347 default: 00348 break; 00349 } 00350 00351 return Pixmap(s); 00352 }
Here is the call graph for this function:
bool Wt::Font::bold | ( | ) | const |
Definition at line 245 of file font.cpp.
References styleFlag().
00245 { 00246 return styleFlag(TTF_STYLE_BOLD); 00247 }
Here is the call graph for this function:
Rect Wt::Font::boundingRect | ( | const Uint16 | ch | ) | const |
Definition at line 432 of file font.cpp.
References deconst().
Referenced by Wt::Painter::boundingRect().
00432 { 00433 int minx, maxx, miny, maxy; 00434 TTF_GlyphMetrics(deconst(), ch, &minx, &maxx, &miny, &maxy, 0); 00435 return Rect(minx, miny, maxx - minx + 1, maxy - miny + 1); 00436 }
Here is the call graph for this function:
TTF_Font * Wt::Font::deconst | ( | ) | const [private] |
Definition at line 162 of file font.cpp.
Referenced by ascent(), blitText(), boundingRect(), descent(), faces(), faceStyleName(), family(), height(), leftBearing(), lineSpacing(), monoSpace(), rightBearing(), size(), style(), and width().
00162 { 00163 //SDL breakage 00164 return const_cast<TTF_Font *> 00165 (static_cast<const TTF_Font *>(*this)); 00166 }
Font & Wt::Font::defaultFont | ( | ) | [static] |
Definition at line 184 of file font.cpp.
References default_font.
00184 { 00185 return *default_font; 00186 }
Definition at line 180 of file font.cpp.
References DEFAULT_POINTSIZE.
00180 { 00181 return (ptsize) ? ptsize : DEFAULT_POINTSIZE; 00182 }
int Wt::Font::descent | ( | ) | const |
std::string Wt::Font::description | ( | ) | const |
Definition at line 188 of file font.cpp.
References Bold, filename_, Italic, pointSize(), style(), and Underline.
Referenced by Font(), init(), and Wt::operator<<().
00188 { 00189 std::string desc = filename_ + ", "; 00190 desc += boost::lexical_cast<std::string>(pointSize()) + ", "; 00191 00192 int st = style(); 00193 desc += (st & Bold) ? "b" : ""; 00194 desc += (st & Italic) ? "i" : ""; 00195 desc += (st & Underline) ? "u" : ""; 00196 return desc; 00197 }
Here is the call graph for this function:
void Wt::Font::detach | ( | ) | [protected] |
Definition at line 155 of file font.cpp.
References filename_, index_, open_font(), pointSize(), style(), and ttf_font.
Referenced by setBackgroundColor(), setEncoding(), setForegroundColor(), setRendering(), and setStyleFlag().
00155 { 00156 //avoid detaching if we are the only client for this font 00157 if (!ttf_font.unique()) { 00158 ttf_font = open_font(filename_, pointSize(), style(), index_); 00159 } 00160 }
Here is the call graph for this function:
int Wt::Font::encoding | ( | ) | const [protected] |
Definition at line 284 of file font.cpp.
References encoding_.
Referenced by setEncoding().
00284 { 00285 return encoding_; 00286 }
int Wt::Font::faces | ( | ) | const [protected] |
std::string Wt::Font::faceStyleName | ( | ) | const [protected] |
std::string Wt::Font::family | ( | ) | const |
const Color & Wt::Font::foregroundColor | ( | ) | const [protected] |
int Wt::Font::height | ( | ) | const |
void Wt::Font::init | ( | ) | [static] |
Definition at line 168 of file font.cpp.
References default_font, description(), and Font().
Referenced by Wt::Application::Application().
00168 { 00169 TTF_Init(); 00170 default_font = new Font(); 00171 map[default_font->description()] = *default_font; 00172 }
Here is the call graph for this function:
bool Wt::Font::italic | ( | ) | const |
Definition at line 253 of file font.cpp.
References styleFlag().
00253 { 00254 return styleFlag(TTF_STYLE_ITALIC); 00255 }
Here is the call graph for this function:
int Wt::Font::leading | ( | ) | const |
Definition at line 389 of file font.cpp.
References height(), and lineSpacing().
00389 { 00390 return lineSpacing() - height(); 00391 }
Here is the call graph for this function:
int Wt::Font::leftBearing | ( | Uint16 | ch | ) | const |
int Wt::Font::lineSpacing | ( | ) | const |
bool Wt::Font::monoSpace | ( | ) | const [protected] |
Definition at line 45 of file font.cpp.
References Wt::BultinFontData, Wt::BultinFontDataSize, default_font, and ttf_font.
Referenced by open_font().
00045 { 00046 if (!default_font) { 00047 SDL_RWops *rwop = SDL_RWFromConstMem(BultinFontData, 00048 BultinFontDataSize); 00049 return Ptr(TTF_OpenFontRW(rwop, true, ptsize), Deleter()); 00050 } 00051 return default_font->ttf_font; 00052 }
Font::Ptr Wt::Font::open_font | ( | const std::string & | filename, | |
int | ptsize, | |||
int | style, | |||
int | index = 0 | |||
) | [static, private] |
Definition at line 54 of file font.cpp.
References open_default_font(), and style().
Referenced by detach(), setFont(), and setPointSize().
00055 { 00056 Ptr f(TTF_OpenFontIndex(filename.c_str(), ptsize, index), Deleter()); 00057 if (!f) 00058 f = open_default_font(ptsize); 00059 00060 if (f) 00061 TTF_SetFontStyle(f.get(), style); 00062 return f; 00063 }
Here is the call graph for this function:
Wt::Font::operator const Ptr | ( | ) | const [inline, private] |
Wt::Font::operator const TTF_Font * | ( | ) | const [inline, private] |
Wt::Font::operator Ptr | ( | ) | [inline, private] |
Wt::Font::operator TTF_Font * | ( | ) | [inline, private] |
int Wt::Font::pointSize | ( | ) | const |
void Wt::Font::quit | ( | ) | [static] |
Definition at line 174 of file font.cpp.
References default_font.
Referenced by Wt::Application::~Application().
00174 { 00175 map.clear(); 00176 delete default_font; 00177 TTF_Quit(); 00178 }
int Wt::Font::rendering | ( | ) | const [protected] |
Definition at line 275 of file font.cpp.
References rendering_.
Referenced by setRendering().
00275 { 00276 return rendering_; 00277 }
int Wt::Font::rightBearing | ( | Uint16 | ch | ) | const |
void Wt::Font::setBackgroundColor | ( | const Color & | bg_color | ) | [protected] |
void Wt::Font::setBold | ( | bool | enable | ) |
Definition at line 249 of file font.cpp.
References setStyleFlag().
00249 { 00250 setStyleFlag(TTF_STYLE_BOLD, enable); 00251 }
Here is the call graph for this function:
void Wt::Font::setEncoding | ( | int | encoding | ) | [protected] |
void Wt::Font::setFont | ( | std::string & | filename | ) |
void Wt::Font::setForegroundColor | ( | const Color & | fg_color | ) | [protected] |
void Wt::Font::setItalic | ( | bool | enable | ) |
Definition at line 257 of file font.cpp.
References setStyleFlag().
00257 { 00258 setStyleFlag(TTF_STYLE_ITALIC, enable); 00259 }
Here is the call graph for this function:
void Wt::Font::setPointSize | ( | int | ptsize | ) |
void Wt::Font::setRendering | ( | int | rendering | ) | [protected] |
Definition at line 270 of file font.cpp.
References detach(), rendering(), and rendering_.
00270 { 00271 detach(); 00272 rendering_ = rendering; 00273 }
Here is the call graph for this function:
void Wt::Font::setStyleFlag | ( | int | flag, | |
bool | enable | |||
) | [protected] |
Definition at line 228 of file font.cpp.
References detach(), and style().
Referenced by setBold(), setItalic(), and setUnderline().
00228 { 00229 int s = style(); 00230 00231 if (enable && (flag & s)) 00232 return; 00233 00234 if (!enable && !(~flag & s)) 00235 return; 00236 00237 detach(); 00238 00239 if (enable) 00240 TTF_SetFontStyle(*this, flag | s); 00241 else 00242 TTF_SetFontStyle(*this, ~flag & s); 00243 }
Here is the call graph for this function:
void Wt::Font::setUnderline | ( | bool | enable | ) |
Definition at line 266 of file font.cpp.
References setStyleFlag().
00266 { 00267 setStyleFlag(TTF_STYLE_UNDERLINE, enable); 00268 }
Here is the call graph for this function:
Size Wt::Font::size | ( | const Uint16 * | text | ) | const |
Size Wt::Font::size | ( | const std::string & | text | ) | const |
Definition at line 306 of file font.cpp.
References ASCII, deconst(), encoding_, and UTF8.
00306 { 00307 int w = 0, h = 0; 00308 if (encoding_ == ASCII) { 00309 TTF_SizeText(deconst(), text.c_str(), &w, &h); 00310 } else if (encoding_ == UTF8) { 00311 TTF_SizeUTF8(deconst(), text.c_str(), &w, &h); 00312 } 00313 return Size(w, h); 00314 }
Here is the call graph for this function:
Size Wt::Font::size | ( | const Uint16 | ch | ) | const |
Definition at line 426 of file font.cpp.
References deconst().
Referenced by boundingRect(), Wt::Label::calc_size_hint(), Wt::PushButton::drawButtonLabel(), Wt::Label::drawContents(), and Wt::PushButton::setButtonSize().
00426 { 00427 int minx, maxx, miny, maxy; 00428 TTF_GlyphMetrics(deconst(), ch, &minx, &maxx, &miny, &maxy, 0); 00429 return Size(maxx - minx, maxy - miny); 00430 }
Here is the call graph for this function:
bool Wt::Font::style | ( | ) | const [protected] |
Definition at line 220 of file font.cpp.
References deconst().
Referenced by description(), detach(), open_font(), setFont(), setPointSize(), setStyleFlag(), and styleFlag().
00220 { 00221 return TTF_GetFontStyle(deconst()); 00222 }
Here is the call graph for this function:
bool Wt::Font::styleFlag | ( | int | flag | ) | const [protected] |
bool Wt::Font::underline | ( | ) | const |
Definition at line 261 of file font.cpp.
References styleFlag().
00261 { 00262 return styleFlag(TTF_STYLE_UNDERLINE); 00263 00264 }
Here is the call graph for this function:
int Wt::Font::width | ( | Uint16 | ch | ) | const |
Definition at line 420 of file font.cpp.
References deconst().
Referenced by Wt::Label::effectiveIndent().
00420 { 00421 int minx, maxx; 00422 TTF_GlyphMetrics(deconst(), ch, &minx, &maxx, 0, 0, 0); 00423 return maxx - minx; 00424 }
Here is the call graph for this function:
Color Wt::Font::bg_color_ [private] |
Definition at line 138 of file font.h.
Referenced by backgroundColor(), blitText(), and setBackgroundColor().
Font * Wt::Font::default_font = 0 [static, private] |
Definition at line 160 of file font.h.
Referenced by defaultFont(), init(), open_default_font(), and quit().
int Wt::Font::encoding_ [private] |
Definition at line 137 of file font.h.
Referenced by blitText(), encoding(), setEncoding(), and size().
Color Wt::Font::fg_color_ [private] |
Definition at line 139 of file font.h.
Referenced by blitText(), foregroundColor(), and setForegroundColor().
std::string Wt::Font::filename_ [private] |
Definition at line 133 of file font.h.
Referenced by description(), detach(), Font(), setFont(), and setPointSize().
int Wt::Font::index_ [private] |
Font::Map Wt::Font::map [static] |
int Wt::Font::ptsize_ [private] |
int Wt::Font::rendering_ [private] |
Ptr Wt::Font::ttf_font [private] |
Definition at line 132 of file font.h.
Referenced by detach(), Font(), open_default_font(), operator const Ptr(), operator const TTF_Font *(), operator Ptr(), operator TTF_Font *(), setFont(), and setPointSize().
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.