Example

This example draws the "Hello World" text string shown in Figure 35 using the glyph run geometry. The TGGlyphRun makes a localized system for text layout. Do not use TGGlyphRun to display a text string; use TTextDisplay instead.


    1  TFont theGlyphFont;
    2  
    3  TStandardText theText( "Hello World" );
    4  UniChar unichars[12];
    5  GlyphCode glyphs[12];
    6  TTextCount numberOfChars = theText.Extract(TTextRange::GetMaximumRange(), unichars, 12);
    7  theGlyphFont.MapCharactersToGlyphs( numberOfChars, unichars, glyphs);
    8  GCoordinate widths[12];
    9  theGlyphFont.GetAdvanceWidths(numberOfChars, glyphs, widths);
    10  
    11  GCoordinate offsets[12];
    12  offsets[0] = 0.;
    13  
    14  for (long i = 0; i < numberOfCharacters - 1; i++)
    15      offsets[i + 1] = offsets[i] + widths[i];
    16  
    17  TGGlyphRun theGlyphText( theGlyphFont, numberOfChars, glyphs, offsets, NIL, 
    18                              TGPoint( 100, 100 ) );
    19  
    20  thePort.Draw( theGlyphText );
Lines 1 through 9: Create the default system font

Lines 11 through 15: Calculate the X offsets

Lines 17 through 20: Create the glyph run graphic and draw it


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker