Discussion:
Font Width Tables
(too old to reply)
Roger Halls
2007-10-23 16:40:12 UTC
Permalink
Anyone out there know where I can get a utility that returns the width
table of fonts?
macropod
2007-10-26 10:50:28 UTC
Permalink
Hi Roger,

Here's a simple macro that outputs the 1pt character widths for the standard character set in whatever font attributes are in use at
your selection point. To get the widths in any other pont size, simply multiply the returned values by whatever point size you want
to use (or change 'xPos / FntSize' to 'xPos' to get the absolute widths for the selected point). Although not necessary for this,
I've added the metrics to an array which you could then query to build up an overall string length.

Sub GetCharWidths()
Dim i As Integer
Dim ChrWidths As String
Dim xPos As Single
Dim yPos As Single
Dim FntSize As Single
Dim CharWidthArray(2, 255)
With Selection
.Collapse
FntSize = .Font.Size
For i = 1 To 255
.TypeText (Chr(i))
xPos = .Information(wdHorizontalPositionRelativeToTextBoundary)
CharWidthArray(1, i) = i
CharWidthArray(2, i) = xPos / FntSize
ActiveDocument.Undo 1
ChrWidths = ChrWidths & i & vbTab & Chr(CharWidthArray(1, i)) & vbTab & CharWidthArray(2, i) & Chr(11)
Next
.TypeText ChrWidths
End With
End Sub

Note: the code will return a few oddities for ASCII values less than 32, for characters that equate with tabs, line breaks,
paragraph breaks and column breaks. But these don't have meaningful widths of their own anyway.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------
Post by Roger Halls
Anyone out there know where I can get a utility that returns the width
table of fonts?
Loading...