Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering or logging in.

RT 98535 - nl(width) not working

  • 1 Replies
  • 981 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 437
    • View Profile
RT 98535 - nl(width) not working
« October 21, 2016, 03:19:49 PM »
Subject:    nl(width) not working
Date:    Tue, 02 Sep 2014 10:43:08 -0400
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Phil M Perry

PDF::API2 v2.022   Perl 5.16.3  Windows 7   severity: Important

From reading the POD and following the code, it appears that the intent of the nl($width) method is to go down to the next line ($self->lead points decrease y) and then indent by $width points. It appears to ignore $width. Thus, nl(width) = nl() = nl(0) = cr(), all of which produce the PDF command  T* .  I suggest that the code be changed to produce (when $width given)  $width $self->lead Td. This should not only go down to the next line (T*), but also move right (+x) by $width, which appears to be the intent of the method. I have not changed Content.pm or its POD yet.
#
Subject:    [rt.cpan.org #98535]
Date:    Sun, 24 Jan 2016 16:23:30 -0500
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Phil M Perry

Can anyone comment on whether I'm reading nl() correctly, and if my proposal is correct and won't break existing code? Thanks. Incidentally, a negative $width should produce an "outdent" (hanging first line).

I don't know why there are both nl() and cr() calls, as they do largely the same thing (see bug 98550). Perhaps any extension to functionality should be for one, and the other deprecated? The basic idea in both is to go down one line (OBJ->lead) and then adjust vertically (cr) or horizontally (nl). A good extension would be to go down or up some integral number of lines (lead value) and allow both vertical and horizontal (indent/outdent) adjustments. Something to keep track of going below the bottom margin and force a new page might also be useful.

Thoughts from the community?
#
Wed Feb 17 18:07:50 2016 steve [...] deefs.net - Correspondence added

$width is (was) an undocumented option to nl() that does (did) nothing.  I've removed it.

There's a separate command (distance) that can handle adding a newline, carriage return, and indent all at once.
#
Wed Feb 17 18:07:50 2016 The RT System itself - Status changed from 'new' to 'open'
#
Wed Feb 17 18:07:51 2016 steve [...] deefs.net - Status changed from 'open' to 'rejected'
#
Subject:    [rt.cpan.org #98535]
Date:    Thu, 18 Feb 2016 14:49:32 -0500
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Phil M Perry

How about the following POD entry? The alternative would be to restore, fix, and document the $width parameter. Or, given the distance() method, consider deprecating both cr() and nl(). Come to think of it, "distance" is a non-intuitive name for that method. Maybe it too should be deprecated and renamed crlf(deltaX, deltaY) or nextline(deltaX, deltaY)? They would be much more obvious.

Code: [Select]
=item $content->nl()

Moves to the start of the next line (carriage return, then down by current leading amount). It is equivalent to C<cr()>.

Use the C<distance()> method if you wish to go to the next line and adjust the position by horizontal and/or vertical amounts.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 437
    • View Profile
Re: RT 98535 - nl(width) not working
« Reply #1: November 18, 2016, 09:50:30 PM »
Fixed in 3.001

nl(indent) is now supported. Unlike other measurements (in points), this one needs to be in "units of text space", which works out to about 75 to 88 per em of width desired. It is therefore sensitive to the font size. A positive value indents (moves text right), while a negative value outdents (moves text left). A value of 0 acts like nl().

<Needs testing to determine exact (if fixed amount) units per em amount. It should be scaled per font, but who knows?>
« Last Edit: May 01, 2017, 11:07:43 AM by Phil »