PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

MeasureString throws exception on text with blank characters
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2695
Page 1 of 1

Author:  kabani [ Thu Jan 02, 2014 10:59 pm ]
Post subject:  MeasureString throws exception on text with blank characters

Dears,
I am using PDFSharp, but I cannot find which version, it is from mid-2012. Here is the problem,
When MeasureString is called (XGraphics.MeasureString(String text, XFont font, XStringFormat stringFormat)),
if the text is a string of blanks, the XSize.FromSizeF(SizeF size) throws a WidthAndHeightCannotBeNegative exception. The width is coming as a very small negative number, like -0.00001....
IT works fine if the text is an empty string.
Any clue?.
Thanks

Author:  () => true [ Fri Jan 03, 2014 3:34 pm ]
Post subject:  Re: MeasureString throws exception on text with blank charac

Hi!

GDI+ build or WPF build?

Will be investigated after the holidays.

Author:  kabani [ Mon Jan 06, 2014 10:11 pm ]
Post subject:  Re: MeasureString throws exception on text with blank charac

Thanks Dear,
It is GDI+ build

Author:  Thomas Hoevel [ Mon Jan 13, 2014 4:36 pm ]
Post subject:  Re: MeasureString throws exception on text with blank charac

Hi!

Cannot replicate.

My test code:
Code:
// Create a font
XFont font = new XFont("Times New Roman", 20, XFontStyle.BoldItalic);

// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
  new XRect(0, 0, page.Width, page.Height),
  XStringFormats.Center);

ue
  {
      var res = gfx.MeasureString(" ", font);
      res = gfx.MeasureString("  ", font);
      res = gfx.MeasureString("   ", font);
      res = gfx.MeasureString("    ", font);
      res = gfx.MeasureString("     ", font);
      res = gfx.MeasureString("      ", font);
      res = gfx.MeasureString("       ", font);
      res = gfx.MeasureString("        ", font);
  }


Width was always 0, no exception was thrown.

We need a sample (maybe an SSCCE) to replicate the issue.

See also:
viewtopic.php?p=2094#p2094

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/