Solved

Retrieving Fixed -pitch true type font list

Posted on 2003-11-03
1
904 Views
Last Modified: 2013-12-03
Environment: D5 Pro...

I need to populate a dropdown list with the names of all Fixed Pitch true type fonts that are installed on the system.  How do I do that?

An example of fixed pitch is Courier New, Lucida Console, etc.  It is those fonts where each letter is the same width.

Thanks
0
Comment
Question by:gspears060598
1 Comment
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 9672324
putt a button and a combobox on a form and add this code to button1click

procedure TForm1.Button1Click(Sender: TObject);
  function IsFixedPitch(Index: Integer): Boolean;
var
  Metrics: TTextMetric;
  lf: TLogFont;
  oldFont, newFont: HFont;
begin
  with lf do begin
    lfHeight := 10;
    lfWidth := 10;
    lfEscapement := 0;
    lfWeight := FW_REGULAR;
    lfItalic := 0;
    lfUnderline := 0;
    lfStrikeOut := 0;
    lfCharSet := DEFAULT_CHARSET;
    lfOutPrecision := OUT_DEFAULT_PRECIS;
    lfClipPrecision := CLIP_DEFAULT_PRECIS;
    lfQuality := DEFAULT_QUALITY;
    lfPitchAndFamily := DEFAULT_PITCH or FF_DONTCARE;
    StrPCopy(lfFaceName, combobox1.Items[Index]);
  end;
  newFont := CreateFontIndirect(lf);
  oldFont := SelectObject(Canvas.Handle, newFont);
  GetTextMetrics(Canvas.Handle, Metrics);
  Result := (Metrics.tmPitchAndFamily and TMPF_FIXED_PITCH) = 0;
  SelectObject(Canvas.Handle, oldFont);
  DeleteObject(newFont);
end;
var
i: Integer;
begin
with combobox1 do begin
      Items.Assign(Screen.Fonts);
  I := 0;
  repeat
   if Items[I] = 'Default' then
   begin
        Items.delete(I);
   end else
         if (not isfixedpitch(i)) then
            items.Delete(i)
      else inc(I);
  until I = Items.count;
  ItemIndex := 0;
  end;
end;

F68 ;-)
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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

21 Experts available now in Live!

Get 1:1 Help Now