Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Font Type

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
Is there a way in VFP 9 to check if a selected font is Fixed or Proportional spaced?
 
Hi Sdocker, and welcome to the forum,

You could try the following code:

Code:
lcFont = "Courier New"  && or whatever
IF FONTMETRIC(16, lcFont, 10) = 54
  ? "This is fixed pitch"
ELSE
  ? "It's proportional"
ENDIF

The returned value tells you the font family. 54 is the family for most fixed-pitch fonts.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks Mike,

Exactly what I was looking for.

Sam
 
I may be showing my age here but 54 is fairly modern. FoxFont is 0 and FixedSys and Terminal are both 48.

In the olden days fixed pitch fonts had their final bit clear and were all even numbers. Fancy fonts were odd.

Geoff Franklin
 
We're close to the end of a Friday afternoon here so a little experiment is tempting ...
Code:
Afont(af)
For n = 1 To Alen(af)
  b = Fontmetric(16, af(n), 10)
  If Not Bittest(b, 0)
    ? af(n)
    ?? b
  Endif
Next

Consolas                54
Courier                 48
Courier New             54
Fixedsys                48
FoxFont                  0
Lucida Console          54
Lucida Sans Typewriter  54
Terminal                48

These are just the fonts I happen to have here on XP. See if you get the same pattern on your own system.

Geoff Franklin
 
Oh, well, Geoff, if you've got nothing better to do, I'll have a go too.

I just ran this:

Code:
LOCAL ARRAY laFonts(1)
LOCAL lnI

AFONT(laFonts)
FOR lnI = 1 TO ALEN(laFonts)
  ? FONTMETRIC(16, laFonts(lnI), 10), laFonts(lnI)
ENDFOR

The results are not completely consistent, and there's a certain amount of overlap (for example, a fixed pitch font can be serif or sans serif). But this is a quick summary of my results:

Code:
[b]Value    Family            Examples[/b]

7        Special/various   MS Outlook, Wingdings
23       Serif             Clarendon, Times New Roman
33       System            System
39       Sans serif        Univers, Verdana
54       Fixed pitch       Courier New, Lucinda Console
71       Cursive           Lucinda Handwriting, Vivaldi
87       Decorative        Broadway, Stencil

No doubt there are others as well.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Sam,

If my previous suggestion doesn't completely work for you, here's another idea:

Code:
lcFont = "Courier New"  && or whatever
IF TXTWIDTH("M", lcFont, 20) = TXTWIDTH(".", lcFont, 20)
  ? "Fixed pitch
ELSE
  ? "Proportional
ENDIF

The idea is that, if the width of a capital M is the same as the width of a dot, it's safe to assume the font is fixed pitch.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
For a fixed pitch font, the value returned by TXTWIDTH() is the same as the length of the string provided to it.

Code:
AFONT(laFonts)
FOR lnI = 1 TO ALEN(laFonts)
  ? laFonts(lnI)+" is "+IIF(TXTWIDTH("M",laFonts(lnI),24)=1.0,"Fixed Width","Proportional")
ENDFOR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top