summaryrefslogtreecommitdiff
path: root/src/Font.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Font.cc')
-rw-r--r--src/Font.cc186
1 files changed, 0 insertions, 186 deletions
diff --git a/src/Font.cc b/src/Font.cc
deleted file mode 100644
index 8f683d9..0000000
--- a/src/Font.cc
+++ /dev/null
@@ -1,186 +0,0 @@
1// Font.cc
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: Font.cc,v 1.22 2002/11/25 14:07:21 fluxgen Exp $
23
24
25#include "Font.hh"
26#include "FontImp.hh"
27
28#ifdef HAVE_CONFIG_H
29#include "../config.h"
30#endif // HAVE_CONFIG_H
31
32// for antialias
33#ifdef USE_XFT
34#include "XftFontImp.hh"
35#endif // USE_XFT
36
37// for multibyte support
38#ifdef USE_XMB
39#include "XmbFontImp.hh"
40#endif //USE_XMB
41
42// standard font system
43#include "XFontImp.hh"
44
45#include "StringUtil.hh"
46
47//use gnu extensions
48#ifndef _GNU_SOURCE
49#define _GNU_SOURCE
50#endif //_GNU_SOURCE
51
52#ifndef __USE_GNU
53#define __USE_GNU
54#endif //__USE_GNU
55
56#include <iostream>
57#include <cstring>
58#include <cstdlib>
59using namespace std;
60
61#ifdef HAVE_SETLOCALE
62#include <locale.h>
63#endif //HAVE_SETLOCALE
64
65namespace FbTk {
66
67bool Font::m_multibyte = false;
68bool Font::m_utf8mode = false;
69
70Font::Font(const char *name, bool antialias):
71m_fontimp(0),
72m_antialias(false), m_rotated(false) {
73
74 // MB_CUR_MAX returns the size of a char in the current locale
75 if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte
76 m_multibyte = true;
77
78 char *s; // temporary string for enviroment variable
79 // check for utf-8 mode
80 if (((s = getenv("LC_ALL")) && *s) ||
81 ((s = getenv("LC_CTYPE")) && *s) ||
82 ((s = getenv("LANG")) && *s)) {
83 if (strstr(s, "UTF-8"))
84 m_utf8mode = true;
85 }
86
87 // create the right font implementation
88 // antialias is prio 1
89#ifdef USE_XFT
90 if (antialias) {
91 m_fontimp.reset(new XftFontImp(0, m_utf8mode));
92 m_antialias = true;
93 }
94#endif //USE_XFT
95 // if we didn't create a Xft font then create basic font
96 if (m_fontimp.get() == 0) {
97#ifdef USE_XMB
98 if (m_multibyte || m_utf8mode)
99 m_fontimp.reset(new XmbFontImp(0, m_utf8mode));
100 else // basic font implementation
101#endif // USE_XMB
102 m_fontimp.reset(new XFontImp());
103 }
104
105 if (name != 0) {
106 load(name);
107 }
108
109}
110
111Font::~Font() {
112
113}
114
115void Font::setAntialias(bool flag) {
116 bool loaded = m_fontimp->loaded();
117#ifdef USE_XFT
118 if (flag && !isAntialias() && !m_rotated) {
119 m_fontimp.reset(new XftFontImp(m_fontstr.c_str(), m_utf8mode));
120 } else if (!flag && isAntialias())
121#endif // USE_XFT
122 {
123#ifdef USE_XMB
124 if (m_multibyte || m_utf8mode)
125 m_fontimp.reset(new XmbFontImp(m_fontstr.c_str(), m_utf8mode));
126 else
127#endif // USE_XMB
128 m_fontimp.reset(new XFontImp(m_fontstr.c_str()));
129 }
130
131 if (m_fontimp->loaded() != loaded) { // if the new font failed to load, fall back to 'fixed'
132 if (!m_fontimp->load("fixed")) // if that failes too, output warning
133 cerr<<"Warning: can't load fallback font 'fixed'."<<endl;
134 }
135
136 m_antialias = flag;
137}
138
139bool Font::load(const char *name) {
140 if (name == 0)
141 return false;
142 m_fontstr = name;
143 return m_fontimp->load(name);
144}
145
146unsigned int Font::textWidth(const char * const text, unsigned int size) const {
147 return m_fontimp->textWidth(text, size);
148}
149
150unsigned int Font::height() const {
151 return m_fontimp->height();
152}
153
154int Font::ascent() const {
155 return m_fontimp->ascent();
156}
157
158int Font::descent() const {
159 return m_fontimp->descent();
160}
161void Font::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const {
162 if (text == 0 || len == 0)
163 return;
164 m_fontimp->drawText(w, screen, gc, text, len, x, y);
165}
166
167void Font::rotate(float angle) {
168#ifdef USE_XFT
169 // if we are rotated and we are changing to horiz text
170 // and we were antialiased before we rotated then change to XftFontImp
171 if (isRotated() && angle == 0 && isAntialias())
172 m_fontimp.reset(new XftFontImp(m_fontstr.c_str(), m_utf8mode));
173#endif // USE_XFT
174 // change to a font imp that handles rotated fonts (i.e just XFontImp at the moment)
175 // if we're going to rotate this font
176 if (angle != 0 && isAntialias() && !isRotated()) {
177 m_fontimp.reset(new XFontImp(m_fontstr.c_str()));
178 }
179
180 //Note: only XFontImp implements FontImp::rotate
181 m_fontimp->rotate(angle);
182
183 m_rotated = (angle == 0 ? false : true);
184}
185
186};