mono / libgdiplus

C-based implementation of the GDI+ API
http://www.mono-project.com/
MIT License
335 stars 171 forks source link

Graphics.MeasureString wrong results in case of PageUnit is Point and all chars fitted #548

Open safern opened 5 years ago

safern commented 5 years ago

charsFitted and linesFitted output paramters values are 0 in case of text fitted in provided area and graphics's PageUnit is Point. The issue is reproducible under linux, but not reproducible under Windows.

Run the following code under linux

var bmp = new Bitmap(200, 50);
using (var graphics = Graphics.FromImage(bmp))
using(var font = new Font("Arial", 10))
{
    graphics.PageUnit = GraphicsUnit.Point;
    graphics.MeasureString("HELLO", font, new SizeF(float.MaxValue, float.MaxValue),
                StringFormat.GenericTypographic, out var chars, out var lines);

     Console.WriteLine($"Chars fitted: {chars}");
     Console.WriteLine($"Lines fitted: {lines}");
  }

Observed: Console output is Chars fitted: 0 Lines fitted: 0

Expected: Console output is Chars fitted: 5 Lines fitted: 1

Moved from: https://github.com/dotnet/corefx/issues/27312

hughbe commented 5 years ago

@safern @akoeplinger can we try merging the opened PRs, may be able to take a look :) /cc @filipnavara

filipnavara commented 5 years ago

@hughbe I will go through them and review and then nag someone to process them ;)