[cairo] text to postscript rendering
Jürgen Ladstätter
info at innova-studios.com
Thu Feb 28 01:35:26 PST 2008
Hi Carl,
thanks for your reply, it helped me a lot!
I can render now utf8 strings with pango to png files, ascii strings with cairo to png and ps.
Pango + utf8 strings to ps works, but the ps file includes the font, not only the outline as i wanted. Maybe you can give me another hint?
Here is how i currently draw pango + utf8 to eps:
void Pango_PS()
{
cairo_t *cr;
cairo_surface_t *surface;
FILE *file = fopen (FILENAME_P, "w");
if (file == NULL) {
fprintf (stderr, "Failed to open file %s for writing.\n", FILENAME_P);
return;
}
surface = cairo_ps_surface_create (FILENAME_P,
WIDTH * 72.0,
HEIGHT * 72.0);
cr = cairo_create (surface);
cairo_surface_destroy(surface);
PangoLayout *layout;
PangoFontDescription *desc;
layout = pango_cairo_create_layout (cr);
pango_layout_set_text (layout, "A Ε ε £ @ € !\"§$%&/()=äöüÄÖÜ", -1);
cairo_move_to (cr, 10, 30);
cairo_set_font_size (cr, 90.0);
desc = pango_font_description_from_string ("French Script MT 27");
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_cairo_show_layout_line (cr, pango_layout_get_line (layout, 0));
g_object_unref (layout);
cairo_destroy (cr);
fclose (file);
}
Kind regards, juergen
-----Ursprüngliche Nachricht-----
Von: Carl Worth [mailto:cworth at cworth.org]
Gesendet: Mittwoch, 27. Februar 2008 17:02
An: info at innova-studios.com
Cc: 'Behdad Esfahbod'; cairo at cairographics.org
Betreff: Re: [cairo] text to postscript rendering
On Wed, 27 Feb 2008 14:03:50 +0100, Jürgen Ladstätter wrote:
> cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
...
> cairo_text_path(cr, "test text" );
>
> and it works very well, but when i now use special characters like
> $, € there is no useful output. Anything known about that?
Yes. The issue here is that cairo's "toy" functions like
cairo_select_font_face and cairo_text_path only work with a single
font at a time. So when you ask for a glyph that doesn't exist in the
font you selected, you won't get any output for that glyph, (that is,
cairo_text_path doesn't do any "font substitution" for you).
> Are there any other functions to select fonts? Because i cant
> exchange "Sans" with any other font i have in MS Word.
You should be able to select any font available on your system by
family name. Cairo-win32 hackers, any reason this wouldn't be working?
Meanwhile, there is another way to deal with fonts, and that is the
"real" font APIs. They are quite a bit harder to use though. First
you'll have to talk to native win32 APIs to open a font, (either an
HFONT or a LOGFONTW), then call one of these functions:
cairo_win32_font_face_create_for_logfontw
cairo_win32_font_face_create_for_hfont
cairo_win32_font_face_create_for_logfontw_hfont
to create a cairo_font_face_t from which you can then call
cairo_scaled_font_create and cairo_set_scaled_font.
Finally, you will also have to do all your own font substitution and
layout and also manually lookup font-glyph IDs for each glyph you
want, and then call cairo_show_glyphs to actually display the glyphs.
So that's definitely a lot more work, and cairo *still* doesn't do any
of the font substitution for you. :-P
But that "real" API does provide the chance for someone to do all this
hard work and provide a library on top of cairo that provides font
substitution, high-quality layout, line-breaking etc. The pango
library is exactly such a library. And here's a simple program showing
how to use it with cairo:
http://cairographics.org/~cworth/utf8test-pango.c
And pango should work just fine on win32 platforms as far as I
understand, (it's not something I've ever tried though).
Hmm... it's probably time for me to roll all of the above up into a
FAQ entry. This issue does come up every once in a while.
-Carl
More information about the cairo
mailing list