StringHeight not accurate?

you could try if one of the plugin ways calculates the right height.

Well, I don’t have plugins…

No. The method I described consist in measuring the space between two consecutive lines, then as you know exactly in pixels how much space there is between lines, make sure several lines cannot produce a result inferior to a multiple of that value.

@Michel Bujardet This is where I feel so dumb: how do I measure the space between two consecutive lines, taking into account that Font and size may vary. Here is one of my tests, where I cannot position the second and third strings at the same distance corresponding to the spacing of the first two lines (Help + endofline + help).
Sure, I can hardcode mTop to a value that will make appear the six lines evenly spaced, but that would work only with Palatino 12.
And using g.textHeight doesn’t make things better.

Sub Paint(g As Graphics, areas() As REALbasic.Rect)
dim mRight as Integer = 10
dim mTop as Integer = 50
g.TextFont = “Palatino”
g.TextSize = 12
'g.Underline = true
'g.Bold = true
dim s as String = “Help” + EndOfLine + “Help”//faking line wrapping

g.DrawString s,mRight,mTop

dim strH as integer = g.StringHeight(s, 10)
mTop = mTop + strH/2 //just to be quick with this test, since I know that I have two lines only
g.DrawString s,mRight,mTop

strH = g.StringHeight(s, 10)
mTop = mTop + strH/2
g.DrawString s,mRight,mTop
End Sub

What I was suggestion would work to deal with stringheight with an homogenous bloc of text.

If you have variable text size, you cannot use block Stringheight. The only I can think of is to calculate for each line the stringheight. But it will require doing some fancy work to do wrapping with different text sizes.

I have trouble visualizing the kind of text you want to create from your code. Could you post a picture of what you want to do ?

I uploaded to dropbox a mini project that shows what I get and what I would like to achieve. If you have time…
Meanwhile, thank you very much.

https://www.dropbox.com/s/20yd8ujzn6fel1i/TestPrint.zip?dl=0

Why not just join your array of strings (s) and use a single drawString call?

  dim mInterSpace, incr, strH1, strH2 as double//strH2 not used here
  dim s() as String
  s.Append "Line 1 (starts)" + EndOfLine + "Line 1" + " (wrapped)"
  s.Append "Line 2 (single line)"
  s.Append "Line 3 (starts)" + EndOfLine + "Line 3" + " (wrapped)" + EndOfLine + "Line 3" + " (wrapped)" + EndOfLine + "Line 3" + " (wrapped)" + EndOfLine + "Line 3" + " (wrapped)"
  s.Append "Line 4 (single line)"
  
  g.TextFont = PopupMenu2.text
  g.TextSize = val(PopupMenu1.text)
  
  dim sOut As string = join(s,EndOfLine)
  
  dim iPadding as integer = 4
  
  g.DrawString sOut, iPadding, 15, g.width - (iPadding * 2)
  
  
  'dim defaultH as integer = g.textHeight//("Line", 125)
  'incr = 15
  'for i as Integer = 0 to s.Ubound
  'g.DrawString s(i), 10, incr, 125
  'strH1 = g.StringHeight(s(i), 125)
  'mInterSpace = strH1 / DefaultH
  'if strH1 > defaultH then
  'incr = incr + (defaultH * mInterSpace) + (defaultH / 2)
  'else
  'incr = incr + defaultH + (defaultH / 3)
  'end if
  'next

[quote=257033:@Carlo Rubini]I uploaded to dropbox a mini project that shows what I get and what I would like to achieve. If you have time…
Meanwhile, thank you very much.

https://www.dropbox.com/s/20yd8ujzn6fel1i/TestPrint.zip?dl=0[/quote]

I had a look at your project. I thought you wanted different text size within the block of text.

I replaced all your for next loop in Canvas1 paint by

g.DrawString join(s, EndOfLine), 10, incr, 125

and it is impeccably spaced.

The alternative with the approach you took is to wrap the text yourself and print them spaced with the height of one line.

@Peter Fargo Because I was still hoping to find a solution that would not upset too much the old code; where records may be several thousand and I have to take care, for instance, of g.nextPage.
So, since it appears that no such solution is available, either I’ll make an array of all the records and feed them as you suggested, or I’ll force strings not to exceed tow lines each.

@Michel Bujardet I’ll see how to deploy your suggestion in the real app.

Meanwhile, thank you.