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; }
public static void Generate(string filename) { using (var stream = new SKFileWStream($"{filename}.pdf")) using (var document = SKDocument.CreatePdf(stream)) { for (int i = 0; i < latexes.Length; i++) { var painter = new CSharpMath.SkiaSharp.MathPainter(12) { LaTeX = $@"\displaystyle {latexes[i]}" }; var rect = painter.Measure.Value; using (var canvas = document.BeginPage(rect.Width, rect.Height)) { canvas.Translate(0, -rect.Top); painter.Draw(canvas, new SKPoint(0, 0)); canvas.DrawRect(rect.Left, rect.Top, rect.Width, rect.Height, redStroke); document.EndPage(); } } } }
/// <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));
/// <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, SKPoint position) => DrawDisplay(settings, display, _ => _.Draw(canvas, position));