Mercurial > emacs
comparison src/macterm.c @ 73298:d16326a96180
(mac_draw_image_string, mac_draw_image_string_16): Add
argument OVERSTRIKE_P.
(mac_draw_string_common, mac_draw_image_string_cg): Likewise.
Support overstrike.
(mac_draw_string, mac_draw_string_16): Remove functions.
(x_draw_glyph_string_foreground): Use overstrike when needed.
(x_draw_composite_glyph_string_foreground): Likewise. Use
mac_draw_image_string_16 instead of mac_draw_string_16.
(mac_load_query_font): Rename from XLoadQueryFont. Take argument F
instead of DPY. All uses changed. Don't save/restore font.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Sun, 08 Oct 2006 07:47:51 +0000 |
parents | 7156654b0c06 |
children | bd82ccfce877 2d56e13fd23d 8dd8c8286063 |
comparison
equal
deleted
inserted
replaced
73297:f4d7960fe496 | 73298:d16326a96180 |
---|---|
889 InvertRect (&r); | 889 InvertRect (&r); |
890 } | 890 } |
891 | 891 |
892 | 892 |
893 static void | 893 static void |
894 mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, bytes_per_char) | 894 mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, |
895 overstrike_p, bytes_per_char) | |
895 struct frame *f; | 896 struct frame *f; |
896 GC gc; | 897 GC gc; |
897 int x, y; | 898 int x, y; |
898 char *buf; | 899 char *buf; |
899 int nchars, bg_width, bytes_per_char; | 900 int nchars, bg_width, overstrike_p, bytes_per_char; |
900 { | 901 { |
901 SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 902 SetPortWindowPort (FRAME_MAC_WINDOW (f)); |
902 | 903 |
903 #if USE_ATSUI | 904 #if USE_ATSUI |
904 if (GC_FONT (gc)->mac_style) | 905 if (GC_FONT (gc)->mac_style) |
944 } | 945 } |
945 MoveTo (x, y); | 946 MoveTo (x, y); |
946 ATSUDrawText (text_layout, | 947 ATSUDrawText (text_layout, |
947 kATSUFromTextBeginning, kATSUToTextEnd, | 948 kATSUFromTextBeginning, kATSUToTextEnd, |
948 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | 949 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); |
950 if (overstrike_p) | |
951 { | |
952 MoveTo (x + 1, y); | |
953 ATSUDrawText (text_layout, | |
954 kATSUFromTextBeginning, kATSUToTextEnd, | |
955 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | |
956 } | |
949 mac_end_clip (gc); | 957 mac_end_clip (gc); |
950 #ifdef MAC_OSX | 958 #ifdef MAC_OSX |
951 } | 959 } |
952 else | 960 else |
953 { | 961 { |
987 CG_SET_FILL_COLOR (context, gc->xgcv.foreground); | 995 CG_SET_FILL_COLOR (context, gc->xgcv.foreground); |
988 err = ATSUSetLayoutControls (text_layout, | 996 err = ATSUSetLayoutControls (text_layout, |
989 sizeof (tags) / sizeof (tags[0]), | 997 sizeof (tags) / sizeof (tags[0]), |
990 tags, sizes, values); | 998 tags, sizes, values); |
991 if (err == noErr) | 999 if (err == noErr) |
992 ATSUDrawText (text_layout, | 1000 { |
993 kATSUFromTextBeginning, kATSUToTextEnd, | 1001 ATSUDrawText (text_layout, |
994 Long2Fix (x), Long2Fix (port_height - y)); | 1002 kATSUFromTextBeginning, kATSUToTextEnd, |
1003 Long2Fix (x), Long2Fix (port_height - y)); | |
1004 if (overstrike_p) | |
1005 ATSUDrawText (text_layout, | |
1006 kATSUFromTextBeginning, kATSUToTextEnd, | |
1007 Long2Fix (x + 1), Long2Fix (port_height - y)); | |
1008 } | |
995 #if USE_CG_DRAWING | 1009 #if USE_CG_DRAWING |
996 mac_end_cg_clip (f); | 1010 mac_end_cg_clip (f); |
997 context = NULL; | 1011 context = NULL; |
998 #else | 1012 #else |
999 CGContextSynchronize (context); | 1013 CGContextSynchronize (context); |
1055 TextFont (GC_FONT (gc)->mac_fontnum); | 1069 TextFont (GC_FONT (gc)->mac_fontnum); |
1056 TextSize (GC_FONT (gc)->mac_fontsize); | 1070 TextSize (GC_FONT (gc)->mac_fontsize); |
1057 TextFace (GC_FONT (gc)->mac_fontface); | 1071 TextFace (GC_FONT (gc)->mac_fontface); |
1058 MoveTo (x, y); | 1072 MoveTo (x, y); |
1059 DrawText (buf, 0, nchars * bytes_per_char); | 1073 DrawText (buf, 0, nchars * bytes_per_char); |
1074 if (overstrike_p) | |
1075 { | |
1076 TextMode (srcOr); | |
1077 MoveTo (x + 1, y); | |
1078 DrawText (buf, 0, nchars * bytes_per_char); | |
1079 } | |
1060 if (bg_width) | 1080 if (bg_width) |
1061 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1081 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
1062 mac_end_clip (gc); | 1082 mac_end_clip (gc); |
1063 | 1083 |
1064 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | 1084 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 |
1067 #endif | 1087 #endif |
1068 } | 1088 } |
1069 } | 1089 } |
1070 | 1090 |
1071 | 1091 |
1072 /* Mac replacement for XDrawString. */ | 1092 /* Mac replacement for XDrawImageString. */ |
1073 | 1093 |
1074 static void | 1094 static void |
1075 mac_draw_string (f, gc, x, y, buf, nchars) | 1095 mac_draw_image_string (f, gc, x, y, buf, nchars, bg_width, overstrike_p) |
1076 struct frame *f; | 1096 struct frame *f; |
1077 GC gc; | 1097 GC gc; |
1078 int x, y; | 1098 int x, y; |
1079 char *buf; | 1099 char *buf; |
1080 int nchars; | 1100 int nchars, bg_width, overstrike_p; |
1081 { | 1101 { |
1082 mac_draw_string_common (f, gc, x, y, buf, nchars, 0, 1); | 1102 mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, |
1083 } | 1103 overstrike_p, 1); |
1084 | 1104 } |
1085 | 1105 |
1086 /* Mac replacement for XDrawString16. */ | 1106 |
1107 /* Mac replacement for XDrawImageString16. */ | |
1087 | 1108 |
1088 static void | 1109 static void |
1089 mac_draw_string_16 (f, gc, x, y, buf, nchars) | 1110 mac_draw_image_string_16 (f, gc, x, y, buf, nchars, bg_width, overstrike_p) |
1090 struct frame *f; | 1111 struct frame *f; |
1091 GC gc; | 1112 GC gc; |
1092 int x, y; | 1113 int x, y; |
1093 XChar2b *buf; | 1114 XChar2b *buf; |
1094 int nchars; | 1115 int nchars, bg_width, overstrike_p; |
1095 { | 1116 { |
1096 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, 0, 2); | 1117 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, bg_width, |
1097 } | 1118 overstrike_p, 2); |
1098 | |
1099 | |
1100 /* Mac replacement for XDrawImageString. */ | |
1101 | |
1102 static void | |
1103 mac_draw_image_string (f, gc, x, y, buf, nchars, bg_width) | |
1104 struct frame *f; | |
1105 GC gc; | |
1106 int x, y; | |
1107 char *buf; | |
1108 int nchars, bg_width; | |
1109 { | |
1110 mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, 1); | |
1111 } | |
1112 | |
1113 | |
1114 /* Mac replacement for XDrawString16. */ | |
1115 | |
1116 static void | |
1117 mac_draw_image_string_16 (f, gc, x, y, buf, nchars, bg_width) | |
1118 struct frame *f; | |
1119 GC gc; | |
1120 int x, y; | |
1121 XChar2b *buf; | |
1122 int nchars, bg_width; | |
1123 { | |
1124 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, bg_width, 2); | |
1125 } | 1119 } |
1126 | 1120 |
1127 | 1121 |
1128 /* Mac replacement for XQueryTextExtents, but takes a character. If | 1122 /* Mac replacement for XQueryTextExtents, but takes a character. If |
1129 STYLE is NULL, measurement is done by QuickDraw Text routines for | 1123 STYLE is NULL, measurement is done by QuickDraw Text routines for |
1293 if (valid_p) | 1287 if (valid_p) |
1294 cg_text_anti_aliasing_threshold = threshold; | 1288 cg_text_anti_aliasing_threshold = threshold; |
1295 } | 1289 } |
1296 | 1290 |
1297 static int | 1291 static int |
1298 mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width) | 1292 mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) |
1299 struct frame *f; | 1293 struct frame *f; |
1300 GC gc; | 1294 GC gc; |
1301 int x, y; | 1295 int x, y; |
1302 XChar2b *buf; | 1296 XChar2b *buf; |
1303 int nchars, bg_width; | 1297 int nchars, bg_width, overstrike_p; |
1304 { | 1298 { |
1305 CGrafPtr port; | 1299 CGrafPtr port; |
1306 float port_height, gx, gy; | 1300 float port_height, gx, gy; |
1307 int i; | 1301 int i; |
1308 CGContextRef context; | 1302 CGContextRef context; |
1360 if (GC_FONT (gc)->mac_fontsize <= cg_text_anti_aliasing_threshold) | 1354 if (GC_FONT (gc)->mac_fontsize <= cg_text_anti_aliasing_threshold) |
1361 CGContextSetShouldAntialias (context, false); | 1355 CGContextSetShouldAntialias (context, false); |
1362 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 | 1356 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 |
1363 CGContextSetTextPosition (context, gx, gy); | 1357 CGContextSetTextPosition (context, gx, gy); |
1364 CGContextShowGlyphsWithAdvances (context, glyphs, advances, nchars); | 1358 CGContextShowGlyphsWithAdvances (context, glyphs, advances, nchars); |
1359 if (overstrike_p) | |
1360 { | |
1361 CGContextSetTextPosition (context, gx + 1.0f, gy); | |
1362 CGContextShowGlyphsWithAdvances (context, glyphs, advances, nchars); | |
1363 } | |
1365 #else | 1364 #else |
1366 for (i = 0; i < nchars; i++) | 1365 for (i = 0; i < nchars; i++) |
1367 { | 1366 { |
1368 CGContextShowGlyphsAtPoint (context, gx, gy, glyphs + i, 1); | 1367 CGContextShowGlyphsAtPoint (context, gx, gy, glyphs + i, 1); |
1368 if (overstrike_p) | |
1369 CGContextShowGlyphsAtPoint (context, gx + 1.0f, gy, glyphs + i, 1); | |
1369 gx += advances[i].width; | 1370 gx += advances[i].width; |
1370 } | 1371 } |
1371 #endif | 1372 #endif |
1372 #if USE_CG_DRAWING | 1373 #if USE_CG_DRAWING |
1373 mac_end_cg_clip (f); | 1374 mac_end_cg_clip (f); |
2769 #endif | 2770 #endif |
2770 ) | 2771 ) |
2771 #if USE_CG_TEXT_DRAWING | 2772 #if USE_CG_TEXT_DRAWING |
2772 if (!s->two_byte_p | 2773 if (!s->two_byte_p |
2773 && mac_draw_image_string_cg (s->f, s->gc, x, s->ybase - boff, | 2774 && mac_draw_image_string_cg (s->f, s->gc, x, s->ybase - boff, |
2774 s->char2b, s->nchars, bg_width)) | 2775 s->char2b, s->nchars, bg_width, |
2776 s->face->overstrike)) | |
2775 ; | 2777 ; |
2776 else | 2778 else |
2777 #endif | 2779 #endif |
2778 mac_draw_image_string_16 (s->f, s->gc, x, s->ybase - boff, | 2780 mac_draw_image_string_16 (s->f, s->gc, x, s->ybase - boff, |
2779 s->char2b, s->nchars, bg_width); | 2781 s->char2b, s->nchars, bg_width, |
2782 s->face->overstrike); | |
2780 else | 2783 else |
2781 mac_draw_image_string (s->f, s->gc, x, s->ybase - boff, | 2784 mac_draw_image_string (s->f, s->gc, x, s->ybase - boff, |
2782 char1b, s->nchars, bg_width); | 2785 char1b, s->nchars, bg_width, |
2786 s->face->overstrike); | |
2783 } | 2787 } |
2784 } | 2788 } |
2785 | 2789 |
2786 /* Draw the foreground of composite glyph string S. */ | 2790 /* Draw the foreground of composite glyph string S. */ |
2787 | 2791 |
2813 s->width - 1, s->height - 1); | 2817 s->width - 1, s->height - 1); |
2814 } | 2818 } |
2815 else | 2819 else |
2816 { | 2820 { |
2817 for (i = 0; i < s->nchars; i++, ++s->gidx) | 2821 for (i = 0; i < s->nchars; i++, ++s->gidx) |
2818 mac_draw_string_16 (s->f, s->gc, | 2822 mac_draw_image_string_16 (s->f, s->gc, |
2819 x + s->cmp->offsets[s->gidx * 2], | 2823 x + s->cmp->offsets[s->gidx * 2], |
2820 s->ybase - s->cmp->offsets[s->gidx * 2 + 1], | 2824 s->ybase - s->cmp->offsets[s->gidx * 2 + 1], |
2821 s->char2b + i, 1); | 2825 s->char2b + i, 1, 0, s->face->overstrike); |
2822 } | 2826 } |
2823 } | 2827 } |
2824 | 2828 |
2825 | 2829 |
2826 #ifdef USE_X_TOOLKIT | 2830 #ifdef USE_X_TOOLKIT |
7780 | 7784 |
7781 return 1; | 7785 return 1; |
7782 } | 7786 } |
7783 | 7787 |
7784 | 7788 |
7785 /* XLoadQueryFont creates and returns an internal representation for a | 7789 /* mac_load_query_font creates and returns an internal representation |
7786 font in a MacFontStruct struct. There is really no concept | 7790 for a font in a MacFontStruct struct. There is really no concept |
7787 corresponding to "loading" a font on the Mac. But we check its | 7791 corresponding to "loading" a font on the Mac. But we check its |
7788 existence and find the font number and all other information for it | 7792 existence and find the font number and all other information for it |
7789 and store them in the returned MacFontStruct. */ | 7793 and store them in the returned MacFontStruct. */ |
7790 | 7794 |
7791 static MacFontStruct * | 7795 static MacFontStruct * |
7792 XLoadQueryFont (Display *dpy, char *fontname) | 7796 mac_load_query_font (f, fontname) |
7797 struct frame *f; | |
7798 char *fontname; | |
7793 { | 7799 { |
7794 int size; | 7800 int size; |
7795 char *name; | 7801 char *name; |
7796 Str255 family; | 7802 Str255 family; |
7797 Str31 charset; | 7803 Str31 charset; |
7998 } | 8004 } |
7999 } | 8005 } |
8000 else | 8006 else |
8001 #endif | 8007 #endif |
8002 { | 8008 { |
8003 GrafPtr port; | |
8004 SInt16 old_fontnum, old_fontsize; | |
8005 Style old_fontface; | |
8006 FontInfo the_fontinfo; | 8009 FontInfo the_fontinfo; |
8007 int is_two_byte_font; | 8010 int is_two_byte_font; |
8008 | 8011 |
8009 #if USE_CG_DRAWING | 8012 #if USE_CG_DRAWING |
8010 mac_prepare_for_quickdraw (NULL); | 8013 mac_prepare_for_quickdraw (f); |
8011 #endif | 8014 #endif |
8012 /* Save the current font number used. */ | 8015 SetPortWindowPort (FRAME_MAC_WINDOW (f)); |
8013 GetPort (&port); | |
8014 #if TARGET_API_MAC_CARBON | |
8015 old_fontnum = GetPortTextFont (port); | |
8016 old_fontsize = GetPortTextSize (port); | |
8017 old_fontface = GetPortTextFace (port); | |
8018 #else | |
8019 old_fontnum = port->txFont; | |
8020 old_fontsize = port->txSize; | |
8021 old_fontface = port->txFace; | |
8022 #endif | |
8023 | 8016 |
8024 TextFont (fontnum); | 8017 TextFont (fontnum); |
8025 TextSize (size); | 8018 TextSize (size); |
8026 TextFace (fontface); | 8019 TextFace (fontface); |
8027 | 8020 |
8099 space_bounds, NULL); | 8092 space_bounds, NULL); |
8100 | 8093 |
8101 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++) | 8094 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++) |
8102 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL); | 8095 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL); |
8103 } | 8096 } |
8104 | |
8105 /* Restore previous font number, size and face. */ | |
8106 TextFont (old_fontnum); | |
8107 TextSize (old_fontsize); | |
8108 TextFace (old_fontface); | |
8109 } | 8097 } |
8110 | 8098 |
8111 if (space_bounds) | 8099 if (space_bounds) |
8112 { | 8100 { |
8113 int c; | 8101 int c; |
8243 int i; | 8231 int i; |
8244 | 8232 |
8245 fontname = (char *) SDATA (XCAR (font_names)); | 8233 fontname = (char *) SDATA (XCAR (font_names)); |
8246 | 8234 |
8247 BLOCK_INPUT; | 8235 BLOCK_INPUT; |
8248 font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname); | 8236 font = mac_load_query_font (f, fontname); |
8249 UNBLOCK_INPUT; | 8237 UNBLOCK_INPUT; |
8250 if (!font) | 8238 if (!font) |
8251 return NULL; | 8239 return NULL; |
8252 | 8240 |
8253 /* Find a free slot in the font table. */ | 8241 /* Find a free slot in the font table. */ |