@@ -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
@@ -2154,17 +2171,8 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
2154
2171
self ._text2path .mathtext_parser .parse (s , 72 , prop )
2155
2172
2156
2173
if gc .get_url () is not None :
2157
- link_annotation = {
2158
- 'Type' : Name ('Annot' ),
2159
- 'Subtype' : Name ('Link' ),
2160
- 'Rect' : (x , y , x + width , y + height ),
2161
- 'Border' : [0 , 0 , 0 ],
2162
- 'A' : {
2163
- 'S' : Name ('URI' ),
2164
- 'URI' : gc .get_url (),
2165
- },
2166
- }
2167
- self .file ._annotations [- 1 ][1 ].append (link_annotation )
2174
+ self .file ._annotations [- 1 ][1 ].append (_get_link_annotation (
2175
+ gc , x , y , width , height ))
2168
2176
2169
2177
fonttype = mpl .rcParams ['pdf.fonttype' ]
2170
2178
@@ -2220,17 +2228,8 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
2220
2228
page , = dvi
2221
2229
2222
2230
if gc .get_url () is not None :
2223
- link_annotation = {
2224
- 'Type' : Name ('Annot' ),
2225
- 'Subtype' : Name ('Link' ),
2226
- 'Rect' : (x , y , x + page .width , y + page .height ),
2227
- 'Border' : [0 , 0 , 0 ],
2228
- 'A' : {
2229
- 'S' : Name ('URI' ),
2230
- 'URI' : gc .get_url (),
2231
- },
2232
- }
2233
- self .file ._annotations [- 1 ][1 ].append (link_annotation )
2231
+ self .file ._annotations [- 1 ][1 ].append (_get_link_annotation (
2232
+ gc , x , y , page .width , page .height ))
2234
2233
2235
2234
# Gather font information and do some setup for combining
2236
2235
# characters into strings. The variable seq will contain a
@@ -2330,17 +2329,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2330
2329
if gc .get_url () is not None :
2331
2330
font .set_text (s )
2332
2331
width , height = font .get_width_height ()
2333
- link_annotation = {
2334
- 'Type' : Name ('Annot' ),
2335
- 'Subtype' : Name ('Link' ),
2336
- 'Rect' : (x , y , x + width / 64 , y + height / 64 ),
2337
- 'Border' : [0 , 0 , 0 ],
2338
- 'A' : {
2339
- 'S' : Name ('URI' ),
2340
- 'URI' : gc .get_url (),
2341
- },
2342
- }
2343
- self .file ._annotations [- 1 ][1 ].append (link_annotation )
2332
+ self .file ._annotations [- 1 ][1 ].append (_get_link_annotation (
2333
+ gc , x , y , width / 64 , height / 64 ))
2344
2334
2345
2335
# If fonttype is neither 3 nor 42, emit the whole string at once
2346
2336
# without manual kerning.
0 commit comments