@@ -2106,6 +2106,19 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
21062106 width , height , descent , glyphs , rects = \
21072107 self ._text2path .mathtext_parser .parse (s , 72 , prop )
21082108
2109+ if gc .get_url () is not None :
2110+ link_annotation = {
2111+ 'Type' : Name ('Annot' ),
2112+ 'Subtype' : Name ('Link' ),
2113+ 'Rect' : (x , y , x + width , y + height ),
2114+ 'Border' : [0 , 0 , 0 ],
2115+ 'A' : {
2116+ 'S' : Name ('URI' ),
2117+ 'URI' : gc .get_url (),
2118+ },
2119+ }
2120+ self .file ._annotations [- 1 ][1 ].append (link_annotation )
2121+
21092122 global_fonttype = mpl .rcParams ['pdf.fonttype' ]
21102123
21112124 # Set up a global transformation matrix for the whole math expression
@@ -2162,6 +2175,19 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
21622175 with dviread .Dvi (dvifile , 72 ) as dvi :
21632176 page , = dvi
21642177
2178+ if gc .get_url () is not None :
2179+ link_annotation = {
2180+ 'Type' : Name ('Annot' ),
2181+ 'Subtype' : Name ('Link' ),
2182+ 'Rect' : (x , y , x + page .width , y + page .height ),
2183+ 'Border' : [0 , 0 , 0 ],
2184+ 'A' : {
2185+ 'S' : Name ('URI' ),
2186+ 'URI' : gc .get_url (),
2187+ },
2188+ }
2189+ self .file ._annotations [- 1 ][1 ].append (link_annotation )
2190+
21652191 # Gather font information and do some setup for combining
21662192 # characters into strings. The variable seq will contain a
21672193 # sequence of font and text entries. A font entry is a list
@@ -2261,6 +2287,21 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
22612287 if is_opentype_cff_font (font .fname ):
22622288 fonttype = 42
22632289
2290+ if gc .get_url () is not None :
2291+ font .set_text (s )
2292+ width , height = font .get_width_height ()
2293+ link_annotation = {
2294+ 'Type' : Name ('Annot' ),
2295+ 'Subtype' : Name ('Link' ),
2296+ 'Rect' : (x , y , x + width / 64 , y + height / 64 ),
2297+ 'Border' : [0 , 0 , 0 ],
2298+ 'A' : {
2299+ 'S' : Name ('URI' ),
2300+ 'URI' : gc .get_url (),
2301+ },
2302+ }
2303+ self .file ._annotations [- 1 ][1 ].append (link_annotation )
2304+
22642305 # If fonttype != 3 or there are no multibyte characters, emit the whole
22652306 # string at once.
22662307 if fonttype != 3 or all (ord (char ) <= 255 for char in s ):
0 commit comments