Hi,
I'm trying to use FontAwesome icons set in my application (
http://fortawesome.github.io/Font-Awesome/cheatsheet/ ) . It is based on font and source is published in many formats like: EOT (didn't check), SVG, TTF, WOFF (didn't check), OTF. Everything fails except TTF (true type font). I have problem with true type transparent. Here is what I tried so far:
1. The best way would be to use FontAwesome as system font. But I can't force user to install font before run my application. So I searched for runtime routines. I found AddFontResource but it is from windows unit and I need cross-platform solution. Could not find anything for Qt/Gtk widgetset. As system font it works perfect for any kind of controls like TLabel, TSpeedButton etc.
2. The easiest way would be just install font on my develop environment, use this font in Gimp/Photoshop and save as PNG icon. I'll use this solution when everything else fail. But I insist to use it as native FPC
3. Finally I got it working with EasyLazFreeType. The problem is with transparent background. Only way I found is fill background with clFuchsia color and use it as TBitmap.TransparentColor. But it is 0 or 1so in place where antialiased pixels are drawed I still see fuchsia color (look at attached image). I tried with mask property but no result. There is a lot of layers: drawer, bitmap, interface image. Maybe I'm doing something wrong. Any idea? Here is working example (you need FontAwesome.ttf from attachments)
uses fpimage, LCLType, IntfGraphics, GraphType,
EasyLazFreeType, LazFreeTypeIntfDrawer;
function CreateFAIcon(constref ACode: String; ASize: Byte=16): TBitmap;
var
img: TLazIntfImage;
d: TIntfFreeTypeDrawer;
f: TFreeTypeFont;
begin
Result := TBitmap.Create;
img := TLazIntfImage.Create(0,0, [riqfRGB]);
d := TIntfFreeTypeDrawer.Create(img);
f := TFreeTypeFont.Create;
try
f.Name := 'FontAwesome.ttf';
f.SizeInPixels := ASize;
f.Hinted := true;
f.ClearType := true;
f.Quality := grqHighQuality;
f.SmallLinePadding := false;
img.SetSize(ASize,ASize);
//d.FillPixels(TColorToFPColor(clWhite));
//d.FillPixels(colTransparent);
d.FillPixels(TColorToFPColor(clFuchsia));
//d.FillPixels(TColorToFPColor(clNone));
d.DrawText(ACode, f, ASize, ASize, colBlack, [ftaRight, ftaBottom]);
Result.LoadFromIntfImage(img);
Result.Transparent := True;
Result.TransparentColor := clFuchsia;
finally
f.Free;
d.Free;
img.Free;
end;
end;
And usage:
procedure TForm1.SpeedButton1Click(Sender: TObject);
var b: TBitmap;
begin
b := CreateFAIcon(#239#131#185, 50);
try
SpeedButton1.Glyph.Assign(b);
finally
b.Free;
end;
end;
Regards