Generate a png file containing latex's rendering of tex string. Return the file name.
(cls, tex, fontsize, dpi)
| 309 | |
| 310 | @classmethod |
| 311 | def make_png(cls, tex, fontsize, dpi): |
| 312 | """ |
| 313 | Generate a png file containing latex's rendering of tex string. |
| 314 | |
| 315 | Return the file name. |
| 316 | """ |
| 317 | pngpath = cls._get_base_path(tex, fontsize, dpi).with_suffix(".png") |
| 318 | if not pngpath.exists(): |
| 319 | dvipath = cls.make_dvi(tex, fontsize) |
| 320 | with TemporaryDirectory(dir=pngpath.parent) as tmpdir: |
| 321 | cmd = ["dvipng", "-bg", "Transparent", "-D", str(dpi), |
| 322 | "-T", "tight", "-o", "file.png", dvipath] |
| 323 | # When testing, disable FreeType rendering for reproducibility; |
| 324 | # but dvipng 1.16 has a bug (fixed in f3ff241) that breaks |
| 325 | # --freetype0 mode, so for it we keep FreeType enabled; the |
| 326 | # image will be slightly off. |
| 327 | if (getattr(mpl, "_called_from_pytest", False) and |
| 328 | mpl._get_executable_info("dvipng").raw_version != "1.16"): |
| 329 | cmd.insert(1, "--freetype0") |
| 330 | cls._run_checked_subprocess(cmd, tex, cwd=tmpdir) |
| 331 | Path(tmpdir, "file.png").replace(pngpath) |
| 332 | return str(pngpath) |
| 333 | |
| 334 | @classmethod |
| 335 | def get_grey(cls, tex, fontsize=None, dpi=None): |
no test coverage detected