freetype-devel
[Top][All Lists]
Advanced

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

Re: [Devel] A beginners question


From: Vincent Caron
Subject: Re: [Devel] A beginners question
Date: 30 Sep 2002 23:37:26 +0200

On Mon, 2002-09-30 at 23:04, Callum Prentice wrote:
> --------------- snip ---------------
> FT_Library library;
> FT_Init_FreeType ( &library );
> 
> FT_Face face;
> FT_New_Face ( library, "c:/windows/fonts/arial.ttf", 0, &face );

Note: you're loading a scalable font, expect vectorial data. If you load
a bitmap font (such as Window's FNT ones), there's no need for
'rendering' the glyph, it's already pixels.


> int charCode = 'A';
> int glyph_index = FT_Get_Char_Index ( face, charCode );
> 
> std::wcout << L"glyph index is " << glyph_index << std::endl;
> 
> FT_Glyph glyph;
> FT_Load_Char ( face, glyph_index, FT_LOAD_DEFAULT );

FT_Load_Char expects a character code relative to the selected charmap.
Your truetype font has a Unicode charmap, and it's automatically
selected for you at loading time. So feed Unicode to this function.

Here you're making a confusion with FT_Load_Glyph which expects a glyph
index. Either use FT_Load_Char alone or the
FT_Get_Char_Index+FT_Load_Glyph combo.


> FT_Get_Glyph ( face->glyph, &glyph );
> 
> FT_Glyph_To_Bitmap ( &glyph, ft_render_mode_normal, 0, 1 );
> 
> FT_BitmapGlyph  glyph_bitmap;
> glyph_bitmap = (FT_BitmapGlyph)glyph;
> 
> FT_Bitmap myBitmap = glyph_bitmap->bitmap;

Nice thing to know : if you use FT_Load_Char(..., FT_LOAD_RENDER)
instead of FT_LOAD_DEFAULT, the face's glyphslot will contain a rendered
bitmap (ie. FT_BitmapGlyph), instead of bare vectorial data (ie.
FT_OutlineGlyph). It saves these last 5 lines. And also extra (useless)
work when you're loading bitmap fonts.


> --------------- snip ---------------

> so, it all looks like it's probably working except that the number of rows is 
> 1 and
> width/pitch is 2 which can't be correct.

You forgot to set the font size. Remember, it's (unscaled) vectorial
data. Use FT_Set_Pixel_Sizes and you're done. It's simpler with bitmap
fonts since most of all have only one instance of a face at a given
size, so you obviously don't have to select any size.


> could someone who's done this before tell me if (a) this currently the best 
> method to
> use and (b) if this is it, suggest why it's not working.

You still have to discover the intricacy of the caches and font metrics
:) Have a deep look at the doc and the function reference, it's very
well done.





reply via email to

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