Bug 173726 - mpage calculates page scaling incorrectly
Summary: mpage calculates page scaling incorrectly
Alias: None
Product: Fedora
Classification: Fedora
Component: mpage
Version: 4
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Radek Vokal
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2005-11-19 18:35 UTC by redhat-bugs2eran
Modified: 2007-11-30 22:11 UTC (History)
0 users

Clone Of:
Last Closed: 2006-02-09 10:52:54 UTC

Attachments (Terms of Use)
Patch to fix the reported problem (1.24 KB, patch)
2005-11-19 18:37 UTC, redhat-bugs2eran
no flags Details | Diff

Description redhat-bugs2eran 2005-11-19 18:35:33 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.0.7-1.1.fc4 Firefox/1.0.7

Description of problem:
The '-M' option of mpage allows for changing the paper magins, and scales the input PostScript to fill the new margins. This calculation is done incorrectly, as acknowledged in the mpage(1) manpage: 

  "Very large values have funny effects.
   This is left as an exercise to the user."

Well, this user found the error: it lies in post.c lines 730-731 and 867-868. These lines compute the scaling factor as (WIDTH-MARGIN)/WIDTH, which incorrect since the margins are given in logical units (i.e., units of the input page rather than the output page), as explained in the manpage. Moreover, the left and bottom margins are handled by translation in logical units, so the current code is inconsistent any way you look at it.

Attached is a patch which fixes this, by calculating the ratio as WIDTH/(WIDTH+MARGIN). 

As a sanity check, consider the case WIDTH=MARGIN, which should shrink by a factor of 2 (and does with my formula), but with the current code shrinks to the content to zero size.

Compatibility-wise this sould be OK, since the old and new code give similar results for small margins, and for large margins the old code was broken and inconsistent anyway (as warned in the manpage). But I suggest changing the version number (add a suffix?), in case some applications (like mike) need to check for a good version.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Run 
$ mpage -1 -M500r /usr/share/doc/bash-3.0/bash.ps > out.ps && evince out.ps
and observe that the content is shrunk too much (as if the right margin is given in physical units instead of logical unit)

2. Run 
$ mpage -1 -M500l /usr/share/doc/bash-3.0/bash.ps > out.ps && evince out.ps
and observe that the left margin is determined correctly in logical units, but again the content is shrunk too much.

3. Run
page -1 -M300l300r /usr/share/doc/bash-3.0/bash.ps > out.ps && evince out.ps
and observe that the result is nonsensical.

Additional info:

Comment 1 redhat-bugs2eran 2005-11-19 18:37:45 UTC
Created attachment 121266 [details]
Patch to fix the reported problem

Note You need to log in before you can comment on or make changes to this bug.