back TypeServer QuickTour next
Step 5 - Draw Some Text

Now that we have a Strike defined we're ready to draw some text:


    TSSERVER  myServer=NULL;    /* TypeServer-handle          */
    MGBITMAP  myBitmap=NULL;    /* bitmap-handle              */
    TSFONT    myTTFont=NULL;    /* TrueType font-handle       */
    TSSTRIKE  myStrike=NULL;    /* strike-handle              */
    FIXPOINT  fxPoint;          /* fixed-point x,y-coordinate */
         
    /* create a TypeServer, define a bitmap, open a font, create a strike */
    tsServer_Create( &myServer );
    mgBitmap_CreateDirect( 1024, 768, 8, NULL, &myBitmap );
    tsFont_OpenFile( myServer, "arial.ttf", 0, 0, &myTTFont );
    tsStrike_Create( myFont, myBitmap, &myStrike );
    if ( (myServer==NULL) || (myBitmap==NULL) || (myTTFont==NULL) || (myStrike==NULL) ) 
        { /* handle error condition */ }
        
    /* set text size and color */
    tsStrike_SetTypeSize( myStrike, IntToFix(12), tsPixels );
    tsStrike_SetColorsRGB( myStrike, RGB_Make(0,0,0), RGB_Make(255,255,255) );

    /* draw "Hello World" starting at pixel location (80.0, 100.0) */
    fxPoint.x = IntToFix(80);
    fxPoint.y = IntToFix(100);
    tsStrike_DrawStringA( myStrike, &fxPoint, "Hello World" );

To provide true WYSIWYG accuracy, TypeServer uses fixed-point coordinates based on quick integer math.  Fixed-point coordinates provide sub-pixel accuracy needed to minimize pixel rounding and cummulative positioning errors.

TypeServer includes a complete set of functions for drawing text, and computing character and string dimensions for size-specific CHAR, WCHAR, and generic TCHAR data types: 

tsStrike_ ASCII
CHAR
Unicode
WCHAR
Generic
TCHAR
get character dimensions GetCharExtentA() GetCharExtentW() GetCharExtentT()
get string dimensions GetStringExtentA() GetStringExtentW() GetStringExtentT()
draw character DrawCharA() DrawCharW() DrawCharT()
draw string DrawStringA() DrawStringW() DrawStringT()

TypeServer Strike and Bitmap

next»


Home | Products | Order | Register | Support | Company | Contact | Feedback

Copyright © 1999-2001 - Metagraphics Software Corporation.