unit fontsets; {$MODE OBJFPC} {$M+} interface uses fonts, classes; // TODO avoid refcounting (just use a TFont directly)? type TFontset = class(TInterfacedObject, IFont, IInterface) private fFonts : IInterfaceList; public destructor Destroy(); override; published constructor Create(); procedure AppendFont(const aFont : IFont); function GetGlyph(aCode : Cardinal) : TGlyphP{or nil}; // GetGlyphOrFallback = GetGlyph or FallbackGlyph function GetFallbackGlyph() : TGlyphP; // not nil. // (can't be published in the interface by FPC so exposed as a function, not a property). end; implementation uses sysutils; constructor TFontset.Create(); begin inherited Create(); fFonts := TInterfaceList.Create(); // False); end; destructor TFontset.Destroy(); begin FreeAndNil(fFonts); inherited Destroy(); end; procedure TFontset.AppendFont(const aFont : IFont); begin fFonts.Add(aFont); end; function TFontset.GetGlyph(aCode : Cardinal) : TGlyphP{or nil}; var i : Integer; begin Result := nil; for i := 0 to fFonts.Count - 1 do begin Result := IFont(fFonts[i]).GetGlyph(aCode); if Assigned(Result) then Break; end; end; function TFontset.GetFallbackGlyph() : TGlyphP; // not nil. // (can't be published in the interface by FPC so exposed as a function, not a property). var i : Integer; begin Result := nil; for i := 0 to fFonts.Count - 1 do begin Result := IFont(fFonts[i]).GetFallbackGlyph(); if Assigned(Result) then Break; end; end; end.