Image32_Ttf

This unit is required when drawing text in cross-platform applications. It requires access to a TrueType font file, which it reads directly. In this unit there are two classes - TFontReader and TGlyphCache.

TFontReader returns raw glyph information primarily though its GetGlyphInfo method and its FontInfo property. Nevertheless, the complexities of TFontReader are managed transparently by TTGlyphCache.

Retrieving font data directly from font files is relatively slow. It's much more efficient to cache the glyph information retrieved and to pre-scale glyphs to a nominated height. This is the role of TGlyphCache and it also provides methods to horizontally and vertically align text within specified regions.

Example:
  var
    notoSansNormFont : TFontReader;
    notoSansNorm14   : TGlyphCache;
    glyphPaths       : TPathsD;
    rec              : TRect;
    nextCharIdx      : integer;
    nextCharPt       : TPointD;
  const
    essay = 'Image32 Rocks!'#10'Write lots of '+
      'interesting things about Image32.';
  begin    
    // create a fontReader and glyphCache ...
    notoSansNormFont := TFontReader.Create;
    notoSansNorm14 := 
      TGlyphCache.Create(notoSansNormFont, 
        DpiAware(14));
    try
      notoSansNormFont.LoadFromResource(
        'NOTOSANSFONT', RT_RCDATA);
      if not notoSansNormFont.IsValidFontFormat then 
        Exit;
        
      rec := Rect(20, 20,
        ClientWidth-20, ClientHeight-20);   

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

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

See Examples FMX2 for a more complete example.

Contents

Types Classes Routines
TArrayOfTKern TFontReader DrawText
TFontFormat TGlyphCache DrawTextVertical
TFontInfo FilterOnFacename
TGlyphMetrics FilterOnStyles
TTable_Glyf GetFacenameAndStyle
TTable_Hmtx GetFontFolder
TTextAlign GetInstalledTtfFilenames
TTextVAlign

See Also

TFontReader, TFontReader.GetGlyphInfo, TFontReader.FontInfo, TGlyphCache