xftfont.cpp (1159B)
1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us> 2 // See LICENSE for license details. 3 4 #include "xftfont.h" 5 6 #ifdef XFT_SUPPORT 7 8 extern "C" { 9 #include <X11/Xlib.h> 10 } 11 12 #include "monitor.h" 13 #include "xcore.h" 14 15 WXftFont::WXftFont(Monitor *monitor, XftFont *font) : 16 WFont(monitor) 17 { 18 font_ = font; 19 type_ = WFont::XFT; 20 } 21 22 WXftFont *WXftFont::load(Monitor *monitor, string name) { 23 24 XftFont *font = XCORE->xftOpenFontName(monitor->id(), name); 25 26 WXftFont *result = 0; 27 if (font) { 28 result = new WXftFont(monitor, font); 29 result->setHeight(font->height); 30 } 31 return result; 32 } 33 34 WXftFont::~WXftFont() { 35 XCORE->xftCloseFont(font_); 36 } 37 38 int WXftFont::textWidth(string text) { 39 return XCORE->textWidth(font_, text); 40 } 41 42 unsigned int WXftFont::height() { 43 return height_; 44 } 45 46 void WXftFont::setHeight(unsigned int height) { 47 height_ = height; 48 } 49 50 void WXftFont::drawText(Window window, GC gc, int x, int y, string text) { 51 XCORE->drawText(font_, window, gc, monitor_->id(), x, y, text); 52 } 53 54 int WXftFont::ascent() { 55 return font_->ascent; 56 } 57 58 int WXftFont::descent() { 59 return font_->descent; 60 } 61 62 #endif