New TextPaintProperties for Font edging, hinting and sub-pixel positioning
This commit is contained in:
Родитель
1b46689a0c
Коммит
720e083f7c
|
@ -122,6 +122,21 @@ namespace Sandbox
|
|||
Invalidate();
|
||||
break;
|
||||
|
||||
case Keys.F1:
|
||||
_driver.SubpixelPositioning = !_driver.SubpixelPositioning;
|
||||
Invalidate();
|
||||
break;
|
||||
|
||||
case Keys.F2:
|
||||
_driver.Hinting = (SKFontHinting)(((int)_driver.Hinting + 1) % 4);
|
||||
Invalidate();
|
||||
break;
|
||||
|
||||
case Keys.F3:
|
||||
_driver.Edging = (SKFontEdging)(((int)_driver.Edging + 1) % 3);
|
||||
Invalidate();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -238,6 +238,9 @@ namespace SandboxDriver
|
|||
var options = new TextPaintOptions()
|
||||
{
|
||||
SelectionColor = new SKColor(0x60FF0000),
|
||||
Hinting = Hinting,
|
||||
Edging = Edging,
|
||||
SubpixelPositioning = SubpixelPositioning,
|
||||
};
|
||||
|
||||
HitTestResult? htr = null;
|
||||
|
@ -313,7 +316,7 @@ namespace SandboxDriver
|
|||
}
|
||||
}
|
||||
|
||||
var state = $"Size: {width} x {height} Base Direction: {BaseDirection} Alignment: {TextAlignment} Content: {ContentMode} scale: {Scale} time: {elapsed}";
|
||||
var state = $"Size: {width} x {height} Base Direction: {BaseDirection} Alignment: {TextAlignment} Content: {ContentMode} scale: {Scale} time: {elapsed} subpixel: {SubpixelPositioning} hinting: {Hinting} edging: {Edging}";
|
||||
canvas.DrawText(state, margin, 20, new SKPaint()
|
||||
{
|
||||
Typeface = SKTypeface.FromFamilyName("Arial"),
|
||||
|
@ -345,6 +348,10 @@ namespace SandboxDriver
|
|||
float _hitTestY;
|
||||
bool _showHitTest;
|
||||
|
||||
public SKFontEdging Edging = SKFontEdging.Antialias;
|
||||
public SKFontHinting Hinting = SKFontHinting.Normal;
|
||||
public bool SubpixelPositioning = true;
|
||||
|
||||
public void HitTest(float x, float y)
|
||||
{
|
||||
_hitTestX = x;
|
||||
|
|
|
@ -619,9 +619,6 @@ namespace Topten.RichTextKit
|
|||
|
||||
// Setup SKPaint
|
||||
paint.Color = Style.TextColor;
|
||||
paint.IsAntialias = ctx.Options.IsAntialias;
|
||||
paint.LcdRenderText = ctx.Options.LcdRenderText;
|
||||
paint.HintingLevel = ctx.Options.HintingLevel;
|
||||
|
||||
unsafe
|
||||
{
|
||||
|
@ -634,8 +631,10 @@ namespace Topten.RichTextKit
|
|||
if (_font == null)
|
||||
{
|
||||
_font = new SKFont(this.Typeface, this.Style.FontSize * glyphScale);
|
||||
_font.Subpixel = true;
|
||||
}
|
||||
_font.Hinting = ctx.Options.Hinting;
|
||||
_font.Edging = ctx.Options.Edging;
|
||||
_font.Subpixel = ctx.Options.SubpixelPositioning;
|
||||
|
||||
// Create the SKTextBlob (if necessary)
|
||||
if (_textBlob == null)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
// under the License.
|
||||
|
||||
using SkiaSharp;
|
||||
using System;
|
||||
|
||||
namespace Topten.RichTextKit
|
||||
{
|
||||
|
@ -26,7 +27,7 @@ namespace Topten.RichTextKit
|
|||
/// Constructs a new text paint options
|
||||
/// </summary>
|
||||
public TextPaintOptions()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,32 +82,53 @@ namespace Topten.RichTextKit
|
|||
} = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Controls whether text is rendered with anti-aliasing.
|
||||
/// Controls how font edges are drawn
|
||||
/// </summary>
|
||||
public bool IsAntialias
|
||||
public SKFontEdging Edging
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = SKFontEdging.Antialias;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Requests text be drawn at sub-pixel offsets
|
||||
/// </summary>
|
||||
public bool SubpixelPositioning
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = true;
|
||||
|
||||
/// <summary>
|
||||
/// Controls whether text is rendered with anti-aliasing.
|
||||
/// </summary>
|
||||
[Obsolete("Use Edging property instead of IsAntialias")]
|
||||
public bool IsAntialias
|
||||
{
|
||||
get => Edging != SKFontEdging.Alias;
|
||||
set => Edging = value ? SKFontEdging.Antialias : SKFontEdging.Alias;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controls whether text is rendered using LCD sub-pixel rendering.
|
||||
/// </summary>
|
||||
[Obsolete("Use Edging property instead of LcdRenderText")]
|
||||
public bool LcdRenderText
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = false;
|
||||
get => Edging == SKFontEdging.SubpixelAntialias;
|
||||
set => Edging = value ? SKFontEdging.SubpixelAntialias : SKFontEdging.Antialias;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Controls the font hint used when rendering text
|
||||
/// </summary>
|
||||
public SKPaintHinting HintingLevel
|
||||
public SKFontHinting Hinting
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = SKPaintHinting.Normal;
|
||||
} = SKFontHinting.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// A default set of paint options that renders text blocks without
|
||||
|
|
Загрузка…
Ссылка в новой задаче