Solved

Font Installing

Posted on 2000-04-08
16
289 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
ID: 2697752
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
ID: 2697753
null
0
 

Author Comment

by:boozilla
ID: 2698064
Adjusted points from 50 to 100
0
 

Author Comment

by:boozilla
ID: 2698065
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
ID: 2698465
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
ID: 2698566
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
ID: 2698720
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
ID: 2698770
not comming from res file...from .ttf or .fot file...please look at my source above...thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:inthe
ID: 2705639
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
ID: 2709909
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
ID: 2714202
Adjusted points from 100 to 200
0
 

Author Comment

by:boozilla
ID: 2714214
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
ID: 2714228
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
ID: 2714680
yes please
0
 
LVL 17

Expert Comment

by:inthe
ID: 2717667
0
 

Author Comment

by:boozilla
ID: 2719712
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now