Hopefully someone else has seen this and can advise.
I believe that fontAscent is not accurate until something has been drawn to the graphics context. I’ve ended up having to do something like DrawText “”,0,0 and then text shows up right.
The evidence seems to be drawing one line of text using the FontAscent as part of the calculation for the Y position, and then a second string. They stagger.
Hope this makes sense and if so, that there is a more logical workaround than what I’m doing.
Var p As New PDFDocument
Var g As Graphics = p.Graphics
g.FontName = "Helvetica"
g.FontSize = 24
Var x As Double = 20
Var y As Double = g.Height / 2 - g.FontAscent / 2
g.DrawText("One", x, y)
x = x + g.TextWidth("One") + 20
g.DrawText("Two", x, y)
x = x + g.TextWidth("Two") + 20
g.DrawText("Three", x, y)
g.DrawLine(20, g.Height / 2, g.Width - 20, g.Height / 2)
Var f As FolderItem = SpecialFolder.Desktop.child("FontAscentExample.pdf")
If f.Exists Then f.Delete
p.Save(f)
f.Open
Yes, I can store a value in a variable to use. My concern is that this should be consistent and now I’m not positive which case is giving me the right result. I tend to think it’s the subsequent calls since “two” and “three” position the same. I don’t want to cache the wrong value to reuse.
Yeah, it doesn’t seem right that FontAscent changes from 10 to 26 after printing something. Even if you cache the correct value (whichever that is), something is weird.