You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Right to Left languages add a space at the beginning of a line #96
Not sure if I'm doing right to left correctly but when I render a multi line text, any line that isn't the end of the paragraph has an extra space at the beginning of the line. Here are a few examples:
In this example you can see the first 4 lines there is a slight space at the beginning but the last line is more right.
In this example the first line of the second paragraph has a slight space but the second line is flush with the other lines.
Here's the code I'm using to create the string:
public void DrawText(
SKCanvas canvas,
string text,
SkiaTextLayoutOptions layoutOptions
)
{
if (string.IsNullOrWhiteSpace(text))
{
return;
}
var richString = new RichString
{
MaxWidth = layoutOptions.MaxWidthPixels,
MaxHeight = layoutOptions.MaxHeightPixels,
};
var margin = layoutOptions.MarginPixels;
richString.MarginTop(margin).MarginBottom(margin).MarginLeft(margin).MarginRight(margin);
richString.Add(text, layoutOptions.FontFamily, fontSize: DefaultFontSize);
richString.Alignment(TextAlignment.Right);
var options = new TextPaintOptions
{
Edging = SKFontEdging.Antialias,
};
var startingPoint = new SKPoint(layoutOptions.StartingX, layoutOptions.StartingY);
richString.Paint(canvas, startingPoint, options);
}
Here's a super simple implementation that shows the problem:
const int docSize = 576;
const string outputPath = @"C:\Users\gbcha\Downloads\hebrew.png";
var richString = new RichString
{
MaxWidth = docSize
};
richString.Add("אמא ואבא,\n\nהיה לנו כיף! עזרתם לנו נורא ואנחנו מודים לכם מקרב לבאני וולריו נהנו כלכך ממתנת הלילה במלון ואנחנו אסירי תודה. מחכים הבא!\nניתאי, עלמה, ולריו, וטליה");
richString.Alignment(TextAlignment.Right);
using var bitmap = new SKBitmap(docSize, docSize);
using var bitmapCanvas = new SKCanvas(bitmap);
bitmapCanvas.Clear(SKColors.White);
richString.Paint(bitmapCanvas, new SKPoint(0, 0));
using var image = SKImage.FromBitmap(bitmap);
using var data = image.Encode(SKEncodedImageFormat.Png, 100);
using var output = File.OpenWrite(outputPath);
data.SaveTo(output);
Activity
gbreen12 commentedon May 2, 2025
Here's a super simple implementation that shows the problem:
Output:
gbreen12 commentedon May 2, 2025
If I remove the end of the line to make it so it doesn't wrap it removes the extra space: