Skip to content

Commit

Permalink
修复坐标渲染显示内容
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Oct 19, 2024
1 parent 7732dae commit 77dfe6c
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ public void Render(RenderInfoProvider renderInfoProvider)
LineDrawingArgument argument = lineInfo.Argument;
foreach (CharData charData in argument.CharList)
{
Point startPoint = charData.GetStartPoint();
Rect bounds = charData.GetBounds();
Point startPoint = bounds.LeftTop;

float x = (float) startPoint.X;
float y = (float) startPoint.Y;
var skiaTextRenderInfo = new SkiaTextRenderInfo(charData.CharObject.ToText(), x, y, charData.RunProperty);
float width = (float) bounds.Width;
float height = (float) bounds.Height;
var skiaTextRenderInfo = new SkiaTextRenderInfo(charData.CharObject.ToText(), x, y, width, height, charData.RunProperty);
list.Add(skiaTextRenderInfo);
}

Expand Down Expand Up @@ -96,16 +100,20 @@ public void Render(SKCanvas canvas)
{
skPaint.TextSize = (float) skiaTextRenderInfo.RunProperty.FontSize;

skPaint.GetGlyphWidths(skiaTextRenderInfo.Text, out var skBounds);
float x = skiaTextRenderInfo.X;
float y = skiaTextRenderInfo.Y;

var y = skiaTextRenderInfo.Y;
// 由于 Skia 的 DrawText 传入的 Point 是文本的最下方,因此需要调整 Y 值
y += skiaTextRenderInfo.Height;

if (skBounds != null && skBounds.Length > 0)
{
y += skBounds[0].Height;
}
//skPaint.GetGlyphWidths(skiaTextRenderInfo.Text, out var skBounds);

//if (skBounds != null && skBounds.Length > 0)
//{
// y += skBounds[0].Height;
//}

canvas.DrawText(skiaTextRenderInfo.Text, new SKPoint(skiaTextRenderInfo.X, y), skPaint);
canvas.DrawText(skiaTextRenderInfo.Text, new SKPoint(x, y), skPaint);
}

SKPaint caretPaint = skPaint;
Expand All @@ -126,5 +134,5 @@ public void Render(SKCanvas canvas)
}).ToSKRect(), caretPaint);
}

record SkiaTextRenderInfo(string Text, float X, float Y, IReadOnlyRunProperty RunProperty);
record SkiaTextRenderInfo(string Text, float X, float Y, float Width, float Height, IReadOnlyRunProperty RunProperty);
}

0 comments on commit 77dfe6c

Please sign in to comment.