unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Does face support underline other than a straight line?
@ 2012-01-24 10:00 Leo
  2012-01-25  6:03 ` Chong Yidong
  0 siblings, 1 reply; 9+ messages in thread
From: Leo @ 2012-01-24 10:00 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 55 bytes --]

Hello,

I found in other editors something like this:


[-- Attachment #2: wave.png --]
[-- Type: image/png, Size: 6869 bytes --]

[-- Attachment #3: Type: text/plain, Size: 130 bytes --]


ie they support wave underline. I am curious whether emacs can do this
too?

Best wishes,
Leo

-- 
Happy Chinese Spring Festival

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-24 10:00 Does face support underline other than a straight line? Leo
@ 2012-01-25  6:03 ` Chong Yidong
  2012-01-25  6:46   ` Eli Zaretskii
  2012-01-25  6:49   ` Stephen J. Turnbull
  0 siblings, 2 replies; 9+ messages in thread
From: Chong Yidong @ 2012-01-25  6:03 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

Leo <sdl.web@gmail.com> writes:

> Hello,
>
> I found in other editors something like this:
>
> ie they support wave underline. I am curious whether emacs can do this
> too?

I think implementing this would be a pain in the butt, since underlining
is currently done with primitive X calls.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-25  6:03 ` Chong Yidong
@ 2012-01-25  6:46   ` Eli Zaretskii
  2012-01-25  6:49   ` Stephen J. Turnbull
  1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2012-01-25  6:46 UTC (permalink / raw)
  To: Chong Yidong; +Cc: sdl.web, emacs-devel

> From: Chong Yidong <cyd@gnu.org>
> Date: Wed, 25 Jan 2012 14:03:36 +0800
> Cc: emacs-devel@gnu.org
> 
> Leo <sdl.web@gmail.com> writes:
> 
> > I found in other editors something like this:
> >
> > ie they support wave underline. I am curious whether emacs can do this
> > too?
> 
> I think implementing this would be a pain in the butt, since underlining
> is currently done with primitive X calls.

What would be a less painful way of implementing the "wave"
underlining?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-25  6:03 ` Chong Yidong
  2012-01-25  6:46   ` Eli Zaretskii
@ 2012-01-25  6:49   ` Stephen J. Turnbull
  2012-01-25  7:13     ` Eli Zaretskii
  1 sibling, 1 reply; 9+ messages in thread
From: Stephen J. Turnbull @ 2012-01-25  6:49 UTC (permalink / raw)
  To: Chong Yidong; +Cc: Leo, emacs-devel

Chong Yidong writes:
 > Leo <sdl.web@gmail.com> writes:
 > 
 > > Hello,
 > >
 > > I found in other editors something like this:
 > >
 > > ie they support wave underline. I am curious whether emacs can do this
 > > too?
 > 
 > I think implementing this would be a pain in the butt, since underlining
 > is currently done with primitive X calls.

If Emacs supports background pixmaps to attach to faces, then it
should be possible to create an appropriate pixmap on the fly.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-25  6:49   ` Stephen J. Turnbull
@ 2012-01-25  7:13     ` Eli Zaretskii
  2012-01-25  9:26       ` Stephen J. Turnbull
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2012-01-25  7:13 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: cyd, sdl.web, emacs-devel

> From: "Stephen J. Turnbull" <stephen@xemacs.org>
> Date: Wed, 25 Jan 2012 15:49:08 +0900
> Cc: Leo <sdl.web@gmail.com>, emacs-devel@gnu.org
> 
> Chong Yidong writes:
>  > Leo <sdl.web@gmail.com> writes:
>  > 
>  > > Hello,
>  > >
>  > > I found in other editors something like this:
>  > >
>  > > ie they support wave underline. I am curious whether emacs can do this
>  > > too?
>  > 
>  > I think implementing this would be a pain in the butt, since underlining
>  > is currently done with primitive X calls.
> 
> If Emacs supports background pixmaps to attach to faces, then it
> should be possible to create an appropriate pixmap on the fly.

