From 3fb9d0765f6427c8d4e221e932e97eeb937bb5ef Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 29 Jan 2020 01:20:32 +0100 Subject: [PATCH] Slightly improve output of dvi debug utilities, and tiny cleanups. New output of `python -mmatplotlib.dviread /path/to/dvi` for `$\frac{1}{2}$`: ``` === new page === (w: 261235, h: 553676, d: 225994) font: 'cmr7' scale: 0.4375 x y glyph chr w (glyphs) 1061683 1183756 49 1 261235 1061683 1667786 50 2 261235 x y w h (boxes) 1061683 1291058 26213 261235 ``` old output: ``` === new page === font b'cmr7' scaled 0.4375 1061683 1183756 49 1 261235 1061683 1667786 50 2 261235 1061683 1291058 BOX 26213 261235 ``` --- lib/matplotlib/dviread.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index 06d86dcbde0a..90c14a9fbbc4 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -259,8 +259,8 @@ def _output(self): for elt in self.text + self.boxes: if isinstance(elt, Box): x, y, h, w = elt - e = 0 # zero depth - else: # glyph + e = 0 # zero depth + else: # glyph x, y, font, g, w = elt h, e = font._height_depth_of(g) minx = min(minx, x) @@ -1044,14 +1044,19 @@ def _fontfile(cls, suffix, texname): with Dvi(args.filename, args.dpi) as dvi: fontmap = PsfontsMap(find_tex_file('pdftex.map')) for page in dvi: - print('=== new page ===') + print(f"=== new page === " + f"(w: {page.width}, h: {page.height}, d: {page.descent})") for font, group in itertools.groupby( page.text, lambda text: text.font): - print('font', font.texname, 'scaled', font._scale / 2 ** 20) + print(f"font: {font.texname.decode('latin-1')!r}\t" + f"scale: {font._scale / 2 ** 20}") + print("x", "y", "glyph", "chr", "w", "(glyphs)", sep="\t") for text in group: print(text.x, text.y, text.glyph, chr(text.glyph) if chr(text.glyph).isprintable() else ".", - text.width) - for x, y, w, h in page.boxes: - print(x, y, 'BOX', w, h) + text.width, sep="\t") + if page.boxes: + print("x", "y", "w", "h", "", "(boxes)", sep="\t") + for x, y, w, h in page.boxes: + print(x, y, w, h, sep="\t")