From: Alp Aker <alptekin.aker@gmail.com>
To: "Aurélien Aptel" <aurelien.aptel+emacs@gmail.com>
Cc: "Juanma Barranquero" <lekktu@gmail.com>,
emacs-devel@gnu.org, "Juri Linkov" <juri@jurta.org>,
"Stefan Monnier" <monnier@iro.umontreal.ca>,
"Jan Djärv" <jan.h.d@swipnet.se>,
"Drew Adams" <drew.adams@oracle.com>
Subject: Re: [patch] add "underwave" face attribute
Date: Sun, 5 Feb 2012 19:18:50 -0500 [thread overview]
Message-ID: <CACxch4rCBek1=dhhWkmrge3Y2zJY4TWODoZPFhS-iGTqCOzYGw@mail.gmail.com> (raw)
In-Reply-To: <CA+5B0FP1wVLRt9WqTT2OymtcgN3uVq=7iXZHHk1EeEntA2+jRA@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 828 bytes --]
Aurélien Aptel wrote:
> Mac OSX clipping works differently and I'm not sure what to do... See
> XXX coments in nsterm.m
I fixed up the NextStep portion; attached is a new diff reflecting the
changes to nsterm.m. In particular, in ns_draw_underwave:
(1) I changed the API calls for the clipping.
(2) Because of the way the NS port handles cursor drawing, one can't
extract the x-origin and width for the underwave directly from the glyph
string as you did. I made the appropriate changes.
(3) On the various displays I tried, changing wave_height from 2 to 3
dramatically improved the appearance. I took the liberty of using the
latter value. (Perhaps wave_height and wave_length should be exposed to
the user as options?)
(4) I rearranged the code to make it more obviously parallel
to x_draw_underwave.
[-- Attachment #1.2: Type: text/html, Size: 1162 bytes --]
[-- Attachment #2: underwave-clip-2.diff --]
[-- Type: application/octet-stream, Size: 6344 bytes --]
=== modified file 'src/nsterm.m'
--- src/nsterm.m 2012-02-04 15:10:54 +0000
+++ src/nsterm.m 2012-02-05 23:52:29 +0000
@@ -2598,6 +2598,66 @@
return n;
}
+/* --------------------------------------------------------------------
+ Draw a wavy line under glyph string s. The wave fills wave_height
+ pixels from y.
+
+ x wave_length = 2
+ --
+ y * * * * *
+ |* * * * * * * * *
+ wave_height = 3 | * * * *
+ --------------------------------------------------------------------- */
+
+static void
+ns_draw_underwave (struct glyph_string *s, CGFloat width, CGFloat x)
+{
+ int wave_height = 3, wave_length = 3;
+ int y, dx, dy, odd, xmax;
+ NSPoint a, b;
+ NSRect waveClip, stringClip, finalClip;
+
+ dx = wave_length;
+ dy = wave_height - 1;
+ y = s->ybase + 1;
+ xmax = x + width;
+
+ /* Find and set clipping rectangle */
+
+ waveClip = NSMakeRect (x, y, width, wave_height);
+ ns_get_glyph_string_clip_rect (s, &stringClip);
+ finalClip = NSIntersectionRect (waveClip, stringClip);
+
+ if (NSIsEmptyRect (finalClip))
+ return;
+
+ [[NSGraphicsContext currentContext] saveGraphicsState];
+ NSRectClip (finalClip);
+
+ /* Draw the waves */
+
+ a.x = x - ((int)(x) % dx);
+ b.x = a.x + dx;
+ odd = ((int)(a.x)/dx) % 2;
+ a.y = b.y = y;
+
+ if (odd)
+ a.y += dy;
+ else
+ b.y += dy;
+
+ while (a.x <= xmax)
+ {
+ [NSBezierPath strokeLineFromPoint:a toPoint: b];
+ a.x = b.x, a.y = b.y;
+ b.x += dx, b.y = y + odd*dy;
+ odd = !odd;
+ }
+
+ /* Restore previous clipping rectangle(s) */
+ [[NSGraphicsContext currentContext] restoreGraphicsState];
+}
+
void
ns_draw_text_decoration (struct glyph_string *s, struct face *face,
NSColor *defaultCol, CGFloat width, CGFloat x)
@@ -2611,63 +2671,75 @@
/* Do underline. */
if (face->underline_p)
{
- NSRect r;
- unsigned long thickness, position;
-
- /* If the prev was underlined, match its appearance. */
- if (s->prev && s->prev->face->underline_p
- && s->prev->underline_thickness > 0)
- {
- thickness = s->prev->underline_thickness;
- position = s->prev->underline_position;
- }
- else
- {
- struct font *font;
- unsigned long descent;
-
- font=s->font;
- descent = s->y + s->height - s->ybase;
-
- /* Use underline thickness of font, defaulting to 1. */
- thickness = (font && font->underline_thickness > 0)
- ? font->underline_thickness : 1;
-
- /* Determine the offset of underlining from the baseline. */
- if (x_underline_at_descent_line)
- position = descent - thickness;
- else if (x_use_underline_position_properties
- && font && font->underline_position >= 0)
- position = font->underline_position;
- else if (font)
- position = lround (font->descent / 2);
- else
- position = underline_minimum_offset;
-
- position = max (position, underline_minimum_offset);
-
- /* Ensure underlining is not cropped. */
- if (descent <= position)
- {
- position = descent - 1;
- thickness = 1;
- }
- else if (descent < position + thickness)
- thickness = 1;
- }
-
- s->underline_thickness = thickness;
- s->underline_position = position;
-
- r = NSMakeRect (x, s->ybase + position, width, thickness);
-
- if (face->underline_defaulted_p)
- [defaultCol set];
- else
- [ns_lookup_indexed_color (face->underline_color, s->f) set];
- NSRectFill (r);
+ if (s->face->underline_type == FACE_UNDER_WAVE)
+ {
+ if (face->underline_defaulted_p)
+ [defaultCol set];
+ else
+ [ns_lookup_indexed_color (face->underline_color, s->f) set];
+
+ ns_draw_underwave (s, width, x);
+ }
+ else if (s->face->underline_type == FACE_UNDER_LINE)
+ {
+
+ NSRect r;
+ unsigned long thickness, position;
+
+ /* If the prev was underlined, match its appearance. */
+ if (s->prev && s->prev->face->underline_p
+ && s->prev->underline_thickness > 0)
+ {
+ thickness = s->prev->underline_thickness;
+ position = s->prev->underline_position;
+ }
+ else
+ {
+ struct font *font;
+ unsigned long descent;
+
+ font=s->font;
+ descent = s->y + s->height - s->ybase;
+
+ /* Use underline thickness of font, defaulting to 1. */
+ thickness = (font && font->underline_thickness > 0)
+ ? font->underline_thickness : 1;
+
+ /* Determine the offset of underlining from the baseline. */
+ if (x_underline_at_descent_line)
+ position = descent - thickness;
+ else if (x_use_underline_position_properties
+ && font && font->underline_position >= 0)
+ position = font->underline_position;
+ else if (font)
+ position = lround (font->descent / 2);
+ else
+ position = underline_minimum_offset;
+
+ position = max (position, underline_minimum_offset);
+
+ /* Ensure underlining is not cropped. */
+ if (descent <= position)
+ {
+ position = descent - 1;
+ thickness = 1;
+ }
+ else if (descent < position + thickness)
+ thickness = 1;
+ }
+
+ s->underline_thickness = thickness;
+ s->underline_position = position;
+
+ r = NSMakeRect (x, s->ybase + position, width, thickness);
+
+ if (face->underline_defaulted_p)
+ [defaultCol set];
+ else
+ [ns_lookup_indexed_color (face->underline_color, s->f) set];
+ NSRectFill (r);
+ }
}
-
/* Do overline. We follow other terms in using a thickness of 1
and ignoring overline_margin. */
if (face->overline_p)
next prev parent reply other threads:[~2012-02-06 0:18 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-26 20:16 [patch] add "underwave" face attribute Aurélien Aptel
2012-01-27 15:50 ` Stefan Monnier
2012-01-27 17:08 ` Drew Adams
2012-01-31 23:38 ` Aurélien Aptel
2012-02-01 16:21 ` Leo
2012-02-01 23:11 ` Juri Linkov
2012-02-02 0:18 ` Aurélien Aptel
2012-02-02 0:52 ` Juanma Barranquero
2012-02-03 19:37 ` Aurélien Aptel
2012-02-04 8:14 ` Jan Djärv
2012-02-04 18:22 ` Aurélien Aptel
2012-02-06 0:18 ` Alp Aker [this message]
2012-02-06 0:24 ` Aurélien Aptel
2012-02-06 0:51 ` Alp Aker
2012-02-06 0:55 ` Aurélien Aptel
2012-02-06 1:14 ` Alp Aker
2012-02-06 11:27 ` Aurélien Aptel
2012-02-06 17:20 ` Aurélien Aptel
2012-02-12 11:19 ` Aurélien Aptel
2012-02-12 16:59 ` Stefan Monnier
2012-02-12 17:08 ` Leo
2012-02-12 17:29 ` Aurélien Aptel
-- strict thread matches above, loose matches on Subject: below --
2012-01-26 17:55 Aurélien Aptel
2012-01-27 4:01 ` Leo
2012-01-27 10:25 ` Andreas Schwab
2012-01-27 13:02 ` Aurélien Aptel
2012-01-27 14:06 ` Andreas Schwab
2012-01-27 14:55 ` Aurélien Aptel
2012-01-27 15:53 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACxch4rCBek1=dhhWkmrge3Y2zJY4TWODoZPFhS-iGTqCOzYGw@mail.gmail.com' \
--to=alptekin.aker@gmail.com \
--cc=aurelien.aptel+emacs@gmail.com \
--cc=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
--cc=jan.h.d@swipnet.se \
--cc=juri@jurta.org \
--cc=lekktu@gmail.com \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).