Forum > Other

(Fpgui) Why can't assign Tfpgfont to this font?

(1/2) > >>

vkhoa:
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

--- Code: ---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. 
--- End code ---

engkin:
You are using the font file name, while you are supposed to use the typeface name. For this font use: VNI-Bamas

vkhoa:
You say right, but even though I has changed it to typeface name, nothing changed

Graeme:
On my system the font name appears as "VNI\-Bamas".

Graeme:
Attached is a zip archive of a working project. Initially the applications starts up and paints the text using the default font defined by fpGUI (plus Tahoma - as selected in code). Output looks fine. See first screenshot.

Then select the VNI font with the font dialog, at which point the output looks like screenshot 2. Now the lines appear slightly different - not sure why. Maybe the VNI font doesn't have specific glyphs.

Selecting the Unifont font (a GPL v2 font with ALL glyphs for the Unicode BMP), then the lines look identical again. So the display and attached test app seems to work just fine.

Just curious: What language is that text?

Navigation

[0] Message Index

[#] Next page

Go to full version