Skip to content

Added Halo for FontRun - #44

Merged
toptensoftware merged 3 commits into
toptensoftware:masterfrom
charlenni:Halo
Jan 24, 2022
Merged

toptensoftware merged 3 commits into
toptensoftware:masterfrom
charlenni:Halo

Conversation

@charlenni

Copy link
Copy Markdown
Contributor

Added Halo to IStyle and Style
Added handling of Halo in FontRun
Added examples to SandboxDriver

This isn't far from perfect. The sizes aren't corrected for the halo. But I assume, that this isn't very important ;-)

Further, I don't know if there are other parts in RichTextKit, that draw anything to canvas.

The result looks like this:

grafik

Added handling of Halo in FontRun
Added examples to SandboxDriver
@m1dst

m1dst commented Jan 10, 2022 •

Copy link
Copy Markdown

This is exactly what I was looking for however I applied your changes but saw no halo applied.

My text is created using a RichString. I see no reference to FontRun in the RichString file so suspect further digging is required.... or I've screwed up.

An example of the style I tested..

var styleNormal = new Style
                                          {
                                            FontFamily = "OpenSans-Regular",
                                            FontSize = textSize,
                                            TextColor = SKColors.Yellow,
                                            HaloBlur = 5,
                                            HaloColor = SKColors.Red,
                                            HaloWidth = 5,
                                            LineHeight = 1.2f
                                        };

An example of the RichString

var rs = new RichString { DefaultStyle = styleNormal, MaxHeight = bitmap.Height, MaxWidth = bitmap.Width }
                        .Alignment(textAlignment)
                        .MarginLeft(textSize).MarginTop(textSize).MarginRight(textSize).MarginBottom(textSize)
                        .Add(pui.OverlayContent, fontSize: textSize);

Hope that helps.

@charlenni

Copy link
Copy Markdown
Contributor Author

You are right. Because I don't use RichString, I didn't see this problem. I added now the code to handle halo in RichString too. Perhaps you can test it?

@m1dst

m1dst commented Jan 10, 2022

Copy link
Copy Markdown

image

You nailed it. Thanks!

@charlenni

Copy link
Copy Markdown
Contributor Author

@m1dst Be careful. The halo isn't added to the measurements. If we want to do it correct, then width and height should be increased by Math.Max(haloWidth, haloBlur). But I assume, that halo is only used by small texts for special reasons.

@m1dst

m1dst commented Jan 10, 2022

Copy link
Copy Markdown

@charlenni Makes sense. In my use case I am using it to watermark images. Plenty of padding around it, all looks good.

@toptensoftware

Copy link
Copy Markdown
Owner

This isn't far from perfect

What exactly are the issues here? Is it just that the returned measured sizes don't include the halo size?

@charlenni

Copy link
Copy Markdown
Contributor Author

Yes. The halo isn't used to calculate the sizes. I'm still not sure, if this is a good or bad idea. The problem is, that the measured sizes aren't correct. I didn't look through RichTextKit to find the places, where this happens. If you say, we need it, then I could try to find them.

@toptensoftware
toptensoftware merged commit cee3a5f into toptensoftware:master Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants