PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
XTextFormatter.cs incorrect Layout https://forum.pdfsharp.net/viewtopic.php?f=3&t=447 |
Page 1 of 1 |
Author: | janvee [ Mon Aug 11, 2008 3:31 pm ] |
Post subject: | XTextFormatter.cs incorrect Layout |
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); } |
Author: | Thomas Hoevel [ Thu Nov 19, 2009 1:38 pm ] |
Post subject: | Re: XTextFormatter.cs incorrect Layout |
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. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |