At last, I get some troubles with the shared example.
I used it as is, and it worked fine, but I went ahead and add a way to increase the font size. Because I put the testing Canvas above an existing window, I changed the colors.
Here’s my current code (MouseDown and Paint are Canvas1 Events, the gSize Property is in Window1):
Function MouseDown(X As Integer, Y As Integer) As Boolean
gSize = gSize + 16
Sub Paint(g As Graphics, areas() As REALbasic.Rect)
// Fills the Canvas background
g.ForeColor = &cffff00
g.DrawRect(0, 0, g.Width, g.Height)
g.FillRect(0, 0, g.Width, g.Height)
// Set a Default Size
g.TextSize = gSize
// Text Color
g.ForeColor = &c000000
// Compute the draw location
Dim textToDraw As String = “tout petit” // String with ascent and descent
Dim textWidth As Double = g.StringWidth( textToDraw )
Dim textX As Double = (g.Width - textWidth) / 2
Dim textY As Double = ((g.height - g.StringHeight(textToDraw,g.Width)) / 2) + g.TextAscent
// Draw the String
g.DrawString(textToDraw, textX, textY, textWidth)
gSize As Integer = 64
My conclusion: maybe my idea to make the print centered by code was a bad idea.
Also, the String Draw Size depends on its length (a max size around 140 pixels can be defined for a long string).
The base line change each time I enlarge the Font Size. Due to the bad idea to use “Top” as a test text, it tooks me time to realize some sizes will probably never be used; a meaningful string is far more than 3 characters (Using “Top” was a good idea because it holds a character with Ascent and another with Descent; it is also draw at the… top of the Canvas… a second one is drawn at its bottom…)…