PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 8:10 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: Mon Aug 11, 2008 3:31 pm 
Offline

Joined: Mon Aug 11, 2008 3:25 pm
Posts: 1
When you draw a string containing 2 spaces like "this is me" then in the actual drawing 3 spaces are used. This prohibits exact placing of various sequential strings. The code below contains the fixes marked with "JV-2008-8-11"

Code:
void CreateLayout()
{
  double rectWidth = this.layoutRectangle.width;
  double rectHeight = this.layoutRectangle.height - this.cyAscent - this.cyDescent;
  int firstIndex = 0;
  double x = 0, y = 0;
  int count = this.blocks.Count;
  for (int idx = 0; idx < count; idx++)
  {
    Block block = (Block)this.blocks[idx];
    if (block.Type == BlockType.LineBreak)
    {
      if (Alignment == XParagraphAlignment.Justify)
        ((Block)this.blocks[firstIndex]).Alignment = XParagraphAlignment.Left;
      AlignLine(firstIndex, idx - 1, rectWidth);
      firstIndex = idx + 1;
      x = 0;
      y += this.lineSpace;
    }
    else
    {
        double width =  block.Width; //JV-2008-08-11
      if ((x + width <= rectWidth || x == 0) && block.Type != BlockType.LineBreak)
      {
        block.Location = new XPoint(x, y);
          x += width + this.spaceWidth; // JV-2008-08-11
      }
      else
      {
        AlignLine(firstIndex, idx - 1, rectWidth);
        firstIndex = idx;
        y += this.lineSpace;
        if (y > rectHeight)
        {
          block.Stop = true;
          break;
        }
        block.Location = new XPoint(0, y);
        x = width;
      }
    }
  }
  if (firstIndex < count && this.Alignment != XParagraphAlignment.Justify)
    AlignLine(firstIndex, count - 1, rectWidth);
}


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 19, 2009 1:38 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!

Thanks for the feedback.

At the end, you also have to add the width of a space:
Code:
        block.Location = new XPoint(0, y);
        x = width;


The next version of PDFsharp will do it your way.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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: No registered users and 52 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