New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSDraw.rectangle produces incorrect PostScript #6428
Comments
Thanks for figuring out the solution. I've created PR #6429 to resolve this. |
There's some clarification that you could add to the docs and the docstring: it draws a solid black rectangle, and the box parameter is (left, top, width, height). Note that the height goes downwards even though the origin on the page is at the bottom-left. Oh, and FTR: the Python code uses "%d", so it truncates to int points (1/72 inch), but PostScript is OK with decimal places. |
Would it be simpler then to think of the parameters as (left, bottom, width, height)? I've added that to the PR.
Is there any documentation that you know of that states that? |
If you tried As for reals (as PostScript calls them, Python calls them floats), it's in PostScript's specification. Will anyone notice if snaps to 1/72 inch? That's not my decision! :-) If you do want to have (left, bottom, width, height), alter this bit of PostScript from:
to:
|
Rather than changing the PostScript code, I've pushed a change to the PR to add the bottom and height parameters together internally. |
You'd also need to negate the height because, currently, the height goes downwards (the PostScript code negates it to make it go downwards). IMHO, tweaking the PostScript makes more sense - it's a smaller change (moving a |
I've updated the PR to match your suggestion. As an aside, is there any reason that we couldn't also change
to
? |
I've realised that what I said about negating the height was wrong. However, my argument still stands. The fact that PostScript puts the origin at the bottom-left, and that the docs for PSDraw state that the origin is at the bottom-left, means that having the height go downwards can lead to confusion, as it did for me! As for the code, the 100 div # Convert the grey level from a percentage I'd probably leave it as it is for the time being, unless you're not happy about giving the grey level as a percentage (I'm thinking about future improvements where you might want to let the user set the fill colour - would a percentage be more friendly than a fraction?). |
I was thinking that if it is always zero, then dividing it by 100 doesn't do anything. And there's no need to set it back to black if it is already black. |
As I said, in the future you might want to let the user set the grey level for the fill. but if it's a case of YAGNI, then OK. |
This code should draw a rectangle, but it produces a blank page:
I inspected the PostScript that it produced and it didn't make a whole lot of sense to me (I've worked with it in the past) until I realised that the parameters on the PostScript stack were in the wrong order.
The PostScript says "72 288 M 216 144 0 Vr" when it should say "72 288 M 0 216 144 Vr", i.e. it's "
left
top
Mwidth
height
0 Vr" instead of "left
top
M 0width
height
Vr".When I edited the PostScript, I got the expected result.
The text was updated successfully, but these errors were encountered: