Skip Menu |

This queue is for tickets about the PDF-API2 CPAN distribution.

Report information
The Basics
Id: 98546
Status: open
Priority: 0/
Queue: PDF-API2

People
Owner: Nobody in particular
Requestors: philperry [...] hvc.rr.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: handling last line of justified text
Date: Tue, 02 Sep 2014 12:01:20 -0400
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
PDF::API2 v2.022 Perl 5.16.3 Windows 7 severity: Wishlist Currently, the last line of text sent to Content.pm's text_fill_justified() method is stretched with hspace() to fill the entire width, which results in short words being severely distorted. The last line should be left-, center-, or right-justified (requiring a new parameter) without any scaling. Both text_fill_justified() and text_justified() suffer from this problem, even on non-last (full) lines. It would be better to use wordspace() and charspace() to stretch out the content to fill a width, rather than simply scaling up everything with hscale(). As discussed above, the last line (unfilled) would simply be justified to one side or the center. I sent a sample PDF to the maintainer which demonstrates these problems (page 5).
Subject: [rt.cpan.org #98546]
Date: Sat, 23 Jan 2016 15:13:03 -0500
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
It appears that at some point after I opened this bug report, someone partially fixed the main issue (that a partial last line was stretched to fill the full width). Now, if it is the last line, it is simply output unstretched (hscale/hspace not changed) and left justified. While an improvement, some users may wish to center or right justify the last line. I propose to add an -align %opts flag to override the default left justification. For text_justified(), the user is specifying how much text is to be put in the allotted space, so let's just leave text_justified() alone with regards to the last line (presumably the user knows what they're doing with their last line), and add a final line -align only to text_fill_justified(). I feel that both functions should have their algorithm fixed so that charspace() and wordspace() are used to stretch a line to fit, rather than hscale()/hspace(), which severely distorts characters. I'm thinking of using wordspace() to (up to) double the size of spaces between words (note that multiple spaces get collapsed to single spaces, and currently this is done only with ASCII spaces x20). Any additional stretching would be satisfied with charspace(). If a ridiculous amount of stretching is requested, after some point (e.g., 1em added space per character) wordspace() might again grow to satisfy the rest of the request. Possibly these parameters could be set/overridden globally (with a new call), or as %opts optional parameters in the two calls. For a given line, the old wordspace and charspace settings would be saved and restored, and be changed only for this one line. Non-ASCII spaces (NBSP, thinsp, emspace, etc.) depend on the character encoding used, and will not be dealt with for the time being. Nor will multiple spaces in the original line, at least for the "fill" function. We also need to decide what to do if hspace/hscale, wordspace, and/or charspace come in with non-default values. For the simple text_justified(), do we just scale down all these settings (wordspace and charspace) until the line fits (only going to hspace/hscale as a last resort)? For text_fill_justified(), do we set them to 100%/0pt/0pt as our starting point, or do we try to accommodate user scaling and spacing requests as much as possible? Thoughts on this?
Subject: [rt.cpan.org #98546]
Date: Sun, 24 Jan 2016 11:54:57 -0500
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
By the way, to add a comment to this thread, just email bug-PDF-API2 [at] rt.cpan.org with subject line [rt.cpan.org #98546]. Note 1 space between org and #, and the [ ] around the whole subject. Nothing else. If you don't follow this format carefully, you will end up creating a new bug report! HTML formatting within the body does not work.
Subject: [rt.cpan.org #98546]
Date: Sun, 31 Jan 2016 12:35:57 -0500
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
Another thought on text_fill_justified(), when the line won't fit and needs to be compressed in some manner: first use a small negative charspace(), and then a small negative wordspace(). If more compression is needed, use hscale() to compress everything. The idea is to go to hscale only as a last resort, as it noticeably distorts letterforms (same with expansion to fill). We need to be careful to limit the charspace and wordspace amounts to some percentage of an em, so that letters (and even worse, words) don't touch. We also need to consider whether it would be better to temporarily zero-out existing charspace and wordspace (and hscale to 100%) as the starting point, or should we put the new settings on top of any existing ones?
Subject: [rt.cpan.org #98546]
Date: Sun, 31 Jan 2016 12:40:56 -0500
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
Note: that would be text_justified() when the line is too wide, and text_fill_justified() only when a word is not split (hyphenated) and is too wide to fit the space. Otherwise, for the "fill" version, you should never see the line having to be reduced in width.
FYI, this is fixed in PDF::Builder