Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting the right font

Posted on 1998-10-23
4
Medium Priority
?
208 Views
Last Modified: 2013-12-02
Hi,

How can I make sure that the font I am using in my application always will be available on other computers? Should I link it as a ressource? And how do I do that?
I am using Delphi 1.0.

Thanks,

/Pede
0
Comment
Question by:pede
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 300 total points
ID: 1344105
hi pede,

if you were working 32bit I'd directed you to :
http://www.bhnet.com.br/~simonet/archive/portfont.zip

but for D1, look at this source :

How can my app use MY FONTS? not user's

From: choate@cswnet.com (Brad Choate)

Can someone please tell me the neatest way to make sure my app uses
fonts that I can provide, rather than the nearest font the user has
installed on their system?  I have tried copying a #.ttf file into the
users windows\system directory but the app still can't pick it up.

The following is some Delphi 1 code that I have used for successfully installing dynamic fonts that are only
loaded while the application is running. You can place the font file(s) within the application directory. It will be
installed when the form loads and unloaded once the form is destroyed. You may need to modify the code to
work with Delphi 2 since it calls various Windows API calls that may or may not have changed. Where you see
"..." in the code, that is just to identify that other code can be placed there.

Of course, substitute "MYFONT" for the name of your font file.



type
TForm1=class( TForm )
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
.
private
{ Private declarations }
bLoadedFont: boolean;
public
{ Public declarations }
end;

procedure TForm1.FormCreate(Sender: TObject);

var
sAppDir: string;
sFontRes: string;

begin
sAppDir := Application.ExeName;
sAppDir := copy( sAppDir, 1, rpos( '\', sAppDir ) );

sFontRes := sAppDir + 'MYFONT.FOT';
if not FileExists( sFontRes ) then
begin
sFontRes := sFontRes + #0;
sFont := sAppDir + 'MYFONT.TTF' + #0;
CreateScalableFontResource( 0, @sFontRes[ 1 ], @sFont[ 1 ], nil );
end;

sFontRes := sAppDir + 'MYFONT.FOT';
if FileExists( sFontRes ) then
begin
sFontRes := sFontRes + #0;
if AddFontResource( @sFontRes[ 1 ] ) = 0 then
bLoadedFont := false
else
begin
bLoadedFont := true;
SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
end;
end;

.
end;

procedure TForm1.FormDestroy(Sender: TObject);

var
sFontRes: string;

begin
if bLoadedFont then
begin
sFontRes := sAppDir + 'MYFONT.FOT' + #0;
RemoveFontResource( @sFontRes[ 1 ] );
SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
end;
end;

ps. First test the code, because I don't know if this works.

ZiF.


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344106
Hello you two.... I just wanted to say why do all that work when you need only one line of code to do that... Inprise have thought of that already :-)

And here is the line of code you need...

Form1.Font.Pitch := fpVariable;

Set this property to all form's Font property and there you have it... It updates the appropriate fonts depending on the resolution of the computer...
Hope this helps....

Cheers,
Viktor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344107
viktor,

 I don't think this works in D1.
 Besides, Pede asked how to make it so that on all PC's his own font-type (e.g. Arial, Roman, ... own made...) will be used.

Zif.
0
 
LVL 1

Author Comment

by:pede
ID: 1344108
Yep - this is what I was looking for :)

/Pede
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question