Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Font Installing

Posted on 2000-04-08
16
Medium Priority
?
317 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
[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
  • 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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

705 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