@@ -250,6 +250,23 @@ def _datetime_to_pdf(d):
250
250
return r
251
251
252
252
253
+ def _get_link_annotation (gc , x , y , width , height ):
254
+ """
255
+ Create a link annotation object for embedding URLs.
256
+ """
257
+ link_annotation = {
258
+ 'Type' : Name ('Annot' ),
259
+ 'Subtype' : Name ('Link' ),
260
+ 'Rect' : (x , y , x + width , y + height ),
261
+ 'Border' : [0 , 0 , 0 ],
262
+ 'A' : {
263
+ 'S' : Name ('URI' ),
264
+ 'URI' : gc .get_url (),
265
+ },
266
+ }
267
+ return link_annotation
268
+
269
+
253
270
def pdfRepr (obj ):
254
271
"""Map Python objects to PDF syntax."""
255
272
@@ -2156,17 +2173,8 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
2156
2173
self ._text2path .mathtext_parser .parse (s , 72 , prop )
2157
2174
2158
2175
if gc .get_url () is not None :
2159
- link_annotation = {
2160
- 'Type' : Name ('Annot' ),
2161
- 'Subtype' : Name ('Link' ),
2162
- 'Rect' : (x , y , x + width , y + height ),
2163
- 'Border' : [0 , 0 , 0 ],
2164
- 'A' : {
2165
- 'S' : Name ('URI' ),
2166
- 'URI' : gc .get_url (),
2167
- },
2168
- }
2169
- self .file ._annotations [- 1 ][1 ].append (link_annotation )
2176
+ self .file ._annotations [- 1 ][1 ].append (_get_link_annotation (
2177
+ gc , x , y , width , height ))
2170
2178
2171
2179
fonttype = mpl .rcParams ['pdf.fonttype' ]
2172
2180
@@ -2222,17 +2230,8 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
2222
2230
page , = dvi
2223
2231
2224
2232
if gc .get_url () is not None :
2225
- link_annotation = {
2226
- 'Type' : Name ('Annot' ),
2227
- 'Subtype' : Name ('Link' ),
2228
- 'Rect' : (x , y , x + page .width , y + page .height ),
2229
- 'Border' : [0 , 0 , 0 ],
2230
- 'A' : {
2231
- 'S' : Name ('URI' ),
2232
- 'URI' : gc .get_url (),
2233
- },
2234
- }
2235
- self .file ._annotations [- 1 ][1 ].append (link_annotation )
2233
+ self .file ._annotations [- 1 ][1 ].append (_get_link_annotation (
2234
+ gc , x , y , page .width , page .height ))
2236
2235
2237
2236
# Gather font information and do some setup for combining
2238
2237
# characters into strings. The variable seq will contain a
@@ -2332,17 +2331,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2332
2331
if gc .get_url () is not None :
2333
2332
font .set_text (s )
2334
2333
width , height = font .get_width_height ()
2335
- link_annotation = {
2336
- 'Type' : Name ('Annot' ),
2337
- 'Subtype' : Name ('Link' ),
2338
- 'Rect' : (x , y , x + width / 64 , y + height / 64 ),
2339
- 'Border' : [0 , 0 , 0 ],
2340
- 'A' : {
2341
- 'S' : Name ('URI' ),
2342
- 'URI' : gc .get_url (),
2343
- },
2344
- }
2345
- self .file ._annotations [- 1 ][1 ].append (link_annotation )
2334
+ self .file ._annotations [- 1 ][1 ].append (_get_link_annotation (
2335
+ gc , x , y , width / 64 , height / 64 ))
2346
2336
2347
2337
# If fonttype is neither 3 nor 42, emit the whole string at once
2348
2338
# without manual kerning.
0 commit comments