We have the :stipple attribute of faces; is that what you mean?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-25  7:13     ` Eli Zaretskii
@ 2012-01-25  9:26       ` Stephen J. Turnbull
  2012-01-25 17:32         ` Aurélien Aptel
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen J. Turnbull @ 2012-01-25  9:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: cyd, sdl.web, emacs-devel

Eli Zaretskii writes:

 > > If Emacs supports background pixmaps to attach to faces, then it
 > > should be possible to create an appropriate pixmap on the fly.
 > 
 > We have the :stipple attribute of faces; is that what you mean?

I don't know how that works; never used it.  In X11, "stipple" means a
bitmap (mask), and I don't think that would cut it, you need to paint
the whole background.  I wouldn't be surprised if in Emacs it just
means "background image", though.

In XEmacs you can specify a color or a pixmap as background (bitmaps
are promoted to pixmaps, but with -- until about a week ago -- less
than satisfactory results).  So you could specify a background pixmap
(eg, as an XPM) as

                                +------+
                                |      |
                                |      |
                                |      |
                                |      |
                                | **   |
                                |*  *  |
                                |    **|
                                +------+

and it will be tiled appropriately over the extent of the face, and
the text will be printed over that in the foreground color.  Sort of
like poor man's image layers.

Of course you have to set the background color of the pixmap to the
background of the face, and you also have to get the height of the
pixmap in pixels exactly right, I suspect.  The latter might be
difficult for some fonts, especially with sizes specified in printer's
units rather than pixels.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-25  9:26       ` Stephen J. Turnbull
@ 2012-01-25 17:32         ` Aurélien Aptel
  2012-01-25 17:36           ` Aurélien Aptel
  0 siblings, 1 reply; 9+ messages in thread
From: Aurélien Aptel @ 2012-01-25 17:32 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: Eli Zaretskii, cyd, sdl.web, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 812 bytes --]

On Wed, Jan 25, 2012 at 10:26 AM, Stephen J. Turnbull
<stephen@xemacs.org> wrote:
> In XEmacs you can specify a color or a pixmap as background (bitmaps
> are promoted to pixmaps, but with -- until about a week ago -- less
> than satisfactory results).  So you could specify a background pixmap
> (eg, as an XPM) as
> [...]
> and it will be tiled appropriately over the extent of the face, and
> the text will be printed over that in the foreground color.  Sort of
> like poor man's image layers.

I think it would be simpler to do directly in C. I'm new to this but
it should be simple to add a new field "underwave_p" in struct face (
with underline_p, overline_p) in dispextern.h:1590 and handle it (for
X11) near xterm.c:2756.

See POC program attached for drawing underwaved text in X11.

[-- Attachment #2: underwave.c --]
[-- Type: text/x-csrc, Size: 3681 bytes --]

/* 
   X11 underwaved text example by <aurelien.aptel@gmail.com>
   Usage: gcc -lX11 underwave.c && ./a.out 
   Press ESC to quit, any other key to change the strings
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>

#define RAND(min,max) (rand()%((max)-(min))+(min))

#define FONT_NAME    "-*-fixed-*-*-*-*-13-*-*-*-*-*-iso8859-*"
#define WAVE_COLOR   "red"
#define WAVE_HEIGHT  2
#define WAVE_THICK   1

Window win;
Display* dpy;
GC gc;
int screen;
int width, height;
XFontStruct* font_info;
char* font_name = FONT_NAME;
int font_height;
int seed = 42;
unsigned long undercolor, black;

void init (int w, int h)
{
    XColor color;
    XColorMap cmap;
    unsigned int line_width = WAVE_THICK;
    int line_style = LineSolid;
    int cap_style = CapButt;
    int join_style = JoinBevel;

    width = w, height = h;
    
    dpy = XOpenDisplay(NULL);

    if(!dpy)
        puts("err: XOpenDisplay"), exit(1);

    screen = XDefaultScreen(dpy);
    win = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
                              100, 100, width, height, 0,
                              BlackPixel(dpy, screen),
                              WhitePixel(dpy, screen));

    cmap = XDefaultColormap(dpy, screen);
    black = BlackPixel(dpy, screen);
    XAllocNamedColor(dpy, cmap, WAVE_COLOR, &color, &color);
    undercolor = color.pixel;
    
    gc = XCreateGC(dpy, win, 0, NULL);
    XSetForeground(dpy, gc, BlackPixel(dpy, screen));
    XSetBackground(dpy, gc, WhitePixel(dpy, screen));
    XSetLineAttributes(dpy, gc, line_width, line_style, cap_style, join_style);

    font_info = XLoadQueryFont(dpy, font_name);
    XSetFont(dpy, gc, font_info->fid);
    font_height = font_info->ascent + font_info->descent;
}

void draw_wave (int x0, int y0, int w)
{
    int dx = WAVE_HEIGHT;
    int dy = dx/2;
    int x1, y1, x2, y2, i, times = w/dx;

    for(i = 0; i < times; i++) {
        x1 = x0 + i*dx;
        y1 = y0 + (i%2 ? 1 : -1) * dy;
        x2 = x0 + (i+1)*dx;
        y2 = y0 + ((i+1)%2 ? 1 : -1) * dy;
        XDrawLine(dpy, win, gc, x1, y1, x2, y2);
    }
}

void draw_underwave_string (char* str, int y)
{
    int len = strlen(str);
    int w = XTextWidth(font_info, str, len);
    int x = (width-w)/2;

    XSetForeground(dpy, gc, black);
    XDrawString(dpy, win, gc, x, y+font_info->ascent, str, len);
    XSetForeground(dpy, gc, undercolor);
    draw_wave(x, y+font_height, w);
}

void draw (void)
{
    char buf[256];
    int i, j, y, n = 20;

    srand(seed);
    XClearWindow(dpy, win);

    for(i = 1; i <= n; i++) {
        y = (height-font_height*1.5*n)/2+font_height*1.5*i;

        /* random ascii string */
        memset(buf, 0, sizeof buf);
        for(j = 0; j < i; j++)
            buf[j] = RAND(32, 126);
        buf[j] = 0;

        draw_underwave_string(buf, y);
    }
}

