meanwhile I read about this issue and tested a lot of suggestions given in the forum. But I could not come to a solution.
Font and fontsize do not change during execution of the code (paint event of a canvas). But assigning different font-name and size, difference in height comes quicky to the eye.
dim r as String = “I” + endofline + “go” + endofline + “to” + endofline + “London”
dim mSplitter() as String = split(r, EndOfLine)
dim incr as double = mtop// + (g.TextHeight - g.TextAscent)// *2//integer
for j as Integer = 0 to mSplitter.Ubound
dim theLine as string = mSplitter(j)
g.DrawText(theLine, (g.Width - g.TextWidth(theLine)) / 2, incr)
incr = incr + mTop //+ (g.TextHeight - g.TextAscent)// / 3 -2
next
As you can see from the various alternatives after each commented line (//), I tried a lot of solutions, but I have not come to a stable one.
That is, the overall heigh of the text when drawn center.aligned is never of the same height of the text when drawn as left.aligned.
Suggestions welcome. Thanks.
[removed a few lines because they would not show properly here].
I am not sure what the computer is doing with the left-alignment or center-alignment. Could I ask you to change the attached code and show me what you are seeing?
Hi, Eugene,
yes your code works on my computer exactly as it used to work.
I’m afraid I cannot undestand what to change; in fact, after clicking the OK button I see what I said in the original post: i.e. comparing to the vertical spacing before clicking OK, now the line vertical spacing gets bigger.
Or am I not understanding what you intended to say? You know, i’m rather dense.
Meanwhile, thank you for giving your time.
Its all good, I am just trying to understand the issues and help you
What is the code that you were using to draw centre.align and left.align, and do you see the issue with the example program?
Sorry, it is clear I did not understand well what you said.
So, what I get from your code is correct, yet when I run the same code in my project then the vertical distance between the four lines is smaller (as I tried to explain in my post.
This is my project, and you can see that the line spacing is smaller:
Difficult to understand, since we are running the same code…
The only difference is that I run your code on Xojo 24, and my code on Xojo 2021. Trying now to make my project work with Xojo 24 since it stumbles when launching the debugger.
I’ll let you now.
Meanwhile, thanks again
@Eugene_Dakin Actually the problem is still the one outlined in my post. In fact, when running your project I did not notice that the font name defaults to Times New Roman when it is not Arial. So, changing the alternate font to Times one can clearly see the difference in line-spacing between Left-align and Center-align (of course, each fonts behaves its own way, only that I was accostumed testing with Times because it was the one showing more clearly the line-spacing difference).
Attaching your file revised: I added a checkbox: “Align Center”; ticking it one can see the difference in line-spacing I’m talking about and it confirms that the issue is the code inside the canvas.
Hi, the file attached in my reply to Eugene shows the issue.
As I said, every font behaves its own way according to its height and ascent etc.; with Times the difference comes at once to the eye; with other fonts it is less noticeble.
All this points to the inadeguacy of my code.
Thank you.
Thanks for changing the program to help me understand the issue. I ran the program and made screen-grabs, and compared the height of the letters, and they seem to be the same. Is there another test that I can perform to view this issue?
Hi Eugene,
I added a fontMenu and another canvas, so that you can test more quickly the fonts and see the difference if any…
Although I see that that majority of the fonts behave in a positive way, nevertheless there are fonts showing different rendering: apart from Times, there is Palatino, Hoefler, Helvetica and so on that draw correctly in text editors.
Thank you, EugeneTest 2021 2.xojo_binary_project.zip (11.4 KB)
Guys, keep in mind that the issue is probably in the fonts themselves, in which case passing these sample projects back and forth may not yield the same results no matter what you do.
By passing the files I make myself sure that the issue is in the fonts themselves; i.e. that the code in the paint event of the canvas needs adjusting; yet I don’t know how.
Visually line spacings can be different.
For example between this 2 lines :
aeiou
aeiou
The space is bigger than between
pgj
fhlt
because for this 4 lines the TextHeight is the same but not the hight of the characters.