|
| 1 | +namespace CSharpMath.Rendering.Tests { |
| 2 | + using System; |
| 3 | + using System.Drawing; |
| 4 | + using BackEnd; |
| 5 | + using Xunit; |
| 6 | + using CSharpMath.Display.FrontEnd; |
| 7 | + |
| 8 | + public class TestMeasure { |
| 9 | + class D : Display.IDisplay<Fonts, Glyph> { |
| 10 | + public float Ascent => 12; |
| 11 | + public float Descent => 3; |
| 12 | + public float Width => 10; |
| 13 | + |
| 14 | + public PointF Position { get => PointF.Empty; set => throw new NotImplementedException(); } |
| 15 | + public Atom.Range Range => throw new NotImplementedException(); |
| 16 | + public Structures.Color? TextColor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
| 17 | + public Structures.Color? BackColor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
| 18 | + public bool HasScript { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
| 19 | + public void Draw(IGraphicsContext<Fonts, Glyph> context) => throw new NotImplementedException(); |
| 20 | + public void SetTextColorRecursive(Structures.Color? textColor) => throw new NotImplementedException(); |
| 21 | + } |
| 22 | + class DEditorKeyboard : Editor.MathKeyboard<Fonts, Glyph> { |
| 23 | + public DEditorKeyboard() : base(TypesettingContext.Instance, new Fonts()) => |
| 24 | + Display = new Display.Displays.ListDisplay<Fonts, Glyph>(new[] { new D() }); |
| 25 | + } |
| 26 | + class DRenderingMath : SkiaSharp.MathPainter { |
| 27 | + public DRenderingMath() => |
| 28 | + Display = new Display.Displays.ListDisplay<Fonts, Glyph>(new[] { new D() }); |
| 29 | + protected override void UpdateDisplayCore(float unused) { } |
| 30 | + } |
| 31 | + class DRenderingText : SkiaSharp.TextPainter { |
| 32 | + public DRenderingText() => |
| 33 | + Display = new Display.Displays.ListDisplay<Fonts, Glyph>(new[] { new D() }); |
| 34 | + protected override void UpdateDisplayCore(float canvasWidth) { } |
| 35 | + } |
| 36 | + class DRenderingKeyboard : FrontEnd.MathKeyboard { |
| 37 | + public DRenderingKeyboard() => |
| 38 | + Display = new Display.Displays.ListDisplay<Fonts, Glyph>(new[] { new D() }); |
| 39 | + } |
| 40 | + /// <summary> |
| 41 | + /// CSharpMath and CSharpMath.Editor use the mathematical coordinate system, |
| 42 | + /// i.e. the rectangle position is at the bottom-left. |
| 43 | + /// </summary> |
| 44 | + [Fact] |
| 45 | + public void CoreMeasure_YIsNegDescent() { |
| 46 | + Assert.Equal(new RectangleF(0, -3, 10, 15), new D().DisplayBounds()); |
| 47 | + Assert.Equal(new RectangleF(0, -3, 10, 15), new DEditorKeyboard().Measure); |
| 48 | + } |
| 49 | + /// <summary> |
| 50 | + /// CSharpMath.Rendering and descendants use the graphical coordinate system, |
| 51 | + /// i.e. the rectangle position is at the top-left. |
| 52 | + /// </summary> |
| 53 | + [Fact] |
| 54 | + public void RenderingMeasure_YIsNegAscent() { |
| 55 | + Assert.Equal(new RectangleF(0, -12, 10, 15), new DRenderingMath().Measure()); |
| 56 | + Assert.Equal(new RectangleF(0, -12, 10, 15), new DRenderingText().Measure(float.NaN)); |
| 57 | + Assert.Equal(new RectangleF(0, -12, 10, 15), new DRenderingKeyboard().Measure); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments