aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlp Aker2011-07-28 14:26:29 -0400
committerChong Yidong2011-07-28 14:26:29 -0400
commit4843aac304884a75581bcc27454cb9fc4353f036 (patch)
tree07866fa7e7fbf056ba614ca67d7d97ced8c12bd7 /src
parentbc7ece8713dd2e9f6f6497c62b300f7d07cdcc6e (diff)
downloademacs-4843aac304884a75581bcc27454cb9fc4353f036.tar.gz
emacs-4843aac304884a75581bcc27454cb9fc4353f036.zip
Implement strike-through and overline on NextStep (Bug#8863).
* src/nsfont.m (nsfont_open): Use underline position provided by font, instead of hard-coded value of 2. (nsfont_draw): Call ns_draw_text_decoration instead. * src/nsterm.h: Add declaration for ns_draw_text_decoration. * src/nsterm.m (ns_draw_text_decoration): New function for drawing underline, overline, and strike-through. (ns_dumpglyphs_image, ns_dumpglyphs_stretch): Add call to ns_draw_text_decoration. Change treatment of cursor drawing to accomodate underlining, etc.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/nsfont.m39
-rw-r--r--src/nsterm.h7
-rw-r--r--src/nsterm.m196
4 files changed, 195 insertions, 63 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e821b75f4c8..24b36e7ff61 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12011-07-26 Alp Aker <alp.tekin.aker@gmail.com>
2
3 Implement strike-through and overline on NextStep (Bug#8863).
4
5 * nsfont.m (nsfont_open): Use underline position provided by font,
6 instead of hard-coded value of 2.
7 (nsfont_draw): Call ns_draw_text_decoration instead.
8
9 * nsterm.h: Add declaration for ns_draw_text_decoration.
10
11 * nsterm.m (ns_draw_text_decoration): New function for drawing
12 underline, overline, and strike-through.
13 (ns_dumpglyphs_image, ns_dumpglyphs_stretch): Add call to
14 ns_draw_text_decoration. Change treatment of cursor drawing to
15 accomodate underlining, etc.
16
12011-07-28 Eli Zaretskii <eliz@gnu.org> 172011-07-28 Eli Zaretskii <eliz@gnu.org>
2 18
3 * buffer.c (init_buffer_once): Set bidi-display-reordering to t by 19 * buffer.c (init_buffer_once): Set bidi-display-reordering to t by
diff --git a/src/nsfont.m b/src/nsfont.m
index 76c70aadf9f..3720e9a4615 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -845,7 +845,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
845 expand = 0.0; 845 expand = 0.0;
846 hshrink = 1.0; 846 hshrink = 1.0;
847 847
848 font_info->underpos = 2; /*[sfont underlinePosition] is often clipped out */ 848 font_info->underpos = [sfont underlinePosition];
849 font_info->underwidth = [sfont underlineThickness]; 849 font_info->underwidth = [sfont underlineThickness];
850 font_info->size = font->pixel_size; 850 font_info->size = font->pixel_size;
851 font_info->voffset = lrint (hshrink * [sfont ascender] + expand * hd / 2); 851 font_info->voffset = lrint (hshrink * [sfont ascender] + expand * hd / 2);
@@ -1196,20 +1196,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1196/*[context GSSetTextDrawingMode: GSTextFill]; /// not implemented yet */ 1196/*[context GSSetTextDrawingMode: GSTextFill]; /// not implemented yet */
1197 } 1197 }
1198 1198
1199 /* do underline */ 1199 [col set];
1200 if (face->underline_p)
1201 {
1202 if (face->underline_color != 0)
1203 [ns_lookup_indexed_color (face->underline_color, s->f) set];
1204 else
1205 [col set];
1206 DPSmoveto (context, r.origin.x, r.origin.y + font->underpos);
1207 DPSlineto (context, r.origin.x+r.size.width, r.origin.y+font->underpos);
1208 if (face->underline_color != 0)
1209 [col set];
1210 }
1211 else
1212 [col set];
1213 1200
1214 /* draw with DPSxshow () */ 1201 /* draw with DPSxshow () */
1215 DPSmoveto (context, r.origin.x, r.origin.y); 1202 DPSmoveto (context, r.origin.x, r.origin.y);
@@ -1255,23 +1242,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1255 CGContextSetTextDrawingMode (gcontext, kCGTextFill); 1242 CGContextSetTextDrawingMode (gcontext, kCGTextFill);
1256 } 1243 }
1257 1244
1258 if (face->underline_p) 1245 [col set];
1259 {
1260 if (face->underline_color != 0)
1261 [ns_lookup_indexed_color (face->underline_color, s->f) set];
1262 else
1263 [col set];
1264 CGContextBeginPath (gcontext);
1265 CGContextMoveToPoint (gcontext,
1266 r.origin.x, r.origin.y + font->underpos);
1267 CGContextAddLineToPoint (gcontext, r.origin.x + r.size.width,
1268 r.origin.y + font->underpos);
1269 CGContextStrokePath (gcontext);
1270 if (face->underline_color != 0)
1271 [col set];
1272 }
1273 else
1274 [col set];
1275 1246
1276 CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y); 1247 CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
1277 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from, 1248 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from,
@@ -1287,6 +1258,10 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1287 CGContextRestoreGState (gcontext); 1258 CGContextRestoreGState (gcontext);
1288 } 1259 }
1289#endif /* NS_IMPL_COCOA */ 1260#endif /* NS_IMPL_COCOA */
1261
1262 /* Draw underline, overline, strike-through. */
1263 ns_draw_text_decoration (s, face, col, r.size.width, r.origin.x);
1264
1290 return to-from; 1265 return to-from;
1291} 1266}
1292 1267
diff --git a/src/nsterm.h b/src/nsterm.h
index f419391a11e..227429ed515 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -825,6 +825,13 @@ extern unsigned long ns_get_rgb_color (struct frame *f,
825 float r, float g, float b, float a); 825 float r, float g, float b, float a);
826extern NSPoint last_mouse_motion_position; 826extern NSPoint last_mouse_motion_position;
827 827
828/* From nsterm.m, needed in nsfont.m. */
829#ifdef __OBJC__
830extern void
831ns_draw_text_decoration (struct glyph_string *s, struct face *face,
832 NSColor *defaultCol, CGFloat width, CGFloat x);
833#endif
834
828#ifdef NS_IMPL_GNUSTEP 835#ifdef NS_IMPL_GNUSTEP
829extern char gnustep_base_version[]; /* version tracking */ 836extern char gnustep_base_version[]; /* version tracking */
830#endif 837#endif
diff --git a/src/nsterm.m b/src/nsterm.m
index e45dc1a902d..e9e7dcc0804 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -263,8 +263,6 @@ static void ns_condemn_scroll_bars (struct frame *f);
263static void ns_judge_scroll_bars (struct frame *f); 263static void ns_judge_scroll_bars (struct frame *f);
264void x_set_frame_alpha (struct frame *f); 264void x_set_frame_alpha (struct frame *f);
265 265
266/* FIXME: figure out what to do with underline_minimum_offset. */
267
268 266
269/* ========================================================================== 267/* ==========================================================================
270 268
@@ -2597,6 +2595,107 @@ ns_get_glyph_string_clip_rect (struct glyph_string *s, NativeRectangle *nr)
2597 return n; 2595 return n;
2598} 2596}
2599 2597
2598void
2599ns_draw_text_decoration (struct glyph_string *s, struct face *face,
2600 NSColor *defaultCol, CGFloat width, CGFloat x)
2601/* --------------------------------------------------------------------------
2602 Draw underline, overline, and strike-through on glyph string s.
2603 -------------------------------------------------------------------------- */
2604{
2605 if (s->for_overlaps)
2606 return;
2607
2608 /* Do underline. */
2609 if (face->underline_p)
2610 {
2611 NSRect r;
2612 unsigned long thickness, position;
2613
2614 /* If the prev was underlined, match its appearance. */
2615 if (s->prev && s->prev->face->underline_p
2616 && s->prev->underline_thickness > 0)
2617 {
2618 thickness = s->prev->underline_thickness;
2619 position = s->prev->underline_position;
2620 }
2621 else
2622 {
2623 struct font *font;
2624 unsigned long descent;
2625
2626 font=s->font;
2627 descent = s->y + s->height - s->ybase;
2628
2629 /* Use underline thickness of font, defaulting to 1. */
2630 thickness = (font && font->underline_thickness > 0)
2631 ? font->underline_thickness : 1;
2632
2633 /* Determine the offset of underlining from the baseline. */
2634 if (x_underline_at_descent_line)
2635 position = descent - thickness;
2636 else if (x_use_underline_position_properties
2637 && font && font->underline_position >= 0)
2638 position = font->underline_position;
2639 else if (font)
2640 position = lround (font->descent / 2);
2641 else
2642 position = underline_minimum_offset;
2643
2644 position = max (position, underline_minimum_offset);
2645
2646 /* Ensure underlining is not cropped. */
2647 if (descent <= position)
2648 {
2649 position = descent - 1;
2650 thickness = 1;
2651 }
2652 else if (descent < position + thickness)
2653 thickness = 1;
2654 }
2655
2656 s->underline_thickness = thickness;
2657 s->underline_position = position;
2658
2659 r = NSMakeRect (x, s->ybase + position, width, thickness);
2660
2661 if (face->underline_defaulted_p)
2662 [defaultCol set];
2663 else
2664 [ns_lookup_indexed_color (face->underline_color, s->f) set];
2665 NSRectFill (r);
2666 }
2667
2668 /* Do overline. We follow other terms in using a thickness of 1
2669 and ignoring overline_margin. */
2670 if (face->overline_p)
2671 {
2672 NSRect r;
2673 r = NSMakeRect (x, s->y, width, 1);
2674
2675 if (face->overline_color_defaulted_p)
2676 [defaultCol set];
2677 else
2678 [ns_lookup_indexed_color (face->overline_color, s->f) set];
2679 NSRectFill (r);
2680 }
2681
2682 /* Do strike-through. We follow other terms for thickness and
2683 vertical position.*/
2684 if (face->strike_through_p)
2685 {
2686 NSRect r;
2687 unsigned long dy;
2688
2689 dy = lrint ((s->height - 1) / 2);
2690 r = NSMakeRect (x, s->y + dy, width, 1);
2691
2692 if (face->strike_through_color_defaulted_p)
2693 [defaultCol set];
2694 else
2695 [ns_lookup_indexed_color (face->strike_through_color, s->f) set];
2696 NSRectFill (r);
2697 }
2698}
2600 2699
2601static void 2700static void
2602ns_draw_box (NSRect r, float thickness, NSColor *col, char left_p, char right_p) 2701ns_draw_box (NSRect r, float thickness, NSColor *col, char left_p, char right_p)
@@ -2854,6 +2953,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2854 char raised_p; 2953 char raised_p;
2855 NSRect br; 2954 NSRect br;
2856 struct face *face; 2955 struct face *face;
2956 NSColor *tdCol;
2857 2957
2858 NSTRACE (ns_dumpglyphs_image); 2958 NSTRACE (ns_dumpglyphs_image);
2859 2959
@@ -2882,10 +2982,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2882 else 2982 else
2883 face = FACE_FROM_ID (s->f, s->first_glyph->face_id); 2983 face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
2884 2984
2885 if (s->hl == DRAW_CURSOR) 2985 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set];
2886 [FRAME_CURSOR_COLOR (s->f) set];
2887 else
2888 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set];
2889 2986
2890 if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin 2987 if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin
2891 || s->img->mask || s->img->pixmap == 0 || s->width != s->background_width) 2988 || s->img->mask || s->img->pixmap == 0 || s->width != s->background_width)
@@ -2923,6 +3020,27 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2923 [img compositeToPoint: NSMakePoint (x, y + s->slice.height) 3020 [img compositeToPoint: NSMakePoint (x, y + s->slice.height)
2924 operation: NSCompositeSourceOver]; 3021 operation: NSCompositeSourceOver];
2925 3022
3023 if (s->hl == DRAW_CURSOR)
3024 {
3025 [FRAME_CURSOR_COLOR (s->f) set];
3026 if (s->w->phys_cursor_type == FILLED_BOX_CURSOR)
3027 tdCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f);
3028 else
3029 /* Currently on NS img->mask is always 0. Since
3030 get_window_cursor_type specifies a hollow box cursor when on
3031 a non-masked image we never reach this clause. But we put it
3032 in in antipication of better support for image masks on
3033 NS. */
3034 tdCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
3035 }
3036 else
3037 {
3038 tdCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
3039 }
3040
3041 /* Draw underline, overline, strike-through. */
3042 ns_draw_text_decoration (s, face, tdCol, br.size.width, br.origin.x);
3043
2926 /* Draw relief, if requested */ 3044 /* Draw relief, if requested */
2927 if (s->img->relief || s->hl ==DRAW_IMAGE_RAISED || s->hl ==DRAW_IMAGE_SUNKEN) 3045 if (s->img->relief || s->hl ==DRAW_IMAGE_RAISED || s->hl ==DRAW_IMAGE_SUNKEN)
2928 { 3046 {
@@ -2967,12 +3085,27 @@ ns_dumpglyphs_stretch (struct glyph_string *s)
2967 NSRect r[2]; 3085 NSRect r[2];
2968 int n, i; 3086 int n, i;
2969 struct face *face; 3087 struct face *face;
3088 NSColor *fgCol, *bgCol;
2970 3089
2971 if (!s->background_filled_p) 3090 if (!s->background_filled_p)
2972 { 3091 {
2973 n = ns_get_glyph_string_clip_rect (s, r); 3092 n = ns_get_glyph_string_clip_rect (s, r);
2974 *r = NSMakeRect (s->x, s->y, s->background_width, s->height); 3093 *r = NSMakeRect (s->x, s->y, s->background_width, s->height);
2975 3094
3095 ns_focus (s->f, r, n);
3096
3097 if (s->hl == DRAW_MOUSE_FACE)
3098 {
3099 face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3100 if (!face)
3101 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
3102 }
3103 else
3104 face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
3105
3106 bgCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f);
3107 fgCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
3108
2976 for (i=0; i<n; i++) 3109 for (i=0; i<n; i++)
2977 { 3110 {
2978 if (!s->row->full_width_p) 3111 if (!s->row->full_width_p)
@@ -2998,30 +3131,37 @@ ns_dumpglyphs_stretch (struct glyph_string *s)
2998 FRAME_PIXEL_WIDTH (s->f)); 3131 FRAME_PIXEL_WIDTH (s->f));
2999 } 3132 }
3000 3133
3134 [bgCol set];
3135
3001 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid 3136 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3002 overwriting cursor (usually when cursor on a tab) */ 3137 overwriting cursor (usually when cursor on a tab) */
3003 if (s->hl == DRAW_CURSOR) 3138 if (s->hl == DRAW_CURSOR)
3004 { 3139 {
3005 r[i].origin.x += s->width; 3140 CGFloat x, width;
3006 r[i].size.width -= s->width;
3007 }
3008 }
3009 3141
3010 ns_focus (s->f, r, n); 3142 x = r[i].origin.x;
3143 width = s->w->phys_cursor_width;
3144 r[i].size.width -= width;
3145 r[i].origin.x += width;
3011 3146
3012 if (s->hl == DRAW_MOUSE_FACE) 3147 NSRectFill (r[i]);
3013 {
3014 face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3015 if (!face)
3016 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
3017 }
3018 else
3019 face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
3020 3148
3021 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set]; 3149 /* Draw overlining, etc. on the cursor. */
3150 if (s->w->phys_cursor_type == FILLED_BOX_CURSOR)
3151 ns_draw_text_decoration (s, face, bgCol, width, x);
3152 else
3153 ns_draw_text_decoration (s, face, fgCol, width, x);
3154 }
3155 else
3156 {
3157 NSRectFill (r[i]);
3158 }
3022 3159
3023 NSRectFill (r[0]); 3160 /* Draw overlining, etc. on the stretch glyph (or the part
3024 NSRectFill (r[1]); 3161 of the stretch glyph after the cursor). */
3162 ns_draw_text_decoration (s, face, fgCol, r[i].size.width,
3163 r[i].origin.x);
3164 }
3025 ns_unfocus (s->f); 3165 ns_unfocus (s->f);
3026 s->background_filled_p = 1; 3166 s->background_filled_p = 1;
3027 } 3167 }
@@ -6556,23 +6696,17 @@ Only works on OSX 10.6 or later. */);
6556 Vx_toolkit_scroll_bars = Qnil; 6696 Vx_toolkit_scroll_bars = Qnil;
6557#endif 6697#endif
6558 6698
6559 /* these are unsupported but we need the declarations to avoid whining
6560 messages from cus-start.el */
6561 DEFVAR_BOOL ("x-use-underline-position-properties", 6699 DEFVAR_BOOL ("x-use-underline-position-properties",
6562 x_use_underline_position_properties, 6700 x_use_underline_position_properties,
6563 doc: /* NOT SUPPORTED UNDER NS. 6701 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6564*Non-nil means make use of UNDERLINE_POSITION font properties.
6565A value of nil means ignore them. If you encounter fonts with bogus 6702A value of nil means ignore them. If you encounter fonts with bogus
6566UNDERLINE_POSITION font properties, for example 7x13 on XFree prior 6703UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6567to 4.1, set this to nil. 6704to 4.1, set this to nil. */);
6568
6569NOTE: Not supported on Mac yet. */);
6570 x_use_underline_position_properties = 0; 6705 x_use_underline_position_properties = 0;
6571 6706
6572 DEFVAR_BOOL ("x-underline-at-descent-line", 6707 DEFVAR_BOOL ("x-underline-at-descent-line",
6573 x_underline_at_descent_line, 6708 x_underline_at_descent_line,
6574 doc: /* NOT SUPPORTED UNDER NS. 6709 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6575*Non-nil means to draw the underline at the same place as the descent line.
6576A value of nil means to draw the underline according to the value of the 6710A value of nil means to draw the underline according to the value of the
6577variable `x-use-underline-position-properties', which is usually at the 6711variable `x-use-underline-position-properties', which is usually at the
6578baseline level. The default value is nil. */); 6712baseline level. The default value is nil. */);