[PATCH weston] Add font entry to shell section for title fonts

Pekka Paalanen ppaalanen at gmail.com
Mon Sep 1 04:05:42 PDT 2014


On Thu, 28 Aug 2014 20:31:37 +0900
Ryo Munakata <ryomnktml at gmail.com> wrote:

> cairo-util has used sans font family for title fonts so far.
> But sans doesn't support non-ascii characters.
> So now let users choose a font family for titles.
> 
> The entry name is generic, 'font' so that other places
> where draw texts can use this entry too.
> 
> Signed-off-by: Ryo Munakata <ryomnktml at gmail.com>
> ---
>  man/weston.ini.man  |  3 +++
>  shared/cairo-util.c | 16 +++++++++++++++-
>  shared/cairo-util.h |  1 +
>  weston.ini.in       |  1 +
>  4 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/man/weston.ini.man b/man/weston.ini.man
> index ccd7185..0830255 100644
> --- a/man/weston.ini.man
> +++ b/man/weston.ini.man
> @@ -260,6 +260,9 @@ sets the path to lock screen background image (string). (tablet shell only)
>  .TP 7
>  .BI "homescreen=" path
>  sets the path to home screen background image (string). (tablet shell only)
> +.TP 7
> +.BI "font=" font-family
> +sets the font family name. Title fonts only supported now.
>  .RE
>  .SH "LAUNCHER SECTION"
>  There can be multiple launcher sections, one for each launcher.
> diff --git a/shared/cairo-util.c b/shared/cairo-util.c
> index 26286c5..7bdb8cb 100644
> --- a/shared/cairo-util.c
> +++ b/shared/cairo-util.c
> @@ -337,6 +337,18 @@ theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags)
>  	}
>  }
>  
> +static char *
> +config_get_font_family()
> +{
> +	char *font_family;
> +	struct weston_config *config
> +		= weston_config_parse("weston.ini");
> +	struct weston_config_section *section
> +		= weston_config_get_section(config, "shell", NULL, NULL);
> +	weston_config_section_get_string(section, "font", &font_family, "sans");
> +	return font_family;
> +}
> +
>  struct theme *
>  theme_create(void)
>  {
> @@ -350,6 +362,7 @@ theme_create(void)
>  	t->margin = 32;
>  	t->width = 6;
>  	t->titlebar_height = 27;
> +	t->title_font = config_get_font_family();
>  	t->frame_radius = 3;
>  	t->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
>  	cr = cairo_create(t->shadow);
> @@ -408,6 +421,7 @@ theme_destroy(struct theme *t)
>  	cairo_surface_destroy(t->active_frame);
>  	cairo_surface_destroy(t->inactive_frame);
>  	cairo_surface_destroy(t->shadow);
> +	free(t->title_font);
>  	free(t);
>  }
>  
> @@ -458,7 +472,7 @@ theme_render_frame(struct theme *t,
>  		cairo_clip(cr);
>  
>  		cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
> -		cairo_select_font_face(cr, "sans",
> +		cairo_select_font_face(cr, t->title_font,
>  				       CAIRO_FONT_SLANT_NORMAL,
>  				       CAIRO_FONT_WEIGHT_BOLD);
>  		cairo_set_font_size(cr, 14);
> diff --git a/shared/cairo-util.h b/shared/cairo-util.h
> index fb25c34..060e01b 100644
> --- a/shared/cairo-util.h
> +++ b/shared/cairo-util.h
> @@ -53,6 +53,7 @@ struct theme {
>  	int margin;
>  	int width;
>  	int titlebar_height;
> +	char *title_font;
>  };
>  
>  struct theme *
> diff --git a/weston.ini.in b/weston.ini.in
> index 4fca0bb..6fef17e 100644
> --- a/weston.ini.in
> +++ b/weston.ini.in
> @@ -15,6 +15,7 @@ startup-animation=fade
>  #num-workspaces=6
>  #cursor-theme=whiteglass
>  #cursor-size=24
> +#font=sans
>  
>  #lockscreen-icon=/usr/share/icons/gnome/256x256/actions/lock.png
>  #lockscreen=/usr/share/backgrounds/gnome/Garden.jpg

Hi,

considering that the toytoolkit (well, shared/cairo-util.h here) uses
cairo_show_text(), which is documented as:

	"The cairo_show_text() function call is part of what the cairo
designers call the "toy" text API. It is convenient for short demos and
simple programs, but it is not expected to be adequate for serious
text-using applications. See cairo_show_glyphs() for the "real" text
display API in cairo."
- http://cairographics.org/manual/cairo-text.html#cairo-show-text

I'm not sure being able to choose the font is appropriate. If we wanted
text to work right, we cannot trust any single font to contain all the
needed glyphs, which is what cairo_show_text() assumes. We'd need a
list of fonts to fall back when a glyph is not found.

If this was just about the toytoolkit alone, I would probably not
bother with it, but since we use the same code to draw Xwayland
decorations, maybe doing text rendering properly would be worth it?

Would be much better to rely on pangocairo, as it seems we already use
pangocairo when it's available. When pangocairo is disabled in the
build, we should fall back to the current cairo_show_text().

Does that make sense?


Thanks,
pq


More information about the wayland-devel mailing list