aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2006-06-06 03:52:51 +0000
committerKenichi Handa2006-06-06 03:52:51 +0000
commitc9ff09ee7343af7ed488fd4a3c9e13e064c98d6f (patch)
treede49611d93b54d025cd85ba2309e1173fb597fc3 /src
parent426b211949af62dfd0a198aba19aecbf9b3f2b10 (diff)
downloademacs-c9ff09ee7343af7ed488fd4a3c9e13e064c98d6f.tar.gz
emacs-c9ff09ee7343af7ed488fd4a3c9e13e064c98d6f.zip
Include "font.h".
(x_set_mouse_face_gc, x_set_glyph_string_clipping) (x_set_glyph_string_clipping_exactly) (x_compute_glyph_string_overhangs) (x_draw_glyph_string_foreground) (x_draw_composite_glyph_string_foreground, x_draw_glyph_string) (x_free_frame_resources) [USE_FONT_BACKEND]: If enable_font_backend is nonzero, use font-backend mechanism. (x_new_fontset2) [USE_FONT_BACKEND]: New function.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c253
1 files changed, 250 insertions, 3 deletions
diff --git a/src/xterm.c b/src/xterm.c
index d58839db09f..c25f23cc573 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -102,6 +102,10 @@ Boston, MA 02110-1301, USA. */
102#include "gtkutil.h" 102#include "gtkutil.h"
103#endif 103#endif
104 104
105#ifdef USE_FONT_BACKEND
106#include "font.h"
107#endif /* USE_FONT_BACKEND */
108
105#ifdef USE_LUCID 109#ifdef USE_LUCID
106extern int xlwmenu_window_p P_ ((Widget w, Window window)); 110extern int xlwmenu_window_p P_ ((Widget w, Window window));
107extern void xlwmenu_redisplay P_ ((Widget)); 111extern void xlwmenu_redisplay P_ ((Widget));
@@ -1076,6 +1080,11 @@ x_set_mouse_face_gc (s)
1076 /* If font in this face is same as S->font, use it. */ 1080 /* If font in this face is same as S->font, use it. */
1077 if (s->font == s->face->font) 1081 if (s->font == s->face->font)
1078 s->gc = s->face->gc; 1082 s->gc = s->face->gc;
1083#ifdef USE_FONT_BACKEND
1084 else if (enable_font_backend)
1085 /* No need of setting a font for s->gc. */
1086 s->gc = s->face->gc;
1087#endif /* USE_FONT_BACKEND */
1079 else 1088 else
1080 { 1089 {
1081 /* Otherwise construct scratch_cursor_gc with values from FACE 1090 /* Otherwise construct scratch_cursor_gc with values from FACE
@@ -1173,6 +1182,10 @@ x_set_glyph_string_clipping (s)
1173 XRectangle r; 1182 XRectangle r;
1174 get_glyph_string_clip_rect (s, &r); 1183 get_glyph_string_clip_rect (s, &r);
1175 XSetClipRectangles (s->display, s->gc, 0, 0, &r, 1, Unsorted); 1184 XSetClipRectangles (s->display, s->gc, 0, 0, &r, 1, Unsorted);
1185#ifdef USE_FONT_BACKEND
1186 s->clip_x = r.x, s->clip_y = r.y;
1187 s->clip_width = r.width, s->clip_height = r.height;
1188#endif /* USE_FONT_BACKEND */
1176} 1189}
1177 1190
1178 1191
@@ -1185,6 +1198,18 @@ x_set_glyph_string_clipping_exactly (src, dst)
1185 struct glyph_string *src, *dst; 1198 struct glyph_string *src, *dst;
1186{ 1199{
1187 XRectangle r; 1200 XRectangle r;
1201
1202#ifdef USE_FONT_BACKEND
1203 if (enable_font_backend)
1204 {
1205 r.x = dst->clip_x = src->x;
1206 r.width = dst->clip_width = src->clip_width;
1207 r.y = dst->clip_y = src->clip_y;
1208 r.height = dst->clip_height = src->clip_height;
1209 }
1210 else
1211 {
1212#endif /* USE_FONT_BACKEND */
1188 struct glyph_string *clip_head = src->clip_head; 1213 struct glyph_string *clip_head = src->clip_head;
1189 struct glyph_string *clip_tail = src->clip_tail; 1214 struct glyph_string *clip_tail = src->clip_tail;
1190 1215
@@ -1192,6 +1217,9 @@ x_set_glyph_string_clipping_exactly (src, dst)
1192 src->clip_head = src->clip_tail = src; 1217 src->clip_head = src->clip_tail = src;
1193 get_glyph_string_clip_rect (src, &r); 1218 get_glyph_string_clip_rect (src, &r);
1194 src->clip_head = clip_head, src->clip_tail = clip_tail; 1219 src->clip_head = clip_head, src->clip_tail = clip_tail;
1220#ifdef USE_FONT_BACKEND
1221 }
1222#endif /* USE_FONT_BACKEND */
1195 XSetClipRectangles (dst->display, dst->gc, 0, 0, &r, 1, Unsorted); 1223 XSetClipRectangles (dst->display, dst->gc, 0, 0, &r, 1, Unsorted);
1196} 1224}
1197 1225
@@ -1208,6 +1236,24 @@ x_compute_glyph_string_overhangs (s)
1208 { 1236 {
1209 XCharStruct cs; 1237 XCharStruct cs;
1210 int direction, font_ascent, font_descent; 1238 int direction, font_ascent, font_descent;
1239
1240#ifdef USE_FONT_BACKEND
1241 if (enable_font_backend)
1242 {
1243 unsigned *code = alloca (sizeof (unsigned) * s->nchars);
1244 struct font *font = (struct font *) s->font_info;
1245 struct font_metrics metrics;
1246 int i;
1247
1248 for (i = 0; i < s->nchars; i++)
1249 code[i] = (s->char2b[i].byte1 << 8) | s->char2b[i].byte2;
1250 font->driver->text_extents (font, code, s->nchars, &metrics);
1251 cs.rbearing = metrics.rbearing;
1252 cs.lbearing = metrics.lbearing;
1253 cs.width = metrics.width;
1254 }
1255 else
1256#endif /* USE_FONT_BACKEND */
1211 XTextExtents16 (s->font, s->char2b, s->nchars, &direction, 1257 XTextExtents16 (s->font, s->char2b, s->nchars, &direction,
1212 &font_ascent, &font_descent, &cs); 1258 &font_ascent, &font_descent, &cs);
1213 s->right_overhang = cs.rbearing > cs.width ? cs.rbearing - cs.width : 0; 1259 s->right_overhang = cs.rbearing > cs.width ? cs.rbearing - cs.width : 0;
@@ -1307,6 +1353,30 @@ x_draw_glyph_string_foreground (s)
1307 x += g->pixel_width; 1353 x += g->pixel_width;
1308 } 1354 }
1309 } 1355 }
1356#ifdef USE_FONT_BACKEND
1357 else if (enable_font_backend)
1358 {
1359 unsigned *code = alloca (sizeof (unsigned) * s->nchars);
1360 int boff = s->font_info->baseline_offset;
1361 struct font *font = (struct font *) s->font_info;
1362 int y;
1363
1364 for (i = 0; i < s->nchars; i++)
1365 code[i] = (s->char2b[i].byte1 << 8) | s->char2b[i].byte2;
1366
1367 if (s->font_info->vertical_centering)
1368 boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
1369
1370 y = s->ybase - boff;
1371 if (s->for_overlaps
1372 || (s->background_filled_p && s->hl != DRAW_CURSOR))
1373 font->driver->draw (s, 0, s->nchars, x, y, 0);
1374 else
1375 font->driver->draw (s, 0, s->nchars, x, y, 1);
1376 if (s->face->overstrike)
1377 font->driver->draw (s, 0, s->nchars, x + 1, y, 0);
1378 }
1379#endif /* USE_FONT_BACKEND */
1310 else 1380 else
1311 { 1381 {
1312 char *char1b = (char *) s->char2b; 1382 char *char1b = (char *) s->char2b;
@@ -1389,6 +1459,60 @@ x_draw_composite_glyph_string_foreground (s)
1389 XDrawRectangle (s->display, s->window, s->gc, x, s->y, 1459 XDrawRectangle (s->display, s->window, s->gc, x, s->y,
1390 s->width - 1, s->height - 1); 1460 s->width - 1, s->height - 1);
1391 } 1461 }
1462#ifdef USE_FONT_BACKEND
1463 else if (enable_font_backend)
1464 {
1465 struct font *font = (struct font *) s->font_info;
1466 int y = s->ybase;
1467 int width = 0;
1468
1469 if (s->cmp->method == COMPOSITION_WITH_GLYPH_STRING)
1470 {
1471 Lisp_Object gstring = AREF (XHASH_TABLE (composition_hash_table)
1472 ->key_and_value,
1473 s->cmp->hash_index * 2);
1474 int from;
1475
1476 for (i = from = 0; i < s->nchars; i++)
1477 {
1478 Lisp_Object g = LGSTRING_GLYPH (gstring, i);
1479
1480 if (XINT (LGLYPH_XOFF (4)) == 0 && XINT (LGLYPH_YOFF (g)) == 0
1481 && XINT (LGLYPH_WADJUST (g)) == 0)
1482 {
1483 width += XINT (LGLYPH_WIDTH (g));
1484 continue;
1485 }
1486 if (from < i)
1487 {
1488 font->driver->draw (s, from, i, x, y, 0);
1489 x += width;
1490 }
1491 font->driver->draw (s, i, i + 1,
1492 x + XINT (LGLYPH_XOFF (g)),
1493 y + XINT (LGLYPH_XOFF (g)),
1494 0);
1495 x += XINT (LGLYPH_WIDTH (g)) + XINT (LGLYPH_WADJUST (g));
1496 from = i + 1;
1497 width = 0;
1498 }
1499 if (from < i)
1500 font->driver->draw (s, from, i, x, y, 0);
1501 }
1502 else
1503 {
1504 for (i = 0; i < s->nchars; i++, ++s->gidx)
1505 {
1506 int xx = x + s->cmp->offsets[s->gidx * 2];
1507 int yy = y - s->cmp->offsets[s->gidx * 2 + 1];
1508
1509 font->driver->draw (s, i, i + 1, xx, yy, 0);
1510 if (s->face->overstrike)
1511 font->driver->draw (s, i, i + 1, xx + 1, yy, 0);
1512 }
1513 }
1514 }
1515#endif /* USE_FONT_BACKEND */
1392 else 1516 else
1393 { 1517 {
1394 for (i = 0; i < s->nchars; i++, ++s->gidx) 1518 for (i = 0; i < s->nchars; i++, ++s->gidx)
@@ -2643,6 +2767,9 @@ x_draw_glyph_string (s)
2643 x_set_glyph_string_gc (next); 2767 x_set_glyph_string_gc (next);
2644 x_set_glyph_string_clipping (next); 2768 x_set_glyph_string_clipping (next);
2645 x_draw_glyph_string_background (next, 1); 2769 x_draw_glyph_string_background (next, 1);
2770#ifdef USE_FONT_BACKEND
2771 next->clip_width = 0;
2772#endif /* USE_FONT_BACKEND */
2646 } 2773 }
2647 } 2774 }
2648 2775
@@ -2711,6 +2838,12 @@ x_draw_glyph_string (s)
2711 int y; 2838 int y;
2712 2839
2713 /* Get the underline thickness. Default is 1 pixel. */ 2840 /* Get the underline thickness. Default is 1 pixel. */
2841#ifdef USE_FONT_BACKEND
2842 if (enable_font_backend)
2843 /* In the future, we must use information of font. */
2844 h = 1;
2845 else
2846#endif /* USE_FONT_BACKEND */
2714 if (!XGetFontProperty (s->font, XA_UNDERLINE_THICKNESS, &h)) 2847 if (!XGetFontProperty (s->font, XA_UNDERLINE_THICKNESS, &h))
2715 h = 1; 2848 h = 1;
2716 2849
@@ -2722,6 +2855,12 @@ x_draw_glyph_string (s)
2722 ROUND ((maximum descent) / 2), with 2855 ROUND ((maximum descent) / 2), with
2723 ROUND(x) = floor (x + 0.5) */ 2856 ROUND(x) = floor (x + 0.5) */
2724 2857
2858#ifdef USE_FONT_BACKEND
2859 if (enable_font_backend)
2860 /* In the future, we must use information of font. */
2861 y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
2862 else
2863#endif
2725 if (x_use_underline_position_properties 2864 if (x_use_underline_position_properties
2726 && XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &tem)) 2865 && XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &tem))
2727 y = s->ybase + (long) tem; 2866 y = s->ybase + (long) tem;
@@ -2802,9 +2941,15 @@ x_draw_glyph_string (s)
2802 prev->hl = s->hl; 2941 prev->hl = s->hl;
2803 x_set_glyph_string_gc (prev); 2942 x_set_glyph_string_gc (prev);
2804 x_set_glyph_string_clipping_exactly (s, prev); 2943 x_set_glyph_string_clipping_exactly (s, prev);
2805 x_draw_glyph_string_foreground (prev); 2944 if (prev->first_glyph->type == CHAR_GLYPH)
2945 x_draw_glyph_string_foreground (prev);
2946 else
2947 x_draw_composite_glyph_string_foreground (prev);
2806 XSetClipMask (prev->display, prev->gc, None); 2948 XSetClipMask (prev->display, prev->gc, None);
2807 prev->hl = save; 2949 prev->hl = save;
2950#ifdef USE_FONT_BACKEND
2951 prev->clip_width = 0;
2952#endif /* USE_FONT_BACKEND */
2808 } 2953 }
2809 } 2954 }
2810 2955
@@ -2814,7 +2959,7 @@ x_draw_glyph_string (s)
2814 2959
2815 for (next = s->next; next; next = next->next) 2960 for (next = s->next; next; next = next->next)
2816 if (next->hl != s->hl 2961 if (next->hl != s->hl
2817 && next->x - next->left_overhang && s->next->hl != s->hl) 2962 && next->x - next->left_overhang < s->x + s->width)
2818 { 2963 {
2819 /* As next will be drawn while clipped to its own area, 2964 /* As next will be drawn while clipped to its own area,
2820 we must draw the left_overhang part using s->hl now. */ 2965 we must draw the left_overhang part using s->hl now. */
@@ -2823,15 +2968,24 @@ x_draw_glyph_string (s)
2823 next->hl = s->hl; 2968 next->hl = s->hl;
2824 x_set_glyph_string_gc (next); 2969 x_set_glyph_string_gc (next);
2825 x_set_glyph_string_clipping_exactly (s, next); 2970 x_set_glyph_string_clipping_exactly (s, next);
2826 x_draw_glyph_string_foreground (next); 2971 if (next->first_glyph->type == CHAR_GLYPH)
2972 x_draw_glyph_string_foreground (next);
2973 else
2974 x_draw_composite_glyph_string_foreground (next);
2827 XSetClipMask (next->display, next->gc, None); 2975 XSetClipMask (next->display, next->gc, None);
2828 next->hl = save; 2976 next->hl = save;
2977#ifdef USE_FONT_BACKEND
2978 next->clip_width = 0;
2979#endif /* USE_FONT_BACKEND */
2829 } 2980 }
2830 } 2981 }
2831 } 2982 }
2832 2983
2833 /* Reset clipping. */ 2984 /* Reset clipping. */
2834 XSetClipMask (s->display, s->gc, None); 2985 XSetClipMask (s->display, s->gc, None);
2986#ifdef USE_FONT_BACKEND
2987 s->clip_width = 0;
2988#endif /* USE_FONT_BACKEND */
2835} 2989}
2836 2990
2837/* Shift display to make room for inserted glyphs. */ 2991/* Shift display to make room for inserted glyphs. */
@@ -8007,6 +8161,90 @@ x_new_fontset (f, fontsetname)
8007 return fontset_name (fontset); 8161 return fontset_name (fontset);
8008} 8162}
8009 8163
8164#ifdef USE_FONT_BACKEND
8165Lisp_Object
8166x_new_fontset2 (f, fontsetname)
8167 struct frame *f;
8168 Lisp_Object fontsetname;
8169{
8170 int fontset;
8171 struct font *font;
8172 XFontStruct *xfont;
8173
8174 if (STRINGP (fontsetname))
8175 {
8176 fontset = fs_query_fontset (fontsetname, 0);
8177 if (fontset > 0 && f->output_data.x->fontset == fontset)
8178 /* This fontset is already set in frame F. There's nothing more
8179 to do. */
8180 return fontset_name (fontset);
8181 if (fontset == 0)
8182 /* The default fontset can't be the default font. */
8183 return Qt;
8184 if (fontset < 0)
8185 fontset = new_fontset_from_font_name (fontsetname);
8186 }
8187 else
8188 fontset = new_fontset_from_font (f, fontsetname);
8189
8190 if (fontset < 0)
8191 return Qnil;
8192
8193 font = fontset_ascii_font (f, fontset);
8194 xfont = font->font.font;
8195
8196 if (FRAME_FONT (f) == xfont)
8197 /* This font is already set in frame F. There's nothing more to
8198 do. */
8199 return fontset_name (fontset);
8200
8201 BLOCK_INPUT;
8202
8203 FRAME_FONT (f) = xfont;
8204 FRAME_BASELINE_OFFSET (f) = font->font.baseline_offset;
8205 FRAME_FONTSET (f) = fontset;
8206
8207 FRAME_COLUMN_WIDTH (f) = font->font.average_width;
8208 FRAME_SPACE_WIDTH (f) = font->font.space_width;
8209 FRAME_LINE_HEIGHT (f) = font->font.height;
8210
8211 compute_fringe_widths (f, 1);
8212
8213 /* Compute the scroll bar width in character columns. */
8214 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0)
8215 {
8216 int wid = FRAME_COLUMN_WIDTH (f);
8217 FRAME_CONFIG_SCROLL_BAR_COLS (f)
8218 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid - 1) / wid;
8219 }
8220 else
8221 {
8222 int wid = FRAME_COLUMN_WIDTH (f);
8223 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
8224 }
8225
8226 /* Now make the frame display the given font. */
8227 if (FRAME_X_WINDOW (f) != 0)
8228 {
8229 /* Don't change the size of a tip frame; there's no point in
8230 doing it because it's done in Fx_show_tip, and it leads to
8231 problems because the tip frame has no widget. */
8232 if (NILP (tip_frame) || XFRAME (tip_frame) != f)
8233 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
8234 }
8235
8236#ifdef HAVE_X_I18N
8237 if (FRAME_XIC (f)
8238 && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea)))
8239 xic_set_xfontset (f, SDATA (fontset_ascii (fontset)));
8240#endif
8241
8242 UNBLOCK_INPUT;
8243
8244 return fontset_name (fontset);
8245}
8246#endif /* USE_FONT_BACKEND */
8247
8010 8248
8011/*********************************************************************** 8249/***********************************************************************
8012 X Input Methods 8250 X Input Methods
@@ -9008,6 +9246,15 @@ x_free_frame_resources (f)
9008 commands to the X server. */ 9246 commands to the X server. */
9009 if (dpyinfo->display) 9247 if (dpyinfo->display)
9010 { 9248 {
9249#ifdef USE_FONT_BACKEND
9250 /* We must free faces before destroying windows because some
9251 font-driver (e.g. xft) access a window while finishing a
9252 face. */
9253 if (enable_font_backend
9254 && FRAME_FACE_CACHE (f))
9255 free_frame_faces (f);
9256#endif /* USE_FONT_BACKEND */
9257
9011 if (f->output_data.x->icon_desc) 9258 if (f->output_data.x->icon_desc)
9012 XDestroyWindow (FRAME_X_DISPLAY (f), f->output_data.x->icon_desc); 9259 XDestroyWindow (FRAME_X_DISPLAY (f), f->output_data.x->icon_desc);
9013 9260