diff --git a/CSharpMath.Apple/BackEnd/AppleGraphicsContext.cs b/CSharpMath.Apple/BackEnd/AppleGraphicsContext.cs index 52b813ab..68bdbf5e 100644 --- a/CSharpMath.Apple/BackEnd/AppleGraphicsContext.cs +++ b/CSharpMath.Apple/BackEnd/AppleGraphicsContext.cs @@ -4,7 +4,6 @@ using CoreGraphics; using CoreText; using CSharpMath.Display; -using Color = CSharpMath.Structures.Color; using TFont = CSharpMath.Apple.AppleMathFont; using TGlyph = System.UInt16; diff --git a/CSharpMath.Apple/Extensions/AttributedGlyphRun.cs b/CSharpMath.Apple/Extensions/AttributedGlyphRun.cs index b56dc9c3..6aede197 100644 --- a/CSharpMath.Apple/Extensions/AttributedGlyphRun.cs +++ b/CSharpMath.Apple/Extensions/AttributedGlyphRun.cs @@ -23,7 +23,7 @@ public static NSMutableAttributedString ToNsAttributedString if (kernedGlyphs[i].KernAfterGlyph is var kern && !(kern is 0)) attributedString.AddAttribute (CTStringAttributeKey.KerningAdjustment, new NSNumber(kern), range); - if (kernedGlyphs[i].Foreground is Structures.Color foreground) + if (kernedGlyphs[i].Foreground is System.Drawing.Color foreground) attributedString.AddAttribute(CTStringAttributeKey.ForegroundColor, ObjCRuntime.Runtime.GetNSObject(foreground.ToCGColor().Handle), range); } diff --git a/CSharpMath.Apple/Extensions/Color.cs b/CSharpMath.Apple/Extensions/Color.cs index 84cbbe3a..828c7de9 100644 --- a/CSharpMath.Apple/Extensions/Color.cs +++ b/CSharpMath.Apple/Extensions/Color.cs @@ -1,9 +1,9 @@ namespace CSharpMath.Apple { - using Structures; + using System.Drawing; partial class Extensions { public static CoreGraphics.CGColor ToCGColor(this Color color) => - new CoreGraphics.CGColor(color.Rf, color.Gf, color.Bf, color.Af); + new CoreGraphics.CGColor(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); public static UIKit.UIColor ToUIColor(this Color color) => - new UIKit.UIColor(color.Rf, color.Gf, color.Bf, color.Af); + new UIKit.UIColor(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); } } \ No newline at end of file diff --git a/CSharpMath.Avalonia/AvaloniaCanvas.cs b/CSharpMath.Avalonia/AvaloniaCanvas.cs index 74d97f24..0e6e276a 100644 --- a/CSharpMath.Avalonia/AvaloniaCanvas.cs +++ b/CSharpMath.Avalonia/AvaloniaCanvas.cs @@ -4,7 +4,7 @@ using Avalonia.Media; using CSharpMath.Rendering.FrontEnd; -using CSharpMathColor = CSharpMath.Structures.Color; +using CSharpMathColor = System.Drawing.Color; namespace CSharpMath.Avalonia { public sealed class AvaloniaCanvas : ICanvas { diff --git a/CSharpMath.Avalonia/AvaloniaPath.cs b/CSharpMath.Avalonia/AvaloniaPath.cs index 7794ff6a..cddedd98 100644 --- a/CSharpMath.Avalonia/AvaloniaPath.cs +++ b/CSharpMath.Avalonia/AvaloniaPath.cs @@ -1,5 +1,5 @@ using CSharpMath.Rendering.FrontEnd; -using CSharpMathColor = CSharpMath.Structures.Color; +using CSharpMathColor = System.Drawing.Color; using Avalonia; using Avalonia.Media; diff --git a/CSharpMath.Avalonia/Extensions.cs b/CSharpMath.Avalonia/Extensions.cs index 6e0b19a7..a5d79cda 100644 --- a/CSharpMath.Avalonia/Extensions.cs +++ b/CSharpMath.Avalonia/Extensions.cs @@ -1,5 +1,3 @@ -using SizeF = System.Drawing.SizeF; - using Avalonia; using Avalonia.Media; using Avalonia.Media.Imaging; @@ -7,16 +5,15 @@ using AvaloniaTextAlignment = Avalonia.Media.TextAlignment; using CSharpMath.Rendering.FrontEnd; -using CSharpMathColor = CSharpMath.Structures.Color; using CSharpMathTextAlignment = CSharpMath.Rendering.FrontEnd.TextAlignment; namespace CSharpMath.Avalonia { public static class Extensions { - public static AvaloniaColor ToAvaloniaColor(this CSharpMathColor color) => + public static AvaloniaColor ToAvaloniaColor(this System.Drawing.Color color) => new AvaloniaColor(color.A, color.R, color.G, color.B); - internal static CSharpMathColor ToCSharpMathColor(this AvaloniaColor color) => - new CSharpMathColor(color.R, color.G, color.B, color.A); + internal static System.Drawing.Color ToCSharpMathColor(this AvaloniaColor color) => + System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B); internal static CSharpMathTextAlignment ToCSharpMathTextAlignment(this AvaloniaTextAlignment alignment) => alignment switch @@ -27,7 +24,7 @@ internal static CSharpMathTextAlignment ToCSharpMathTextAlignment(this AvaloniaT _ => CSharpMathTextAlignment.Left }; - public static SolidColorBrush ToSolidColorBrush(this CSharpMathColor color) => + public static SolidColorBrush ToSolidColorBrush(this System.Drawing.Color color) => new SolidColorBrush(color.ToAvaloniaColor()); class DrawVisual : Visual where TContent : class { diff --git a/CSharpMath.Avalonia/MathPainter.cs b/CSharpMath.Avalonia/MathPainter.cs index 5353bf76..d36ac352 100644 --- a/CSharpMath.Avalonia/MathPainter.cs +++ b/CSharpMath.Avalonia/MathPainter.cs @@ -1,7 +1,7 @@ using AvaloniaColor = Avalonia.Media.Color; using CSharpMath.Rendering.FrontEnd; -using CSharpMathColor = CSharpMath.Structures.Color; +using CSharpMathColor = System.Drawing.Color; namespace CSharpMath.Avalonia { public sealed class MathPainter : MathPainter { diff --git a/CSharpMath.Avalonia/TextPainter.cs b/CSharpMath.Avalonia/TextPainter.cs index fbbb30fb..cdfc4321 100644 --- a/CSharpMath.Avalonia/TextPainter.cs +++ b/CSharpMath.Avalonia/TextPainter.cs @@ -1,7 +1,7 @@ using AvaloniaColor = Avalonia.Media.Color; using CSharpMath.Rendering.FrontEnd; -using CSharpMathColor = CSharpMath.Structures.Color; +using CSharpMathColor = System.Drawing.Color; namespace CSharpMath.Avalonia { public sealed class TextPainter : TextPainter { diff --git a/CSharpMath.CoreTests/LaTeXParserTest.cs b/CSharpMath.CoreTests/LaTeXParserTest.cs index a0d642f3..a5c481da 100644 --- a/CSharpMath.CoreTests/LaTeXParserTest.cs +++ b/CSharpMath.CoreTests/LaTeXParserTest.cs @@ -456,9 +456,9 @@ public void TestMatrix(string env, string left, string right, string leftOutput, [InlineData(@"\color{red}{{\left( \begin{matrix}1&2\\ 3&4\end{matrix}\right) }}")] public void TestRedMatrix(string input) { var list = ParseLaTeX(input); - Assert.Collection(list, CheckAtom("", color => { - Assert.Equal(new Structures.Color(255, 0, 0), color.Colour); - Assert.Collection(color.InnerList, + Assert.Collection(list, CheckAtom("", colored => { + Assert.Equal(System.Drawing.Color.FromArgb(255, 0, 0), colored.Color); + Assert.Collection(colored.InnerList, CheckAtom("", inner => { Assert.Equal(new Boundary("("), inner.LeftBoundary); Assert.Equal(new Boundary(")"), inner.RightBoundary); @@ -1091,29 +1091,29 @@ public void TestNoLimits(string input, string output, bool? limits) { // Sync with CSharpMath.Rendering.Text.Tests TextLaTeXParserTests [Theory] - [InlineData("0xFFF", "white", 0xFF, 0xFF, 0xFF)] - [InlineData("#ff0", "yellow", 0xFF, 0xFF, 0x00)] - [InlineData("0xf00f", "blue", 0x00, 0x00, 0xFF)] - [InlineData("#F0F0", "lime", 0x00, 0xFF, 0x00)] - [InlineData("0x008000", "green", 0x00, 0x80, 0x00)] + [InlineData("#FFFFFF", "white", 0xFF, 0xFF, 0xFF)] + [InlineData("#ffff00", "yellow", 0xFF, 0xFF, 0x00)] + [InlineData("#ff0000ff", "blue", 0x00, 0x00, 0xFF)] + [InlineData("#FF00FF00", "lime", 0x00, 0xFF, 0x00)] + [InlineData("#008000", "green", 0x00, 0x80, 0x00)] [InlineData("#d3D3d3", "lightgray", 0xD3, 0xD3, 0xD3)] - [InlineData("0xFf000000", "black", 0x00, 0x00, 0x00)] + [InlineData("#Ff000000", "black", 0x00, 0x00, 0x00)] [InlineData("#fFa9A9a9", "gray", 0xA9, 0xA9, 0xA9)] [InlineData("cyan", "cyan", 0x00, 0xFF, 0xFF)] [InlineData("BROWN", "brown", 0x96, 0x4B, 0x00)] [InlineData("oLIve", "olive", 0x80, 0x80, 0x00)] - [InlineData("0x12345678", "#12345678", 0x34, 0x56, 0x78, 0x12)] + [InlineData("#12345678", "#12345678", 0x34, 0x56, 0x78, 0x12)] [InlineData("#fedcba98", "#FEDCBA98", 0xDC, 0xBA, 0x98, 0xFE)] public void TestColor(string inColor, string outColor, byte r, byte g, byte b, byte a = 0xFF) { var list = ParseLaTeX($@"\color{{{inColor}}}ab"); Assert.Collection(list, - CheckAtom("", color => { - Assert.Equal(r, color.Colour.R); - Assert.Equal(g, color.Colour.G); - Assert.Equal(b, color.Colour.B); - Assert.Equal(a, color.Colour.A); - Assert.False(color.ScriptsAllowed); - Assert.Collection(color.InnerList, CheckAtom("a")); + CheckAtom("", colored => { + Assert.Equal(r, colored.Color.R); + Assert.Equal(g, colored.Color.G); + Assert.Equal(b, colored.Color.B); + Assert.Equal(a, colored.Color.A); + Assert.False(colored.ScriptsAllowed); + Assert.Collection(colored.InnerList, CheckAtom("a")); }), CheckAtom("b") ); @@ -1121,13 +1121,13 @@ public void TestColor(string inColor, string outColor, byte r, byte g, byte b, b list = ParseLaTeX($@"\colorbox{{{inColor}}}ab"); Assert.Collection(list, - CheckAtom("", color => { - Assert.Equal(r, color.Colour.R); - Assert.Equal(g, color.Colour.G); - Assert.Equal(b, color.Colour.B); - Assert.Equal(a, color.Colour.A); - Assert.False(color.ScriptsAllowed); - Assert.Collection(color.InnerList, CheckAtom("a")); + CheckAtom("", colorBox => { + Assert.Equal(r, colorBox.Color.R); + Assert.Equal(g, colorBox.Color.G); + Assert.Equal(b, colorBox.Color.B); + Assert.Equal(a, colorBox.Color.A); + Assert.False(colorBox.ScriptsAllowed); + Assert.Collection(colorBox.InnerList, CheckAtom("a")); }), CheckAtom("b") ); @@ -1138,18 +1138,18 @@ public void TestColor(string inColor, string outColor, byte r, byte g, byte b, b public void TestColorScripts() { var list = ParseLaTeX(@"\color{red}1\colorbox{blue}2"); Assert.Collection(list, - CheckAtom("", color => { - Assert.Equal("red", color.Colour.ToString()); - Assert.Empty(color.Superscript); - Assert.Throws(() => color.Superscript.Add(new Variable("a"))); - Assert.Throws(() => color.Superscript.Append(new MathList(new Variable("a")))); - Assert.Empty(color.Subscript); - Assert.Throws(() => color.Subscript.Add(new Variable("b"))); - Assert.Throws(() => color.Subscript.Append(new MathList(new Variable("b")))); - Assert.Collection(color.InnerList, CheckAtom("1")); + CheckAtom("", colored => { + Assert.Equal("red", LaTeXSettings.ColorToString(colored.Color, new StringBuilder()).ToString()); + Assert.Empty(colored.Superscript); + Assert.Throws(() => colored.Superscript.Add(new Variable("a"))); + Assert.Throws(() => colored.Superscript.Append(new MathList(new Variable("a")))); + Assert.Empty(colored.Subscript); + Assert.Throws(() => colored.Subscript.Add(new Variable("b"))); + Assert.Throws(() => colored.Subscript.Append(new MathList(new Variable("b")))); + Assert.Collection(colored.InnerList, CheckAtom("1")); }), CheckAtom("", colorBox => { - Assert.Equal("blue", colorBox.Colour.ToString()); + Assert.Equal("blue", LaTeXSettings.ColorToString(colorBox.Color, new StringBuilder()).ToString()); Assert.Empty(colorBox.Superscript); Assert.Throws(() => colorBox.Superscript.Add(new Variable("a"))); Assert.Throws(() => colorBox.Superscript.Append(new MathList(new Variable("a")))); diff --git a/CSharpMath.CoreTests/MathAtomTest.cs b/CSharpMath.CoreTests/MathAtomTest.cs index 98a4c1d1..4d6dc8f2 100644 --- a/CSharpMath.CoreTests/MathAtomTest.cs +++ b/CSharpMath.CoreTests/MathAtomTest.cs @@ -184,16 +184,16 @@ public void TestCopyOpen() { CheckClone(open.Subscript, clone.Subscript); } [Fact] - public void TestCopyColor() { - var color = new Color(new Structures.Color(255, 0, 0), new MathList(new Open("("))); - var clone = color.Clone(false); - Assert.Equal(new Structures.Color(255, 0, 0), clone.Colour); - CheckClone(color, clone); - CheckClone(color.InnerList, clone.InnerList); + public void TestCopyColored() { + var colored = new Colored(System.Drawing.Color.FromArgb(255, 0, 0), new MathList(new Open("("))); + var clone = colored.Clone(false); + Assert.Equal(System.Drawing.Color.FromArgb(255, 0, 0), clone.Color); + CheckClone(colored, clone); + CheckClone(colored.InnerList, clone.InnerList); - var colorBox = new ColorBox(new Structures.Color(128, 0, 0), new MathList(new Close(")"))); + var colorBox = new ColorBox(System.Drawing.Color.FromArgb(128, 0, 0), new MathList(new Close(")"))); var cloneBox = colorBox.Clone(false); - Assert.Equal(new Structures.Color(128, 0, 0), cloneBox.Colour); + Assert.Equal(System.Drawing.Color.FromArgb(128, 0, 0), cloneBox.Color); CheckClone(colorBox, cloneBox); CheckClone(colorBox.InnerList, cloneBox.InnerList); } diff --git a/CSharpMath.CoreTests/TypesetterTests.cs b/CSharpMath.CoreTests/TypesetterTests.cs index 02a0022d..68fefb40 100644 --- a/CSharpMath.CoreTests/TypesetterTests.cs +++ b/CSharpMath.CoreTests/TypesetterTests.cs @@ -462,11 +462,11 @@ public void TestColor() => TestOuter(@"\color{red}\color{blue}x\colorbox{yellow}\colorbox{green}yz", 3, 14, 4, 30, l1 => { Assert.Null(l1.BackColor); - Assert.Equal(Structures.Color.PredefinedColors["red"], l1.TextColor); + Assert.Equal(LaTeXSettings.PredefinedColors["red"], l1.TextColor); TestList(1, 14, 4, 10, 0, 0, LinePosition.Regular, Range.UndefinedInt, l2 => { Assert.Null(l2.BackColor); - Assert.Equal(Structures.Color.PredefinedColors["blue"], l2.TextColor); + Assert.Equal(LaTeXSettings.PredefinedColors["blue"], l2.TextColor); TestList(1, 14, 4, 10, 0, 0, LinePosition.Regular, Range.UndefinedInt, d => { var line = Assert.IsType>(d); Assert.Single(line.Atoms); @@ -474,16 +474,16 @@ public void TestColor() => Assert.Equal(new PointF(), line.Position); Assert.False(line.HasScript); Assert.Null(line.BackColor); - Assert.Equal(Structures.Color.PredefinedColors["blue"], line.TextColor); + Assert.Equal(LaTeXSettings.PredefinedColors["blue"], line.TextColor); })(l2); })(l1); }, l1 => { - Assert.Equal(Structures.Color.PredefinedColors["yellow"], l1.BackColor); + Assert.Equal(LaTeXSettings.PredefinedColors["yellow"], l1.BackColor); Assert.Null(l1.TextColor); TestList(1, 14, 4, 10, 10, 0, LinePosition.Regular, Range.UndefinedInt, l2 => { - Assert.Equal(Structures.Color.PredefinedColors["green"], l2.BackColor); + Assert.Equal(LaTeXSettings.PredefinedColors["green"], l2.BackColor); Assert.Null(l2.TextColor); TestList(1, 14, 4, 10, 0, 0, LinePosition.Regular, Range.UndefinedInt, d => { var line = Assert.IsType>(d); diff --git a/CSharpMath.Editor.Tests.FSharp/RandomKeyboardInputsTest.fs b/CSharpMath.Editor.Tests.FSharp/RandomKeyboardInputsTest.fs index e3781a07..c287c65f 100644 --- a/CSharpMath.Editor.Tests.FSharp/RandomKeyboardInputsTest.fs +++ b/CSharpMath.Editor.Tests.FSharp/RandomKeyboardInputsTest.fs @@ -48,7 +48,7 @@ let rec private findShortening(kl:MathKeyboardInput list) = [] let ``random inputs don't crash editor``() = - let results = List.init 500 (fun _ -> test100keypresses()) + let results = List.init 100 (fun _ -> test100keypresses()) let shortestError = results |> List.choose (function Ok _ -> None | Error e -> Some e) diff --git a/CSharpMath.Editor.Tests.Visualizer/Checker.cs b/CSharpMath.Editor.Tests.Visualizer/Checker.cs index 10000492..e0454da2 100644 --- a/CSharpMath.Editor.Tests.Visualizer/Checker.cs +++ b/CSharpMath.Editor.Tests.Visualizer/Checker.cs @@ -154,7 +154,7 @@ public static void ConsoleFillRectangle(Rectangle rect, Color? color) { Console.ResetColor(); } public static void ConsoleDrawHorizontal - (int x1_, int y_, int x2_, int thickness, Structures.Color? color) { + (int x1_, int y_, int x2_, int thickness, Color? color) { var rect = Adjust(Rectangle.FromLTRB(x1_, y_ - thickness / 2, x2_, y_ + thickness / 2)); SetConsoleColor(color); for (int i = 0; i < thickness; i++) { diff --git a/CSharpMath.Editor.Tests.Visualizer/GraphicsContext.cs b/CSharpMath.Editor.Tests.Visualizer/GraphicsContext.cs index fe9a3472..0849070b 100644 --- a/CSharpMath.Editor.Tests.Visualizer/GraphicsContext.cs +++ b/CSharpMath.Editor.Tests.Visualizer/GraphicsContext.cs @@ -10,7 +10,7 @@ public class GraphicsContext : Display.FrontEnd.IGraphicsContext readonly Stack stack = new Stack(); PointF trans = new PointF(); public void DrawGlyphRunWithOffset(AttributedGlyphRun text, - PointF point, Structures.Color? color) { + PointF point, Color? color) { var advance = 0.0; foreach (var ((glyph, kernAfter, foreground), bounds) in text.GlyphInfos.Zip( @@ -25,7 +25,7 @@ public void DrawGlyphRunWithOffset(AttributedGlyphRun text, } } public void DrawGlyphsAtPoints(IReadOnlyList glyphs, - TestFont font, IEnumerable points, Structures.Color? color) { + TestFont font, IEnumerable points, Color? color) { var zipped = glyphs.Zip(points, ValueTuple.Create); var bounds = TestTypesettingContexts.Instance.GlyphBoundsProvider .GetBoundingRectsForGlyphs(font, glyphs, glyphs.Count); @@ -37,10 +37,10 @@ public void DrawGlyphsAtPoints(IReadOnlyList glyphs, ); } } - public void FillRect(RectangleF rect, Structures.Color color) => + public void FillRect(RectangleF rect, Color color) => Checker.ConsoleFillRectangle(new Rectangle((int)(rect.X + trans.X), (int)(rect.Y + trans.Y), (int)rect.Width, (int)rect.Height), color); public void DrawLine - (float x1, float y1, float x2, float y2, float strokeWidth, Structures.Color? color) { + (float x1, float y1, float x2, float y2, float strokeWidth, Color? color) { if (y1 != y2) throw new NotImplementedException("Non-horizontal lines currently not supported"); if (!Checker.OutputLines) return; Checker.ConsoleDrawHorizontal((int)(x1 + trans.X), (int)(y1 + trans.Y), (int)(x2 + trans.X), diff --git a/CSharpMath.Editor/Extensions/FractionDisplay.cs b/CSharpMath.Editor/Extensions/FractionDisplay.cs index f79e0fc7..13b59ad3 100644 --- a/CSharpMath.Editor/Extensions/FractionDisplay.cs +++ b/CSharpMath.Editor/Extensions/FractionDisplay.cs @@ -1,10 +1,8 @@ namespace CSharpMath.Editor { using System; using System.Drawing; - using Display.Displays; using Display.FrontEnd; - using Color = Structures.Color; partial class Extensions { public static MathListIndex IndexForPoint( diff --git a/CSharpMath.Editor/Extensions/IDisplay.cs b/CSharpMath.Editor/Extensions/IDisplay.cs index 5f6e17fa..7208e3d9 100644 --- a/CSharpMath.Editor/Extensions/IDisplay.cs +++ b/CSharpMath.Editor/Extensions/IDisplay.cs @@ -65,7 +65,7 @@ public static float DistanceFromPointToRect(PointF point, RectangleF rect) { _ => null, }; public static void HighlightCharacterAt - (this IDisplay display, MathListIndex index, Structures.Color color) + (this IDisplay display, MathListIndex index, Color color) where TFont : IFont { switch (display) { case TextLineDisplay text: @@ -93,7 +93,7 @@ public static void HighlightCharacterAt break; } } - public static void Highlight(this IDisplay display, Structures.Color color) + public static void Highlight(this IDisplay display, Color color) where TFont : IFont { switch (display) { case TextLineDisplay text: diff --git a/CSharpMath.Editor/Extensions/IGlyphDisplay.cs b/CSharpMath.Editor/Extensions/IGlyphDisplay.cs index 2097fcac..c287f91c 100644 --- a/CSharpMath.Editor/Extensions/IGlyphDisplay.cs +++ b/CSharpMath.Editor/Extensions/IGlyphDisplay.cs @@ -1,10 +1,8 @@ namespace CSharpMath.Editor { using System; using System.Drawing; - using Display; using Display.FrontEnd; - using Color = Structures.Color; partial class Extensions { public static MathListIndex IndexForPoint( diff --git a/CSharpMath.Editor/Extensions/InnerDisplay.cs b/CSharpMath.Editor/Extensions/InnerDisplay.cs index 789abd8a..941a314a 100644 --- a/CSharpMath.Editor/Extensions/InnerDisplay.cs +++ b/CSharpMath.Editor/Extensions/InnerDisplay.cs @@ -1,10 +1,8 @@ namespace CSharpMath.Editor { using System; using System.Drawing; - using Display.Displays; using Display.FrontEnd; - using Color = Structures.Color; partial class Extensions { public static MathListIndex IndexForPoint( diff --git a/CSharpMath.Editor/Extensions/LargeOpLimitsDisplay.cs b/CSharpMath.Editor/Extensions/LargeOpLimitsDisplay.cs index fecb8e75..2f37f37e 100644 --- a/CSharpMath.Editor/Extensions/LargeOpLimitsDisplay.cs +++ b/CSharpMath.Editor/Extensions/LargeOpLimitsDisplay.cs @@ -1,11 +1,9 @@ namespace CSharpMath.Editor { using System; using System.Drawing; - using Display; using Display.Displays; using Display.FrontEnd; - using Color = Structures.Color; partial class Extensions { public static MathListIndex IndexForPoint( diff --git a/CSharpMath.Editor/Extensions/ListDisplay.cs b/CSharpMath.Editor/Extensions/ListDisplay.cs index 1bc05771..1d97117b 100644 --- a/CSharpMath.Editor/Extensions/ListDisplay.cs +++ b/CSharpMath.Editor/Extensions/ListDisplay.cs @@ -7,7 +7,6 @@ namespace CSharpMath.Editor { using Display.Displays; using Display.FrontEnd; using Structures; - using Color = Structures.Color; partial class Extensions { public static MathListIndex? IndexForPoint diff --git a/CSharpMath.Editor/Extensions/RadicalDisplay.cs b/CSharpMath.Editor/Extensions/RadicalDisplay.cs index f543e4ee..56fcdc05 100644 --- a/CSharpMath.Editor/Extensions/RadicalDisplay.cs +++ b/CSharpMath.Editor/Extensions/RadicalDisplay.cs @@ -1,10 +1,8 @@ namespace CSharpMath.Editor { using System; using System.Drawing; - using Display.Displays; using Display.FrontEnd; - using Color = Structures.Color; partial class Extensions { public static MathListIndex IndexForPoint( diff --git a/CSharpMath.Editor/Extensions/TextLineDisplay.cs b/CSharpMath.Editor/Extensions/TextLineDisplay.cs index a90a0200..4fd9ed97 100644 --- a/CSharpMath.Editor/Extensions/TextLineDisplay.cs +++ b/CSharpMath.Editor/Extensions/TextLineDisplay.cs @@ -2,12 +2,10 @@ namespace CSharpMath.Editor { using System; using System.Drawing; using System.Linq; - using Display; using Display.Displays; using Display.FrontEnd; using Structures; - using Color = Structures.Color; partial class Extensions { public static int? GlyphIndexForXOffset diff --git a/CSharpMath.Editor/MathKeyboard.cs b/CSharpMath.Editor/MathKeyboard.cs index 542975ff..5dfb427f 100644 --- a/CSharpMath.Editor/MathKeyboard.cs +++ b/CSharpMath.Editor/MathKeyboard.cs @@ -85,7 +85,7 @@ public MathListIndex InsertionIndex { } public TFont Font { get; set; } public LineStyle LineStyle { get; set; } - public Structures.Color SelectColor { get; set; } + public Color SelectColor { get; set; } public virtual RectangleF Measure => Display?.DisplayBounds() ?? RectangleF.Empty; public bool HasText => MathList?.Atoms?.Count > 0; public void RecreateDisplayFromMathList() { @@ -430,7 +430,7 @@ void InsertSymbolName(string name, bool subscript = false, bool superscript = fa } switch (input) { -#warning Unimplemented up/down buttons + // TODO: Implement up/down buttons case MathKeyboardInput.Up: break; case MathKeyboardInput.Down: @@ -861,7 +861,7 @@ public void InsertMathList(MathList list, PointF point) { InsertionIndex = index; // move the index to the end of the new list. } - public void HighlightCharacterAt(MathListIndex index, Structures.Color color) { + public void HighlightCharacterAt(MathListIndex index, Color color) { // setup highlights before drawing the MTLine Display?.HighlightCharacterAt(index, color); RedrawRequested?.Invoke(this, EventArgs.Empty); diff --git a/CSharpMath.Forms.Example/CSharpMath.Forms.Example.Ooui/CSharpMath.Forms.Example.Ooui.csproj b/CSharpMath.Forms.Example/CSharpMath.Forms.Example.Ooui/CSharpMath.Forms.Example.Ooui.csproj deleted file mode 100644 index 04ea8b4d..00000000 --- a/CSharpMath.Forms.Example/CSharpMath.Forms.Example.Ooui/CSharpMath.Forms.Example.Ooui.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - - - diff --git a/CSharpMath.Forms.Example/CSharpMath.Forms.Example.Ooui/Program.cs b/CSharpMath.Forms.Example/CSharpMath.Forms.Example.Ooui/Program.cs deleted file mode 100644 index a4d10996..00000000 --- a/CSharpMath.Forms.Example/CSharpMath.Forms.Example.Ooui/Program.cs +++ /dev/null @@ -1,84 +0,0 @@ -using Ooui; -using Xamarin.Forms; - -namespace CSharpMath.Forms.Example.Ooui { - using CSharpMath.Rendering.FrontEnd; - using CSharpMath.Structures; - class Program { - static void Main(string[] args) { - Xamarin.Forms.Forms.Init(); - // Throws unfortuately, needs SkiaSharp renderer - var canvas = new Canvas { Width = 400, Height = 400, Style = { BackgroundColor = new global::Ooui.Color(128, 128, 128), Color = "#00FF00" } }; - var context = canvas.GetContext2D(); - context.Rect(10, 10, canvas.Width - 20, canvas.Height - 20); - context.Fill(); - canvas.Click += (s, e) => { - var radius = 10; - new MathPainter { FontSize = 10, LaTeX = @"\raisebox{-40pt}a" }.Draw(canvas, TextAlignment.TopLeft); - }; - new MathPainter { LaTeX = "1+2" }.Draw(canvas, TextAlignment.TopLeft); - UI.Publish("/", new Div(new global::Ooui.Button("Hi!"), canvas)); - System.Console.WriteLine("Server ready! Press Enter to terminate..."); - System.Console.ReadLine(); - } - public sealed class OouiPath : Path { - public OouiPath(CanvasRenderingContext2D context) { - this.context = context; - context.BeginPath(); - } - public override Color? Foreground { get; set; } - private readonly CanvasRenderingContext2D context; - public override void MoveTo(float x0, float y0) { - context.ClosePath(); - context.BeginPath(); - context.MoveTo(x0, y0); - } - public override void LineTo(float x1, float y1) => context.LineTo(x1, y1); - public override void Curve3(float x1, float y1, float x2, float y2) => - context.QuadraticCurveTo(x1, y1, x2, y2); - public override void Curve4(float x1, float y1, float x2, float y2, float x3, float y3) => - context.BezierCurveTo(x1, y1, x2, y2, x3, y3); - public override void CloseContour() => context.ClosePath(); - public override void Dispose() { - context.Fill(); - } - } - public sealed class OouiCanvas : ICanvas { - readonly Canvas canvas; - readonly CanvasRenderingContext2D context; - public OouiCanvas(Canvas canvas) { - this.canvas = canvas; - context = canvas.GetContext2D(); - } - public float Width => canvas.Width; - public float Height => canvas.Height; - public Color DefaultColor { get; set; } - public Color? CurrentColor { get; set; } - public PaintStyle CurrentStyle { get;set; } - - public void DrawLine(float x1, float y1, float x2, float y2, float lineThickness) { - context.BeginPath(); - context.MoveTo(x1, y1); - context.LineTo(x2, y2); - context.ClosePath(); - context.Fill(); - } - public void FillRect(float left, float top, float width, float height) => - context.FillRect(left, top, width, height); - public void Restore() => context.Restore(); - public void Save() => context.Save(); - public void Scale(float sx, float sy) => context.Scale(sx, sy); - public Path StartNewPath() => new OouiPath(context); - public void StrokeRect(float left, float top, float width, float height) => - context.StrokeRect(left, top, width, height); - public void Translate(float dx, float dy) => context.Translate(dx, dy); - } - class MathPainter : MathPainter { - public override global::Ooui.Color UnwrapColor(Color color) => - new global::Ooui.Color(color.R, color.G, color.B, color.A); - public override ICanvas WrapCanvas(Canvas canvas) => new OouiCanvas(canvas); - public override Color WrapColor(global::Ooui.Color color) => - new Color(color.R, color.G, color.B, color.A); - } - } -} \ No newline at end of file diff --git a/CSharpMath.Forms/MathKeyboardExtensions.cs b/CSharpMath.Forms/MathKeyboardExtensions.cs index 2e6a5cd0..246f3cdb 100644 --- a/CSharpMath.Forms/MathKeyboardExtensions.cs +++ b/CSharpMath.Forms/MathKeyboardExtensions.cs @@ -1,5 +1,6 @@ using SkiaSharp; using SkiaSharp.Views.Forms; + namespace CSharpMath.Forms { using Rendering.FrontEnd; using SkiaSharp; diff --git a/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidColor.png b/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidColor.png index 8aad27d7..b301b28e 100644 Binary files a/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidColor.png and b/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidColor.png differ diff --git a/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidCommand.png b/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidCommand.png index 36159de6..8d4c7897 100644 Binary files a/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidCommand.png and b/CSharpMath.Rendering.Tests/MathDisplay/ErrorInvalidCommand.png differ diff --git a/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidColor.png b/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidColor.png index 8aad27d7..b301b28e 100644 Binary files a/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidColor.png and b/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidColor.png differ diff --git a/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidCommand.png b/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidCommand.png index 36159de6..8d4c7897 100644 Binary files a/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidCommand.png and b/CSharpMath.Rendering.Tests/MathInline/ErrorInvalidCommand.png differ diff --git a/CSharpMath.Rendering.Tests/TestMeasure.cs b/CSharpMath.Rendering.Tests/TestMeasure.cs index d20b63df..fc399fda 100644 --- a/CSharpMath.Rendering.Tests/TestMeasure.cs +++ b/CSharpMath.Rendering.Tests/TestMeasure.cs @@ -13,11 +13,11 @@ class D : Display.IDisplay { public PointF Position { get => PointF.Empty; set => throw new NotImplementedException(); } public Atom.Range Range => throw new NotImplementedException(); - public Structures.Color? TextColor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public Structures.Color? BackColor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public Color? TextColor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public Color? BackColor { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public bool HasScript { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public void Draw(IGraphicsContext context) => throw new NotImplementedException(); - public void SetTextColorRecursive(Structures.Color? textColor) => throw new NotImplementedException(); + public void SetTextColorRecursive(Color? textColor) => throw new NotImplementedException(); } class DEditorKeyboard : Editor.MathKeyboard { public DEditorKeyboard() : base(TypesettingContext.Instance, new Fonts()) => diff --git a/CSharpMath.Rendering.Tests/TestRendering.cs b/CSharpMath.Rendering.Tests/TestRendering.cs index 561b0310..f3c6a1d0 100644 --- a/CSharpMath.Rendering.Tests/TestRendering.cs +++ b/CSharpMath.Rendering.Tests/TestRendering.cs @@ -102,12 +102,12 @@ public void TextRightInfiniteWidth(string file, string latex) => Run(file, latex, new TTextPainter(), TextAlignment.TopRight, textPainterCanvasWidth: float.PositiveInfinity); protected void Run( string inFile, string latex, Painter painter, TextAlignment alignment = TextAlignment.TopLeft, - float textPainterCanvasWidth = TextPainter.DefaultCanvasWidth, [CallerMemberName]string folder = "") where TContent : class { + float textPainterCanvasWidth = TextPainter.DefaultCanvasWidth, [CallerMemberName] string folder = "") where TContent : class { folder = TestRenderingFixture.GetFolder(folder); var frontEnd = FrontEnd.ToLowerInvariant(); // Prevent black background behind black rendered output in File Explorer preview - painter.HighlightColor = painter.UnwrapColor(new Structures.Color(0xF0, 0xF0, 0xF0)); + painter.HighlightColor = painter.UnwrapColor(System.Drawing.Color.FromArgb(0xF0, 0xF0, 0xF0)); painter.LaTeX = latex; var actualFile = new FileInfo(System.IO.Path.Combine(folder, inFile + "." + frontEnd + ".png")); @@ -135,9 +135,9 @@ protected void Run( new TheoryData { { "Baseline", new TPainter() }, { "Stroke", new TPainter { PaintStyle = PaintStyle.Stroke } }, -#warning For some reason the Avalonia front end behaves correctly for TextPainter Magnification test but not the SkiaSharp front end?? + // TODO: For some reason the Avalonia front end behaves correctly for TextPainter Magnification test but not the SkiaSharp front end?? { "Magnification", new TPainter { Magnification = 2 } }, -#warning For some reason SkiaSharp produces an erroneous image only on Ubuntu?? + // TODO: For some reason SkiaSharp produces an erroneous image only on Ubuntu?? //{ "LocalTypeface", new TPainter { // LocalTypefaces = new[] { // new Typography.OpenFont.OpenFontReader().Read( @@ -149,18 +149,18 @@ protected void Run( { "ScriptLineStyle", new TPainter { LineStyle = Atom.LineStyle.Script } }, { "ScriptScriptLineStyle", new TPainter { LineStyle = Atom.LineStyle.ScriptScript } }, { "GlyphBoxColor", new TPainter { GlyphBoxColor = ( - new TPainter().UnwrapColor(Structures.Color.PredefinedColors["green"]), - new TPainter().UnwrapColor(Structures.Color.PredefinedColors["blue"]) + new TPainter().UnwrapColor(Atom.LaTeXSettings.PredefinedColors["green"]), + new TPainter().UnwrapColor(Atom.LaTeXSettings.PredefinedColors["blue"]) ) } }, { "TextColor", new TPainter { TextColor = - new TPainter().UnwrapColor(Structures.Color.PredefinedColors["orange"]) } }, + new TPainter().UnwrapColor(Atom.LaTeXSettings.PredefinedColors["orange"]) } }, }; public static TheoryData MathPainterSettingsData => PainterSettingsData(); public static TheoryData TextPainterSettingsData => PainterSettingsData(); [SkippableTheory] [MemberData(nameof(MathPainterSettingsData))] public virtual void MathPainterSettings(string file, TMathPainter painter) => - Run(file, @"\sqrt[3]\frac\color{#F00}a\mathbb C", painter); + Run(file, @"\sqrt[3]\frac\color{#FF0000}a\mathbb C", painter); [SkippableTheory] [MemberData(nameof(TextPainterSettingsData))] public void TextPainterSettings(string file, TTextPainter painter) => diff --git a/CSharpMath.Rendering.Tests/TestRenderingMathData.cs b/CSharpMath.Rendering.Tests/TestRenderingMathData.cs index 54feeb7c..bfc3d365 100644 --- a/CSharpMath.Rendering.Tests/TestRenderingMathData.cs +++ b/CSharpMath.Rendering.Tests/TestRenderingMathData.cs @@ -3,11 +3,11 @@ namespace CSharpMath.Rendering.Tests { public sealed class TestRenderingMathData : TestRenderingSharedData { public const string AccentOver = @"\acute{x}"; -#warning Fix following line's output + //TODO: Fix following line's output public const string AccentOverF = @"\hat{f}"; public const string AccentOverMultiple = @"\widehat{ABcd}"; public const string AccentUnder = @"\threeunderdot{x}"; -#warning Fix following line's output + //TODO: Fix following line's output public const string AccentUnderThin = @"\threeunderdot{i}"; public const string Choose = @"{6 \choose x}"; public const string Commands = @"5\times(-2 \div 1) = -10"; @@ -80,7 +80,7 @@ public sealed class TestRenderingMathData : TestRenderingSharedData GetEnumerator() => public const string CapitalGreeks = @"ΑΒ\Gamma \Delta ΕΖΗ\Theta ΙΚ\Lambda ΜΝ\Xi Ο\Pi Ρ\Sigma Τ\Upsilon \Phi Χ\Psi \Omega "; public const string Cyrillic = @"А а\ Б б\ В в\ Г г\ Д д\ Е е\ Ё ё\ Ж ж\\ З з\ И и\ Й й\ К к\ Л л\ М м\ Н н\ О о\ П п" + @"\\ Р р\ С с\ Т т\ У у\ Ф ф\ Х х\ Ц ц\ Ч ч\\ Ш ш\ Щ щ\ Ъ ъ\ Ы ы\ Ь ь\ Э э\ Ю ю\ Я я"; - public const string Color = @"\color{#008}a\color{#00F}b\color{#080}c\color{#088}d\color{#08F}e\color{#0F0}f\color{#0F8}g\color{#0FF}h\color{#800}i\color{#808}j\color{#80F}k\color{#880}l\color{#888}m\color{#88F}n\color{#8F0}o\color{#8F8}p\color{#8FF}q\color{#F00}r\color{#F08}s\color{#F0F}t\color{#F80}u\color{#F88}v\color{#F8F}w\color{#FF0}x\color{#FF8}y\color{#FFF}z"; - public const string ErrorInvalidCommand = @"\color{#008}a\color{#00F}b\color{#080}c\color{#088}d\color{#08F}e\color{#0F0}f\color{#0F8}g\color{#0FF}h\color{#800}i\color{#808}j\color{#80F}k\color{#880}l\color{#888}m\color{#88F}n\color{#8F0}o\color{#8F8}p\color{#8FF}q\color{#F00}r\color{#F08}s\color{#F0F}t\color{#F80}u\color{#F88}v\color{#F8F}w\color{#FF0}x\color{#FF8}y\color{#FFF}\notacommand"; - public const string ErrorInvalidColor = @"\color{#008}a\color{#00F}b\color{#080}c\color{#088}d\color{#08F}e\color{#0F0}f\color{0F8}g\color{#0FF}h\color{#800}i\color{#808}j\color{#80F}k\color{#880}l\color{#888}m\color{#88F}n\color{#8F0}o\color{#8F8}p\color{#8FF}q\color{#F00}r\color{#F08}s\color{#F0F}t\color{#F80}u\color{#F88}v\color{#F8F}w\color{#FF0}x\color{#FF8}y\color{#FFF}z"; + public const string Color = @"\color{#000088}a\color{#0000FF}b\color{#008800}c\color{#008888}d\color{#0088FF}e\color{#00FF00}f\color{#00FF88}g\color{#00FFFF}h\color{#880000}i\color{#880088}j\color{#8800FF}k\color{#888800}l\color{#888888}m\color{#8888FF}n\color{#88FF00}o\color{#88FF88}p\color{#88FFFF}q\color{#FF0000}r\color{#FF0088}s\color{#FF00FF}t\color{#FF8800}u\color{#FF8888}v\color{#FF88FF}w\color{#FFFF00}x\color{#FFFF88}y\color{#FFFFFF}z"; + public const string ErrorInvalidCommand = @"\color{#000088}a\color{#0000FF}b\color{#008800}c\color{#008888}d\color{#0088FF}e\color{#00FF00}f\color{#00FF88}g\color{#00FFFF}h\color{#880000}i\color{#880088}j\color{#8800FF}k\color{#888800}l\color{#888888}m\color{#8888FF}n\color{#88FF00}o\color{#88FF88}p\color{#88FFFF}q\color{#FF0000}r\color{#FF0088}s\color{#FF00FF}t\color{#FF8800}u\color{#FF8888}v\color{#FF88FF}w\color{#FFFF00}x\color{#FFFF88}y\color{#FFFFFF}\notacommand"; + public const string ErrorInvalidColor = @"\color{#000088}a\color{#0000FF}b\color{#008800}c\color{#008888}d\color{#0088FF}e\color{#00FF00}f\color{0F8}g\color{#00FFFF}h\color{#880000}i\color{#880088}j\color{#8800FF}k\color{#888800}l\color{#888888}m\color{#8888FF}n\color{#88FF00}o\color{#88FF88}p\color{#88FFFF}q\color{#FF0000}r\color{#FF0088}s\color{#FF00FF}t\color{#FF8800}u\color{#FF8888}v\color{#FF88FF}w\color{#FFFF00}x\color{#FFFF88}y\color{#FFFFFF}z"; public const string ErrorMissingBrace = @"}z"; } } diff --git a/CSharpMath.Rendering.Tests/TestRenderingTextData.cs b/CSharpMath.Rendering.Tests/TestRenderingTextData.cs index 02a5d66b..3e86950b 100644 --- a/CSharpMath.Rendering.Tests/TestRenderingTextData.cs +++ b/CSharpMath.Rendering.Tests/TestRenderingTextData.cs @@ -16,7 +16,7 @@ public sealed class TestRenderingTextData : TestRenderingSharedData { - new TextAtom.Color(new TextAtom.Text(colored), Structures.Color.PredefinedColors["red"]) + new TextAtom.Colored(new TextAtom.Text(colored), Atom.LaTeXSettings.PredefinedColors["red"]) }; if (after != null) list.Add(new TextAtom.Text(after)); Assert.Equal(list.Count == 1 ? list[0] : new TextAtom.List(list), atom); @@ -155,29 +155,29 @@ public void Space(string command, float length, bool isMu, string? outCommand = // Sync with CSharpMath.CoreTests LaTeXParserTests [Theory] - [InlineData("0xFFF", "white", 0xFF, 0xFF, 0xFF)] - [InlineData("#ff0", "yellow", 0xFF, 0xFF, 0x00)] - [InlineData("0xf00f", "blue", 0x00, 0x00, 0xFF)] - [InlineData("#F0F0", "lime", 0x00, 0xFF, 0x00)] - [InlineData("0x008000", "green", 0x00, 0x80, 0x00)] + [InlineData("#FFFFFF", "white", 0xFF, 0xFF, 0xFF)] + [InlineData("#ffff00", "yellow", 0xFF, 0xFF, 0x00)] + [InlineData("#ff0000ff", "blue", 0x00, 0x00, 0xFF)] + [InlineData("#FF00FF00", "lime", 0x00, 0xFF, 0x00)] + [InlineData("#008000", "green", 0x00, 0x80, 0x00)] [InlineData("#d3D3d3", "lightgray", 0xD3, 0xD3, 0xD3)] - [InlineData("0xFf000000", "black", 0x00, 0x00, 0x00)] + [InlineData("#Ff000000", "black", 0x00, 0x00, 0x00)] [InlineData("#fFa9A9a9", "gray", 0xA9, 0xA9, 0xA9)] [InlineData("cyan", "cyan", 0x00, 0xFF, 0xFF)] [InlineData("BROWN", "brown", 0x96, 0x4B, 0x00)] [InlineData("oLIve", "olive", 0x80, 0x80, 0x00)] - [InlineData("0x12345678", "#12345678", 0x34, 0x56, 0x78, 0x12)] + [InlineData("#12345678", "#12345678", 0x34, 0x56, 0x78, 0x12)] [InlineData("#fedcba98", "#FEDCBA98", 0xDC, 0xBA, 0x98, 0xFE)] public void Color(string inColor, string outColor, byte r, byte g, byte b, byte a = 0xFF) { var atom = Parse($@"\color{{{inColor}}}ab"); CheckAtom(l => Assert.Collection(l.Content, - CheckAtom(color => { - Assert.Equal(r, color.Colour.R); - Assert.Equal(g, color.Colour.G); - Assert.Equal(b, color.Colour.B); - Assert.Equal(a, color.Colour.A); - CheckAtom(t => Assert.Equal("a", t.Content))(color.Content); + CheckAtom(colored => { + Assert.Equal(r, colored.Colour.R); + Assert.Equal(g, colored.Colour.G); + Assert.Equal(b, colored.Colour.B); + Assert.Equal(a, colored.Colour.A); + CheckAtom(t => Assert.Equal("a", t.Content))(colored.Content); }), CheckAtom(t => Assert.Equal("b", t.Content)) ) diff --git a/CSharpMath.Rendering/BackEnd/GraphicsContext.cs b/CSharpMath.Rendering/BackEnd/GraphicsContext.cs index 330f2e0d..429ac235 100644 --- a/CSharpMath.Rendering/BackEnd/GraphicsContext.cs +++ b/CSharpMath.Rendering/BackEnd/GraphicsContext.cs @@ -5,7 +5,6 @@ using CSharpMath.Rendering.FrontEnd; using CSharpMath.Structures; using Typography.OpenFont; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Rendering.BackEnd { public class GraphicsContext : IGraphicsContext { @@ -18,7 +17,7 @@ public GraphicsContext(ICanvas canvas, (Color glyph, Color textRun)? glyphBoxCol } public (Color glyph, Color textRun)? GlyphBoxColor { get; set; } public ICanvas Canvas { get; set; } -#warning Remove (Must have a Mac to test) + // TODO: Remove (Must have a Mac to test) void IGraphicsContext.SetTextPosition(PointF position) => Translate(position); public void DrawGlyphsAtPoints (IReadOnlyList glyphs, Fonts font, IEnumerable points, Color? color) { diff --git a/CSharpMath.Rendering/FrontEnd/ICanvas.cs b/CSharpMath.Rendering/FrontEnd/ICanvas.cs index 90d46a5e..22e7a97b 100644 --- a/CSharpMath.Rendering/FrontEnd/ICanvas.cs +++ b/CSharpMath.Rendering/FrontEnd/ICanvas.cs @@ -1,5 +1,5 @@ using System; -using CSharpMath.Structures; +using System.Drawing; namespace CSharpMath.Rendering.FrontEnd { public interface ICanvas { diff --git a/CSharpMath.Rendering/FrontEnd/MathKeyboard.cs b/CSharpMath.Rendering/FrontEnd/MathKeyboard.cs index e2b1e34d..909bcd4f 100644 --- a/CSharpMath.Rendering/FrontEnd/MathKeyboard.cs +++ b/CSharpMath.Rendering/FrontEnd/MathKeyboard.cs @@ -13,7 +13,7 @@ public MathKeyboard(float fontSize = PainterConstants.DefaultFontSize, double bl // Rendering: Convert to public override RectangleF Measure => Display != null ? new RectangleF(0, -Display.Ascent, Display.Width, Display.Ascent + Display.Descent) : RectangleF.Empty; - public void DrawCaret(ICanvas canvas, Structures.Color color, CaretShape shape) { + public void DrawCaret(ICanvas canvas, Color color, CaretShape shape) { if (CaretState != MathKeyboardCaretState.Shown || Display is null) return; var cursorPosition = Display.PointForIndex(TypesettingContext.Instance, InsertionIndex) ?? Display.Position; diff --git a/CSharpMath.Rendering/FrontEnd/Painter.cs b/CSharpMath.Rendering/FrontEnd/Painter.cs index d5b59083..551b2725 100644 --- a/CSharpMath.Rendering/FrontEnd/Painter.cs +++ b/CSharpMath.Rendering/FrontEnd/Painter.cs @@ -3,7 +3,6 @@ using CSharpMath.Display; using CSharpMath.Structures; -using Color = CSharpMath.Structures.Color; using Typography.OpenFont; using System.Collections.Specialized; @@ -20,9 +19,9 @@ public abstract class Painter : ICSharpMathAPI Rendering.Text.TextLaTeXParser.NoEnhancedColors; - set => Rendering.Text.TextLaTeXParser.NoEnhancedColors = value; - } public static Rendering.BackEnd.Typefaces GlobalTypefaces => Rendering.BackEnd.Fonts.GlobalTypefaces; - public static Structures.BiDictionary PredefinedColors => - Structures.Color.PredefinedColors; - public static Structures.AliasDictionary PredefinedLaTeXBoundaryDelimiters => + public static BiDictionary PredefinedColors => + Atom.LaTeXSettings.PredefinedColors; + public static AliasDictionary PredefinedLaTeXBoundaryDelimiters => Atom.LaTeXSettings.BoundaryDelimiters; - public static Structures.AliasDictionary PredefinedLaTeXFontStyles => + public static AliasDictionary PredefinedLaTeXFontStyles => Atom.LaTeXSettings.FontStyles; - public static Structures.AliasDictionary PredefinedLaTeXCommands => + public static AliasDictionary PredefinedLaTeXCommands => Atom.LaTeXSettings.Commands; - public static Structures.BiDictionary PredefinedLaTeXTextAccents => + public static BiDictionary PredefinedLaTeXTextAccents => Rendering.Text.TextLaTeXSettings.PredefinedAccents; - public static Structures.AliasDictionary PredefinedLaTeXTextSymbols => + public static AliasDictionary PredefinedLaTeXTextSymbols => Rendering.Text.TextLaTeXSettings.PredefinedTextSymbols; - public static Dictionary PredefinedLengthUnits => - Structures.Space.PredefinedLengthUnits; + public static Dictionary PredefinedLengthUnits => + Space.PredefinedLengthUnits; } } diff --git a/CSharpMath.Rendering/Text/TextAtom.cs b/CSharpMath.Rendering/Text/TextAtom.cs index 603d6a40..98d6812c 100644 --- a/CSharpMath.Rendering/Text/TextAtom.cs +++ b/CSharpMath.Rendering/Text/TextAtom.cs @@ -80,12 +80,12 @@ public sealed class Size : TextAtom { public override bool Equals(TextAtom atom) => atom is Size s && s.PointSize == PointSize && s.Content.Equals(Content); public override int GetHashCode() => (PointSize, Content).GetHashCode(); } - public sealed class Color : TextAtom { - public Color(TextAtom content, Structures.Color colour) => (Content, Colour) = (content, colour); + public sealed class Colored : TextAtom { + public Colored(TextAtom content, System.Drawing.Color colour) => (Content, Colour) = (content, colour); public TextAtom Content { get; } - public Structures.Color Colour { get; } + public System.Drawing.Color Colour { get; } public override int? SingleChar(FontStyle style) => Content.SingleChar(style); - public override bool Equals(TextAtom atom) => atom is Color c && c.Colour == Colour && c.Content.Equals(Content); + public override bool Equals(TextAtom atom) => atom is Colored c && c.Colour == Colour && c.Content.Equals(Content); public override int GetHashCode() => (Colour, Content).GetHashCode(); } public sealed class List : TextAtom { diff --git a/CSharpMath.Rendering/Text/TextAtomListBuilder.cs b/CSharpMath.Rendering/Text/TextAtomListBuilder.cs index 9b8f6143..84b5d49a 100644 --- a/CSharpMath.Rendering/Text/TextAtomListBuilder.cs +++ b/CSharpMath.Rendering/Text/TextAtomListBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System.Drawing; using System.Collections; using System.Collections.Generic; @@ -24,7 +24,7 @@ public void Text(string text) { public void Space(Space space) => Add(new TextAtom.Space(space)); public void Style(TextAtom atom, Atom.FontStyle style) => Add(new TextAtom.Style(atom, style)); public void Size(TextAtom atom, float fontSize) => Add(new TextAtom.Size(atom, fontSize)); - public void Color(TextAtom atom, Color color) => Add(new TextAtom.Color(atom, color)); + public void Color(TextAtom atom, Color color) => Add(new TextAtom.Colored(atom, color)); public Result Math(string mathLaTeX, bool displayStyle, int startAt, ref int endAt) { var builder = new Atom.LaTeXParser(mathLaTeX); var mathList = builder.Build(); diff --git a/CSharpMath.Rendering/Text/TextLaTeXParser.cs b/CSharpMath.Rendering/Text/TextLaTeXParser.cs index cf0a9294..d805de7b 100644 --- a/CSharpMath.Rendering/Text/TextLaTeXParser.cs +++ b/CSharpMath.Rendering/Text/TextLaTeXParser.cs @@ -6,6 +6,7 @@ namespace CSharpMath.Rendering.Text { using Atom; using CSharpMath.Structures; + using System.Drawing; using static CSharpMath.Structures.Result; public static class TextLaTeXParser { /* //Paste this into the C# Interactive, fill yourself @@ -37,7 +38,6 @@ string BreakText(string text, string seperator = "|") } BreakText(@"Here are some text $1 + 12 \frac23 \sqrt4$ $$Display$$ text") */ - public static bool NoEnhancedColors { get; set; } public static Result TextAtomFromLaTeX(string latexSource) { if (string.IsNullOrEmpty(latexSource)) return new TextAtom.List(Array.Empty()); @@ -146,7 +146,7 @@ SpanResult ReadArgumentString(ReadOnlySpan latexInput, ref ReadOnlyS } Result ReadColor(ReadOnlySpan latexInput, ref ReadOnlySpan section) => ReadArgumentString(latexInput, ref section).Bind(color => - Color.Create(color, !NoEnhancedColors) is Color value ? + LaTeXSettings.ParseColor(color.ToString()) is Color value ? Ok(value) : Err("Invalid color: " + color.ToString()) ); @@ -381,7 +381,7 @@ Result ReadColor(ReadOnlySpan latexInput, ref ReadOnlySpan se } //case "red", "yellow", ... case var shortColor when - !NoEnhancedColors && Color.PredefinedColors.TryGetByFirst(shortColor, out var color): { + LaTeXSettings.PredefinedColors.TryGetByFirst(shortColor, out var color): { int tmp_commandLength = shortColor.Length; if (ReadArgumentAtom(latex).Bind( coloredContent => atoms.Color(coloredContent, color) @@ -486,8 +486,9 @@ public static StringBuilder TextAtomToLaTeX(TextAtom atom, StringBuilder? b = nu case TextAtom.Size z: b.Append(@"\fontsize{").Append(z.PointSize).Append("}{"); return TextAtomToLaTeX(z.Content, b).Append('}'); - case TextAtom.Color c: - b.Append(@"\color{").Append(c.Colour).Append("}{"); + case TextAtom.Colored c: + b.Append(@"\color{"); + LaTeXSettings.ColorToString(c.Colour, b).Append("}{"); return TextAtomToLaTeX(c.Content, b).Append('}'); case TextAtom.List l: foreach (var a in l.Content) diff --git a/CSharpMath.Rendering/Text/TextTypesetter.cs b/CSharpMath.Rendering/Text/TextTypesetter.cs index b1fd5af2..9df5097d 100644 --- a/CSharpMath.Rendering/Text/TextTypesetter.cs +++ b/CSharpMath.Rendering/Text/TextTypesetter.cs @@ -9,9 +9,10 @@ namespace CSharpMath.Rendering.Text { using FrontEnd; using Display = Display.Displays.ListDisplay; using CSharpMath.Structures; + using System.Drawing; public static class TextTypesetter { public static (Display relative, Display absolute) Layout(TextAtom input, Fonts inputFont, float canvasWidth) { -#warning Multiply these constants by resolution + // TODO: Multiply these constants by resolution const float abovedisplayskip = 12, abovedisplayshortskip = 0, belowdisplayskip = 12, belowdisplayshortskip = 7; if (input == null) return @@ -59,7 +60,7 @@ void AddDisplaysWithLineBreaks( (sz.Content, new Fonts(fonts, sz.PointSize), line, displayList, displayMathList, style, color); break; - case TextAtom.Color c: + case TextAtom.Colored c: AddDisplaysWithLineBreaks (c.Content, fonts, line, displayList, displayMathList, style, c.Colour); break; diff --git a/CSharpMath.SkiaSharp/Extensions.cs b/CSharpMath.SkiaSharp/Extensions.cs index de7a2900..4a07f426 100644 --- a/CSharpMath.SkiaSharp/Extensions.cs +++ b/CSharpMath.SkiaSharp/Extensions.cs @@ -1,13 +1,13 @@ -using CSharpMath.Structures; using CSharpMath.Rendering.FrontEnd; using SkiaSharp; +using System.Drawing; namespace CSharpMath.SkiaSharp { public static class Extensions { public static SKColor ToNative(this Color color) => new SKColor(color.R, color.G, color.B, color.A); public static Color FromNative(this SKColor color) => - new Color(color.Red, color.Green, color.Blue, color.Alpha); + Color.FromArgb(color.Alpha, color.Red, color.Green, color.Blue); public static System.IO.Stream? DrawAsStream (this Painter painter, float textPainterCanvasWidth = TextPainter.DefaultCanvasWidth, diff --git a/CSharpMath.SkiaSharp/MathPainter.cs b/CSharpMath.SkiaSharp/MathPainter.cs index 18a8310e..454edd16 100644 --- a/CSharpMath.SkiaSharp/MathPainter.cs +++ b/CSharpMath.SkiaSharp/MathPainter.cs @@ -3,7 +3,6 @@ using CSharpMath.Rendering.BackEnd; using CSharpMath.Rendering.FrontEnd; using SkiaSharp; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.SkiaSharp { public class MathPainter : MathPainter { diff --git a/CSharpMath.SkiaSharp/SkiaCanvas.cs b/CSharpMath.SkiaSharp/SkiaCanvas.cs index 86155083..bb858345 100644 --- a/CSharpMath.SkiaSharp/SkiaCanvas.cs +++ b/CSharpMath.SkiaSharp/SkiaCanvas.cs @@ -1,6 +1,7 @@ using CSharpMath.Rendering.FrontEnd; -using CSharpMath.Structures; +using System.Drawing; using SkiaSharp; + namespace CSharpMath.SkiaSharp { public sealed class SkiaCanvas : ICanvas { public SkiaCanvas(SKCanvas canvas, bool antiAlias) { @@ -16,7 +17,7 @@ public SkiaCanvas(SKCanvas canvas, bool antiAlias) { private readonly SKPaint _paint; private SKPaint StyledPaint(PaintStyle style, float? strokeWidth = null) { - //In SkiaSharp, line will still be visible even if width is 0 + // In SkiaSharp, line will still be visible even if width is 0 _paint.Color = strokeWidth == 0 ? SKColors.Transparent @@ -26,7 +27,7 @@ private SKPaint StyledPaint(PaintStyle style, float? strokeWidth = null) { return _paint; } internal SKPaint Paint => StyledPaint(CurrentStyle); - //Canvas methods + // Canvas methods public void StrokeRect(float left, float top, float width, float height) => Canvas.DrawRect( SKRect.Create(left, top, width, height), StyledPaint(PaintStyle.Stroke)); diff --git a/CSharpMath.SkiaSharp/SkiaPath.cs b/CSharpMath.SkiaSharp/SkiaPath.cs index 0cee9243..0d8adc78 100644 --- a/CSharpMath.SkiaSharp/SkiaPath.cs +++ b/CSharpMath.SkiaSharp/SkiaPath.cs @@ -1,7 +1,7 @@ using SKPath = SkiaSharp.SKPath; +using System.Drawing; namespace CSharpMath.SkiaSharp { - using Structures; public sealed class SkiaPath : Rendering.FrontEnd.Path { public SkiaPath(SkiaCanvas owner) => _owner = owner; public override Color? Foreground { get; set; } diff --git a/CSharpMath.SkiaSharp/TextPainter.cs b/CSharpMath.SkiaSharp/TextPainter.cs index 36a3dea1..b48d83ea 100644 --- a/CSharpMath.SkiaSharp/TextPainter.cs +++ b/CSharpMath.SkiaSharp/TextPainter.cs @@ -1,6 +1,6 @@ using CSharpMath.Rendering.FrontEnd; using SkiaSharp; -using Color = CSharpMath.Structures.Color; +using System.Drawing; namespace CSharpMath.SkiaSharp { public class TextPainter : TextPainter { diff --git a/CSharpMath.sln b/CSharpMath.sln index db66c9e4..e16a376d 100644 --- a/CSharpMath.sln +++ b/CSharpMath.sln @@ -69,7 +69,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpMath.Editor.Tests", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpMath.Editor.Tests.Visualizer", "CSharpMath.Editor.Tests.Visualizer\CSharpMath.Editor.Tests.Visualizer.csproj", "{C60126CE-A71D-4D11-A4A8-A45B67312E98}" EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "CSharpMath.Editor.Tests.FSharp", "CSharpMath.Editor.Tests.FSharp\CSharpMath.Editor.Tests.FSharp.fsproj", "{65492AC6-8B98-42FF-AAA1-1DBDC050A25F}" +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CSharpMath.Editor.Tests.FSharp", "CSharpMath.Editor.Tests.FSharp\CSharpMath.Editor.Tests.FSharp.fsproj", "{65492AC6-8B98-42FF-AAA1-1DBDC050A25F}" EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "PixelFarm.Typography (Excerpt)", "PixelFarm.Typography (Excerpt)\PixelFarm.Typography (Excerpt).shproj", "{3ECA00B3-0925-4418-B6F2-AC49AA3520BB}" EndProject @@ -99,8 +99,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AngouriMath", "AngouriMath\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpMath.Evaluation.Tests", "CSharpMath.Evaluation.Tests\CSharpMath.Evaluation.Tests.csproj", "{06241755-626A-4992-9CAE-C5A5745CB83C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpMath.Forms.Example.Ooui", "CSharpMath.Forms.Example\CSharpMath.Forms.Example.Ooui\CSharpMath.Forms.Example.Ooui.csproj", "{338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "AngouriMath\Tests\UnitTests\UnitTests.csproj", "{1EE81B65-9B82-43B2-8C2C-4FC691F2D450}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpMath.Ios.Tests", "CSharpMath.Ios.Tests\CSharpMath.Ios.Tests.csproj", "{30C91103-12E5-47AE-85FE-41B0218A8997}" @@ -1468,54 +1466,6 @@ Global {06241755-626A-4992-9CAE-C5A5745CB83C}.Release|x64.Build.0 = Release|Any CPU {06241755-626A-4992-9CAE-C5A5745CB83C}.Release|x86.ActiveCfg = Release|Any CPU {06241755-626A-4992-9CAE-C5A5745CB83C}.Release|x86.Build.0 = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|x64.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Ad-Hoc|x86.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|Any CPU.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|ARM.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|ARM.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|iPhone.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|iPhone.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|x64.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|x64.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|x86.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.AppStore|x86.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|ARM.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|ARM.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|iPhone.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|x64.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|x64.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|x86.ActiveCfg = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Debug|x86.Build.0 = Debug|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|Any CPU.Build.0 = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|ARM.ActiveCfg = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|ARM.Build.0 = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|iPhone.ActiveCfg = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|iPhone.Build.0 = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|x64.ActiveCfg = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|x64.Build.0 = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|x86.ActiveCfg = Release|Any CPU - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1}.Release|x86.Build.0 = Release|Any CPU {1EE81B65-9B82-43B2-8C2C-4FC691F2D450}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU {1EE81B65-9B82-43B2-8C2C-4FC691F2D450}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU {1EE81B65-9B82-43B2-8C2C-4FC691F2D450}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU @@ -1652,7 +1602,6 @@ Global {2FD3FBBD-FD06-4E49-BA91-4FC5ADC33BA7} = {125C1FE9-F684-4E87-A9EF-969FD1E2D726} {F3FE15B5-1995-4444-85FF-6CAC564A9113} = {74FBDC58-E93A-4DCE-B83F-AA936EE57B31} {06241755-626A-4992-9CAE-C5A5745CB83C} = {125C1FE9-F684-4E87-A9EF-969FD1E2D726} - {338E9ACF-EB26-4D5B-9ADB-B0C4588D71E1} = {C365BD30-D4E7-444A-A66D-25AAB9C67038} {1EE81B65-9B82-43B2-8C2C-4FC691F2D450} = {74FBDC58-E93A-4DCE-B83F-AA936EE57B31} {30C91103-12E5-47AE-85FE-41B0218A8997} = {1D406122-CB0D-4366-8EBC-2207EA64B7F1} EndGlobalSection diff --git a/CSharpMath/Atom/Atoms/ColorBox.cs b/CSharpMath/Atom/Atoms/ColorBox.cs index bc4ac3a0..0b36cebe 100644 --- a/CSharpMath/Atom/Atoms/ColorBox.cs +++ b/CSharpMath/Atom/Atoms/ColorBox.cs @@ -1,21 +1,22 @@ using System.Text; +using System.Drawing; namespace CSharpMath.Atom.Atoms { public sealed class ColorBox : MathAtom, IMathListContainer { - public Structures.Color Colour { get; set; } + public Color Color { get; set; } public MathList InnerList { get; } System.Collections.Generic.IEnumerable IMathListContainer.InnerLists => new[] { InnerList }; - public ColorBox(Structures.Color color, MathList innerList) : base(string.Empty) => - (Colour, InnerList) = (color, innerList); + public ColorBox(Color color, MathList innerList) : base(string.Empty) => + (Color, InnerList) = (color, innerList); public override string DebugString => new StringBuilder(@"\colorbox") - .AppendInBracesOrLiteralNull(Colour.ToString()) + .AppendInBracesOrLiteralNull(Color.ToString()) .AppendInBracesOrLiteralNull(InnerList.DebugString).ToString(); public override bool ScriptsAllowed => false; public new ColorBox Clone(bool finalize) => (ColorBox)base.Clone(finalize); protected override MathAtom CloneInside(bool finalize) => - new ColorBox(Colour, InnerList.Clone(finalize)); - public override int GetHashCode() => (base.GetHashCode(), Colour, InnerList).GetHashCode(); + new ColorBox(Color, InnerList.Clone(finalize)); + public override int GetHashCode() => (base.GetHashCode(), Color, InnerList).GetHashCode(); } } \ No newline at end of file diff --git a/CSharpMath/Atom/Atoms/Color.cs b/CSharpMath/Atom/Atoms/Colored.cs similarity index 52% rename from CSharpMath/Atom/Atoms/Color.cs rename to CSharpMath/Atom/Atoms/Colored.cs index 5e24608c..c7e19068 100644 --- a/CSharpMath/Atom/Atoms/Color.cs +++ b/CSharpMath/Atom/Atoms/Colored.cs @@ -1,21 +1,22 @@ -using System.Text; - -namespace CSharpMath.Atom.Atoms { - public sealed class Color : MathAtom, IMathListContainer { - public Structures.Color Colour { get; set; } - public MathList InnerList { get; } - System.Collections.Generic.IEnumerable IMathListContainer.InnerLists => - new[] { InnerList }; - public Color(Structures.Color color, MathList innerList) : base(string.Empty) => - (Colour, InnerList) = (color, innerList); - public override string DebugString => - new StringBuilder(@"\color") - .AppendInBracesOrLiteralNull(Colour.ToString()) - .AppendInBracesOrLiteralNull(InnerList.DebugString).ToString(); - public override bool ScriptsAllowed => false; - public new Color Clone(bool finalize) => (Color)base.Clone(finalize); - protected override MathAtom CloneInside(bool finalize) => - new Color(Colour, InnerList.Clone(finalize)); - public override int GetHashCode() => (base.GetHashCode(), Colour, InnerList).GetHashCode(); - } +using System.Text; +using System.Drawing; + +namespace CSharpMath.Atom.Atoms { + public sealed class Colored : MathAtom, IMathListContainer { + public Color Color { get; set; } + public MathList InnerList { get; } + System.Collections.Generic.IEnumerable IMathListContainer.InnerLists => + new[] { InnerList }; + public Colored(Color color, MathList innerList) : base(string.Empty) => + (Color, InnerList) = (color, innerList); + public override string DebugString => + new StringBuilder(@"\color") + .AppendInBracesOrLiteralNull(Color.ToString()) + .AppendInBracesOrLiteralNull(InnerList.DebugString).ToString(); + public override bool ScriptsAllowed => false; + public new Colored Clone(bool finalize) => (Colored)base.Clone(finalize); + protected override MathAtom CloneInside(bool finalize) => + new Colored(Color, InnerList.Clone(finalize)); + public override int GetHashCode() => (base.GetHashCode(), Color, InnerList).GetHashCode(); + } } \ No newline at end of file diff --git a/CSharpMath/Atom/Atoms/Fraction.cs b/CSharpMath/Atom/Atoms/Fraction.cs index fc08509b..629966d7 100644 --- a/CSharpMath/Atom/Atoms/Fraction.cs +++ b/CSharpMath/Atom/Atoms/Fraction.cs @@ -26,8 +26,7 @@ protected override MathAtom CloneInside(bool finalize) => .AppendInBracesOrEmptyBraces(Numerator?.DebugString) .AppendInBracesOrEmptyBraces(Denominator?.DebugString) .AppendDebugStringOfScripts(this).ToString(); - public override bool Equals(object obj) => - obj is Fraction f ? EqualsFraction(f) : false; + public override bool Equals(object obj) => obj is Fraction f && EqualsFraction(f); public bool EqualsFraction(Fraction other) => EqualsAtom(other) && Numerator.NullCheckingStructuralEquality(other.Numerator) diff --git a/CSharpMath/Atom/LaTeXParser.cs b/CSharpMath/Atom/LaTeXParser.cs index f34a06ec..e97aebc6 100644 --- a/CSharpMath/Atom/LaTeXParser.cs +++ b/CSharpMath/Atom/LaTeXParser.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Drawing; namespace CSharpMath.Atom { using Atoms; + using CSharpMath.Structures; using InvalidCodePathException = Structures.InvalidCodePathException; public class LaTeXParser { interface IEnvironment { } @@ -95,7 +97,7 @@ private void UnlookCharacter() => return r; } continue; -#warning TODO Example + // TODO: Example //https://phabricator.wikimedia.org/T99369 //https://phab.wmfusercontent.org/file/data/xsimlcnvo42siudvwuzk/PHID-FILE-bdcqexocj5b57tj2oezn/math_rendering.png //dt, \text{d}t, \partial t, \nabla\psi \\ \underline\overline{dy/dx, \text{d}y/\text{d}x, \frac{dy}{dx}, \frac{\text{d}y}{\text{d}x}, \frac{\partial^2}{\partial x_1\partial x_2}y} \\ \prime, @@ -198,7 +200,7 @@ private string ReadString() { return builder.ToString(); } - private Structures.Color? ReadColor() { + private Color? ReadColor() { if (!ExpectCharacter('{')) { SetError("Missing {"); return null; @@ -216,16 +218,17 @@ private string ReadString() { } } var str = builder.ToString(); - if (!(Structures.Color.Create(str.AsSpan()) is { } color)) { + if (LaTeXSettings.ParseColor(str) is Color color) { + SkipSpaces(); + if (!ExpectCharacter('}')) { + SetError("Missing }"); + return null; + } + return color; + } else { SetError("Invalid color: " + str); return null; } - SkipSpaces(); - if (!ExpectCharacter('}')) { - SetError("Missing }"); - return null; - } - return color; } private void SkipSpaces() { @@ -404,7 +407,7 @@ private string ReadCommand() { case "color": return (ReadColor()) switch { - { } color when BuildInternal(true) is { } ml => new Color(color, ml), + Color color when BuildInternal(true) is MathList ml => new Colored(color, ml), _ => null, }; case "colorbox": @@ -423,7 +426,7 @@ private string ReadCommand() { if (error != null) { SetError(error); return null; - } else return new Space(space); + } else return new Atoms.Space(space); } SetError($@"\{command} is not allowed in math mode"); return null; @@ -434,7 +437,7 @@ private string ReadCommand() { if (error != null) { SetError(error); return null; - } else return new Space(space); + } else return new Atoms.Space(space); } SetError($@"\{command} is not allowed in text mode"); return null; @@ -684,7 +687,7 @@ private MathAtom? BuildTable table.InterRowAdditionalSpacing = 1; table.InterColumnSpacing = 18; for (int i = 0, j = 0; i < arrayAlignments.Length && j < table.NColumns; i++, j++) { -#warning vertical lines in array currently unsupported + // TODO: vertical lines in array currently unsupported while (arrayAlignments[i] == '|') i++; table.SetAlignment(arrayAlignments[i] switch { @@ -754,7 +757,7 @@ private MathAtom? BuildTable // add delimiters return new Inner( LaTeXSettings.BoundaryDelimiters["{"], - new MathList(new Space(Structures.Space.ShortSpace), table), + new MathList(new Atoms.Space(Structures.Space.ShortSpace), table), Boundary.Empty ); } @@ -992,16 +995,16 @@ static string BoundaryToLaTeX(Boundary delimiter) { break; } break; - case Color color: - builder.Append(@"\color{") - .Append(color.Colour) + case Colored colored: + builder.Append(@"\color{"); + LaTeXSettings.ColorToString(colored.Color, builder) .Append("}{"); - MathListToLaTeX(color.InnerList, builder, currentFontStyle); + MathListToLaTeX(colored.InnerList, builder, currentFontStyle); builder.Append("}"); break; case ColorBox colorBox: - builder.Append(@"\colorbox{") - .Append(colorBox.Colour) + builder.Append(@"\colorbox{"); + LaTeXSettings.ColorToString(colorBox.Color, builder) .Append("}{"); MathListToLaTeX(colorBox.InnerList, builder, currentFontStyle); builder.Append("}"); @@ -1020,7 +1023,7 @@ static string BoundaryToLaTeX(Boundary delimiter) { case var _ when LaTeXSettings.CommandForAtom(atom) is string name: builder.Append(@"\").Append(name).Append(" "); break; - case Space space: + case Atoms.Space space: var intSpace = (int)space.Length; if (space.IsMu) builder.Append(@"\mkern") diff --git a/CSharpMath/Atom/LaTeXSettings.cs b/CSharpMath/Atom/LaTeXSettings.cs index 3ab767bc..6f8425bd 100644 --- a/CSharpMath/Atom/LaTeXSettings.cs +++ b/CSharpMath/Atom/LaTeXSettings.cs @@ -1,8 +1,13 @@ using System; using System.Collections.Generic; +using System.Drawing; +using System.Globalization; namespace CSharpMath.Atom { + using System.Text; using Atoms; + using Structures; + using Space = Atoms.Space; //https://mirror.hmc.edu/ctan/macros/latex/contrib/unicode-math/unimath-symbols.pdf public static class LaTeXSettings { public static MathAtom Times => new BinaryOperator("×"); @@ -118,6 +123,61 @@ public static class LaTeXSettings { { "lrcorner", new Boundary("⌟") }, }; + + public static Color? ParseColor(string? hexOrName) { + if (hexOrName == null) return null; + if (hexOrName.StartsWith("#", StringComparison.InvariantCulture)) { + var hex = hexOrName.Substring(1); + return + (hex.Length, int.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var i)) switch + { + (8, true) => Color.FromArgb(i), + (6, true) => Color.FromArgb(unchecked((int)0xff000000) + i), + _ => null + }; + } +#pragma warning disable CA1308 // Normalize strings to uppercase + if (PredefinedColors.TryGetByFirst(hexOrName.ToLowerInvariant(), out var predefined)) + return predefined; +#pragma warning restore CA1308 // Normalize strings to uppercase + return null; + } + public static StringBuilder ColorToString(Color color, StringBuilder sb) { + if (PredefinedColors.TryGetBySecond(color, out var outString)) { + return sb.Append(outString); + } else { + sb.Append('#'); + if (color.A != 255) + sb.Append(color.A.ToStringInvariant("X2")); + return sb.Append(color.R.ToStringInvariant("X2")) + .Append(color.G.ToStringInvariant("X2")) + .Append(color.B.ToStringInvariant("X2")); + } + } + //https://en.wikibooks.org/wiki/LaTeX/Colors#Predefined_colors + public static BiDictionary PredefinedColors { get; } = + new BiDictionary { + { "black", Color.FromArgb(0, 0, 0) }, + { "blue", Color.FromArgb(0, 0, 255) }, + { "brown", Color.FromArgb(150, 75, 0) }, + { "cyan", Color.FromArgb(0, 255, 255) }, + { "darkgray", Color.FromArgb(128, 128, 128) }, + { "gray", Color.FromArgb(169, 169, 169) }, + { "green", Color.FromArgb(0, 128, 0) }, + { "lightgray", Color.FromArgb(211, 211, 211) }, + { "lime", Color.FromArgb(0, 255, 0) }, + { "magenta", Color.FromArgb(255, 0, 255) }, + { "olive", Color.FromArgb(128, 128, 0) }, + { "orange", Color.FromArgb(255, 128, 0) }, + { "pink", Color.FromArgb(255, 192, 203) }, + { "purple", Color.FromArgb(128, 0, 128) }, + { "red", Color.FromArgb(255, 0,0) }, + { "teal", Color.FromArgb(0, 128, 128) }, + { "violet", Color.FromArgb(128, 0, 255) }, + { "white", Color.FromArgb(255, 255, 255) }, + { "yellow", Color.FromArgb(255, 255, 0) } + }; + public static Structures.AliasDictionary FontStyles { get; } = new Structures.AliasDictionary { { "mathnormal", FontStyle.Default }, @@ -575,7 +635,7 @@ public static class LaTeXSettings { // Table 17: Some Other Constructions { "widehat", new Accent("\u0302") }, { "widetilde", new Accent("\u0303") }, -#warning implement \overleftarrow, \overrightarrow, \overbrace, \underbrace + // TODO: implement \overleftarrow, \overrightarrow, \overbrace, \underbrace // \overleftarrow{} // \overrightarrow{} // \overline{} diff --git a/CSharpMath/Atom/MathAtom.cs b/CSharpMath/Atom/MathAtom.cs index ff7b5f8e..9426bac5 100644 --- a/CSharpMath/Atom/MathAtom.cs +++ b/CSharpMath/Atom/MathAtom.cs @@ -87,7 +87,7 @@ public bool EqualsAtom(MathAtom otherAtom) => //FontStyle == otherAtom.FontStyle && Superscript.NullCheckingStructuralEquality(otherAtom.Superscript) && Subscript.NullCheckingStructuralEquality(otherAtom.Subscript); - public override bool Equals(object obj) => obj is MathAtom a ? EqualsAtom(a) : false; + public override bool Equals(object obj) => obj is MathAtom a && EqualsAtom(a); bool IEquatable.Equals(MathAtom otherAtom) => EqualsAtom(otherAtom); public override int GetHashCode() => (Superscript, Subscript, Nucleus).GetHashCode(); } diff --git a/CSharpMath/Atom/MathList.cs b/CSharpMath/Atom/MathList.cs index 7cfeeba2..53af9617 100644 --- a/CSharpMath/Atom/MathList.cs +++ b/CSharpMath/Atom/MathList.cs @@ -31,7 +31,7 @@ public MathList Clone(bool finalize) { prevNode?.IndexRange.Location + prevNode?.IndexRange.Length ?? 0; newNode.IndexRange = new Range(prevIndex, 1); } -#warning One day when C# receives "or patterns", simplify this abomination + //TODO: One day when C# receives "or patterns", simplify this abomination switch (prevNode, newNode) { case (null, Atoms.BinaryOperator b): newNode = b.ToUnaryOperator(); @@ -90,7 +90,7 @@ public bool EqualsList(MathList otherList) { } return true; } - public override bool Equals(object obj) => obj is MathList l ? EqualsList(l) : false; + public override bool Equals(object obj) => obj is MathList l && EqualsList(l); public override int GetHashCode() => Atoms.Count == 0 ? 0 : Atoms.GetHashCode(); // Special case empty list for LaTeXDefaults bool IEquatable.Equals(MathList otherList) => EqualsList(otherList); diff --git a/CSharpMath/Display/Displays/AccentDisplay.cs b/CSharpMath/Display/Displays/AccentDisplay.cs index 93bcf95f..214802ba 100644 --- a/CSharpMath/Display/Displays/AccentDisplay.cs +++ b/CSharpMath/Display/Displays/AccentDisplay.cs @@ -1,6 +1,5 @@ using System.Drawing; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/FractionDisplay.cs b/CSharpMath/Display/Displays/FractionDisplay.cs index 5425f559..ad47596a 100644 --- a/CSharpMath/Display/Displays/FractionDisplay.cs +++ b/CSharpMath/Display/Displays/FractionDisplay.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/GlyphConstructionDisplay.cs b/CSharpMath/Display/Displays/GlyphConstructionDisplay.cs index 043367a8..fa6ed418 100644 --- a/CSharpMath/Display/Displays/GlyphConstructionDisplay.cs +++ b/CSharpMath/Display/Displays/GlyphConstructionDisplay.cs @@ -2,7 +2,6 @@ using System.Drawing; using System.Linq; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/GlyphDisplay.cs b/CSharpMath/Display/Displays/GlyphDisplay.cs index 4a5e9bc5..4ff3a2af 100644 --- a/CSharpMath/Display/Displays/GlyphDisplay.cs +++ b/CSharpMath/Display/Displays/GlyphDisplay.cs @@ -1,6 +1,5 @@ using System.Drawing; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/InnerDisplay.cs b/CSharpMath/Display/Displays/InnerDisplay.cs index a3d79f15..b176366d 100644 --- a/CSharpMath/Display/Displays/InnerDisplay.cs +++ b/CSharpMath/Display/Displays/InnerDisplay.cs @@ -1,6 +1,5 @@ using System.Drawing; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/LargeOpLimitsDisplay.cs b/CSharpMath/Display/Displays/LargeOpLimitsDisplay.cs index 6cbac0fe..bb9471f9 100644 --- a/CSharpMath/Display/Displays/LargeOpLimitsDisplay.cs +++ b/CSharpMath/Display/Displays/LargeOpLimitsDisplay.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/ListDisplay.cs b/CSharpMath/Display/Displays/ListDisplay.cs index e647d8c3..767d1418 100644 --- a/CSharpMath/Display/Displays/ListDisplay.cs +++ b/CSharpMath/Display/Displays/ListDisplay.cs @@ -2,7 +2,6 @@ using System.Drawing; using System.Linq; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/OverUnderLineDisplay.cs b/CSharpMath/Display/Displays/OverUnderLineDisplay.cs index 03c6cd02..0e2ec572 100644 --- a/CSharpMath/Display/Displays/OverUnderLineDisplay.cs +++ b/CSharpMath/Display/Displays/OverUnderLineDisplay.cs @@ -1,6 +1,5 @@ using System.Drawing; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/RadicalDisplay.cs b/CSharpMath/Display/Displays/RadicalDisplay.cs index 48b93f60..124aa070 100644 --- a/CSharpMath/Display/Displays/RadicalDisplay.cs +++ b/CSharpMath/Display/Displays/RadicalDisplay.cs @@ -1,6 +1,5 @@ using System.Drawing; using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.Displays { using FrontEnd; diff --git a/CSharpMath/Display/Displays/TextLineDisplay.cs b/CSharpMath/Display/Displays/TextLineDisplay.cs index 87a5635a..03a2fb79 100644 --- a/CSharpMath/Display/Displays/TextLineDisplay.cs +++ b/CSharpMath/Display/Displays/TextLineDisplay.cs @@ -1,5 +1,4 @@ using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; using System.Collections.Generic; using System.Drawing; using System.Linq; diff --git a/CSharpMath/Display/Displays/TextRunDisplay.cs b/CSharpMath/Display/Displays/TextRunDisplay.cs index 77635224..e76decba 100644 --- a/CSharpMath/Display/Displays/TextRunDisplay.cs +++ b/CSharpMath/Display/Displays/TextRunDisplay.cs @@ -1,5 +1,4 @@ using CSharpMath.Atom; -using Color = CSharpMath.Structures.Color; using System.Drawing; using System.Linq; diff --git a/CSharpMath/Display/FrontEnd/IGraphicsContext.cs b/CSharpMath/Display/FrontEnd/IGraphicsContext.cs index 26a803b8..1dce3dac 100644 --- a/CSharpMath/Display/FrontEnd/IGraphicsContext.cs +++ b/CSharpMath/Display/FrontEnd/IGraphicsContext.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Drawing; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display.FrontEnd { /// Represents a front-end graphics context. Used for drawing. diff --git a/CSharpMath/Display/GlyphInfo.cs b/CSharpMath/Display/GlyphInfo.cs index efa7b50d..e9f019fa 100644 --- a/CSharpMath/Display/GlyphInfo.cs +++ b/CSharpMath/Display/GlyphInfo.cs @@ -1,3 +1,5 @@ +using System.Drawing; + namespace CSharpMath.Display { public class GlyphInfo { public GlyphInfo(TGlyph glyph, float kern = 0) { @@ -6,8 +8,8 @@ public GlyphInfo(TGlyph glyph, float kern = 0) { } public TGlyph Glyph { get; } public float KernAfterGlyph { get; set; } - public Structures.Color? Foreground { get; set; } - public void Deconstruct(out TGlyph glyph, out float kernAfter, out Structures.Color? foreground) => + public Color? Foreground { get; set; } + public void Deconstruct(out TGlyph glyph, out float kernAfter, out Color? foreground) => (glyph, kernAfter, foreground) = (Glyph, KernAfterGlyph, Foreground); } } \ No newline at end of file diff --git a/CSharpMath/Display/IDisplay.cs b/CSharpMath/Display/IDisplay.cs index 451b7798..8e4517a1 100644 --- a/CSharpMath/Display/IDisplay.cs +++ b/CSharpMath/Display/IDisplay.cs @@ -1,6 +1,5 @@ using CSharpMath.Atom; using System.Drawing; -using Color = CSharpMath.Structures.Color; namespace CSharpMath.Display { using FrontEnd; diff --git a/CSharpMath/Display/Typesetter.cs b/CSharpMath/Display/Typesetter.cs index 90b05e0d..0b79f4e6 100644 --- a/CSharpMath/Display/Typesetter.cs +++ b/CSharpMath/Display/Typesetter.cs @@ -4,7 +4,6 @@ using CSharpMath.Atom.Atoms; using CSharpMath.Display.Displays; using CSharpMath.Display.FrontEnd; -using Color = CSharpMath.Atom.Atoms.Color; using InvalidCodePathException = CSharpMath.Structures.InvalidCodePathException; using System.Drawing; using System.Linq; @@ -183,11 +182,11 @@ private void CreateDisplayAtoms(List preprocessedAtoms) { // We need to preserve the prevAtom for any inter-element space changes, // so we skip to the next node. continue; - case Color color: + case Colored colored: AddDisplayLine(false); - AddInterElementSpace(prevAtom, color); - var colorDisplay = CreateLine(color.InnerList, _font, _context, _style, false); - colorDisplay.SetTextColorRecursive(color.Colour); + AddInterElementSpace(prevAtom, colored); + var colorDisplay = CreateLine(colored.InnerList, _font, _context, _style, false); + colorDisplay.SetTextColorRecursive(colored.Color); colorDisplay.Position = _currentPosition; _currentPosition.X += colorDisplay.Width; _displayAtoms.Add(colorDisplay); @@ -196,7 +195,7 @@ private void CreateDisplayAtoms(List preprocessedAtoms) { AddDisplayLine(false); AddInterElementSpace(prevAtom, colorBox); colorDisplay = CreateLine(colorBox.InnerList, _font, _context, _style, false); - colorDisplay.BackColor = colorBox.Colour; + colorDisplay.BackColor = colorBox.Color; colorDisplay.Position = _currentPosition; _currentPosition.X += colorDisplay.Width; _displayAtoms.Add(colorDisplay); @@ -720,7 +719,7 @@ private IGlyphDisplay _FindGlyphForBoundary( } private IGlyphDisplay _GetRadicalGlyph(float radicalHeight) { -#warning GlyphFinder.FindGlyph + // TODO: something related to GlyphFinder.FindGlyph var radicalGlyph = _context.GlyphFinder.FindGlyphForCharacterAtIndex(_font, 0, "\u221A"); var glyph = _FindGlyph(radicalGlyph, radicalHeight, out float glyphAscent, out float glyphDescent, out float glyphWidth); diff --git a/CSharpMath/Structures/Color.cs b/CSharpMath/Structures/Color.cs deleted file mode 100644 index 30bd8a1a..00000000 --- a/CSharpMath/Structures/Color.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; - -namespace CSharpMath.Structures { -#warning Replace this with TColor - public readonly struct Color : IEquatable { - public Color(byte r, byte g, byte b, byte a = 0xFF) => - (R, G, B, A) = (r, g, b, a); - public Color(float rf, float gf, float bf, float af = 1f) - : this((byte)(rf * 255f), (byte)(gf * 255f), (byte)(bf * 255f), (byte)(af * 255f)) { } - public byte R { get; } - public byte G { get; } - public byte B { get; } - public byte A { get; } - public float Rf => R / 255f; - public float Gf => G / 255f; - public float Bf => B / 255f; - public float Af => A / 255f; - public void Deconstruct(out byte r, out byte g, out byte b) { r = R; g = G; b = B; } - public void Deconstruct(out byte r, out byte g, out byte b, out byte a) - { Deconstruct(out r, out g, out b); a = A; } - public void Deconstruct(out float rf, out float gf, out float bf) - { rf = Rf; gf = Gf; bf = Bf; } - public void Deconstruct(out float rf, out float gf, out float bf, out float af) - { Deconstruct(out rf, out gf, out bf); af = Af; } - public bool Equals(Color other) => (R, G, B, A) == (other.R, other.G, other.B, other.A); - public override bool Equals(object obj) => obj is Color c ? Equals(c) : false; - public static bool operator ==(Color left, Color right) => left.Equals(right); - public static bool operator !=(Color left, Color right) => !left.Equals(right); - public override int GetHashCode() => unchecked(R * 13 + G * 37 + B * 113 + A * 239); - public override string ToString() => - PredefinedColors.TryGetBySecond(this, out var name) - ? name : $"#{A:X2}{R:X2}{G:X2}{B:X2}"; - public static Color? Create(ReadOnlySpan hexOrName, bool extraSweet = true) { - if (hexOrName == null) return null; - if (extraSweet && (hexOrName.StartsWithInvariant("#") || hexOrName.StartsWithInvariant("0x"))) - return FromHexString(hexOrName.RemovePrefix("#").RemovePrefix("0x")); - Span loweredName = stackalloc char[hexOrName.Length]; - hexOrName.ToLowerInvariant(loweredName); - if (PredefinedColors.TryGetByFirst(loweredName.ToString(), out var predefined)) - return predefined; - return null; - static Color? FromHexString(ReadOnlySpan hex) { - static int? CharToByte(char c) => - c >= '0' && c <= '9' ? c - '0' : - c >= 'A' && c <= 'F' ? c - 'A' + 10 : - c >= 'a' && c <= 'f' ? c - 'a' + 10 : - new int?(); - static byte? FromHex1(ReadOnlySpan hex, int index) => - //read one hex char -> byte - (byte?)(CharToByte(hex[index]) * 17); - static byte? FromHex2(ReadOnlySpan hex, int index) => - //read two hex chars -> byte - (byte?)(CharToByte(hex[index]) * 16 + CharToByte(hex[index + 1])); - return hex.Length switch - { - 3 => (FromHex1(hex, 0), FromHex1(hex, 1), FromHex1(hex, 2)) switch - { - (byte r, byte g, byte b) => new Color(r, g, b), - _ => new Color?() - }, - 4 => (FromHex1(hex, 0), FromHex1(hex, 1), FromHex1(hex, 2), FromHex1(hex, 3)) switch - { - (byte a, byte r, byte g, byte b) => new Color(r, g, b, a), - _ => new Color?() - }, - 6 => (FromHex2(hex, 0), FromHex2(hex, 2), FromHex2(hex, 4)) switch - { - (byte r, byte g, byte b) => new Color(r, g, b), - _ => new Color?() - }, - 8 => (FromHex2(hex, 0), FromHex2(hex, 2), FromHex2(hex, 4), FromHex2(hex, 6)) switch - { - (byte a, byte r, byte g, byte b) => new Color(r, g, b, a), - _ => new Color?() - }, - _ => null, - }; - } - } - //https://en.wikibooks.org/wiki/LaTeX/Colors#Predefined_colors - public static BiDictionary PredefinedColors { get; } = - new BiDictionary { - { "black", new Color(0, 0, 0) }, - { "blue", new Color(0, 0, 255) }, - { "brown", new Color(150, 75, 0) }, - { "cyan", new Color(0, 255, 255) }, - { "darkgray", new Color(128, 128, 128) }, - { "gray", new Color(169, 169, 169) }, - { "green", new Color(0, 128, 0) }, - { "lightgray", new Color(211, 211, 211) }, - { "lime", new Color(0, 255, 0) }, - { "magenta", new Color(255, 0, 255) }, - { "olive", new Color(128, 128, 0) }, - { "orange", new Color(255, 128, 0) }, - { "pink", new Color(255, 192, 203) }, - { "purple", new Color(128, 0, 128) }, - { "red", new Color(255, 0,0) }, - { "teal", new Color(0, 128, 128) }, - { "violet", new Color(128, 0, 255) }, - { "white", new Color(255, 255, 255) }, - { "yellow", new Color(255, 255, 0) } - }; - } -} \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index ad68c46e..8d82f882 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -47,7 +47,7 @@ Really, any one you like! [Unity](wiki/@GettingStarted~Unity.md) [ASP.NET](wiki/@GettingStarted~ASP.md) -[Ooui.Wasm](wiki/@GettingStarted~Ooui.md)--> +--> # Platform support @@ -314,7 +314,7 @@ chl: chart labels, here a graph written in https://en.wikipedia.org/wiki/DOT_lan For all uses and possible values of the API parameters, see https://developers.google.com/chart/image/docs/chart_params --> -![Project structure](https://quickchart.io/chart?cht=gv&chl=graph{node[shape=box];{rank=same;AngouriMath;"Typography.OpenFont";"Typography.TextBreak";CSharpMath};AngouriMath[shape=record,label="{_Dependencies|AngouriMath}"];"Typography.OpenFont"[shape=record,label="{_Dependencies|Typography.OpenFont}"];"Typography.TextBreak"[shape=record,label="{_Dependencies|Typography.TextBreak}"];CSharpMath[shape=record,label="{_Core|CSharpMath}"];"CSharpMath.Apple"[shape=record,label="{iOS|CSharpMath.Apple}"];"CSharpMath.Avalonia"[shape=record,label="{Avalonia|CSharpMath.Avalonia}"];"CSharpMath.SkiaSharp"[shape=record,label="{SkiaSharp|CSharpMath.SkiaSharp}"];"CSharpMath.Forms"[shape=record,label="{Xamarin.Forms|CSharpMath.Forms}"];"Typography.OpenFont"--"Typography.GlyphLayout";"Typography.TextBreak"--"TextBreakTests";AngouriMath--UnitTests;CSharpMath--"CSharpMath.CoreTests";CSharpMath--"CSharpMath.Apple"--"CSharpMath.Ios"--{"CSharpMath.Ios.Example";"CSharpMath.Ios.Tests"};CSharpMath--"CSharpMath.Editor"--"CSharpMath.Editor.Tests"--"CSharpMath.Editor.Tests.Visualizer";"CSharpMath.Editor"--"CSharpMath.Editor.Tests.FSharp";{"CSharpMath.Editor";AngouriMath}--"CSharpMath.Evaluation"--{"CSharpMath.Evaluation.Tests";"CSharpMath.Forms.Example"};{"CSharpMath.Editor";"Typography.GlyphLayout";"Typography.TextBreak"}--"CSharpMath.Rendering"--"CSharpMath.Rendering.Text.Tests";"CSharpMath.Rendering"--"CSharpMath.Avalonia"--"CSharpMath.Avalonia.Example";"CSharpMath.Rendering"--"CSharpMath.SkiaSharp"--"CSharpMath.Forms"--"CSharpMath.Forms.Example";"CSharpMath.Forms.Example"--{"CSharpMath.Forms.Example.Android";"CSharpMath.Forms.Example.iOS";"CSharpMath.Forms.Example.UWP";"CSharpMath.Forms.Example.WPF";"CSharpMath.Forms.Example.Ooui"};{"CSharpMath.Avalonia";"CSharpMath.SkiaSharp"}--"CSharpMath.Rendering.Tests";"CSharpMath.Xaml"--{"CSharpMath.Avalonia";"CSharpMath.Forms"}--"CSharpMath.Xaml.Tests"}) +![Project structure](https://quickchart.io/chart?cht=gv&chl=graph{node[shape=box];{rank=same;AngouriMath;"Typography.OpenFont";"Typography.TextBreak";CSharpMath};AngouriMath[shape=record,label="{_Dependencies|AngouriMath}"];"Typography.OpenFont"[shape=record,label="{_Dependencies|Typography.OpenFont}"];"Typography.TextBreak"[shape=record,label="{_Dependencies|Typography.TextBreak}"];CSharpMath[shape=record,label="{_Core|CSharpMath}"];"CSharpMath.Apple"[shape=record,label="{iOS|CSharpMath.Apple}"];"CSharpMath.Avalonia"[shape=record,label="{Avalonia|CSharpMath.Avalonia}"];"CSharpMath.SkiaSharp"[shape=record,label="{SkiaSharp|CSharpMath.SkiaSharp}"];"CSharpMath.Forms"[shape=record,label="{Xamarin.Forms|CSharpMath.Forms}"];"Typography.OpenFont"--"Typography.GlyphLayout";"Typography.TextBreak"--"TextBreakTests";AngouriMath--UnitTests;CSharpMath--"CSharpMath.CoreTests";CSharpMath--"CSharpMath.Apple"--"CSharpMath.Ios"--{"CSharpMath.Ios.Example";"CSharpMath.Ios.Tests"};CSharpMath--"CSharpMath.Editor"--"CSharpMath.Editor.Tests"--"CSharpMath.Editor.Tests.Visualizer";"CSharpMath.Editor"--"CSharpMath.Editor.Tests.FSharp";{"CSharpMath.Editor";AngouriMath}--"CSharpMath.Evaluation"--{"CSharpMath.Evaluation.Tests";"CSharpMath.Forms.Example"};{"CSharpMath.Editor";"Typography.GlyphLayout";"Typography.TextBreak"}--"CSharpMath.Rendering"--"CSharpMath.Rendering.Text.Tests";"CSharpMath.Rendering"--"CSharpMath.Avalonia"--"CSharpMath.Avalonia.Example";"CSharpMath.Rendering"--"CSharpMath.SkiaSharp"--"CSharpMath.Forms"--"CSharpMath.Forms.Example";"CSharpMath.Forms.Example"--{"CSharpMath.Forms.Example.Android";"CSharpMath.Forms.Example.iOS";"CSharpMath.Forms.Example.UWP";"CSharpMath.Forms.Example.WPF"};{"CSharpMath.Avalonia";"CSharpMath.SkiaSharp"}--"CSharpMath.Rendering.Tests";"CSharpMath.Xaml"--{"CSharpMath.Avalonia";"CSharpMath.Forms"}--"CSharpMath.Xaml.Tests"}) ## Major processes of drawing LaTeX