[PATCH 2/2] Some CJK glyphs are wide, which occupy two columns. If the glyph is wide, then use two columns instead of one.

Kristian Høgsberg hoegsberg at gmail.com
Mon Jul 8 15:07:18 PDT 2013


On Thu, Jun 06, 2013 at 03:32:42PM +0800, Peng Wu wrote:
> ---
>  clients/Makefile.am |  2 +-
>  clients/terminal.c  | 18 ++++++++++++++++--
>  2 files changed, 17 insertions(+), 3 deletions(-)

This makes sense, but I'm not happy about the pango dependency.  One
of the few reasons (if not the only reason) for weston-terminal to
exist is that it only depends on a few wayland libraries.  In
particular, it doesn't pull in any of the major toolkit silos.

I suspect that we would have to copy some unicode table into the
weston terminal to replace g_unichar_iswide(), and if that's a crazy
suggestion, let's just not do it.  But if it's feasible, let's do
that, and maybe also see if you can make selection work with wide characters?

Kristian

> diff --git a/clients/Makefile.am b/clients/Makefile.am
> index cad0d40..d37d66a 100644
> --- a/clients/Makefile.am
> +++ b/clients/Makefile.am
> @@ -104,7 +104,7 @@ weston_screenshooter_SOURCES =			\
>  weston_screenshooter_LDADD = libtoytoolkit.la
>  
>  weston_terminal_SOURCES = terminal.c
> -weston_terminal_LDADD = libtoytoolkit.la -lutil
> +weston_terminal_LDADD = libtoytoolkit.la -lutil $(PANGO_LIBS)
>  
>  image_SOURCES = image.c
>  image_LDADD = libtoytoolkit.la
> diff --git a/clients/terminal.c b/clients/terminal.c
> index 0d4f726..4495530 100644
> --- a/clients/terminal.c
> +++ b/clients/terminal.c
> @@ -33,6 +33,7 @@
>  #include <ctype.h>
>  #include <cairo.h>
>  #include <sys/epoll.h>
> +#include <glib.h>
>  
>  #include <wayland-client.h>
>  
> @@ -942,6 +943,9 @@ redraw_handler(struct widget *widget, void *data)
>  	struct glyph_run run;
>  	cairo_font_extents_t extents;
>  	double average_width;
> +	gunichar unichar;
> +	gboolean iswide;
> +	int extracol;
>  
>  	surface = window_get_surface(terminal->window);
>  	widget_get_allocation(terminal->widget, &allocation);
> @@ -991,22 +995,32 @@ redraw_handler(struct widget *widget, void *data)
>  	glyph_run_init(&run, terminal, cr);
>  	for (row = 0; row < terminal->height; row++) {
>  		p_row = terminal_get_row(terminal, row);
> +		extracol = 0;
>  		for (col = 0; col < terminal->width; col++) {
>  			/* get the attributes for this character cell */
>  			terminal_decode_attr(terminal, row, col, &attr);
>  
>  			glyph_run_flush(&run, attr);
>  
> -			text_x = col * average_width;
> +			/* check dual width unicode character */
> +			unichar = g_utf8_get_char((const char*) p_row[col].byte);
> +			iswide = g_unichar_iswide(unichar);
> +
> +			text_x = (col + extracol) * average_width;
>  			text_y = extents.ascent + row * extents.height;
>  			if (attr.attr.a & ATTRMASK_UNDERLINE) {
>  				terminal_set_color(terminal, cr, attr.attr.fg);
>  				cairo_move_to(cr, text_x, (double)text_y + 1.5);
> -				cairo_line_to(cr, text_x + average_width, (double) text_y + 1.5);
> +				if (iswide)
> +					cairo_line_to(cr, text_x + average_width * 2, (double) text_y + 1.5);
> +				else
> +					cairo_line_to(cr, text_x + average_width, (double) text_y + 1.5);
>  				cairo_stroke(cr);
>  			}
>  
>  			glyph_run_add(&run, text_x, text_y, &p_row[col]);
> +			if (iswide)
> +				extracol++;
>  		}
>  	}
>  
> -- 
> 1.8.1.4
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list