PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 9:30 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Feb 28, 2012 4:25 pm 
Offline

Joined: Thu Feb 09, 2012 4:59 pm
Posts: 14
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?


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 28, 2012 5:51 pm 
Offline

Joined: Thu Feb 09, 2012 4:59 pm
Posts: 14
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;


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 40 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group