Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

PDF and PS output issues #1273

Open
daewok opened this issue Mar 2, 2022 · 5 comments
Open

PDF and PS output issues #1273

daewok opened this issue Mar 2, 2022 · 5 comments

Comments

@daewok
Copy link
Contributor

daewok commented Mar 2, 2022

I think this is likely several separate bugs, but I'm not sure the best way to break them apart. All of these tests were done using #1269. GitHub isn't letting me upload .ps files, so you'll have to run the example to fully compare.

  1. Both the PDF and PS backends have issues drawing rounded shapes. The PDF backend seems to draw the bottom right corner the wrong direction. The PS backend seems to relocate the rounded corners to the center of the shape. Compare (sorry, it's a transparent png...) mcclim-graph.png
    to mcclim-graph-not-scaled.pdf and mcclim-graph-not-scaled.ps.
  2. The PDF backend may not display all text unless :scale-to-fit t. Compare mcclim-graph-truncated.pdf to mcclim-graph-truncated-scaled.pdf.
  3. The PS backend doesn't scale to fit correctly. See mcclim-graph-scaled.ps.
  4. The PS backend stops displaying text at the same point the PDF backend seems to, but :scale-to-fit t doesn't fix it. Compare mcclim-graph-truncated-scaled.ps and mcclim-graph-truncated.ps.

Code:

(defparameter *simple-graph*
  '((s1 10 2)
    (s8 9)
    (s24 27 25)
    (s30 31 33)
    (s35 36 43)
    (2 3 16 17 t1 18)
    (3 4)
    (4 5)
    (5 6 t35 23)
    (6 7)
    (7 t8)
    (9 42 t1)
    (10 11 14 t1 13 12)
    (11 4)
    (12 29)
    (13 19)
    (14 15)
    (15 t1)
    (16 15)
    (17 19)
    (18 29)
    (19 21 20 28)
    (20 15)
    (21 22)
    (22 23 t35)
    (23 t24 t1)
    (25 t1 26)
    (26 4)
    (27 t24)
    (28 29)
    (29 t30)
    (31 t1 32)
    (32 23)
    (33 t30 34)
    (34 29)
    (36 19)
    (37 39 41 38 40)
    (38 4)
    (39 15)
    (40 19)
    (41 29)
    (42 4)
    (43 38 40))
  "Figure 1-2b from \"A Technique for Drawing Directed Graphs\" by Emden
R. Gansner, Eleftherios Koutsofios, Stephen C. North, Kiem-phong Vo")

(defun format-graph (graph stream &optional (roots '(s8 s24 37 s35 s1 s30)))
  (clim:format-graph-from-roots
   roots
   (lambda (obj stream)
     (clim:surrounding-output-with-border (stream :shape :rounded)
       (princ obj stream)))
   (lambda (obj)
     (cdr (assoc obj graph)))
   :stream stream
   :maximize-generations t
   :orientation :vertical
   :graph-type :digraph
   :merge-duplicates t))

(clim-extensions:with-output-to-drawing-stream (s :pdf "/tmp/mcclim-graph-not-scaled.pdf")
  (format-graph *simple-graph* s))

(clim-extensions:with-output-to-drawing-stream (s :pdf "/tmp/mcclim-graph-truncated.pdf")
  (format-graph *simple-graph* s '(s8 s24 s30)))

(clim-extensions:with-output-to-drawing-stream (s :pdf "/tmp/mcclim-graph-truncated-scaled.pdf" :scale-to-fit t)
  (format-graph *simple-graph* s '(s8 s24 s30)))

(clim-extensions:with-output-to-drawing-stream (s :pdf "/tmp/mcclim-graph-scaled.pdf" :scale-to-fit t)
  (format-graph *simple-graph* s))

(clim-extensions:with-output-to-drawing-stream (s :ps "/tmp/mcclim-graph-not-scaled.ps")
  (format-graph *simple-graph* s))

(clim-extensions:with-output-to-drawing-stream (s :ps "/tmp/mcclim-graph-truncated.ps")
  (format-graph *simple-graph* s '(s8 s24 s30)))

(clim-extensions:with-output-to-drawing-stream (s :ps "/tmp/mcclim-graph-truncated-scaled.ps" :scale-to-fit t)
  (format-graph *simple-graph* s '(s8 s24 s30)))

(clim-extensions:with-output-to-drawing-stream (s :ps "/tmp/mcclim-graph-scaled.ps" :scale-to-fit t)
  (format-graph *simple-graph* s))

(clim-extensions:with-output-to-drawing-stream (s :raster "/tmp/mcclim-graph.png")
  (format-graph *simple-graph* s))
@dkochmanski
Copy link
Member

simpler test case for rounded corners.

(defun draw-test (stream)
  (loop for alpha from 0 by (/ pi 2)
        for beta from (/ pi 2) by (/ pi 2)
        for y from 50 by 75
        for ink in (list +red+ +green+ +blue+ +deep-pink+) do
          (with-drawing-options (stream :ink ink)
            (medium-draw-ellipse* stream 50 y 25 0 0 25 alpha beta nil))))

(progn
  (clim-extensions:with-output-to-drawing-stream (s :ps "/tmp/this-test.ps")
    (draw-test s))
  (uiop:run-program "xdg-open /tmp/this-test.ps"))

(progn
  (clim-extensions:with-output-to-drawing-stream (s :pdf "/tmp/this-test.pdf")
    (draw-test s))
  (uiop:run-program "xdg-open /tmp/this-test.pdf"))

(clim-extensions:with-output-to-drawing-stream (s :svg "/tmp/this-test.svg" :preview t)
  (draw-test s))

@dkochmanski
Copy link
Member

I've solved the rounded shapes issue locally. one was due to the angle normalization, another one because of a naive handedness fixup in the postscript backend.

@dkochmanski
Copy link
Member

the issue with fitting is /probably/ because font metrics are botched and bounding rectangles of text records are miscomputed. both ps and pdf use the same font metric code, so that makes this suspicion even more plausible. if we replay +everywhere+ instead of the rectangle in question (even when fit-to-scale is not present), then output shows correctly.

dkochmanski added a commit that referenced this issue Mar 25, 2022
The previous approach was a little naive because it assumed that changing signs
will solve the handedness problem. We need to properly untransform regions.

Partially addresses #1273.
dkochmanski added a commit that referenced this issue Mar 25, 2022
The function normalize angle returned (0,0) when END-ANGLE was smaller than
START-ANGLE. This is not corect, consider:

start-angle: pi
end-angle:   pi/2

Then we want to draw an ellipse that takes three quaters of the ellipse
excluding the second one (CCW). This commit removes that constraint.

Partially addresses #1273.
dkochmanski added a commit that referenced this issue Mar 25, 2022
The previous approach was a little naive because it assumed that changing signs
will solve the handedness problem. We need to properly untransform regions.

Partially addresses #1273.
dkochmanski added a commit that referenced this issue Mar 25, 2022
The function normalize angle returned (0,0) when END-ANGLE was smaller than
START-ANGLE. This is not corect, consider:

start-angle: pi
end-angle:   pi/2

Then we want to draw an ellipse that takes three quaters of the ellipse
excluding the second one (CCW). This commit removes that constraint.

Partially addresses #1273.
dkochmanski added a commit that referenced this issue Mar 28, 2022
Previously the code assumed that a MEDIUM-TRANSFORMATION is always the
+IDENTITY-TRANSFORMATION+. This does not hold for records that are subclasses of
the GS-TRANSFORMATION-MIXIN (most notably DRAW-TEXT-OUTPUT-RECORD).

Fixes #1273.
dkochmanski added a commit that referenced this issue Mar 28, 2022
The function normalize angle returned (0,0) when END-ANGLE was smaller than
START-ANGLE. This is not corect, consider:

start-angle: pi
end-angle:   pi/2

Then we want to draw an ellipse that takes three quaters of the ellipse
excluding the second one (CCW). This commit removes that constraint.

Partially addresses #1273.
@dkochmanski
Copy link
Member

@daewok please check the drawing-backends branch whether everything works (it seems to!).

dkochmanski added a commit that referenced this issue Mar 29, 2022
The previous approach was a little naive because it assumed that changing signs
will solve the handedness problem. We need to properly untransform regions.

Partially addresses #1273.
dkochmanski added a commit that referenced this issue Mar 29, 2022
The function normalize angle returned (0,0) when END-ANGLE was smaller than
START-ANGLE. This is not corect, consider:

start-angle: pi
end-angle:   pi/2

Then we want to draw an ellipse that takes three quaters of the ellipse
excluding the second one (CCW). This commit removes that constraint.

Partially addresses #1273.
@daewok
Copy link
Contributor Author

daewok commented Apr 8, 2022

Most everything works! Only issue I still see is that this:

(clim-extensions:with-output-to-drawing-stream (s :ps "/tmp/mcclim-graph-scaled.ps" :scale-to-fit t)
  (format-graph *simple-graph* s))

results in an image that seems to be scaled appropriately, but everything that would be off the page if not scaled is missing.

@dkochmanski dkochmanski reopened this Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants