freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Glyph rotation with FreeType2


From: David Turner
Subject: Re: Glyph rotation with FreeType2
Date: Tue, 05 Sep 2000 15:12:57 +0200

Hi Karsten,

"Fleischer, Karsten (K.)" a écrit :
> 
> Hello,
> 
> I just started my first experiments with FreeType2. I decided to use
> FreeType2 because the API seems to be less complex than FreeType1's.
> I have to draw rotated strings, so I started off with the example code from
> docs/tutorial/step1.html. This seemed not to be working, so I changed the
> code a bit:
> 
>         FT_GlyphSlot    slot = face->glyph;
>         FT_Matrix               matrix;
>         FT_Vector               pen;
> 
>         int error, n;
> 
>         matrix.xx = (FT_Fixed) ( cos(angle) * 0x10000);
>         matrix.xy = (FT_Fixed) (-sin(angle) * 0x10000);
>         matrix.yx = (FT_Fixed) ( sin(angle) * 0x10000);
>         matrix.yy = (FT_Fixed) ( cos(angle) * 0x10000);
> 
>         pen.x = 0;
>         pen.y = 0;
> 
>         for(n = 0; n < strlen(string); n++)
>         {
>                 FT_Set_Transform(face, &matrix, NULL);
> 
>                 FT_Load_Char(face, string[n], FT_LOAD_DEFAULT);
> 
>                 FT_Render_Glyph(slot, ft_render_mode_mono);
> 
>                 draw_ft_bitmap(&slot->bitmap, x + slot->bitmap_left + pen.x
> / 64, height - y - slot->bitmap_top - pen.y / 64);
> 
>                 pen.x += slot->advance.x;
>                 pen.y += slot->advance.y;
>         }
> 
> (x, y) is the screen position to draw the text at, height is the
> screen/window height. Error handling omitted.
> 

> I had to change the FT_Load_Char call to FT_LOAD_DEFAULT, as FT_LOAD_DEFAULT
> | FT_LOAD_MONOCHROME didn't give me a bitmap (why?).

Because FT_LOAD_MONOCHROME is only tested when you use FT_LOAD_RENDER.
Otherwise, it's simply ignored (and a vector outline is loaded in the
glyph slot).

> Then, translating with the pen vector in FT_Set_Transform and drawing at
> bitmap_left/top didn't work. The space between the glyphs was too wide. The
> positioning I'm doing is a guess, but it looks OK.

The positioning you're doing is correct and perfectly valid. What the
tutorial shows is that there are various way to perform the same thing,
depending on what specific things are important to you..

I think that the problem you had probably comes from a notorious bug
in Beta 8 that happened with auto-hinted transformed glyphs. Basically,
the transform is applied twice, instead of once. It is fixed in the
current snapshot and I strongly encourage you to upgrade if you
didn't do it yet.. sorry..

That might explain your "space between glyphs is too wide" when using
the pen position in the transform..

> Then another problem came up when angle != 0: The glyph bitmap was rotated
> by 2*angle, but the advance vector by 1*angle! Looks very strange.
> So I set up another matrix with cos(angle/2) etc. for rotating the glyph and
> the above matrix for advancing.
> 
That's definitely the bug I'm talking about..

> Did I do something wrong, or is this a bug?
> 
A bug, please try with the current snapshot. Thanks,

- David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]