public void Test_Utils_Color_LighterBy() { var colorFrom = Colors.Red; var expectedColor = CanvasPathGeometry.CreateColor("#FFFF7F7F"); Assert.AreEqual(expectedColor, colorFrom.LighterBy(0.5f)); }
public void Test_CanvasBrush_LinearGradientBrush_3() { CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var linearbrush = CanvasPathGeometry.CreateBrush(device, "LG M 0 80 Z0 0 S 0.00 #ffee5124, 0.18 #fff05627, 0.26 #fff15b29, 0.6 #fff58535, 1.00 #fff9af41 3.0"); }
public void Test_CanvasBrush_SolidBrush_3() { CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var solidbrush = CanvasPathGeometry.CreateBrush(device, "SC #FF1233AA O .75 23 35"); }
public void Test_CanvasBrush_RadialGradientBrush_3() { CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var radialbrush = CanvasPathGeometry.CreateBrush(device, "RG 40 60 320 400 S 0.00 #ffee5124, 0.18 #fff05627, 0.26 #fff15b29, 0.72 #fff58535, 1.00 #fff9af41 5.0"); }
public void Test_CreateColor_2() { var color = CanvasPathGeometry.CreateColor("FF7FFF"); Assert.AreEqual(255, color.A); Assert.AreEqual(255, color.R); Assert.AreEqual(127, color.G); Assert.AreEqual(255, color.B); }
public void Test_Utils_Color_Lerp() { var colorFrom = Colors.Red; var colorTo = Colors.Green; var expectedColor = CanvasPathGeometry.CreateColor("#FF7F4000"); Assert.AreEqual(expectedColor, colorFrom.Lerp(colorTo, 0.5f)); }
public void Test_CreateColor_3() { var color = CanvasPathGeometry.CreateColor("0.25 1 0.5 0.5"); Assert.AreEqual(127, color.A); Assert.AreEqual(63, color.R); Assert.AreEqual(255, color.G); Assert.AreEqual(127, color.B); }
public void Test_CanvasStroke_2() { // Invalid data CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var stroke = CanvasPathGeometry.CreateStroke(device, "ST 4.5 6 LG M 0 0 Z80 80 S 0.00 #ffff0000, 0.5 #ff00ff00, 0.99 #ff0000ff CSS DS 2 Do 2 SC 1 EC 2 CDS 2 2 0 2 1 3"); }
public void Test_CreateColor_8() { var color = CanvasPathGeometry.CreateColor(new Vector4(4, 5, 6, 7)); Assert.AreEqual(255, color.A); Assert.AreEqual(255, color.R); Assert.AreEqual(255, color.G); Assert.AreEqual(255, color.B); }
public void Test_CreateColor_9() { var color = CanvasPathGeometry.CreateColor(new Vector4(4, 0.25f, 6, 0.5f)); Assert.AreEqual(255, color.R); Assert.AreEqual(63, color.G); Assert.AreEqual(255, color.B); Assert.AreEqual(127, color.A); }
public void Test_CanvasStroke_4() { // Extra characters in the stroke data CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var stroke = CanvasPathGeometry.CreateStroke(device, "ST 4.5 LG M 0 0 Z80 80 S 0.00 #ffff0000, 0.5 #ff00ff00, 0.99 #ff0000ff CSS DS 2 Do 2 SC 1 EC 2 CDS 2 2 0 2 1 3 A 10"); }
public void Test_CanvasStrokeStyle_1() { var style = CanvasPathGeometry.CreateStrokeStyle("CSS DS 1 LJ1 ML 0.5 DO4 SC 0 EC1 DC3 TB1CDS 2 2 0 2 1 3"); Assert.AreEqual(true, style.LineJoin == CanvasLineJoin.Bevel); Assert.AreEqual(true, style.MiterLimit == 0.5f); Assert.AreEqual(true, style.StartCap == CanvasCapStyle.Flat); Assert.AreEqual(true, style.EndCap == CanvasCapStyle.Square); Assert.AreEqual(true, style.TransformBehavior == CanvasStrokeTransformBehavior.Fixed); }
public void Test_CanvasBrush_Squircle() { CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var squircle = CanvasPathGeometry.CreateSquircle(device, 10, 10, 200, 200, 130, 130); Assert.IsNotNull(squircle, "Could not create Squircle CanvasGeometry"); }
public void Test_CanvasGeometry_3() { CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); const string sample = "F1 M 331.341,81.975 L 398.766,218.593 L 549.533,240.500 L 440.437,346.842 L 466.191,497.000 L 331.341,426.105 L 196.491,497.000 L 222.245,346.842 L 113.150,240.500 L 263.916,218.593 L 331.341,81.975 Z S A M P L E E R R O R"; var geometry = CanvasPathGeometry.CreateGeometry(device, sample); }
public void Test_CanvasStroke_1() { CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var stroke = CanvasPathGeometry.CreateStroke(device, "ST 4.5 LG M 0 0 Z80 80 S 0.00 #ffff0000, 0.5 #ff00ff00, 0.99 #ff0000ff CSS DS 2 LJ1 Do 2 SC 1 EC 2 CDS 2 2 0 2 1 3"); Assert.AreEqual(true, stroke.Width == 4.5f); Assert.AreEqual(true, stroke.Style.LineJoin == CanvasLineJoin.Bevel); Assert.AreEqual(true, stroke.Style.StartCap == CanvasCapStyle.Square); Assert.AreEqual(true, stroke.Style.EndCap == CanvasCapStyle.Round); Assert.AreEqual(true, stroke.Style.TransformBehavior == CanvasStrokeTransformBehavior.Normal); }
public void Test_CanvasBrush() { CanvasDevice device = new CanvasDevice(); Assert.IsNotNull(device, "Could not create CanvasDevice instance."); var solidbrush = CanvasPathGeometry.CreateBrush(device, "SC #FF1233AA O .75"); Assert.IsNotNull(solidbrush, "Could not create SolidColorBrush instance."); var linearbrush = CanvasPathGeometry.CreateBrush(device, "LG M 0 80 Z0 0 S 0.00 #ffee5124, 0.18 #fff05627, 0.26 #fff15b29, 0.6 #fff58535, 1.00 #fff9af41"); Assert.IsNotNull(linearbrush, "Could not create LinearGradientBrush instance."); var radialbrush = CanvasPathGeometry.CreateBrush(device, "RG 40 60 320 400 S 0.00 #ffee5124, 0.18 #fff05627, 0.26 #fff15b29, 0.72 #fff58535, 1.00 #fff9af41"); Assert.IsNotNull(radialbrush, "Could not create RadialGradientBrush instance."); }
private void OnCanvasDraw(CanvasControl sender, CanvasDrawEventArgs args) { if (string.IsNullOrWhiteSpace(_data)) { CommandsList.Text = string.Empty; return; } this._errorGeometry ??= CanvasPathGeometry.CreateGeometry(sender, ErrorString); _logger?.Clear(); CommandsList.Text = string.Empty; try { _logger?.AppendLine("// The following commands represent the CanvasPathBuilder command(s) needed"); _logger?.AppendLine("// to create the CanvasGeometry from the specified Win2d Path Mini Language."); var geometry = CanvasPathGeometry.CreateGeometry(sender, _data); _reader.StartLogging(); geometry.SendPathTo(_reader); _logger?.AppendLine(_reader.EndLogging()); CommandsList.Text = _logger?.ToString() ?? string.Empty; args.DrawingSession.FillGeometry(geometry, _fillColor); args.DrawingSession.DrawGeometry(geometry, _strokeColor, _strokeThickness); RootPivot.SelectedIndex = 0; CommandsList.Foreground = _commandBrush; } catch (ArgumentException argEx) { var message = argEx.Message; var errorCode = message.Substring(0, 11); var parseError = string.Empty; if (message.StartsWith(ParseError1)) { parseError = "Parse Error: No matching data!"; } else if (message.StartsWith(ParseError2)) { parseError = "Parse Error: Multiple FillRule elements present in Path Data!"; } else if (message.StartsWith(ParseError3)) { var tokens = message.Split('\n', StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 3) { parseError = $"Parse Error at {tokens[1]}. Cannot parse '{tokens[2]}'."; } } else { parseError = "Parsing error! Invalid input data!"; } args.DrawingSession.FillGeometry(_errorGeometry, Colors.Black); CommandsList.Text = parseError; RootPivot.SelectedIndex = 1; CommandsList.Foreground = _commandErrorBrush; } catch (Exception) { args.DrawingSession.FillGeometry(_errorGeometry, Colors.Black); CommandsList.Text = "Parsing error! Invalid input data!"; RootPivot.SelectedIndex = 1; CommandsList.Foreground = _commandErrorBrush; } }
public CanvasPathGeometryPage() { this.InitializeComponent(); _reader = new GeometryStreamReader(); _logger = new StringBuilder(); _colors = new List <Color>() { Colors.Transparent, Colors.Black, Colors.White, Colors.Crimson, CanvasPathGeometry.CreateColor("#bf5af2"), CanvasPathGeometry.CreateColor("#0a84ff"), CanvasPathGeometry.CreateColor("#32d74b"), CanvasPathGeometry.CreateColor("#ff9500"), CanvasPathGeometry.CreateColor("#ffd60a") }; _commandBrush = new SolidColorBrush(Colors.White); _commandErrorBrush = new SolidColorBrush(Colors.Red); var colorList = new List <string>() { "Transparent", "Black", "White", "Crimson", "Purple", "LightBlue", "LightGreen", "Orange", "Yellow" }; this._samples = new List <string>() { string.Empty, Sample1, Sample2, Sample3, Sample4, Sample5 }; var sampleList = new List <string>() { "None", "Sample 1", "Sample 2", "Sample 3", "Sample 4", "Sample 5", }; StrokeList.ItemsSource = colorList; FillList.ItemsSource = colorList; StrokeThickness.Value = 1; StrokeList.SelectedIndex = 1; FillList.SelectedIndex = 0; _selectionChanged = false; }
public void Test_CreateColor_7() { var color1 = CanvasPathGeometry.CreateColor("4 5 6 7"); }
public void Test_CanvasStrokeStyle_4() { // Extra characters in the data var style = CanvasPathGeometry.CreateStrokeStyle("CSS DS 1 LJ1 ML 0.5 DO4 SC 0 EC1 DC3 TB1CDS 2 2 0 2 1 3 12 23 34"); }
public void Test_CreateColor_6() { var color1 = CanvasPathGeometry.CreateColor("F112233"); }
public void Test_CreateColor_5() { var color1 = CanvasPathGeometry.CreateColor("FFF"); }
public void Test_CreateColor_4() { var color1 = CanvasPathGeometry.CreateColor("XYZXYZ"); }
public void Test_CanvasStrokeStyle_3() { // Multiple CanvasStrokeStyles in the same data var style = CanvasPathGeometry.CreateStrokeStyle("CSS DS 1 LJ1 ML 0.5 DO4 SC 0 EC1 DC3 TB1CDS 2 2 0 2 1 3 CSS DS 1 LJ1 ML 0.5 DO4 SC 0 EC1 DC3 TB1"); }
public void Test_CanvasStrokeStyle_2() { // Invalid data var style = CanvasPathGeometry.CreateStrokeStyle("CDS DS 1 LJ1 ML 0.5 DO4 SC 0 EC1 DC3 TB1CDS 2 2 0 2 1 3"); }