(self, gc, x, y, s, prop, angle, *, mtext=None)
| 2199 | self.file.output(Op.grestore) |
| 2200 | |
| 2201 | def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None): |
| 2202 | # docstring inherited |
| 2203 | texmanager = self.get_texmanager() |
| 2204 | fontsize = prop.get_size_in_points() |
| 2205 | dvifile = texmanager.make_dvi(s, fontsize) |
| 2206 | with dviread.Dvi(dvifile, 72) as dvi: |
| 2207 | page, = dvi |
| 2208 | |
| 2209 | if gc.get_url() is not None: |
| 2210 | self.file._annotations[-1][1].append(_get_link_annotation( |
| 2211 | gc, x, y, page.width, page.height, angle)) |
| 2212 | |
| 2213 | # Gather font information and do some setup for combining |
| 2214 | # characters into strings. The variable seq will contain a |
| 2215 | # sequence of font and text entries. A font entry is a list |
| 2216 | # ['font', name, size] where name is a Name object for the |
| 2217 | # font. A text entry is ['text', x, y, glyphs, x+w] where x |
| 2218 | # and y are the starting coordinates, w is the width, and |
| 2219 | # glyphs is a list; in this phase it will always contain just |
| 2220 | # one single-character string, but later it may have longer |
| 2221 | # strings interspersed with kern amounts. |
| 2222 | oldfont, seq = None, [] |
| 2223 | for text in page.text: |
| 2224 | if text.font != oldfont: |
| 2225 | pdfname = self.file.dviFontName(text.font) |
| 2226 | seq += [['font', pdfname, text.font.size]] |
| 2227 | oldfont = text.font |
| 2228 | seq += [['text', text.x, text.y, [bytes([text.glyph])], text.x+text.width]] |
| 2229 | self.file._character_tracker.track_glyph(text.font, text.glyph, text.index) |
| 2230 | |
| 2231 | # Find consecutive text strings with constant y coordinate and |
| 2232 | # combine into a sequence of strings and kerns, or just one |
| 2233 | # string (if any kerns would be less than 0.1 points). |
| 2234 | i, curx, fontsize = 0, 0, None |
| 2235 | while i < len(seq)-1: |
| 2236 | elt, nxt = seq[i:i+2] |
| 2237 | if elt[0] == 'font': |
| 2238 | fontsize = elt[2] |
| 2239 | elif elt[0] == nxt[0] == 'text' and elt[2] == nxt[2]: |
| 2240 | offset = elt[4] - nxt[1] |
| 2241 | if abs(offset) < 0.1: |
| 2242 | elt[3][-1] += nxt[3][0] |
| 2243 | elt[4] += nxt[4]-nxt[1] |
| 2244 | else: |
| 2245 | elt[3] += [offset*1000.0/fontsize, nxt[3][0]] |
| 2246 | elt[4] = nxt[4] |
| 2247 | del seq[i+1] |
| 2248 | continue |
| 2249 | i += 1 |
| 2250 | |
| 2251 | # Create a transform to map the dvi contents to the canvas. |
| 2252 | mytrans = Affine2D().rotate_deg(angle).translate(x, y) |
| 2253 | |
| 2254 | # Output the text. |
| 2255 | self.check_gc(gc, gc._rgb) |
| 2256 | self.file.output(Op.begin_text) |
| 2257 | curx, cury, oldx, oldy = 0, 0, 0, 0 |
| 2258 | for elt in seq: |
nothing calls this directly
no test coverage detected