WrapTextWidth not wrapping/breaking long words #180
|
I'm trying to wrap text inside a box and it works fine for most text, however if the text is longer then the width set using WrapTextWidth in TextOptions, the word will not wrap (and word break) and it will be drawn outside the box and wrap only the last letter in the word. My setup: TextOptions textOptions = new TextOptions()
{
WrapTextWidth = width,
HorizontalAlignment = SixLabors.Fonts.HorizontalAlignment.Left,
VerticalAlignment = SixLabors.Fonts.VerticalAlignment.Top
};
DrawingOptions drawingOptions = new DrawingOptions()
{
TextOptions = textOptions
};
Image.Mutate(x => x.DrawText(drawingOptions, "Text that will wrap inside the box just fine followed by Areallylongwordthatwontfitinmysetwidth", font, brush, new SixLabors.ImageSharp.Point(xPosition, yPosition)));And the results: Any idea how to get the long word to break so that it wraps like other text inside the box? I really don't want to have to manually break apart the word by doing some sort of loop that measures and breaks the word apart and was hoping I'm just missing something somewhere. |
Answered by
JimBobSquarePants
Dec 2, 2021
Replies: 1 comment 2 replies
|
You'll need to use the latest MyGet build for this. There's been some significant changes to the API while we get things ready for RC1. using var image = new Image<Rgb24>(404, 147, Color.White);
TextOptions options = new(SystemFonts.CreateFont("arial", 16))
{
WrappingLength = image.Width * .5F,
WordBreaking = WordBreaking.BreakAll,
Origin = new Vector2(20, 20),
};
image.Mutate(x => x.DrawText(options, "Text that will wrap inside the box just fine followed by Areallylongwordthatwontfitinmysetwidth", Color.Black));
image.SaveAsPng("word-break.png"); |
2 replies
Answer selected by
msipessr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


You'll need to use the latest MyGet build for this.
1.0.0-beta13.15There's been some significant changes to the API while we get things ready for RC1.