Recent

Author Topic: [ptcGraph] How to use InstallUserFont function  (Read 516 times)

Roland57

  • Sr. Member
  • ****
  • Posts: 310
[ptcGraph] How to use InstallUserFont function
« on: July 28, 2022, 02:23:44 pm »
Hello!

I tried to use the InstallUserFont function from the ptcGraph unit.

Here is my code:

Code: Pascal  [Select][+][-]
  1. uses
  2. {$IFDEF unix}
  3.   cThreads,
  4. {$ENDIF}
  5.   ptcGraph, ptcCrt;
  6.  
  7. procedure ChangeFont(const aFontName: string; const aSize: word);
  8. const
  9.   fontError = -1;
  10. var
  11.   font: smallint;
  12. begin
  13.   font := InstallUserFont(aFontName);
  14.   if font = fontError then
  15.   begin
  16.     WriteLn(ErrOutput, {$I %FILE%} + ' line ' + {$I %LINE%} + ': Failed to change font');
  17.     Exit;
  18.   end;
  19.   WriteLn('font = ', font);
  20.   SetTextStyle(font, HorizDir, aSize);
  21. end;
  22.  
  23. var
  24.   gd, gm: smallint;
  25.  
  26. begin
  27.   gd := VESA;
  28.   gm := m800x600x16m;
  29.   InitGraph(gd, gm, '');
  30.   SetBkColor($FFFFFF);
  31.   ClearViewPort;
  32.  
  33.   SetFillStyle(SolidFill, $FF00FF);
  34.   Bar(0, 0, 199, 199);
  35.  
  36.   ChangeFont('SourceCode Pro', 12);
  37.   SetColor($000080);
  38.   OutTextXY(
  39.     (200 - TextWidth('A')) div 2,
  40.     (200 - TextHeight('A')) div 2,
  41.     'A'
  42.   );
  43.  
  44.   ReadKey;
  45.   CloseGraph;
  46. end.
  47.  

I appended this line in ptcgraph/inc/gtext.inc:

Code: Pascal  [Select][+][-]
  1.     function InstallUserFont(const FontFileName : string) : smallint;
  2.  
  3.       begin
  4.          _graphresult:=grOk;
  5.          { first check if we do not allocate too many fonts! }
  6.          if installedfonts=maxfonts then
  7.            begin
  8.               _graphresult:=grError;
  9.               InstallUserFont := DefaultFont;
  10.               WriteLn(ErrOutput, {$I %FILE%} + ' line ' + {$I %LINE%} + ': Too many fonts'); // <---
  11.               exit;

I don't get any error message, but it doesn't work: on the screen I still have the default font (see screenshot).

What am I doing wrong?

P.-S. I use (I believe) the latest ptcGraph version. I downloaded it with this command:

Code: Bash  [Select][+][-]
  1. timestamp=$(date +"%Y%m%d")
  2. svn checkout https://svn.code.sf.net/p/ptcpas/code/trunk ptcpas-code-$timestamp
« Last Edit: July 28, 2022, 02:29:24 pm by Roland57 »

retronick

  • New Member
  • *
  • Posts: 17
Re: [ptcGraph] How to use InstallUserFont function
« Reply #1 on: August 04, 2022, 02:54:34 am »
I can only comment from using from Windows but ptcgraph does not distribute the *.chr font files. Grab them from my github.
it does not use true type fonts.

https://github.com/RetroNick2020/Channel-Code/tree/master/freepascal/BGI%20CHR%20Font%20Demo


Roland57

  • Sr. Member
  • ****
  • Posts: 310
Re: [ptcGraph] How to use InstallUserFont function
« Reply #2 on: August 04, 2022, 08:48:30 am »
Thanks. The demo works on Linux, and looks nice.  :)

If I understand well, goth.inc has been generated from GOTH.CHR?


retronick

  • New Member
  • *
  • Posts: 17
Re: [ptcGraph] How to use InstallUserFont function
« Reply #3 on: August 25, 2022, 06:22:41 am »
yes - correct. you can convert any of the fonts into an array so they can be part of your exe. use the freepascal/lazarus tool data2inc to generate the array from the font file. is located in the bin folder




 

TinyPortal © 2005-2018