Recent

Author Topic: (Fpgui) Why can't assign Tfpgfont to this font?  (Read 10101 times)

vkhoa

  • New Member
  • *
  • Posts: 47
(Fpgui) Why can't assign Tfpgfont to this font?
« on: February 25, 2015, 06:18:12 am »
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: [Select]
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. 

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #1 on: February 25, 2015, 01:44:08 pm »
You are using the font file name, while you are supposed to use the typeface name. For this font use: VNI-Bamas

vkhoa

  • New Member
  • *
  • Posts: 47
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #2 on: February 26, 2015, 04:16:58 am »
You say right, but even though I has changed it to typeface name, nothing changed

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #3 on: February 28, 2015, 01:11:32 am »
On my system the font name appears as "VNI\-Bamas".
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #4 on: February 28, 2015, 01:21:40 am »
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?

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #5 on: February 28, 2015, 01:27:43 am »
Just thought I would mention.... I don't visit these forums much, so might miss questions asked. I recommend you post fpGUI support questions in the official fpGUI support newsgroups. You can use any News (NNTP) client (eg: Mozilla Thunderbird, Claws-Mail, XanaNews etc), or the web interface to read and post in those newsgroups.

Details on how to connect:
  http://fpgui.sourceforge.net/support.shtml
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

vkhoa

  • New Member
  • *
  • Posts: 47
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #6 on: February 28, 2015, 07:38:48 am »
Thanks very much for the replies!
Weird, it not worked for me, I use windows xp
I think the problem the the font face name
in screenshot1, when any font which contains "-", "@", "." is chosen, the preview text example didn't apear in that font
then I rename the font that doesn't contain those characters above, the form displayed correctly (screenshot2)
Can anyone tell me how to assign the tfpgfont to font name with those characters, is it needed to use any kind of escape character? (I have placed "\", "/" before "-" but it is not worked)

The string  'Chào tất cả các bạn' is in Vietnamese, it means "Hello everybody"
« Last Edit: February 28, 2015, 07:53:40 am by vkhoa »

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #7 on: February 28, 2015, 11:37:45 am »
OK, I haven't tried using your VNI font under Windows. Later today I'll give it a try. I think  I have an idea of what could cause the problem. Thanks for the extra information, it should help a lot.
« Last Edit: February 28, 2015, 07:03:11 pm by Graeme Geldenhuys »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #8 on: February 28, 2015, 07:01:41 pm »
Weird, it not worked for me, I use windows xp. I think the problem the the font face name in screenshot1, when any font which contains "-", "@", "." is chosen, the preview text example didn't appear in that font
Please get an update from Git and switch to the release-1.4 branch which contains some last minute fixes that aren't in the develop branch yet - but will be soon. Anyway, issue was that the tokenizer that splits up a font description (eg: Arial-12:bold) into its various parts, did not accept the '-', or '@' characters as part of the font name. This has now been fixed and tested on Win2000. I also fixed the Font Dialog which also uses the same tokenizer.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

vkhoa

  • New Member
  • *
  • Posts: 47
Re: (Fpgui) Why can't assign Tfpgfont to this font?
« Reply #9 on: March 01, 2015, 08:04:45 am »
I downloaded the fix, it worked
thanks :)

 

TinyPortal © 2005-2018