1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
… | |
… | |
163 | #define dTermDisplay Display *disp = term->dpy |
163 | #define dTermDisplay Display *disp = term->dpy |
164 | #define dTermGC GC gc = term->gc |
164 | #define dTermGC GC gc = term->gc |
165 | |
165 | |
166 | ///////////////////////////////////////////////////////////////////////////// |
166 | ///////////////////////////////////////////////////////////////////////////// |
167 | |
167 | |
168 | #if XFT |
|
|
169 | rxvt_drawable::~rxvt_drawable () |
|
|
170 | { |
|
|
171 | if (xftdrawable) |
|
|
172 | XftDrawDestroy (xftdrawable); |
|
|
173 | } |
|
|
174 | |
|
|
175 | rxvt_drawable::operator XftDraw *() |
|
|
176 | { |
|
|
177 | if (!xftdrawable) |
|
|
178 | xftdrawable = XftDrawCreate (screen->dpy, drawable, screen->visual, screen->cmap); |
|
|
179 | |
|
|
180 | return xftdrawable; |
|
|
181 | } |
|
|
182 | #endif |
|
|
183 | |
|
|
184 | ///////////////////////////////////////////////////////////////////////////// |
|
|
185 | |
|
|
186 | static const char * |
168 | static const char * |
187 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
169 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
188 | { |
170 | { |
189 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
171 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
190 | uint8_t *res = buf; |
172 | uint8_t *res = buf; |
… | |
… | |
250 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
232 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
251 | { |
233 | { |
252 | dTermDisplay; |
234 | dTermDisplay; |
253 | dTermGC; |
235 | dTermGC; |
254 | |
236 | |
255 | if (color == Color_bg) |
237 | if (color < 0 || color == Color_bg) |
256 | XClearArea (disp, d, x, y, w, h, false); |
238 | XClearArea (disp, d, x, y, w, h, false); |
257 | else if (color >= 0) |
239 | else |
258 | { |
240 | { |
259 | #if XFT |
241 | #if XFT |
260 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
242 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
261 | #else |
243 | #else |
262 | XSetForeground (disp, gc, term->pix_colors[color]); |
244 | XSetForeground (disp, gc, term->pix_colors[color]); |
… | |
… | |
1282 | void |
1264 | void |
1283 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1265 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1284 | const text_t *text, int len, |
1266 | const text_t *text, int len, |
1285 | int fg, int bg) |
1267 | int fg, int bg) |
1286 | { |
1268 | { |
1287 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
|
|
1288 | |
|
|
1289 | XGlyphInfo extents; |
1269 | XGlyphInfo extents; |
1290 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1270 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1291 | XftGlyphSpec *ep = enc; |
1271 | XftGlyphSpec *ep = enc; |
1292 | |
1272 | |
1293 | dTermDisplay; |
1273 | dTermDisplay; |
1294 | dTermGC; |
1274 | dTermGC; |
1295 | |
1275 | |
|
|
1276 | int w = term->fwidth * len; |
|
|
1277 | int h = term->fheight; |
|
|
1278 | |
|
|
1279 | bool buffered = bg >= 0 // we don't use a transparent bg |
|
|
1280 | #ifndef FORCE_UNBUFFERED_XFT |
|
|
1281 | # if defined(XPM_BACKGROUND) || defined(TRANSPARENT) |
|
|
1282 | || !term->am_transparent // we aren't transparent |
|
|
1283 | || term->am_pixmap_trans // we have a pixmap |
|
|
1284 | # endif |
|
|
1285 | #endif |
|
|
1286 | ; |
|
|
1287 | |
1296 | // cut trailing spaces |
1288 | // cut trailing spaces |
1297 | while (len && text [len - 1] == ' ') |
1289 | while (len && text [len - 1] == ' ') |
1298 | len--; |
1290 | len--; |
|
|
1291 | |
|
|
1292 | int x_ = buffered ? 0 : x; |
|
|
1293 | int y_ = buffered ? 0 : y; |
1299 | |
1294 | |
1300 | while (len) |
1295 | while (len) |
1301 | { |
1296 | { |
1302 | int cwidth = term->fwidth; |
1297 | int cwidth = term->fwidth; |
1303 | FcChar32 fc = *text++; len--; |
1298 | FcChar32 fc = *text++; len--; |
… | |
… | |
1309 | { |
1304 | { |
1310 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1305 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1311 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1306 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1312 | |
1307 | |
1313 | ep->glyph = glyph; |
1308 | ep->glyph = glyph; |
1314 | ep->x = x + (cwidth - extents.xOff >> 1); |
1309 | ep->x = x_ + (cwidth - extents.xOff >> 1); |
1315 | ep->y = y + ascent; |
1310 | ep->y = y_ + ascent; |
1316 | |
1311 | |
1317 | if (extents.xOff == 0) |
1312 | if (extents.xOff == 0) |
1318 | ep->x = x + cwidth; |
1313 | ep->x = x_ + cwidth; |
1319 | |
1314 | |
1320 | ep++; |
1315 | ep++; |
1321 | } |
1316 | } |
1322 | |
1317 | |
1323 | x += cwidth; |
1318 | x_ += cwidth; |
|
|
1319 | } |
|
|
1320 | |
|
|
1321 | if (buffered) |
1324 | } |
1322 | { |
1325 | |
|
|
1326 | if (ep != enc) |
1323 | if (ep != enc) |
|
|
1324 | { |
|
|
1325 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
|
|
1326 | |
|
|
1327 | #if defined(XPM_BACKGROUND) || defined(TRANSPARENT) |
|
|
1328 | if (bg < 0 && term->am_pixmap_trans) |
|
|
1329 | XCopyArea (disp, term->pixmap, d2, gc, |
|
|
1330 | x + term->window_vt_x, y + term->window_vt_y, |
|
|
1331 | w, h, 0, 0); |
|
|
1332 | else if (bg < 0 && term->bgPixmap.pixmap) |
|
|
1333 | { |
|
|
1334 | XGCValues gcv; |
|
|
1335 | |
|
|
1336 | gcv.fill_style = FillTiled; |
|
|
1337 | gcv.tile = term->pixmap; |
|
|
1338 | gcv.ts_x_origin = -x; |
|
|
1339 | gcv.ts_y_origin = -y; |
|
|
1340 | |
|
|
1341 | GC gc2 = XCreateGC (disp, d2, |
|
|
1342 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
|
|
1343 | &gcv); |
|
|
1344 | |
|
|
1345 | XFillRectangle (disp, d2, gc2, 0, 0, w, h); |
|
|
1346 | |
|
|
1347 | XFreeGC (disp, gc2); |
|
|
1348 | } |
|
|
1349 | else |
|
|
1350 | #endif |
|
|
1351 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
|
|
1352 | |
|
|
1353 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1354 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
|
|
1355 | } |
|
|
1356 | else |
|
|
1357 | clear_rect (d, x, y, w, h, bg); |
|
|
1358 | } |
|
|
1359 | else |
|
|
1360 | { |
|
|
1361 | clear_rect (d, x, y, w, h, bg); |
1327 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1362 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1363 | } |
1328 | } |
1364 | } |
|
|
1365 | |
1329 | #endif |
1366 | #endif |
1330 | |
1367 | |
1331 | ///////////////////////////////////////////////////////////////////////////// |
1368 | ///////////////////////////////////////////////////////////////////////////// |
1332 | |
1369 | |
1333 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1370 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |