aboutsummaryrefslogtreecommitdiff
path: root/src/XftFontImp.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-11-26 15:57:11 (GMT)
committerfluxgen <fluxgen>2002-11-26 15:57:11 (GMT)
commitb5acf3a78f51e9fb1503f82e2235d98694328a67 (patch)
treea003883b85909bc1e1d20d30e1e2d98f8df6e470 /src/XftFontImp.cc
parentfe2e6b32e7fd285a32d5210220e18da9abb7732f (diff)
downloadfluxbox-b5acf3a78f51e9fb1503f82e2235d98694328a67.zip
fluxbox-b5acf3a78f51e9fb1503f82e2235d98694328a67.tar.bz2
moved to FbTk
Diffstat (limited to 'src/XftFontImp.cc')
-rw-r--r--src/XftFontImp.cc140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/XftFontImp.cc b/src/XftFontImp.cc
deleted file mode 100644
index 5104ce0..0000000
--- a/src/XftFontImp.cc
+++ /dev/null
@@ -1,140 +0,0 @@
1// XftFontImp.cc Xft font implementation for FbTk
2// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22//$Id: XftFontImp.cc,v 1.4 2002/11/17 17:20:49 fluxgen Exp $
23
24#include "XftFontImp.hh"
25#include "BaseDisplay.hh"
26
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif //HAVE_CONFIG_H
30
31XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0),
32m_utf8mode(utf8) {
33 if (name != 0)
34 load(name);
35}
36
37XftFontImp::~XftFontImp() {
38 if (m_xftfont != 0)
39 XftFontClose(BaseDisplay::getXDisplay(), m_xftfont);
40}
41
42bool XftFontImp::load(const std::string &name) {
43 //Note: assumes screen 0 for now, changes on draw if needed
44
45 Display *disp = BaseDisplay::getXDisplay();
46 XftFont *newxftfont = XftFontOpenName(disp, 0, name.c_str());
47
48 if (newxftfont == 0) { // failed to open font, lets test with XLFD
49 newxftfont = XftFontOpenXlfd(disp, 0, name.c_str());
50 if (newxftfont == 0)
51 return false;
52 }
53 // destroy old font and set new
54 if (m_xftfont != 0)
55 XftFontClose(disp, m_xftfont);
56
57 m_xftfont = newxftfont;
58
59 return true;
60}
61
62void XftFontImp::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const {
63 if (m_xftfont == 0)
64 return;
65 Display *disp = BaseDisplay::getXDisplay();
66 XftDraw *draw = XftDrawCreate(disp,
67 w,
68 DefaultVisual(disp, screen),
69 DefaultColormap(disp, screen));
70
71 XGCValues gc_val;
72
73 // get foreground pixel value and convert it to XRenderColor value
74 // TODO: we should probably check return status
75 XGetGCValues(disp, gc, GCForeground, &gc_val);
76
77 // get red, green, blue values
78 XColor xcol;
79 xcol.pixel = gc_val.foreground;
80 XQueryColor(disp, DefaultColormap(disp, screen), &xcol);
81
82 // convert xcolor to XftColor
83 XRenderColor rendcol;
84 rendcol.red = xcol.red;
85 rendcol.green = xcol.green;
86 rendcol.blue = xcol.blue;
87 rendcol.alpha = 0xFFFF;
88 XftColor xftcolor;
89 XftColorAllocValue(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen),
90 &rendcol, &xftcolor);
91
92 // draw string
93#ifdef HAVE_XFT_UTF8_STRING
94 if (m_utf8mode) {
95 XftDrawStringUtf8(draw,
96 &xftcolor,
97 m_xftfont,
98 x, y,
99 (XftChar8 *)(text), len);
100 } else
101#endif // HAVE_XFT_UTF8_STRING
102 {
103 XftDrawString8(draw,
104 &xftcolor,
105 m_xftfont,
106 x, y,
107 (XftChar8 *)(text), len);
108 }
109
110 XftColorFree(disp, DefaultVisual(disp, screen),
111 DefaultColormap(disp, screen), &xftcolor);
112 XftDrawDestroy(draw);
113}
114
115unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) const {
116 if (m_xftfont == 0)
117 return 0;
118 XGlyphInfo ginfo;
119#ifdef HAVE_XFT_UTF8_STRING
120 if (m_utf8mode) {
121 XftTextExtentsUtf8(BaseDisplay::getXDisplay(),
122 m_xftfont,
123 (XftChar8 *)text, len,
124 &ginfo);
125 } else
126#endif //HAVE_XFT_UTF8_STRING
127 {
128 XftTextExtents8(BaseDisplay::getXDisplay(),
129 m_xftfont,
130 (XftChar8 *)text, len,
131 &ginfo);
132 }
133 return ginfo.xOff;
134}
135
136unsigned int XftFontImp::height() const {
137 if (m_xftfont == 0)
138 return 0;
139 return m_xftfont->height;
140}