Igpprivatefontcollection. addfontfile: loads the font from the file;
Igpprivatefontcollection. addmemoryfont: loads fonts from memory
Addfontfile test:
Uses gdiplus; function getfontsdirectory: string; var Len: integer; Buf: array [0 .. MAX_PATH-1] of char; begin getwindowsdirectory (BUF, length (BUF); Result: = BUF + '\ fonts \'; end; Procedure tform1.formpaint (Sender: tobject); var fontcollection: igpprivatefontcollection; fontfamily: igpfontfamily; Font: igpfont; graphics: igpgraphics; brush: igpsolidbrush; point: tgppointf; begin fontcollection: = tgpprivatefontcollection. create; fontcollection. addfontfile (getfontsdirectory + 'msyh. ttf'); // fonfonfontcollection. addfontfile (getfontsdirectory + 'simhei. ttf'); // fontcollection. addfontfile (getfontsdirectory + 'simli. ttf'); // fontcollection. addfontfile (getfontsdirectory + 'simkai. ttf'); // returns the gb2312 graphics: = tgpgraphics. create (handle); brush: = tgpsolidbrush. create (tgpcolor. red); point. initialize (10, 10); For fontfamily in fontcollection. families do begin Font: = tgpfont. create (fontfamily, 16, fontstyleregular, unitpixel); graphics. drawstring (fontfamily. familyname, Font, point, brush); point. y: = point. Y + font. getheight (0); // when the parameter is 0 or nil, unitpixel end must be specified for font creation; end;
Addmemoryfont test:
uses GdiPlus;procedure TForm1.Button1Click(Sender: TObject);var Stream: TMemoryStream; FontCollection: IGPPrivateFontCollection; FontFamily: IGPFontFamily; Font: IGPFont; Graphics: IGPGraphics; Brush: IGPSolidBrush; Point: TGPPointF;begin Stream := TMemoryStream.Create; Stream.LoadFromFile('C:\Windows\Fonts\msyhbd.ttf'); FontCollection := TGPPrivateFontCollection.Create; FontCollection.AddMemoryFont(Stream.Memory, Stream.Size); FontFamily := FontCollection.Families[0]; Font := TGPFont.Create(FontFamily.FamilyName, 24); Brush := TGPSolidBrush.Create(TGPColor.Create(0, 0, 0)); Point.Initialize(10, 10); Graphics := TGPGraphics.Create(Handle); Graphics.DrawString(FontFamily.FamilyName, Font, Point, Brush); Stream.Free;end;