Sorry if I am posting a question that is apparently contradictory, but what I need doesn’t apparently fit.
I use a font that either has a lot of ascent or a lot of leading and a fair percentage of the text is below the border.
So the bottoms of a string of text is chopped off.
TextAscent might be the answer , and apparently leading isn’t a calculation but a measurement of a textarea’s linespacing.
I cannot find any uses of textascent, so I need to ask.
I use this formula to get the font size
eArea = eHeight * eWidth
fSize = SizeOfFontMax
While eArea < gArea And fSize > SizeOfFontMin // Sets the area for ALL text size so everything will fit in the TextArea provided it is larger SizeOfFontMin
fSize = fSize -1
g.TextSize = fSize
gArea = g.StringWidth(stkOfStrgs(0)) * fSize
Suggestions for changes to the formula or an alternate formula?
Thanks. I had and I am just as confused. The LR doesn’t explain how you find you baseline.
I even did a search on the docs online.
How do you find baseline? Does that differ with multi-line text as in WordWrap?
Is there an example that calculates TextSize so I know I’ve gotten it correct?
Xojo places text on the “baseline”…
so if you want the TOP of you character (bounding rectangle) at “Y” then
you draw the character at Y+g.textascent
g.textHeight is the height of the bounding rectangle and is always greater than g.textascent
each character with have its own “stringWidth” value (with the exception of mono-space fonts like Courier and Menlo where they will all be equal)
NOTE : the character attributes (textascent/textheight and stringwidth) ARE NOT necessarily the same based on the same character of the same named font between macOS , Windows and Linux (or even iOS for that matter although that will most likely match macOS)
dim y as integer=50
g.drawstring "line one",100,y+g.textAscent
g.drawstring "line two",100,y+g.textAscent
also note : macOS and iOS use fractional values, while Windows uses Integer (which will really screw things up sometimes)
Sorry for being dense, but I’m missing 3 things from your example.
How do you come up with Y??
Does drawstring overwrite “line one” with “line two”?
How do you find the rectangle
I also found this post that sort of explains thing
Extracting Font measurements from Graphics Object
- “Y” is where YOU want the TOP of the text to be
- No, line two is place an appropraite value BELOW line one
- a little math, you have textascent, textheight, stringwidth,
- there are dozens of topics on this forum discussing all of this
best way is to experiment, draw character string, draw lines at various places to see where they intersect
its not rocket science… its just a little math and understanding
Thanks Dave. That makes stuff workable.
Sometimes I have problems remembering which hand is my right hand.
[quote=366816:@Arthur Gabhart]Thanks Dave. That makes stuff workable.
Sometimes I have problems remembering which hand is my right hand.[/quote]
I don’t… . its the one that isn’t the “LEFT” hand… now if I could just remember which one that is