Solved

Font Installing

Posted on 2000-04-08
16
286 Views
Last Modified: 2013-12-03
I cant seem to get a font installed for my app. using this code.  When run it shows its installed in the combo box I have linked to it...but the label that should display the new font just shows the System font instead..please help!

procedure TForm1.FormCreate(Sender: TObject);
begin
    sFontFilename:='comic';
    CreateScalableFontResource(0,PChar(sFontFilename+'.fot'),PChar(sFontFilename+'.ttf'),nil);
    if AddFontResource( PChar( sFontFileName+'.fot' ) ) <> 0 then begin
      SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
    end;
    ComboBox1.Items := Screen.Fonts;
    label1.Font.Name:='Comic Sans MS';
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Result := RemoveFontResource( PChar( sFontFilename+'.fot' ) );
  SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
end;
0
Comment
Question by:boozilla
  • 8
  • 8
16 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
Hi
you can try :
 Screen.Fonts.Add(Fontname)

or this was answer from another question:


procedure TMyForm.AddFonts;
var Res : TResourceStream;
    p,p2: PChar;                  
begin
    GetSystemDirectory(WinDir,255);
    Res := TResourceStream.Create(hInstance, 'MY_FONT',
Pchar('FONT1'));
    StrPCopy(p,Windir + '\myfont.ttf');
    Res.SavetoFile(p);
    Res.Free;
    StrPCopy(p2,Windir + '\myfont.fot');    
    CreateScalableFontResource(0, p, 'myfont.fot', windir);
    if HiByte(HiWord(Getversion)) < 129 then
AddFontResource(p2)    
  else AddFontResource(p);
    SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
end;


procedure RemoveFonts;
begin
RemoveFontResource(p) ;
if FileExists(P) then DeleteFile(p);
end;
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
null
0
 

Author Comment

by:boozilla
Comment Utility
Adjusted points from 50 to 100
0
 

Author Comment

by:boozilla
Comment Utility
I already have the font showing up in the combo box like I stated in my question...and the other suggestion is essentually what I doing right now except with resources.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
i tested this ,it worked fine for label:



var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  CurDir: array[0..MAX_PATH] of char;
 begin
  {retrieve the current directory}
  GetCurrentDirectory(MAX_PATH, @CurDir[0]);
  {create a font resource file}
  CreateScalableFontResource(0, PChar(CurDir+'\Ventilat.fot'),
                             PChar(CurDir+'\Ventilat.ttf'),
                             nil);
  {add the font to the internal Windows font tables, making it available
   to any application}
  AddFontResource(PChar(CurDir+'\ventilat.fot'));
  {inform all applications of the change to the font tables}
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  CurDir: array[0..MAX_PATH] of char;   // holds the current directory
begin
  {retrieve the current directory}
  GetCurrentDirectory(MAX_PATH, @CurDir[0]);
  {remove the font resource from the internal Windows font tables}
  RemoveFontResource(PChar(CurDir+'\ventilat.fot'));
  {inform all applications of the change to the font tables}
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  label1.font.name := 'Ventilat';
  label1.caption := 'hello from new font';
end;

end.
0
 

Author Comment

by:boozilla
Comment Utility
This is essencually what I have in my question, I dont see the difference.  The problem comes in when you run it on a machine without said font installed.  Some font sizes work..and others wont.  Example...I load Truebusent and Comic...I assign some controls to Comic at 13 size..no attitudes..and others at 14 size no attitudes.  Guess what..some of the controls look ok..others dont have the right fonts.  Ive tried different sizes with varing results. Its irratic at best.  Im using Delphi 5.  This is tested on a machine that doesnt have those fonts installed on it.  If someone would like and example EXE of what happens that is very simple I can e-mail it to you.  Thank you for all your done so far.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
er ok but i tested this on some fonts (ventalat and quake) which i dont have installed.
i downloaded them specificaly to test this with and worked ok ..
i understand yours is probably coming from a res file but esentually it is the same..
well i can test more tommorrow and try other fonts..
0
 

Author Comment

by:boozilla
Comment Utility
not comming from res file...from .ttf or .fot file...please look at my source above...thanks
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 17

Expert Comment

by:inthe
Comment Utility
Hi
sorry ignore the resource comment my mind was on too many things.
well i have tested this more on using various strange fonts i downloaded and assigning them to components (dtatetimepickers/buttons/etc) and it always works very well (using the very first code you pasted) so i dont know what to say.
do the font work corretly in other applications if you install them in windows ?  

i can be mailed at
Inthe@Future-Software-House.co.uk
if you want to send a demo project for me too look at.
Regards Barry
0
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
Comment Utility
hi,
yep your compiled exe did not work on 3 pcs i try on.

so i made a new demo using code from above and your comic font, compiled and it worked.
i have mailed back the demo i made for you to try.
i have tried my demo on 3 pc's with no comic installed and so far has always worked.
i am lost to see what is wrong at your end ..
some dll problem/conflict possibly ?
0
 

Author Comment

by:boozilla
Comment Utility
Adjusted points from 100 to 200
0
 

Author Comment

by:boozilla
Comment Utility
Thank you for all your testing.  Im not sure what the real deal is, could be this machine.  Sometimes it works now and sometimes not.  If you can think of anything please let me know.

David
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
i wish i knew what dlls etc was affecting this ..maybe commctrl but not sure ,you could always try the commctrl update from microsoft site i can give url tommorrow from work if you want to try it.


0
 

Author Comment

by:boozilla
Comment Utility
yes please
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
0
 

Author Comment

by:boozilla
Comment Utility
I figured it out....you cant set the font initally to what your trying to assign it to problamatically.  Very wierd!  Thanks again for all your help inthe.

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now