Get font metrics

K

Karl E. Peterson

Jack Fredrick formulated the question :
Does anybody know how to get the metrics of a selected font/word?

What sorts of metrics are you looking for? Those offered by structures
like LOGFONT, or more detailed info on each glyph within?
 
M

Moishy

Jack Fredrick formulated the question :


What sorts of metrics are you looking for?  Those offered by structures
like LOGFONT, or more detailed info on each glyph within?

LOGFONT structures are fine. If possible to find characters supported
by the font it would be even better.
 
M

Moishy

Jack Fredrick formulated the question :


What sorts of metrics are you looking for?  Those offered by structures
like LOGFONT, or more detailed info on each glyph within?

The metrics available LOGFONT structures are what I had in mind, If
possible to find which chars are supported by each font that would be
great, I've been looking for something like that for a long time.
 
K

Karl E. Peterson

Moishy laid this down on his screen :
The metrics available LOGFONT structures are what I had in mind, If
possible to find which chars are supported by each font that would be
great, I've been looking for something like that for a long time.

Okay, here's a sample you may want to look at...

Uses EnumFontFamilies for that info on any/all fonts on the system:
http://vb.mvps.org/samples/FontFilter

What info are you starting with? YOu may also be interested in...

Looks inside the internal table structure of TTF files:
http://vb.mvps.org/samples/FontFilter

Very messy, but it's *all* there.
 
M

Moishy

Moishy laid this down on his screen :



Okay, here's a sample you may want to look at...

Uses EnumFontFamilies for that info on any/all fonts on the system:http://vb.mvps.org/samples/FontFilter

What info are you starting with?  YOu may also be interested in...

Looks inside the internal table structure of TTF files:http://vb.mvps.org/samples/FontFilter

Very messy, but it's *all* there.

Thank you very much, I hope to get around to delve into the topic
sometime this week.
Can you please give me a quick example how to determine a fonts height
and width for a specific char or string?
 
M

Moishy

Does anybody know how to get the metrics of a selected font/word?

Thank you very much. I hope to delve into this sometime this week. In the meantime can you please show me how to extract the height of a specific char or string for a given font?
 
K

Karl E. Peterson

Moishy formulated on Tuesday :
Thank you very much, I hope to get around to delve into the topic
sometime this week.
Can you please give me a quick example how to determine a fonts height
and width for a specific char or string?

I've never done that, myself. Please realize that those values will be
dependent on device context. So, it's relatively easy to determine for
any given DC, but if you want to do it for any random font you'll need
to create a compatible DC and select that font into it first. Then, I
believe you can use GetTextExtentPoint32 to retrieve the metrics for
any given string.

http://msdn.microsoft.com/en-us/library/dd144938(v=vs.85).aspx

You can probably Google for that API call and VB6 and/or VBA to find
functional examples...

http://www.ex-designz.net/apidetail.asp?api_id=590
 
M

Moishy

Moishy formulated on Tuesday :











I've never done that, myself.  Please realize that those values will be
dependent on device context.  So, it's relatively easy to determine for
any given DC, but if you want to do it for any random font you'll need
to create a compatible DC and select that font into it first.  Then, I
believe you can use GetTextExtentPoint32 to retrieve the metrics for
any given string.

http://msdn.microsoft.com/en-us/library/dd144938(v=vs.85).aspx

You can probably Google for that API call and VB6 and/or VBA to find
functional examples...

http://www.ex-designz.net/apidetail.asp?api_id=590

First of all, why is the height of a specific letter in a specific
font dependable upon the DC, I want to know the real value as created
by the creator of the font?

I converted your example to Word VBA. All works well besides the
filtering based upon the cboCharset. Here is a link to the file
(https://rapidshare.com/files/2732974441/FontEnum.doc) your help will
be most appreciated.
 
K

Karl E. Peterson

Moishy formulated the question :
First of all, why is the height of a specific letter in a specific
font dependable upon the DC, I want to know the real value as created
by the creator of the font?

Relative to what? The DC is what gives it context. (Which, of course,
is the C in DC.)
I converted your example to Word VBA. All works well besides the
filtering based upon the cboCharset. Here is a link to the file
(https://rapidshare.com/files/2732974441/FontEnum.doc) your help will
be most appreciated.

With what, in particular?
 
M

Moishy

Moishy formulated the question :


Relative to what?  The DC is what gives it context.  (Which, of course,
is the C in DC.)


With what, in particular?
Relative to what? The DC is what gives it context. (Which, of course,
is the C in DC.)
When measuring a persons height (feet and inches etc.) it isn't
relative to any thing, why are computer measurements any different?
With what, in particular?
Getting the procedure to filter results based upon the value of
cboCharset.
 
K

Karl E. Peterson

Moishy brought next idea :
When measuring a persons height (feet and inches etc.) it isn't
relative to any thing, why are computer measurements any different?

Well, because people aren't scalable. Fonts are. They're just
outlines, defined mathematically.

Tell me this, how long is y=mx+b?
Getting the procedure to filter results based upon the value of
cboCharset.

Hmmm, well, for starters, I'm getting an error on that download link.
But it's really not polite to upload something like that, and ask folks
to trust it, anyway. What sort of failure is it? What have you done
to troubleshoot it? Can you isolate the failure and post the snippet
here?
 
M

Moishy

Moishy brought next idea :



Well, because people aren't scalable.  Fonts are.  They're just
outlines, defined mathematically.

Tell me this, how long is y=mx+b?



Hmmm, well, for starters, I'm getting an error on that download link.
But it's really not polite to upload something like that, and ask folks
to trust it, anyway.  What sort of failure is it?  What have you done
to troubleshoot it?  Can you isolate the failure and post the snippet
here?
Well, because people aren't scalable. Fonts are. They're just
outlines, defined mathematically.

Ok, so I imagine that using the default printer dc makes the most
sense for Word. Please correct me if I'm wrong.
Hmmm, well, for starters, I'm getting an error on that download link.
But it's really not polite to upload something like that, and ask folks
to trust it, anyway. What sort of failure is it? What have you done
to troubleshoot it? Can you isolate the failure and post the snippet
here?

Double Hmmm, I don't know why you're getting an error on the download
link I just tried it and it works. Well I'm sorry if I seemed non-
polite, I didn't think you would mind (after all you see the
extension, and can easily bypass any auto-exec macro), but knowing the
world we live in I can see your concern.
Well, there aren't any compile or runtime errors, and yet regardless
of the value of cboCharsets all fonts are displayed.
This is the adapted code:
Private Sub cmdEnum2_Click()
Dim cnt As Long
Dim lf As LOGFONT
Dim fnt As String
Dim Skip As Boolean
Dim hDC As Long
Dim hWndTarget As Variant

If IsMissing(hWndTarget) Then hWndTarget = GetFocus
hDC = GetDC(hWndTarget)

' Clear the list filled with this method.
lstFonts2.Clear

' Set callback module properties.
MFontFilter.FilterHidden = (chkFilterHidden1.Value = False)
MFontFilter.FilterVertical = (chkFilterVertical1.Value = False)

' Exercise the EnumFontFamiliesEx callback.
' lf.lfCharSet = cboCharset.ItemData(cboCharset.ListIndex)
EnumFontFamiliesEx hDC, lf, AddressOf EnumFontFamExProc,
lstFonts2, 0&

' Sort the listbox
Call SortListBox(lstFonts2, 0, 1, 1)

' Show the number of fonts found
lblCount2.Caption = lstFonts2.ListCount & " fonts"

ReleaseDC hWndTarget, hDC

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top