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: 01 Oct 2002 02:36:17 +0200

On Tue, 2002-10-01 at 01:50, Callum Prentice wrote:
> firstly, thank you very much vincent for taking the time to go through all of 
> that -
> your notes / examples helped enormously.

You're welcome. I was once the same guy looking for those answers :)


> ---------- snip ----------
> FT_Set_Pixel_Sizes ( face, 64, 0 );

You should provide the same width and height (ie. 64, 64), you should
actually zero-height glyphs with this call ! :)


> from chinese web pages and used them in the FT_Load_Char ( face, L'¥_', 
> FT_LOAD_RENDER )
> call along with a chinese character font (simhei.ttf) but have had no luck.  
> using an
> integer value instead of a wide character - e.g. 32563 - works perfectly so i 
> think i'm
> missing a call - perhaps something to specifiy to encoding scheme.

You'll have to dive into the world of 'charmaps'. Font files embed zero,
one or more charmaps. Each charmap provides a mapping from a character
code using a well known encoding (Latin1, GB2313, KOI8-R, Unicode) to
the internal glyph number.

First thing, check available charmaps in your simhei.ttf file. Quick
test : use the 'ftdump' program included in the ft2demos package. It'll
display available charmaps in a 'raw form' (using TrueType IDs in your
case, lookup the TT_PLATFORM_* and subsequent macros in
<freetype/ttnameid.h>).

Then you'll have sooner or later to make this check at runtime. FreeType
will select the Unicode charmap if it's present as a default, so you'll
want to do first :

if (face->charmap->num_charmaps)
  bailout("Ouch, no charmap at all"); /* Happens with 'symbolic fonts'
such as windings */

if (face->charmap->encoding == FT_ENCODING_UNICODE)
  cool("we have a Unicode charmap and it's selected");

What's left ? If you want to support Chinese glyphs, you can still try
it with GB2312 or BIG5 (rather popular over there) :

/* Scan available charmaps */
int gotcha = 0;
for (i = 0; i < face->num_charmaps && !gotcha; i++)
{
  switch (face->charmaps[i]->encoding)
  {
    case FT_ENCODING_GB2313:
    case FT_ENCODING_BIG5:
      FT_Set_Charmap(face, face->charmaps[i]);
      gotcha = 1;
      break;
  }
}

Now the whole story depends on your native data format. If you're
Unicode (UCS2 or UCS4) all the way, then you can make a
Unicode->{gb2313, big5) on-the-fly conversion method which is
automatically called before calling FT_Get_Char() or FT_Load_Char(). You
can either consider iconv() (part of GNU libc under Linux, fetch
libiconv or libicu on other OSes), either setup your own tables if you
only have a few conversions to do.


> 2/ speed - potentially there will be a lot of text being drawn along with 
> some real time
> input in text entry fields for example - i'm hoping this method will be fast 
> enough for
> that.

This is the cache part. The API is not really straight forward. Not hard
to use, but it lacks the whole picture, ie. a tutorial. Short answer :
caches are used in ft2demos/src/ftcommon.i, have a look. All cache have
a FTC_ prefix to their API. You basically cache both charmap and glyph
lookups.

Long answer : this would actually be a _long_ answer. David, Werner &
co, are you interested in my attempt to write a tutorial on the cache
topic ? (It'll take some time, I'm lacking free time ! :-/)

I'm about to release some code based on this experience, however it's
still not self explanatory IMHO. Anyway it's already public, crawl in it
if you like :

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ngl/ngl/src/font/nglFontBase_shr.cpp?rev=1.25&content-type=text/vnd.viewcvs-markup


It's a generic support class, I'm using it for glyph rendering under
OpenGL (yes, I know about other similar projects :)). Oh BTW, it's evil
C++ :)





reply via email to

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