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
|
@@ -0,0 +1,1228 @@
|
|
|
1
|
+
# Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
|
|
2
|
+
"""
|
|
3
|
+
A class representing a Type 1 font.
|
|
4
|
+
|
|
5
|
+
This version reads pfa and pfb files and splits them for embedding in
|
|
6
|
+
pdf files. It also supports SlantFont and ExtendFont transformations,
|
|
7
|
+
similarly to pdfTeX and friends.
|
|
8
|
+
|
|
9
|
+
Usage::
|
|
10
|
+
|
|
11
|
+
font = Type1Font(filename)
|
|
12
|
+
clear_part, encrypted_part, finale = font.parts
|
|
13
|
+
slanted_font = font.transform({'slant': 0.167})
|
|
14
|
+
extended_font = font.transform({'extend': 1.2})
|
|
15
|
+
subset_font = font.subset([ord(c) for c in 'Hello World'])
|
|
16
|
+
|
|
17
|
+
Sources:
|
|
18
|
+
|
|
19
|
+
* Adobe Technical Note #5040, Supporting Downloadable PostScript
|
|
20
|
+
Language Fonts.
|
|
21
|
+
|
|
22
|
+
* Adobe Type 1 Font Format, Adobe Systems Incorporated, third printing,
|
|
23
|
+
v1.1, 1993. ISBN 0-201-57044-0.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
import binascii
|
|
29
|
+
import functools
|
|
30
|
+
import itertools
|
|
31
|
+
import logging
|
|
32
|
+
import re
|
|
33
|
+
import string
|
|
34
|
+
import struct
|
|
35
|
+
import typing as T
|
|
36
|
+
|
|
37
|
+
import numpy as np
|
|
38
|
+
|
|
39
|
+
from matplotlib_rs.cbook import _format_approx
|
|
40
|
+
from . import _api
|
|
41
|
+
|
|
42
|
+
_log = logging.getLogger(__name__)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class _Token:
|
|
46
|
+
"""
|
|
47
|
+
A token in a PostScript stream.
|
|
48
|
+
|
|
49
|
+
Attributes
|
|
50
|
+
----------
|
|
51
|
+
pos : int
|
|
52
|
+
Position, i.e. offset from the beginning of the data.
|
|
53
|
+
raw : str
|
|
54
|
+
Raw text of the token.
|
|
55
|
+
kind : str
|
|
56
|
+
Description of the token (for debugging or testing).
|
|
57
|
+
"""
|
|
58
|
+
__slots__ = ('pos', 'raw')
|
|
59
|
+
kind = '?'
|
|
60
|
+
|
|
61
|
+
def __init__(self, pos, raw):
|
|
62
|
+
_log.debug('type1font._Token %s at %d: %r', self.kind, pos, raw)
|
|
63
|
+
self.pos = pos
|
|
64
|
+
self.raw = raw
|
|
65
|
+
|
|
66
|
+
def __str__(self):
|
|
67
|
+
return f"<{self.kind} {self.raw} @{self.pos}>"
|
|
68
|
+
|
|
69
|
+
def endpos(self):
|
|
70
|
+
"""Position one past the end of the token"""
|
|
71
|
+
return self.pos + len(self.raw)
|
|
72
|
+
|
|
73
|
+
def is_keyword(self, *names):
|
|
74
|
+
"""Is this a name token with one of the names?"""
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
def is_slash_name(self):
|
|
78
|
+
"""Is this a name token that starts with a slash?"""
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
def is_delim(self):
|
|
82
|
+
"""Is this a delimiter token?"""
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
def is_number(self):
|
|
86
|
+
"""Is this a number token?"""
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
def value(self):
|
|
90
|
+
return self.raw
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class _NameToken(_Token):
|
|
94
|
+
kind = 'name'
|
|
95
|
+
|
|
96
|
+
def is_slash_name(self):
|
|
97
|
+
return self.raw.startswith('/')
|
|
98
|
+
|
|
99
|
+
def value(self):
|
|
100
|
+
return self.raw[1:]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class _BooleanToken(_Token):
|
|
104
|
+
kind = 'boolean'
|
|
105
|
+
|
|
106
|
+
def value(self):
|
|
107
|
+
return self.raw == 'true'
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class _KeywordToken(_Token):
|
|
111
|
+
kind = 'keyword'
|
|
112
|
+
|
|
113
|
+
def is_keyword(self, *names):
|
|
114
|
+
return self.raw in names
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class _DelimiterToken(_Token):
|
|
118
|
+
kind = 'delimiter'
|
|
119
|
+
|
|
120
|
+
def is_delim(self):
|
|
121
|
+
return True
|
|
122
|
+
|
|
123
|
+
def opposite(self):
|
|
124
|
+
return {'[': ']', ']': '[',
|
|
125
|
+
'{': '}', '}': '{',
|
|
126
|
+
'<<': '>>', '>>': '<<'
|
|
127
|
+
}[self.raw]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class _WhitespaceToken(_Token):
|
|
131
|
+
kind = 'whitespace'
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class _StringToken(_Token):
|
|
135
|
+
kind = 'string'
|
|
136
|
+
_escapes_re = re.compile(r'\\([\\()nrtbf]|[0-7]{1,3})')
|
|
137
|
+
_replacements = {'\\': '\\', '(': '(', ')': ')', 'n': '\n',
|
|
138
|
+
'r': '\r', 't': '\t', 'b': '\b', 'f': '\f'}
|
|
139
|
+
_ws_re = re.compile('[\0\t\r\f\n ]')
|
|
140
|
+
|
|
141
|
+
@classmethod
|
|
142
|
+
def _escape(cls, match):
|
|
143
|
+
group = match.group(1)
|
|
144
|
+
try:
|
|
145
|
+
return cls._replacements[group]
|
|
146
|
+
except KeyError:
|
|
147
|
+
return chr(int(group, 8))
|
|
148
|
+
|
|
149
|
+
@functools.lru_cache
|
|
150
|
+
def value(self):
|
|
151
|
+
if self.raw[0] == '(':
|
|
152
|
+
return self._escapes_re.sub(self._escape, self.raw[1:-1])
|
|
153
|
+
else:
|
|
154
|
+
data = self._ws_re.sub('', self.raw[1:-1])
|
|
155
|
+
if len(data) % 2 == 1:
|
|
156
|
+
data += '0'
|
|
157
|
+
return binascii.unhexlify(data)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class _BinaryToken(_Token):
|
|
161
|
+
kind = 'binary'
|
|
162
|
+
|
|
163
|
+
def value(self):
|
|
164
|
+
return self.raw[1:]
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class _NumberToken(_Token):
|
|
168
|
+
kind = 'number'
|
|
169
|
+
|
|
170
|
+
def is_number(self):
|
|
171
|
+
return True
|
|
172
|
+
|
|
173
|
+
def value(self):
|
|
174
|
+
if '.' not in self.raw:
|
|
175
|
+
return int(self.raw)
|
|
176
|
+
else:
|
|
177
|
+
return float(self.raw)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _tokenize(data: bytes, skip_ws: bool) -> T.Generator[_Token, int, None]:
|
|
181
|
+
"""
|
|
182
|
+
A generator that produces _Token instances from Type-1 font code.
|
|
183
|
+
|
|
184
|
+
The consumer of the generator may send an integer to the tokenizer to
|
|
185
|
+
indicate that the next token should be _BinaryToken of the given length.
|
|
186
|
+
|
|
187
|
+
Parameters
|
|
188
|
+
----------
|
|
189
|
+
data : bytes
|
|
190
|
+
The data of the font to tokenize.
|
|
191
|
+
|
|
192
|
+
skip_ws : bool
|
|
193
|
+
If true, the generator will drop any _WhitespaceTokens from the output.
|
|
194
|
+
"""
|
|
195
|
+
|
|
196
|
+
text = data.decode('ascii', 'replace')
|
|
197
|
+
whitespace_or_comment_re = re.compile(r'[\0\t\r\f\n ]+|%[^\r\n]*')
|
|
198
|
+
token_re = re.compile(r'/{0,2}[^]\0\t\r\f\n ()<>{}/%[]+')
|
|
199
|
+
instring_re = re.compile(r'[()\\]')
|
|
200
|
+
hex_re = re.compile(r'^<[0-9a-fA-F\0\t\r\f\n ]*>$')
|
|
201
|
+
oct_re = re.compile(r'[0-7]{1,3}')
|
|
202
|
+
pos = 0
|
|
203
|
+
next_binary: int | None = None
|
|
204
|
+
|
|
205
|
+
while pos < len(text):
|
|
206
|
+
if next_binary is not None:
|
|
207
|
+
n = next_binary
|
|
208
|
+
next_binary = (yield _BinaryToken(pos, data[pos:pos+n]))
|
|
209
|
+
pos += n
|
|
210
|
+
continue
|
|
211
|
+
match = whitespace_or_comment_re.match(text, pos)
|
|
212
|
+
if match:
|
|
213
|
+
if not skip_ws:
|
|
214
|
+
next_binary = (yield _WhitespaceToken(pos, match.group()))
|
|
215
|
+
pos = match.end()
|
|
216
|
+
elif text[pos] == '(':
|
|
217
|
+
# PostScript string rules:
|
|
218
|
+
# - parentheses must be balanced
|
|
219
|
+
# - backslashes escape backslashes and parens
|
|
220
|
+
# - also codes \n\r\t\b\f and octal escapes are recognized
|
|
221
|
+
# - other backslashes do not escape anything
|
|
222
|
+
start = pos
|
|
223
|
+
pos += 1
|
|
224
|
+
depth = 1
|
|
225
|
+
while depth:
|
|
226
|
+
match = instring_re.search(text, pos)
|
|
227
|
+
if match is None:
|
|
228
|
+
raise ValueError(
|
|
229
|
+
f'Unterminated string starting at {start}')
|
|
230
|
+
pos = match.end()
|
|
231
|
+
if match.group() == '(':
|
|
232
|
+
depth += 1
|
|
233
|
+
elif match.group() == ')':
|
|
234
|
+
depth -= 1
|
|
235
|
+
else: # a backslash
|
|
236
|
+
char = text[pos]
|
|
237
|
+
if char in r'\()nrtbf':
|
|
238
|
+
pos += 1
|
|
239
|
+
else:
|
|
240
|
+
octal = oct_re.match(text, pos)
|
|
241
|
+
if octal:
|
|
242
|
+
pos = octal.end()
|
|
243
|
+
else:
|
|
244
|
+
pass # non-escaping backslash
|
|
245
|
+
next_binary = (yield _StringToken(start, text[start:pos]))
|
|
246
|
+
elif text[pos:pos + 2] in ('<<', '>>'):
|
|
247
|
+
next_binary = (yield _DelimiterToken(pos, text[pos:pos + 2]))
|
|
248
|
+
pos += 2
|
|
249
|
+
elif text[pos] == '<':
|
|
250
|
+
start = pos
|
|
251
|
+
try:
|
|
252
|
+
pos = text.index('>', pos) + 1
|
|
253
|
+
except ValueError as e:
|
|
254
|
+
raise ValueError(f'Unterminated hex string starting at {start}'
|
|
255
|
+
) from e
|
|
256
|
+
if not hex_re.match(text[start:pos]):
|
|
257
|
+
raise ValueError(f'Malformed hex string starting at {start}')
|
|
258
|
+
next_binary = (yield _StringToken(pos, text[start:pos]))
|
|
259
|
+
else:
|
|
260
|
+
match = token_re.match(text, pos)
|
|
261
|
+
if match:
|
|
262
|
+
raw = match.group()
|
|
263
|
+
if raw.startswith('/'):
|
|
264
|
+
next_binary = (yield _NameToken(pos, raw))
|
|
265
|
+
elif match.group() in ('true', 'false'):
|
|
266
|
+
next_binary = (yield _BooleanToken(pos, raw))
|
|
267
|
+
else:
|
|
268
|
+
try:
|
|
269
|
+
float(raw)
|
|
270
|
+
next_binary = (yield _NumberToken(pos, raw))
|
|
271
|
+
except ValueError:
|
|
272
|
+
next_binary = (yield _KeywordToken(pos, raw))
|
|
273
|
+
pos = match.end()
|
|
274
|
+
else:
|
|
275
|
+
next_binary = (yield _DelimiterToken(pos, text[pos]))
|
|
276
|
+
pos += 1
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class _BalancedExpression(_Token):
|
|
280
|
+
pass
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _expression(initial, tokens, data):
|
|
284
|
+
"""
|
|
285
|
+
Consume some number of tokens and return a balanced PostScript expression.
|
|
286
|
+
|
|
287
|
+
Parameters
|
|
288
|
+
----------
|
|
289
|
+
initial : _Token
|
|
290
|
+
The token that triggered parsing a balanced expression.
|
|
291
|
+
tokens : iterator of _Token
|
|
292
|
+
Following tokens.
|
|
293
|
+
data : bytes
|
|
294
|
+
Underlying data that the token positions point to.
|
|
295
|
+
|
|
296
|
+
Returns
|
|
297
|
+
-------
|
|
298
|
+
_BalancedExpression
|
|
299
|
+
"""
|
|
300
|
+
delim_stack = []
|
|
301
|
+
token = initial
|
|
302
|
+
while True:
|
|
303
|
+
if token.is_delim():
|
|
304
|
+
if token.raw in ('[', '{'):
|
|
305
|
+
delim_stack.append(token)
|
|
306
|
+
elif token.raw in (']', '}'):
|
|
307
|
+
if not delim_stack:
|
|
308
|
+
raise RuntimeError(f"unmatched closing token {token}")
|
|
309
|
+
match = delim_stack.pop()
|
|
310
|
+
if match.raw != token.opposite():
|
|
311
|
+
raise RuntimeError(
|
|
312
|
+
f"opening token {match} closed by {token}"
|
|
313
|
+
)
|
|
314
|
+
if not delim_stack:
|
|
315
|
+
break
|
|
316
|
+
else:
|
|
317
|
+
raise RuntimeError(f'unknown delimiter {token}')
|
|
318
|
+
elif not delim_stack:
|
|
319
|
+
break
|
|
320
|
+
token = next(tokens)
|
|
321
|
+
return _BalancedExpression(
|
|
322
|
+
initial.pos,
|
|
323
|
+
data[initial.pos:token.endpos()].decode('ascii', 'replace')
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
class Type1Font:
|
|
328
|
+
"""
|
|
329
|
+
A class representing a Type-1 font, for use by backends.
|
|
330
|
+
|
|
331
|
+
Attributes
|
|
332
|
+
----------
|
|
333
|
+
parts : tuple
|
|
334
|
+
A 3-tuple of the cleartext part, the encrypted part, and the finale of
|
|
335
|
+
zeros.
|
|
336
|
+
|
|
337
|
+
decrypted : bytes
|
|
338
|
+
The decrypted form of ``parts[1]``.
|
|
339
|
+
|
|
340
|
+
prop : dict[str, Any]
|
|
341
|
+
A dictionary of font properties. Noteworthy keys include:
|
|
342
|
+
|
|
343
|
+
- FontName: PostScript name of the font
|
|
344
|
+
- Encoding: dict from numeric codes to glyph names
|
|
345
|
+
- FontMatrix: bytes object encoding a matrix
|
|
346
|
+
- UniqueID: optional font identifier, dropped when modifying the font
|
|
347
|
+
- CharStrings: dict from glyph names to byte code
|
|
348
|
+
- Subrs: array of byte code subroutines
|
|
349
|
+
- OtherSubrs: bytes object encoding some PostScript code
|
|
350
|
+
"""
|
|
351
|
+
__slots__ = ('parts', 'decrypted', 'prop', '_pos', '_abbr')
|
|
352
|
+
# the _pos dict contains (begin, end) indices to parts[0] + decrypted
|
|
353
|
+
# so that they can be replaced when transforming the font;
|
|
354
|
+
# but since sometimes a definition appears in both parts[0] and decrypted,
|
|
355
|
+
# _pos[name] is an array of such pairs
|
|
356
|
+
#
|
|
357
|
+
# _abbr maps three standard abbreviations to their particular names in
|
|
358
|
+
# this font (e.g. 'RD' is named '-|' in some fonts)
|
|
359
|
+
|
|
360
|
+
def __init__(self, input):
|
|
361
|
+
"""
|
|
362
|
+
Initialize a Type-1 font.
|
|
363
|
+
|
|
364
|
+
Parameters
|
|
365
|
+
----------
|
|
366
|
+
input : str or 3-tuple
|
|
367
|
+
Either a pfb file name, or a 3-tuple of already-decoded Type-1
|
|
368
|
+
font `~.Type1Font.parts`.
|
|
369
|
+
"""
|
|
370
|
+
if isinstance(input, tuple) and len(input) == 3:
|
|
371
|
+
self.parts = input
|
|
372
|
+
else:
|
|
373
|
+
with open(input, 'rb') as file:
|
|
374
|
+
data = self._read(file)
|
|
375
|
+
self.parts = self._split(data)
|
|
376
|
+
|
|
377
|
+
self.decrypted = self._decrypt(self.parts[1], 'eexec')
|
|
378
|
+
self._abbr = {'RD': 'RD', 'ND': 'ND', 'NP': 'NP'}
|
|
379
|
+
self._parse()
|
|
380
|
+
|
|
381
|
+
def _read(self, file):
|
|
382
|
+
"""Read the font from a file, decoding into usable parts."""
|
|
383
|
+
rawdata = file.read()
|
|
384
|
+
if not rawdata.startswith(b'\x80'):
|
|
385
|
+
return rawdata
|
|
386
|
+
|
|
387
|
+
data = b''
|
|
388
|
+
while rawdata:
|
|
389
|
+
if not rawdata.startswith(b'\x80'):
|
|
390
|
+
raise RuntimeError('Broken pfb file (expected byte 128, '
|
|
391
|
+
'got %d)' % rawdata[0])
|
|
392
|
+
type = rawdata[1]
|
|
393
|
+
if type in (1, 2):
|
|
394
|
+
length, = struct.unpack('<i', rawdata[2:6])
|
|
395
|
+
segment = rawdata[6:6 + length]
|
|
396
|
+
rawdata = rawdata[6 + length:]
|
|
397
|
+
|
|
398
|
+
if type == 1: # ASCII text: include verbatim
|
|
399
|
+
data += segment
|
|
400
|
+
elif type == 2: # binary data: encode in hexadecimal
|
|
401
|
+
data += binascii.hexlify(segment)
|
|
402
|
+
elif type == 3: # end of file
|
|
403
|
+
break
|
|
404
|
+
else:
|
|
405
|
+
raise RuntimeError('Unknown segment type %d in pfb file' % type)
|
|
406
|
+
|
|
407
|
+
return data
|
|
408
|
+
|
|
409
|
+
def _split(self, data):
|
|
410
|
+
"""
|
|
411
|
+
Split the Type 1 font into its three main parts.
|
|
412
|
+
|
|
413
|
+
The three parts are: (1) the cleartext part, which ends in a
|
|
414
|
+
eexec operator; (2) the encrypted part; (3) the fixed part,
|
|
415
|
+
which contains 512 ASCII zeros possibly divided on various
|
|
416
|
+
lines, a cleartomark operator, and possibly something else.
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
# Cleartext part: just find the eexec and skip whitespace
|
|
420
|
+
idx = data.index(b'eexec')
|
|
421
|
+
idx += len(b'eexec')
|
|
422
|
+
while data[idx] in b' \t\r\n':
|
|
423
|
+
idx += 1
|
|
424
|
+
len1 = idx
|
|
425
|
+
|
|
426
|
+
# Encrypted part: find the cleartomark operator and count
|
|
427
|
+
# zeros backward
|
|
428
|
+
idx = data.rindex(b'cleartomark') - 1
|
|
429
|
+
zeros = 512
|
|
430
|
+
while zeros and data[idx] in b'0' or data[idx] in b'\r\n':
|
|
431
|
+
if data[idx] in b'0':
|
|
432
|
+
zeros -= 1
|
|
433
|
+
idx -= 1
|
|
434
|
+
if zeros:
|
|
435
|
+
# this may have been a problem on old implementations that
|
|
436
|
+
# used the zeros as necessary padding
|
|
437
|
+
_log.info('Insufficiently many zeros in Type 1 font')
|
|
438
|
+
|
|
439
|
+
# Convert encrypted part to binary (if we read a pfb file, we may end
|
|
440
|
+
# up converting binary to hexadecimal to binary again; but if we read
|
|
441
|
+
# a pfa file, this part is already in hex, and I am not quite sure if
|
|
442
|
+
# even the pfb format guarantees that it will be in binary).
|
|
443
|
+
idx1 = len1 + ((idx - len1 + 2) & ~1) # ensure an even number of bytes
|
|
444
|
+
binary = binascii.unhexlify(data[len1:idx1])
|
|
445
|
+
|
|
446
|
+
return data[:len1], binary, data[idx+1:]
|
|
447
|
+
|
|
448
|
+
@staticmethod
|
|
449
|
+
def _decrypt(ciphertext, key, ndiscard=4):
|
|
450
|
+
"""
|
|
451
|
+
Decrypt ciphertext using the Type-1 font algorithm.
|
|
452
|
+
|
|
453
|
+
The algorithm is described in Adobe's "Adobe Type 1 Font Format".
|
|
454
|
+
The key argument can be an integer, or one of the strings
|
|
455
|
+
'eexec' and 'charstring', which map to the key specified for the
|
|
456
|
+
corresponding part of Type-1 fonts.
|
|
457
|
+
|
|
458
|
+
The ndiscard argument should be an integer, usually 4.
|
|
459
|
+
That number of bytes is discarded from the beginning of plaintext.
|
|
460
|
+
"""
|
|
461
|
+
|
|
462
|
+
key = _api.getitem_checked({'eexec': 55665, 'charstring': 4330}, key=key)
|
|
463
|
+
plaintext = []
|
|
464
|
+
for byte in ciphertext:
|
|
465
|
+
plaintext.append(byte ^ (key >> 8))
|
|
466
|
+
key = ((key+byte) * 52845 + 22719) & 0xffff
|
|
467
|
+
|
|
468
|
+
return bytes(plaintext[ndiscard:])
|
|
469
|
+
|
|
470
|
+
@staticmethod
|
|
471
|
+
def _encrypt(plaintext, key, ndiscard=4):
|
|
472
|
+
"""
|
|
473
|
+
Encrypt plaintext using the Type-1 font algorithm.
|
|
474
|
+
|
|
475
|
+
The algorithm is described in Adobe's "Adobe Type 1 Font Format".
|
|
476
|
+
The key argument can be an integer, or one of the strings
|
|
477
|
+
'eexec' and 'charstring', which map to the key specified for the
|
|
478
|
+
corresponding part of Type-1 fonts.
|
|
479
|
+
|
|
480
|
+
The ndiscard argument should be an integer, usually 4. That
|
|
481
|
+
number of bytes is prepended to the plaintext before encryption.
|
|
482
|
+
This function prepends NUL bytes for reproducibility, even though
|
|
483
|
+
the original algorithm uses random bytes, presumably to avoid
|
|
484
|
+
cryptanalysis.
|
|
485
|
+
"""
|
|
486
|
+
|
|
487
|
+
key = _api.getitem_checked({'eexec': 55665, 'charstring': 4330}, key=key)
|
|
488
|
+
ciphertext = []
|
|
489
|
+
for byte in b'\0' * ndiscard + plaintext:
|
|
490
|
+
c = byte ^ (key >> 8)
|
|
491
|
+
ciphertext.append(c)
|
|
492
|
+
key = ((key + c) * 52845 + 22719) & 0xffff
|
|
493
|
+
|
|
494
|
+
return bytes(ciphertext)
|
|
495
|
+
|
|
496
|
+
def _parse(self):
|
|
497
|
+
"""
|
|
498
|
+
Find the values of various font properties. This limited kind
|
|
499
|
+
of parsing is described in Chapter 10 "Adobe Type Manager
|
|
500
|
+
Compatibility" of the Type-1 spec.
|
|
501
|
+
"""
|
|
502
|
+
# Start with reasonable defaults
|
|
503
|
+
prop = {'Weight': 'Regular', 'ItalicAngle': 0.0, 'isFixedPitch': False,
|
|
504
|
+
'UnderlinePosition': -100, 'UnderlineThickness': 50}
|
|
505
|
+
pos = {}
|
|
506
|
+
data = self.parts[0] + self.decrypted
|
|
507
|
+
|
|
508
|
+
source = _tokenize(data, True)
|
|
509
|
+
while True:
|
|
510
|
+
# See if there is a key to be assigned a value
|
|
511
|
+
# e.g. /FontName in /FontName /Helvetica def
|
|
512
|
+
try:
|
|
513
|
+
token = next(source)
|
|
514
|
+
except StopIteration:
|
|
515
|
+
break
|
|
516
|
+
if token.is_delim():
|
|
517
|
+
# skip over this - we want top-level keys only
|
|
518
|
+
_expression(token, source, data)
|
|
519
|
+
if token.is_slash_name():
|
|
520
|
+
key = token.value()
|
|
521
|
+
keypos = token.pos
|
|
522
|
+
else:
|
|
523
|
+
continue
|
|
524
|
+
|
|
525
|
+
# Some values need special parsing
|
|
526
|
+
if key in ('Subrs', 'CharStrings', 'Encoding', 'OtherSubrs'):
|
|
527
|
+
parser = {
|
|
528
|
+
'Subrs': self._parse_subrs,
|
|
529
|
+
'CharStrings': self._parse_charstrings,
|
|
530
|
+
'Encoding': self._parse_encoding,
|
|
531
|
+
'OtherSubrs': self._parse_othersubrs
|
|
532
|
+
}[key]
|
|
533
|
+
try:
|
|
534
|
+
prop[key], endpos = parser(source, data)
|
|
535
|
+
except StopIteration:
|
|
536
|
+
raise RuntimeError(
|
|
537
|
+
f"Malformed Type1 font file: Incomplete /{key}"
|
|
538
|
+
) from None
|
|
539
|
+
pos.setdefault(key, []).append((keypos, endpos))
|
|
540
|
+
continue
|
|
541
|
+
|
|
542
|
+
try:
|
|
543
|
+
token = next(source)
|
|
544
|
+
except StopIteration:
|
|
545
|
+
break
|
|
546
|
+
|
|
547
|
+
if isinstance(token, _KeywordToken):
|
|
548
|
+
# constructs like
|
|
549
|
+
# FontDirectory /Helvetica known {...} {...} ifelse
|
|
550
|
+
# mean the key was not really a key
|
|
551
|
+
continue
|
|
552
|
+
|
|
553
|
+
if token.is_delim():
|
|
554
|
+
value = _expression(token, source, data).raw
|
|
555
|
+
else:
|
|
556
|
+
value = token.value()
|
|
557
|
+
|
|
558
|
+
# look for a 'def' possibly preceded by access modifiers
|
|
559
|
+
try:
|
|
560
|
+
kw = next(
|
|
561
|
+
kw for kw in source
|
|
562
|
+
if not kw.is_keyword('readonly', 'noaccess', 'executeonly')
|
|
563
|
+
)
|
|
564
|
+
except StopIteration:
|
|
565
|
+
break
|
|
566
|
+
|
|
567
|
+
# sometimes noaccess def and readonly def are abbreviated
|
|
568
|
+
if kw.is_keyword('def', self._abbr['ND'], self._abbr['NP']):
|
|
569
|
+
prop[key] = value
|
|
570
|
+
pos.setdefault(key, []).append((keypos, kw.endpos()))
|
|
571
|
+
|
|
572
|
+
# detect the standard abbreviations
|
|
573
|
+
if value == '{noaccess def}':
|
|
574
|
+
self._abbr['ND'] = key
|
|
575
|
+
elif value == '{noaccess put}':
|
|
576
|
+
self._abbr['NP'] = key
|
|
577
|
+
elif value == '{string currentfile exch readstring pop}':
|
|
578
|
+
self._abbr['RD'] = key
|
|
579
|
+
|
|
580
|
+
# Fill in the various *Name properties
|
|
581
|
+
if 'FontName' not in prop:
|
|
582
|
+
prop['FontName'] = (prop.get('FullName') or
|
|
583
|
+
prop.get('FamilyName') or
|
|
584
|
+
'Unknown')
|
|
585
|
+
if 'FullName' not in prop:
|
|
586
|
+
prop['FullName'] = prop['FontName']
|
|
587
|
+
if 'FamilyName' not in prop:
|
|
588
|
+
extras = ('(?i)([ -](regular|plain|italic|oblique|(semi)?bold|'
|
|
589
|
+
'(ultra)?light|extra|condensed))+$')
|
|
590
|
+
prop['FamilyName'] = re.sub(extras, '', prop['FullName'])
|
|
591
|
+
|
|
592
|
+
# Parse FontBBox
|
|
593
|
+
toks = [*_tokenize(prop['FontBBox'].encode('ascii'), True)]
|
|
594
|
+
if ([tok.kind for tok in toks]
|
|
595
|
+
!= ['delimiter', 'number', 'number', 'number', 'number', 'delimiter']
|
|
596
|
+
or toks[-1].raw != toks[0].opposite()):
|
|
597
|
+
raise RuntimeError(
|
|
598
|
+
f"FontBBox should be a size-4 array, was {prop['FontBBox']}")
|
|
599
|
+
prop['FontBBox'] = [tok.value() for tok in toks[1:-1]]
|
|
600
|
+
|
|
601
|
+
# Decrypt the encrypted parts
|
|
602
|
+
ndiscard = prop.get('lenIV', 4)
|
|
603
|
+
cs = prop['CharStrings']
|
|
604
|
+
for key, value in cs.items():
|
|
605
|
+
cs[key] = self._decrypt(value, 'charstring', ndiscard)
|
|
606
|
+
if 'Subrs' in prop:
|
|
607
|
+
prop['Subrs'] = [
|
|
608
|
+
self._decrypt(value, 'charstring', ndiscard)
|
|
609
|
+
for value in prop['Subrs']
|
|
610
|
+
]
|
|
611
|
+
|
|
612
|
+
self.prop = prop
|
|
613
|
+
self._pos = pos
|
|
614
|
+
|
|
615
|
+
def _parse_subrs(self, tokens, _data):
|
|
616
|
+
count_token = next(tokens)
|
|
617
|
+
if not count_token.is_number():
|
|
618
|
+
raise RuntimeError(
|
|
619
|
+
f"Token following /Subrs must be a number, was {count_token}"
|
|
620
|
+
)
|
|
621
|
+
count = count_token.value()
|
|
622
|
+
next(t for t in tokens if t.is_keyword('array'))
|
|
623
|
+
# Accumulate the parsed subrs into a dict and only allocate the result
|
|
624
|
+
# list once the body has been read. Allocating ``[None] * count`` up
|
|
625
|
+
# front lets a malformed font declare a huge count in a few bytes and
|
|
626
|
+
# force a large allocation before it is rejected.
|
|
627
|
+
entries = {}
|
|
628
|
+
for _ in range(count):
|
|
629
|
+
next(t for t in tokens if t.is_keyword('dup'))
|
|
630
|
+
index_token = next(tokens)
|
|
631
|
+
if not index_token.is_number():
|
|
632
|
+
raise RuntimeError(
|
|
633
|
+
"Token following dup in Subrs definition must be a "
|
|
634
|
+
f"number, was {index_token}"
|
|
635
|
+
)
|
|
636
|
+
nbytes_token = next(tokens)
|
|
637
|
+
if not nbytes_token.is_number():
|
|
638
|
+
raise RuntimeError(
|
|
639
|
+
"Second token following dup in Subrs definition must "
|
|
640
|
+
f"be a number, was {nbytes_token}"
|
|
641
|
+
)
|
|
642
|
+
token = next(tokens)
|
|
643
|
+
if not token.is_keyword(self._abbr['RD']):
|
|
644
|
+
raise RuntimeError(
|
|
645
|
+
f"Token preceding subr must be {self._abbr['RD']}, "
|
|
646
|
+
f"was {token}"
|
|
647
|
+
)
|
|
648
|
+
binary_token = tokens.send(1+nbytes_token.value())
|
|
649
|
+
entries[index_token.value()] = binary_token.value()
|
|
650
|
+
|
|
651
|
+
# The indices must cover 0 to count-1 exactly.
|
|
652
|
+
if (len(entries) != count
|
|
653
|
+
or (count and (min(entries), max(entries)) != (0, count - 1))):
|
|
654
|
+
raise RuntimeError(
|
|
655
|
+
"Malformed Type1 font file: /Subrs indices do not cover "
|
|
656
|
+
f"0 to {count - 1}"
|
|
657
|
+
)
|
|
658
|
+
array = [entries[index] for index in range(count)]
|
|
659
|
+
|
|
660
|
+
return array, next(tokens).endpos()
|
|
661
|
+
|
|
662
|
+
def _parse_charstrings(self, tokens, _data):
|
|
663
|
+
count_token = next(tokens)
|
|
664
|
+
if not count_token.is_number():
|
|
665
|
+
raise RuntimeError(
|
|
666
|
+
"Token following /CharStrings must be a number, "
|
|
667
|
+
f"was {count_token}"
|
|
668
|
+
)
|
|
669
|
+
count = count_token.value()
|
|
670
|
+
charstrings = {}
|
|
671
|
+
next(t for t in tokens if t.is_keyword('begin'))
|
|
672
|
+
while True:
|
|
673
|
+
token = next(t for t in tokens
|
|
674
|
+
if t.is_keyword('end') or t.is_slash_name())
|
|
675
|
+
if token.raw == 'end':
|
|
676
|
+
return charstrings, token.endpos()
|
|
677
|
+
glyphname = token.value()
|
|
678
|
+
nbytes_token = next(tokens)
|
|
679
|
+
if not nbytes_token.is_number():
|
|
680
|
+
raise RuntimeError(
|
|
681
|
+
f"Token following /{glyphname} in CharStrings definition "
|
|
682
|
+
f"must be a number, was {nbytes_token}"
|
|
683
|
+
)
|
|
684
|
+
token = next(tokens)
|
|
685
|
+
if not token.is_keyword(self._abbr['RD']):
|
|
686
|
+
raise RuntimeError(
|
|
687
|
+
f"Token preceding charstring must be {self._abbr['RD']}, "
|
|
688
|
+
f"was {token}"
|
|
689
|
+
)
|
|
690
|
+
binary_token = tokens.send(1+nbytes_token.value())
|
|
691
|
+
charstrings[glyphname] = binary_token.value()
|
|
692
|
+
|
|
693
|
+
@staticmethod
|
|
694
|
+
def _parse_encoding(tokens, _data):
|
|
695
|
+
# this only works for encodings that follow the Adobe manual
|
|
696
|
+
# but some old fonts include non-compliant data - we log a warning
|
|
697
|
+
# and return a possibly incomplete encoding
|
|
698
|
+
encoding = {}
|
|
699
|
+
while True:
|
|
700
|
+
token = next(t for t in tokens
|
|
701
|
+
if t.is_keyword('StandardEncoding', 'dup', 'def'))
|
|
702
|
+
if token.is_keyword('StandardEncoding'):
|
|
703
|
+
return _StandardEncoding, token.endpos()
|
|
704
|
+
if token.is_keyword('def'):
|
|
705
|
+
return encoding, token.endpos()
|
|
706
|
+
index_token = next(tokens)
|
|
707
|
+
if not index_token.is_number():
|
|
708
|
+
_log.warning(
|
|
709
|
+
f"Parsing encoding: expected number, got {index_token}"
|
|
710
|
+
)
|
|
711
|
+
continue
|
|
712
|
+
name_token = next(tokens)
|
|
713
|
+
if not name_token.is_slash_name():
|
|
714
|
+
_log.warning(
|
|
715
|
+
f"Parsing encoding: expected slash-name, got {name_token}"
|
|
716
|
+
)
|
|
717
|
+
continue
|
|
718
|
+
encoding[index_token.value()] = name_token.value()
|
|
719
|
+
|
|
720
|
+
def _parse_othersubrs(self, tokens, data):
|
|
721
|
+
init_pos = None
|
|
722
|
+
while True:
|
|
723
|
+
token = next(tokens)
|
|
724
|
+
if init_pos is None:
|
|
725
|
+
init_pos = token.pos
|
|
726
|
+
if token.is_delim():
|
|
727
|
+
_expression(token, tokens, data)
|
|
728
|
+
elif token.is_keyword('def', self._abbr['ND']):
|
|
729
|
+
return data[init_pos:token.endpos()], token.endpos()
|
|
730
|
+
|
|
731
|
+
def transform(self, effects):
|
|
732
|
+
"""
|
|
733
|
+
Return a new font that is slanted and/or extended.
|
|
734
|
+
|
|
735
|
+
Parameters
|
|
736
|
+
----------
|
|
737
|
+
effects : dict
|
|
738
|
+
A dict with optional entries:
|
|
739
|
+
|
|
740
|
+
- 'slant' : float, default: 0
|
|
741
|
+
Tangent of the angle that the font is to be slanted to the
|
|
742
|
+
right. Negative values slant to the left.
|
|
743
|
+
- 'extend' : float, default: 1
|
|
744
|
+
Scaling factor for the font width. Values less than 1 condense
|
|
745
|
+
the glyphs.
|
|
746
|
+
|
|
747
|
+
Returns
|
|
748
|
+
-------
|
|
749
|
+
`Type1Font`
|
|
750
|
+
"""
|
|
751
|
+
fontname = self.prop['FontName']
|
|
752
|
+
italicangle = self.prop['ItalicAngle']
|
|
753
|
+
|
|
754
|
+
array = [
|
|
755
|
+
float(x) for x in (self.prop['FontMatrix']
|
|
756
|
+
.lstrip('[').rstrip(']').split())
|
|
757
|
+
]
|
|
758
|
+
oldmatrix = np.eye(3, 3)
|
|
759
|
+
oldmatrix[0:3, 0] = array[::2]
|
|
760
|
+
oldmatrix[0:3, 1] = array[1::2]
|
|
761
|
+
modifier = np.eye(3, 3)
|
|
762
|
+
|
|
763
|
+
if 'slant' in effects:
|
|
764
|
+
slant = effects['slant']
|
|
765
|
+
fontname += f'_Slant_{int(1000 * slant)}'
|
|
766
|
+
italicangle = round(
|
|
767
|
+
float(italicangle) - np.arctan(slant) / np.pi * 180,
|
|
768
|
+
5
|
|
769
|
+
)
|
|
770
|
+
modifier[1, 0] = slant
|
|
771
|
+
|
|
772
|
+
if 'extend' in effects:
|
|
773
|
+
extend = effects['extend']
|
|
774
|
+
fontname += f'_Extend_{int(1000 * extend)}'
|
|
775
|
+
modifier[0, 0] = extend
|
|
776
|
+
|
|
777
|
+
newmatrix = np.dot(modifier, oldmatrix)
|
|
778
|
+
array[::2] = newmatrix[0:3, 0]
|
|
779
|
+
array[1::2] = newmatrix[0:3, 1]
|
|
780
|
+
fontmatrix = (
|
|
781
|
+
f"[{' '.join(_format_approx(x, 6) for x in array)}]"
|
|
782
|
+
)
|
|
783
|
+
newparts = self._replace(
|
|
784
|
+
[(x, f'/FontName/{fontname} def')
|
|
785
|
+
for x in self._pos['FontName']]
|
|
786
|
+
+ [(x, f'/ItalicAngle {italicangle} def')
|
|
787
|
+
for x in self._pos['ItalicAngle']]
|
|
788
|
+
+ [(x, f'/FontMatrix {fontmatrix} readonly def')
|
|
789
|
+
for x in self._pos['FontMatrix']]
|
|
790
|
+
+ [(x, '') for x in self._pos.get('UniqueID', [])]
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
return Type1Font((
|
|
794
|
+
newparts[0],
|
|
795
|
+
self._encrypt(newparts[1], 'eexec'),
|
|
796
|
+
self.parts[2]
|
|
797
|
+
))
|
|
798
|
+
|
|
799
|
+
def with_encoding(self, encoding):
|
|
800
|
+
"""
|
|
801
|
+
Change the encoding of the font.
|
|
802
|
+
|
|
803
|
+
Parameters
|
|
804
|
+
----------
|
|
805
|
+
encoding : dict
|
|
806
|
+
A dictionary mapping character codes to glyph names.
|
|
807
|
+
|
|
808
|
+
Returns
|
|
809
|
+
-------
|
|
810
|
+
`Type1Font`
|
|
811
|
+
"""
|
|
812
|
+
newparts = self._replace(
|
|
813
|
+
[(x, '') for x in self._pos.get('UniqueID', [])]
|
|
814
|
+
+ [(self._pos['Encoding'][0], self._postscript_encoding(encoding))]
|
|
815
|
+
)
|
|
816
|
+
return Type1Font((
|
|
817
|
+
newparts[0],
|
|
818
|
+
self._encrypt(newparts[1], 'eexec'),
|
|
819
|
+
self.parts[2]
|
|
820
|
+
))
|
|
821
|
+
|
|
822
|
+
def _replace(self, replacements):
|
|
823
|
+
"""
|
|
824
|
+
Change the font according to `replacements`
|
|
825
|
+
|
|
826
|
+
Parameters
|
|
827
|
+
----------
|
|
828
|
+
replacements : list of ((int, int), str)
|
|
829
|
+
Each element is ((pos0, pos1), replacement) where pos0 and
|
|
830
|
+
pos1 are indices to the original font data (parts[0] and the
|
|
831
|
+
decrypted part concatenated). The data in the interval
|
|
832
|
+
pos0:pos1 will be replaced by the replacement text. To
|
|
833
|
+
accommodate binary data, the replacement is taken to be in
|
|
834
|
+
Latin-1 encoding.
|
|
835
|
+
|
|
836
|
+
The case where pos0 is inside parts[0] and pos1 inside
|
|
837
|
+
the decrypted part is not supported.
|
|
838
|
+
|
|
839
|
+
Returns
|
|
840
|
+
-------
|
|
841
|
+
(bytes, bytes)
|
|
842
|
+
The new parts[0] and decrypted part (which needs to be
|
|
843
|
+
encrypted in the transformed font).
|
|
844
|
+
"""
|
|
845
|
+
data = bytearray(self.parts[0])
|
|
846
|
+
data.extend(self.decrypted)
|
|
847
|
+
len0 = len(self.parts[0])
|
|
848
|
+
for (pos0, pos1), value in sorted(replacements, reverse=True):
|
|
849
|
+
data[pos0:pos1] = value.encode('latin-1')
|
|
850
|
+
if pos0 < len(self.parts[0]):
|
|
851
|
+
if pos1 >= len(self.parts[0]):
|
|
852
|
+
raise RuntimeError(
|
|
853
|
+
f"text to be replaced with {value} spans "
|
|
854
|
+
"the eexec boundary"
|
|
855
|
+
)
|
|
856
|
+
len0 += len(value) - pos1 + pos0
|
|
857
|
+
|
|
858
|
+
return bytes(data[:len0]), bytes(data[len0:])
|
|
859
|
+
|
|
860
|
+
def subset(self, characters, name_prefix):
|
|
861
|
+
"""
|
|
862
|
+
Return a new font that only defines the given characters.
|
|
863
|
+
|
|
864
|
+
Parameters
|
|
865
|
+
----------
|
|
866
|
+
characters : sequence of bytes
|
|
867
|
+
The subset of characters to include. These are indices into the
|
|
868
|
+
font's encoding array. The encoding array of a Type-1 font can
|
|
869
|
+
only include 256 characters, but other glyphs may be accessed
|
|
870
|
+
via the seac operator.
|
|
871
|
+
name_prefix : str
|
|
872
|
+
Prefix to prepend to the font name.
|
|
873
|
+
|
|
874
|
+
Returns
|
|
875
|
+
-------
|
|
876
|
+
`Type1Font`
|
|
877
|
+
"""
|
|
878
|
+
characters = frozenset(characters)
|
|
879
|
+
if _log.isEnabledFor(logging.DEBUG):
|
|
880
|
+
_log.debug(
|
|
881
|
+
"Subsetting font %s to characters %s = %s",
|
|
882
|
+
self.prop['FontName'],
|
|
883
|
+
sorted(characters),
|
|
884
|
+
[self.prop['Encoding'].get(code) for code in sorted(characters)],
|
|
885
|
+
)
|
|
886
|
+
encoding = {code: glyph
|
|
887
|
+
for code, glyph in self.prop['Encoding'].items()
|
|
888
|
+
if code in characters}
|
|
889
|
+
# todo and done include strings (glyph names)
|
|
890
|
+
todo = {'.notdef', *encoding.values()}
|
|
891
|
+
done = set()
|
|
892
|
+
seen_subrs = {0, 1, 2, 3}
|
|
893
|
+
while todo:
|
|
894
|
+
glyph = todo.pop()
|
|
895
|
+
called_glyphs, called_subrs = _CharstringSimulator(self).run(glyph)
|
|
896
|
+
done.add(glyph)
|
|
897
|
+
todo.update(called_glyphs - done)
|
|
898
|
+
seen_subrs.update(called_subrs)
|
|
899
|
+
|
|
900
|
+
charstrings = self._subset_charstrings(done)
|
|
901
|
+
subrs = self._subset_subrs(seen_subrs)
|
|
902
|
+
newparts = self._replace(
|
|
903
|
+
[(x, f'/FontName /{name_prefix}{self.prop["FontName"]} def')
|
|
904
|
+
for x in self._pos['FontName']]
|
|
905
|
+
+ [(self._pos['CharStrings'][0], charstrings),
|
|
906
|
+
(self._pos['Subrs'][0], subrs),
|
|
907
|
+
(self._pos['Encoding'][0], self._postscript_encoding(encoding))
|
|
908
|
+
] + [(x, '') for x in self._pos.get('UniqueID', [])]
|
|
909
|
+
)
|
|
910
|
+
return type(self)((
|
|
911
|
+
newparts[0],
|
|
912
|
+
self._encrypt(newparts[1], 'eexec'),
|
|
913
|
+
self.parts[2]
|
|
914
|
+
))
|
|
915
|
+
|
|
916
|
+
@staticmethod
|
|
917
|
+
def _charstring_tokens(data):
|
|
918
|
+
"""Parse a Type-1 charstring
|
|
919
|
+
|
|
920
|
+
Yield opcode names and integer parameters.
|
|
921
|
+
"""
|
|
922
|
+
data = iter(data)
|
|
923
|
+
for byte in data:
|
|
924
|
+
if 32 <= byte <= 246:
|
|
925
|
+
yield byte - 139
|
|
926
|
+
elif 247 <= byte <= 250:
|
|
927
|
+
byte2 = next(data)
|
|
928
|
+
yield (byte-247) * 256 + byte2 + 108
|
|
929
|
+
elif 251 <= byte <= 254:
|
|
930
|
+
byte2 = next(data)
|
|
931
|
+
yield -(byte-251)*256 - byte2 - 108
|
|
932
|
+
elif byte == 255:
|
|
933
|
+
bs = bytes(itertools.islice(data, 4))
|
|
934
|
+
yield struct.unpack('>i', bs)[0]
|
|
935
|
+
elif byte == 12:
|
|
936
|
+
byte1 = next(data)
|
|
937
|
+
yield {
|
|
938
|
+
0: 'dotsection',
|
|
939
|
+
1: 'vstem3',
|
|
940
|
+
2: 'hstem3',
|
|
941
|
+
6: 'seac',
|
|
942
|
+
7: 'sbw',
|
|
943
|
+
12: 'div',
|
|
944
|
+
16: 'callothersubr',
|
|
945
|
+
17: 'pop',
|
|
946
|
+
33: 'setcurrentpoint'
|
|
947
|
+
}[byte1]
|
|
948
|
+
else:
|
|
949
|
+
yield {
|
|
950
|
+
1: 'hstem',
|
|
951
|
+
3: 'vstem',
|
|
952
|
+
4: 'vmoveto',
|
|
953
|
+
5: 'rlineto',
|
|
954
|
+
6: 'hlineto',
|
|
955
|
+
7: 'vlineto',
|
|
956
|
+
8: 'rrcurveto',
|
|
957
|
+
9: 'closepath',
|
|
958
|
+
10: 'callsubr',
|
|
959
|
+
11: 'return',
|
|
960
|
+
13: 'hsbw',
|
|
961
|
+
14: 'endchar',
|
|
962
|
+
21: 'rmoveto',
|
|
963
|
+
22: 'hmoveto',
|
|
964
|
+
30: 'vhcurveto',
|
|
965
|
+
31: 'hvcurveto'
|
|
966
|
+
}[byte]
|
|
967
|
+
|
|
968
|
+
def _postscript_encoding(self, encoding):
|
|
969
|
+
"""Return a PostScript encoding array for the encoding."""
|
|
970
|
+
return '\n'.join([
|
|
971
|
+
'/Encoding 256 array',
|
|
972
|
+
'0 1 255 { 1 index exch /.notdef put} for',
|
|
973
|
+
*(
|
|
974
|
+
f'dup {i} /{glyph} put'
|
|
975
|
+
for i, glyph in sorted(encoding.items())
|
|
976
|
+
if glyph != '.notdef'
|
|
977
|
+
),
|
|
978
|
+
'readonly def\n',
|
|
979
|
+
])
|
|
980
|
+
|
|
981
|
+
def _subset_charstrings(self, glyphs):
|
|
982
|
+
"""Return a PostScript CharStrings array for the glyphs."""
|
|
983
|
+
charstrings = self.prop['CharStrings']
|
|
984
|
+
lenIV = self.prop.get('lenIV', 4)
|
|
985
|
+
ordered = sorted(glyphs)
|
|
986
|
+
encrypted = [
|
|
987
|
+
self._encrypt(charstrings[glyph], 'charstring', lenIV).decode('latin-1')
|
|
988
|
+
for glyph in ordered
|
|
989
|
+
]
|
|
990
|
+
RD, ND = self._abbr['RD'], self._abbr['ND']
|
|
991
|
+
return '\n'.join([
|
|
992
|
+
f'/CharStrings {len(ordered)} dict dup begin',
|
|
993
|
+
*(
|
|
994
|
+
f'/{glyph} {len(enc)} {RD} {enc} {ND}'
|
|
995
|
+
for glyph, enc in zip(ordered, encrypted)
|
|
996
|
+
),
|
|
997
|
+
'end\n',
|
|
998
|
+
])
|
|
999
|
+
|
|
1000
|
+
def _subset_subrs(self, indices):
|
|
1001
|
+
"""Return a PostScript Subrs array for the subroutines."""
|
|
1002
|
+
# we can't remove subroutines, we just replace unused ones with a stub
|
|
1003
|
+
subrs = self.prop['Subrs']
|
|
1004
|
+
n_subrs = len(subrs)
|
|
1005
|
+
lenIV = self.prop.get('lenIV', 4)
|
|
1006
|
+
stub = self._encrypt(b'\x0b', 'charstring', lenIV).decode('latin-1')
|
|
1007
|
+
encrypted = [
|
|
1008
|
+
self._encrypt(subrs[i], 'charstring', lenIV).decode('latin-1')
|
|
1009
|
+
if i in indices
|
|
1010
|
+
else stub
|
|
1011
|
+
for i in range(n_subrs)
|
|
1012
|
+
]
|
|
1013
|
+
RD, ND, NP = self._abbr['RD'], self._abbr['ND'], self._abbr['NP']
|
|
1014
|
+
return '\n'.join([
|
|
1015
|
+
f'/Subrs {n_subrs} array',
|
|
1016
|
+
*(
|
|
1017
|
+
f'dup {i} {len(enc)} {RD} {enc} {NP}'
|
|
1018
|
+
for i, enc in enumerate(encrypted)
|
|
1019
|
+
),
|
|
1020
|
+
])
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
class _CharstringSimulator:
|
|
1024
|
+
__slots__ = ('font', 'buildchar_stack', 'postscript_stack', 'glyphs', 'subrs')
|
|
1025
|
+
|
|
1026
|
+
def __init__(self, font):
|
|
1027
|
+
self.font = font
|
|
1028
|
+
self.buildchar_stack = []
|
|
1029
|
+
self.postscript_stack = []
|
|
1030
|
+
self.glyphs = set()
|
|
1031
|
+
self.subrs = set()
|
|
1032
|
+
|
|
1033
|
+
def run(self, glyph_or_subr):
|
|
1034
|
+
"""Run the charstring interpreter on a glyph or subroutine.
|
|
1035
|
+
|
|
1036
|
+
This does not actually execute the code but simulates it to find out
|
|
1037
|
+
which subroutines get called when executing the glyph or subroutine.
|
|
1038
|
+
|
|
1039
|
+
Parameters
|
|
1040
|
+
----------
|
|
1041
|
+
glyph_or_subr : str or int
|
|
1042
|
+
The name of the glyph or the index of the subroutine to simulate.
|
|
1043
|
+
|
|
1044
|
+
Returns
|
|
1045
|
+
-------
|
|
1046
|
+
glyphs : set[str]
|
|
1047
|
+
The set of glyph names called by the glyph or subroutine.
|
|
1048
|
+
subrs : set[int]
|
|
1049
|
+
The set of subroutines called by the glyph or subroutine.
|
|
1050
|
+
"""
|
|
1051
|
+
if isinstance(glyph_or_subr, str):
|
|
1052
|
+
program = self.font.prop['CharStrings'][glyph_or_subr]
|
|
1053
|
+
self.glyphs.add(glyph_or_subr)
|
|
1054
|
+
else:
|
|
1055
|
+
program = self.font.prop['Subrs'][glyph_or_subr]
|
|
1056
|
+
self.subrs.add(glyph_or_subr)
|
|
1057
|
+
for opcode in self.font._charstring_tokens(program):
|
|
1058
|
+
if opcode in ('return', 'endchar'):
|
|
1059
|
+
return self.glyphs, self.subrs
|
|
1060
|
+
self._step(opcode)
|
|
1061
|
+
else:
|
|
1062
|
+
font_name = self.font.prop.get('FontName', '(unknown)')
|
|
1063
|
+
_log.info(
|
|
1064
|
+
f"Glyph or subr {glyph_or_subr} in font {font_name} does not end "
|
|
1065
|
+
"with return or endchar"
|
|
1066
|
+
)
|
|
1067
|
+
return self.glyphs, self.subrs
|
|
1068
|
+
|
|
1069
|
+
def _step(self, opcode):
|
|
1070
|
+
"""Run one step in the charstring interpreter."""
|
|
1071
|
+
match opcode:
|
|
1072
|
+
case int():
|
|
1073
|
+
self.buildchar_stack.append(opcode)
|
|
1074
|
+
case (
|
|
1075
|
+
'hsbw' | 'sbw' | 'closepath' | 'hlineto' | 'hmoveto' | 'hcurveto' |
|
|
1076
|
+
'hvcurveto' | 'rlineto' | 'rmoveto' | 'rrcurveto' | 'vhcurveto' |
|
|
1077
|
+
'vlineto' | 'vmoveto' | 'dotsection' | 'hstem' | 'hstem3' |
|
|
1078
|
+
'vstem' | 'vstem3' | 'setcurrentpoint'
|
|
1079
|
+
):
|
|
1080
|
+
self.buildchar_stack.clear()
|
|
1081
|
+
case 'seac': # Standard Encoding Accented Character
|
|
1082
|
+
codes = self.buildchar_stack[3:5]
|
|
1083
|
+
self.glyphs.update(_StandardEncoding[int(x)] for x in codes)
|
|
1084
|
+
self.buildchar_stack.clear()
|
|
1085
|
+
case 'div':
|
|
1086
|
+
num1, num2 = self.buildchar_stack[-2:]
|
|
1087
|
+
if num2 == 0:
|
|
1088
|
+
_log.warning(
|
|
1089
|
+
f"Division by zero in font {self.font.prop['FontName']}"
|
|
1090
|
+
)
|
|
1091
|
+
self.buildchar_stack[-2:] = [0]
|
|
1092
|
+
else:
|
|
1093
|
+
self.buildchar_stack[-2:] = [num1/num2]
|
|
1094
|
+
case 'callothersubr':
|
|
1095
|
+
n, othersubr = self.buildchar_stack[-2:]
|
|
1096
|
+
if not isinstance(n, int):
|
|
1097
|
+
_log.warning(
|
|
1098
|
+
f"callothersubr {othersubr} with non-integer argument "
|
|
1099
|
+
f"count in font {self.font.prop['FontName']}"
|
|
1100
|
+
)
|
|
1101
|
+
n = int(n)
|
|
1102
|
+
args = self.buildchar_stack[-2-n:-2]
|
|
1103
|
+
if othersubr == 3:
|
|
1104
|
+
self.postscript_stack.append(args[0])
|
|
1105
|
+
else:
|
|
1106
|
+
self.postscript_stack.extend(args[::-1])
|
|
1107
|
+
self.buildchar_stack[-2-n:] = []
|
|
1108
|
+
case 'callsubr':
|
|
1109
|
+
subr = self.buildchar_stack.pop()
|
|
1110
|
+
if not isinstance(subr, int):
|
|
1111
|
+
_log.warning(
|
|
1112
|
+
f"callsubr with non-integer argument {subr} in font "
|
|
1113
|
+
f"{self.font.prop['FontName']}"
|
|
1114
|
+
)
|
|
1115
|
+
subr = int(subr)
|
|
1116
|
+
self.run(subr)
|
|
1117
|
+
case 'pop':
|
|
1118
|
+
if not self.postscript_stack:
|
|
1119
|
+
_log.warning(
|
|
1120
|
+
f"pop with empty stack in font {self.font.prop['FontName']}"
|
|
1121
|
+
)
|
|
1122
|
+
self.postscript_stack.append(0)
|
|
1123
|
+
self.buildchar_stack.append(self.postscript_stack.pop())
|
|
1124
|
+
case _:
|
|
1125
|
+
raise RuntimeError(f'opcode {opcode}')
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
_StandardEncoding = {
|
|
1129
|
+
**{ord(letter): letter for letter in string.ascii_letters},
|
|
1130
|
+
0: '.notdef',
|
|
1131
|
+
32: 'space',
|
|
1132
|
+
33: 'exclam',
|
|
1133
|
+
34: 'quotedbl',
|
|
1134
|
+
35: 'numbersign',
|
|
1135
|
+
36: 'dollar',
|
|
1136
|
+
37: 'percent',
|
|
1137
|
+
38: 'ampersand',
|
|
1138
|
+
39: 'quoteright',
|
|
1139
|
+
40: 'parenleft',
|
|
1140
|
+
41: 'parenright',
|
|
1141
|
+
42: 'asterisk',
|
|
1142
|
+
43: 'plus',
|
|
1143
|
+
44: 'comma',
|
|
1144
|
+
45: 'hyphen',
|
|
1145
|
+
46: 'period',
|
|
1146
|
+
47: 'slash',
|
|
1147
|
+
48: 'zero',
|
|
1148
|
+
49: 'one',
|
|
1149
|
+
50: 'two',
|
|
1150
|
+
51: 'three',
|
|
1151
|
+
52: 'four',
|
|
1152
|
+
53: 'five',
|
|
1153
|
+
54: 'six',
|
|
1154
|
+
55: 'seven',
|
|
1155
|
+
56: 'eight',
|
|
1156
|
+
57: 'nine',
|
|
1157
|
+
58: 'colon',
|
|
1158
|
+
59: 'semicolon',
|
|
1159
|
+
60: 'less',
|
|
1160
|
+
61: 'equal',
|
|
1161
|
+
62: 'greater',
|
|
1162
|
+
63: 'question',
|
|
1163
|
+
64: 'at',
|
|
1164
|
+
91: 'bracketleft',
|
|
1165
|
+
92: 'backslash',
|
|
1166
|
+
93: 'bracketright',
|
|
1167
|
+
94: 'asciicircum',
|
|
1168
|
+
95: 'underscore',
|
|
1169
|
+
96: 'quoteleft',
|
|
1170
|
+
123: 'braceleft',
|
|
1171
|
+
124: 'bar',
|
|
1172
|
+
125: 'braceright',
|
|
1173
|
+
126: 'asciitilde',
|
|
1174
|
+
161: 'exclamdown',
|
|
1175
|
+
162: 'cent',
|
|
1176
|
+
163: 'sterling',
|
|
1177
|
+
164: 'fraction',
|
|
1178
|
+
165: 'yen',
|
|
1179
|
+
166: 'florin',
|
|
1180
|
+
167: 'section',
|
|
1181
|
+
168: 'currency',
|
|
1182
|
+
169: 'quotesingle',
|
|
1183
|
+
170: 'quotedblleft',
|
|
1184
|
+
171: 'guillemotleft',
|
|
1185
|
+
172: 'guilsinglleft',
|
|
1186
|
+
173: 'guilsinglright',
|
|
1187
|
+
174: 'fi',
|
|
1188
|
+
175: 'fl',
|
|
1189
|
+
177: 'endash',
|
|
1190
|
+
178: 'dagger',
|
|
1191
|
+
179: 'daggerdbl',
|
|
1192
|
+
180: 'periodcentered',
|
|
1193
|
+
182: 'paragraph',
|
|
1194
|
+
183: 'bullet',
|
|
1195
|
+
184: 'quotesinglbase',
|
|
1196
|
+
185: 'quotedblbase',
|
|
1197
|
+
186: 'quotedblright',
|
|
1198
|
+
187: 'guillemotright',
|
|
1199
|
+
188: 'ellipsis',
|
|
1200
|
+
189: 'perthousand',
|
|
1201
|
+
191: 'questiondown',
|
|
1202
|
+
193: 'grave',
|
|
1203
|
+
194: 'acute',
|
|
1204
|
+
195: 'circumflex',
|
|
1205
|
+
196: 'tilde',
|
|
1206
|
+
197: 'macron',
|
|
1207
|
+
198: 'breve',
|
|
1208
|
+
199: 'dotaccent',
|
|
1209
|
+
200: 'dieresis',
|
|
1210
|
+
202: 'ring',
|
|
1211
|
+
203: 'cedilla',
|
|
1212
|
+
205: 'hungarumlaut',
|
|
1213
|
+
206: 'ogonek',
|
|
1214
|
+
207: 'caron',
|
|
1215
|
+
208: 'emdash',
|
|
1216
|
+
225: 'AE',
|
|
1217
|
+
227: 'ordfeminine',
|
|
1218
|
+
232: 'Lslash',
|
|
1219
|
+
233: 'Oslash',
|
|
1220
|
+
234: 'OE',
|
|
1221
|
+
235: 'ordmasculine',
|
|
1222
|
+
241: 'ae',
|
|
1223
|
+
245: 'dotlessi',
|
|
1224
|
+
248: 'lslash',
|
|
1225
|
+
249: 'oslash',
|
|
1226
|
+
250: 'oe',
|
|
1227
|
+
251: 'germandbls',
|
|
1228
|
+
}
|