Solved

How to load fonts from disk

Posted on 1997-07-23
2
187 Views
Last Modified: 2013-12-02
how can i load fonts from disk (ttf-files) and use them in my
Delphi program ???
I want to make a font viewer for UNinstalled font
0
Comment
Question by:frost072397
2 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 100 total points
Comment Utility
Something like this:

type
  TForm1=class( TForm )
      procedure FormCreate(Sender: TObject);
      procedure FormDestroy(Sender: TObject);
      ...
    private
      { Private declarations }
      bLoadedFont: boolean;
    public
      { Public declarations }
  end;

procedure TForm1.FormCreate(Sender: TObject);

  var
    sAppDir: string;
    sFontRes: string;

  begin
  sAppDir := Application.ExeName;
  sAppDir := copy( sAppDir, 1, rpos( '\', sAppDir ) );

  sFontRes := sAppDir + 'MYFONT.FOT';
  if not FileExists( sFontRes ) then
    begin
    sFontRes := sFontRes + #0;
    sFont := sAppDir + 'MYFONT.TTF' + #0;
    CreateScalableFontResource( 0, @sFontRes[ 1 ], @sFont[ 1 ], nil );
    end;

  sFontRes := sAppDir + 'MYFONT.FOT';
  if FileExists( sFontRes ) then
    begin
    sFontRes := sFontRes + #0;
    if AddFontResource( @sFontRes[ 1 ] ) = 0 then
      bLoadedFont := false
    else
      begin
      bLoadedFont := true;
      SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
      end;
    end;

  ...
  end;

procedure TForm1.FormDestroy(Sender: TObject);

  var
    sFontRes: string;

  begin
  if bLoadedFont then
    begin
    sFontRes := sAppDir + 'MYFONT.FOT' + #0;
    RemoveFontResource( @sFontRes[ 1 ] );
    SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
    end;
  end;

/// John
0
 

Author Comment

by:frost072397
Comment Utility
have to check it out....but looks good, thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

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

18 Experts available now in Live!

Get 1:1 Help Now