Solved

Retrieving Fixed -pitch true type font list

Posted on 2003-11-03
1
901 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

12 Experts available now in Live!

Get 1:1 Help Now