freetype
[Top][All Lists]
Advanced

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

Glyph rotation with FreeType2


From: Fleischer, Karsten (K.)
Subject: Glyph rotation with FreeType2
Date: Fri, 25 Aug 2000 07:45:46 -0400

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

Did I do something wrong, or is this a bug?

Karsten



reply via email to

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