matplotlib-rs 0.0.8__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/releases/0.0.1.md +268 -0
- docs/releases/0.0.2.md +69 -0
- docs/releases/0.0.3.md +80 -0
- docs/releases/0.0.4.md +73 -0
- docs/releases/0.0.5.md +24 -0
- docs/releases/0.0.6.md +24 -0
- docs/releases/0.0.7.md +24 -0
- docs/releases/0.0.8.md +16 -0
- licenses/LICENSE_CONTOURPY +29 -0
- licenses/LICENSE_CYCLER +27 -0
- licenses/LICENSE_DATEUTIL +54 -0
- licenses/LICENSE_KIWISOLVER +71 -0
- licenses/LICENSE_LIBWEBP +56 -0
- licenses/LICENSE_MATPLOTLIB +1253 -0
- licenses/LICENSE_PYPARSING +20 -0
- licenses/LICENSE_QHULL +39 -0
- licenses/LICENSE_SIX +18 -0
- matplotlib_rs/__init__.py +1683 -0
- matplotlib_rs/__main__.py +27 -0
- matplotlib_rs/_afm.py +500 -0
- matplotlib_rs/_animation_data.py +263 -0
- matplotlib_rs/_api/__init__.py +495 -0
- matplotlib_rs/_api/deprecation.py +534 -0
- matplotlib_rs/_axis_py.py +2991 -0
- matplotlib_rs/_blocking_input.py +31 -0
- matplotlib_rs/_cm.py +1500 -0
- matplotlib_rs/_cm_bivar.py +1289 -0
- matplotlib_rs/_cm_listed.py +2848 -0
- matplotlib_rs/_cm_multivar.py +167 -0
- matplotlib_rs/_color_data.py +1142 -0
- matplotlib_rs/_colormap.py +132 -0
- matplotlib_rs/_constrained_layout.py +825 -0
- matplotlib_rs/_contour.py +108 -0
- matplotlib_rs/_doc_cache.py +12214 -0
- matplotlib_rs/_docstring.py +142 -0
- matplotlib_rs/_enums.py +178 -0
- matplotlib_rs/_figure_rs.py +294 -0
- matplotlib_rs/_fontconfig_pattern.py +129 -0
- matplotlib_rs/_foreign.py +220 -0
- matplotlib_rs/_hook.py +94 -0
- matplotlib_rs/_image.py +160 -0
- matplotlib_rs/_imageio.py +229 -0
- matplotlib_rs/_internal_utils.py +65 -0
- matplotlib_rs/_kiwi.py +484 -0
- matplotlib_rs/_layoutgrid.py +549 -0
- matplotlib_rs/_live.py +192 -0
- matplotlib_rs/_mathtext.py +3103 -0
- matplotlib_rs/_mathtext_data.py +1811 -0
- matplotlib_rs/_mplrs.cp313-win_amd64.pyd +0 -0
- matplotlib_rs/_path.py +25 -0
- matplotlib_rs/_png.py +162 -0
- matplotlib_rs/_pylab_helpers.py +137 -0
- matplotlib_rs/_qhull.py +66 -0
- matplotlib_rs/_rcpush.py +84 -0
- matplotlib_rs/_spines_rs.py +108 -0
- matplotlib_rs/_style_helpers.py +52 -0
- matplotlib_rs/_text_helpers.py +51 -0
- matplotlib_rs/_tight_bbox.py +85 -0
- matplotlib_rs/_tight_layout.py +302 -0
- matplotlib_rs/_tri.py +140 -0
- matplotlib_rs/_type1font.py +1228 -0
- matplotlib_rs/_vendor/__init__.py +8 -0
- matplotlib_rs/_vendor/cycler.py +574 -0
- matplotlib_rs/_vendor/dateutil/__init__.py +27 -0
- matplotlib_rs/_vendor/dateutil/_common.py +44 -0
- matplotlib_rs/_vendor/dateutil/_tzdata_impl.py +148 -0
- matplotlib_rs/_vendor/dateutil/_version.py +5 -0
- matplotlib_rs/_vendor/dateutil/easter.py +90 -0
- matplotlib_rs/_vendor/dateutil/parser/__init__.py +62 -0
- matplotlib_rs/_vendor/dateutil/parser/_parser.py +1614 -0
- matplotlib_rs/_vendor/dateutil/parser/isoparser.py +417 -0
- matplotlib_rs/_vendor/dateutil/relativedelta.py +597 -0
- matplotlib_rs/_vendor/dateutil/rrule.py +1765 -0
- matplotlib_rs/_vendor/dateutil/tz/__init__.py +61 -0
- matplotlib_rs/_vendor/dateutil/tz/_common.py +420 -0
- matplotlib_rs/_vendor/dateutil/tz/_factories.py +81 -0
- matplotlib_rs/_vendor/dateutil/tz/_tzfile.py +1429 -0
- matplotlib_rs/_vendor/dateutil/tz/_tzpath.py +105 -0
- matplotlib_rs/_vendor/dateutil/tz/tz.py +1473 -0
- matplotlib_rs/_vendor/dateutil/tz/win.py +371 -0
- matplotlib_rs/_vendor/dateutil/tzwin.py +3 -0
- matplotlib_rs/_vendor/dateutil/utils.py +72 -0
- matplotlib_rs/_vendor/dateutil/zoneinfo/__init__.py +234 -0
- matplotlib_rs/_vendor/pyparsing/__init__.py +414 -0
- matplotlib_rs/_vendor/pyparsing/actions.py +265 -0
- matplotlib_rs/_vendor/pyparsing/common.py +571 -0
- matplotlib_rs/_vendor/pyparsing/core.py +6973 -0
- matplotlib_rs/_vendor/pyparsing/exceptions.py +354 -0
- matplotlib_rs/_vendor/pyparsing/helpers.py +1770 -0
- matplotlib_rs/_vendor/pyparsing/results.py +929 -0
- matplotlib_rs/_vendor/pyparsing/testing.py +399 -0
- matplotlib_rs/_vendor/pyparsing/unicode.py +357 -0
- matplotlib_rs/_vendor/pyparsing/util.py +515 -0
- matplotlib_rs/_vendor/pyparsing/warnings.py +11 -0
- matplotlib_rs/_vendor/six.py +1004 -0
- matplotlib_rs/animation.py +1843 -0
- matplotlib_rs/artist.py +2302 -0
- matplotlib_rs/axes/__init__.py +19 -0
- matplotlib_rs/axes/_axes.py +9402 -0
- matplotlib_rs/axes/_bar.py +185 -0
- matplotlib_rs/axes/_base.py +5236 -0
- matplotlib_rs/axes/_base_rs.py +727 -0
- matplotlib_rs/axes/_boxplot.py +391 -0
- matplotlib_rs/axes/_hist.py +99 -0
- matplotlib_rs/axes/_secondary_axes.py +357 -0
- matplotlib_rs/axis.py +1963 -0
- matplotlib_rs/backend_bases.py +3760 -0
- matplotlib_rs/backend_managers.py +388 -0
- matplotlib_rs/backend_tools.py +1002 -0
- matplotlib_rs/backends/__init__.py +6 -0
- matplotlib_rs/backends/_backend_pdf_ps.py +451 -0
- matplotlib_rs/backends/backend_agg.py +552 -0
- matplotlib_rs/backends/backend_mixed.py +123 -0
- matplotlib_rs/backends/backend_pdf.py +2711 -0
- matplotlib_rs/backends/backend_pgf.py +1031 -0
- matplotlib_rs/backends/backend_ps.py +1491 -0
- matplotlib_rs/backends/backend_svg.py +1395 -0
- matplotlib_rs/backends/backend_template.py +214 -0
- matplotlib_rs/backends/registry.py +423 -0
- matplotlib_rs/bezier.py +691 -0
- matplotlib_rs/category.py +236 -0
- matplotlib_rs/cbook.py +2762 -0
- matplotlib_rs/cm.py +251 -0
- matplotlib_rs/collections.py +2711 -0
- matplotlib_rs/colorbar.py +1586 -0
- matplotlib_rs/colorizer.py +909 -0
- matplotlib_rs/colors.py +4278 -0
- matplotlib_rs/container.py +256 -0
- matplotlib_rs/contour.py +1756 -0
- matplotlib_rs/dates.py +1847 -0
- matplotlib_rs/dviread.py +1386 -0
- matplotlib_rs/figure.py +3815 -0
- matplotlib_rs/font_manager.py +1855 -0
- matplotlib_rs/ft2font.py +515 -0
- matplotlib_rs/gridspec.py +808 -0
- matplotlib_rs/hatch.py +244 -0
- matplotlib_rs/image.py +1863 -0
- matplotlib_rs/inset.py +291 -0
- matplotlib_rs/layout_engine.py +310 -0
- matplotlib_rs/legend.py +1480 -0
- matplotlib_rs/legend_handler.py +812 -0
- matplotlib_rs/lines.py +1886 -0
- matplotlib_rs/markers.py +908 -0
- matplotlib_rs/mathtext.py +141 -0
- matplotlib_rs/mlab.py +959 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-BoldOblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Oblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansDisplay.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Bold.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-BoldOblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Oblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Bold.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-BoldItalic.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Italic.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerifDisplay.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/LICENSE_DEJAVU +99 -0
- matplotlib_rs/mpl-data/fonts/ttf/LICENSE_STIX +124 -0
- matplotlib_rs/mpl-data/fonts/ttf/LastResortHE-Regular.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneral.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBolIta.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralItalic.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUni.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBolIta.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniIta.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizFiveSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmb10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmex10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmmi10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmr10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmss10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmsy10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmti10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmtt10.ttf +0 -0
- matplotlib_rs/mpl-data/images/back-symbolic.svg +46 -0
- matplotlib_rs/mpl-data/images/back.pdf +0 -0
- matplotlib_rs/mpl-data/images/back.png +0 -0
- matplotlib_rs/mpl-data/images/back.svg +46 -0
- matplotlib_rs/mpl-data/images/back_large.png +0 -0
- matplotlib_rs/mpl-data/images/filesave-symbolic.svg +68 -0
- matplotlib_rs/mpl-data/images/filesave.pdf +72 -0
- matplotlib_rs/mpl-data/images/filesave.png +0 -0
- matplotlib_rs/mpl-data/images/filesave.svg +68 -0
- matplotlib_rs/mpl-data/images/filesave_large.png +0 -0
- matplotlib_rs/mpl-data/images/forward-symbolic.svg +46 -0
- matplotlib_rs/mpl-data/images/forward.pdf +0 -0
- matplotlib_rs/mpl-data/images/forward.png +0 -0
- matplotlib_rs/mpl-data/images/forward.svg +46 -0
- matplotlib_rs/mpl-data/images/forward_large.png +0 -0
- matplotlib_rs/mpl-data/images/hand.pdf +0 -0
- matplotlib_rs/mpl-data/images/hand.png +0 -0
- matplotlib_rs/mpl-data/images/hand.svg +130 -0
- matplotlib_rs/mpl-data/images/help-symbolic.svg +52 -0
- matplotlib_rs/mpl-data/images/help.pdf +71 -0
- matplotlib_rs/mpl-data/images/help.png +0 -0
- matplotlib_rs/mpl-data/images/help.svg +52 -0
- matplotlib_rs/mpl-data/images/help_large.png +0 -0
- matplotlib_rs/mpl-data/images/home-symbolic.svg +59 -0
- matplotlib_rs/mpl-data/images/home.pdf +0 -0
- matplotlib_rs/mpl-data/images/home.png +0 -0
- matplotlib_rs/mpl-data/images/home.svg +59 -0
- matplotlib_rs/mpl-data/images/home_large.png +0 -0
- matplotlib_rs/mpl-data/images/matplotlib.pdf +0 -0
- matplotlib_rs/mpl-data/images/matplotlib.png +0 -0
- matplotlib_rs/mpl-data/images/matplotlib.svg +3171 -0
- matplotlib_rs/mpl-data/images/matplotlib_large.png +0 -0
- matplotlib_rs/mpl-data/images/move-symbolic.svg +73 -0
- matplotlib_rs/mpl-data/images/move.pdf +0 -0
- matplotlib_rs/mpl-data/images/move.png +0 -0
- matplotlib_rs/mpl-data/images/move.svg +73 -0
- matplotlib_rs/mpl-data/images/move_large.png +0 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options.pdf +0 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options.png +0 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options.svg +48 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options_large.png +0 -0
- matplotlib_rs/mpl-data/images/subplots-symbolic.svg +81 -0
- matplotlib_rs/mpl-data/images/subplots.pdf +0 -0
- matplotlib_rs/mpl-data/images/subplots.png +0 -0
- matplotlib_rs/mpl-data/images/subplots.svg +81 -0
- matplotlib_rs/mpl-data/images/subplots_large.png +0 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect-symbolic.svg +40 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect.pdf +69 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect.png +0 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect.svg +40 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect_large.png +0 -0
- matplotlib_rs/mpl-data/kpsewhich.lua +4 -0
- matplotlib_rs/mpl-data/matplotlibrc +849 -0
- matplotlib_rs/mpl-data/plot_directive/plot_directive.css +16 -0
- matplotlib_rs/mpl-data/sample_data/Minduka_Present_Blue_Pack.png +0 -0
- matplotlib_rs/mpl-data/sample_data/README.txt +2 -0
- matplotlib_rs/mpl-data/sample_data/Stocks.csv +526 -0
- matplotlib_rs/mpl-data/sample_data/axes_grid/bivariate_normal.npy +0 -0
- matplotlib_rs/mpl-data/sample_data/data_x_x2_x3.csv +11 -0
- matplotlib_rs/mpl-data/sample_data/eeg.dat +0 -0
- matplotlib_rs/mpl-data/sample_data/embedding_in_wx3.xrc +65 -0
- matplotlib_rs/mpl-data/sample_data/goog.npz +0 -0
- matplotlib_rs/mpl-data/sample_data/grace_hopper.jpg +0 -0
- matplotlib_rs/mpl-data/sample_data/jacksboro_fault_dem.npz +0 -0
- matplotlib_rs/mpl-data/sample_data/logo2.png +0 -0
- matplotlib_rs/mpl-data/sample_data/membrane.dat +0 -0
- matplotlib_rs/mpl-data/sample_data/msft.csv +66 -0
- matplotlib_rs/mpl-data/sample_data/s1045.ima.gz +0 -0
- matplotlib_rs/mpl-data/sample_data/topobathy.npz +0 -0
- matplotlib_rs/mpl-data/stylelib/Solarize_Light2.mplstyle +53 -0
- matplotlib_rs/mpl-data/stylelib/_classic_test_patch.mplstyle +8 -0
- matplotlib_rs/mpl-data/stylelib/_mpl-gallery-nogrid.mplstyle +19 -0
- matplotlib_rs/mpl-data/stylelib/_mpl-gallery.mplstyle +19 -0
- matplotlib_rs/mpl-data/stylelib/bmh.mplstyle +27 -0
- matplotlib_rs/mpl-data/stylelib/classic.mplstyle +491 -0
- matplotlib_rs/mpl-data/stylelib/dark_background.mplstyle +26 -0
- matplotlib_rs/mpl-data/stylelib/fast.mplstyle +11 -0
- matplotlib_rs/mpl-data/stylelib/fivethirtyeight.mplstyle +37 -0
- matplotlib_rs/mpl-data/stylelib/ggplot.mplstyle +39 -0
- matplotlib_rs/mpl-data/stylelib/grayscale.mplstyle +29 -0
- matplotlib_rs/mpl-data/stylelib/petroff10.mplstyle +5 -0
- matplotlib_rs/mpl-data/stylelib/petroff6.mplstyle +5 -0
- matplotlib_rs/mpl-data/stylelib/petroff8.mplstyle +5 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-bright.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-colorblind.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark-palette.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-darkgrid.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-deep.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-muted.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-notebook.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-paper.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-pastel.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-poster.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-talk.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-ticks.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-white.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-whitegrid.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8.mplstyle +57 -0
- matplotlib_rs/mpl-data/stylelib/tableau-colorblind10.mplstyle +3 -0
- matplotlib_rs/mpl_toolkits/__init__.py +3 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/__init__.py +11 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/anchored_artists.py +415 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_divider.py +619 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_grid.py +565 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_rgb.py +158 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_size.py +272 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/inset_locator.py +525 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/mpl_axes.py +129 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/parasite_axes.py +261 -0
- matplotlib_rs/mpl_toolkits/axisartist/__init__.py +15 -0
- matplotlib_rs/mpl_toolkits/axisartist/angle_helper.py +396 -0
- matplotlib_rs/mpl_toolkits/axisartist/axes_divider.py +3 -0
- matplotlib_rs/mpl_toolkits/axisartist/axis_artist.py +1148 -0
- matplotlib_rs/mpl_toolkits/axisartist/axisline_style.py +193 -0
- matplotlib_rs/mpl_toolkits/axisartist/axislines.py +475 -0
- matplotlib_rs/mpl_toolkits/axisartist/floating_axes.py +265 -0
- matplotlib_rs/mpl_toolkits/axisartist/grid_finder.py +329 -0
- matplotlib_rs/mpl_toolkits/axisartist/grid_helper_curvelinear.py +353 -0
- matplotlib_rs/mpl_toolkits/axisartist/parasite_axes.py +8 -0
- matplotlib_rs/mpl_toolkits/mplot3d/__init__.py +4 -0
- matplotlib_rs/mpl_toolkits/mplot3d/art3d.py +1758 -0
- matplotlib_rs/mpl_toolkits/mplot3d/axes3d.py +4462 -0
- matplotlib_rs/mpl_toolkits/mplot3d/axis3d.py +807 -0
- matplotlib_rs/mpl_toolkits/mplot3d/proj3d.py +270 -0
- matplotlib_rs/offsetbox.py +1726 -0
- matplotlib_rs/patches.py +5049 -0
- matplotlib_rs/path.py +1147 -0
- matplotlib_rs/patheffects.py +512 -0
- matplotlib_rs/projections/__init__.py +126 -0
- matplotlib_rs/projections/geo.py +512 -0
- matplotlib_rs/projections/polar.py +1518 -0
- matplotlib_rs/pylab.py +68 -0
- matplotlib_rs/pyplot.py +4834 -0
- matplotlib_rs/quiver.py +1236 -0
- matplotlib_rs/rcsetup.py +3435 -0
- matplotlib_rs/sankey.py +815 -0
- matplotlib_rs/scale.py +1002 -0
- matplotlib_rs/spines.py +618 -0
- matplotlib_rs/stackplot.py +144 -0
- matplotlib_rs/streamplot.py +768 -0
- matplotlib_rs/style/__init__.py +269 -0
- matplotlib_rs/style/core.py +28 -0
- matplotlib_rs/table.py +860 -0
- matplotlib_rs/texmanager.py +375 -0
- matplotlib_rs/text.py +2412 -0
- matplotlib_rs/textpath.py +377 -0
- matplotlib_rs/ticker.py +3111 -0
- matplotlib_rs/transforms.py +3069 -0
- matplotlib_rs/tri/__init__.py +24 -0
- matplotlib_rs/tri/_triangulation.py +248 -0
- matplotlib_rs/tri/_tricontour.py +271 -0
- matplotlib_rs/tri/_trifinder.py +97 -0
- matplotlib_rs/tri/_triinterpolate.py +1575 -0
- matplotlib_rs/tri/_tripcolor.py +170 -0
- matplotlib_rs/tri/_triplot.py +87 -0
- matplotlib_rs/tri/_trirefine.py +308 -0
- matplotlib_rs/tri/_tritools.py +264 -0
- matplotlib_rs/typing.py +597 -0
- matplotlib_rs/units.py +196 -0
- matplotlib_rs/widgets.py +4455 -0
- matplotlib_rs-0.0.8.dist-info/METADATA +392 -0
- matplotlib_rs-0.0.8.dist-info/RECORD +352 -0
- matplotlib_rs-0.0.8.dist-info/WHEEL +4 -0
- matplotlib_rs-0.0.8.dist-info/sboms/matplotlib-rs.cyclonedx.json +4390 -0
matplotlib_rs/dviread.py
ADDED
|
@@ -0,0 +1,1386 @@
|
|
|
1
|
+
# Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
|
|
2
|
+
"""
|
|
3
|
+
A module for reading dvi files output by TeX. Several limitations make
|
|
4
|
+
this not (currently) useful as a general-purpose dvi preprocessor, but
|
|
5
|
+
it is currently used by the pdf backend for processing usetex text.
|
|
6
|
+
|
|
7
|
+
Interface::
|
|
8
|
+
|
|
9
|
+
with Dvi(filename, 72) as dvi:
|
|
10
|
+
# iterate over pages:
|
|
11
|
+
for page in dvi:
|
|
12
|
+
w, h, d = page.width, page.height, page.descent
|
|
13
|
+
for x, y, font, glyph, width in page.text:
|
|
14
|
+
fontname = font.texname
|
|
15
|
+
pointsize = font.size
|
|
16
|
+
...
|
|
17
|
+
for x, y, height, width in page.boxes:
|
|
18
|
+
...
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import dataclasses
|
|
22
|
+
import enum
|
|
23
|
+
import logging
|
|
24
|
+
import os
|
|
25
|
+
import re
|
|
26
|
+
import struct
|
|
27
|
+
import subprocess
|
|
28
|
+
import sys
|
|
29
|
+
from collections import namedtuple
|
|
30
|
+
from functools import cache, cached_property, lru_cache, partial, wraps
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
import numpy as np
|
|
34
|
+
|
|
35
|
+
import matplotlib_rs as mpl
|
|
36
|
+
from matplotlib_rs import _api, cbook, font_manager
|
|
37
|
+
from matplotlib_rs.ft2font import LoadFlags
|
|
38
|
+
|
|
39
|
+
_log = logging.getLogger(__name__)
|
|
40
|
+
|
|
41
|
+
# Many dvi related files are looked for by external processes, require
|
|
42
|
+
# additional parsing, and are used many times per rendering, which is why they
|
|
43
|
+
# are cached using lru_cache().
|
|
44
|
+
|
|
45
|
+
# Dvi is a bytecode format documented in
|
|
46
|
+
# https://ctan.org/pkg/dvitype
|
|
47
|
+
# https://texdoc.org/serve/dvitype.pdf/0
|
|
48
|
+
#
|
|
49
|
+
# The file consists of a preamble, some number of pages, a postamble,
|
|
50
|
+
# and a finale. Different opcodes are allowed in different contexts,
|
|
51
|
+
# so the Dvi object has a parser state:
|
|
52
|
+
#
|
|
53
|
+
# pre: expecting the preamble
|
|
54
|
+
# outer: between pages (followed by a page or the postamble,
|
|
55
|
+
# also e.g. font definitions are allowed)
|
|
56
|
+
# page: processing a page
|
|
57
|
+
# post_post: state after the postamble (our current implementation
|
|
58
|
+
# just stops reading)
|
|
59
|
+
# finale: the finale (unimplemented in our current implementation)
|
|
60
|
+
|
|
61
|
+
_dvistate = enum.Enum('DviState', 'pre outer inpage post_post finale')
|
|
62
|
+
|
|
63
|
+
# The marks on a page consist of text and boxes. A page also has dimensions.
|
|
64
|
+
Page = namedtuple('Page', 'text boxes height width descent')
|
|
65
|
+
Box = namedtuple('Box', 'x y height width')
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Also a namedtuple, for backcompat.
|
|
69
|
+
class Text(namedtuple('Text', 'x y font glyph width')):
|
|
70
|
+
"""
|
|
71
|
+
A glyph in the dvi file.
|
|
72
|
+
|
|
73
|
+
In order to render the glyph, load the glyph at index ``text.index``
|
|
74
|
+
from the font at ``text.font.resolve_path()`` with size ``text.font.size``,
|
|
75
|
+
warped with ``text.font.effects``, then draw it at position
|
|
76
|
+
``(text.x, text.y)``.
|
|
77
|
+
|
|
78
|
+
``text.glyph`` is the glyph number actually stored in the dvi file (whose
|
|
79
|
+
interpretation depends on the font). ``text.width`` is the glyph width in
|
|
80
|
+
dvi units.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def index(self):
|
|
85
|
+
"""
|
|
86
|
+
The FreeType index of this glyph (that can be passed to FT_Load_Glyph).
|
|
87
|
+
"""
|
|
88
|
+
# See DviFont._index_dvi_to_freetype for details on the index mapping.
|
|
89
|
+
return self.font._index_dvi_to_freetype(self.glyph)
|
|
90
|
+
|
|
91
|
+
font_path = property(lambda self: self.font.resolve_path())
|
|
92
|
+
font_size = property(lambda self: self.font.size)
|
|
93
|
+
font_effects = property(lambda self: self.font.effects)
|
|
94
|
+
|
|
95
|
+
@property # To be deprecated together with font_path, font_size, font_effects.
|
|
96
|
+
def glyph_name_or_index(self):
|
|
97
|
+
"""
|
|
98
|
+
The glyph name, the native charmap glyph index, or the raw glyph index.
|
|
99
|
+
|
|
100
|
+
If the font is a TrueType file (which can currently only happen for
|
|
101
|
+
DVI files generated by xetex or luatex), then this number is the raw
|
|
102
|
+
index of the glyph, which can be passed to FT_Load_Glyph/load_glyph.
|
|
103
|
+
|
|
104
|
+
Otherwise, the font is a PostScript font. For such fonts, if
|
|
105
|
+
:file:`pdftex.map` specifies an encoding for this glyph's font,
|
|
106
|
+
that is a mapping of glyph indices to Adobe glyph names; which
|
|
107
|
+
is used by this property to convert dvi numbers to glyph names.
|
|
108
|
+
Callers can then convert glyph names to glyph indices (with
|
|
109
|
+
FT_Get_Name_Index/get_name_index), and load the glyph using
|
|
110
|
+
FT_Load_Glyph/load_glyph.
|
|
111
|
+
|
|
112
|
+
If :file:`pdftex.map` specifies no encoding for a PostScript font,
|
|
113
|
+
this number is an index to the font's "native" charmap; glyphs should
|
|
114
|
+
directly load using FT_Load_Char/load_char after selecting the native
|
|
115
|
+
charmap.
|
|
116
|
+
"""
|
|
117
|
+
# The last section is only true on luatex since luaotfload 3.23; this
|
|
118
|
+
# must be checked by the code generated by texmanager. (luaotfload's
|
|
119
|
+
# docs states "No one should rely on the mapping between DVI character
|
|
120
|
+
# codes and font glyphs [prior to v3.15] unless they tightly
|
|
121
|
+
# control all involved versions and are deeply familiar with the
|
|
122
|
+
# implementation", but a further mapping bug was fixed in luaotfload
|
|
123
|
+
# commit 8f2dca4, first included in v3.23).
|
|
124
|
+
entry = PsfontsMap(find_tex_file("pdftex.map"))[self.font.texname]
|
|
125
|
+
return (_parse_enc(entry.encoding)[self.glyph]
|
|
126
|
+
if entry.encoding is not None else self.glyph)
|
|
127
|
+
|
|
128
|
+
def _as_unicode_or_name(self):
|
|
129
|
+
if self.font.subfont:
|
|
130
|
+
raise NotImplementedError("Indexing TTC fonts is not supported yet")
|
|
131
|
+
path = self.font.resolve_path()
|
|
132
|
+
if path.name.lower().endswith("pk"):
|
|
133
|
+
# PK fonts have no encoding information; report glyphs as ASCII but
|
|
134
|
+
# with a "?" to indicate that this is just a guess.
|
|
135
|
+
return (f"{chr(self.glyph)}?" if chr(self.glyph).isprintable() else
|
|
136
|
+
f"pk{self.glyph:#02x}")
|
|
137
|
+
face = font_manager.get_font(path)
|
|
138
|
+
glyph_name = face.get_glyph_name(self.index)
|
|
139
|
+
import fontTools.agl # (usetex only)
|
|
140
|
+
glyph_str = fontTools.agl.toUnicode(glyph_name)
|
|
141
|
+
return glyph_str or glyph_name
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# Opcode argument parsing
|
|
145
|
+
#
|
|
146
|
+
# Each of the following functions takes a Dvi object and delta, which is the
|
|
147
|
+
# difference between the opcode and the minimum opcode with the same meaning.
|
|
148
|
+
# Dvi opcodes often encode the number of argument bytes in this delta.
|
|
149
|
+
_arg_mapping = dict(
|
|
150
|
+
# raw: Return delta as is.
|
|
151
|
+
raw=lambda dvi, delta: delta,
|
|
152
|
+
# u1: Read 1 byte as an unsigned number.
|
|
153
|
+
u1=lambda dvi, delta: dvi._read_arg(1, signed=False),
|
|
154
|
+
# u4: Read 4 bytes as an unsigned number.
|
|
155
|
+
u4=lambda dvi, delta: dvi._read_arg(4, signed=False),
|
|
156
|
+
# s4: Read 4 bytes as a signed number.
|
|
157
|
+
s4=lambda dvi, delta: dvi._read_arg(4, signed=True),
|
|
158
|
+
# slen: Read delta bytes as a signed number, or None if delta is None.
|
|
159
|
+
slen=lambda dvi, delta: dvi._read_arg(delta, signed=True) if delta else None,
|
|
160
|
+
# slen1: Read (delta + 1) bytes as a signed number.
|
|
161
|
+
slen1=lambda dvi, delta: dvi._read_arg(delta + 1, signed=True),
|
|
162
|
+
# ulen1: Read (delta + 1) bytes as an unsigned number.
|
|
163
|
+
ulen1=lambda dvi, delta: dvi._read_arg(delta + 1, signed=False),
|
|
164
|
+
# olen1: Read (delta + 1) bytes as an unsigned number if less than 4 bytes,
|
|
165
|
+
# as a signed number if 4 bytes.
|
|
166
|
+
olen1=lambda dvi, delta: dvi._read_arg(delta + 1, signed=(delta == 3)),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _dispatch(table, min, max=None, state=None, args=('raw',)):
|
|
171
|
+
"""
|
|
172
|
+
Decorator for dispatch by opcode. Sets the values in *table*
|
|
173
|
+
from *min* to *max* to this method, adds a check that the Dvi state
|
|
174
|
+
matches *state* if not None, reads arguments from the file according
|
|
175
|
+
to *args*.
|
|
176
|
+
|
|
177
|
+
Parameters
|
|
178
|
+
----------
|
|
179
|
+
table : dict[int, callable]
|
|
180
|
+
The dispatch table to be filled in.
|
|
181
|
+
|
|
182
|
+
min, max : int
|
|
183
|
+
Range of opcodes that calls the registered function; *max* defaults to
|
|
184
|
+
*min*.
|
|
185
|
+
|
|
186
|
+
state : _dvistate, optional
|
|
187
|
+
State of the Dvi object in which these opcodes are allowed.
|
|
188
|
+
|
|
189
|
+
args : list[str], default: ['raw']
|
|
190
|
+
Sequence of argument specifications:
|
|
191
|
+
|
|
192
|
+
- 'raw': opcode minus minimum
|
|
193
|
+
- 'u1': read one unsigned byte
|
|
194
|
+
- 'u4': read four bytes, treat as an unsigned number
|
|
195
|
+
- 's4': read four bytes, treat as a signed number
|
|
196
|
+
- 'slen': read (opcode - minimum) bytes, treat as signed
|
|
197
|
+
- 'slen1': read (opcode - minimum + 1) bytes, treat as signed
|
|
198
|
+
- 'ulen1': read (opcode - minimum + 1) bytes, treat as unsigned
|
|
199
|
+
- 'olen1': read (opcode - minimum + 1) bytes, treat as unsigned
|
|
200
|
+
if under four bytes, signed if four bytes
|
|
201
|
+
"""
|
|
202
|
+
def decorate(method):
|
|
203
|
+
get_args = [_arg_mapping[x] for x in args]
|
|
204
|
+
|
|
205
|
+
@wraps(method)
|
|
206
|
+
def wrapper(self, byte):
|
|
207
|
+
if state is not None and self.state != state:
|
|
208
|
+
raise ValueError("state precondition failed")
|
|
209
|
+
return method(self, *[f(self, byte-min) for f in get_args])
|
|
210
|
+
if max is None:
|
|
211
|
+
table[min] = wrapper
|
|
212
|
+
else:
|
|
213
|
+
for i in range(min, max+1):
|
|
214
|
+
assert table[i] is None
|
|
215
|
+
table[i] = wrapper
|
|
216
|
+
return wrapper
|
|
217
|
+
return decorate
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class Dvi:
|
|
221
|
+
"""
|
|
222
|
+
A reader for a dvi ("device-independent") file, as produced by TeX.
|
|
223
|
+
|
|
224
|
+
The current implementation can only iterate through pages in order,
|
|
225
|
+
and does not even attempt to verify the postamble.
|
|
226
|
+
|
|
227
|
+
This class can be used as a context manager to close the underlying
|
|
228
|
+
file upon exit. Pages can be read via iteration. Here is an overly
|
|
229
|
+
simple way to extract text without trying to detect whitespace::
|
|
230
|
+
|
|
231
|
+
>>> with matplotlib.dviread.Dvi('input.dvi', 72) as dvi:
|
|
232
|
+
... for page in dvi:
|
|
233
|
+
... print(''.join(chr(t.glyph) for t in page.text))
|
|
234
|
+
"""
|
|
235
|
+
# dispatch table
|
|
236
|
+
_dtable = [None] * 256
|
|
237
|
+
_dispatch = partial(_dispatch, _dtable)
|
|
238
|
+
|
|
239
|
+
def __init__(self, filename, dpi):
|
|
240
|
+
"""
|
|
241
|
+
Read the data from the file named *filename* and convert
|
|
242
|
+
TeX's internal units to units of *dpi* per inch.
|
|
243
|
+
*dpi* only sets the units and does not limit the resolution.
|
|
244
|
+
Use None to return TeX's internal units.
|
|
245
|
+
"""
|
|
246
|
+
_log.debug('Dvi: %s', filename)
|
|
247
|
+
self.file = open(filename, 'rb')
|
|
248
|
+
self.dpi = dpi
|
|
249
|
+
self.fonts = {}
|
|
250
|
+
self.state = _dvistate.pre
|
|
251
|
+
self._missing_font = None
|
|
252
|
+
|
|
253
|
+
def __enter__(self):
|
|
254
|
+
"""Context manager enter method, does nothing."""
|
|
255
|
+
return self
|
|
256
|
+
|
|
257
|
+
def __exit__(self, etype, evalue, etrace):
|
|
258
|
+
"""
|
|
259
|
+
Context manager exit method, closes the underlying file if it is open.
|
|
260
|
+
"""
|
|
261
|
+
self.close()
|
|
262
|
+
|
|
263
|
+
def __iter__(self):
|
|
264
|
+
"""
|
|
265
|
+
Iterate through the pages of the file.
|
|
266
|
+
|
|
267
|
+
Yields
|
|
268
|
+
------
|
|
269
|
+
Page
|
|
270
|
+
Details of all the text and box objects on the page.
|
|
271
|
+
The Page tuple contains lists of Text and Box tuples and
|
|
272
|
+
the page dimensions, and the Text and Box tuples contain
|
|
273
|
+
coordinates transformed into a standard Cartesian
|
|
274
|
+
coordinate system at the dpi value given when initializing.
|
|
275
|
+
The coordinates are floating point numbers, but otherwise
|
|
276
|
+
precision is not lost and coordinate values are not clipped to
|
|
277
|
+
integers.
|
|
278
|
+
"""
|
|
279
|
+
while self._read():
|
|
280
|
+
yield self._output()
|
|
281
|
+
|
|
282
|
+
def close(self):
|
|
283
|
+
"""Close the underlying file if it is open."""
|
|
284
|
+
if not self.file.closed:
|
|
285
|
+
self.file.close()
|
|
286
|
+
|
|
287
|
+
def _output(self):
|
|
288
|
+
"""
|
|
289
|
+
Output the text and boxes belonging to the most recent page.
|
|
290
|
+
page = dvi._output()
|
|
291
|
+
"""
|
|
292
|
+
minx = miny = np.inf
|
|
293
|
+
maxx = maxy = -np.inf
|
|
294
|
+
maxy_pure = -np.inf
|
|
295
|
+
for elt in self.text + self.boxes:
|
|
296
|
+
if isinstance(elt, Box):
|
|
297
|
+
x, y, h, w = elt
|
|
298
|
+
e = 0 # zero depth
|
|
299
|
+
else: # glyph
|
|
300
|
+
x, y, font, g, w = elt
|
|
301
|
+
h, e = font._height_depth_of(g)
|
|
302
|
+
minx = min(minx, x)
|
|
303
|
+
miny = min(miny, y - h)
|
|
304
|
+
maxx = max(maxx, x + w)
|
|
305
|
+
maxy = max(maxy, y + e)
|
|
306
|
+
maxy_pure = max(maxy_pure, y)
|
|
307
|
+
if self._baseline_v is not None:
|
|
308
|
+
maxy_pure = self._baseline_v # This should normally be the case.
|
|
309
|
+
self._baseline_v = None
|
|
310
|
+
|
|
311
|
+
if not self.text and not self.boxes: # Avoid infs/nans from inf+/-inf.
|
|
312
|
+
return Page(text=[], boxes=[], width=0, height=0, descent=0)
|
|
313
|
+
|
|
314
|
+
if self.dpi is None:
|
|
315
|
+
# special case for ease of debugging: output raw dvi coordinates
|
|
316
|
+
return Page(text=self.text, boxes=self.boxes,
|
|
317
|
+
width=maxx-minx, height=maxy_pure-miny,
|
|
318
|
+
descent=maxy-maxy_pure)
|
|
319
|
+
|
|
320
|
+
# convert from TeX's "scaled points" to dpi units
|
|
321
|
+
d = self.dpi / (72.27 * 2**16)
|
|
322
|
+
descent = (maxy - maxy_pure) * d
|
|
323
|
+
|
|
324
|
+
text = [Text((x-minx)*d, (maxy-y)*d - descent, f, g, w*d)
|
|
325
|
+
for (x, y, f, g, w) in self.text]
|
|
326
|
+
boxes = [Box((x-minx)*d, (maxy-y)*d - descent, h*d, w*d)
|
|
327
|
+
for (x, y, h, w) in self.boxes]
|
|
328
|
+
|
|
329
|
+
return Page(text=text, boxes=boxes, width=(maxx-minx)*d,
|
|
330
|
+
height=(maxy_pure-miny)*d, descent=descent)
|
|
331
|
+
|
|
332
|
+
def _read(self):
|
|
333
|
+
"""
|
|
334
|
+
Read one page from the file. Return True if successful,
|
|
335
|
+
False if there were no more pages.
|
|
336
|
+
"""
|
|
337
|
+
# Pages appear to start with the sequence
|
|
338
|
+
# bop (begin of page)
|
|
339
|
+
# xxx comment
|
|
340
|
+
# <push, ..., pop> # if using chemformula
|
|
341
|
+
# down
|
|
342
|
+
# push
|
|
343
|
+
# down
|
|
344
|
+
# <push, push, xxx, right, xxx, pop, pop> # if using xcolor
|
|
345
|
+
# down
|
|
346
|
+
# push
|
|
347
|
+
# down (possibly multiple)
|
|
348
|
+
# push <= here, v is the baseline position.
|
|
349
|
+
# etc.
|
|
350
|
+
# (dviasm is useful to explore this structure.)
|
|
351
|
+
# Thus, we use the vertical position at the first time the stack depth
|
|
352
|
+
# reaches 3, while at least three "downs" have been executed (excluding
|
|
353
|
+
# those popped out (corresponding to the chemformula preamble)), as the
|
|
354
|
+
# baseline (the "down" count is necessary to handle xcolor).
|
|
355
|
+
down_stack = [0]
|
|
356
|
+
self._baseline_v = None
|
|
357
|
+
while True:
|
|
358
|
+
byte = self.file.read(1)[0]
|
|
359
|
+
self._dtable[byte](self, byte)
|
|
360
|
+
if self._missing_font:
|
|
361
|
+
raise self._missing_font.to_exception()
|
|
362
|
+
name = self._dtable[byte].__name__
|
|
363
|
+
if name == "_push":
|
|
364
|
+
down_stack.append(down_stack[-1])
|
|
365
|
+
elif name == "_pop":
|
|
366
|
+
down_stack.pop()
|
|
367
|
+
elif name == "_down":
|
|
368
|
+
down_stack[-1] += 1
|
|
369
|
+
if (self._baseline_v is None
|
|
370
|
+
and len(getattr(self, "stack", [])) == 3
|
|
371
|
+
and down_stack[-1] >= 4):
|
|
372
|
+
self._baseline_v = self.v
|
|
373
|
+
if byte == 140: # end of page
|
|
374
|
+
return True
|
|
375
|
+
if self.state is _dvistate.post_post: # end of file
|
|
376
|
+
self.close()
|
|
377
|
+
return False
|
|
378
|
+
|
|
379
|
+
def _read_arg(self, nbytes, signed=False):
|
|
380
|
+
"""
|
|
381
|
+
Read and return a big-endian integer *nbytes* long.
|
|
382
|
+
Signedness is determined by the *signed* keyword.
|
|
383
|
+
"""
|
|
384
|
+
return int.from_bytes(self.file.read(nbytes), "big", signed=signed)
|
|
385
|
+
|
|
386
|
+
@_dispatch(min=0, max=127, state=_dvistate.inpage)
|
|
387
|
+
def _set_char_immediate(self, char):
|
|
388
|
+
self._put_char_real(char)
|
|
389
|
+
if isinstance(self.fonts[self.f], cbook._ExceptionInfo):
|
|
390
|
+
return
|
|
391
|
+
self.h += self.fonts[self.f]._width_of(char)
|
|
392
|
+
|
|
393
|
+
@_dispatch(min=128, max=131, state=_dvistate.inpage, args=('olen1',))
|
|
394
|
+
def _set_char(self, char):
|
|
395
|
+
self._put_char_real(char)
|
|
396
|
+
if isinstance(self.fonts[self.f], cbook._ExceptionInfo):
|
|
397
|
+
return
|
|
398
|
+
self.h += self.fonts[self.f]._width_of(char)
|
|
399
|
+
|
|
400
|
+
@_dispatch(132, state=_dvistate.inpage, args=('s4', 's4'))
|
|
401
|
+
def _set_rule(self, a, b):
|
|
402
|
+
self._put_rule_real(a, b)
|
|
403
|
+
self.h += b
|
|
404
|
+
|
|
405
|
+
@_dispatch(min=133, max=136, state=_dvistate.inpage, args=('olen1',))
|
|
406
|
+
def _put_char(self, char):
|
|
407
|
+
self._put_char_real(char)
|
|
408
|
+
|
|
409
|
+
def _put_char_real(self, char):
|
|
410
|
+
font = self.fonts[self.f]
|
|
411
|
+
if isinstance(font, cbook._ExceptionInfo):
|
|
412
|
+
self._missing_font = font
|
|
413
|
+
elif font._vf is None:
|
|
414
|
+
self.text.append(Text(self.h, self.v, font, char,
|
|
415
|
+
font._width_of(char)))
|
|
416
|
+
else:
|
|
417
|
+
scale = font._scale
|
|
418
|
+
for x, y, f, g, w in font._vf[char].text:
|
|
419
|
+
newf = DviFont(scale=_mul1220(scale, f._scale),
|
|
420
|
+
metrics=f._metrics, texname=f.texname, vf=f._vf)
|
|
421
|
+
self.text.append(Text(self.h + _mul1220(x, scale),
|
|
422
|
+
self.v + _mul1220(y, scale),
|
|
423
|
+
newf, g, newf._width_of(g)))
|
|
424
|
+
self.boxes.extend([Box(self.h + _mul1220(x, scale),
|
|
425
|
+
self.v + _mul1220(y, scale),
|
|
426
|
+
_mul1220(a, scale), _mul1220(b, scale))
|
|
427
|
+
for x, y, a, b in font._vf[char].boxes])
|
|
428
|
+
|
|
429
|
+
@_dispatch(137, state=_dvistate.inpage, args=('s4', 's4'))
|
|
430
|
+
def _put_rule(self, a, b):
|
|
431
|
+
self._put_rule_real(a, b)
|
|
432
|
+
|
|
433
|
+
def _put_rule_real(self, a, b):
|
|
434
|
+
if a > 0 and b > 0:
|
|
435
|
+
self.boxes.append(Box(self.h, self.v, a, b))
|
|
436
|
+
|
|
437
|
+
@_dispatch(138)
|
|
438
|
+
def _nop(self, _):
|
|
439
|
+
pass
|
|
440
|
+
|
|
441
|
+
@_dispatch(139, state=_dvistate.outer, args=('s4',)*11)
|
|
442
|
+
def _bop(self, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, p):
|
|
443
|
+
self.state = _dvistate.inpage
|
|
444
|
+
self.h = self.v = self.w = self.x = self.y = self.z = 0
|
|
445
|
+
self.stack = []
|
|
446
|
+
self.text = [] # list of Text objects
|
|
447
|
+
self.boxes = [] # list of Box objects
|
|
448
|
+
|
|
449
|
+
@_dispatch(140, state=_dvistate.inpage)
|
|
450
|
+
def _eop(self, _):
|
|
451
|
+
self.state = _dvistate.outer
|
|
452
|
+
del self.h, self.v, self.w, self.x, self.y, self.z, self.stack
|
|
453
|
+
|
|
454
|
+
@_dispatch(141, state=_dvistate.inpage)
|
|
455
|
+
def _push(self, _):
|
|
456
|
+
self.stack.append((self.h, self.v, self.w, self.x, self.y, self.z))
|
|
457
|
+
|
|
458
|
+
@_dispatch(142, state=_dvistate.inpage)
|
|
459
|
+
def _pop(self, _):
|
|
460
|
+
self.h, self.v, self.w, self.x, self.y, self.z = self.stack.pop()
|
|
461
|
+
|
|
462
|
+
@_dispatch(min=143, max=146, state=_dvistate.inpage, args=('slen1',))
|
|
463
|
+
def _right(self, b):
|
|
464
|
+
self.h += b
|
|
465
|
+
|
|
466
|
+
@_dispatch(min=147, max=151, state=_dvistate.inpage, args=('slen',))
|
|
467
|
+
def _right_w(self, new_w):
|
|
468
|
+
if new_w is not None:
|
|
469
|
+
self.w = new_w
|
|
470
|
+
self.h += self.w
|
|
471
|
+
|
|
472
|
+
@_dispatch(min=152, max=156, state=_dvistate.inpage, args=('slen',))
|
|
473
|
+
def _right_x(self, new_x):
|
|
474
|
+
if new_x is not None:
|
|
475
|
+
self.x = new_x
|
|
476
|
+
self.h += self.x
|
|
477
|
+
|
|
478
|
+
@_dispatch(min=157, max=160, state=_dvistate.inpage, args=('slen1',))
|
|
479
|
+
def _down(self, a):
|
|
480
|
+
self.v += a
|
|
481
|
+
|
|
482
|
+
@_dispatch(min=161, max=165, state=_dvistate.inpage, args=('slen',))
|
|
483
|
+
def _down_y(self, new_y):
|
|
484
|
+
if new_y is not None:
|
|
485
|
+
self.y = new_y
|
|
486
|
+
self.v += self.y
|
|
487
|
+
|
|
488
|
+
@_dispatch(min=166, max=170, state=_dvistate.inpage, args=('slen',))
|
|
489
|
+
def _down_z(self, new_z):
|
|
490
|
+
if new_z is not None:
|
|
491
|
+
self.z = new_z
|
|
492
|
+
self.v += self.z
|
|
493
|
+
|
|
494
|
+
@_dispatch(min=171, max=234, state=_dvistate.inpage)
|
|
495
|
+
def _fnt_num_immediate(self, k):
|
|
496
|
+
self.f = k
|
|
497
|
+
|
|
498
|
+
@_dispatch(min=235, max=238, state=_dvistate.inpage, args=('olen1',))
|
|
499
|
+
def _fnt_num(self, new_f):
|
|
500
|
+
self.f = new_f
|
|
501
|
+
|
|
502
|
+
@_dispatch(min=239, max=242, args=('ulen1',))
|
|
503
|
+
def _xxx(self, datalen):
|
|
504
|
+
special = self.file.read(datalen)
|
|
505
|
+
_log.debug(
|
|
506
|
+
'Dvi._xxx: encountered special: %s',
|
|
507
|
+
''.join([chr(ch) if 32 <= ch < 127 else '<%02x>' % ch
|
|
508
|
+
for ch in special]))
|
|
509
|
+
|
|
510
|
+
@_dispatch(min=243, max=246, args=('olen1', 'u4', 'u4', 'u4', 'u1', 'u1'))
|
|
511
|
+
def _fnt_def(self, k, c, s, d, a, l):
|
|
512
|
+
self._fnt_def_real(k, c, s, d, a, l)
|
|
513
|
+
|
|
514
|
+
def _fnt_def_real(self, k, c, s, d, a, l):
|
|
515
|
+
n = self.file.read(a + l)
|
|
516
|
+
fontname = n[-l:]
|
|
517
|
+
if fontname.startswith(b"[") and c == 0x4c756146: # c == "LuaF"
|
|
518
|
+
# See https://chat.stackexchange.com/rooms/106428 (and also
|
|
519
|
+
# https://tug.org/pipermail/dvipdfmx/2021-January/000168.html).
|
|
520
|
+
# AFAICT luatex's dvi drops info re: OpenType variation-axis values.
|
|
521
|
+
self.fonts[k] = DviFont.from_luatex(s, n)
|
|
522
|
+
return
|
|
523
|
+
fontname = fontname.decode("ascii")
|
|
524
|
+
try:
|
|
525
|
+
tfm = _tfmfile(fontname)
|
|
526
|
+
except FileNotFoundError as exc:
|
|
527
|
+
if fontname.startswith("[") and fontname.endswith(";") and c == 0:
|
|
528
|
+
cbook._add_note(
|
|
529
|
+
exc,
|
|
530
|
+
"This dvi file was likely generated with a too-old "
|
|
531
|
+
"version of luaotfload; luaotfload 3.23 is required.")
|
|
532
|
+
# Explicitly allow defining missing fonts for Vf support; we only
|
|
533
|
+
# register an error when trying to load a glyph from a missing font
|
|
534
|
+
# and throw that error in Dvi._read. For Vf, _finalize_packet
|
|
535
|
+
# checks whether a missing glyph has been used, and in that case
|
|
536
|
+
# skips the glyph definition.
|
|
537
|
+
self.fonts[k] = cbook._ExceptionInfo.from_exception(exc)
|
|
538
|
+
return
|
|
539
|
+
if c != 0 and tfm.checksum != 0 and c != tfm.checksum:
|
|
540
|
+
raise ValueError(f'tfm checksum mismatch: {n}')
|
|
541
|
+
try:
|
|
542
|
+
vf = _vffile(fontname)
|
|
543
|
+
except FileNotFoundError:
|
|
544
|
+
vf = None
|
|
545
|
+
self.fonts[k] = DviFont(scale=s, metrics=tfm, texname=n, vf=vf)
|
|
546
|
+
|
|
547
|
+
@_dispatch(247, state=_dvistate.pre, args=('u1', 'u4', 'u4', 'u4', 'u1'))
|
|
548
|
+
def _pre(self, i, num, den, mag, k):
|
|
549
|
+
self.file.read(k) # comment in the dvi file
|
|
550
|
+
if i not in [2, 7]: # 2: pdftex, luatex; 7: xetex
|
|
551
|
+
raise ValueError(f"Unknown dvi format {i}")
|
|
552
|
+
if num != 25400000 or den != 7227 * 2**16:
|
|
553
|
+
raise ValueError("Nonstandard units in dvi file")
|
|
554
|
+
# meaning: TeX always uses those exact values, so it
|
|
555
|
+
# should be enough for us to support those
|
|
556
|
+
# (There are 72.27 pt to an inch so 7227 pt =
|
|
557
|
+
# 7227 * 2**16 sp to 100 in. The numerator is multiplied
|
|
558
|
+
# by 10^5 to get units of 10**-7 meters.)
|
|
559
|
+
if mag != 1000:
|
|
560
|
+
raise ValueError("Nonstandard magnification in dvi file")
|
|
561
|
+
# meaning: LaTeX seems to frown on setting \mag, so
|
|
562
|
+
# I think we can assume this is constant
|
|
563
|
+
self.state = _dvistate.outer
|
|
564
|
+
|
|
565
|
+
@_dispatch(248, state=_dvistate.outer)
|
|
566
|
+
def _post(self, _):
|
|
567
|
+
self.state = _dvistate.post_post
|
|
568
|
+
# TODO: actually read the postamble and finale?
|
|
569
|
+
# currently post_post just triggers closing the file
|
|
570
|
+
|
|
571
|
+
@_dispatch(249, args=())
|
|
572
|
+
def _post_post(self):
|
|
573
|
+
raise NotImplementedError
|
|
574
|
+
|
|
575
|
+
@_dispatch(250, args=())
|
|
576
|
+
def _begin_reflect(self):
|
|
577
|
+
raise NotImplementedError
|
|
578
|
+
|
|
579
|
+
@_dispatch(251, args=())
|
|
580
|
+
def _end_reflect(self):
|
|
581
|
+
raise NotImplementedError
|
|
582
|
+
|
|
583
|
+
@_dispatch(252, args=())
|
|
584
|
+
def _define_native_font(self):
|
|
585
|
+
k = self._read_arg(4, signed=False)
|
|
586
|
+
s = self._read_arg(4, signed=False)
|
|
587
|
+
flags = self._read_arg(2, signed=False)
|
|
588
|
+
l = self._read_arg(1, signed=False)
|
|
589
|
+
n = self.file.read(l)
|
|
590
|
+
i = self._read_arg(4, signed=False)
|
|
591
|
+
effects = {}
|
|
592
|
+
if flags & 0x0200:
|
|
593
|
+
effects["rgba"] = [self._read_arg(1, signed=False) for _ in range(4)]
|
|
594
|
+
if flags & 0x1000:
|
|
595
|
+
effects["extend"] = self._read_arg(4, signed=True) / 65536
|
|
596
|
+
if flags & 0x2000:
|
|
597
|
+
effects["slant"] = self._read_arg(4, signed=True) / 65536
|
|
598
|
+
if flags & 0x4000:
|
|
599
|
+
effects["embolden"] = self._read_arg(4, signed=True) / 65536
|
|
600
|
+
self.fonts[k] = DviFont.from_xetex(s, n, i, effects)
|
|
601
|
+
|
|
602
|
+
@_dispatch(253, args=())
|
|
603
|
+
def _set_glyphs(self):
|
|
604
|
+
w = self._read_arg(4, signed=False)
|
|
605
|
+
k = self._read_arg(2, signed=False)
|
|
606
|
+
xy = [self._read_arg(4, signed=True) for _ in range(2 * k)]
|
|
607
|
+
g = [self._read_arg(2, signed=False) for _ in range(k)]
|
|
608
|
+
font = self.fonts[self.f]
|
|
609
|
+
for i in range(k):
|
|
610
|
+
self.text.append(Text(self.h + xy[2 * i], self.v + xy[2 * i + 1],
|
|
611
|
+
font, g[i], font._width_of(g[i])))
|
|
612
|
+
self.h += w
|
|
613
|
+
|
|
614
|
+
@_dispatch(254, args=())
|
|
615
|
+
def _set_text_and_glyphs(self):
|
|
616
|
+
l = self._read_arg(2, signed=False)
|
|
617
|
+
t = self.file.read(2 * l) # utf16
|
|
618
|
+
w = self._read_arg(4, signed=False)
|
|
619
|
+
k = self._read_arg(2, signed=False)
|
|
620
|
+
xy = [self._read_arg(4, signed=True) for _ in range(2 * k)]
|
|
621
|
+
g = [self._read_arg(2, signed=False) for _ in range(k)]
|
|
622
|
+
font = self.fonts[self.f]
|
|
623
|
+
for i in range(k):
|
|
624
|
+
self.text.append(Text(self.h + xy[2 * i], self.v + xy[2 * i + 1],
|
|
625
|
+
font, g[i], font._width_of(g[i])))
|
|
626
|
+
self.h += w
|
|
627
|
+
|
|
628
|
+
@_dispatch(255)
|
|
629
|
+
def _malformed(self, raw):
|
|
630
|
+
raise ValueError("unknown command: byte 255")
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
class DviFont:
|
|
634
|
+
"""
|
|
635
|
+
Encapsulation of a font that a DVI file can refer to.
|
|
636
|
+
|
|
637
|
+
This class holds a font's texname and size, supports comparison,
|
|
638
|
+
and knows the widths of glyphs in the same units as the AFM file.
|
|
639
|
+
There are also internal attributes (for use by dviread.py) that
|
|
640
|
+
are *not* used for comparison.
|
|
641
|
+
|
|
642
|
+
The size is in Adobe points (converted from TeX points).
|
|
643
|
+
|
|
644
|
+
Parameters
|
|
645
|
+
----------
|
|
646
|
+
scale : float
|
|
647
|
+
Factor by which the font is scaled from its natural size.
|
|
648
|
+
metrics : Tfm | TtfMetrics
|
|
649
|
+
TeX font metrics for this font
|
|
650
|
+
texname : bytes
|
|
651
|
+
Name of the font as used internally in the DVI file, as an ASCII
|
|
652
|
+
bytestring. This is usually very different from any external font
|
|
653
|
+
names; `PsfontsMap` can be used to find the external name of the font.
|
|
654
|
+
vf : Vf
|
|
655
|
+
A TeX "virtual font" file, or None if this font is not virtual.
|
|
656
|
+
|
|
657
|
+
Attributes
|
|
658
|
+
----------
|
|
659
|
+
texname : bytes
|
|
660
|
+
fname : str
|
|
661
|
+
Compatibility shim so that DviFont can be used with
|
|
662
|
+
``_backend_pdf_ps.CharacterTracker``; not a real filename.
|
|
663
|
+
size : float
|
|
664
|
+
Size of the font in Adobe points, converted from the slightly
|
|
665
|
+
smaller TeX points.
|
|
666
|
+
"""
|
|
667
|
+
|
|
668
|
+
def __init__(self, scale, metrics, texname, vf):
|
|
669
|
+
_api.check_isinstance(bytes, texname=texname)
|
|
670
|
+
self._scale = scale
|
|
671
|
+
self._metrics = metrics
|
|
672
|
+
self.texname = texname
|
|
673
|
+
self._vf = vf
|
|
674
|
+
self._path = None
|
|
675
|
+
self._encoding = None
|
|
676
|
+
|
|
677
|
+
@classmethod
|
|
678
|
+
def from_luatex(cls, scale, texname):
|
|
679
|
+
path_b, sep, rest = texname[1:].rpartition(b"]")
|
|
680
|
+
if not (texname.startswith(b"[") and sep and rest[:1] in [b"", b":"]):
|
|
681
|
+
raise ValueError(f"Invalid modern font name: {texname}")
|
|
682
|
+
# utf8 on Windows, not utf16!
|
|
683
|
+
path = path_b.decode("utf8") if os.name == "nt" else os.fsdecode(path_b)
|
|
684
|
+
subfont = 0
|
|
685
|
+
effects = {}
|
|
686
|
+
if rest[1:]:
|
|
687
|
+
for kv in rest[1:].decode("ascii").split(";"):
|
|
688
|
+
key, val = kv.split("=", 1)
|
|
689
|
+
if key == "index":
|
|
690
|
+
subfont = val
|
|
691
|
+
elif key in ["embolden", "slant", "extend"]:
|
|
692
|
+
effects[key] = int(val) / 65536
|
|
693
|
+
else:
|
|
694
|
+
_log.warning("Ignoring invalid key-value pair: %r", kv)
|
|
695
|
+
metrics = TtfMetrics(path)
|
|
696
|
+
font = cls(scale, metrics, texname, vf=None)
|
|
697
|
+
font._path = Path(path)
|
|
698
|
+
font.subfont = subfont
|
|
699
|
+
font.effects = effects
|
|
700
|
+
return font
|
|
701
|
+
|
|
702
|
+
@classmethod
|
|
703
|
+
def from_xetex(cls, scale, texname, subfont, effects):
|
|
704
|
+
# utf8 on Windows, not utf16!
|
|
705
|
+
path = texname.decode("utf8") if os.name == "nt" else os.fsdecode(texname)
|
|
706
|
+
metrics = TtfMetrics(path)
|
|
707
|
+
font = cls(scale, metrics, b"[" + texname + b"]", vf=None)
|
|
708
|
+
font._path = Path(path)
|
|
709
|
+
font.subfont = subfont
|
|
710
|
+
font.effects = effects
|
|
711
|
+
return font
|
|
712
|
+
|
|
713
|
+
size = property(lambda self: self._scale * (72.0 / (72.27 * 2**16)))
|
|
714
|
+
|
|
715
|
+
widths = _api.deprecated("3.11")(property(lambda self: [
|
|
716
|
+
(1000 * self._tfm.width.get(char, 0)) >> 20
|
|
717
|
+
for char in range(max(self._tfm.width, default=-1) + 1)]))
|
|
718
|
+
|
|
719
|
+
@property
|
|
720
|
+
def fname(self):
|
|
721
|
+
"""A fake filename"""
|
|
722
|
+
return self.texname.decode('latin-1')
|
|
723
|
+
|
|
724
|
+
@property
|
|
725
|
+
def face_index(self): # For compatibility with FT2Font.
|
|
726
|
+
return 0
|
|
727
|
+
|
|
728
|
+
def _get_fontmap(self, string):
|
|
729
|
+
"""Get the mapping from characters to the font that includes them.
|
|
730
|
+
|
|
731
|
+
Each value maps to self; there is no fallback mechanism for DviFont.
|
|
732
|
+
"""
|
|
733
|
+
return {char: self for char in string}
|
|
734
|
+
|
|
735
|
+
def __eq__(self, other):
|
|
736
|
+
return (type(self) is type(other)
|
|
737
|
+
and self.texname == other.texname and self.size == other.size)
|
|
738
|
+
|
|
739
|
+
def __ne__(self, other):
|
|
740
|
+
return not self.__eq__(other)
|
|
741
|
+
|
|
742
|
+
def __repr__(self):
|
|
743
|
+
return f"<{type(self).__name__}: {self.texname}>"
|
|
744
|
+
|
|
745
|
+
def _width_of(self, char):
|
|
746
|
+
"""Width of char in dvi units."""
|
|
747
|
+
metrics = self._metrics.get_metrics(char)
|
|
748
|
+
if metrics is None:
|
|
749
|
+
_log.debug('No width for char %d in font %s.', char, self.texname)
|
|
750
|
+
return 0
|
|
751
|
+
return _mul1220(metrics.tex_width, self._scale)
|
|
752
|
+
|
|
753
|
+
def _height_depth_of(self, char):
|
|
754
|
+
"""Height and depth of char in dvi units."""
|
|
755
|
+
metrics = self._metrics.get_metrics(char)
|
|
756
|
+
if metrics is None:
|
|
757
|
+
_log.debug('No metrics for char %d in font %s', char, self.texname)
|
|
758
|
+
return [0, 0]
|
|
759
|
+
hd = [
|
|
760
|
+
_mul1220(metrics.tex_height, self._scale),
|
|
761
|
+
_mul1220(metrics.tex_depth, self._scale),
|
|
762
|
+
]
|
|
763
|
+
# cmsyXX (symbols font) glyph 0 ("minus") has a nonzero descent
|
|
764
|
+
# so that TeX aligns equations properly
|
|
765
|
+
# (https://tex.stackexchange.com/q/526103/)
|
|
766
|
+
# but we actually care about the rasterization depth to align
|
|
767
|
+
# the dvipng-generated images.
|
|
768
|
+
if re.match(br'^cmsy\d+$', self.texname) and char == 0:
|
|
769
|
+
hd[-1] = 0
|
|
770
|
+
return hd
|
|
771
|
+
|
|
772
|
+
def resolve_path(self):
|
|
773
|
+
if self._path is None:
|
|
774
|
+
fontmap = PsfontsMap(find_tex_file("pdftex.map"))
|
|
775
|
+
try:
|
|
776
|
+
psfont = fontmap[self.texname]
|
|
777
|
+
except LookupError as exc:
|
|
778
|
+
try:
|
|
779
|
+
find_tex_file(f"{self.texname.decode('ascii')}.mf")
|
|
780
|
+
except FileNotFoundError:
|
|
781
|
+
raise exc from None
|
|
782
|
+
else:
|
|
783
|
+
self._path = Path(find_tex_file(
|
|
784
|
+
f"{self.texname.decode('ascii')}.600pk"))
|
|
785
|
+
else:
|
|
786
|
+
if psfont.filename is None:
|
|
787
|
+
raise ValueError("No usable font file found for {} ({}); "
|
|
788
|
+
"the font may lack a Type-1 version"
|
|
789
|
+
.format(psfont.psname.decode("ascii"),
|
|
790
|
+
psfont.texname.decode("ascii")))
|
|
791
|
+
self._path = Path(psfont.filename)
|
|
792
|
+
return self._path
|
|
793
|
+
|
|
794
|
+
@cached_property
|
|
795
|
+
def subfont(self):
|
|
796
|
+
return 0
|
|
797
|
+
|
|
798
|
+
@cached_property
|
|
799
|
+
def effects(self):
|
|
800
|
+
if self.resolve_path().match("*.600pk"):
|
|
801
|
+
return {}
|
|
802
|
+
return PsfontsMap(find_tex_file("pdftex.map"))[self.texname].effects
|
|
803
|
+
|
|
804
|
+
def _index_dvi_to_freetype(self, idx):
|
|
805
|
+
"""Convert dvi glyph indices to FreeType ones."""
|
|
806
|
+
# Glyphs indices stored in the dvi file map to FreeType glyph indices
|
|
807
|
+
# (i.e., which can be passed to FT_Load_Glyph) in various ways:
|
|
808
|
+
# - for xetex & luatex "native fonts", dvi indices are directly equal
|
|
809
|
+
# to FreeType indices.
|
|
810
|
+
# - if pdftex.map specifies an ".enc" file for the font, that file maps
|
|
811
|
+
# dvi indices to Adobe glyph names, which can then be converted to
|
|
812
|
+
# FreeType glyph indices with FT_Get_Name_Index.
|
|
813
|
+
# - if no ".enc" file is specified, then the font must be a Type 1
|
|
814
|
+
# font, and dvi indices directly index into the font's CharStrings
|
|
815
|
+
# vector.
|
|
816
|
+
if self.texname.startswith(b"["):
|
|
817
|
+
return idx
|
|
818
|
+
if self._encoding is None:
|
|
819
|
+
face = font_manager.get_font(self.resolve_path())
|
|
820
|
+
psfont = PsfontsMap(find_tex_file("pdftex.map"))[self.texname]
|
|
821
|
+
if psfont.encoding:
|
|
822
|
+
self._encoding = [face.get_name_index(name)
|
|
823
|
+
for name in _parse_enc(psfont.encoding)]
|
|
824
|
+
else:
|
|
825
|
+
self._encoding = face._get_type1_encoding_vector()
|
|
826
|
+
return self._encoding[idx]
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
class Vf(Dvi):
|
|
830
|
+
r"""
|
|
831
|
+
A virtual font (\*.vf file) containing subroutines for dvi files.
|
|
832
|
+
|
|
833
|
+
Parameters
|
|
834
|
+
----------
|
|
835
|
+
filename : str or path-like
|
|
836
|
+
|
|
837
|
+
Notes
|
|
838
|
+
-----
|
|
839
|
+
The virtual font format is a derivative of dvi:
|
|
840
|
+
http://mirrors.ctan.org/info/knuth/virtual-fonts
|
|
841
|
+
This class reuses some of the machinery of `Dvi`
|
|
842
|
+
but replaces the `!_read` loop and dispatch mechanism.
|
|
843
|
+
|
|
844
|
+
Examples
|
|
845
|
+
--------
|
|
846
|
+
::
|
|
847
|
+
|
|
848
|
+
vf = Vf(filename)
|
|
849
|
+
glyph = vf[code]
|
|
850
|
+
glyph.text, glyph.boxes, glyph.width
|
|
851
|
+
"""
|
|
852
|
+
|
|
853
|
+
def __init__(self, filename):
|
|
854
|
+
super().__init__(filename, 0)
|
|
855
|
+
try:
|
|
856
|
+
self._first_font = None
|
|
857
|
+
self._chars = {}
|
|
858
|
+
self._read()
|
|
859
|
+
finally:
|
|
860
|
+
self.close()
|
|
861
|
+
|
|
862
|
+
def __getitem__(self, code):
|
|
863
|
+
return self._chars[code]
|
|
864
|
+
|
|
865
|
+
def _read(self):
|
|
866
|
+
"""
|
|
867
|
+
Read one page from the file. Return True if successful,
|
|
868
|
+
False if there were no more pages.
|
|
869
|
+
"""
|
|
870
|
+
packet_char = packet_ends = None
|
|
871
|
+
packet_len = packet_width = None
|
|
872
|
+
while True:
|
|
873
|
+
byte = self.file.read(1)[0]
|
|
874
|
+
# If we are in a packet, execute the dvi instructions
|
|
875
|
+
if self.state is _dvistate.inpage:
|
|
876
|
+
byte_at = self.file.tell()-1
|
|
877
|
+
if byte_at == packet_ends:
|
|
878
|
+
self._finalize_packet(packet_char, packet_width)
|
|
879
|
+
packet_len = packet_char = packet_width = None
|
|
880
|
+
# fall through to out-of-packet code
|
|
881
|
+
elif byte_at > packet_ends:
|
|
882
|
+
raise ValueError("Packet length mismatch in vf file")
|
|
883
|
+
else:
|
|
884
|
+
if byte in (139, 140) or byte >= 243:
|
|
885
|
+
raise ValueError(f"Inappropriate opcode {byte} in vf file")
|
|
886
|
+
Dvi._dtable[byte](self, byte)
|
|
887
|
+
continue
|
|
888
|
+
|
|
889
|
+
# We are outside a packet
|
|
890
|
+
if byte < 242: # a short packet (length given by byte)
|
|
891
|
+
packet_len = byte
|
|
892
|
+
packet_char = self._read_arg(1)
|
|
893
|
+
packet_width = self._read_arg(3)
|
|
894
|
+
packet_ends = self._init_packet(byte)
|
|
895
|
+
self.state = _dvistate.inpage
|
|
896
|
+
elif byte == 242: # a long packet
|
|
897
|
+
packet_len = self._read_arg(4)
|
|
898
|
+
packet_char = self._read_arg(4)
|
|
899
|
+
packet_width = self._read_arg(4)
|
|
900
|
+
self._init_packet(packet_len)
|
|
901
|
+
elif 243 <= byte <= 246:
|
|
902
|
+
k = self._read_arg(byte - 242, byte == 246)
|
|
903
|
+
c = self._read_arg(4)
|
|
904
|
+
s = self._read_arg(4)
|
|
905
|
+
d = self._read_arg(4)
|
|
906
|
+
a = self._read_arg(1)
|
|
907
|
+
l = self._read_arg(1)
|
|
908
|
+
self._fnt_def_real(k, c, s, d, a, l)
|
|
909
|
+
if self._first_font is None:
|
|
910
|
+
self._first_font = k
|
|
911
|
+
elif byte == 247: # preamble
|
|
912
|
+
i = self._read_arg(1)
|
|
913
|
+
k = self._read_arg(1)
|
|
914
|
+
x = self.file.read(k)
|
|
915
|
+
cs = self._read_arg(4)
|
|
916
|
+
ds = self._read_arg(4)
|
|
917
|
+
self._pre(i, x, cs, ds)
|
|
918
|
+
elif byte == 248: # postamble (just some number of 248s)
|
|
919
|
+
break
|
|
920
|
+
else:
|
|
921
|
+
raise ValueError(f"Unknown vf opcode {byte}")
|
|
922
|
+
|
|
923
|
+
def _init_packet(self, pl):
|
|
924
|
+
if self.state != _dvistate.outer:
|
|
925
|
+
raise ValueError("Misplaced packet in vf file")
|
|
926
|
+
self.h = self.v = self.w = self.x = self.y = self.z = 0
|
|
927
|
+
self.stack = []
|
|
928
|
+
self.text = []
|
|
929
|
+
self.boxes = []
|
|
930
|
+
self.f = self._first_font
|
|
931
|
+
self._missing_font = None
|
|
932
|
+
return self.file.tell() + pl
|
|
933
|
+
|
|
934
|
+
def _finalize_packet(self, packet_char, packet_width):
|
|
935
|
+
if not self._missing_font: # Otherwise we don't have full glyph definition.
|
|
936
|
+
self._chars[packet_char] = Page(
|
|
937
|
+
text=self.text, boxes=self.boxes, width=packet_width,
|
|
938
|
+
height=None, descent=None)
|
|
939
|
+
self.state = _dvistate.outer
|
|
940
|
+
|
|
941
|
+
def _pre(self, i, x, cs, ds):
|
|
942
|
+
if self.state is not _dvistate.pre:
|
|
943
|
+
raise ValueError("pre command in middle of vf file")
|
|
944
|
+
if i != 202:
|
|
945
|
+
raise ValueError(f"Unknown vf format {i}")
|
|
946
|
+
if len(x):
|
|
947
|
+
_log.debug('vf file comment: %s', x)
|
|
948
|
+
self.state = _dvistate.outer
|
|
949
|
+
# cs = checksum, ds = design size
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
def _mul1220(num1, num2):
|
|
953
|
+
"""Multiply two numbers in 12.20 fixed point format."""
|
|
954
|
+
# Separated into a function because >> has surprising precedence
|
|
955
|
+
return (num1*num2) >> 20
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
@dataclasses.dataclass(frozen=True, kw_only=True)
|
|
959
|
+
class TexMetrics:
|
|
960
|
+
"""
|
|
961
|
+
Metrics of a glyph, with TeX semantics.
|
|
962
|
+
|
|
963
|
+
TeX metrics have different semantics from FreeType metrics: tex_width
|
|
964
|
+
corresponds to FreeType's ``advance`` (i.e., including whitespace padding);
|
|
965
|
+
tex_height to ``bearingY`` (how much the glyph extends over the baseline);
|
|
966
|
+
tex_depth to ``height - bearingY`` (how much the glyph extends under the
|
|
967
|
+
baseline, as a positive number).
|
|
968
|
+
"""
|
|
969
|
+
tex_width: int
|
|
970
|
+
tex_height: int
|
|
971
|
+
tex_depth: int
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
class Tfm:
|
|
975
|
+
"""
|
|
976
|
+
A TeX Font Metric file.
|
|
977
|
+
|
|
978
|
+
This implementation covers only the bare minimum needed by the Dvi class.
|
|
979
|
+
|
|
980
|
+
Parameters
|
|
981
|
+
----------
|
|
982
|
+
filename : str or path-like
|
|
983
|
+
|
|
984
|
+
Attributes
|
|
985
|
+
----------
|
|
986
|
+
checksum : int
|
|
987
|
+
Used for verifying against the dvi file.
|
|
988
|
+
design_size : int
|
|
989
|
+
Design size of the font (in 12.20 TeX points); unused because it is
|
|
990
|
+
overridden by the scale factor specified in the dvi file.
|
|
991
|
+
"""
|
|
992
|
+
|
|
993
|
+
def __init__(self, filename):
|
|
994
|
+
_log.debug('opening tfm file %s', filename)
|
|
995
|
+
with open(filename, 'rb') as file:
|
|
996
|
+
header1 = file.read(24)
|
|
997
|
+
lh, bc, ec, nw, nh, nd = struct.unpack('!6H', header1[2:14])
|
|
998
|
+
_log.debug('lh=%d, bc=%d, ec=%d, nw=%d, nh=%d, nd=%d',
|
|
999
|
+
lh, bc, ec, nw, nh, nd)
|
|
1000
|
+
header2 = file.read(4*lh)
|
|
1001
|
+
self.checksum, self.design_size = struct.unpack('!2I', header2[:8])
|
|
1002
|
+
# there is also encoding information etc.
|
|
1003
|
+
char_info = file.read(4*(ec-bc+1))
|
|
1004
|
+
widths = struct.unpack(f'!{nw}i', file.read(4*nw))
|
|
1005
|
+
heights = struct.unpack(f'!{nh}i', file.read(4*nh))
|
|
1006
|
+
depths = struct.unpack(f'!{nd}i', file.read(4*nd))
|
|
1007
|
+
self._glyph_metrics = {}
|
|
1008
|
+
for idx, char in enumerate(range(bc, ec+1)):
|
|
1009
|
+
byte0 = char_info[4*idx]
|
|
1010
|
+
byte1 = char_info[4*idx+1]
|
|
1011
|
+
self._glyph_metrics[char] = TexMetrics(
|
|
1012
|
+
tex_width=widths[byte0],
|
|
1013
|
+
tex_height=heights[byte1 >> 4],
|
|
1014
|
+
tex_depth=depths[byte1 & 0xf],
|
|
1015
|
+
)
|
|
1016
|
+
|
|
1017
|
+
def get_metrics(self, idx):
|
|
1018
|
+
"""Return a glyph's TexMetrics, or None if unavailable."""
|
|
1019
|
+
return self._glyph_metrics.get(idx)
|
|
1020
|
+
|
|
1021
|
+
width = _api.deprecated("3.11", alternative="get_metrics")(
|
|
1022
|
+
property(lambda self: {c: m.tex_width for c, m in self._glyph_metrics}))
|
|
1023
|
+
height = _api.deprecated("3.11", alternative="get_metrics")(
|
|
1024
|
+
property(lambda self: {c: m.tex_height for c, m in self._glyph_metrics}))
|
|
1025
|
+
depth = _api.deprecated("3.11", alternative="get_metrics")(
|
|
1026
|
+
property(lambda self: {c: m.tex_depth for c, m in self._glyph_metrics}))
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
class TtfMetrics:
|
|
1030
|
+
def __init__(self, filename):
|
|
1031
|
+
self._face = font_manager.get_font(filename)
|
|
1032
|
+
|
|
1033
|
+
def get_metrics(self, idx):
|
|
1034
|
+
# _mul1220 uses a truncating bitshift for compatibility with dvitype.
|
|
1035
|
+
# When upem is 2048 the conversion to 12.20 is exact, but when
|
|
1036
|
+
# upem is 1000 (e.g. lmroman10-regular.otf) the metrics themselves
|
|
1037
|
+
# are not exactly representable as 12.20 fp. Manual testing via
|
|
1038
|
+
# \sbox0{x}\count0=\wd0\typeout{\the\count0} suggests that metrics
|
|
1039
|
+
# are rounded (not truncated) after conversion to 12.20 and before
|
|
1040
|
+
# multiplication by the scale.
|
|
1041
|
+
upem = self._face.units_per_EM # Usually 2048 or 1000.
|
|
1042
|
+
g = self._face.load_glyph(idx, LoadFlags.NO_SCALE)
|
|
1043
|
+
return TexMetrics(
|
|
1044
|
+
tex_width=round(g.horiAdvance / upem * 2**20),
|
|
1045
|
+
tex_height=round(g.horiBearingY / upem * 2**20),
|
|
1046
|
+
tex_depth=round((g.height - g.horiBearingY) / upem * 2**20),
|
|
1047
|
+
)
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
PsFont = namedtuple('PsFont', 'texname psname effects encoding filename')
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
class PsfontsMap:
|
|
1054
|
+
"""
|
|
1055
|
+
A psfonts.map formatted file, mapping TeX fonts to PS fonts.
|
|
1056
|
+
|
|
1057
|
+
Parameters
|
|
1058
|
+
----------
|
|
1059
|
+
filename : str or path-like
|
|
1060
|
+
|
|
1061
|
+
Notes
|
|
1062
|
+
-----
|
|
1063
|
+
For historical reasons, TeX knows many Type-1 fonts by different
|
|
1064
|
+
names than the outside world. (For one thing, the names have to
|
|
1065
|
+
fit in eight characters.) Also, TeX's native fonts are not Type-1
|
|
1066
|
+
but Metafont, which is nontrivial to convert to PostScript except
|
|
1067
|
+
as a bitmap. While high-quality conversions to Type-1 format exist
|
|
1068
|
+
and are shipped with modern TeX distributions, we need to know
|
|
1069
|
+
which Type-1 fonts are the counterparts of which native fonts. For
|
|
1070
|
+
these reasons a mapping is needed from internal font names to font
|
|
1071
|
+
file names.
|
|
1072
|
+
|
|
1073
|
+
A texmf tree typically includes mapping files called e.g.
|
|
1074
|
+
:file:`psfonts.map`, :file:`pdftex.map`, or :file:`dvipdfm.map`.
|
|
1075
|
+
The file :file:`psfonts.map` is used by :program:`dvips`,
|
|
1076
|
+
:file:`pdftex.map` by :program:`pdfTeX`, and :file:`dvipdfm.map`
|
|
1077
|
+
by :program:`dvipdfm`. :file:`psfonts.map` might avoid embedding
|
|
1078
|
+
the 35 PostScript fonts (i.e., have no filename for them, as in
|
|
1079
|
+
the Times-Bold example above), while the pdf-related files perhaps
|
|
1080
|
+
only avoid the "Base 14" pdf fonts. But the user may have
|
|
1081
|
+
configured these files differently.
|
|
1082
|
+
|
|
1083
|
+
Examples
|
|
1084
|
+
--------
|
|
1085
|
+
>>> map = PsfontsMap(find_tex_file('pdftex.map'))
|
|
1086
|
+
>>> entry = map[b'ptmbo8r']
|
|
1087
|
+
>>> entry.texname
|
|
1088
|
+
b'ptmbo8r'
|
|
1089
|
+
>>> entry.psname
|
|
1090
|
+
b'Times-Bold'
|
|
1091
|
+
>>> entry.encoding
|
|
1092
|
+
'/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc'
|
|
1093
|
+
>>> entry.effects
|
|
1094
|
+
{'slant': 0.16700000000000001}
|
|
1095
|
+
>>> entry.filename
|
|
1096
|
+
"""
|
|
1097
|
+
__slots__ = ('_filename', '_unparsed', '_parsed')
|
|
1098
|
+
|
|
1099
|
+
# Create a filename -> PsfontsMap cache, so that calling
|
|
1100
|
+
# `PsfontsMap(filename)` with the same filename a second time immediately
|
|
1101
|
+
# returns the same object.
|
|
1102
|
+
@lru_cache
|
|
1103
|
+
def __new__(cls, filename):
|
|
1104
|
+
self = object.__new__(cls)
|
|
1105
|
+
self._filename = os.fsdecode(filename)
|
|
1106
|
+
# Some TeX distributions have enormous pdftex.map files which would
|
|
1107
|
+
# take hundreds of milliseconds to parse, but it is easy enough to just
|
|
1108
|
+
# store the unparsed lines (keyed by the first word, which is the
|
|
1109
|
+
# texname) and parse them on-demand.
|
|
1110
|
+
with open(filename, 'rb') as file:
|
|
1111
|
+
self._unparsed = {}
|
|
1112
|
+
for line in file:
|
|
1113
|
+
tfmname = line.split(b' ', 1)[0]
|
|
1114
|
+
self._unparsed.setdefault(tfmname, []).append(line)
|
|
1115
|
+
self._parsed = {}
|
|
1116
|
+
return self
|
|
1117
|
+
|
|
1118
|
+
def __getitem__(self, texname):
|
|
1119
|
+
assert isinstance(texname, bytes)
|
|
1120
|
+
if texname in self._unparsed:
|
|
1121
|
+
for line in self._unparsed.pop(texname):
|
|
1122
|
+
if self._parse_and_cache_line(line):
|
|
1123
|
+
break
|
|
1124
|
+
try:
|
|
1125
|
+
return self._parsed[texname]
|
|
1126
|
+
except KeyError:
|
|
1127
|
+
raise LookupError(
|
|
1128
|
+
f"The font map {self._filename!r} is missing a PostScript font "
|
|
1129
|
+
f"associated to TeX font {texname.decode('ascii')!r}; this problem can "
|
|
1130
|
+
f"often be solved by installing a suitable PostScript font package in "
|
|
1131
|
+
f"your TeX package manager") from None
|
|
1132
|
+
|
|
1133
|
+
def _parse_and_cache_line(self, line):
|
|
1134
|
+
"""
|
|
1135
|
+
Parse a line in the font mapping file.
|
|
1136
|
+
|
|
1137
|
+
The format is (partially) documented at
|
|
1138
|
+
http://mirrors.ctan.org/systems/doc/pdftex/manual/pdftex-a.pdf
|
|
1139
|
+
https://tug.org/texinfohtml/dvips.html#psfonts_002emap
|
|
1140
|
+
Each line can have the following fields:
|
|
1141
|
+
|
|
1142
|
+
- tfmname (first, only required field),
|
|
1143
|
+
- psname (defaults to tfmname, must come immediately after tfmname if
|
|
1144
|
+
present),
|
|
1145
|
+
- fontflags (integer, must come immediately after psname if present,
|
|
1146
|
+
ignored by us),
|
|
1147
|
+
- special (SlantFont and ExtendFont, only field that is double-quoted),
|
|
1148
|
+
- fontfile, encodingfile (optional, prefixed by <, <<, or <[; << always
|
|
1149
|
+
precedes a font, <[ always precedes an encoding, < can precede either
|
|
1150
|
+
but then an encoding file must have extension .enc; < and << also
|
|
1151
|
+
request different font subsetting behaviors but we ignore that; < can
|
|
1152
|
+
be separated from the filename by whitespace).
|
|
1153
|
+
|
|
1154
|
+
special, fontfile, and encodingfile can appear in any order.
|
|
1155
|
+
"""
|
|
1156
|
+
# If the map file specifies multiple encodings for a font, we
|
|
1157
|
+
# follow pdfTeX in choosing the last one specified. Such
|
|
1158
|
+
# entries are probably mistakes but they have occurred.
|
|
1159
|
+
# https://tex.stackexchange.com/q/10826/
|
|
1160
|
+
|
|
1161
|
+
if not line or line.startswith((b" ", b"%", b"*", b";", b"#")):
|
|
1162
|
+
return
|
|
1163
|
+
tfmname = basename = special = encodingfile = fontfile = None
|
|
1164
|
+
is_subsetted = is_t1 = is_truetype = False
|
|
1165
|
+
matches = re.finditer(br'"([^"]*)(?:"|$)|(\S+)', line)
|
|
1166
|
+
for match in matches:
|
|
1167
|
+
quoted, unquoted = match.groups()
|
|
1168
|
+
if unquoted:
|
|
1169
|
+
if unquoted.startswith(b"<<"): # font
|
|
1170
|
+
fontfile = unquoted[2:]
|
|
1171
|
+
elif unquoted.startswith(b"<["): # encoding
|
|
1172
|
+
encodingfile = unquoted[2:]
|
|
1173
|
+
elif unquoted.startswith(b"<"): # font or encoding
|
|
1174
|
+
word = (
|
|
1175
|
+
# <foo => foo
|
|
1176
|
+
unquoted[1:]
|
|
1177
|
+
# < by itself => read the next word
|
|
1178
|
+
or next(filter(None, next(matches).groups())))
|
|
1179
|
+
if word.endswith(b".enc"):
|
|
1180
|
+
encodingfile = word
|
|
1181
|
+
else:
|
|
1182
|
+
fontfile = word
|
|
1183
|
+
is_subsetted = True
|
|
1184
|
+
elif tfmname is None:
|
|
1185
|
+
tfmname = unquoted
|
|
1186
|
+
elif basename is None:
|
|
1187
|
+
basename = unquoted
|
|
1188
|
+
elif quoted:
|
|
1189
|
+
special = quoted
|
|
1190
|
+
effects = {}
|
|
1191
|
+
if special:
|
|
1192
|
+
words = reversed(special.split())
|
|
1193
|
+
for word in words:
|
|
1194
|
+
if word == b"SlantFont":
|
|
1195
|
+
effects["slant"] = float(next(words))
|
|
1196
|
+
elif word == b"ExtendFont":
|
|
1197
|
+
effects["extend"] = float(next(words))
|
|
1198
|
+
|
|
1199
|
+
# Verify some properties of the line that would cause it to be ignored
|
|
1200
|
+
# otherwise.
|
|
1201
|
+
if fontfile is not None:
|
|
1202
|
+
if fontfile.endswith((b".ttf", b".ttc")):
|
|
1203
|
+
is_truetype = True
|
|
1204
|
+
elif not fontfile.endswith(b".otf"):
|
|
1205
|
+
is_t1 = True
|
|
1206
|
+
elif basename is not None:
|
|
1207
|
+
is_t1 = True
|
|
1208
|
+
if is_truetype and is_subsetted and encodingfile is None:
|
|
1209
|
+
return
|
|
1210
|
+
if not is_t1 and ("slant" in effects or "extend" in effects):
|
|
1211
|
+
return
|
|
1212
|
+
if abs(effects.get("slant", 0)) > 1:
|
|
1213
|
+
return
|
|
1214
|
+
if abs(effects.get("extend", 0)) > 2:
|
|
1215
|
+
return
|
|
1216
|
+
|
|
1217
|
+
if basename is None:
|
|
1218
|
+
basename = tfmname
|
|
1219
|
+
if encodingfile is not None:
|
|
1220
|
+
encodingfile = find_tex_file(encodingfile)
|
|
1221
|
+
if fontfile is not None:
|
|
1222
|
+
fontfile = find_tex_file(fontfile)
|
|
1223
|
+
self._parsed[tfmname] = PsFont(
|
|
1224
|
+
texname=tfmname, psname=basename, effects=effects,
|
|
1225
|
+
encoding=encodingfile, filename=fontfile)
|
|
1226
|
+
return True
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
def _parse_enc(path):
|
|
1230
|
+
r"""
|
|
1231
|
+
Parse a \*.enc file referenced from a psfonts.map style file.
|
|
1232
|
+
|
|
1233
|
+
The format supported by this function is a tiny subset of PostScript.
|
|
1234
|
+
|
|
1235
|
+
Parameters
|
|
1236
|
+
----------
|
|
1237
|
+
path : `os.PathLike`
|
|
1238
|
+
|
|
1239
|
+
Returns
|
|
1240
|
+
-------
|
|
1241
|
+
list
|
|
1242
|
+
The nth list item is the PostScript glyph name of the nth glyph.
|
|
1243
|
+
"""
|
|
1244
|
+
no_comments = re.sub("%.*", "", Path(path).read_text(encoding="ascii"))
|
|
1245
|
+
array = re.search(r"(?s)\[(.*)\]", no_comments).group(1)
|
|
1246
|
+
lines = [line for line in array.split() if line]
|
|
1247
|
+
if all(line.startswith("/") for line in lines):
|
|
1248
|
+
return [line[1:] for line in lines]
|
|
1249
|
+
else:
|
|
1250
|
+
raise ValueError(f"Failed to parse {path} as Postscript encoding")
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
class _LuatexKpsewhich:
|
|
1254
|
+
@cache # A singleton.
|
|
1255
|
+
def __new__(cls):
|
|
1256
|
+
self = object.__new__(cls)
|
|
1257
|
+
self._proc = self._new_proc()
|
|
1258
|
+
return self
|
|
1259
|
+
|
|
1260
|
+
def _new_proc(self):
|
|
1261
|
+
return subprocess.Popen(
|
|
1262
|
+
["luatex", "--luaonly", str(cbook._get_data_path("kpsewhich.lua"))],
|
|
1263
|
+
# mktexpk logs to stderr; suppress that.
|
|
1264
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
|
|
1265
|
+
# Store generated pk fonts in our own cache.
|
|
1266
|
+
env={"MT_VARTEXFONTS": str(Path(mpl.get_cachedir(), "vartexfonts")),
|
|
1267
|
+
**os.environ})
|
|
1268
|
+
|
|
1269
|
+
def search(self, filename):
|
|
1270
|
+
if self._proc.poll() is not None: # Dead, restart it.
|
|
1271
|
+
self._proc = self._new_proc()
|
|
1272
|
+
self._proc.stdin.write(os.fsencode(filename) + b"\n")
|
|
1273
|
+
self._proc.stdin.flush()
|
|
1274
|
+
out = self._proc.stdout.readline().rstrip()
|
|
1275
|
+
return None if out == b"nil" else os.fsdecode(out)
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
@lru_cache
|
|
1279
|
+
def find_tex_file(filename):
|
|
1280
|
+
"""
|
|
1281
|
+
Find a file in the texmf tree using kpathsea_.
|
|
1282
|
+
|
|
1283
|
+
The kpathsea library, provided by most existing TeX distributions, both
|
|
1284
|
+
on Unix-like systems and on Windows (MikTeX), is invoked via a long-lived
|
|
1285
|
+
luatex process if luatex is installed, or via kpsewhich otherwise.
|
|
1286
|
+
|
|
1287
|
+
.. _kpathsea: https://www.tug.org/kpathsea/
|
|
1288
|
+
|
|
1289
|
+
Parameters
|
|
1290
|
+
----------
|
|
1291
|
+
filename : str or path-like
|
|
1292
|
+
|
|
1293
|
+
Raises
|
|
1294
|
+
------
|
|
1295
|
+
FileNotFoundError
|
|
1296
|
+
If the file is not found.
|
|
1297
|
+
"""
|
|
1298
|
+
|
|
1299
|
+
# we expect these to always be ascii encoded, but use utf-8
|
|
1300
|
+
# out of caution
|
|
1301
|
+
if isinstance(filename, bytes):
|
|
1302
|
+
filename = filename.decode('utf-8', errors='replace')
|
|
1303
|
+
|
|
1304
|
+
try:
|
|
1305
|
+
lk = _LuatexKpsewhich()
|
|
1306
|
+
except (FileNotFoundError, OSError):
|
|
1307
|
+
lk = None # Fallback to directly calling kpsewhich, as below.
|
|
1308
|
+
|
|
1309
|
+
if lk:
|
|
1310
|
+
path = lk.search(filename)
|
|
1311
|
+
else:
|
|
1312
|
+
if sys.platform == 'win32':
|
|
1313
|
+
# On Windows only, kpathsea can use utf-8 for cmd args and output.
|
|
1314
|
+
# The `command_line_encoding` environment variable is set to force
|
|
1315
|
+
# it to always use utf-8 encoding. See Matplotlib issue #11848.
|
|
1316
|
+
kwargs = {'env': {**os.environ, 'command_line_encoding': 'utf-8'},
|
|
1317
|
+
'encoding': 'utf-8'}
|
|
1318
|
+
else: # On POSIX, run through the equivalent of os.fsdecode().
|
|
1319
|
+
kwargs = {'env': {**os.environ},
|
|
1320
|
+
'encoding': sys.getfilesystemencoding(),
|
|
1321
|
+
'errors': 'surrogateescape'}
|
|
1322
|
+
kwargs['env'].update(
|
|
1323
|
+
MT_VARTEXFONTS=str(Path(mpl.get_cachedir(), "vartexfonts")))
|
|
1324
|
+
|
|
1325
|
+
try:
|
|
1326
|
+
path = cbook._check_and_log_subprocess(
|
|
1327
|
+
['kpsewhich', '-mktex=pk', filename], _log, **kwargs,
|
|
1328
|
+
).rstrip('\n')
|
|
1329
|
+
except (FileNotFoundError, OSError, RuntimeError):
|
|
1330
|
+
path = None
|
|
1331
|
+
|
|
1332
|
+
if path:
|
|
1333
|
+
return path
|
|
1334
|
+
else:
|
|
1335
|
+
raise FileNotFoundError(
|
|
1336
|
+
f"Matplotlib's TeX implementation searched for a file named "
|
|
1337
|
+
f"{filename!r} in your texmf tree, but could not find it")
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
@lru_cache
|
|
1341
|
+
def _fontfile(cls, suffix, texname):
|
|
1342
|
+
return cls(find_tex_file(texname + suffix))
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
_tfmfile = partial(_fontfile, Tfm, ".tfm")
|
|
1346
|
+
_vffile = partial(_fontfile, Vf, ".vf")
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
if __name__ == '__main__':
|
|
1350
|
+
import itertools
|
|
1351
|
+
from argparse import ArgumentParser
|
|
1352
|
+
|
|
1353
|
+
parser = ArgumentParser()
|
|
1354
|
+
parser.add_argument("filename")
|
|
1355
|
+
parser.add_argument("dpi", nargs="?", type=float, default=None)
|
|
1356
|
+
parser.add_argument("-d", "--debug", action="store_true")
|
|
1357
|
+
args = parser.parse_args()
|
|
1358
|
+
|
|
1359
|
+
if args.debug:
|
|
1360
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
1361
|
+
|
|
1362
|
+
def _print_fields(*args):
|
|
1363
|
+
print(" ".join(map("{:>11}".format, args)))
|
|
1364
|
+
|
|
1365
|
+
with Dvi(args.filename, args.dpi) as dvi:
|
|
1366
|
+
for page in dvi:
|
|
1367
|
+
print(f"=== NEW PAGE === "
|
|
1368
|
+
f"(w: {page.width}, h: {page.height}, d: {page.descent})")
|
|
1369
|
+
print("--- GLYPHS ---")
|
|
1370
|
+
for font, group in itertools.groupby(page.text, lambda text: text.font):
|
|
1371
|
+
font_name = (font.texname.decode("utf8") if os.name == "nt"
|
|
1372
|
+
else os.fsdecode(font.texname))
|
|
1373
|
+
if isinstance(font._metrics, Tfm):
|
|
1374
|
+
print(f"font: {font_name} at {font.resolve_path()}")
|
|
1375
|
+
else:
|
|
1376
|
+
print(f"font: {font_name}")
|
|
1377
|
+
print(f"scale: {font._scale / 2 ** 20}")
|
|
1378
|
+
_print_fields("x", "y", "glyph", "chr", "w")
|
|
1379
|
+
for text in group:
|
|
1380
|
+
_print_fields(text.x, text.y, text.glyph,
|
|
1381
|
+
text._as_unicode_or_name(), text.width)
|
|
1382
|
+
if page.boxes:
|
|
1383
|
+
print("--- BOXES ---")
|
|
1384
|
+
_print_fields("x", "y", "h", "w")
|
|
1385
|
+
for box in page.boxes:
|
|
1386
|
+
_print_fields(box.x, box.y, box.height, box.width)
|