Re: How to create a PangoCairoFontMap?
- From: "Cosmin Humeniuc" <cosmin mandrivausers ro>
- To: "Behdad Esfahbod" <behdad behdad org>
- Cc: gtk-i18n-list gnome org
- Subject: Re: How to create a PangoCairoFontMap?
- Date: Tue, 11 Dec 2007 09:33:36 +0200
On 12/10/07, Behdad Esfahbod <behdad behdad org> wrote:
> On Mon, 2007-12-10 at 12:46 +0200, Cosmin Humeniuc wrote:
> >
> > Hi,
> >
> > I did use that function, but it returns a PangoFontMap*, while
> > pango_cairo_font_map_create_context() asks for a PangoCairoFontMap*,
> > and this leads to the following warning:
> >
> > passing argument 1 of 'pango_cairo_font_map_create_context' from
> > incompatible pointer type
>
> Yes, you need to cast. This is unfortunate but can't be changed now.
>
>
> > And if I use pango_cairo_context_set_font_options() with the returned
> > context, it has no effect.
>
> That's a separate issue and most probably a problem in your code. We
> can check it out if you send a short sample to the list.
Thank you for the reply, Behdad.
Here is an example where I draw some text using Cairo, and then using
Pango with Cairo. Both should have no antialiasing, however only the
former is right.
/*----------*/
#include <string.h>
#include <pango/pangocairo.h>
/** Draw some text using cairo only */
void cairo_draw_text(cairo_t* cr) {
cairo_select_font_face (cr, "Serif", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 48.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 10.0, 50.0);
cairo_font_options_t* options = cairo_font_options_create();
cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_NONE);
cairo_set_font_options(cr, options);
cairo_show_text (cr, "cairo");
}
/** Draw some text using pango with cairo */
void pango_draw_text(cairo_t* cr) {
PangoLayout *layout;
PangoFontDescription *desc;
PangoContext *pango;
PangoFontMap* map;
int width, height;
/* Create a PangoLayout, set the font and text */
layout = pango_cairo_create_layout (cr);
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_set_text (layout, "pango", -1);
desc = pango_font_description_from_string("Serif Bold 48");
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_layout_get_size(layout, &width, &height);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_font_options_t* options = cairo_font_options_create();
cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_NONE);
map = pango_cairo_font_map_get_default();
pango = pango_cairo_font_map_create_context((PangoCairoFontMap*)map);
pango_cairo_context_set_font_options(pango, options);
pango_layout_context_changed(layout);
pango_cairo_update_layout(cr, layout);
cairo_move_to (cr, 10, 30);
pango_cairo_show_layout (cr, layout);
/* free the layout object */
g_object_unref (layout);
}
int main(int argc, char *argv[]) {
cairo_t *cr;
cairo_surface_t *surface;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 320, 240);
cr = cairo_create (surface);
/* Paint the background in white */
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_paint (cr);
cairo_draw_text(cr);
pango_draw_text(cr);
/* Write the output to a file */
cairo_surface_write_to_png (surface, "out.png");
/* Cleanup */
cairo_destroy (cr);
cairo_surface_destroy (surface);
return 0;
}
/*----------*/
Cosmin
>
> --
> behdad
> http://behdad.org/
>
> ...very few phenomena can pull someone out of Deep Hack Mode, with two
> noted exceptions: being struck by lightning, or worse, your *computer*
> being struck by lightning. -- Matt Welsh
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]