Skip to content

Commit

Permalink
fix char position bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Nov 18, 2024
1 parent acfcafd commit e6de66c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ private void DrawPixelAndMoveHead(ref Point head, Line line, LineStyle? lineStyl
default:
{
var symbol = new SimpleSymbol(glyph);
// if we are attempting to draw a wide glyph we need to make sure that the clipping point
// is for the last physical char. Aka a double char should be clipped if it's second rendered
// char would break the boundary of the clip.
// var clippingPoint = new Point(characterPoint.X + symbol.Width - 1, characterPoint.Y);
var newPixel = new Pixel(symbol, foregroundColor, typeface.Style, typeface.Weight);
CurrentClip.ExecuteWithClipping(characterPoint, () =>
{
Expand All @@ -542,19 +546,20 @@ private void DrawPixelAndMoveHead(ref Point head, Line line, LineStyle? lineStyl
if (oldPixel.Width == 0)
{
// if the oldPixel was empty, we need to set the previous pixel to space
var targetX = characterPoint.X + currentXPosition - 1;
var targetX = characterPoint.X - 1;
if (targetX >= 0)
{
_pixelBuffer.Set((PixelBufferCoordinate)(PixelBufferCoordinate)new Point(targetX, characterPoint.Y),
(oldPixel2) => new Pixel(new PixelForeground(new SimpleSymbol(' '), Colors.Transparent), oldPixel2.Background));
}
}
else if (oldPixel.Width > 1)
else
if (oldPixel.Width > 1)
{
// if oldPixel was wide we need to reset overlapped symbols from empty to space
for (ushort i = 1; i < oldPixel.Width; i++)
{
var targetX = characterPoint.X + currentXPosition + i;
var targetX = characterPoint.X + i;
if (targetX < _pixelBuffer.Size.Width)
{
_pixelBuffer.Set((PixelBufferCoordinate)new Point(targetX, characterPoint.Y),
Expand All @@ -568,11 +573,11 @@ private void DrawPixelAndMoveHead(ref Point head, Line line, LineStyle? lineStyl
{
for (int i = 1; i < symbol.Width; i++)
{
var targetX = characterPoint.X + currentXPosition + i;
var targetX = characterPoint.X + i;
if (targetX < _pixelBuffer.Size.Width)
{
_pixelBuffer.Set((PixelBufferCoordinate)new Point(targetX, characterPoint.Y),
(oldPixel2) => new Pixel(new PixelForeground(new SimpleSymbol(), Colors.Transparent), newPixel.Background));
(oldPixel2) => new Pixel(new PixelForeground(new SimpleSymbol(), Colors.Transparent), oldPixel2.Background));
}
}
}
Expand Down

0 comments on commit e6de66c

Please sign in to comment.