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?