int main (void)
{
    int done = 0;
    XEvent e;
    int mask = ExposureMask | KeyPressMask | StructureNotifyMask;

    init(300, 300);

    XSelectInput(dpy, win, mask);
    XMapWindow(dpy, win);

    while (!done) {
        XNextEvent(dpy, &e);
        switch (e.type) {
        case Expose:
                draw();
            break;
        case ConfigureNotify:
            width = e.xconfigure.width;
            height = e.xconfigure.height;
            draw();
            break;
        case KeyPress:
            if(XLookupKeysym(&e.xkey, 0) == XK_Escape)
                done = 1;
            else {
                seed = time(NULL)+rand();
                draw();
            }
            break;
        }
    }

    XFreeGC(dpy, gc);
    XCloseDisplay(dpy);

    return 0;
}

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-25 17:32         ` Aurélien Aptel
@ 2012-01-25 17:36           ` Aurélien Aptel
  2012-01-25 20:05             ` Aurélien Aptel
  0 siblings, 1 reply; 9+ messages in thread
From: Aurélien Aptel @ 2012-01-25 17:36 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: Eli Zaretskii, cyd, sdl.web, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 75 bytes --]

Screenshot attached for the lazy (and because i'm happy with the result :)

[-- Attachment #2: underwave.png --]
[-- Type: image/png, Size: 18373 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Does face support underline other than a straight line?
  2012-01-25 17:36           ` Aurélien Aptel
