aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2024-05-01 22:02:15 +0800
committerPo Lu2024-05-01 22:02:47 +0800
commita5f57a86347eb950d201875cb8bba92d424611db (patch)
tree3124bd39ebcc1845ddebfeba07e52b8f5b8d428d /src
parent04635f399b01925b8ed6bcf555e2f528cba2e401 (diff)
downloademacs-a5f57a86347eb950d201875cb8bba92d424611db.tar.gz
emacs-a5f57a86347eb950d201875cb8bba92d424611db.zip
Implement dots and dashes on Nextstep
* src/Makefile.in (NON_OBJC_CFLAGS): Add -Wstrict-flex-arrays. * src/nsterm.m (ns_draw_dash, ns_fill_underline): New functions. (ns_draw_text_decoration): Port dash and dot display from X.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in3
-rw-r--r--src/nsterm.m78
2 files changed, 68 insertions, 13 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 747ec7d406f..e839a74dabf 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -417,7 +417,8 @@ pdmp :=
417endif 417endif
418 418
419# Flags that might be in WARN_CFLAGS but are not valid for Objective C. 419# Flags that might be in WARN_CFLAGS but are not valid for Objective C.
420NON_OBJC_CFLAGS = -Wignored-attributes -Wignored-qualifiers -Wopenmp-simd -Wnested-externs 420NON_OBJC_CFLAGS = -Wignored-attributes -Wignored-qualifiers -Wopenmp-simd \
421 -Wnested-externs -Wstrict-flex-arrays
421# Ditto, but for C++. 422# Ditto, but for C++.
422NON_CXX_CFLAGS = -Wmissing-prototypes -Wnested-externs -Wold-style-definition \ 423NON_CXX_CFLAGS = -Wmissing-prototypes -Wnested-externs -Wold-style-definition \
423 -Wstrict-prototypes -Wno-override-init 424 -Wstrict-prototypes -Wno-override-init
diff --git a/src/nsterm.m b/src/nsterm.m
index bd4010f2844..71fa6e22164 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3310,7 +3310,66 @@ ns_draw_underwave (struct glyph_string *s, EmacsCGFloat width, EmacsCGFloat x)
3310 [[NSGraphicsContext currentContext] restoreGraphicsState]; 3310 [[NSGraphicsContext currentContext] restoreGraphicsState];
3311} 3311}
3312 3312
3313/* Draw a dashed underline of thickness THICKNESS and width WIDTH onto
3314 the focused frame at a vertical offset of OFFSET from the position of
3315 the glyph string S, with each segment SEGMENT pixels in length. */
3313 3316
3317static void
3318ns_draw_dash (struct glyph_string *s, int width, int segment,
3319 int offset, int thickness)
3320{
3321 CGFloat pattern[2], y_center = s->ybase + offset + thickness / 2.0;
3322 NSBezierPath *path = [[NSBezierPath alloc] init];
3323
3324 pattern[0] = segment;
3325 pattern[1] = segment;
3326
3327 [path setLineDash: pattern count: 2 phase: (CGFloat) s->x];
3328 [path setLineWidth: thickness];
3329 [path moveToPoint: NSMakePoint (s->x, y_center)];
3330 [path lineToPoint: NSMakePoint (s->x + width, y_center)];
3331 [path stroke];
3332 [path release];
3333}
3334
3335/* Draw an underline of STYLE onto the focused frame at an offset of
3336 POSITION from the baseline of the glyph string S, S->WIDTH in length,
3337 and THICKNESS in height. */
3338
3339static void
3340ns_fill_underline (struct glyph_string *s, enum face_underline_type style,
3341 int position, int thickness)
3342{
3343 int segment;
3344 NSRect rect;
3345
3346 segment = thickness * 3;
3347
3348 switch (style)
3349 {
3350 /* FACE_UNDERLINE_DOUBLE_LINE is treated identically to SINGLE, as
3351 the second line will be filled by another invocation of this
3352 function. */
3353 case FACE_UNDERLINE_SINGLE:
3354 case FACE_UNDERLINE_DOUBLE_LINE:
3355 rect = NSMakeRect (s->x, s->ybase + position, s->width, thickness);
3356 NSRectFill (rect);
3357 break;
3358
3359 case FACE_UNDERLINE_DOTS:
3360 segment = thickness;
3361 FALLTHROUGH;
3362
3363 case FACE_UNDERLINE_DASHES:
3364 ns_draw_dash (s, s->width, segment, position, thickness);
3365 break;
3366
3367 case FACE_NO_UNDERLINE:
3368 case FACE_UNDERLINE_WAVE:
3369 default:
3370 emacs_abort ();
3371 }
3372}
3314 3373
3315static void 3374static void
3316ns_draw_text_decoration (struct glyph_string *s, struct face *face, 3375ns_draw_text_decoration (struct glyph_string *s, struct face *face,
@@ -3337,18 +3396,14 @@ ns_draw_text_decoration (struct glyph_string *s, struct face *face,
3337 3396
3338 ns_draw_underwave (s, width, x); 3397 ns_draw_underwave (s, width, x);
3339 } 3398 }
3340 else if (s->face->underline == FACE_UNDERLINE_SINGLE 3399 else if (face->underline >= FACE_UNDERLINE_SINGLE)
3341 || s->face->underline == FACE_UNDERLINE_DOUBLE_LINE)
3342 { 3400 {
3343
3344 NSRect r;
3345 unsigned long thickness, position; 3401 unsigned long thickness, position;
3346 3402
3347 /* If the prev was underlined, match its appearance. */ 3403 /* If the prev was underlined, match its appearance. */
3348 if (s->prev 3404 if (s->prev
3349 && ((s->prev->face->underline == FACE_UNDERLINE_SINGLE) 3405 && (s->prev->face->underline != FACE_UNDERLINE_WAVE
3350 || (s->prev->face->underline 3406 && s->prev->face->underline >= FACE_UNDERLINE_SINGLE)
3351 == FACE_UNDERLINE_DOUBLE_LINE))
3352 && s->prev->underline_thickness > 0 3407 && s->prev->underline_thickness > 0
3353 && (s->prev->face->underline_at_descent_line_p 3408 && (s->prev->face->underline_at_descent_line_p
3354 == s->face->underline_at_descent_line_p) 3409 == s->face->underline_at_descent_line_p)
@@ -3414,12 +3469,11 @@ ns_draw_text_decoration (struct glyph_string *s, struct face *face,
3414 s->underline_thickness = thickness; 3469 s->underline_thickness = thickness;
3415 s->underline_position = position; 3470 s->underline_position = position;
3416 3471
3417 r = NSMakeRect (x, s->ybase + position, width, thickness);
3418
3419 if (!face->underline_defaulted_p) 3472 if (!face->underline_defaulted_p)
3420 [[NSColor colorWithUnsignedLong:face->underline_color] set]; 3473 [[NSColor colorWithUnsignedLong:face->underline_color] set];
3421 3474
3422 NSRectFill (r); 3475 ns_fill_underline (s, s->face->underline, position,
3476 thickness);
3423 3477
3424 /* Place a second underline above the first if this was 3478 /* Place a second underline above the first if this was
3425 requested in the face specification. */ 3479 requested in the face specification. */
@@ -3428,8 +3482,8 @@ ns_draw_text_decoration (struct glyph_string *s, struct face *face,
3428 { 3482 {
3429 /* Compute the position of the second underline. */ 3483 /* Compute the position of the second underline. */
3430 position = position - thickness - 1; 3484 position = position - thickness - 1;
3431 r = NSMakeRect (x, s->ybase + position, width, thickness); 3485 ns_fill_underline (s, s->face->underline, position,
3432 NSRectFill (r); 3486 thickness);
3433 } 3487 }
3434 } 3488 }
3435 } 3489 }