[cairo] Newbie questions on fonts
Baz
brian.ewins at gmail.com
Tue Oct 16 08:54:18 PDT 2007
I may have figured out your 'only shows squares' problem. I didn't put
2+2 together that you were getting this problem with pdfs on the Mac,
so you're probably using Preview. (slaps forehead).... Adrian's done a
pile of work since 1.4.10 to improve pdf output, in particular there
were problems displaying pdfs with embedded fonts in Preview - the bug
looks exactly as you describe.
If you're able to, can you check your pdf output with something else -
pretty much anything else workes, eg xpdf, acrobat. Or alternatively,
if you could build with cairo from git, you should get the bugfixed
version. I've raised a bug with Apple about this, hopefully Preview
will be fixed sometime soon.
On to your code...
On 16/10/2007, Fred Clare <fred at ucar.edu> wrote:
> Can you see anything obviously wrong with my complete code?:
A few things not to do with your font problems, none serious...
> #include <math.h>
> #include <stdio.h>
> #include <cairo.h>
> #include <cairo-ps.h>
> #include <cairo-ft.h>
>
> #define FILENAME "text_test.ps"
>
> int main (int argc, char *argv[]) {
>
> FT_Library library;
> FT_Face face;
> int error;
>
> cairo_font_face_t *font_face;
>
> cairo_surface_t *surface;
> cairo_t *cr;
>
This check:
> FILE *file;
> file = fopen (FILENAME, "w");
> if (file == NULL) {
> fprintf (stderr, "Failed to open file %s for writing.\n",
> FILENAME);
> return 1;
> }
... is unnecessary - cairo_ps_surface_create does it too. You can
check the status of the surface returned by cairo_ps_surface_create
instead.
>
> error = FT_Init_FreeType( &library );
> if ( error )
> {
> printf("Error initializing FreeType library\n");
> return 1;
> }
>
> error = FT_New_Face( library,
> "/Library/Fonts/ArialHBBold.ttf",
> 0,
> &face );
> if ( error == FT_Err_Unknown_File_Format )
> {
> printf("The font file could be opened and read, \n but it
> appears that its font format is unsupported\n");
> return 1;
> }
> else if ( error )
> {
> printf("Font file could not be opened or otherwise is broken.
> \n");
> return 1;
> }
>
> font_face = cairo_ft_font_face_create_for_ft_face(face,0);
>
> surface = cairo_ps_surface_create (FILENAME, 600, 600);
> cr = cairo_create (surface);
> cairo_surface_destroy(surface);
>
> cairo_set_font_face(cr, font_face);
> cairo_set_font_size (cr, 30);
> cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
>
> cairo_move_to (cr, 200, 100);
> cairo_show_text (cr, "Magnetic");
>
> cairo_stroke(cr);
This strokes an empty path. cairo_show_text will show the text anyway
(and move the current point).
> cairo_show_page(cr);
> cairo_destroy(cr);
> fclose(file);
Also unnecessary, the file will be closed when you release the surface
(via cairo_destroy)
>
> return 0;
> }
>
> Thanks much.
>
> Fred Clare
no problem.
-Baz
More information about the cairo
mailing list