mardi 1 avril 2014

Load font from resource using Firemonkey GDI+ canvas


Vote count:

0




I have a Firemonkey app which uses GDI+ for drawing (set GlobalUseDX10 and GlobalUseDirect2D) to False). From what I see in the Firemonkey's source, the GDI+ canvas is the only one that implements the LoadFontFromStream function (in FMX.Canvas.GDIP.pas).


The problem is I can't manage to find an example on how to use that. I tried the following code:



procedure TForm1.FormCreate(Sender: TObject);
var f1,f2,f3,f4,f5: TResourceStream;
begin
f1 := TResourceStream.Create(hInstance, 'OPENSANSBOLD', RT_RCDATA);
f2 := TResourceStream.Create(hInstance, 'OPENSANSEXTRABOLD', RT_RCDATA);
f3 := TResourceStream.Create(hInstance, 'OPENSANSLIGHT', RT_RCDATA);
f4 := TResourceStream.Create(hInstance, 'OPENSANSREGULAR', RT_RCDATA);
f5 := TResourceStream.Create(hInstance, 'OPENSANSSEMIBOLD', RT_RCDATA);
Form1.Canvas.LoadFontFromStream(f1);
Form1.Canvas.LoadFontFromStream(f2);
Form1.Canvas.LoadFontFromStream(f3);
Form1.Canvas.LoadFontFromStream(f4);
ExisitingLabel.Font.Family := 'Open Sans';
end


The resource is found, the font is loaded but I can't seem to apply it to the label. What could be the problem?



asked 44 secs ago






Aucun commentaire:

Enregistrer un commentaire