

Using errstr18

21. 1. 1998
Erwin Dieterich


If you don't like error messages containing error codes like this:

    test > ftlint 24 furiosot.ttf
    furiosot.ttf: could not find or open file. Error code = 0x0087

and prefer something more informative like this:

    test > ftlint 24 furiosot.ttf
    furiosot.ttf: could not find or open file.
    FreeType error message: OS/2 table missing

then read on. You will find something here that could be helpful  
to you. If you don't care, you can nevertheless read on.


The core engine of FreeType has defined about 50 different error
codes. Nearly all FreeType functions are able to return such an 
error code in case something goes wrong. If you are not able to
memorize the error codes, you have to look them up apiref.txt.
But if you are writing a program that is intended
for "normal" users (e.g. a font lister) you should give those users
more than just some integer or hex number. Errstr18 (located in
lib/extend) offers the possibility to translate a FreeType error code 
into a string describing the error with one function call. Errstr18 
is fully internationalized on Unix computers. So if your environment
variables are set accordingly, errstr18 can return the error strings 
in your language (supposed it is supported). See i18n.txt on how to 
use national language support (NLS), on the languages that are 
supported now and on how to disable NLS. IF NLS is disabled, errstr18 
contains no operating system specific components.


Errstr18 offers only one function:

   char* TT_ErrToString18(int error)

It returns a pointer to a string describing the error that occured.
A simple example on how to use errstr18, extending the code given
in apiref.txt on TT_Open_Face:

      error = TT_Open_Face( engine, "c:\ttf\wingding.ttf", &face );
      if ( error )
        {
          fprintf( stderr, "could not open face\n" );
          fprintf( stderr, "Reason: %s\n", TT_ErrToString18(error) );
        }

Note that in this example no NLS has been used for the strings. With
NLS the code could be written as:

      error = TT_Open_Face( engine, "c:\ttf\wingding.ttf", &face );
      if ( error )
        {
          fprintf( stderr, gettext("could not open face\n") );
          fprintf( stderr, gettext("Reason: %s\n"), TT_ErrToString18(error) );
        }

See i18n.txt for more information on NLS.


If you have any questions or comments regarding this short introduction
to an even shorter function, feel free to email me at 
Erwin.Dieterich.ED@Bayer-AG.de

