MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / draw_text

Method draw_text

lib/matplotlib/backends/backend_pdf.py:2294–2389  ·  view source on GitHub ↗
(self, gc, x, y, s, prop, angle, ismath=False, mtext=None)

Source from the content-addressed store, hash-verified

2292 return s.encode(encoding, 'replace')
2293
2294 def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2295 # docstring inherited
2296
2297 # TODO: combine consecutive texts into one BT/ET delimited section
2298
2299 self.check_gc(gc, gc._rgb)
2300 if ismath:
2301 return self.draw_mathtext(gc, x, y, s, prop, angle)
2302
2303 fontsize = prop.get_size_in_points()
2304 if mtext is not None:
2305 features = mtext.get_fontfeatures()
2306 language = mtext.get_language()
2307 else:
2308 features = language = None
2309
2310 # For Type-1 fonts, emit the whole string at once without manual kerning.
2311 if mpl.rcParams['pdf.use14corefonts']:
2312 font = self._get_font_afm(prop)
2313 self.file.output(Op.begin_text,
2314 self.file.fontName(prop), fontsize, Op.selectfont)
2315 self._setup_textpos(x, y, angle)
2316 self.file.output(self.encode_string(s, fonttype=1),
2317 Op.show, Op.end_text)
2318
2319 # A sequence of characters is broken into multiple chunks. The chunking
2320 # serves two purposes:
2321 # - For Type 3 fonts, there is no way to access multibyte characters, as they
2322 # cannot have a CIDMap. Therefore, in this case we break the string into
2323 # chunks, where each chunk contains a string of consecutive 1-byte
2324 # characters in a 256-character subset of the font. A distinct version of
2325 # the original font is created for each 256-character subset.
2326 # - A sequence of characters is split into chunks to allow for kerning
2327 # adjustments between consecutive chunks.
2328 #
2329 # Each chunk is emitted with the regular text show command (TJ) with appropriate
2330 # kerning between chunks.
2331 else:
2332 font = self._get_font_ttf(prop)
2333 fonttype = mpl.rcParams['pdf.fonttype']
2334
2335 def output_singlebyte_chunk(kerns_or_chars):
2336 if not kerns_or_chars:
2337 return
2338 self.file.output(
2339 # See pdf spec "Text space details" for the 1000/fontsize
2340 # (aka. 1000/T_fs) factor.
2341 [(-1000 * next(group) / fontsize) if tp == float # a kern
2342 else self._encode_glyphs(group, fonttype)
2343 for tp, group in itertools.groupby(kerns_or_chars, type)],
2344 Op.showkern)
2345 kerns_or_chars.clear()
2346 # Do the rotation and global translation as a single matrix
2347 # concatenation up front
2348 self.file.output(Op.gsave)
2349 a = math.radians(angle)
2350 self.file.output(math.cos(a), math.sin(a),
2351 -math.sin(a), math.cos(a),

Callers

nothing calls this directly

Calls 15

check_gcMethod · 0.95
draw_mathtextMethod · 0.95
_setup_textposMethod · 0.95
encode_stringMethod · 0.95
FontPathClass · 0.90
_get_link_annotationFunction · 0.85
get_fontfeaturesMethod · 0.80
get_languageMethod · 0.80
_get_font_afmMethod · 0.80
outputMethod · 0.80
fontNameMethod · 0.80
_get_font_ttfMethod · 0.80

Tested by

no test coverage detected