wmi

git clone git://oldgit.suckless.org/wmi/
Log | Files | Refs | LICENSE

xfont.cpp (1093B)


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