1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# HG changeset patch
# User Jonathan Kew <jkew@mozilla.com>
# Date 1628081557 0
# Wed Aug 04 12:52:37 2021 +0000
# Node ID 2635200eb5ec6f6eff1ecd0fad1ef029f0b994af
# Parent 99c4916f4a924ede94aee9044fe3f753d2e2be2d
Bug 1892913 - patch 14 - Add cairo-quartz-surface named-destination support from bug 1722300 patch 3.
diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
@@ -2192,24 +2192,13 @@ static cairo_status_t
}
static cairo_int_status_t
-_cairo_quartz_surface_tag (void *abstract_surface,
- cairo_bool_t begin,
- const char *tag_name,
- const char *attributes,
- const cairo_pattern_t *source,
- const cairo_stroke_style_t *style,
- const cairo_matrix_t *ctm,
- const cairo_matrix_t *ctm_inverse,
- const cairo_clip_t *clip)
+_cairo_quartz_surface_link (cairo_quartz_surface_t *surface,
+ cairo_bool_t begin,
+ const char *attributes)
{
cairo_link_attrs_t link_attrs;
cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
int i, num_rects;
- cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
-
- /* Currently the only tag we support is "Link" */
- if (strcmp (tag_name, "Link"))
- return CAIRO_INT_STATUS_UNSUPPORTED;
/* We only process the 'begin' tag, and expect a rect attribute;
using the extents of the drawing operations enclosed by the begin/end
@@ -2223,11 +2212,24 @@ static cairo_int_status_t
num_rects = _cairo_array_num_elements (&link_attrs.rects);
if (num_rects > 0) {
- CFURLRef url = CFURLCreateWithBytes (NULL,
- (const UInt8 *) link_attrs.uri,
- strlen (link_attrs.uri),
- kCFStringEncodingUTF8,
- NULL);
+ /* Create either a named destination or a URL, depending which is present
+ in the link attributes. */
+ CFURLRef url = NULL;
+ CFStringRef name = NULL;
+ if (link_attrs.uri && *link_attrs.uri)
+ url = CFURLCreateWithBytes (NULL,
+ (const UInt8 *) link_attrs.uri,
+ strlen (link_attrs.uri),
+ kCFStringEncodingUTF8,
+ NULL);
+ else if (link_attrs.dest && *link_attrs.dest)
+ name = CFStringCreateWithBytes (kCFAllocatorDefault,
+ (const UInt8 *) link_attrs.dest,
+ strlen (link_attrs.dest),
+ kCFStringEncodingUTF8,
+ FALSE);
+ else /* silently ignore link that doesn't have a usable target */
+ goto cleanup;
for (i = 0; i < num_rects; i++) {
CGRect link_rect;
@@ -2241,12 +2243,19 @@ static cairo_int_status_t
rectf.width,
rectf.height);
- CGPDFContextSetURLForRect (surface->cgContext, url, link_rect);
+ if (url)
+ CGPDFContextSetURLForRect (surface->cgContext, url, link_rect);
+ else
+ CGPDFContextSetDestinationForRect (surface->cgContext, name, link_rect);
}
- CFRelease (url);
+ if (url)
+ CFRelease (url);
+ else
+ CFRelease (name);
}
+cleanup:
_cairo_array_fini (&link_attrs.rects);
free (link_attrs.dest);
free (link_attrs.uri);
@@ -2255,6 +2264,74 @@ static cairo_int_status_t
return status;
}
+static cairo_int_status_t
+_cairo_quartz_surface_dest (cairo_quartz_surface_t *surface,
+ cairo_bool_t begin,
+ const char *attributes)
+{
+ cairo_dest_attrs_t dest_attrs;
+ cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
+ double x = 0, y = 0;
+
+ /* We only process the 'begin' tag, and expect 'x' and 'y' attributes. */
+ if (!begin)
+ return status;
+
+ status = _cairo_tag_parse_dest_attributes (attributes, &dest_attrs);
+ if (unlikely (status))
+ return status;
+
+ if (unlikely (!dest_attrs.name || !strlen (dest_attrs.name)))
+ goto cleanup;
+
+ CFStringRef name = CFStringCreateWithBytes (kCFAllocatorDefault,
+ (const UInt8 *) dest_attrs.name,
+ strlen (dest_attrs.name),
+ kCFStringEncodingUTF8,
+ FALSE);
+
+ if (dest_attrs.x_valid)
+ x = dest_attrs.x;
+ if (dest_attrs.y_valid)
+ y = dest_attrs.y;
+
+ CGPDFContextAddDestinationAtPoint (surface->cgContext,
+ name,
+ CGPointMake (x, surface->extents.height - y));
+ CFRelease (name);
+
+cleanup:
+ free (dest_attrs.name);
+
+ return status;
+}
+
+static cairo_int_status_t
+_cairo_quartz_surface_tag (void *abstract_surface,
+ cairo_bool_t begin,
+ const char *tag_name,
+ const char *attributes,
+ const cairo_pattern_t *source,
+ const cairo_stroke_style_t *style,
+ const cairo_matrix_t *ctm,
+ const cairo_matrix_t *ctm_inverse,
+ const cairo_clip_t *clip)
+{
+ cairo_link_attrs_t link_attrs;
+ int i, num_rects;
+ cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
+
+ /* Currently the only tags we support are CAIRO_TAG_LINK and CAIRO_TAG_DEST */
+ if (!strcmp (tag_name, CAIRO_TAG_LINK))
+ return _cairo_quartz_surface_link (surface, begin, attributes);
+
+ if (!strcmp (tag_name, CAIRO_TAG_DEST))
+ return _cairo_quartz_surface_dest (surface, begin, attributes);
+
+ /* Unknown tag names are silently ignored here. */
+ return CAIRO_INT_STATUS_SUCCESS;
+}
+
// XXXtodo implement show_page; need to figure out how to handle begin/end
static const cairo_surface_backend_t cairo_quartz_surface_backend = {
|