PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
XGraphics.MeasureString ignoring trailing spaces https://forum.pdfsharp.net/viewtopic.php?f=2&t=1925 |
Page 1 of 1 |
Author: | hoylemd [ Tue Feb 28, 2012 4:25 pm ] |
Post subject: | XGraphics.MeasureString ignoring trailing spaces |
Hi forums, Is there a way to have XGraphics.MeasureString not ignore trailing spaces? This code: Code: text = "test: "; graphics.DrawString(text, font, brush, drawpoint); drawpoint.X += graphics.MeasureString(text, font).Width; text = "stuff"; graphics.DrawString(text, font, brush, drawpoint); drawpoint.X = 0; drawpoint.Y += graphics.MeasureString(text, font).Height; text = "test: stuff"; graphics.DrawString(text, font, brush, drawpoint); drawpoint.X = 0; drawpoint.Y += graphics.MeasureString(text, font).Height; text = "test:"; graphics.DrawString(text, font, brush, drawpoint); drawpoint.X += graphics.MeasureString(text, font).Width; text = " stuff"; graphics.DrawString(text, font, brush, drawpoint); draws: test:stuff test: stuff test: stuff The first test is ignoring the two trailing spaces at the end of "test", and the other two operate as expected. I need to be able to accomodate trailing spaces. Is there any way around this, or will I have to mess around with the source code? |
Author: | hoylemd [ Tue Feb 28, 2012 5:51 pm ] |
Post subject: | Re: XGraphics.MeasureString ignoring trailing spaces |
In case this never gets a response, this is my current workaround: I use my own wrapper methods for most of PDFSharp's methods. In my MeasureString method, I append a character to the end of the string to measure, measure this modified string, then subtract the width of that character from the measurement. pseudocode: Code: function wrapMeasureString(text, font)
teststring = text + "."; size = MeasureString(teststring, font); size.width -= MeasureString(".", font).Width; return size; |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |