Img32.Text

This unit is required when drawing text, and can be used cross-platform. Only TrueType fonts are supported, and these can be loaded either indirectly via operating system function calls, or directly from TTF files or compiled application resources. The unit contains three important classes - TFontReader, TFontManager and TGlyphCache.

TFontReader objects return raw glyph information primarily though its GetGlyphInfo method and its FontInfo property. However because directly accessing this data is slow, this is best circumvented by using TGlyphCache objects. TGlyphCache objects not only dramatically speed up text rendering, the class also provides numerous methods to greatly simplify displaying text.

The TFontManager class is intended primarily as a single instance class that's instantiated automatically, and accessed via the FontManager function. As its name implies, it manages font (ie TFontReader) construction and destruction. Multiple instances of TFontManager are permitted and may be useful on occasions.

Example:
  var
    font            : TFontReader;
    notoSans14      : TGlyphCache;
    glyphPaths      : TPathsD;
    rec             : TRect;
    nextCharIdx     : integer;
    nextCharPt      : TPointD;
  const
    essay = 'Img32 Rocks!'#10'Write lots of '+
      'interesting things about Img32.';
  begin    
    //get a font which will be destroyed by
    //FontManager when the application terminates
    font := FontManager.LoadFromResource(
        'NOTOSANSFONT', RT_RCDATA);
    if not font.IsValidFontFormat then Exit;        
        
    //create a 'glyphCache' using the 
    //specified font with size = 14
    notoSans14 := 
      TGlyphCache.Create(font, DpiAware(14));
    try    
      rec := Rect(20, 20,
        ClientWidth-20, ClientHeight-20);   

      // get the text outlines (glyphs) ...  
      notoSans14.GetTextGlyphs(rec, essay,
        taJustify, tvaMiddle, glyphPaths, 
        nextCharIdx, nextCharPt);

      // now draw the text
      DrawPolygon(imgMain,
        glyphPaths, frNonZero, clBlack32);
        
    finally
      notoSans14.Free;
    end;
            

See Examples FMX2 for a more complete example.

Contents

Types Classes Routines
PGlyphInfo TFontManager DrawAngledText
TArrayOfTKern TFontReader DrawText
TFontFormat TGlyphCache DrawVerticalText
TFontInfo FontManager
TGlyphInfo GetFontFolder
TGlyphMetrics GetInstalledTtfFilenames
TMacStyle GetTextGlyphsOnPath
TMacStyles
TTable_Glyf
TTable_Hmtx
TTextAlign
TTextVAlign

See Also

TFontManager, TFontReader, TFontReader.GetGlyphInfo, TFontReader.FontInfo, TGlyphCache, FontManager