From c5d315cf523e605c67bb8634f3c97d026b538e18 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Wed, 30 Oct 2024 17:24:56 -0700 Subject: [PATCH] lint fixes --- src/Consolonia.Core/Drawing/ConsoleBrush.cs | 4 ++-- src/Consolonia.Core/Drawing/DrawingContextImpl.cs | 4 +--- .../Drawing/PixelBufferImplementation/Pixel.cs | 10 ++++------ .../PixelBufferImplementation/PixelBackground.cs | 1 - .../PixelBufferImplementation/PixelForeground.cs | 2 +- .../Drawing/PixelBufferImplementation/SimpleSymbol.cs | 2 -- src/Consolonia.Core/Drawing/RenderTarget.cs | 4 +--- .../Infrastructure/InputLessDefaultNetConsole.cs | 1 - src/Consolonia.Core/Text/GlyphRunImpl.cs | 1 - src/Consolonia.Core/Text/TextShaper.cs | 2 +- 10 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/Consolonia.Core/Drawing/ConsoleBrush.cs b/src/Consolonia.Core/Drawing/ConsoleBrush.cs index 7a19aff7..988d8367 100644 --- a/src/Consolonia.Core/Drawing/ConsoleBrush.cs +++ b/src/Consolonia.Core/Drawing/ConsoleBrush.cs @@ -1,6 +1,4 @@ using System; -using System.ComponentModel; -using System.Globalization; using Avalonia; using Avalonia.Media; using Consolonia.Core.Drawing.PixelBufferImplementation; @@ -183,6 +181,8 @@ private static Color InterpolateColor(IGradientBrush brush, double relativePosit break; } } + if (before == null && after == null) + throw new ArgumentException("no gradientstops defined"); if (before == null) { diff --git a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs index dcd0249b..044454d0 100644 --- a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs +++ b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs @@ -126,8 +126,6 @@ public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry) } return; } - default: - break; } Rect r2 = r.TransformToAABB(Transform); @@ -270,7 +268,7 @@ public Matrix Transform lineStyle = null; if (pen is not { - Brush: ConsoleBrush or LineBrush or ImmutablePen or ImmutableSolidColorBrush, + Brush: ConsoleBrush or LineBrush or ImmutableSolidColorBrush, Thickness: 1, DashStyle: null or { Dashes: { Count: 0 } }, LineCap: PenLineCap.Flat, diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs index 0de2f31e..8aaea01e 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs @@ -1,8 +1,5 @@ using System; -using System.Diagnostics.CodeAnalysis; -using Avalonia.Controls.Documents; using Avalonia.Media; -using Consolonia.Core.Text; // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global @@ -28,7 +25,7 @@ public Pixel(char character, Color foregroundColor, FontStyle style = FontStyle. } public Pixel(byte drawingBoxSymbol, Color foregroundColor) : this( - new DrawingBoxSymbol(drawingBoxSymbol), foregroundColor, FontStyle.Normal, FontWeight.Normal) + new DrawingBoxSymbol(drawingBoxSymbol), foregroundColor) { } @@ -71,12 +68,13 @@ public Pixel Blend(Pixel pixelAbove) case PixelBackgroundMode.Transparent: // when a textdecoration of underline happens a DrawLine() is called over the top of the a pixel with non-zero symbol. // this detects this situation and eats the draw line, turning it into a textdecoration - if (pixelAbove.Foreground.Symbol is DrawingBoxSymbol box && + if (pixelAbove.Foreground.Symbol is DrawingBoxSymbol && this.Foreground.Symbol is SimpleSymbol simpleSymbol && ((ISymbol)simpleSymbol).GetCharacter() != (Char)0) + { // this is a line being draw through text. add TextDecoration for underline. - newForeground = new PixelForeground(this.Foreground.Symbol, this.Foreground.Weight, this.Foreground.Style, TextDecorations.Underline, this.Foreground.Color); + newForeground = new PixelForeground(Foreground.Symbol, Foreground.Weight, Foreground.Style, TextDecorations.Underline, Foreground.Color); } else { diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs index 62669b73..a7e53761 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using Avalonia.Media; namespace Consolonia.Core.Drawing.PixelBufferImplementation diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs index 28113f27..b53c7840 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs @@ -9,7 +9,7 @@ public readonly struct PixelForeground public PixelForeground(ISymbol symbol, FontWeight weight = FontWeight.Normal, FontStyle style = FontStyle.Normal, TextDecorationCollection textDecorations = null, Color? color = null) { ArgumentNullException.ThrowIfNull(symbol); - Symbol = symbol ?? new SimpleSymbol('░'); + Symbol = symbol; Color = color ?? Colors.White; Weight = weight; Style = style; diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs index 1fb969a1..63d6a830 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs @@ -1,5 +1,3 @@ -using System; - namespace Consolonia.Core.Drawing.PixelBufferImplementation { public readonly struct SimpleSymbol : ISymbol diff --git a/src/Consolonia.Core/Drawing/RenderTarget.cs b/src/Consolonia.Core/Drawing/RenderTarget.cs index 9ab3d12f..480351ac 100644 --- a/src/Consolonia.Core/Drawing/RenderTarget.cs +++ b/src/Consolonia.Core/Drawing/RenderTarget.cs @@ -6,7 +6,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Media; -using Avalonia.Media.TextFormatting.Unicode; using Avalonia.Platform; using Consolonia.Core.Drawing.PixelBufferImplementation; using Consolonia.Core.Infrastructure; @@ -117,8 +116,7 @@ private void RenderToDevice() if (!_consoleWindow.InvalidatedRects.Any(rect => rect.ContainsExclusive(new Point(x, y)))) continue;*/ if (pixel.Background.Mode != PixelBackgroundMode.Colored) - throw new InvalidOperationException( - "All pixels in the buffer must have exact console color before rendering"); + throw new InvalidOperationException("All pixels in the buffer must have exact console color before rendering"); if (x == pixelBuffer.Width - 1 && y == pixelBuffer.Height - 1) break; diff --git a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs index 5392386d..8e877b46 100644 --- a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs +++ b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/Consolonia.Core/Text/GlyphRunImpl.cs b/src/Consolonia.Core/Text/GlyphRunImpl.cs index 1a39b899..7fbcbb50 100644 --- a/src/Consolonia.Core/Text/GlyphRunImpl.cs +++ b/src/Consolonia.Core/Text/GlyphRunImpl.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using Avalonia; diff --git a/src/Consolonia.Core/Text/TextShaper.cs b/src/Consolonia.Core/Text/TextShaper.cs index 74d3ee1e..5331aeab 100644 --- a/src/Consolonia.Core/Text/TextShaper.cs +++ b/src/Consolonia.Core/Text/TextShaper.cs @@ -14,7 +14,7 @@ public ShapedBuffer ShapeText(ReadOnlyMemory text, TextShaperOptions optio var glyphInfos = Convert(text.Span.ToString()); var shapedBuffer = new ShapedBuffer(text, glyphInfos.Length, - options.Typeface ?? new GlyphTypeface(), 1, 0 /*todo: must be 1 for right to left?*/); + options.Typeface, 1, 0 /*todo: must be 1 for right to left?*/); for (int i = 0; i < shapedBuffer.Length; i++) shapedBuffer[i] = glyphInfos[i]; return shapedBuffer;