Standard-Toolkit icon indicating copy to clipboard operation
Standard-Toolkit copied to clipboard

[Bug/Feature Request]: `KryptonLabel` does not support surrogates

Open neumatho opened this issue 7 months ago • 18 comments

As the topic says, KryptonLabel does not support unicode surrogates when rendering. Take this example:

Hello 👾

In the screenshot below, the first label is a normal WinForm label control. The second is a KryptonLabel. Both uses Segoe UI font size 18.

Image

neumatho avatar Jun 08 '25 12:06 neumatho

Hi @neumatho,

Thanks for posting.

If you switch UseCompatibleTextRendering on the WinForms label you can see that when set to true the label does not interpret the unicode character correctly.

The Kryptonlabel only uses Graphics.DrawString(), which is needed to display the label vertically (TextRenderer.DrawText() cannot rotate text) .

It might well be that Segoe does not have your character onboard. If it does it is a WinForms problem.

In this context we cannot not fix this given the vertical display functionality.

Image

giduac avatar Jun 15 '25 05:06 giduac

Hi @neumatho & @giduac

This one sounds like a feature request for EXT to me

cc. @Smurf-IV

PWagner1 avatar Jun 15 '25 06:06 PWagner1

It would be great if it at least could be toggled from a property.

neumatho avatar Jun 15 '25 07:06 neumatho

Hi @neumatho

Please can you open a new feature request on https://github.com/Krypton-Suite/Extended-Toolkit?

PWagner1 avatar Jun 15 '25 08:06 PWagner1

No , Not an Ext feature.. It's a compatibility issue with Unicode and should apply to all controls in Std.

Smurf-IV avatar Jun 15 '25 08:06 Smurf-IV

No , Not an Ext feature.. It's a compatibility issue with Unicode and should apply to all controls in Std.

So, is it really a bug/feature request?

PWagner1 avatar Jun 15 '25 08:06 PWagner1

So, is it really a bug/feature request?

If Winforms can do it, and Toolkit cannot, then yes. It's a bug.

Smurf-IV avatar Jun 15 '25 08:06 Smurf-IV

@PWagner1 @Smurf-IV,

For klabel it cannot be fixed because:

The Kryptonlabel only uses Graphics.DrawString(), which is needed to display the label vertically (TextRenderer.DrawText() cannot rotate text) .

It might well be that Segoe does not have your character onboard. If it does it is a WinForms problem.

giduac avatar Jun 15 '25 08:06 giduac

Hmm, Lot's of things in Toolkit perform text direction stuff. If the character are in UniCode, then fonts "Should" be able to draw them.

I wonder if an experiment with CanvasTextLayout could work

Smurf-IV avatar Jun 15 '25 09:06 Smurf-IV

Hmm, Lot's of things in Toolkit perform text direction stuff. If the character are in UniCode, then fonts "Should" be able to draw them.

I wonder if an experiment with CanvasTextLayout could work

I'd give it a try. Also don't forget that many of the controls were designed back in 2006, when UniCode characters weren't a 'thing'.

PWagner1 avatar Jun 15 '25 09:06 PWagner1

@neumatho Can "we" have a compressed example source project please ?

Smurf-IV avatar Jun 15 '25 09:06 Smurf-IV

@neumatho, @Smurf-IV @PWagner1

Here's some more background about this. https://github.com/dotnet/winforms/issues/7282

giduac avatar Jun 15 '25 10:06 giduac

And @neumatho can you please have a look using Character Map if Segoe does have this image of your onboard.

giduac avatar Jun 15 '25 10:06 giduac

CanvasTextLayout

@Smurf-IV

To short circuit things, can you please give a small example of how to use CanvasTextLayout which is part of WinUI in Winforms?

Thanks.

giduac avatar Jun 16 '25 05:06 giduac

Here is a test example. This character is not a single unicode value, but a combination of two unicode values (so called surrogates), more exactly 0xd83d and 0xdc7e for this character.

LabelTest.zip

neumatho avatar Jun 16 '25 14:06 neumatho

Here is a test example. This character is not a single unicode value, but a combination of two unicode values (so called surrogates), more exactly 0xd83d and 0xdc7e for this character.

LabelTest.zip

please read this ticket: https://github.com/dotnet/winforms/issues/7282

giduac avatar Jun 16 '25 14:06 giduac

CanvasTextLayout

@Smurf-IV

To short circuit things, can you please give a small example of how to use CanvasTextLayout which is part of WinUI in Winforms?

Thanks.

@Smurf-IV ,

Any other suggestions?

giduac avatar Jun 17 '25 17:06 giduac

Any other suggestions?

Not today, I'll see if I have time this Weekend to go hunting.

Smurf-IV avatar Jun 18 '25 06:06 Smurf-IV

@Smurf-IV,

Any other suggestions?

giduac avatar Jun 29 '25 11:06 giduac

@Smurf-IV,

Any other suggestions?

Still looking, Didn't get time these last 2 weekends to dedicate time to just this....

Smurf-IV avatar Jun 30 '25 06:06 Smurf-IV

@Smurf-IV,

Any other suggestions?

giduac avatar Jul 19 '25 18:07 giduac

@Smurf-IV,

Any other suggestions?

@giduac Maybe a "Flag" to switch to the other Text renderer, with a tooltip caveat? (For Labels and buttons only!) At least until a workaround that allows text direction etc to be taken care of for "All" the other areas text is drawn

@neumatho What I have done in the past is to put these type of "Glyphs" into an image, and then use that in the Label / button

Smurf-IV avatar Jul 20 '25 07:07 Smurf-IV

at? (F

@Smurf-IV

I thought about this. But it would be a mixed solution. Using Graphics when drawing vertical and TextRenderer when horizontal. That's a half solution...

At dotnet winforms they stated that they wont fix it for DN 4.x.x

What I have done in the past is to put these type of "Glyphs" into an image, and then use that in the Label / button

Maybe also a valid way to get there.

giduac avatar Jul 20 '25 07:07 giduac

Using Graphics when drawing vertical and TextRenderer when horizontal.

Hence a flag with the tootltip text stating that it will "not support directional text".

Smurf-IV avatar Jul 20 '25 07:07 Smurf-IV

Using Graphics when drawing vertical and TextRenderer when horizontal.

Hence a flag with the tootltip text stating that it will "not support directional text".

@Smurf-IV Let's do that, that'll make a lot of folk happy.

@neumatho What is your take on this please?

giduac avatar Jul 20 '25 07:07 giduac

@Smurf-IV

This is a change to AccurateText.Drawstring(...) AccurateText.StringFormatToFlags had bugs that have been resolved. Flags need a bit more work, but that is no problem. Changing AccurateText.DrawString is the way to go imo as is shown in the video below.

Image

https://github.com/user-attachments/assets/a6961b1b-234f-4aa0-b0f1-cb4ae6c7e942

giduac avatar Jul 21 '25 04:07 giduac

@neumatho

Please give this Draft PR a test: #2336

giduac avatar Jul 21 '25 16:07 giduac

It work better, but it seem to be clipped.

Image

neumatho avatar Jul 27 '25 14:07 neumatho

It work better, but it seem to be clipped.

Image

The one above looks good. What is the difference between the two labels?

giduac avatar Jul 27 '25 14:07 giduac

First one is Windows Form Label control. The second one is Krypton Label control. The problem seems to be with AutoSize. If I set it to false and set the width big enough, it renders fine.

neumatho avatar Jul 27 '25 14:07 neumatho