aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/XftFontImp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/XftFontImp.cc')
-rw-r--r--src/FbTk/XftFontImp.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/FbTk/XftFontImp.cc b/src/FbTk/XftFontImp.cc
index 15c8212..9e57349 100644
--- a/src/FbTk/XftFontImp.cc
+++ b/src/FbTk/XftFontImp.cc
@@ -23,7 +23,9 @@
23#include "App.hh" 23#include "App.hh"
24#include "FbDrawable.hh" 24#include "FbDrawable.hh"
25 25
26#include <math.h> 26#include <cmath>
27#include <cstdio>
28#include <algorithm>
27 29
28#ifdef HAVE_CONFIG_H 30#ifdef HAVE_CONFIG_H
29#include "config.h" 31#include "config.h"
@@ -32,7 +34,7 @@
32namespace FbTk { 34namespace FbTk {
33 35
34XftFontImp::XftFontImp(const char *name, bool utf8): 36XftFontImp::XftFontImp(const char *name, bool utf8):
35 m_utf8mode(utf8), m_name("") { 37 m_utf8mode(utf8), m_name(""), m_maxlength(0x8000) {
36 38
37 for (int r = ROT0; r <= ROT270; r++) { 39 for (int r = ROT0; r <= ROT270; r++) {
38 m_xftfonts[r] = 0; 40 m_xftfonts[r] = 0;
@@ -74,6 +76,15 @@ bool XftFontImp::load(const std::string &name) {
74 m_xftfonts_loaded[ROT0] = true; 76 m_xftfonts_loaded[ROT0] = true;
75 m_name = name; 77 m_name = name;
76 78
79 // XGlyphInfo (used by XftFontImp::textWidth() / XftTextExtents8() etc)
80 // holds only type 'short' or 'unsigned short'. any text bigger than that
81 // yields either some negative or some 'wrapped' values ('integer
82 // overflow'). to prevent something like this we detect the maximium
83 // number of glyphs by calculating the amount of 'WW' (pretending a 'wide'
84 // glyph) fitting into 32k pixels
85 unsigned int tw = textWidth("WW", 2);
86 m_maxlength = 0x8000 / tw;
87
77 return true; 88 return true;
78} 89}
79 90
@@ -160,6 +171,8 @@ unsigned int XftFontImp::textWidth(const char* text, unsigned int len) const {
160 171
161 XftFont *font = m_xftfonts[ROT0]; 172 XftFont *font = m_xftfonts[ROT0];
162 173
174 len = std::min(len, m_maxlength);
175
163 176
164#ifdef HAVE_XFT_UTF8_STRING 177#ifdef HAVE_XFT_UTF8_STRING
165 if (m_utf8mode) { 178 if (m_utf8mode) {