Solved

Font Installing

Posted on 2000-04-08
16
296 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
erros on link  checking 2 78
Delphi IDE crash without error message ... 7 99
Working with hours 3 65
Delphi...Split view - idea? 1 88
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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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