Skip to content

Commit

Permalink
revert lines to be middle of pixel based so drawline aligns with draw…
Browse files Browse the repository at this point in the history
…rectangle

Added unit tests for drawline overlapping.
  • Loading branch information
tomlm committed Nov 19, 2024
1 parent 04cbbe7 commit 67e29c3
Show file tree
Hide file tree
Showing 2 changed files with 322 additions and 252 deletions.
30 changes: 10 additions & 20 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,35 +304,25 @@ private void DrawLineInternal(IPen pen, Line line)
{
if (pen.Thickness == 0) return;

line = TransformLineInternal(line);

Point head = line.PStart;
if (pen.Brush is MoveConsoleCaretToPositionBrush)
if (pen.Thickness == UnderlineThickness || pen.Thickness == StrikethroughThickness)

Check warning on line 307 in src/Consolonia.Core/Drawing/DrawingContextImpl.cs

View workflow job for this annotation

GitHub Actions / build

"[CompareOfFloatsByEqualityOperator] Equality comparison of floating point numbers. Possible loss of precision while rounding values" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/DrawingContextImpl.cs(307,17)

Check warning on line 307 in src/Consolonia.Core/Drawing/DrawingContextImpl.cs

View workflow job for this annotation

GitHub Actions / build

"[CompareOfFloatsByEqualityOperator] Equality comparison of floating point numbers. Possible loss of precision while rounding values" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/DrawingContextImpl.cs(307,56)
{
CurrentClip.ExecuteWithClipping(head,
() => { _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); });
return;
}
if (line.Vertical)
throw new NotSupportedException("Vertical strikethrough or underline text decorations is not supported.");

if (line.Vertical == false && pen.Thickness > 2)
{
// horizontal lines with thickness larger than one are text decorations
ApplyTextDecorationLineInternal(ref head, pen, line);
ApplyTextDecorationLineInternal(pen, line);
return;
}

var extractColorCheckPlatformSupported = ExtractColorOrNullWithPlatformCheck(pen, out var lineStyle);
if (extractColorCheckPlatformSupported == null)
return;

var color = (Color)extractColorCheckPlatformSupported;

byte pattern = (byte)(line.Vertical ? 0b1010 : 0b0101);
DrawPixelAndMoveHead(ref head, line, lineStyle, pattern, color, line.Length); //line
DrawRectangleLineInternal(pen, line);
}

private void ApplyTextDecorationLineInternal(ref Point head, IPen pen, Line line)
private void ApplyTextDecorationLineInternal(IPen pen, Line line)
{
line = TransformLineInternal(line);

Point head = line.PStart;

TextDecorationLocation textDecoration = pen.Thickness switch
{
UnderlineThickness => TextDecorationLocation.Underline,
Expand Down
Loading

0 comments on commit 67e29c3

Please sign in to comment.