Bug 707822: Take missing coordinates into account when creating link dest.
authorRobin Watts <[email protected]>
Tue, 11 Jun 2024 08:15:49 +0000 (09:15 +0100)
committerSebastian Rasmussen <[email protected]>
Tue, 11 Jun 2024 21:01:03 +0000 (23:01 +0200)
Previously if either coordinate was NaN, then after transformation
both coordinates would be NaN. But it is desired for given coordinates
to be transformed while missing coordinates are kept at NaN.

From an original patch by Sebastian.

source/pdf/pdf-link.c

index 60e015cd5fcb76451409045fbc492164e5772e9c..679cfa0053161b1d34ef8b1177b1bad42d937b06 100644 (file)
@@ -1256,7 +1256,26 @@ pdf_new_dest_from_link(fz_context *ctx, pdf_document *doc, const char *uri, int
                                        pdf_array_push_real(ctx, dest, p.x);
                                break;
                        case FZ_LINK_DEST_XYZ:
-                               p = fz_transform_point_xy(val.x, val.y, invctm);
+                               if (invctm.a == 0 && invctm.d == 0)
+                               {
+                                       /* Rotating by 90 or 270 degrees. */
+                                       p = fz_transform_point_xy(isnan(val.x) ? 0 : val.x, isnan(val.y) ? 0 : val.y, invctm);
+                                       if (isnan(val.x))
+                                               p.y = val.x;
+                                       if (isnan(val.y))
+                                               p.x = val.y;
+                               }
+                               else if (invctm.b == 0 && invctm.c == 0)
+                               {
+                                       /* No rotation, or 180 degrees. */
+                                       p = fz_transform_point_xy(isnan(val.x) ? 0 : val.x, isnan(val.y) ? 0 : val.y, invctm);
+                                       if (isnan(val.x))
+                                               p.x = val.x;
+                                       if (isnan(val.y))
+                                               p.y = val.y;
+                               }
+                               else
+                                       p = fz_transform_point_xy(val.x, val.y, invctm);
                                pdf_array_push(ctx, dest, PDF_NAME(XYZ));
                                if (isnan(p.x))
                                        pdf_array_push(ctx, dest, PDF_NULL);