@ 2012-01-25 20:05             ` Aurélien Aptel
  0 siblings, 0 replies; 9+ messages in thread
From: Aurélien Aptel @ 2012-01-25 20:05 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: Eli Zaretskii, cyd, sdl.web, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 101 bytes --]

Oops, there's a typo in the source, s/XColorMap/Colormap/
Fixed source attached, sorry for spamming.

[-- Attachment #2: underwave.c --]
[-- Type: text/x-csrc, Size: 3680 bytes --]

/* 
   X11 underwaved text example by <aurelien.aptel@gmail.com>
   Usage: gcc -lX11 underwave.c && ./a.out 
   Press ESC to quit, any other key to change the strings
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>

#define RAND(min,max) (rand()%((max)-(min))+(min))

#define FONT_NAME    "-*-fixed-*-*-*-*-13-*-*-*-*-*-iso8859-*"
#define WAVE_COLOR   "red"
#define WAVE_HEIGHT  2
#define WAVE_THICK   1

Window win;
Display* dpy;
GC gc;
int screen;
int width, height;
XFontStruct* font_info;
char* font_name = FONT_NAME;
int font_height;
int seed = 42;
unsigned long undercolor, black;

void init (int w, int h)
{
    XColor color;
    Colormap cmap;
    unsigned int line_width = WAVE_THICK;
    int line_style = LineSolid;
    int cap_style = CapButt;
    int join_style = JoinBevel;

    width = w, height = h;
    
    dpy = XOpenDisplay(NULL);

    if(!dpy)
        puts("err: XOpenDisplay"), exit(1);

    screen = XDefaultScreen(dpy);
    win = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
                              100, 100, width, height, 0,
                              BlackPixel(dpy, screen),
                              WhitePixel(dpy, screen));

    cmap = XDefaultColormap(dpy, screen);
    black = BlackPixel(dpy, screen);
    XAllocNamedColor(dpy, cmap, WAVE_COLOR, &color, &color);
    undercolor = color.pixel;
    
    gc = XCreateGC(dpy, win, 0, NULL);
    XSetForeground(dpy, gc, BlackPixel(dpy, screen));
    XSetBackground(dpy, gc, WhitePixel(dpy, screen));
    XSetLineAttributes(dpy, gc, line_width, line_style, cap_style, join_style);

    font_info = XLoadQueryFont(dpy, font_name);
    XSetFont(dpy, gc, font_info->fid);
    font_height = font_info->ascent + font_info->descent;
}

void draw_wave (int x0, int y0, int w)
{
    int dx = WAVE_HEIGHT;
    int dy = dx/2;
    int x1, y1, x2, y2, i, times = w/dx;

    for(i = 0; i < times; i++) {
        x1 = x0 + i*dx;
        y1 = y0 + (i%2 ? 1 : -1) * dy;
        x2 = x0 + (i+1)*dx;
        y2 = y0 + ((i+1)%2 ? 1 : -1) * dy;
        XDrawLine(dpy, win, gc, x1, y1, x2, y2);
    }
}

void draw_underwave_string (char* str, int y)
{
    int len = strlen(str);
    int w = XTextWidth(font_info, str, len);
    int x = (width-w)/2;

    XSetForeground(dpy, gc, black);
    XDrawString(dpy, win, gc, x, y+font_info->ascent, str, len);
    XSetForeground(dpy, gc, undercolor);
    draw_wave(x, y+font_height, w);
}

void draw (void)
{
    char buf[256];
    int i, j, y, n = 20;

    srand(seed);
    XClearWindow(dpy, win);

    for(i = 1; i <= n; i++) {
        y = (height-font_height*1.5*n)/2+font_height*1.5*i;

        /* random ascii string */
        memset(buf, 0, sizeof buf);
        for(j = 0; j < i; j++)
            buf[j] = RAND(32, 126);
        buf[j] = 0;

        draw_underwave_string(buf, y);
    }
}

int main (void)
{
    int done = 0;
    XEvent e;
    int mask = ExposureMask | KeyPressMask | StructureNotifyMask;

    init(300, 300);

    XSelectInput(dpy, win, mask);
    XMapWindow(dpy, win);

    while (!done) {
        XNextEvent(dpy, &e);
        switch (e.type) {
        case Expose:
                draw();
            break;
        case ConfigureNotify:
            width = e.xconfigure.width;
            height = e.xconfigure.height;
            draw();
            break;
        case KeyPress:
            if(XLookupKeysym(&e.xkey, 0) == XK_Escape)
                done = 1;
            else {
                seed = time(NULL)+rand();
                draw();
            }
            break;
        }
    }

    XFreeGC(dpy, gc);
    XCloseDisplay(dpy);

    return 0;
}

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-01-25 20:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-24 10:00 Does face support underline other than a straight line? Leo
2012-01-25  6:03 ` Chong Yidong
2012-01-25  6:46   ` Eli Zaretskii
2012-01-25  6:49   ` Stephen J. Turnbull
2012-01-25  7:13     ` Eli Zaretskii
2012-01-25  9:26       ` Stephen J. Turnbull
2012-01-25 17:32         ` Aurélien Aptel
2012-01-25 17:36           ` Aurélien Aptel
2012-01-25 20:05             ` Aurélien Aptel

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).