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 TFontCache.

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 TFontCache objects. TFontCache 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      : TFontCache;
    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 'fontCache' using the 
    //specified font with size = 14
    notoSans14 := 
      TFontCache.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 TFontCache DrawAngledText
TArrayOfTKern TFontManager DrawText
TFontFormat TFontReader DrawVerticalText
TFontInfo TWordInfoList FillWordList
TGlyphInfo FontManager
TGlyphMetrics GetFontFolder
TMacStyle GetInstalledTtfFilenames
TMacStyles GetPageMetrics
TTable_Glyf GetTextGlyphsOnPath
TTable_Hmtx
TTextAlign
TTextPageMetrics
TTextVAlign

See Also

TFontCache, TFontManager, TFontReader, TFontReader.GetGlyphInfo, TFontReader.FontInfo, FontManager