SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.44k stars 852 forks source link

Wrapped text "wandering" from baseline on successive lines. #685

Closed 3itao8 closed 6 years ago

3itao8 commented 6 years ago

Prerequisites

Description

Wrapped text appears to "wander" on successive "wraps"

Steps to Reproduce

Following code:

public static void DrawWrappedText()
{
    Console.WriteLine($"Executing {System.Reflection.MethodBase.GetCurrentMethod().Name}");

    // White filled "4 x 6" (if measured as 200 DPI).
    Image<Rgba32> TestImage = new Image<Rgba32>(800, 1200);
    TestImage.Mutate(x => x.Fill(Rgba32.White));

    // Font F = SystemFonts.CreateFont("Arial", 30, FontStyle.Regular);
    Font F = SystemFonts.CreateFont("Baskerville Old Face", 30, FontStyle.Regular);

    string T = "’Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.\"Beware the Jabberwock, my son!  The jaws that bite, the claws that catch!  Beware the Jubjub bird, and shun The frumious Bandersnatch!\"";

    TextGraphicsOptions TGO = new TextGraphicsOptions(true)
    {
        WrapTextWidth = TestImage.Width
    };

    TestImage.Mutate(x => x.DrawText(TGO, T, F, Rgba32.Black, new PointF(10, 50)));

    TestImage.Save("WrappedText.jpg");

}

Produced the following:

wandering-text

Zoom into the 4th line of text. The characters are "wandering" vertically off the baseline.

1st line seems OK, and each successive line seems to get "worse".

Other fonts tried (Arial), but the Baskerville shows issue clearly.,

System Configuration

JimBobSquarePants commented 6 years ago

@3itao8 Thanks for raising this.

Not related to the issue at hand but I notice you are not disposing of images after use. Image<TPixel> implements IDisposable

3itao8 commented 6 years ago

JimBob, no disposal, this is simply evaluation/test code.

johnboatie commented 6 years ago

@JimBobSquarePants Just noticed this now has a milestone.

Guesstimate on RC1 timeframe?

3itao8 commented 6 years ago

@JimBobSquarePants

Sorry about confusion on last comment. Was simply saying that Dispose() wan't called as code sample was simply for test/evaluation/demonstration purposes; obviously not "finished" code.

Thx

antonfirsov commented 6 years ago

My guess is that it's most likely a SixLabors.Fonts issue. An isolated/simplified, glyph-level reproduction would help a lot.

@tocsoft any idea what goes wrong & why it's more visible with this font?