Bug 173726

Summary: mpage calculates page scaling incorrectly
Product: [Fedora] Fedora Reporter: redhat-bugs2eran
Component: mpageAssignee: Radek Vokál <rvokal>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 4   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 2.5.4-6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-02-09 10:52:54 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Patch to fix the reported problem none

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):
mpage-2.5.4-5

How reproducible:
Always

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