PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Tables with negative numbers 'hyphens' causing linebraks
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3860
Page 1 of 1

Author:  OVS [ Mon Oct 15, 2018 9:56 am ]
Post subject:  Tables with negative numbers 'hyphens' causing linebraks

Hello,
I've currently a small problem with negative numbers which I add into my table.

Let me explain:
I got a table with 4 columns each of those columns are fixed width (widening the columns is not an option for my purpose). I'm reading numbers form a ASCII file some of them are positive and some negative.
However if there is a long negative number which will exceed it's column width the migradoc internal 'intelligence' will add a linebreak to the paragraph.

Can I disable this feature to get the number in one line?
Replacing the hyphen with something similar looking does not sound like a good idea.

Here is how I add the paragraph:

Code:
                    cell = DRow.Cells[1];
                    p = new Paragraph();
                    p.AddFormattedText(input, TableFont);
                    cell.Add(p);


Thank you!

Author:  Thomas Hoevel [ Mon Oct 15, 2018 11:15 am ]
Post subject:  Re: Tables with negative numbers 'hyphens' causing linebraks

Hi!
OVS wrote:
Replacing the hyphen with something similar looking does not sound like a good idea.
That would be a simple workaround that surely works.

But then you'll get the next problem: the number does not fit the column - otherwise the "MigraDoc intelligence" would not break at the minus. The number will be drawn across the column margin, maybe into the next column.

A clean solution would be using wider columns - or a smaller font or maybe a narrow font.

Author:  OVS [ Mon Oct 15, 2018 11:46 am ]
Post subject:  Re: Tables with negative numbers 'hyphens' causing linebraks

I've now wrote a method which will measure the string before putting it into the cell. If it is to wide for the cell it will decrease the font size step by step.
It is a recursive method. It will break the recursive loop if the string fits. After that it will set the font back to its original size.

However this still ignores the hyphen (calculation of measured string size) and does not take it into its calculation.

I used the helper class I've found here in the forums to measure the needed space.

However I could set a threshold to do maybe one or two additional recursive calls to further decrease the font in size.

Author:  Thomas Hoevel [ Mon Oct 15, 2018 3:01 pm ]
Post subject:  Re: Tables with negative numbers 'hyphens' causing linebraks

OVS wrote:
However this still ignores the hyphen (calculation of measured string size) and does not take it into its calculation.
I used the helper class I've found here in the forums to measure the needed space.
Could be a bug if the minus is not included in the size calculation.
Would you please provide a link to the helper class?

See also:
http://forum.pdfsharp.net/viewtopic.php?f=2&t=832

Author:  OVS [ Tue Oct 16, 2018 6:47 am ]
Post subject:  Re: Tables with negative numbers 'hyphens' causing linebraks

Sure:

viewtopic.php?f=8&t=3196&p=11662&hilit=TextMeasurement#p11662

Using a 1:1 copy of that.

Author:  Thomas Hoevel [ Tue Oct 16, 2018 11:20 am ]
Post subject:  Re: Tables with negative numbers 'hyphens' causing linebraks

Thanks for the link.

And which version of PDFsharp? 1.50 RC2a? GDI+ build? WPF build?


AFAIK the part of the column used for text is smaller than the width of the column due to the margins of the column.
Did you take the margins into account when comparing text width and column width?

Author:  OVS [ Tue Oct 16, 2018 2:25 pm ]
Post subject:  Re: Tables with negative numbers 'hyphens' causing linebraks

1.50.4740.0 GDI+ build (release)

I take the cell width into account by using this:
Code:
cell.Column.Width



So I guess the margins are not included into the calculation. Now I have to find a way to get the margin for the column I'm currently putting text into.

cell.LeftPadding and cell.RightPadding are set to 0. I added them to the 'available space' anyway. However the behaviour does not change. What's the margin property of the cell?

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