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.cc55
1 files changed, 19 insertions, 36 deletions
diff --git a/src/FbTk/XftFontImp.cc b/src/FbTk/XftFontImp.cc
index 80eb2c4..15c8212 100644
--- a/src/FbTk/XftFontImp.cc
+++ b/src/FbTk/XftFontImp.cc
@@ -77,7 +77,10 @@ bool XftFontImp::load(const std::string &name) {
77 return true; 77 return true;
78} 78}
79 79
80void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) { 80void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char* text, size_t len, int x, int y, FbTk::Orientation orient) {
81
82 if (!text || !*text)
83 return;
81 84
82 if (!validOrientation(orient)) 85 if (!validOrientation(orient))
83 return; 86 return;
@@ -98,12 +101,11 @@ void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString
98 break; 101 break;
99 } 102 }
100 103
101 XftFont *font = m_xftfonts[orient]; 104 Visual* def_visual = DefaultVisual(w.display(), screen);
105 Colormap def_colmap = DefaultColormap(w.display(), screen);
102 106
103 XftDraw *draw = XftDrawCreate(w.display(), 107 XftFont *font = m_xftfonts[orient];
104 w.drawable(), 108 XftDraw *draw = XftDrawCreate(w.display(), w.drawable(), def_visual, def_colmap);
105 DefaultVisual(w.display(), screen),
106 DefaultColormap(w.display(), screen));
107 109
108 XGCValues gc_val; 110 XGCValues gc_val;
109 111
@@ -114,7 +116,7 @@ void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString
114 // get red, green, blue values 116 // get red, green, blue values
115 XColor xcol; 117 XColor xcol;
116 xcol.pixel = gc_val.foreground; 118 xcol.pixel = gc_val.foreground;
117 XQueryColor(w.display(), DefaultColormap(w.display(), screen), &xcol); 119 XQueryColor(w.display(), def_colmap, &xcol);
118 120
119 // convert xcolor to XftColor 121 // convert xcolor to XftColor
120 XRenderColor rendcol; 122 XRenderColor rendcol;
@@ -123,10 +125,7 @@ void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString
123 rendcol.blue = xcol.blue; 125 rendcol.blue = xcol.blue;
124 rendcol.alpha = 0xFFFF; 126 rendcol.alpha = 0xFFFF;
125 XftColor xftcolor; 127 XftColor xftcolor;
126 XftColorAllocValue(w.display(), 128 XftColorAllocValue(w.display(), def_visual, def_colmap, &rendcol, &xftcolor);
127 DefaultVisual(w.display(), screen),
128 DefaultColormap(w.display(), screen),
129 &rendcol, &xftcolor);
130 129
131 // draw string 130 // draw string
132#ifdef HAVE_XFT_UTF8_STRING 131#ifdef HAVE_XFT_UTF8_STRING
@@ -134,39 +133,25 @@ void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString
134 // check the string size, 133 // check the string size,
135 // if the size is zero we use the XftDrawString8 function instead. 134 // if the size is zero we use the XftDrawString8 function instead.
136 XGlyphInfo ginfo; 135 XGlyphInfo ginfo;
137 XftTextExtentsUtf8(w.display(), 136 XftTextExtentsUtf8(w.display(), m_xftfonts[ROT0], (XftChar8 *)text, len, &ginfo);
138 m_xftfonts[ROT0],
139 (XftChar8 *)text.data(), len,
140 &ginfo);
141 if (ginfo.xOff != 0) { 137 if (ginfo.xOff != 0) {
142 XftDrawStringUtf8(draw, 138 XftDrawStringUtf8(draw, &xftcolor, font, x, y, (XftChar8 *)text, len);
143 &xftcolor, 139 XftColorFree(w.display(), def_visual, def_colmap, &xftcolor);
144 font,
145 x, y,
146 (XftChar8 *)(text.data()), len);
147 XftColorFree(w.display(),
148 DefaultVisual(w.display(), screen),
149 DefaultColormap(w.display(), screen), &xftcolor);
150 XftDrawDestroy(draw); 140 XftDrawDestroy(draw);
151 return; 141 return;
152 } 142 }
153 } 143 }
154#endif // HAVE_XFT_UTF8_STRING 144#endif // HAVE_XFT_UTF8_STRING
155 145
156 XftDrawString8(draw, 146 XftDrawString8(draw, &xftcolor, font, x, y, (XftChar8 *)text, len);
157 &xftcolor,
158 font,
159 x, y,
160 (XftChar8 *)(text.data()), len);
161 147
162 148
163 XftColorFree(w.display(), 149 XftColorFree(w.display(), def_visual, def_colmap, &xftcolor);
164 DefaultVisual(w.display(), screen),
165 DefaultColormap(w.display(), screen), &xftcolor);
166 XftDrawDestroy(draw); 150 XftDrawDestroy(draw);
167} 151}
168 152
169unsigned int XftFontImp::textWidth(const FbString &text, unsigned int len) const { 153unsigned int XftFontImp::textWidth(const char* text, unsigned int len) const {
154
170 if (m_xftfonts[ROT0] == 0) 155 if (m_xftfonts[ROT0] == 0)
171 return 0; 156 return 0;
172 157
@@ -180,7 +165,7 @@ unsigned int XftFontImp::textWidth(const FbString &text, unsigned int len) const
180 if (m_utf8mode) { 165 if (m_utf8mode) {
181 XftTextExtentsUtf8(disp, 166 XftTextExtentsUtf8(disp,
182 font, 167 font,
183 (XftChar8 *)text.data(), len, 168 (XftChar8 *)text, len,
184 &ginfo); 169 &ginfo);
185 if (ginfo.xOff != 0) 170 if (ginfo.xOff != 0)
186 return ginfo.xOff; 171 return ginfo.xOff;
@@ -189,9 +174,7 @@ unsigned int XftFontImp::textWidth(const FbString &text, unsigned int len) const
189 } 174 }
190#endif //HAVE_XFT_UTF8_STRING 175#endif //HAVE_XFT_UTF8_STRING
191 176
192 std::string localestr = text; 177 std::string localestr = FbStringUtil::FbStrToLocale(FbString(text, len));
193 localestr.erase(len, std::string::npos);
194 localestr = FbStringUtil::FbStrToLocale(localestr);
195 178
196 XftTextExtents8(disp, 179 XftTextExtents8(disp,
197 font, 180 font,