How can I vertical layout correctly? #428
-
Hi. Windows 11 Home 23H2 With punctuation (At first glance, the “う”, "こ", “も”, “し” and "日" appear to be centered, but this is only because the punctuation marks is misaligned.) As a reference, I have attached a layout in Photoshop. Steps to Reproduceusing SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.Numerics;
const string WithoutPunctuation = "あいうえお「こんにちはー」もしもし ABCDEFG 日本語";
const string WithPunctuation = "あいうえお、「こんにちはー」。もしもし。ABCDEFG 日本語";
void CreateTextImage(string text, string filePath)
{
//using var fs = new System.IO.FileStream("NotoSerifJP-Medium.ttf", FileMode.Open);
//var fontCollection = new FontCollection();
//var fontFamily = fontCollection.Add(fs);
var fontFamily = SystemFonts.Get("Yu Gothic");
var font = fontFamily.CreateFont(30.0F);
var textOption = new RichTextOptions(font)
{
LayoutMode = LayoutMode.VerticalRightLeft,
Origin = new Vector2(10.0F, 10.0F)
};
var bounds = TextMeasurer.MeasureBounds(text, textOption);
var image = new Image<Bgra32>(
(int)Math.Ceiling(bounds.Width + Math.Abs(bounds.Left) * 2.0F),
(int)Math.Ceiling(bounds.Height + Math.Abs(bounds.Top) * 2.0F),
new Bgra32(255, 255, 255)
);
image.Mutate(x =>
{
x.DrawText(textOption, text, Color.Black);
// draw bounding box
x.DrawPolygon(
Pens.Solid(Color.Blue),
new PointF(bounds.Left, bounds.Top),
new PointF(bounds.Right, bounds.Top),
new PointF(bounds.Right, bounds.Bottom),
new PointF(bounds.Left, bounds.Bottom)
);
// draw center line
var centerX = bounds.Left + bounds.Width * 0.5F;
x.DrawLine(
Pens.Solid(Color.Red),
new PointF(centerX, bounds.Top),
new PointF(centerX, bounds.Bottom)
);
});
image.SaveAsPng(filePath);
}
CreateTextImage(WithoutPunctuation, "without_punctuation.png");
CreateTextImage(WithPunctuation, "with_punctuation.png"); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Thanks for providing such great detail! There's definitely something wrong here and I'm investigating now. Can you please add your software versions used to your sample and I'll create an issue. Thanks! |
Beta Was this translation helpful? Give feedback.
Thanks for providing such great detail! There's definitely something wrong here and I'm investigating now. Can you please add your software versions used to your sample and I'll create an issue. Thanks!