Hello!
I tried to use the
InstallUserFont function from the
ptcGraph unit.
Here is my code:
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:
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:
timestamp=$(date +"%Y%m%d")
svn checkout https://svn.code.sf.net/p/ptcpas/code/trunk ptcpas-code-$timestamp