-
Notifications
You must be signed in to change notification settings - Fork 65
/
MathPainter.cs
55 lines (53 loc) · 2.65 KB
/
MathPainter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Drawing;
using CSharpMath.Structures;
using CSharpMath.Rendering.BackEnd;
using CSharpMath.Rendering.FrontEnd;
using SkiaSharp;
namespace CSharpMath.SkiaSharp {
public class MathPainter : MathPainter<SKCanvas, SKColor> {
public bool AntiAlias { get; set; } = true;
public void Draw(SKCanvas canvas, SKPoint point) => Draw(canvas, point.X, point.Y);
public override SKColor UnwrapColor(Color color) => color.ToNative();
public override Color WrapColor(SKColor color) => color.FromNative();
public override ICanvas WrapCanvas(SKCanvas canvas) =>
new SkiaCanvas(canvas, AntiAlias);
/// <summary>
/// Ignores the MathList and LaTeX of the <see cref="MathPainter"/> provided.
/// Repositions the <paramref name="display"/>.
/// </summary>
public static void DrawDisplay(MathPainter settings, Display.IDisplay<Fonts, Glyph>? display,
SKCanvas canvas, PointF position) =>
DrawDisplay(settings, display, _ => _.Draw(canvas, position));
/// <summary>
/// Ignores the MathList and LaTeX of the <see cref="MathPainter"/> provided.
/// Repositions the <paramref name="display"/>.
/// </summary>
public static void DrawDisplay(MathPainter settings, Display.IDisplay<Fonts, Glyph>? display,
SKCanvas canvas, SKPoint position) =>
DrawDisplay(settings, display, _ => _.Draw(canvas, position));
/// <summary>
/// Ignores the MathList and LaTeX of the <see cref="MathPainter"/> provided.
/// Repositions the <paramref name="display"/>.
/// </summary>
public static void DrawDisplay(MathPainter settings, Display.IDisplay<Fonts, Glyph>? display,
SKCanvas canvas, float x, float y) =>
DrawDisplay(settings, display, _ => _.Draw(canvas, x, y));
/// <summary>
/// Ignores the MathList and LaTeX of the <see cref="MathPainter"/> provided.
/// Repositions the <paramref name="display"/>.
/// </summary>
public static void DrawDisplay(MathPainter settings, Display.IDisplay<Fonts, Glyph>? display,
SKCanvas canvas, TextAlignment textAlignment = TextAlignment.Center,
Thickness padding = default, float offsetX = 0, float offsetY = 0) =>
DrawDisplay(settings, display, _ =>
_.Draw(canvas, textAlignment, padding, offsetX, offsetY));
private static void DrawDisplay(MathPainter settings, Display.IDisplay<Fonts, Glyph>? display,
System.Action<MathPainter> draw) {
if (display is null) return;
var original = (settings.Display, settings._displayChanged);
(settings.Display, settings._displayChanged) = (display, false);
draw(settings);
(settings.Display, settings._displayChanged) = original;
}
}
}