Gdiplus [24]: igpprivatefontcollection: loads fonts from files and memory respectively.

Source: Internet
Author: User
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;
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.