Calculating width of a character

You mean letters of different colors ? Can’t you paint them ?

Sorry Michel, I was responding to Christian’s suggestion to use StyledText instead of DrawString. He’s right, but only if it’s an option.

Here’s the difference on a Mac. The widths are the same, but see how the “f” connects to the “i” both when the string is drawn as one and in the TextArea.

[quote=93996:@Kem Tekinay]Here’s the difference on a Mac. The widths are the same, but see how the “f” connects to the “i” both when the string is drawn as one and in the TextArea.
[/quote]

This is yet different than kerning. Kerning is the way within the font to make the spacing between a pair of characters different than what it would be with others. For instance, when an ‘a’ follows a ‘T’, it is better to have the a closer to the T otherwise it would look like too much space. So kerning makes the spacing between T and a smaller than, say, between ‘l’ and ‘a’.

In the case of ‘f’ and ‘i’ the Mac Roman character set contains two special glyphs that represent two characters : fl and fi. So in fact, in the example you provide, one can notice that it is not simply a question of spacing, but the bar in the f is linked to the top of the i. Other common ligatures in typography are st and ft.

Where the Mac has been much more typographically evolved than Windows for a couple decades is that kerning and glyph substitution is still optional in Windows applications, and mostly reserved for Desktop Publishing, whereas the Mac has that in all applications, and that includes Xojo TextArea and labels :slight_smile:

[quote=94002:@Michel Bujardet]This is yet different than kerning. Kerning is the way within the font to make the spacing between a pair of characters different than what it would be with others. For instance, when an ‘a’ follows a ‘T’, it is better to have the a closer to the T otherwise it would look like too much space. So kerning makes the spacing between T and a smaller than, say, between ‘l’ and ‘a’.

In the case of ‘f’ and ‘i’ the Mac Roman character set contains two special glyphs that represent two characters : fl and fi. So in fact, in the example you provide, one can notice that it is not simply a question of spacing, but the bar in the f is linked to the top of the i. Other common ligatures in typography are st and ft.

Where the Mac has been much more typographically evolved than Windows for a couple decades is that kerning and glyph substitution is still optional in Windows applications, and mostly reserved for Desktop Publishing, whereas the Mac has that in all applications, and that includes Xojo TextArea and labels :)[/quote]

You beat me to it. As soon as I saw the title of the thread ligatures, rather than kerning, came to my mind.

Kerning, by default, may not have that much of an impact but ligatures definitively would. Kerning is a bigger problem in fancy fonts, like zapfino.

Imagine what the differences can be when calculating the width of the strings below by character or by whole words:

Indeed with such fonts we are entering calligraphy rather than typography, and character width becomes something else :wink:

Cool graphics.

And StyledTextPrinter should work with graphics objects, including the one in CellTextPaint event for a listbox.

How would you create the StyledTextPrinter instance without a TextArea? I just looked through the LR and can’t find a way.

I use an invisible textarea.

I see.

I thought about doing that and Drawinto. Is it what you do ?

Not drawinto!
Use styledtextprinter class and it’s draw method.

[quote=94106:@Christian Schmitz]Not drawinto!
Use styledtextprinter class and it’s draw method.[/quote]

StyledTextPrinter.DrawBlock ?

Of course

Allright. Thanks.

Thanks everyone for your answers.

Actually, I don’t really know what was wrong. After your comments I rewrote the code from scratch and now it works perfectly.

Sorry the trouble and thanks for the input again

Welcome

36 replies. Must have felt like you opened your door, a bus load of people entered chating and partyed quite a bit, and where gone again :wink:

Glad to read it works :slight_smile:

Michel, you’re right.

II posted it yesterday before I go out and when I checked today I felt astonished (!!!) with all those replies.

But, this spirit of sharing knowledge and willingness to help is what I really love in Xojo