Board index » delphi » Using Different Fonts in Pascal

Using Different Fonts in Pascal

Using TPW, or any other compiler, what is the general syntax for changing the
font of some text..

if I wanted:

     writeln ('Hello');
to be displayed in Arial for example, can I have it do that and then have
another line in the source be displayed in Times New Roman?

Thank you (email @  Nie...@aol.com )

 

Re:Using Different Fonts in Pascal


Quote
NieNen wrote in message <19981121155842.01218.00000...@ng-fa1.aol.com>...
>Using TPW, or any other compiler, what is the general syntax for changing
the
>font of some text..

>if I wanted:

>     writeln ('Hello');
>to be displayed in Arial for example, can I have it do that and then have
>another line in the source be displayed in Times New Roman?

>Thank you (email @  Nie...@aol.com )

I don't think you can do that.  The text editor included with tpw is lousy
by any and all standards.  If you need to do something like that, use a
dedicated text editor like MSWord.

Nikita.

Re:Using Different Fonts in Pascal


No, not within the text editor, I mean I want the font to be displayed in the
EXE when ran

Re:Using Different Fonts in Pascal


NieNen asked how to change the font used by WriteLn in
Turbo Pascal for Windows with the WinCrt unit.

Short Answer:  You cannot change the font which WinCrt uses.

Long Answer:
The easiest thing to do is copy the WinCrt.pas (from the TPW\DOC directory)
and modify it to make your own "MyCrt.pas" unit to use in your program.

You need to change the line:
  SaveFont := SelectObject(DC, GetStockObject(System_Fixed_Font));
in the InitDeviceContext Procedure.
Replace GetStockObject(System_Fixed_Font) with your preferred font:
SaveFont:=SelectObject(DC,CreateFont(Size,0,0,0,0,0,0,0,0,0,0,0,0,FontName));
(I'm not sure what happens if the requested fontname does not exist.)

You will also have to remove that new font when you are finished:
In the DoneDeviceContext Procedure (right after InitDeviceContext),
change the line:  SelectObject(DC, SaveFont);
to:  DeleteObject(SelectObject(DC, SaveFont));

To allow multiple fonts, you could create a public "FontName" variable
declared in the Implementation part of your new unit:
  Var FontName:PChar;
Then your program could change the font at will.
(Even the size if you add a variable for that.)

WARNINGS

1)  WinCrt does NOT buffer fonts.  If your window gets covered and needs
    to be repainted, ALL characters will get redrawn based on the current
    font.  (This is a pain to fix.  No problem if you use only one font.)

2)  WinCrt calculates the cursor positions based on the original fontsize,
    assuming a mono-space font.  Doing more than one WRITE on a line may
    lead to incorrect spacing between the WRITE's.
    Changing font sizes will cause line spacing problems since that spacing
    is calculated for the original font.  This could be "sort of" fixed with
    a few lines to recalculate spacing when the font is changed.
        GetTextMetrics(DC, Metrics);
        CharSize.X := Metrics.tmMaxCharWidth;
        CharSize.Y := Metrics.tmHeight + Metrics.tmExternalLeading;
        CharAscent := Metrics.tmAscent;

For my class, I have rewritten the WinCrt to support non-character keys
(function and arrow keys), the mouse, changing text colors, and graphics.
I'm going to have to handle the buffer problem pretty soon.
However, it's still more Borland's work than mine, so I shouldn't post
it as an example.  (One day I'll do a complete rewrite they way Borland
SHOULD have done it in the first place.)

  |\/|                          ||  Burnaby South Secondary School
  |  |orew...@planeteer.com     ||    Beautiful British Columbia
Mathematics & Computer Science  ||             (Canada)

Other Threads