The program is to change the font name in the text box, click Display to repaint in the font. THe font file is in a kind of encoding (VNI) of my language. Please rename the attachment to "VBAMASN.ttf" and install it then run the program
program DrawVniChars;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,SysUtils,strutils,
fpg_main,
fpg_base,
fpg_form,fpg_widget,fpg_button,fpg_edit,
fpg_panel;
type
frm1= class;
mywg =class(TfpgWidget)
public
frm:frm1;
procedure HandlePaint;override;
end;
frm1= class(TfpgForm)
private
pn:mywg;
bt:tfpgbutton;fontnameedit:tfpgedit;
public
procedure AfterCreate; override;
procedure pnclick(obj:tobject);
end;
procedure mywg.HandlePaint;
var s,ch:string;i,w,leftt:integer;fnt:tfpgfont;
begin
s:='Chaøo taát caû caùc baïn ẫ';
Canvas.Clear(clwhite);
Canvas.SetFont(fpgGetFont(frm.fontnameedit.Text));
Canvas.DrawText(5, 5,200,30,'Chaøo taát caû caùc baïn ẫ',textflagsdflt,2);
Canvas.SetFont(fpgGetFont('tahoma'));
Canvas.DrawText(5, 45,200,30,'Chào tất cả các bạn ẫ',textflagsdflt,2);
fnt:=fpgGetFont(frm.fontnameedit.Text);
Canvas.SetFont(fnt);
canvas.drawtext(5,95,30,10,'font desc: "'+fnt.FontDesc+'"',textflagsdflt,2);
canvas.drawtext(5,115,30,10,'if it is displayed correctly, line 1 looks similar to line 2',textflagsdflt,2);
canvas.drawtext(5,135,30,10,'line 1, 3 will be in font which name is in textbox',textflagsdflt,2);
{leftt:=5;
for i:=1 to length(s) do begin
ch:=midstr(s,i,1);
w:=fnt.TextWidth(ch);
canvas.drawtext(leftt,135,30,10,ch,textflagsdflt,2);
leftt+=w;
end;}
end;
procedure frm1.pnclick(obj:tobject);
begin
pn.Invalidate;
end;
procedure frm1.AfterCreate;
var fnt:tfpgfont;
begin
Name := 'd';
SetPosition(581, 313, 640, 325);
WindowTitle := 'Draw Vni characters';
Hint := '';
//fnt:=tfpgfont.Create();
pn:=mywg.Create(self);
pn.SetPosition(5,5,700,220);
pn.frm:=self;
fontnameedit:=tfpgedit.Create(self);
fontnameedit.SetPosition(5,pn.Top+pn.Height,200,30);
fontnameedit.Text:='VBAMASN';
bt:=tfpgbutton.Create(self);
bt.SetPosition(5,fontnameedit.Top+fontnameedit.Height,200,30);
bt.Text:='Display';
bt.OnClick:=@pnclick;
end;
procedure MainProc;
var
frm: frm1;
begin
fpgApplication.Initialize;
frm := frm1.Create(nil);
try
frm.Show;
fpgApplication.Run;
finally
frm.Free;
end;
end;
begin
MainProc;
end.