-
Notifications
You must be signed in to change notification settings - Fork 809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option for clear type text #3846
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,12 @@ public class Label | |
public bool AntiAliasBackground { get; set; } = true; | ||
public bool AntiAliasText { get; set; } = true; | ||
|
||
/// <summary> | ||
/// To make use of ClearType text, you must also set the SKSurfaceProperties | ||
/// of your SKSurface to be something other than SKPixelGeometry.Unknown | ||
/// </summary> | ||
public bool SubPixelAntiAliasText { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if we should make this an enum, since setting I'm thinking something along the lines of enum TextAntialiasType {
None,
Antialias,
SubpixelAntialias,
} Then we can set the booleans but allow a simpler API. But we'll need to keep |
||
|
||
// TODO: use a class for cached typeface management | ||
|
||
private SKTypeface? CachedTypeface = null; | ||
|
@@ -170,6 +176,7 @@ private void ApplyTextPaint(SKPaint paint) | |
paint.TextSize = FontSize; | ||
paint.Color = ForeColor.ToSKColor(); | ||
paint.IsAntialias = AntiAliasText; | ||
paint.LcdRenderText = SubPixelAntiAliasText; | ||
paint.Shader = null; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is something that has to be enabled on the control, and I don't like the idea of having AA flags being placed in two very different places. I think the solution is probably making some
TextAntialiasType
a global field which is read in both places (maybe on thePlot
class?). And if necessary we can preserve some way for the user to mix unantialiased text with AA text. But I'm not convinced that the user would want something like that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the problem is that you have to be able to set SKSurfaceProperties when creating the SKSurface, which you can only do by implementing your own SKElement class (SKElement is implemented in SkiaSharp)
The only clean way I can see to do it would be to have a copy of the SkiaSharp SKElement class inside of the ScottPlot library itself. But appreciate you won't want to do that just for this use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already use
SKElement
on (most of) the controls. For example, see https://github.com/ScottPlot/ScottPlot/blob/main/src/ScottPlot5/ScottPlot5%20Controls/ScottPlot.WPF/Themes/Generic.xamlWorst case scenario, we can subclass
SKElement
to provide our ownOnRender
function (relevant code for WPF is here: https://github.com/mono/SkiaSharp/blob/main/source/SkiaSharp.Views/SkiaSharp.Views.WPF/SKElement.cs). But I'm admittedly not that pleased at the idea of duplicating most of the function just to allow a slightly differentSKSurface.Create
call. Granted it doesn't look like these views are changed much, but it doesn't fill me with joy. I do also see some private methods and fields which we'd need to copy-paste for this to work.This could also be achieved by copying , but that's not ideal, one of the big benefits of ScottPlot 5 is we don't normally need to copy bitmaps between the plot and the controls.