Forum > Graphics
[ptcGraph] How to use InstallUserFont function
(1/1)
Roland57:
Hello!
I tried to use the InstallUserFont function from the ptcGraph unit.
Here is my code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses{$IFDEF unix} cThreads,{$ENDIF} ptcGraph, ptcCrt; procedure ChangeFont(const aFontName: string; const aSize: word);const fontError = -1;var font: smallint;begin font := InstallUserFont(aFontName); if font = fontError then begin WriteLn(ErrOutput, {$I %FILE%} + ' line ' + {$I %LINE%} + ': Failed to change font'); Exit; end; WriteLn('font = ', font); SetTextStyle(font, HorizDir, aSize);end; var gd, gm: smallint; begin gd := VESA; gm := m800x600x16m; InitGraph(gd, gm, ''); SetBkColor($FFFFFF); ClearViewPort; SetFillStyle(SolidFill, $FF00FF); Bar(0, 0, 199, 199); ChangeFont('SourceCode Pro', 12); SetColor($000080); OutTextXY( (200 - TextWidth('A')) div 2, (200 - TextHeight('A')) div 2, 'A' ); ReadKey; CloseGraph;end.
I appended this line in ptcgraph/inc/gtext.inc:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- function InstallUserFont(const FontFileName : string) : smallint; begin _graphresult:=grOk; { first check if we do not allocate too many fonts! } if installedfonts=maxfonts then begin _graphresult:=grError; InstallUserFont := DefaultFont; WriteLn(ErrOutput, {$I %FILE%} + ' line ' + {$I %LINE%} + ': Too many fonts'); // <--- 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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---timestamp=$(date +"%Y%m%d")svn checkout https://svn.code.sf.net/p/ptcpas/code/trunk ptcpas-code-$timestamp
retronick:
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:
Thanks. The demo works on Linux, and looks nice. :)
If I understand well, goth.inc has been generated from GOTH.CHR?
retronick:
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
Navigation
[0] Message Index