E
euthymos
I'm making a program, in VB.NET, that creates and fills a table in a
Microsoft Word document.
Therefore I need a method to calculate the exact height, in
millimeters, of a text line written with a certain font, at a certain
size.
Searching the Internet I've found this:
Private Function GetFontHeight(ByVal FontName As String, _
ByVal FontSize As Single) As Single
Dim myGraphics As Graphics = Me.CreateGraphics()
Dim myFont As Font = New Font(FontName, FontSize)
myGraphics.PageUnit = GraphicsUnit.Millimeter
Return myGraphics.MeasureString("Ag", myFont).Height * 0.9 '
<<< STRANGE!!!
End Function
The result was so imprecise that I had to add that 0.9 coefficient (I
calculated it with several attempts by approximation). But the result
is imprecise.
There seems to be a discrepancy between the height of a line in the
Graphics object, and the height of that same line in Microsoft Word.
That discrepancy is about 10%. Strange, isn't it?
Microsoft Word document.
Therefore I need a method to calculate the exact height, in
millimeters, of a text line written with a certain font, at a certain
size.
Searching the Internet I've found this:
Private Function GetFontHeight(ByVal FontName As String, _
ByVal FontSize As Single) As Single
Dim myGraphics As Graphics = Me.CreateGraphics()
Dim myFont As Font = New Font(FontName, FontSize)
myGraphics.PageUnit = GraphicsUnit.Millimeter
Return myGraphics.MeasureString("Ag", myFont).Height * 0.9 '
<<< STRANGE!!!
End Function
The result was so imprecise that I had to add that 0.9 coefficient (I
calculated it with several attempts by approximation). But the result
is imprecise.
There seems to be a discrepancy between the height of a line in the
Graphics object, and the height of that same line in Microsoft Word.
That discrepancy is about 10%. Strange, isn't it?