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
    notoSansFont    : TFontReader;
    notoSans14      : TFontCache;
    glyphPaths      : TPathsD;
    rec             : TRect;
    nextCharIdx     : integer;
    nextCharPt      : TPointD;
  const
    essay = 'Img32 Rocks!'#10'Write lots of '+
      'interesting things about Img32.';
  begin    
    notoSansFont := FontManager.
      LoadFromResource(
      'NOTOSANSFONT', RT_RCDATA);
    if not notoSansFont.IsValidFontFormat then 
      Exit;        
        
    notoSans14 := TFontCache.Create(notoSansFont, 
      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;     
      //notoSansFont.Free; //managed by FontManager 
    end;
    

See Examples FMX2 for a more complete example.

Contents

Types
PGlyphInfo TArrayOfTKern TFontFormat TFontInfo TGlyphInfo TGlyphMetrics TMacStyle TMacStyles TTable_Glyf TTable_Hmtx TTextAlign TTextPageMetrics TTextVAlign

Classes
TFontCache TFontManager TFontReader TWordInfoList

Routines
DrawAngledText DrawText DrawVerticalText FillWordList FontManager GetFontFolder GetInstalledTtfFilenames GetPageMetrics GetTextOutlineOnPath

See Also

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