libgdiplus icon indicating copy to clipboard operation
libgdiplus copied to clipboard

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

Open safern opened this issue 6 years ago • 2 comments

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

safern avatar May 14 '19 17:05 safern

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

hughbe avatar May 14 '19 17:05 hughbe

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

filipnavara avatar May 15 '19 08:05 filipnavara