[cairo] Newbie questions on fonts

Fred Clare fred at ucar.edu
Tue Oct 16 18:22:09 PDT 2007


Brian and Björn,


On Oct 16, 2007, at 9:54 AM, Baz wrote:

> 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)....

No need for such a slap.  I had followed the recent thread on problems
with displaying text in pdf output on a Mac using Preview.  That is why
I was using PostScript output and viewing with Ghostscript.

> 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.

Well, I just tried X11 output and get the same rectangles using the
font /Library/Fonts/ArialHB.ttf.  *However* when I try using the Vera
.ttf fonts they seem to work fine.  So, I think I have quite a few fonts
to work with.  Is there a way to use the fonts distributed with  
Ghostscript
with freetype?    It would appear that not all .ttf fonts are created
equal, since I seem to get the rectangles with several of them.  In
particular I downloaded a greek .ttf font that is producing the  
rectangles.
Or, possibly more likely, I am doing something dumb.

> 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...

Thanks for the pointers on my code below and for all your help,
you have been most patient with a beginner.

Fred



>
> 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