Solved

Font Installing

Posted on 2000-04-08
16
292 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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
 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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