Ft2lib

From EDM2
Jump to: navigation, search

Using Innotek FT2LIB for your own applications

This article is intended to explain how to use the ft2lib (anti-aliasing typeface support by Innotek (Now part of Oracle) in your own applications. It will not discuss in detail how this library works.

Modes of operation

There are 2 ways ftlib can be used from within your application:

  • Intercept all Gpi* API calls, and replace them with ft2lib variants.
  • Use the ft2lib Gpi* API variants within your application directly.

The first has some ease of use advantages over the second. If you replace all Gpi* calls you don't have to actually recode your program to use ft2lib, but you simply tell ft2lib to intercept all Gpi* calls. The second advantage of this approach is that on systems without ft2lib installed your application works as well, just without antialiasing.

Using the second method of course gives you the advantage that you will have full control over where ft2lib is used and where not. This will allow you to use ft2lib within the WPS without enabling ft2lib for the whole WPS.

Intercept all Gpi* API calls

On netlabs you will find a little ft2lib enablement library: ft2lib enablement package. This package is needed for this sample. I will not outline a complete PM program, since I figure that you know how to do that. This will just contain code snipets on how to do it:

#include <ft2lib.h> //Include the ft2lib functions

Now some where in your 'main' line you have to add the following line:

Ft2EnableFontEngine(TRUE);

make sure upon linking to add ft2lib.lib to your make statement.

Use Ft2Lib Ft2* API variants

The above example is a All or nothing solution, you don't have control over the drawing of individual texts with FT2LIB. This Section shows you how you can do that:

#include <ft2lib.h> //Include the ft2lib functions

Now comes the big difference compared to the code above, you have to modify all your GPI* calls into ft2lib calls sample:

case WM_PAINT:
      /*
       * Window contents are drawn here in WM_PAINT processing.
       */
      {
      HPS    hps;                       /* Presentation Space handle    */
      RECTL  rc;                        /* Rectangle coordinates        */
      POINTL pt;                        /* String screen coordinates    */
                                        /* Create a presentation space  */

      char *fonts[] = {"Helvetica", NULL};
      FATTRS fattr;
      APIRET ret;

      hps = WinBeginPaint( hwnd, 0L, &rc );

      memset(&fattr, 0, sizeof(FATTRS));
      fattr.usRecordLength = sizeof(FATTRS);
      //fattr.fsSelection    = FATTR_SEL_ITALIC;
      fattr.lMatch         = 0;

      strcpy(fattr.szFacename, fonts[0]);
      ret = Ft2CreateLogFont(hps, NULL, 1, &fattr);

      Ft2SetCharSet(hps, 1);

      WinFillRect( hps, &rc, SYSCLR_WINDOW);
      pt.x = 50; pt.y = 50;             /* Set the text coordinates,    */
      Ft2SetColor( hps, CLR_NEUTRAL );         /* colour of the text,   */
      Ft2SetBackColor( hps, CLR_BACKGROUND );  /* its background and    */
      Ft2SetBackMix( hps, BM_OVERPAINT );      /* how it mixes,         */
                                               /* and draw the string...*/
      Ft2CharStringAt( hps, &pt, (LONG)strlen( szString ), szString );
      WinEndPaint( hps );                      /* Drawing is complete   */
      break;
      }

on Netlabs ftp you find ft2lib usage samples it is a modified Hello world from the OS/2 toolkit, there is a simple instruction inside the code on what is done.