vec-io 0.2.0__tar.gz → 0.4.0__tar.gz
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.
Potentially problematic release.
This version of vec-io might be problematic. Click here for more details.
- {vec_io-0.2.0 → vec_io-0.4.0}/API.md +473 -214
- {vec_io-0.2.0 → vec_io-0.4.0}/EXAMPLES.md +52 -16
- {vec_io-0.2.0 → vec_io-0.4.0}/PKG-INFO +17 -10
- {vec_io-0.2.0 → vec_io-0.4.0}/README.md +16 -9
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/canvas_demo.py +2 -2
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/fuzz_native.py +439 -28
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/fuzz_pdfread.py +2 -2
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/helpers.py +26 -6
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/scene_oracle.py +29 -10
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/svg_oracle.py +63 -58
- vec_io-0.4.0/tests/test_actual_text.py +262 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_api.py +48 -51
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_canvas_features.py +6 -7
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_cells.py +4 -4
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_cmyk.py +8 -8
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_compile.py +15 -15
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_convert.py +58 -6
- vec_io-0.4.0/tests/test_css_browser.py +343 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_deflate.py +1 -1
- vec_io-0.4.0/tests/test_document_write.py +360 -0
- vec_io-0.4.0/tests/test_dpi.py +213 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_eps.py +42 -42
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_features.py +19 -15
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_filters.py +4 -4
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_flatten.py +39 -24
- vec_io-0.4.0/tests/test_font_fixes.py +260 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_font_sources.py +2 -3
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_fonts_io.py +18 -17
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_google_fonts.py +12 -12
- vec_io-0.4.0/tests/test_image_formats.py +422 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_jxl.py +8 -8
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_marker_runs.py +1 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_native.py +1 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_native_emit.py +1 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_native_jpeg.py +4 -4
- vec_io-0.4.0/tests/test_native_limits.py +357 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_native_png.py +2 -2
- vec_io-0.4.0/tests/test_network.py +235 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_output.py +45 -45
- vec_io-0.4.0/tests/test_output_fixes.py +314 -0
- vec_io-0.4.0/tests/test_paint_browser.py +354 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_pdf_security.py +1 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_pdfa.py +5 -5
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_pdfread.py +16 -16
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_raster.py +64 -56
- vec_io-0.4.0/tests/test_reader_fixes.py +237 -0
- vec_io-0.4.0/tests/test_resize.py +230 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_scene.py +10 -10
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_shapes.py +7 -7
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_simplify.py +62 -28
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_svg_semantics.py +3 -5
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_svg_writer.py +46 -10
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_text.py +3 -3
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_text_as_paths.py +3 -4
- vec_io-0.4.0/tests/test_text_browser.py +258 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_textlayout.py +10 -10
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_threads.py +9 -10
- vec_io-0.4.0/tests/test_trim.py +225 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_type1.py +3 -3
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_units.py +26 -9
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_varfonts.py +2 -2
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_woff2.py +1 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/tools/gen_api.py +36 -10
- vec_io-0.4.0/vec_io/__init__.py +56 -0
- vec_io-0.4.0/vec_io/__main__.py +308 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/canvas.py +433 -373
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/cells.py +21 -21
- vec_io-0.4.0/vec_io/convert.py +244 -0
- vec_io-0.4.0/vec_io/document.py +1232 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/draw.py +60 -108
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/eps/__init__.py +29 -56
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/eps/fonts.py +12 -20
- vec_io-0.4.0/vec_io/errors.py +11 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/filter.py +6 -2
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/flatten.py +153 -121
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/__init__.py +28 -13
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/cff.py +316 -89
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/cff2.py +15 -95
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/download.py +200 -202
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/fontdb.py +116 -45
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/google.py +46 -65
- vec_io-0.4.0/vec_io/fonts/opentype.py +1180 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/sfnt.py +223 -148
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/type1.py +22 -138
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/variations.py +4 -85
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/geometry.py +0 -4
- vec_io-0.4.0/vec_io/image/__init__.py +131 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/image/avif.py +69 -5
- vec_io-0.4.0/vec_io/image/bmp.py +297 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/image/codecs.py +6 -13
- vec_io-0.4.0/vec_io/image/gif.py +122 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/image/jbig2.py +2 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/image/jpx.py +2 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/image/jxl.py +2 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/image/resource.py +171 -27
- vec_io-0.4.0/vec_io/image/webp.py +166 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/lines.py +19 -19
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/README.md +44 -21
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/__init__.py +2 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/_api.py +31 -7
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/bin/linux-aarch64.so +0 -0
- vec_io-0.4.0/vec_io/native/bin/linux-x86_64.so +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/bin/macos-arm64.dylib +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/bin/windows-arm64.dll +0 -0
- vec_io-0.4.0/vec_io/native/bin/windows-x86_64.dll +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/deflate.py +1 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/emit.py +34 -17
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/jpeg.py +5 -4
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/manifest.json +12 -12
- vec_io-0.4.0/vec_io/native/pdfread.py +175 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/png.py +7 -7
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/alloc.c +1 -3
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/ccitt.c +19 -5
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/cull.c +15 -8
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/emit.c +21 -2
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/epsw.c +31 -137
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/filters.c +18 -11
- vec_io-0.4.0/vec_io/native/src/image.c +324 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/interp.c +271 -490
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/items.c +30 -30
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/jpx.c +3 -5
- vec_io-0.4.0/vec_io/native/src/lex.h +182 -0
- vec_io-0.4.0/vec_io/native/src/matrix.h +33 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/paint.c +74 -7
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/path.c +0 -7
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/pdfread.c +84 -184
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/pio.h +15 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/pio_api.h +42 -11
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/png.c +11 -6
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/raster.h +12 -35
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/res.c +13 -4
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/scene.c +173 -315
- vec_io-0.4.0/vec_io/native/src/scene.h +728 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/shade.c +3 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/signatures.c +5 -16
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/stroke.c +21 -5
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/svgw.c +350 -417
- vec_io-0.4.0/vec_io/network.py +147 -0
- vec_io-0.4.0/vec_io/options.py +371 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/paint.py +72 -25
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdf/images.py +9 -7
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdf/objects.py +6 -3
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdf/writer.py +3 -3
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/__init__.py +13 -13
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/ccitt.py +2 -1
- vec_io-0.4.0/vec_io/pdfread/cffinfo.py +116 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/cmap.py +2 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/colors.py +4 -4
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/content.py +44 -54
- vec_io-0.4.0/vec_io/pdfread/convert.py +42 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/errors.py +3 -2
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/file.py +14 -22
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/fonts.py +77 -219
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/functions.py +18 -11
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/images.py +10 -32
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/meshes.py +1 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/parser.py +2 -1
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/reader.py +20 -36
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/resources.py +25 -41
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/security.py +5 -22
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/shadings.py +11 -23
- vec_io-0.4.0/vec_io/pdfread/strings.py +44 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/raster/__init__.py +29 -15
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/raster/groups.py +10 -8
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/raster/resources.py +11 -5
- vec_io-0.4.0/vec_io/resample.py +239 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/scene.py +82 -4
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/shapes.py +14 -14
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/simplify.py +75 -47
- vec_io-0.4.0/vec_io/svg/__init__.py +7 -0
- vec_io-0.4.0/vec_io/svg/basic_shapes.py +250 -0
- vec_io-0.4.0/vec_io/svg/css.py +1043 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/svg/filters.py +8 -40
- vec_io-0.4.0/vec_io/svg/parse.py +535 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/svg/render.py +1316 -282
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/svg/writer.py +124 -74
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/text/__init__.py +586 -137
- vec_io-0.4.0/vec_io/text/bidi.py +413 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/text/breaking.py +41 -19
- vec_io-0.4.0/vec_io/text/harfbuzz.py +222 -0
- vec_io-0.4.0/vec_io/text/shaping.py +402 -0
- vec_io-0.4.0/vec_io/trim.py +151 -0
- vec_io-0.4.0/vec_io/units.py +596 -0
- vec_io-0.2.0/vec_io/__init__.py +0 -40
- vec_io-0.2.0/vec_io/__main__.py +0 -217
- vec_io-0.2.0/vec_io/document.py +0 -889
- vec_io-0.2.0/vec_io/fonts/opentype.py +0 -384
- vec_io-0.2.0/vec_io/image/__init__.py +0 -232
- vec_io-0.2.0/vec_io/native/bin/linux-x86_64.so +0 -0
- vec_io-0.2.0/vec_io/native/bin/windows-x86_64.dll +0 -0
- vec_io-0.2.0/vec_io/native/pdfread.py +0 -75
- vec_io-0.2.0/vec_io/native/src/image.c +0 -150
- vec_io-0.2.0/vec_io/native/src/scene.h +0 -228
- vec_io-0.2.0/vec_io/pdfread/_native.py +0 -95
- vec_io-0.2.0/vec_io/pdfread/cffinfo.py +0 -177
- vec_io-0.2.0/vec_io/pdfread/convert.py +0 -57
- vec_io-0.2.0/vec_io/svg/__init__.py +0 -167
- vec_io-0.2.0/vec_io/svg/css.py +0 -366
- vec_io-0.2.0/vec_io/svg/parse.py +0 -343
- vec_io-0.2.0/vec_io/units.py +0 -105
- {vec_io-0.2.0 → vec_io-0.4.0}/LICENSE +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/bubble_chart.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/drawing_demo.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/heatmap.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/scatter_plot.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/showcase.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/text.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/examples/text_layout.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/pyproject.toml +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/abc.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/abc.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/big.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/big.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/binary.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/binary.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/bits2.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/bits2.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/dictwords.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/dictwords.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/empty.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/empty.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/four.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/four.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/handmade.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/handmade.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/ints.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/ints.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/mixed.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/mixed.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/multi.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/multi.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/one.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/one.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/random.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/random.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/text11.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/text11.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/text_q2.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/text_q2.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/three.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/three.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/w10.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/w10.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/w24.br +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/brotli/w24.out.z +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/clipping.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/css.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/empty.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/filters.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/fonts_face.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/gradients.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/images.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/markers.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/masks.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/opacity.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/paths.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/patterns.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/rasterized.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/shapes.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/strokes.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/structure.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/text-wrap.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/text_basic.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/text_layout.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/text_path.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/text_unicode.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/transforms.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/units.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/use_symbol.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/corpus/viewbox.svg +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/fonts/PioTest-Bold.ttf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/fonts/PioTest-Regular.ttf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/jbig2_encoder.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/jpx_fixtures.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/make_crypt_fixtures.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/maps.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfbuild.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/cmyk8.j2k +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/cmyk8.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/gray12.j2k +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/gray16.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/gray4-signed.j2k +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/graya16.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/gs-r2.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/gs-r3.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/icc-gray8.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r2.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r3.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r4-aes-nometa.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r4-aes.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r4-pdfdoc.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r4-rc4.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r5.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r6-empty.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r6-utf8.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/qpdf-r6.pdf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/rgb8.j2k +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/rgb8.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/rgba8.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/ycc420.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/pdfread/ycc422-offset.jp2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/shapes.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_avif.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_ccitt.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_cmap.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_codecs.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_encodings.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_jpx_jbig2.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/test_parsing.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/testfont.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/varfonts/VarTest.otf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/varfonts/VarTest.ttf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/woff2/make.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/woff2/pair.woff2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/woff2/rich-null.woff2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/woff2/rich.ttf +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tests/woff2/rich.woff2 +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/tools/build_native.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/arrays.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/flate.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/ctan.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/encodings.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/fontshare.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/fontshare_families.txt +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/fontsource.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/fontsource_families.txt +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/glyphlist.txt +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/google_families.txt +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/urw.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/fonts/woff2.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/items.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/brotli.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/filters.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/brotli.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/brotli.h +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/brotli_dict.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/crowding.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/crypt.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/data.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/deflate.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/flat.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/jpeg.h +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/jpeg_dec.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/jpeg_enc.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/math.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/mesh.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/quant.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/rt.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/scan.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/shade.h +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/src/woff2.c +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/native/woff2.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdf/__init__.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdf/pdfa.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/pdfread/cmap_resources.txt +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/py.typed +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/text/path.py +0 -0
- {vec_io-0.2.0 → vec_io-0.4.0}/vec_io/threads.py +0 -0
|
@@ -33,16 +33,30 @@ Complete reference. Worked examples are in [EXAMPLES.md](EXAMPLES.md).
|
|
|
33
33
|
`vec_io.draw` drawings drawn on its pages: all are in it. SVG input is in CSS pixels by
|
|
34
34
|
its own definition and is scaled into the page. `vec_io.units` parses CSS dimensions:
|
|
35
35
|
`split_length(value, units=None)` gives `(number, unit)` or raises `ValueError`;
|
|
36
|
-
`
|
|
37
|
-
degrees; `parse_length` is the lenient SVG form
|
|
36
|
+
`to_points(value, unit_scale, what="length")` gives points; `parse_angle(value,
|
|
37
|
+
strict=False)` gives degrees; `parse_length` is the lenient SVG form (math functions
|
|
38
|
+
evaluated); `evaluate_math(text, resolve=None)` gives a math function's `{unit: number}`
|
|
39
|
+
sum, `simplify_math(value)` replaces those that need no context by their results.
|
|
40
|
+
Tables: `PX_PER_UNIT`, `ANGLE_UNITS`, `RELATIVE_UNITS`.
|
|
41
|
+
* **Lengths.** A number is in the unit of its context, a string carries its unit (`"2in"`,
|
|
42
|
+
`"5mm"`, `"12pt"`; a paper size's side, `"a4"`, where a width or height is asked): on a
|
|
43
|
+
`Page`, the document's unit; in a `View` (so in `convert` and on the command line), CSS
|
|
44
|
+
pixels, for SVG and PDF input alike. `%` and `em` are refused where a length is not
|
|
45
|
+
relative to something. Every length goes through `vec_io.units.to_points`.
|
|
46
|
+
* **Opacity and alpha.** *Opacity* is a multiplier applied when drawing (0–1): the canvas
|
|
47
|
+
state `opacity`, `group(opacity=…)`, the bulk calls' `opacity`, `fill_opacity` and
|
|
48
|
+
`stroke_opacity` of drawings, a gradient stop's `opacity`. *Alpha* is the alpha channel of a
|
|
49
|
+
color or pixel: `Color(r, g, b, alpha)`, `CMYK(…, alpha)`, `Spot(…, alpha)`,
|
|
50
|
+
`with_alpha`, CSS `/ alpha`, `Image.alpha`.
|
|
38
51
|
* **Colors.** A color is a CSS string (`"red"`, `"#rgb[a]"`, `"#rrggbb[aa]"`,
|
|
39
52
|
`"transparent"`, and the CSS Color 4 functions in modern or comma syntax: `rgb[a]()`,
|
|
40
53
|
`hsl[a]()`, `hwb()`, `lab()`, `lch()`, `oklab()`, `oklch()`, `color(<space> r g b)` with
|
|
41
54
|
`srgb`, `srgb-linear`, `display-p3`, `a98-rgb`, `prophoto-rgb`, `rec2020`, `xyz`,
|
|
42
55
|
`xyz-d50`, `xyz-d65`, and `device-cmyk(c m y k)`; each takes `/ alpha` and `none`); a
|
|
43
56
|
tuple `(r, g, b)` or `(r, g, b, a)` of numbers in [0, 1]; or a print color below.
|
|
57
|
+
`Color(r, g, b, alpha=1)` is such a tuple, checked, with `alpha` and `with_alpha(alpha)`.
|
|
44
58
|
Components outside [0, 1] raise `ValueError`: values on the 0–255 scale go through
|
|
45
|
-
`rgb255(r, g, b, alpha=1)` or a CSS string. Colors outside sRGB are gamut mapped as
|
|
59
|
+
`Color.rgb255(r, g, b, alpha=1)` or a CSS string. Colors outside sRGB are gamut mapped as
|
|
46
60
|
CSS Color 4 specifies (chroma reduced in OKLCh).
|
|
47
61
|
* **Print colors.** `CMYK(c, m, y, k, alpha=1)` is a device CMYK color, components in
|
|
48
62
|
[0, 1]. `Spot(name, cmyk, tint=1, alpha=1)` is a spot ink: `cmyk` (a `CMYK` or 4-tuple)
|
|
@@ -55,13 +69,13 @@ Complete reference. Worked examples are in [EXAMPLES.md](EXAMPLES.md).
|
|
|
55
69
|
convert between sRGB (gamma-encoded, 0–1; clipped on the way back) and Oklab;
|
|
56
70
|
`oklch_to_oklab(L, C, H)` takes the hue in degrees; `lchuv_to_srgb(L, C, H)` converts CIE
|
|
57
71
|
LCh(uv) (D65, lightness 0–100) to sRGB as R's `hcl()` does.
|
|
58
|
-
* **Sources.** Files are given as paths; images and SVGs may also be bytes
|
|
59
|
-
Relative references resolve against `base_dir`; without it only `data:`
|
|
60
|
-
With it, any local file the process can read may be embedded
|
|
61
|
-
paths, `file:` URLs on this machine)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* **Types.** The package is typed (`py.typed`). Aliases: `vec_io.
|
|
72
|
+
* **Sources.** Files are given as paths; images and SVGs may also be bytes, `data:` URIs or
|
|
73
|
+
http(s) URLs. Relative references resolve against `base_dir`; without it only `data:`
|
|
74
|
+
URIs and URLs are loaded. With it, any local file the process can read may be embedded
|
|
75
|
+
(`../` paths, absolute paths, `file:` URLs on this machine); `file:` URLs naming another
|
|
76
|
+
host are never read. URLs are fetched unless `network=False`; for untrusted SVG pass
|
|
77
|
+
`network=False` and `base_dir=None` ([Network and other files](#network-and-other-files)).
|
|
78
|
+
* **Types.** The package is typed (`py.typed`). Aliases: `vec_io.ColorLike` (a color argument),
|
|
65
79
|
`vec_io.Paint` (a color, gradient, pattern or `None`), `vec_io.Content` (text layout
|
|
66
80
|
content). Chainable methods return the object's own type.
|
|
67
81
|
* **Arrays.** Coordinates, sizes, per-item values and cell grids are sequences (`None`
|
|
@@ -70,45 +84,72 @@ Complete reference. Worked examples are in [EXAMPLES.md](EXAMPLES.md).
|
|
|
70
84
|
* **C library.** Bulk work (writing content streams, rasterization, culling, PNG and JPEG
|
|
71
85
|
coding, filters) runs in a bundled C library, prebuilt for Linux x86_64/aarch64, Windows
|
|
72
86
|
x86_64/arm64 and macOS arm64. It releases the GIL. Elsewhere, features that need it
|
|
73
|
-
raise `vec_io.
|
|
87
|
+
raise `vec_io.NativeLibraryError` (build it with `tools/build_native.py` and set
|
|
74
88
|
`VEC_IO_NATIVE_LIB`).
|
|
75
89
|
|
|
76
90
|
## 2. Converting SVG
|
|
77
91
|
|
|
78
92
|
```python
|
|
79
|
-
convert(source, output=None, *, format=None, base_dir=None,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
dpi=96, background=None, png=None, jpeg=None, jxl=None, avif=None,
|
|
83
|
-
flatten_transparency=False, flatten_fallback="raster", flatten_dpi=600,
|
|
84
|
-
flatten_budget=256, flatten_cell=0.25) -> bytes
|
|
93
|
+
convert(source, output=None, *, format=None, base_dir=None, fonts=None, filters=True,
|
|
94
|
+
network=True, text_as_paths=False, pdf_a=None, default_dpi=None, page=None,
|
|
95
|
+
password=None, annotations=True, **options) -> bytes
|
|
85
96
|
```
|
|
86
97
|
|
|
87
|
-
Converts an SVG document to PDF, EPS, PNG, JPEG, JPEG XL or AVIF, returns the
|
|
88
|
-
them to `output` (a path or a binary file object) when given. It is a
|
|
89
|
-
pixels with the SVG on its page,
|
|
98
|
+
Converts an SVG (or PDF) document to PDF, EPS, SVG, PNG, JPEG, JPEG XL or AVIF, returns the
|
|
99
|
+
bytes and writes them to `output` (a path or a binary file object) when given. It is a
|
|
100
|
+
`Document` in CSS pixels with the SVG on its page, written by `Document.write` with
|
|
101
|
+
`options` ([Output options](#181-options)).
|
|
90
102
|
|
|
91
103
|
| Parameter | Meaning |
|
|
92
104
|
|---|---|
|
|
93
105
|
| `source` | SVG text or bytes (gzip-compressed SVGZ too), a path, a binary file object, or an `SVGDocument`. A string not starting with `<` is a path. |
|
|
94
|
-
| `format` | `"pdf"`, `"eps"`, `"png"`, `"jpeg"`, `"jxl"` or `"avif"`; default: the extension of an `output` path, else `"pdf"`. |
|
|
95
|
-
| `base_dir` | Directory of relative `<image
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
106
|
+
| `format` | `"pdf"`, `"eps"`, `"svg"`, `"png"`, `"jpeg"`, `"jxl"` or `"avif"`; default: the extension of an `output` path (none: PDF; an unknown one: `OptionError`), else `"pdf"`. |
|
|
107
|
+
| `base_dir` | Directory of relative references (`<image>`, `<use>`, style sheets, `@font-face`); default: a source path's directory; `None`: none read ([Network and other files](#network-and-other-files)). |
|
|
108
|
+
| `network` | Fetch the http and https URLs the SVG refers to, and download fonts (default `True`; [Network and other files](#network-and-other-files)). |
|
|
109
|
+
| `fonts` | A `Fonts` ([Fonts](#16-fonts)). |
|
|
110
|
+
| `filters` | Apply SVG filters (default `True`; rasterizes filtered elements; [Filters](#14-filters)). |
|
|
98
111
|
| `text_as_paths` | Text drawn as glyph outlines, no font written ([Fonts](#16-fonts)). |
|
|
112
|
+
| `media`, `color_scheme` | What `@media` and `<style media>` are evaluated for: `"print"` (default) or `"screen"`, and `prefers-color-scheme` `"light"` (default) or `"dark"`. |
|
|
99
113
|
| `pdf_a` | PDF: `"2b"`, `"2u"` or `"3b"` ([PDF/A](#pdfa)). |
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
114
|
+
| `default_dpi` | The document's `default_dpi`: the resolution of image output without `dpi` (default `"2x"`: 192 dpi, two pixels per CSS pixel). |
|
|
115
|
+
| `page`, `password`, `annotations` | PDF input ([Reading PDF](#reading-pdf)). |
|
|
116
|
+
| `options` | The output's options, as `Document.write` takes them: `compression`, `simplify`, `images`, `flatten`, `font_hinting`, `dpi`, `view`, `background`, `png`, `jpeg`, `jxl`, `avif` ([18.1](#181-options)). Numbers in a `View` are CSS pixels. |
|
|
103
117
|
|
|
104
|
-
`SVGDocument(source
|
|
105
|
-
|
|
118
|
+
`SVGDocument(source, *, base_dir=None, network=True, media="print", color_scheme="light")`
|
|
119
|
+
parses SVG once (`vec_io.svg.parse`),
|
|
120
|
+
with the style sheets it loads (`@import`, `<?xml-stylesheet?>`, relative to `base_dir`);
|
|
121
|
+
`SVGParseError` reports input that is not usable SVG, `OptionError` an option that cannot be
|
|
122
|
+
used ([Errors](#19-errors)).
|
|
106
123
|
|
|
107
124
|
```python
|
|
108
125
|
vec_io.convert("drawing.svg", "drawing.pdf")
|
|
109
126
|
png = vec_io.convert(text, format="png", dpi=192, png=vec_io.PNG(quality=90))
|
|
127
|
+
vec_io.convert("figure.svg", "figure.pdf", view={"trim": True, "margin": "2mm"})
|
|
128
|
+
vec_io.convert("figure.svg", "figure.pdf", view=vec_io.View(size="us", margin="1in"))
|
|
110
129
|
```
|
|
111
130
|
|
|
131
|
+
### Network and other files
|
|
132
|
+
|
|
133
|
+
What an SVG refers to is loaded from `data:` URIs, local files (relative to `base_dir`) and,
|
|
134
|
+
with `network=True` (the default), http and https URLs: `<image>`, `<use>` of an element of
|
|
135
|
+
another document (`other.svg#id`: the document is loaded and the element drawn with its own
|
|
136
|
+
references and style sheets), `@import` style sheets, `<?xml-stylesheet?>`, `@font-face`
|
|
137
|
+
`src: url(…)`, and font downloads ([Font downloads](#font-downloads)). Each file or URL is
|
|
138
|
+
loaded once per document; references between documents may form cycles. A document from a
|
|
139
|
+
URL resolves its relative references on its server and never reads local files.
|
|
140
|
+
|
|
141
|
+
`vec_io.network` sets the limits: 64 MB per resource (`MAX_RESOURCE`), 256 MB per document
|
|
142
|
+
(`MAX_DOCUMENT`), 200 URLs per document (`MAX_RESOURCES`), 30 s per request (`TIMEOUT`);
|
|
143
|
+
redirects stay on http and https (never from https to http); a generic user agent. A URL
|
|
144
|
+
that cannot be fetched gives a `NetworkWarning` and is drawn as missing. `network=False`
|
|
145
|
+
fetches nothing and turns font downloads off, whatever `Fonts(downloads=…)` says (a
|
|
146
|
+
`Fonts(db=…)` keeps its own setting).
|
|
147
|
+
|
|
148
|
+
**Security.** An untrusted SVG can make the process fetch any URL, including ones on the
|
|
149
|
+
local network, and, with a `base_dir`, read any local file the process can read into the
|
|
150
|
+
output. For untrusted input pass `network=False` and `base_dir=None` (CLI: `--no-network`,
|
|
151
|
+
and a document read from stdin).
|
|
152
|
+
|
|
112
153
|
### Reading PDF
|
|
113
154
|
|
|
114
155
|
```python
|
|
@@ -126,7 +167,8 @@ becomes the metadata. Forms, actions other than links, JavaScript and embedded f
|
|
|
126
167
|
not read. Illustrator files (`.ai`, Illustrator 9 and later) are PDF files and read as
|
|
127
168
|
such; their private data is ignored.
|
|
128
169
|
|
|
129
|
-
`convert` and the command line read PDF input (data
|
|
170
|
+
`convert` and the command line read PDF input (data with `%PDF-` near its start, before any
|
|
171
|
+
`<`, not gzip): every page
|
|
130
172
|
(or `page`) as PDF, page `page` (default 0) as an image; `password` and `annotations` as
|
|
131
173
|
above. `Canvas.draw_pdf` places a page ([5.5](#55-images-and-svg)).
|
|
132
174
|
|
|
@@ -134,7 +176,7 @@ above. `Canvas.draw_pdf` places a page ([5.5](#55-images-and-svg)).
|
|
|
134
176
|
|---|---|
|
|
135
177
|
| File | cross-reference tables and streams, incremental updates, object streams; a damaged table rebuilt by scanning the file; encryption (standard handler, RC4 and AES, revisions 2–6) |
|
|
136
178
|
| Filters | Flate, LZW (PNG and TIFF predictors), ASCII85, ASCIIHex, RunLength, CCITT fax; DCT, JPEG 2000, JBIG2 and JPEG XL images kept encoded for PDF output |
|
|
137
|
-
| Content | paths, clips, device colours, graphics states (alpha, soft masks, blend modes
|
|
179
|
+
| Content | paths, clips, device colours, graphics states (alpha, soft masks, blend modes; image output composites every group as isolated), forms and transparency groups, images (masks, soft masks, colour keys, `Decode`, 1–16 bits), tiling patterns, shadings 1–7, optional content (the default configuration), Type 3 glyphs |
|
|
138
180
|
| Colour | Gray, RGB, CMYK; ICC by component count; CalGray, CalRGB and Lab to sRGB; Indexed; Separation (a spot colour when its alternate is CMYK) and DeviceN through their tint transforms; functions 0, 2, 3, 4 |
|
|
139
181
|
| Fonts | TrueType, Type 1, Type 1C, OpenType and Type 3 simple fonts; CID fonts (CFF, TrueType, `CIDToGIDMap`), embedded and predefined CMaps; glyphs placed by the PDF's widths; fonts that are not embedded drawn with an installed or downloaded family of their name (the standard 14 with URW's metric-compatible families) |
|
|
140
182
|
|
|
@@ -149,7 +191,9 @@ glyphs nested 32 deep, 50 million operators per page), an Illustrator file saved
|
|
|
149
191
|
PDF content (save it again with "Create PDF Compatible File"), PostScript (an Illustrator
|
|
150
192
|
8 or earlier `.ai` or EPS file: convert it with `ps2pdf`). `PDFReadWarning`: content left
|
|
151
193
|
out (an unknown operator, a broken object, an image without its library…), once per kind
|
|
152
|
-
and file.
|
|
194
|
+
and file. A stream naming an unknown crypt filter is left out with a `PDFReadWarning`; the
|
|
195
|
+
rest of the file is read. Text strings (document information, outline titles, link URIs)
|
|
196
|
+
are UTF-16 or UTF-8 with a byte order mark, else PDFDocEncoding.
|
|
153
197
|
|
|
154
198
|
```python
|
|
155
199
|
doc = vec_io.open_pdf("report.pdf", pages=[0, 1])
|
|
@@ -167,61 +211,89 @@ vec_io --download-font FAMILY …
|
|
|
167
211
|
| Argument | Meaning |
|
|
168
212
|
|---|---|
|
|
169
213
|
| `INPUT` | SVG or PDF file (`.ai` too), or `-` for stdin. |
|
|
170
|
-
| `OUTPUT` | Output file, or `-` for stdout. Default: `INPUT` with the extension of `--format` (`.pdf`, `.eps`, `.png`, `.jpg`, `.jxl`, `.avif`). |
|
|
171
|
-
| `--format FORMAT` | `pdf
|
|
172
|
-
| `--
|
|
173
|
-
| `--compression LEVEL` | `fast`, `balanced` (default) or `best`: the encoder's effort. |
|
|
214
|
+
| `OUTPUT` | Output file, or `-` for stdout. Default: `INPUT` with the extension of `--format` (`.pdf`, `.eps`, `.svg`, `.png`, `.jpg`, `.jxl`, `.avif`). |
|
|
215
|
+
| `--format FORMAT` | `pdf`, `eps`, `svg`, `png`, `jpeg`, `jxl` or `avif`. Default: from the extension of `OUTPUT` (`.pdf`, `.eps`, `.svg`, `.png`, `.jpg` or `.jpeg`, `.jxl`, `.avif`, any case), else `pdf`. |
|
|
216
|
+
| `--compression LEVEL` | `fast`, `balanced` (default) or `small`: the encoder's effort; `none`: uncompressed streams (PDF, EPS). |
|
|
174
217
|
| `--font-dir DIR` | Extra font directory (repeatable). |
|
|
175
218
|
| `--no-system-fonts` | Ignore installed fonts. |
|
|
176
219
|
| `--font-downloads MODE` | Downloads of families that are not installed: `on` (default, or `VEC_IO_FONT_DOWNLOADS`), `off`, or `cache` (downloaded families only) ([Font downloads](#font-downloads)). |
|
|
177
220
|
| `--no-font-downloads` | Same as `--font-downloads off`. |
|
|
178
221
|
| `--download-font FAMILY` | Download every style of a family into the cache from the first source that has it and print its files, without converting (repeatable; no `INPUT`). Exit status 1 when one fails. |
|
|
179
|
-
| `--filters` |
|
|
222
|
+
| `--no-filters` | Do not apply SVG filters (applied by default). |
|
|
223
|
+
| `--no-network` | Fetch no URL and download no font ([Network and other files](#network-and-other-files)). |
|
|
180
224
|
| `--text-as-paths` | Text drawn as glyph outlines, no font written. |
|
|
225
|
+
| `--media MEDIA`, `--color-scheme SCHEME` | What `@media` rules are evaluated for: `print` (default) or `screen`; `light` (default) or `dark`. |
|
|
181
226
|
| `--quality N` | PDF: store rasterized content as JPEG (JPEG XL with `--jxl`) of quality N (1–100); images: the quality of the image (JPEG default 90, JPEG XL and AVIF default lossless, PNG a lossy palette). |
|
|
182
227
|
| `--jxl` | Write the PDF's images as JPEG XL ([JPEG XL](#jpeg-xl)). |
|
|
183
228
|
| `--pdf-a LEVEL` | Write PDF/A: `2b`, `2u` or `3b`. |
|
|
184
229
|
| `--simplify [DPI]` | Leave out what later content hides at DPI (default 600); `--simplify auto`: only where it pays off. |
|
|
185
|
-
| `--flatten-transparency` | PDF: translucent content drawn as opaque vectors ([Transparency flattening](#transparency-flattening)); EPS always is. |
|
|
186
|
-
| `--flatten-fallback MODE` | PDF and
|
|
230
|
+
| `--flatten-transparency` | PDF and SVG: translucent content drawn as opaque vectors ([Transparency flattening](#transparency-flattening)); EPS always is. |
|
|
231
|
+
| `--flatten-fallback MODE` | PDF, EPS and SVG: what cannot be flattened becomes: `raster` (default), `opaque` or `error`. |
|
|
187
232
|
| `--flatten-dpi N`, `--flatten-budget N`, `--flatten-cell INCHES` | The raster fallback's resolution (default 600), the pieces per grid cell (default 256) and the cell size (default 0.25). |
|
|
188
|
-
| `--
|
|
233
|
+
| `--width W`, `--height H` | The output's size: CSS pixels, a length (`85mm`) or a paper size (`a4`, `letter`, `us`, `a4-landscape`, …); one keeps the aspect ratio. |
|
|
234
|
+
| `--size SIZE` | Both sides: a paper size (`us`, `a4`, `a4-landscape`, …) or `"8.5in x 11in"` (`x`, `×` or `*`); not with `--width`, `--height` or `--scale`. |
|
|
235
|
+
| `--scale S` | The output zoomed by a factor (not with `--width`/`--height`). |
|
|
236
|
+
| `--aspect MODE` | With both sides only: `fit` (default: the page that size, the content fitted inside) or `stretch`. |
|
|
237
|
+
| `--align A[,V]` | With both sides and `fit`: where the content sits in the room left: `start`, `center` (default) or `end`; two values: horizontal, vertical (start: left, top). |
|
|
238
|
+
| `--trim` | Cut to the content. Blank is transparent or white. |
|
|
239
|
+
| `--margin M` | Blank space on each side (CSS pixels or a length, `2mm`): around the content with `--trim`, inside the size given, else added around the page. |
|
|
240
|
+
| `--dpi N` | The output's resolution, in dpi or `Nx` (N × 96): images rendered at it (default `2x`, 192 dpi); PDF, EPS and SVG images resampled to it (default: kept as they are). |
|
|
241
|
+
| `--dpi-mode MODE` | PDF, EPS, SVG with `--dpi`: `down` (default: images finer than `--dpi` resampled down to it) or `match` (every image resampled to it). |
|
|
242
|
+
| `--dpi-threshold F` | PDF, EPS, SVG with `--dpi`: images within a factor F of `--dpi` kept (default 1.5; at least 1). |
|
|
243
|
+
| `--dpi-average MODE` | PDF, EPS, SVG with `--dpi`: `srgb` (default: the stored values averaged) or `linear` (light averaged) when images are shrunk. |
|
|
189
244
|
| `--page N` | PDF input: the page (from 0; default every page for PDF output, the first for images). |
|
|
190
245
|
| `--password P` | PDF input: the password of an encrypted file. |
|
|
191
246
|
| `--no-annotations` | PDF input: page content only. |
|
|
192
247
|
| `--version` | Print the version. |
|
|
193
248
|
|
|
194
|
-
Exit status 1 on unreadable input, invalid SVG, PDF that cannot be read, malformed fonts
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
249
|
+
Exit status 1 on unreadable input, invalid SVG, PDF that cannot be read, malformed fonts,
|
|
250
|
+
an output that is the input file, or write errors (including a closed standard output);
|
|
251
|
+
status 2 on invalid arguments: `--dpi` or `--simplify` not positive, `--dpi-threshold`
|
|
252
|
+
below 1, `--flatten-dpi`, `--flatten-budget` or `--flatten-cell` not positive, a negative or
|
|
253
|
+
unreadable `--margin`, a `--width`/`--height` that is not a positive length or a known paper
|
|
254
|
+
size, an unreadable `--size` or one with `--width`/`--height`/`--scale`, `--scale` not
|
|
255
|
+
positive or with `--width`/`--height`, an unknown `--align`, `--aspect` or `--align`
|
|
256
|
+
without both sides, a margin that leaves no room at the size, `--quality` outside 1–100,
|
|
257
|
+
a `--format` that disagrees with the extension of `OUTPUT`, an image, EPS or SVG format
|
|
258
|
+
with `--pdf-a` or `--jxl`, or an image format with `--compression none` or
|
|
259
|
+
`--flatten-transparency` (SVG: `--compression none`).
|
|
260
|
+
|
|
261
|
+
The command line builds the option objects `convert` takes (`Fonts`, `View`, `Flatten`,
|
|
262
|
+
`ImagePolicy`, `PNG`, …): its output is `convert`'s for the same options, byte for byte.
|
|
198
263
|
|
|
199
264
|
## 4. Document and Page
|
|
200
265
|
|
|
201
266
|
```python
|
|
202
|
-
Document(unit="pt", title=None, author=None, subject=None, keywords=None, creator=None,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
267
|
+
Document(unit="pt", *, title=None, author=None, subject=None, keywords=None, creator=None,
|
|
268
|
+
fonts=None, base_dir=None, filters=True, network=True, color_mode="rgb",
|
|
269
|
+
ink_limit=None, icc_profile=None, pdf_a=None, creation_date=None,
|
|
270
|
+
text_as_paths=False, default_dpi="2x")
|
|
206
271
|
```
|
|
207
272
|
|
|
208
273
|
A document records what is drawn on its pages: commands, the images and fonts as they were
|
|
209
274
|
given, and what content asks of simplification. Outputs are made from that record when
|
|
210
|
-
asked for, with their own options: `save
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
275
|
+
asked for, with their own options: `write` and `save` write a file of any kind
|
|
276
|
+
([Output](#18-output)), `Page.render` renders a page to an `Image`
|
|
277
|
+
([5.9](#59-rendering-and-image-output)). They can be called any number of times, in any
|
|
278
|
+
order, and drawing may go on after any; the same record written with the same options gives
|
|
279
|
+
the same bytes.
|
|
214
280
|
|
|
215
281
|
The constructor takes document-level choices. `unit` is the document's unit
|
|
216
282
|
([Conventions](#1-conventions)). The metadata arguments fill the PDF document information.
|
|
217
283
|
`base_dir` resolves relative paths given to `draw_image`, `draw_svg`, `add_font`, `attach`
|
|
218
284
|
and `icc_profile` (default: the working directory), and the references of SVGs placed from
|
|
219
|
-
text or bytes. `filters` applies to SVGs placed with `draw_svg`. `
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
285
|
+
text or bytes. `filters` (default on) applies to SVGs placed with `draw_svg`. `network`
|
|
286
|
+
fetches the URLs they refer to and downloads fonts (default on; [Network and other
|
|
287
|
+
files](#network-and-other-files)). `fonts` (a `Fonts`, or a
|
|
288
|
+
dict of its fields) says where fonts come from; `Fonts(db=…)` shares a `FontDB` between
|
|
289
|
+
documents ([Fonts](#16-fonts)). `text_as_paths=True` draws text as the outlines of its
|
|
290
|
+
glyphs ([Fonts](#16-fonts)). `creation_date` (a `datetime`; naive means local time) is
|
|
223
291
|
written as the creation and modification date; PDF/A files default to the current time,
|
|
224
|
-
other files have no date unless one is given.
|
|
292
|
+
other files have no date unless one is given. `default_dpi` is the resolution of image
|
|
293
|
+
output when none is given (`Page.render`, `write` to an image format); PDF, EPS and SVG
|
|
294
|
+
output never use it. A resolution (`dpi`, `default_dpi`, `ImagePolicy(dpi=…)`,
|
|
295
|
+
`Flatten(dpi=…)`) is a number of dots per inch or `"Nx"`, N image pixels per CSS pixel
|
|
296
|
+
(N × 96: `"2x"` is 192).
|
|
225
297
|
|
|
226
298
|
| Print parameter | Meaning |
|
|
227
299
|
|---|---|
|
|
@@ -236,45 +308,79 @@ mode: only its luminosity matters, and viewers disagree on the luminosity of ink
|
|
|
236
308
|
|
|
237
309
|
| Method | Description |
|
|
238
310
|
|---|---|
|
|
239
|
-
| `add_page(width=None, height=None, size="A4", landscape=False)` | New `Page`: `width` and `height` in the document's unit, or a
|
|
311
|
+
| `add_page(width=None, height=None, size="A4", landscape=False)` | New `Page`: `width` and `height` (numbers in the document's unit, lengths, or a paper size's side; one alone: `ValueError`), or `size`: a paper size (`"A4"`, `"us"`, `"a4-landscape"`), two lengths (`"8.5in x 11in"`, numbers in the document's unit) or a pair. |
|
|
240
312
|
| `add_bookmark(title, page, y=None, parent=None)` | Outline entry for `page` (a `Page` or index), optionally at `y`. Returns a `Bookmark`, usable as `parent`. |
|
|
241
313
|
| `add_font(data_or_path, family=None, weight=None, italic=None)` | Register a font file (path or bytes) under `family` (default: its own name). |
|
|
314
|
+
| `add_image(img, smooth=None, rasterized=False, quality=None)`, `add_pattern(obj, scene=None)` | Resources of samples and patterns, for code that writes scenes itself. |
|
|
242
315
|
| `attach(name, data, mime=None, description=None, relationship="Unspecified")` | Embed a file (bytes or a path). `relationship` is the PDF/A-3 `AFRelationship`: `Source`, `Data`, `Alternative`, `Supplement` or `Unspecified`. Not allowed in PDF/A-2. |
|
|
243
|
-
| `
|
|
244
|
-
| `save(file, **options)` |
|
|
245
|
-
| `to_eps(page=0, *, compress=True, simplify=None, compression="balanced", images=None, font_hinting=False, text_as_paths=False, flatten_fallback="raster", flatten_dpi=600, flatten_budget=256, flatten_cell=0.25)` | One page (a `Page` or its index) as EPS `bytes` ([EPS output](#eps-output)). |
|
|
246
|
-
| `save_eps(file, page=0, **options)` | Write one page as EPS to a path or binary file object; `options` as `to_eps`. |
|
|
316
|
+
| `write(kind, *, pages=None, **options)` | The document as `bytes` of `kind` (`"pdf"`, `"eps"`, `"svg"`, `"png"`, `"jpeg"`/`"jpg"`, `"jxl"`, `"avif"`) with the output's options ([18.1](#181-options)). `pages`: a `Page`, an index or a list of them; default every page for PDF, the first for the others, which hold one page. |
|
|
317
|
+
| `save(file, *, format=None, pages=None, **options)` | `write` to a path or a binary file object; `format` defaults to the path's extension (none: PDF). |
|
|
247
318
|
| `pages` | The pages, in order. |
|
|
319
|
+
| `bookmarks` | The top-level `Bookmark`s (`title`, `page`, `y`, `parent`, `children`), also of a PDF read. |
|
|
320
|
+
| `font_db` | The `FontDB` text is shaped with (read-only). |
|
|
321
|
+
| `points_per_unit` | Points per document unit: `1` for `pt`, `0.75` for `px` (read-only). |
|
|
248
322
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
| `images` | An `ImagePolicy`: how images are stored ([Image encoding](#image-encoding)). |
|
|
255
|
-
| `font_hinting` | Keep the TrueType hinting in embedded subsets (default: left out, [Fonts](#16-fonts)). |
|
|
256
|
-
| `flatten_transparency`, `flatten_fallback`, `flatten_dpi`, `flatten_budget`, `flatten_cell` | Translucent content drawn as opaque vectors, and what cannot be ([Transparency flattening](#transparency-flattening)). |
|
|
257
|
-
|
|
258
|
-
```python
|
|
259
|
-
ImagePolicy(quality=None, jxl=False)
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
`quality` (1–100): rasterized content (rasterized groups, filtered elements) is stored lossy
|
|
263
|
-
at this quality, as JPEG, or as JPEG XL with `jxl`; `None`: lossless. A group's own
|
|
264
|
-
`quality` overrides it. `jxl`: write images as JPEG XL ([JPEG XL](#jpeg-xl)). Other images
|
|
265
|
-
keep their encoding.
|
|
323
|
+
The constructor's `unit`, `title`, `author`, `subject`, `keywords`, `creator`, `base_dir`,
|
|
324
|
+
`filters`, `network`, `color_mode`, `pdf_a`, `creation_date`, `text_as_paths` and `default_dpi` are
|
|
325
|
+
attributes of the same names. A document without pages gets an empty A4 page when written. A PDF of some of the pages
|
|
326
|
+
keeps the bookmarks and links of those pages (a bookmark of another page is left out, its
|
|
327
|
+
children kept).
|
|
266
328
|
|
|
267
329
|
```python
|
|
268
330
|
doc = vec_io.Document(unit="mm")
|
|
269
331
|
page = doc.add_page(size="A4") # 210 x 297, in mm
|
|
270
|
-
doc.save("a.pdf", compression="
|
|
271
|
-
|
|
272
|
-
|
|
332
|
+
doc.save("a.pdf", compression="small", simplify=True, images={"quality": 85})
|
|
333
|
+
page.save("a.png", dpi=192) # the same record, as an image
|
|
334
|
+
svg = doc.write("svg", view=vec_io.View(trim=True)) # bytes
|
|
273
335
|
```
|
|
274
336
|
|
|
275
|
-
`Page` is the `Canvas` of a page ([5](#5-canvas)) with `render`
|
|
276
|
-
`
|
|
277
|
-
`
|
|
337
|
+
`Page` is the `Canvas` of a page ([5](#5-canvas)) with `render`
|
|
338
|
+
([5.9](#59-rendering-and-image-output)), `write` and `save` (`Document.write`/`save` of that
|
|
339
|
+
page), `view`, `trim`, `resize`, `margin`, `box`, `view_scale`, `document`, `index` and
|
|
340
|
+
`page_width`, `page_height` (its size in points).
|
|
341
|
+
Named sizes (portrait): `A0`–`A6`, `B4`, `B5`, `Letter`, `Legal`, `Tabloid`, `Ledger`,
|
|
342
|
+
`Executive`. `landscape=True` swaps width and height.
|
|
343
|
+
|
|
344
|
+
`page.trim(margin=0) -> (width, height)` shows only what the page draws plus `margin` (a
|
|
345
|
+
number or numeric string in the document's unit, or a length such as `"2mm"`; not `%` or
|
|
346
|
+
`em`) on each side, at scale 1, and returns that size in the document's unit. Blank is transparent or white (RGB components of 250 and up).
|
|
347
|
+
The content is found on renders at 300 dpi, rounded outward inside the page: at most 1/300 in
|
|
348
|
+
is left beyond it, and nothing drawn on the page is cut. `page.box` is the part outputs show, `(x0, y0, x1, y1)` in
|
|
349
|
+
points from the bottom-left corner: every output (PDF, EPS, SVG, `render`) puts its top-left
|
|
350
|
+
corner at its origin, links and link targets included. The page keeps its coordinates:
|
|
351
|
+
drawing may go on after `trim`, and `width`/`height` stay the page's. A margin, or the room
|
|
352
|
+
a fit leaves, may show more than the page: content outside the page is clipped to it in
|
|
353
|
+
every output, so that room is blank. A page that draws nothing is unchanged;
|
|
354
|
+
`RuntimeError` inside `state()`.
|
|
355
|
+
|
|
356
|
+
### Resizing
|
|
357
|
+
|
|
358
|
+
`page.resize(width=None, height=None, scale=None, *, size=None, aspect=None,
|
|
359
|
+
align=None, margin=0) -> (width, height)` shows the page, or what `trim` kept (without its
|
|
360
|
+
margin; each call starts from it), at another size, returned in the document's unit.
|
|
361
|
+
`width`/`height`: a number or numeric string in the document's unit, a length (`"85mm"`), or a paper size's side (`"a4"`,
|
|
362
|
+
`"letter"` or `"us"`, `"legal"`, `"tabloid"`, `"a0"`–`"a6"`, `"b4"`, `"b5"`, …;
|
|
363
|
+
`"a4-landscape"` swaps the sides); `size`: both sides (a paper size, `"8.5in x 11in"` with
|
|
364
|
+
`x`, `×` or `*`, or a pair); `scale`: a factor. One side keeps the aspect ratio. Both sides:
|
|
365
|
+
`aspect="fit"` (default) makes the page that size and fits the content inside its margins,
|
|
366
|
+
placed by `align` (`"start"`, `"center"`, `"end"`, or a pair: horizontal, vertical; start is
|
|
367
|
+
left and top); `aspect="stretch"` scales each axis to the size (text and circles stretched
|
|
368
|
+
when the ratio changes). `aspect` and `align` apply to both sides only. `margin`: blank
|
|
369
|
+
space inside the size, on each side. `page.margin(m)` adds blank space around what the page
|
|
370
|
+
shows. The whole page is zoomed
|
|
371
|
+
(lines, text, markers), as when a figure is scaled in a layout program; the page keeps its
|
|
372
|
+
coordinates and `view_scale` (read-only) gives `(sx, sy)`. What depends on resolution follows the
|
|
373
|
+
scale (the larger factor), so it is the same in the output as without resizing:
|
|
374
|
+
rasterized groups and filters, the output's `simplify` resolution, the flattening fallback,
|
|
375
|
+
and the placements `ImagePolicy(dpi=…)` measures. A trimmed or resized page's gradients and
|
|
376
|
+
patterns follow its view (a PDF page shows its content as a form whose matrix is the view).
|
|
377
|
+
`ValueError` for no size, `scale` or `size` with another size, a size that is not positive
|
|
378
|
+
or unknown, an unknown `aspect` or `align`, `aspect` or `align` without both sides, a
|
|
379
|
+
margin that leaves no room.
|
|
380
|
+
|
|
381
|
+
`page.view(view) -> (width, height)` applies a `View` (or a dict of its fields; numbers in
|
|
382
|
+
CSS pixels): `trim`, then the size or `margin`, as `write(view=…)` does for one output, but
|
|
383
|
+
kept on the page.
|
|
278
384
|
|
|
279
385
|
### PDF/A
|
|
280
386
|
|
|
@@ -307,10 +413,9 @@ paints nothing.
|
|
|
307
413
|
|
|
308
414
|
### 5.1 State
|
|
309
415
|
|
|
310
|
-
`
|
|
311
|
-
restores them
|
|
312
|
-
pattern
|
|
313
|
-
`RuntimeError`. `reset_state()` restores the defaults (not the transform).
|
|
416
|
+
`with page.state():` saves the drawing attributes, the transform and the clip before the
|
|
417
|
+
body and restores them after it. A page written while a `state()` is open, or a group, mask
|
|
418
|
+
or pattern closed inside one opened in it, raises `RuntimeError`.
|
|
314
419
|
|
|
315
420
|
| Attribute | Default | Values |
|
|
316
421
|
|---|---|---|
|
|
@@ -322,8 +427,8 @@ pattern every `push()` needs its `pop()` in the same body; an unbalanced one rai
|
|
|
322
427
|
| `miter_limit` | `4.0` | |
|
|
323
428
|
| `line_dash` | `None` | sequence of lengths |
|
|
324
429
|
| `line_dash_offset` | `0.0` | |
|
|
325
|
-
| `
|
|
326
|
-
| `font_family` | `"
|
|
430
|
+
| `opacity` | `1.0` | multiplies every paint (0–1) |
|
|
431
|
+
| `font_family` | `"system-ui"` | CSS family list (`system-ui`: the platform's interface font, [Fonts](#16-fonts)) |
|
|
327
432
|
| `font_size` | `12.0` | the document's unit |
|
|
328
433
|
| `font_weight` | `"normal"` | `normal`, `bold`, `1`–`1000` |
|
|
329
434
|
| `font_style` | `"normal"` | `normal`, `italic`, `oblique`, `oblique 10deg` |
|
|
@@ -332,7 +437,10 @@ pattern every `push()` needs its `pop()` in the same body; an unbalanced one rai
|
|
|
332
437
|
| `font_optical_sizing` | `"auto"` | `auto` (the `opsz` axis follows the font size) or `none` |
|
|
333
438
|
| `font_kerning` | `"auto"` | `auto`/`normal`: pair kerning; `none` |
|
|
334
439
|
| `font_embed` | `True` | `False`: a standard 14 font, not embedded, when the family names one ([Fonts](#16-fonts)) |
|
|
335
|
-
| `
|
|
440
|
+
| `font_variant` | `"normal"` | CSS `font-variant` keywords: `small-caps`, `oldstyle-nums`, `tabular-nums`, `common-ligatures`, … ([shaping](#shaping)) |
|
|
441
|
+
| `font_feature_settings` | `""` | `'"tnum" 1, "ss01"'` or `{"tnum": 1}` |
|
|
442
|
+
| `direction` | `"ltr"` | `ltr`, `rtl`, `auto` (from the first strong character): the paragraph direction of the bidi algorithm |
|
|
443
|
+
| `text_align` | `"start"` | `start`/`left`, `center`/`middle`, `end`/`right`; `start` and `end` follow `direction` |
|
|
336
444
|
| `letter_spacing` | `0.0` | |
|
|
337
445
|
| `word_spacing` | `0.0` | |
|
|
338
446
|
| `fill_rule` | `"nonzero"` | `nonzero`, `evenodd` |
|
|
@@ -369,7 +477,8 @@ The current path persists until `begin_path()`.
|
|
|
369
477
|
| `fill(paint=<fill_style>, rule=None)` | Fill the path. |
|
|
370
478
|
| `stroke(paint=<stroke_style>)` | Stroke the path (black when `stroke_style` is `None`). |
|
|
371
479
|
| `fill_stroke(fill=<state>, stroke=<state>)` | Fill then stroke. |
|
|
372
|
-
| `clip(path=None, rule=None)` | Intersect the clip with `path` (a `Path` or path data; default the current path), until the enclosing `
|
|
480
|
+
| `clip(path=None, rule=None)` | Intersect the clip with `path` (a `Path` or path data; default the current path), until the enclosing `state()` ends; `with page.clip(path):` clips the body only. |
|
|
481
|
+
| `clip_rect(x, y, width, height)` | Intersect the clip with a rectangle. |
|
|
373
482
|
| `fill_rect(x, y, width, height, fill=<state>)`, `stroke_rect(x, y, width, height, stroke=<state>)` | Independent of the current path. |
|
|
374
483
|
| `draw_path(path, fill=<state>, stroke=<state>, fill_rule=None, markers=None)` | Paint a `Path` or path data with the state's line settings, then its `markers`. |
|
|
375
484
|
| `draw_path_markers(path, markers, stroke_width=None)` | `PathMarker`s at the vertices of a path: one for every vertex, or `(start, mid, end)` (each may be `None`). |
|
|
@@ -413,7 +522,9 @@ page.draw_path("M10 10 L80 20", fill=None, stroke="black", markers=(None, None,
|
|
|
413
522
|
`text` is a string, rich content (a list of strings and `Span` objects,
|
|
414
523
|
[Text layout](#6-text-layout)) or a `GlyphRun`, drawn on one line (newlines become spaces).
|
|
415
524
|
Spans without a color use the fill. One line is shaped as a paragraph is: fonts chosen per
|
|
416
|
-
character, pairs kerned (`font_kerning`),
|
|
525
|
+
character, pairs kerned (`font_kerning`), OpenType features and complex scripts
|
|
526
|
+
([shaping](#shaping)), right-to-left runs reordered (`direction`), words shaped one by one,
|
|
527
|
+
runs of spaces as one space, soft hyphens and U+200B not drawn, so `measure_text(s)` is
|
|
417
528
|
the width of `s` laid out on one line. Fonts are embedded as needed ([Fonts](#16-fonts)).
|
|
418
529
|
|
|
419
530
|
Text on a path is shaped the same way and starts at `offset` along the path (a length, or
|
|
@@ -428,8 +539,8 @@ path; underlines, strikethroughs and links of spans are not drawn.
|
|
|
428
539
|
|
|
429
540
|
| Method | |
|
|
430
541
|
|---|---|
|
|
431
|
-
| `draw_image(source, x, y, width=None, height=None, preserve_aspect_ratio="xMidYMid meet", opacity=1.0, smooth=None)` |
|
|
432
|
-
| `draw_svg(svg, x=0, y=0, width=None, height=None, base_dir=None, clip=True)` | Place SVG text, bytes, a path or an `SVGDocument`. Default size: its CSS pixel size. `clip` clips to its viewport. |
|
|
542
|
+
| `draw_image(source, x, y, width=None, height=None, preserve_aspect_ratio="xMidYMid meet", opacity=1.0, smooth=None)` | An image of the formats of SVG's `<image>` ([SVG support](#15-svg-support)) from a path, bytes, a `data:` URI or (with `network`) an http(s) URL. Without a size, one pixel per unit; with one dimension the aspect ratio is kept. `smooth=False` keeps pixels sharp when scaled. Returns `False` if the image cannot be loaded. |
|
|
543
|
+
| `draw_svg(svg, x=0, y=0, width=None, height=None, base_dir=None, clip=True, media="print", color_scheme="light")` | Place SVG text, bytes, a path or an `SVGDocument`. Default size: its CSS pixel size. `clip` clips to its viewport. `media`, `color_scheme`: as for `convert`. |
|
|
433
544
|
| `draw_pdf(source, page=0, x=0, y=0, width=None, height=None, box="crop", annotations=True, password=None)` | Place a page of a PDF (a path, bytes or a binary file) as a form, clipped to its `box` (`crop`, `media`, `bleed`, `trim`, `art`). Default size: the box's, in points (rotated); one dimension keeps the aspect ratio. A page placed again in the document is the same form ([Reading PDF](#reading-pdf)). |
|
|
434
545
|
|
|
435
546
|
A `vec_io.draw` drawing draws itself: `drawing.draw(page, x, y, width=None, height=None)`
|
|
@@ -450,19 +561,19 @@ Context managers; everything drawn in the body is affected.
|
|
|
450
561
|
|
|
451
562
|
| Method | |
|
|
452
563
|
|---|---|
|
|
453
|
-
| `group(opacity=1.0, rasterize=False, dpi=None, quality=None, simplify=None, filter=None)` | Transparency group. `filter`: a `Filter` run on the body's pixels at `dpi` ([Filters](#14-filters)). `rasterize=True` makes the PDF hold the body as an image at `dpi` (default 300; [Rasterization](#12-rasterization)). `quality`: 1–100 for JPEG (JPEG XL with `ImagePolicy(jxl=True)`), `False` for lossless, `None` for the output's `ImagePolicy`. `simplify`: see [Simplification](#13-simplification); with it and no opacity or `rasterize`, the body is drawn directly, not as a group. Drawing attributes are restored afterwards; if the body raises, nothing is drawn. |
|
|
564
|
+
| `group(opacity=1.0, rasterize=False, dpi=None, quality=None, simplify=None, filter=None, blend="normal", isolate=False)` | Transparency group. `blend`: a CSS `mix-blend-mode` name (`normal`, `multiply`, `screen`, `overlay`, `darken`, `lighten`, `color-dodge`, `color-burn`, `hard-light`, `soft-light`, `difference`, `exclusion`, `hue`, `saturation`, `color`, `luminosity`; `vec_io.paint.BLEND_MODES`) blending the group with what is under it (PDF `/BM`, SVG `mix-blend-mode`, EPS an image); `isolate=True`: an isolated group (blend modes inside it blend with its content only); a group whose content sets a blend mode is isolated. `filter`: a `Filter` run on the body's pixels at `dpi` ([Filters](#14-filters)). `rasterize=True` makes the PDF hold the body as an image at `dpi` (default 300; [Rasterization](#12-rasterization)). `quality`: 1–100 for JPEG (JPEG XL with `ImagePolicy(jxl=True)`), `False` for lossless, `None` for the output's `ImagePolicy`. `simplify`: see [Simplification](#13-simplification); with it and no opacity or `rasterize`, the body is drawn directly, not as a group. Drawing attributes are restored afterwards; if the body raises, nothing is drawn. |
|
|
454
565
|
| `rasterized(dpi=None, opacity=1.0, post_process=None, region=None, quality=None, simplify=None)` | Lower-level rasterization. `post_process(surface)` edits the pixels (premultiplied float32 RGBA in `surface.pixels`); the body is then rasterized while it is drawn, and both outputs show that image. `region` `(x0, y0, x1, y1)` fixes the rasterized area. |
|
|
455
566
|
| `clip(path, rule=None)` | The body clipped to `path` ([5.3](#53-paths-and-painting)). |
|
|
456
|
-
| `
|
|
567
|
+
| `mask(m)` | The body seen through `Mask` `m` ([7](#7-paints-and-recorded-content)): white shows it, black hides it. Drawing attributes are restored afterwards. |
|
|
457
568
|
|
|
458
|
-
`mask()
|
|
569
|
+
`mask()` (no argument), `pattern()` and `marker()` record content to be used elsewhere
|
|
459
570
|
([7](#7-paints-and-recorded-content)).
|
|
460
571
|
|
|
461
572
|
```python
|
|
462
573
|
with page.mask() as fade: # recorded, not drawn
|
|
463
574
|
page.fill_rect(0, 0, 100, 50, fill=vec_io.LinearGradient(0, 0, 100, 0,
|
|
464
575
|
[(0, "white"), (1, "black")]))
|
|
465
|
-
with page.
|
|
576
|
+
with page.mask(fade):
|
|
466
577
|
page.fill_rect(0, 0, 100, 50, fill="red")
|
|
467
578
|
```
|
|
468
579
|
|
|
@@ -475,11 +586,12 @@ page added later), optionally at `page_y`.
|
|
|
475
586
|
### 5.9 Rendering and image output
|
|
476
587
|
|
|
477
588
|
```python
|
|
478
|
-
page.render(dpi=
|
|
589
|
+
page.render(dpi=None, simplify=None, background=None) -> Image
|
|
479
590
|
```
|
|
480
591
|
|
|
481
592
|
Renders the page from what it records: images from their samples (nothing is encoded to be
|
|
482
|
-
decoded again), rasterized groups as vectors, at `dpi` (
|
|
593
|
+
decoded again), rasterized groups as vectors, at `dpi` (default the document's
|
|
594
|
+
`default_dpi`, `"2x"`: two pixels per CSS pixel).
|
|
483
595
|
`background` is a color put under the page, or `None` (transparent). `simplify` decimates
|
|
484
596
|
lines for this resolution; nothing is left out, since rasterizing hidden content costs less
|
|
485
597
|
than finding it ([Simplification](#13-simplification)). `dpi` must be positive.
|
|
@@ -510,7 +622,7 @@ data = image.encode("jpeg", jpeg=vec_io.JPEG(quality=85))
|
|
|
510
622
|
|
|
511
623
|
PNG: lossless by default, in the smallest layout that keeps every pixel (gray, palette of
|
|
512
624
|
1–8 bits, color key or alpha dropped when they apply), with the row filters that compress
|
|
513
|
-
best; `compression="fast"` keeps the samples' layout, `"
|
|
625
|
+
best; `compression="fast"` keeps the samples' layout, `"small"` adds a wider filter search
|
|
514
626
|
and vec_io's Deflate. `quality` (1–100) writes a palette of at most 256 colors chosen in
|
|
515
627
|
Oklab: colors covering at least 0.1% of the pixels stay exact, smooth areas are dithered,
|
|
516
628
|
flat areas and edges are not, and an image that needs more colors for the quality, or that
|
|
@@ -519,7 +631,7 @@ is smaller lossless, is written lossless. On plots, `quality=90` halves the file
|
|
|
519
631
|
|
|
520
632
|
JPEG: Robidoux's quantization tables, the quality scale calibrated so that each value looks
|
|
521
633
|
at least as good (SSIM) as the IJG scale of the specification's tables; `"balanced"` adds
|
|
522
|
-
trellis quantization, deringing of dark edges on white and sharp 4:2:0 color, `"
|
|
634
|
+
trellis quantization, deringing of dark edges on white and sharp 4:2:0 color, `"small"` tries
|
|
523
635
|
four progressive scan orders, `"fast"` quantizes plainly. Progressive files are about 5%
|
|
524
636
|
smaller than baseline ones. On plots and photographs, balanced JPEGs are 9–14% smaller than
|
|
525
637
|
with the specification's tables at the same quality, and 20–36% smaller at the same SSIM.
|
|
@@ -554,13 +666,14 @@ after opening brackets. A word wider than the line is split between glyphs.
|
|
|
554
666
|
| `first_indent` | Indent of the first line of each paragraph. |
|
|
555
667
|
|
|
556
668
|
The text style comes from the canvas state: `font`, `fill_style` (or `text_box`'s `fill`),
|
|
557
|
-
`letter_spacing`, `word_spacing`, `
|
|
669
|
+
`letter_spacing`, `word_spacing`, `opacity`; `font_kerning="none"` turns kerning off.
|
|
558
670
|
[`vec_io.text.layout`](#61-shaping-without-a-page-vec_iotext) does the same without a page.
|
|
559
671
|
|
|
560
672
|
```python
|
|
561
673
|
Span(text, font_family=None, font_size=None, font_weight=None, font_style=None,
|
|
562
674
|
color=None, url=None, letter_spacing=None, word_spacing=None, underline=False,
|
|
563
|
-
baseline_shift=None, font_scale=None, strikethrough=False
|
|
675
|
+
baseline_shift=None, font_scale=None, strikethrough=False, font_variant=None,
|
|
676
|
+
font_features=None)
|
|
564
677
|
```
|
|
565
678
|
|
|
566
679
|
A run of text with its own style; `None` inherits the canvas state. `url` makes the run a
|
|
@@ -568,7 +681,8 @@ link; `underline` draws a line under it; `strikethrough` draws one through it at
|
|
|
568
681
|
strikeout position and thickness (OS/2 `yStrikeoutPosition`, `yStrikeoutSize`; without them
|
|
569
682
|
0.28 em up, as thick as the underline), as SVG's `line-through` is drawn. `font_scale`
|
|
570
683
|
multiplies the size. `baseline_shift` raises the run: `"super"` (0.33 em of the canvas font
|
|
571
|
-
size), `"sub"` (−0.2 em) or a number of em (positive up).
|
|
684
|
+
size), `"sub"` (−0.2 em) or a number of em (positive up). `font_variant` and
|
|
685
|
+
`font_features` add to the font's. Exponents: `["10", Span("5", baseline_shift="super", font_scale=0.7)]`.
|
|
572
686
|
|
|
573
687
|
| `TextLayout` member | |
|
|
574
688
|
|---|---|
|
|
@@ -579,8 +693,10 @@ size), `"sub"` (−0.2 em) or a number of em (positive up). Exponents: `["10", S
|
|
|
579
693
|
| `line_text(k)` | Text of line `k`. |
|
|
580
694
|
|
|
581
695
|
Kerning and justification are written as `TJ` adjustments, so the text stays selectable and
|
|
582
|
-
searchable.
|
|
583
|
-
|
|
696
|
+
searchable. Paragraphs get their bidi levels from the canvas `direction` (each paragraph
|
|
697
|
+
from its first strong character with `auto`); lines are reordered once broken, and
|
|
698
|
+
`start`/`end` alignment follow the paragraph's direction. Speed: 1,800 words in about
|
|
699
|
+
0.02 s (greedy) or 0.035 s (optimal), fonts already loaded. Not supported: hyphenation
|
|
584
700
|
dictionaries.
|
|
585
701
|
|
|
586
702
|
### 6.1 Shaping without a page: `vec_io.text`
|
|
@@ -602,11 +718,12 @@ para.draw(page, x, y, fill="black")
|
|
|
602
718
|
|
|
603
719
|
| Name | |
|
|
604
720
|
|---|---|
|
|
605
|
-
| `Font(family="
|
|
606
|
-
| `shape(content, font, db=None, *, kerning=True, ligatures=False, letter_spacing=0, word_spacing=0)` | `GlyphRun` of a string or rich content on one line. |
|
|
721
|
+
| `Font(family="system-ui", size=12, weight=400, style="normal", stretch="normal", variations=None, optical_sizing="auto", embed=True, unit=1, variant=None, features=None, synthesis="weight style")` | A font description: CSS values as for the canvas attributes; `embed=False` uses a standard 14 font when the family names one; `unit`: CSS px per unit of `size` (a number or a unit name, for `opsz`); `variant`: `font-variant` keywords; `features`: `font-feature-settings`; `synthesis`: `font-synthesis` (`"none"`: no synthetic bold or italic). Immutable and hashable; `replace(**changes)`. |
|
|
722
|
+
| `shape(content, font, db=None, *, kerning=True, ligatures=False, letter_spacing=0, word_spacing=0, direction="ltr")` | `GlyphRun` of a string or rich content on one line, glyphs in visual order (`direction`: `ltr`, `rtl`, `auto`). |
|
|
607
723
|
| `measure(content, font, db=None, **options)` | `Extent(width, ascent, descent)` of that run. |
|
|
608
|
-
| `layout(content, font, width, height=None, db=None, *, align, line_height, overflow, breaking, kerning, ligatures, paragraph_spacing, first_indent, letter_spacing, word_spacing)` | `Paragraphs`: the [layout](#6-text-layout) options; `draw(canvas, x, y, fill=None)`, `width`, `height`, `lines`, `baselines`, `overflow`, `remainder`, `line_text(k)`, `line_cells()` (placed `Line`s). |
|
|
609
|
-
| `GlyphRun` | `text`, `width`, `ascent`, `descent`, `extent`; `segments` (`Segment`: one face and style, with `gids`, `texts`, `chars`, `advances`, `adjusts`); `glyphs` (`Glyph`: `face`, `gid`, `advance`, `adjust`, `text`, `char`, `style`, `synth`). |
|
|
724
|
+
| `layout(content, font, width, height=None, db=None, *, align, line_height, overflow, breaking, kerning, ligatures, paragraph_spacing, first_indent, letter_spacing, word_spacing, direction="ltr")` | `Paragraphs`: the [layout](#6-text-layout) options; `draw(canvas, x, y, fill=None)`, `width`, `height`, `lines`, `baselines`, `overflow`, `remainder`, `line_text(k)`, `line_cells()` (placed `Line`s). |
|
|
725
|
+
| `GlyphRun` | `text`, `width`, `ascent`, `descent`, `extent`; `segments` (`Segment`: one face and style, with `gids`, `texts`, `chars`, `advances`, `adjusts`, `offsets`); `glyphs` (`Glyph`: `face`, `gid`, `advance`, `adjust`, `text`, `char`, `style`, `synth`, `dx`/`dy` (drawn off its pen position: marks, GPOS placements), `level` (bidi)). |
|
|
726
|
+
| `baseline_position(face, size, name)` | Height of a CSS baseline (`middle`, `central`, `hanging`, `mathematical`, `ideographic`, `text-before-edge`, `text-after-edge`, `text-top`, `text-bottom`) above the alphabetic one: the `BASE` table, else as browsers derive it (half the x-height, the middle of ascent and descent, 0.8 and 0.5 of the ascent, the descent, the ascent). |
|
|
610
727
|
| `default_db()` | The process-wide `FontDB` (installed fonts, `VEC_IO_FONT_DIRS`, and font downloads as `VEC_IO_FONT_DOWNLOADS` says). |
|
|
611
728
|
| `NoFontError` | `ValueError`: no outline font at all for the text. |
|
|
612
729
|
|
|
@@ -637,7 +754,7 @@ drawn on the page while it is recorded, and its body starts from the default dra
|
|
|
637
754
|
| With | Records | Used as |
|
|
638
755
|
|---|---|---|
|
|
639
756
|
| `with page.pattern(width, height, x=0, y=0, transform=None) as pattern:` | a `Pattern`: a `width` × `height` tile, its origin at the top-left corner; `x`, `y` offset the tiling, `transform` transforms it | a paint: `fill_style = pattern`, `fill=pattern` |
|
|
640
|
-
| `with page.mask() as mask:` | a `Mask`: what the body draws is the luminance (white keeps, black hides) | `with page.
|
|
757
|
+
| `with page.mask() as mask:` | a `Mask`: what the body draws is the luminance (white keeps, black hides) | `with page.mask(mask):` |
|
|
641
758
|
| `with page.marker() as marker:` | a `Marker`: one marker centered on the origin | `draw_markers(xs, ys, marker)`; `PathMarker(marker, …)` ([5.3](#53-paths-and-painting)) |
|
|
642
759
|
|
|
643
760
|
## 8. Markers
|
|
@@ -796,9 +913,8 @@ it in its own C library).
|
|
|
796
913
|
## 11. Drawings: `vec_io.draw`
|
|
797
914
|
|
|
798
915
|
A drawing is a tree of elements (drawsvg-style names) that draws itself onto a canvas: a
|
|
799
|
-
page of its own document (`Drawing.document`), any page or canvas (`Drawing.draw`), or
|
|
800
|
-
|
|
801
|
-
[18](#18-output)).
|
|
916
|
+
page of its own document (`Drawing.document`), any page or canvas (`Drawing.draw`), or a
|
|
917
|
+
file of any output kind (`Drawing.write`, `Drawing.save`, [18](#18-output)).
|
|
802
918
|
|
|
803
919
|
```python
|
|
804
920
|
import vec_io.draw as draw
|
|
@@ -826,7 +942,8 @@ Element keywords (not inherited): `transform` (a `Matrix` or SVG transform text)
|
|
|
826
942
|
(the element as one transparency group, folded into the paint when it has one), `clip_path`
|
|
827
943
|
(a shape element, `ClipPath`, `Path` or path data), `mask` (an element or `Mask` drawing the
|
|
828
944
|
luminance), `filter` (a `Filter`, run at `rasterize`'s dpi or 300), `rasterize` (`True`
|
|
829
|
-
or a dpi), `quality` (of a rasterized element), `simplify
|
|
945
|
+
or a dpi), `quality` (of a rasterized element), `simplify`, `mix_blend_mode` (a CSS blend
|
|
946
|
+
mode: the element blended as one group), `isolation` (`"isolate"`). `Path`, `Line`, `Polyline` and
|
|
830
947
|
`Polygon` also take `marker_start`, `marker_mid`, `marker_end` and `markers` (all three):
|
|
831
948
|
`Marker` elements. Other keywords raise `TypeError`. `set(**keywords)` changes them (`None` inherits again,
|
|
832
949
|
except for `fill` and `stroke`, where it paints nothing).
|
|
@@ -845,10 +962,9 @@ centered).
|
|
|
845
962
|
| `append(*elements)`, `extend(elements)`, `group(**keywords)` | Children; `group` is a context manager appending and yielding a `Group` (also on `Group`). |
|
|
846
963
|
| `draw(canvas, x=0, y=0, width=None, height=None, clip=True)` | Draw onto a canvas at `(x, y)`, scaled to `width` × `height` (default its own size, in the canvas's unit), clipped to its box. |
|
|
847
964
|
| `document(**options)` | A new `Document` in the drawing's unit with one page holding the drawing; `options`: of the `Document`. |
|
|
848
|
-
| `render(dpi=
|
|
849
|
-
| `
|
|
850
|
-
| `
|
|
851
|
-
| `save(file, format=None, **options)` | PDF, SVG, EPS, PNG, JPEG, JPEG XL or AVIF by `format` or the extension; `options`: of the `Document`, and of the output (`compress`, `compression`, `simplify`, `images`, `font_hinting`, `flatten_*` for PDF; `flatten_*` for SVG; those of `to_eps` for EPS; `dpi`, `simplify`, `background`, `png`, `jpeg`, `jxl`, `avif` for images). |
|
|
965
|
+
| `render(dpi=None, simplify=None, background=None, **options)` | The drawing as an `Image` (default `default_dpi`, a `Document` option) ([5.9](#59-rendering-and-image-output)). |
|
|
966
|
+
| `write(kind, **options)` | The drawing as `bytes` of `kind`: `Document.write` of its document; `options`: of the `Document` (`fonts`, `title`, …) and of the output ([18.1](#181-options)). |
|
|
967
|
+
| `save(file, *, format=None, **options)` | `write` to a path (the format from its extension) or a binary file object. |
|
|
852
968
|
|
|
853
969
|
### 11.3 Elements
|
|
854
970
|
|
|
@@ -863,7 +979,7 @@ centered).
|
|
|
863
979
|
| `Text` | `Text(text, font_size, x=0, y=0, line_height=1.2, path=None, offset=0, side="left", method="align", …)`: a string (`\n` stacks lines `line_height` em apart) or rich content (strings, `TSpan`, `Span`) on one line; with `path` (a shape element, `Path` or path data), along it ([5.4](#54-text)) |
|
|
864
980
|
| `TSpan` | `TSpan(text, font_family=…, font_size=…, font_weight=…, font_style=…, fill=…, underline=…, strikethrough=…, baseline_shift=…, url=…)`: a styled run (a `Span`) |
|
|
865
981
|
| `TextBox` | `TextBox(content, x, y, width, height=None, …)`: wrapped text, box top-left at `(x, y)`; the [layout](#6-text-layout) options as keywords |
|
|
866
|
-
| `Image` | `Image(x, y, width, height, path=None, data=None, preserve_aspect_ratio="xMidYMid meet", smooth=None, …)`:
|
|
982
|
+
| `Image` | `Image(x, y, width, height, path=None, data=None, preserve_aspect_ratio="xMidYMid meet", smooth=None, …)`: an image of the formats of `draw_image` |
|
|
867
983
|
| `SVG` | `SVG(source, x=0, y=0, width=None, height=None, base_dir=None, …)`: an SVG document drawn in the box, with everything SVG has, CSS style sheets included (filters when enabled) |
|
|
868
984
|
| `Use` | `Use(element, x=0, y=0, …)`: the element drawn again, moved; its keywords apply where the element sets none |
|
|
869
985
|
| `Markers`, `Lines`, `Segments`, `Area`, `Rects`, `Polygons` | the bulk calls ([8](#8-markers), [9](#9-lines-segments-and-areas)); `fill`, `stroke`, `stroke_width` and `opacity` may be columns |
|
|
@@ -955,7 +1071,7 @@ an SMask. The first frame of an animation is used. Lossy images are decoded
|
|
|
955
1071
|
to sRGB; lossless ones keep their color space, written as `ICCBased` when it
|
|
956
1072
|
is not sRGB.
|
|
957
1073
|
|
|
958
|
-
**Writing.** With `ImagePolicy(jxl=True)` (`save
|
|
1074
|
+
**Writing.** With `ImagePolicy(jxl=True)` (`write`/`save` of a PDF, `convert`, `--jxl`) every image is written as JPEG XL, as PDFium's JPEG XL support reads it: the
|
|
959
1075
|
JPEG XL file as the stream, `/Filter /JXLDecode`, `/ColorSpace /DeviceGray`
|
|
960
1076
|
or `/DeviceRGB` (`ICCBased` for other color spaces), `/BitsPerComponent 8`,
|
|
961
1077
|
alpha inside the JPEG XL rather than in an SMask:
|
|
@@ -969,7 +1085,7 @@ ISO 32000 has no JPEG XL filter yet; `/JXLDecode` is the name PDFium's
|
|
|
969
1085
|
implementation uses, and viewers without it show nothing for these images.
|
|
970
1086
|
`jxl` cannot be combined with `pdf_a` or `color_mode="cmyk"`, and raises
|
|
971
1087
|
`ValueError` when the PDF is written without libjxl. The encoder effort follows `compression`: 5
|
|
972
|
-
(`fast`), 7 (`balanced`) or 9 (`
|
|
1088
|
+
(`fast`), 7 (`balanced`) or 9 (`small`).
|
|
973
1089
|
|
|
974
1090
|
JPEG XL pays off most on photographs and flat graphics: a recompressed
|
|
975
1091
|
JPEG file is about 25% smaller, and a 960 × 450 heatmap is 51 KB lossless
|
|
@@ -994,7 +1110,7 @@ layout as missing.
|
|
|
994
1110
|
Images are 8-bit sRGB. Without `quality` they are lossless (4:4:4, identity
|
|
995
1111
|
matrix); with it, lossy (BT.601, 4:4:4 from quality 90, 4:2:0 below).
|
|
996
1112
|
Alpha is always lossless. Encoder speed follows `compression`: 8 (`fast`),
|
|
997
|
-
6 (`balanced`) or 4 (`
|
|
1113
|
+
6 (`balanced`) or 4 (`small`). AVIF suits lossy output: a 960 × 450 heatmap
|
|
998
1114
|
is 26 KB at quality 90 and 12 KB at 70, but 115 KB lossless, more than its
|
|
999
1115
|
81 KB PNG.
|
|
1000
1116
|
|
|
@@ -1021,8 +1137,9 @@ clipping, transparency groups and soft masks are supported, and every platform
|
|
|
1021
1137
|
computes identical pixels.
|
|
1022
1138
|
As in PDF viewers, strokes are at least one device pixel wide; images are
|
|
1023
1139
|
smoothed unless `smooth=False` (`/Interpolate false`) or magnified 4 times or
|
|
1024
|
-
more, and minified images are averaged. A
|
|
1025
|
-
|
|
1140
|
+
more, and minified images are averaged. A stroke whose visible dashes make more
|
|
1141
|
+
than 2^24 (16,777,216) outline points, all its subpaths together, raises
|
|
1142
|
+
`RasterizationError`.
|
|
1026
1143
|
|
|
1027
1144
|
The scene is compiled once into a display list: shapes scan converted, plain
|
|
1028
1145
|
forms (markers) rendered once per 1/32-pixel phase, gradients, patterns and
|
|
@@ -1040,7 +1157,7 @@ Text is drawn from the outlines of its fonts (TrueType or CFF), the ones the PDF
|
|
|
1040
1157
|
embeds (scenes hold glyph ids; their codes in each subset are written with the PDF),
|
|
1041
1158
|
wherever it is: groups, masks, patterns, markers, clipping paths, images. A
|
|
1042
1159
|
standard 14 font (`embed=False`) is drawn with the outlines of the installed font its name
|
|
1043
|
-
resolves to
|
|
1160
|
+
resolves to: its URW family (Nimbus Sans, Nimbus Roman, Nimbus Mono PS, Standard Symbols PS, D050000L), then the family's metric aliases ([Fonts](#16-fonts)), the same fonts as for a PDF read at the standard advance
|
|
1044
1161
|
widths; with no installed font at all that raises `RasterizationError`.
|
|
1045
1162
|
|
|
1046
1163
|
Marker timings, 100,000 points on a 400 × 300 pt area:
|
|
@@ -1084,7 +1201,7 @@ decimates. The same page can be written with different settings.
|
|
|
1084
1201
|
|
|
1085
1202
|
| API | Scope |
|
|
1086
1203
|
|---|---|
|
|
1087
|
-
| `Document.
|
|
1204
|
+
| `Document.write(…, simplify=…)`, `save(…, simplify=…)` | every page, group, mask and pattern |
|
|
1088
1205
|
| `Page.render(…, simplify=…)` | decimation of the page's lines |
|
|
1089
1206
|
| `draw_markers`, `draw_segments`, `draw_lines`, `fill_between`, `draw_rects`, `fill_polygons` (`simplify=`) | the call |
|
|
1090
1207
|
| `Canvas.group(simplify=…)` | the body, across calls |
|
|
@@ -1110,7 +1227,8 @@ decimates. The same page can be written with different settings.
|
|
|
1110
1227
|
deleted when hidden but hides nothing; images, shadings and groups hide
|
|
1111
1228
|
nothing either. Under a soft mask, a scope opened by a call or an inline
|
|
1112
1229
|
group does nothing.
|
|
1113
|
-
* SVG output ([18](#18-output))
|
|
1230
|
+
* EPS and SVG output ([18](#18-output)) are simplified as the PDF is, with the same
|
|
1231
|
+
setting.
|
|
1114
1232
|
|
|
1115
1233
|
What changes: in a renderer that composites shapes one by one with partial
|
|
1116
1234
|
coverage (vec_io and PDF viewers), the deleted content changes no pixel by
|
|
@@ -1127,9 +1245,9 @@ At other resolutions the same holds up to slivers smaller than a pixel.
|
|
|
1127
1245
|
| Scene | PDF | Time | Max change | Pixels changed ≥ 1 / ≥ 8 levels |
|
|
1128
1246
|
|---|---|---|---|---|
|
|
1129
1247
|
| Gaussian 60k, sizes 1–4, 3 colors, opaque | 790 → 188 KB | 0.10 → 0.16 s | 47 | 0.013 / 0.003 % |
|
|
1130
|
-
| same,
|
|
1248
|
+
| same, opacity 0.5 | 802 → 586 KB | 0.09 → 0.26 s | 1 | 0.37 / 0 % |
|
|
1131
1249
|
| Binned 60k (duplicates), one color, opaque | 119 → 4 KB | 0.29 → 0.34 s | 212 | 1.0 / 0.94 % |
|
|
1132
|
-
| Binned 60k, 3 colors,
|
|
1250
|
+
| Binned 60k, 3 colors, opacity 0.3 | 159 → 56 KB | 0.32 → 0.42 s | 114 | 1.3 / 0.12 % |
|
|
1133
1251
|
| Gaussian 60k, one color, white outline | 437 → 84 KB | 0.05 → 0.10 s | 1 | 0 / 0 % |
|
|
1134
1252
|
| Segments 40k, one color | 528 → 313 KB | 0.08 → 0.12 s | 0 | 0 / 0 % |
|
|
1135
1253
|
| Segments 40k, 3 colors | 582 → 365 KB | 0.08 → 0.13 s | 1 | 0.003 / 0 % |
|
|
@@ -1182,12 +1300,12 @@ calibrated to, cull exactly where culling saves at least 30 % of the bytes
|
|
|
1182
1300
|
| Scene | PDF | Estimate | `"auto"` |
|
|
1183
1301
|
|---|---|---|---|
|
|
1184
1302
|
| Gaussian 60k, sizes 1–4, 3 colors, opaque | 790 → 188 KB (−76 %) | 0.79 | culls |
|
|
1185
|
-
| same,
|
|
1303
|
+
| same, opacity 0.5 | 802 → 586 KB (−27 %) | 0.14 | keeps |
|
|
1186
1304
|
| Binned 60k (duplicates), one color, opaque | 119 → 4 KB (−97 %) | 0.99 | culls |
|
|
1187
|
-
| Binned 60k, 3 colors,
|
|
1305
|
+
| Binned 60k, 3 colors, opacity 0.3 | 159 → 56 KB (−65 %) | 0.89 | culls |
|
|
1188
1306
|
| Gaussian 60k, one color, white outline | 437 → 84 KB (−81 %) | 0.84 | culls |
|
|
1189
1307
|
| Uniform 2k, one color, opaque | 17 → 16 KB (−1 %) | 0.00 | keeps |
|
|
1190
|
-
| Uniform 200k, one color,
|
|
1308
|
+
| Uniform 200k, one color, opacity 0.3 | 1,490 → 1,432 KB (−4 %) | 0.00 | keeps |
|
|
1191
1309
|
| Binned 1M, one color, opaque | 1,957 → 6 KB (−100 %) | 1.00 | culls |
|
|
1192
1310
|
|
|
1193
1311
|
On a million markers that it does not cull, `"auto"` adds 2 ms.
|
|
@@ -1230,7 +1348,7 @@ SVG's Filter Effects 1, with the same semantics:
|
|
|
1230
1348
|
| `ConvolveMatrix` | `kernel`, `order=3`, `divisor`, `bias`, `target_x`, `target_y`, `edge_mode`, `preserve_alpha` |
|
|
1231
1349
|
| `Turbulence` | `base_frequency`, `octaves`, `seed`, `type` (`turbulence`, `fractalNoise`), `stitch`, `transform` |
|
|
1232
1350
|
| `DiffuseLighting`, `SpecularLighting` | `light` (`DistantLight(azimuth, elevation)`, `PointLight(x, y, z)`, `SpotLight(x, y, z, points_at, specular_exponent, limiting_cone_angle)`), `surface_scale`, `constant`, (`exponent`), `color` |
|
|
1233
|
-
| `Image` | `source` (
|
|
1351
|
+
| `Image` | `source` (image bytes or a path, the formats of `draw_image`), `preserve_aspect_ratio`, `smooth` |
|
|
1234
1352
|
| `DisplacementMap` | `scale`, `x_channel`, `y_channel` (`R`, `G`, `B`, `A`), `input2` |
|
|
1235
1353
|
|
|
1236
1354
|
Every primitive also takes `input` (`"SourceGraphic"`, `"SourceAlpha"` or an earlier
|
|
@@ -1243,12 +1361,12 @@ The pixel work is C (`src/filters.c`).
|
|
|
1243
1361
|
SVG `filter` properties are read into the same `Filter` (`primitiveUnits`, `filterUnits`,
|
|
1244
1362
|
`color-interpolation-filters`, `flood-color`, `lighting-color`; `feImage` references to
|
|
1245
1363
|
elements are transparent; `kernelUnitLength` is ignored) and drawn through
|
|
1246
|
-
`group(filter=…)`. In SVG they are
|
|
1364
|
+
`group(filter=…)`. In SVG they are on by default, as in browsers:
|
|
1247
1365
|
|
|
1248
|
-
| Scope |
|
|
1366
|
+
| Scope | Disable |
|
|
1249
1367
|
|---|---|
|
|
1250
|
-
| Conversion | `convert(…, filters=
|
|
1251
|
-
| Document | `Document(filters=
|
|
1368
|
+
| Conversion | `convert(…, filters=False)`; CLI `--no-filters` |
|
|
1369
|
+
| Document | `Document(filters=False)` (SVGs placed with `draw_svg` and `draw.SVG`) |
|
|
1252
1370
|
| Element and descendants | SVG `data-filters="true"` / `"false"`. Overrides the scope above. |
|
|
1253
1371
|
|
|
1254
1372
|
## 15. SVG support
|
|
@@ -1256,28 +1374,30 @@ elements are transparent; `kernelUnitLength` is ignored) and drawn through
|
|
|
1256
1374
|
| Area | Support |
|
|
1257
1375
|
|---|---|
|
|
1258
1376
|
| Shapes | `rect` (rounded), `circle`, `ellipse`, `line`, `polyline`, `polygon`, `path` (all commands, arcs) |
|
|
1259
|
-
| Structure | `g`, nested `svg`, `use`, `symbol`, `defs`, `a`, `switch`, `viewBox`, `preserveAspectRatio`, `transform
|
|
1260
|
-
| Styling | presentation attributes, `style`, `<style
|
|
1261
|
-
|
|
|
1262
|
-
|
|
|
1377
|
+
| Structure | `g`, nested `svg`, `use`, `symbol`, `defs`, `a`, `switch`, `viewBox`, `preserveAspectRatio`, `transform` (attribute, or the CSS property with units; the `translate`, `rotate` and `scale` properties; `transform-origin` and `transform-box`, default `view-box` and `0 0` as in browsers; 3-D functions projected); a zero-size `viewBox` disables rendering; at most 300,000 elements are instantiated through `<use>` per document (further instances are skipped); `<use>` of an element of another file or URL (`other.svg#a`, [Network and other files](#network-and-other-files)); other references (`url()`, `href` of paint servers) are within the document |
|
|
1378
|
+
| Styling | presentation attributes, `style`, `<style>`, `font` and `marker` shorthands, inheritance, `inherit`, `currentColor`, `!important`; geometry properties (`cx`, `cy`, `r`, `rx`, `ry`, `x`, `y`, `width`, `height` of `rect`, `circle`, `ellipse`, `image`, `use`, nested `svg`, and `d` of `path` as `path("…")` or `none`) set by their attributes or by CSS (a rule beats the attribute; not inherited; unitless numbers taken, as Chrome) |
|
|
1379
|
+
| Selectors | type, class, id, attribute (`=`, `~=`, `\|=`, `^=`, `$=`, `*=`, ` i`/` s` flags); descendant, child, sibling combinators; `:root`, `:empty`, `:first-child`, `:last-child`, `:only-child`, `:nth-child()`/`:nth-last-child()` (with `of S`), `:first-of-type`, `:last-of-type`, `:only-of-type`, `:nth-of-type()`/`:nth-last-of-type()`, `:not()`, `:is()`, `:where()` (no specificity), `:has()`, `:lang()`, `:link`; user-action pseudo-classes (`:hover`, `:focus`, …) and pseudo-elements never match; an invalid selector drops its rule |
|
|
1380
|
+
| CSS | nesting (`&`, nested rules and `@media`); custom properties (`--name`, inherited, also through `<use>`) and `var(--name, fallback)` in any property or attribute (cycles invalid); `calc()`, `min()`, `max()`, `clamp()`, `round()` and the other math functions, mixed units and percentages, wherever a length, number or angle is taken; units `vw`, `vh`, `vmin`, `vmax` (the root viewport), `Q`, `ex`, `ch`, `cap` (the font's metrics), `lh`, `rlh`; `@media` evaluated for print (or screen) and a light (or dark) color scheme, no pointing device, viewport sizes matching; `<style media="…">`; `@font-face`; `@import` and `<?xml-stylesheet?>` style sheets, from files or URLs ([Network and other files](#network-and-other-files)); `@import` of Google Fonts CSS gives Google families ([Font downloads](#font-downloads)) |
|
|
1381
|
+
| Painting | `fill`, `stroke` (CSS Color 4 colors, `device-cmyk()`), `fill-rule`, `stroke-width`/`-linecap`/`-linejoin`/`-miterlimit`/`-dasharray`/`-dashoffset`, `paint-order`, `opacity`, `fill-opacity`, `stroke-opacity`; `context-fill`/`context-stroke` in marker content (the marked shape's fill and stroke); `pathLength` (scales the dashes, their offset and a `textPath`'s `startOffset`; not markers; 0 makes dashes endless as Chrome, negative or invalid is ignored); `vector-effect: non-scaling-stroke` (stroke width and dashes in the root's CSS pixels whatever the transform); `shape-rendering: crispEdges` or `optimizeSpeed` (image output draws the shape without antialiasing; PDF and EPS unchanged; SVG output keeps it) |
|
|
1263
1382
|
| Paint servers | `linearGradient`, `radialGradient` (focal point, `href` inheritance, `gradientTransform`, `spreadMethod`, `stop-opacity`), `pattern` |
|
|
1264
|
-
| Compositing | group opacity, `clipPath` (any shapes and text, `objectBoundingBox`, nested), luminance `mask` |
|
|
1265
|
-
| Markers | `marker-start`/`-mid`/`-end`, `orient` (`auto`, `auto-start-reverse`, angles), `viewBox`, `markerUnits`, `overflow`; drawn through `PathMarker` |
|
|
1266
|
-
| Text | `text`, `tspan`, `tref`, `textPath` (`startOffset`, `side`, `path`, `method="stretch"`); `x`/`y`/`dx`/`dy`/`rotate` lists; `textLength`, `lengthAdjust`; `text-anchor`; `inline-size` (SVG 2 wrapping: lines aligned by `text-anchor`, the first baseline at `y`); `font` and `font-*` (`font-kerning` included); `letter-spacing`, `word-spacing`, `text-decoration` (applies to descendants, painted with the declaring element's fill and stroke; `line-through` at the font's strikeout position and thickness), `dominant-baseline`, `baseline-shift` (`sub`, `super`, lengths, percentages; nested shifts add up), `xml:space` (inherited) |
|
|
1267
|
-
| Images | PNG (all color types and depths, interlacing, transparency), JPEG (embedded unchanged), [JPEG XL](#jpeg-xl) (with libjxl), SVG; `data:` URIs
|
|
1383
|
+
| Compositing | group opacity; `mix-blend-mode` (the 16 modes; the element blended as a group, the root isolated as in browsers; CSS only, not an attribute, as Chrome) and `isolation: isolate`; `clipPath` (any shapes and text, `objectBoundingBox`, nested); `clip-path` basic shapes (`inset()` with `round`, `circle()`, `ellipse()`, `polygon()`, `path()`, positions and `closest-side`/`farthest-side`) with a reference box (`fill-box` default, `stroke-box`, `view-box`; the CSS layout boxes are the fill box); `mask` (`mask-type: luminance` or `alpha`; the `mask` and `mask-image` properties naming a `<mask>`); a `clip-path` or `mask` naming a missing element, or an element of another kind, applies none; an invalid basic shape clips nothing |
|
|
1384
|
+
| Markers | `marker-start`/`-mid`/`-end`, `orient` (`auto`, `auto-start-reverse`, angles in `deg`, `grad`, `rad`, `turn`; a bare number is degrees), `viewBox`, `markerUnits`, `overflow`; drawn through `PathMarker` |
|
|
1385
|
+
| Text | `text`, `tspan`, `tref`, `textPath` (`startOffset`, `side`, `path`, `method="stretch"`); `x`/`y`/`dx`/`dy`/`rotate` lists; `textLength`, `lengthAdjust`; `text-anchor`; `inline-size` (SVG 2 wrapping: lines aligned by `text-anchor`, the first baseline at `y`; edge spaces kept under `xml:space="preserve"` or `white-space: pre`); `font` and `font-*` (`font-kerning` included; default family `system-ui`); `font-variant` and its longhands, `font-feature-settings`, `font-size-adjust`, `font-synthesis` ([shaping](#shaping)); `text-transform` (`uppercase`, `lowercase`, `capitalize`, `full-width`); `letter-spacing`, `word-spacing`, `text-decoration` (the shorthand or `-line`, `-style` (`solid`, `double`, `dotted`, `dashed`, `wavy`), `-thickness` (a length, a percentage of the em, `from-font`); applies to descendants, painted with the declaring element's fill and stroke as in browsers, so `text-decoration-color`, `text-underline-offset` and `text-underline-position` are not used; `line-through` at the font's strikeout position and thickness), `dominant-baseline` and `alignment-baseline` (each character on its element's `alignment-baseline`, else the `dominant-baseline`, as Chrome; on `text` too, which SVG 1.1 does not allow; positions from the font: [`baseline_position`](#61-shaping-without-a-page-vec_iotext)), `baseline-shift` (`sub`, `super`, lengths, percentages; nested shifts add up), `direction` and `unicode-bidi` (the bidi algorithm per text chunk; `text-anchor` follows the direction), `writing-mode` vertical (`vertical-rl`, `vertical-lr`, `tb`, `tb-rl`: upright CJK with `vmtx` advances and `vert` forms, other text sideways on the central baseline; `text-orientation`, `glyph-orientation-vertical`), `xml:space` (inherited) |
|
|
1386
|
+
| Images | PNG (all color types and depths, interlacing, transparency), JPEG (embedded unchanged), GIF (the first frame; palette, transparency, interlacing), BMP (1–32 bits, RLE4/RLE8, bit fields, alpha), ICO (the largest image), [JPEG XL](#jpeg-xl) (with libjxl), WebP (with libwebp: lossy, lossless, alpha, an animation's first frame), AVIF (with libavif, the first frame), SVG; `data:` URIs, local files, http(s) URLs. PDF stores GIF, BMP, ICO and lossless WebP lossless, lossy WebP and AVIF as JPEG at the output's `ImagePolicy(quality=…)`, else 90. Without its library a WebP, AVIF or JPEG XL image warns once (`ImageWarning`) and is drawn as missing (`VEC_IO_LIBWEBP`, `VEC_IO_LIBAVIF`, `VEC_IO_LIBJXL` give a library's path). `image-rendering: pixelated`/`crisp-edges` |
|
|
1268
1387
|
| Filters | see [Filters](#14-filters) |
|
|
1269
1388
|
| vec_io attributes | `data-rasterize`, `data-simplify`, `data-quality`, `data-filters` |
|
|
1270
1389
|
| Input | UTF-8 or declared encodings, SVGZ, common HTML entities |
|
|
1271
1390
|
|
|
1272
1391
|
Document size: `width`/`height` in any CSS unit, else `viewBox`, else
|
|
1273
|
-
300 × 150. `rem`
|
|
1392
|
+
300 × 150. `em`, `ex` and `rem` on the root `<svg>` refer to its own font size; elsewhere
|
|
1393
|
+
`rem` and `rlh` refer to the root's font, `vw` and `vh` to the root's size.
|
|
1274
1394
|
|
|
1275
1395
|
## 16. Fonts
|
|
1276
1396
|
|
|
1277
1397
|
Fonts are embedded as subsets, always. For each character, the font is the first of:
|
|
1278
1398
|
|
|
1279
1399
|
1. The listed families of `font-family`, in order: an `@font-face` font, a font added with
|
|
1280
|
-
`Document.add_font`, or an installed font (`
|
|
1400
|
+
`Document.add_font`, or an installed font (`Fonts.dirs`, then `VEC_IO_FONT_DIRS`, then the
|
|
1281
1401
|
system directories), weight, width and style matched as in CSS Fonts 4 (missing bold
|
|
1282
1402
|
and italic faces are synthesized). A family that is not installed resolves to its
|
|
1283
1403
|
first installed metric alias: Helvetica and Arial to Liberation Sans, Arimo, Nimbus
|
|
@@ -1289,8 +1409,12 @@ Fonts are embedded as subsets, always. For each character, the font is the first
|
|
|
1289
1409
|
next family. Generic families resolve to the first installed family of their list
|
|
1290
1410
|
(`serif`: Times New Roman, Liberation Serif, DejaVu Serif, …; `sans-serif`: Arial,
|
|
1291
1411
|
Helvetica, Liberation Sans, DejaVu Sans, …; `monospace`: Courier New, Liberation Mono,
|
|
1292
|
-
DejaVu Sans Mono,
|
|
1293
|
-
|
|
1412
|
+
DejaVu Sans Mono, …; `system-ui`, the default family: on macOS SF Pro Text below 20 pt
|
|
1413
|
+
and SF Pro Display from there, else Helvetica Neue; on Windows Segoe UI; elsewhere
|
|
1414
|
+
fontconfig's `system-ui` match (the desktop's interface font: Adwaita Sans, Cantarell,
|
|
1415
|
+
Noto Sans, Ubuntu…), then Noto Sans, DejaVu Sans), else to the best installed face of
|
|
1416
|
+
all; for text with no font at all, to Noto Sans (`sans-serif`, `system-ui`), Noto Serif
|
|
1417
|
+
or Noto Sans Mono from Google Fonts.
|
|
1294
1418
|
2. The generic family the list implies (`serif` for Times-like names, `monospace` for
|
|
1295
1419
|
Courier-like ones, else `sans-serif`).
|
|
1296
1420
|
3. Any installed font that has the character (Greek, Cyrillic, CJK, …), then any family
|
|
@@ -1304,9 +1428,9 @@ WinAnsi (Symbol and ZapfDingbats theirs) with the Adobe metrics, and is not kern
|
|
|
1304
1428
|
characters take steps 1–4. SVG text is always embedded.
|
|
1305
1429
|
|
|
1306
1430
|
Text needs an outline font. With none available at all (no installed font, or
|
|
1307
|
-
`
|
|
1431
|
+
`Fonts(system=False)` without `dirs`, `VEC_IO_FONT_DIRS`, `@font-face` or `add_font`,
|
|
1308
1432
|
and font downloads off or failing), drawing or measuring text raises `NoFontError`
|
|
1309
|
-
(
|
|
1433
|
+
(a `ValueError`) naming these remedies; documents without text need
|
|
1310
1434
|
no font. A silent fallback to the standard 14
|
|
1311
1435
|
fonts would make the PDF depend on the viewer's fonts, differ from vec_io's own images,
|
|
1312
1436
|
and fail anyway in image output and PDF/A, which need outlines.
|
|
@@ -1333,10 +1457,42 @@ their text cannot be selected or searched. Text filled with a flat color draws e
|
|
|
1333
1457
|
from a form defined once (SVG: a `<use>` of a definition); text with a gradient or pattern,
|
|
1334
1458
|
stroked or clipping text are paths. A page of 4,500 characters in Liberation Sans is about
|
|
1335
1459
|
11 KB this way (4.5 KB as text); a plot's few labels add a few KB.
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1460
|
+
### Shaping
|
|
1461
|
+
|
|
1462
|
+
One shaper serves Canvas text, paragraphs, `vec_io.text` and SVG text.
|
|
1463
|
+
|
|
1464
|
+
- Pair kerning (GPOS `kern`, else the `kern` table) applies to every text
|
|
1465
|
+
(`font-kerning: none` and `font_kerning="none"` turn it off).
|
|
1466
|
+
- Standard ligatures (`liga`) apply to paragraphs and to `vec_io.text.shape` with
|
|
1467
|
+
`ligatures=True`; `font-variant` asks for others (`clig`, `calt`, `dlig`, `hlig`); other
|
|
1468
|
+
text shows one glyph per character.
|
|
1469
|
+
- `font-variant` (and `font-variant-caps`, `-numeric`, `-ligatures`, `-position`,
|
|
1470
|
+
`-east-asian`, `-alternates`) map to OpenType features (`smcp`, `c2sc`, `pcap`, `onum`,
|
|
1471
|
+
`lnum`, `tnum`, `pnum`, `frac`, `zero`, `liga`, `dlig`, `subs`, `sups`, `jp78`…);
|
|
1472
|
+
`font-feature-settings` applies after them. Small capitals are synthesized when the font
|
|
1473
|
+
has none, as browsers do: capitals at 0.7 of the size, written as a font of their own
|
|
1474
|
+
so that they extract as the lowercase text.
|
|
1475
|
+
- The built-in shaper applies GSUB lookups of every type (single, multiple, alternate,
|
|
1476
|
+
ligature, contextual, chained, extension, reverse chained) and GPOS lookups (single,
|
|
1477
|
+
pair, cursive, mark-to-base, mark-to-ligature, mark-to-mark, contextual), with lookup
|
|
1478
|
+
flags and mark filtering sets; `ccmp`, `locl`, `rlig`, `mark`, `mkmk`, `curs` are always
|
|
1479
|
+
on; marks get no advance and sit on their anchors.
|
|
1480
|
+
- Complex scripts (Arabic, Syriac, N'Ko, Mongolian, the Indic scripts, Sinhala, Thai, Lao,
|
|
1481
|
+
Tibetan, Myanmar, Khmer, Javanese, Balinese…) are shaped by HarfBuzz when it is
|
|
1482
|
+
installed (an optional system library loaded with ctypes: `libharfbuzz`;
|
|
1483
|
+
`VEC_IO_LIBHARFBUZZ` gives its path, `VEC_IO_NO_LIBHARFBUZZ=1` turns it off); without it
|
|
1484
|
+
they are drawn by the built-in shaper, unjoined and unreordered, with a `VecIOWarning`
|
|
1485
|
+
(once per script). Latin, Greek, Cyrillic, CJK and Hebrew need no HarfBuzz.
|
|
1486
|
+
- Right-to-left and mixed text is ordered by the Unicode Bidirectional Algorithm (UAX #9:
|
|
1487
|
+
embeddings, overrides, isolates, brackets, mirrored characters).
|
|
1488
|
+
- Text extraction: each glyph's ToUnicode entry is its characters (a ligature its
|
|
1489
|
+
components; in a cluster of several glyphs, each glyph its own character); glyphs are
|
|
1490
|
+
written in visual order. A cluster whose glyphs, read in that order (reversed right to
|
|
1491
|
+
left), are not its characters (an Indic vowel sign drawn before its consonant, a vowel
|
|
1492
|
+
split around one) is shown in marked content, `/Span <</ActualText (…)>> BDC … EMC`,
|
|
1493
|
+
giving its characters, so viewers copy and search them in logical order. Right-to-left
|
|
1494
|
+
runs need none: viewers reorder them. Text on a path (glyph by glyph) and
|
|
1495
|
+
`text_as_paths` get no spans.
|
|
1340
1496
|
A subset costs a few KB: a plot page's labels and bold title in Arial (two faces) add
|
|
1341
1497
|
about 4 KB, compressed (20 KB with the hinting).
|
|
1342
1498
|
|
|
@@ -1383,12 +1539,14 @@ Downloads are on by default:
|
|
|
1383
1539
|
|
|
1384
1540
|
| Setting | Effect |
|
|
1385
1541
|
|---|---|
|
|
1386
|
-
| `
|
|
1387
|
-
| `
|
|
1388
|
-
| `
|
|
1542
|
+
| `Fonts(downloads=None)` (default) | `VEC_IO_FONT_DOWNLOADS`: `1`/`on` (default), `0`/`off`, or `cache` |
|
|
1543
|
+
| `Fonts(downloads=True)` / `False` | Downloads on / off. |
|
|
1544
|
+
| `Fonts(downloads="cache")` | Families already downloaded only; no network. |
|
|
1545
|
+
| `Document(network=False)`, `convert(network=False)`, CLI `--no-network` | Downloads off, whatever `downloads` says. |
|
|
1389
1546
|
|
|
1390
|
-
`
|
|
1391
|
-
CLI has `--font-downloads MODE`, `--no-font-downloads` and
|
|
1547
|
+
`Document(fonts=…)` and `convert(fonts=…)` take a `Fonts`; `FontDB` takes
|
|
1548
|
+
`font_downloads` itself. The CLI has `--font-downloads MODE`, `--no-font-downloads` and
|
|
1549
|
+
`--download-font FAMILY`.
|
|
1392
1550
|
|
|
1393
1551
|
* **Names.** A family is fetched by its own name only, from the first source that lists
|
|
1394
1552
|
it (Google first, so `Anton` comes from Google, not Fontshare); when that download fails,
|
|
@@ -1397,8 +1555,9 @@ CLI has `--font-downloads MODE`, `--no-font-downloads` and `--download-font FAMI
|
|
|
1397
1555
|
named after it are stand-ins only when installed), `Nimbus Sans` fetches Nimbus Sans.
|
|
1398
1556
|
Other names ("SF Pro", a typo) never cause a request. In SVG, the families of an
|
|
1399
1557
|
`@import url(https://fonts.googleapis.com/css2?family=…)` count as Google families, and
|
|
1400
|
-
`@font-face` sources on `fonts.gstatic.com` are fetched into the cache; other
|
|
1401
|
-
|
|
1558
|
+
`@font-face` sources on `fonts.gstatic.com` are fetched into the cache; other URLs are
|
|
1559
|
+
fetched as the document's other resources ([Network and other
|
|
1560
|
+
files](#network-and-other-files)).
|
|
1402
1561
|
* **Styles.** A static face is chosen by CSS matching among the faces the source has
|
|
1403
1562
|
(Lato at weight 450 fetches Lato Regular); a variable file serves every weight, width,
|
|
1404
1563
|
slant and optical size exactly as an installed copy. A Fontsource style is several files,
|
|
@@ -1457,11 +1616,11 @@ again (the styles it has), replacing the cached version.
|
|
|
1457
1616
|
|
|
1458
1617
|
### Installed fonts
|
|
1459
1618
|
|
|
1460
|
-
For machine-independent output, pass `
|
|
1461
|
-
provide fonts with
|
|
1462
|
-
downloaded family is a font directory). `VEC_IO_FONT_DIRS` (directories separated by
|
|
1463
|
-
`os.pathsep`) adds font directories to every `FontDB`, also with `
|
|
1464
|
-
|
|
1619
|
+
For machine-independent output, pass `fonts=Fonts(dirs=…, system=False, downloads=False)`
|
|
1620
|
+
and provide fonts with those directories, `@font-face` or `add_font` (a copied cache folder
|
|
1621
|
+
of a downloaded family is a font directory). `VEC_IO_FONT_DIRS` (directories separated by
|
|
1622
|
+
`os.pathsep`) adds font directories to every `FontDB`, also with `system=False`; the tests
|
|
1623
|
+
point it at their own font.
|
|
1465
1624
|
|
|
1466
1625
|
Font directories are scanned once per process. The name, weight and style of
|
|
1467
1626
|
every font file are kept in a persistent index (`fonts.json` in
|
|
@@ -1501,24 +1660,96 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
|
|
|
1501
1660
|
|
|
1502
1661
|
## 18. Output
|
|
1503
1662
|
|
|
1663
|
+
Every output is written by `Document.write(kind, *, pages=None, **options)` (and
|
|
1664
|
+
`Document.save`, `Page.write`/`save`, `Drawing.write`/`save`, `convert`, the command line):
|
|
1665
|
+
one way to give each option, one set of options per kind.
|
|
1666
|
+
|
|
1667
|
+
### 18.1 Options
|
|
1668
|
+
|
|
1669
|
+
| Option | Outputs | Meaning |
|
|
1670
|
+
|---|---|---|
|
|
1671
|
+
| `compression` | PDF, EPS | `"fast"`, `"balanced"` (default) or `"small"`: the effort of every compressed stream, of image samples and of JPEG and JPEG XL encoding; `None`: streams uncompressed (a readable PDF 1.4; readable PostScript). |
|
|
1672
|
+
| `simplify` | all | `None` (default): only what the content asks for; `True` (600 dpi) or a resolution: leave out what later content hides, and decimate lines; `"auto"`: per bulk call, where it pays off ([Simplification](#13-simplification)). Images only decimate. |
|
|
1673
|
+
| `images` | PDF, EPS, SVG | An `ImagePolicy`: how images are stored (below; [Image encoding](#image-encoding)). |
|
|
1674
|
+
| `flatten` | PDF, EPS, SVG | A `Flatten`: translucent content drawn as opaque vectors ([Transparency flattening](#transparency-flattening)). |
|
|
1675
|
+
| `font_hinting` | PDF, EPS | Keep the TrueType hinting in embedded subsets (default: left out). |
|
|
1676
|
+
| `text_as_paths` | EPS | Every font drawn as glyph outlines. |
|
|
1677
|
+
| `dpi` | all | The output's resolution. Images: rendered at it (default the document's `default_dpi`). PDF, EPS and SVG: their images resampled to it (`ImagePolicy`'s `dpi`); not given, kept as they are. |
|
|
1678
|
+
| `view` | all | A `View`: what each page shows and at what size, for this output only (the pages keep their own view). |
|
|
1679
|
+
| `background` | images | A color under the page; `None`: transparent (white for JPEG). |
|
|
1680
|
+
| `png`, `jpeg`, `jxl`, `avif` | that image format | The format's options: `PNG`, `JPEG`, `JXL`, `AVIF` ([5.9](#59-rendering-and-image-output)). |
|
|
1681
|
+
|
|
1682
|
+
An unknown option, an option of another output (`"compression applies to PDF and EPS
|
|
1683
|
+
output"`) or a value that cannot be used raises `OptionError`.
|
|
1684
|
+
|
|
1685
|
+
The options that group settings are objects of `vec_io.options` (also exported by
|
|
1686
|
+
`vec_io`): frozen dataclasses, checked when made (`OptionError`), with `replace(**changes)`.
|
|
1687
|
+
A dict of an object's fields is accepted wherever the object is (`flatten={"dpi": 300}`).
|
|
1688
|
+
|
|
1689
|
+
| Object | Fields |
|
|
1690
|
+
|---|---|
|
|
1691
|
+
| `Fonts(dirs=(), system=True, downloads=None, db=None)` | Font sources: directories searched first (then `VEC_IO_FONT_DIRS`), installed fonts, downloads of named families (`True`, `False`, `"cache"`; `None`: `VEC_IO_FONT_DOWNLOADS`, on by default), or `db`, a `FontDB` used as it is (with none of the others). `Document(fonts=…)`, `convert(fonts=…)`. |
|
|
1692
|
+
| `Flatten(transparency=None, fallback="raster", dpi=600, budget=256, cell=0.25)` | `transparency`: flatten (`None`: the output's default: on for EPS, off for PDF and SVG); what cannot be flattened becomes (`"raster"`, `"opaque"`, `"error"`); the raster fallback's resolution; pieces per grid cell; the cell size in inches. |
|
|
1693
|
+
| `View(trim=False, margin=None, width=None, height=None, scale=None, size=None, aspect=None, align=None)` | Numbers in CSS pixels, strings lengths. `trim`: each page cut to what it draws (images to the pixel, unless a size or `scale` is given; PDF, EPS and SVG as `Page.trim`). `margin`: blank space on each side: around what `trim` kept, inside a size given, else added around the page. `width`/`height` (a length or a paper size's side: `"a4"`, `"letter"`, `"a4-landscape"`), `size` (both: `"us"`, `"8.5in x 11in"`, a pair) or `scale` (a factor): the output's size, each page zoomed as a whole ([Resizing](#resizing)). With both sides, `aspect`: `"fit"` (default; placed by `align`: `"start"`, `"center"`, `"end"`, or a pair) or `"stretch"`; `aspect` or `align` without both sides is an `OptionError`. `Page.view(view)` keeps one on a page. |
|
|
1694
|
+
| `ImagePolicy(…)` | Below. |
|
|
1695
|
+
| `PNG`, `JPEG`, `JXL`, `AVIF` | Image formats ([5.9](#59-rendering-and-image-output)). |
|
|
1696
|
+
|
|
1697
|
+
```python
|
|
1698
|
+
ImagePolicy(quality=None, jxl=False, dpi=None, dpi_mode="down", dpi_threshold=1.5,
|
|
1699
|
+
dpi_average="srgb")
|
|
1700
|
+
```
|
|
1701
|
+
|
|
1702
|
+
`quality` (1–100): rasterized content (rasterized groups, filtered elements) is stored lossy
|
|
1703
|
+
at this quality, as JPEG, or as JPEG XL with `jxl`; `None`: lossless. A group's own
|
|
1704
|
+
`quality` overrides it. `jxl`: write images as JPEG XL ([JPEG XL](#jpeg-xl)). Other images
|
|
1705
|
+
keep their encoding.
|
|
1706
|
+
|
|
1707
|
+
`dpi`: the resolution of the output's images (PDF, EPS, SVG), in pixels per inch where they
|
|
1708
|
+
are placed; `None` (default): images as they are. Each image is measured at its largest
|
|
1709
|
+
placement (each axis; forms, markers, patterns and masks included):
|
|
1710
|
+
|
|
1711
|
+
| Setting | Meaning |
|
|
1712
|
+
|---|---|
|
|
1713
|
+
| `dpi_mode` | `"down"` (default): an image finer than `dpi` is resampled down to it, a coarser one kept. `"match"`: every image resampled to `dpi`, down or up (enlarged: Catmull–Rom, or pixels repeated for `smooth=False` images). |
|
|
1714
|
+
| `dpi_threshold` | Images within this factor of `dpi` are kept (default 1.5: 310 dpi with `dpi=300` is kept; 1: every image off `dpi` resampled). At least 1. |
|
|
1715
|
+
| `dpi_average` | Shrinking averages each output pixel's area: `"srgb"` (default) the stored values, as viewers minify images, so the file looks as it did on screen; `"linear"` the light (thin dark lines and text lighter, thin bright features on dark brighter). |
|
|
1716
|
+
|
|
1717
|
+
An image off its range on one axis is resampled on both, so its pixels keep their shape.
|
|
1718
|
+
Color is weighted by alpha (no fringes from colors under transparent pixels); alpha is
|
|
1719
|
+
resampled with it. A resampled JPEG is stored as JPEG at `quality` (else 90), resampled
|
|
1720
|
+
rasterized content as rasterized content is (lossy at its group's or `quality`); other images
|
|
1721
|
+
stay lossless. Rasterized groups and the flattening fallback are made at the resolution
|
|
1722
|
+
directly (`down`: the smaller of theirs and `dpi`; `match`: `dpi`). Image output does not use
|
|
1723
|
+
the policy: `dpi` there is the rendering's resolution.
|
|
1724
|
+
|
|
1725
|
+
```python
|
|
1726
|
+
doc.write("pdf", compression="small", images={"quality": 85, "dpi": 300})
|
|
1727
|
+
doc.save("figure.svg", flatten=vec_io.Flatten(transparency=True), view={"trim": True})
|
|
1728
|
+
page.save("figure.png", dpi=192, png={"quality": 90}, view={"margin": "2mm"})
|
|
1729
|
+
policy = vec_io.ImagePolicy(quality=80)
|
|
1730
|
+
doc.write("eps", images=policy.replace(dpi=150))
|
|
1731
|
+
```
|
|
1732
|
+
|
|
1733
|
+
### 18.2 Files
|
|
1734
|
+
|
|
1504
1735
|
* Compressed (default): PDF 1.5. Streams are zlib-compressed, small objects
|
|
1505
1736
|
are packed into compressed object streams and the cross-reference table is
|
|
1506
1737
|
a compressed xref stream; identical streams are written once. Tiny
|
|
1507
1738
|
documents use whichever layout is smaller. On SVG files this halves the
|
|
1508
1739
|
output size compared with a classic layout (median ratio 0.53).
|
|
1509
1740
|
* `compression` of every compressed stream: `"fast"` (zlib level 1),
|
|
1510
|
-
`"balanced"` (zlib 6, default) or `"
|
|
1741
|
+
`"balanced"` (zlib 6, default) or `"small"`: vec_io's Deflate (binary-tree match
|
|
1511
1742
|
finder, near-optimal parsing iterated over the Huffman costs, block splitting),
|
|
1512
1743
|
as small as libdeflate's best level and 3–6 % smaller than zlib's best (PNG rows,
|
|
1513
1744
|
PDF streams). On a 17 MB content stream (a 1M-point line) `fast` is 6.5× faster
|
|
1514
|
-
than `balanced` and 16 % larger; on SVG conversions `
|
|
1745
|
+
than `balanced` and 16 % larger; on SVG conversions `small` writes 9 % less Flate
|
|
1515
1746
|
data than `balanced`, in 1.6× the time of zlib's best. PNG data embedded as is is
|
|
1516
|
-
recompressed at `
|
|
1747
|
+
recompressed at `small`.
|
|
1517
1748
|
* Streams of 1 MB or more are compressed in 1 MB chunks on worker threads
|
|
1518
1749
|
(`VEC_IO_THREADS`, see [Rendering](#rendering)): each chunk is primed with
|
|
1519
1750
|
the previous 32 KB, so the result is one zlib stream within 0.01 % of the
|
|
1520
1751
|
serial size, and the same bytes for any number of threads.
|
|
1521
|
-
* `
|
|
1752
|
+
* `compression=None`: classic, human-readable PDF 1.4 layout, for debugging.
|
|
1522
1753
|
* Every file carries a document `/ID` derived from its content.
|
|
1523
1754
|
* Object numbers and resource names are given when a file is written: names per
|
|
1524
1755
|
category in the order the resources were first used (`F1`, `GS1`, `Fm1`, `Im2`…),
|
|
@@ -1531,25 +1762,35 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
|
|
|
1531
1762
|
(`font_hinting=True`); CFF subsets keep their hints (they are part of the
|
|
1532
1763
|
charstrings).
|
|
1533
1764
|
* SVG conversion: one page of the SVG's size, 1 px = 0.75 pt.
|
|
1534
|
-
* SVG output: `
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1765
|
+
* SVG output: `write("svg")` of a document, page or drawing (and `convert(…,
|
|
1766
|
+
format="svg")`) writes what a page draws, sized in the document's unit, read from its scene
|
|
1767
|
+
command by command by the C library, as the PDF writer reads it, with what the PDF keeps
|
|
1768
|
+
(`simplify`; rasterized groups as their images, stored by `images`; `flatten`): paths with their
|
|
1769
|
+
fills and strokes, `<text>` with every glyph placed (`<tspan>` where kerning or
|
|
1770
|
+
adjustments move one; the faces named by family, weight and style; characters XML 1.0
|
|
1771
|
+
does not allow left out), `<image>` (PNG and JPEG files as given; rasterized content as
|
|
1772
|
+
the PDF stores it: JPEG at the group's or `images`' quality, its alpha as a mask in an SVG
|
|
1773
|
+
image, else PNG; other images as PNG), gradients and tiling patterns, clips
|
|
1539
1774
|
and soft masks (`<clipPath>`, `<mask>`), forms (marker shapes, groups) as `<defs>` reused
|
|
1540
1775
|
by `<use>`, links as `<a>`; smooth cells' mesh becomes an image of about two samples per
|
|
1541
1776
|
unit, and a filtered group the image it is drawn as. Colors are RGB (CMYK and spot colors
|
|
1542
|
-
as their approximation)
|
|
1777
|
+
as their approximation). Read back
|
|
1543
1778
|
by vec_io, a page renders as it did (tests: mean difference under half an 8-bit level;
|
|
1544
1779
|
marker sprites and meshes differ at edges). 200,000 markers take 20 ms (12 MB), a
|
|
1545
1780
|
1M-point line 42 ms, 1.5–2.6× the PDF content writer.
|
|
1546
1781
|
* Shapes and text stay vectors; only rasterized groups, filters and PNG
|
|
1547
1782
|
output produce pixels.
|
|
1783
|
+
* A page whose view shows more than the page (a margin, a fit's room) has its content
|
|
1784
|
+
clipped to the page in every output. A trimmed or resized PDF page draws its content as
|
|
1785
|
+
one form XObject (`/Pg`) whose `/Matrix` is the view and `/BBox` what it shows; other
|
|
1786
|
+
pages write their content directly.
|
|
1548
1787
|
* Numbers: coordinates (paths, rectangles, marker positions, lines, areas,
|
|
1549
1788
|
segments, cells) are written to 1/1000 pt or finer on the page:
|
|
1550
1789
|
the decimals follow the largest scale of the transform, from 0 to 6 (3 for
|
|
1551
|
-
user units in points, 5 for inches). Transform matrices,
|
|
1552
|
-
|
|
1790
|
+
user units in points, 5 for inches). Transform matrices have 6 decimals, more (up to
|
|
1791
|
+
12) when a scale is below 0.1, so that it keeps 6 significant digits (`0.000360892`, the
|
|
1792
|
+
scales of exporters' large internal units); SVG output writes such scales with an
|
|
1793
|
+
exponent (`3.60892e-4`). Line widths and dashes have 6 decimals, colors 4. Drawing records a scene (`scene.py`) whose numbers
|
|
1553
1794
|
are rounded to these decimals when they are captured; the C library writes the content
|
|
1554
1795
|
streams from it.
|
|
1555
1796
|
* Identical inputs give identical bytes, and a document written again with the same
|
|
@@ -1566,7 +1807,7 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
|
|
|
1566
1807
|
|
|
1567
1808
|
### Transparency flattening
|
|
1568
1809
|
|
|
1569
|
-
`
|
|
1810
|
+
`flatten=Flatten(transparency=True)` (PDF and SVG output of `write`, `save`, `convert`;
|
|
1570
1811
|
`--flatten-transparency`) writes pages without transparency: no `/ca` or `/CA` below 1, no
|
|
1571
1812
|
soft mask, no transparency group (SVG: no `opacity`, no `<mask>`). Off by default; pages
|
|
1572
1813
|
without transparency are written as they are.
|
|
@@ -1581,15 +1822,16 @@ without transparency are written as they are.
|
|
|
1581
1822
|
have alpha), images (new samples) and text are flattened; group opacity flattens the
|
|
1582
1823
|
group as one layer, then composites it. Forms placed under or as translucent content are
|
|
1583
1824
|
drawn per placement; others keep their reuse.
|
|
1584
|
-
* Fallback (`
|
|
1825
|
+
* Fallback (`Flatten.fallback`): for content that cannot be flattened (a gradient over a
|
|
1585
1826
|
different gradient, an image over an image or a gradient, a soft mask of varying alpha, a
|
|
1586
|
-
tiling pattern
|
|
1587
|
-
|
|
1588
|
-
(default
|
|
1827
|
+
blend mode, a tiling pattern, a dashed stroke whose outline takes more than 2^24 points) and for grid
|
|
1828
|
+
cells of `cell` inches (default 0.25) holding more than `budget` pieces
|
|
1829
|
+
(default 256; adjacent cells form one region): `"raster"`
|
|
1830
|
+
(default) draws the region as an image of what the page shows there, at `dpi`
|
|
1589
1831
|
(default 600), lossless, 2 pixels wider than its cells and clipped to them and to the
|
|
1590
1832
|
outline of what it shows (up to 2,000 shapes); content drawn after it stays vectors, over
|
|
1591
1833
|
it. `"opaque"` draws that content as if its alpha were 1 (one
|
|
1592
|
-
`
|
|
1834
|
+
`FlattenWarning` per output); `"error"` raises `ValueError` naming the
|
|
1593
1835
|
page and what failed. A dense translucent scatter is the expected over-budget case.
|
|
1594
1836
|
* Anti-aliasing: where a translucent shape's edge lies over another shape, its opaque draw
|
|
1595
1837
|
and the piece over that shape each cover the edge pixel in part, as viewers draw them:
|
|
@@ -1598,9 +1840,9 @@ without transparency are written as they are.
|
|
|
1598
1840
|
|
|
1599
1841
|
### EPS output
|
|
1600
1842
|
|
|
1601
|
-
`
|
|
1602
|
-
|
|
1603
|
-
|
|
1843
|
+
`write("eps", pages=…)` and `save("….eps")` of a document, page or drawing, `convert(…,
|
|
1844
|
+
format="eps")`, CLI `--format eps`: one page as an EPS file (EPSF-3.0, PostScript
|
|
1845
|
+
LanguageLevel 3).
|
|
1604
1846
|
|
|
1605
1847
|
* Header: `%%BoundingBox` and `%%HiResBoundingBox` of the page (points), `%%Creator:
|
|
1606
1848
|
vec_io`, `%%Title` (the document's), `%%LanguageLevel: 3`, `%%DocumentData: Clean7Bit`,
|
|
@@ -1608,8 +1850,8 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
|
|
|
1608
1850
|
short procedures), the setup (fonts, images, shadings, forms), the page and `showpage`.
|
|
1609
1851
|
Every byte is 7-bit ASCII and lines stay under 256 characters: binary data is ASCII85.
|
|
1610
1852
|
* Transparency is always flattened ([Transparency flattening](#transparency-flattening)),
|
|
1611
|
-
with the raster fallback by default; `
|
|
1612
|
-
|
|
1853
|
+
with the raster fallback by default; `Flatten`'s `fallback`, `dpi`, `budget` and `cell`
|
|
1854
|
+
tune it (`Flatten(transparency=False)` raises `OptionError`).
|
|
1613
1855
|
* The page is written as the PDF has it (its content streams, with the output's
|
|
1614
1856
|
`simplify`), translated by the C library (`src/epsw.c`): paths, fills (nonzero, even-odd),
|
|
1615
1857
|
strokes, dashes, caps, joins, miter limits, clips and transforms; DeviceGray, DeviceRGB
|
|
@@ -1627,16 +1869,17 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
|
|
|
1627
1869
|
through a filter (`currentfile /ASCII85Decode filter cvx exec`, and `/FlateDecode` when
|
|
1628
1870
|
compressed). Glyphs are placed by
|
|
1629
1871
|
`xshow`/`xyshow` at vec_io's positions; stroked and clipping text uses `charpath`.
|
|
1630
|
-
Variable fonts
|
|
1631
|
-
|
|
1872
|
+
Variable fonts are embedded as the static instance the PDF has (Type 42, or CFF from
|
|
1873
|
+
CFF2). Fonts that cannot be subset, and every font with `text_as_paths=True`, are drawn
|
|
1874
|
+
as glyph outlines (a procedure per glyph, filled,
|
|
1632
1875
|
stroked or clipped as the text's render mode asks; no font in the file). Standard 14
|
|
1633
1876
|
fonts that are not embedded are the interpreter's own, WinAnsi-encoded.
|
|
1634
|
-
* `
|
|
1635
|
-
programs are Flate-compressed (at
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
* Options: `simplify`, `compression`, `images` (no JPEG XL), `font_hinting` as for
|
|
1639
|
-
`
|
|
1877
|
+
* `compression` (default `"balanced"`): the page's content, the forms, glyph outlines and
|
|
1878
|
+
font programs are Flate-compressed (at its level), ASCII85, and run through a filter
|
|
1879
|
+
(`currentfile /ASCII85Decode filter /FlateDecode filter cvx exec`); `None` writes them as
|
|
1880
|
+
readable PostScript (fonts ASCII85).
|
|
1881
|
+
* Options: `simplify`, `compression`, `images` (no JPEG XL), `font_hinting` as for PDF;
|
|
1882
|
+
`text_as_paths`. PDF/A documents and `jxl` images raise `ValueError`.
|
|
1640
1883
|
* Ghostscript (`gs -dEPSCrop`) draws an EPS as it draws the flattened PDF (tests: the same
|
|
1641
1884
|
pixels for paths, colors, gradients, images, forms and patterns; text within its edge
|
|
1642
1885
|
pixels). Sizes, compressed: 1–3× the PDF on the SVG corpus (ASCII85 adds a quarter, and
|
|
@@ -1644,19 +1887,31 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
|
|
|
1644
1887
|
|
|
1645
1888
|
## 19. Errors
|
|
1646
1889
|
|
|
1890
|
+
Every error vec_io raises for what it cannot read, write or use derives from
|
|
1891
|
+
`vec_io.VecIOError`, every warning from `vec_io.VecIOWarning` (a `UserWarning`); all are
|
|
1892
|
+
exported by `vec_io`.
|
|
1893
|
+
|
|
1647
1894
|
| Exception | Raised for |
|
|
1648
1895
|
|---|---|
|
|
1649
|
-
| `
|
|
1650
|
-
| `
|
|
1651
|
-
| `
|
|
1652
|
-
| `
|
|
1653
|
-
| `
|
|
1654
|
-
| `
|
|
1655
|
-
| `
|
|
1656
|
-
| `
|
|
1657
|
-
| `
|
|
1896
|
+
| `OptionError` (`ValueError`) | An option that cannot be used: unknown, of another output, a value out of range (an unknown format, a size, margin or flatten setting, `aspect` or `align` without both sides). |
|
|
1897
|
+
| `SVGParseError` (`ValueError`) | Input that is not a usable SVG document. |
|
|
1898
|
+
| `PDFReadError` (`ValueError`) | A PDF that cannot be read, a wrong password, a file past a limit ([Reading PDF](#reading-pdf)). |
|
|
1899
|
+
| `FontError` (`ValueError`) | Malformed or unsupported font data: from `Document.add_font`, and when writing or rasterizing a font whose glyph data is malformed. `@font-face` fonts that cannot be read are ignored. |
|
|
1900
|
+
| `NoFontError` (`ValueError`) | Text with no outline font available at all ([Fonts](#16-fonts)). |
|
|
1901
|
+
| `FontDownloadError` (`OSError`) | `download` of a source or `google.refresh` failing ([Font downloads](#font-downloads)); while drawing, a failing family gives a `FontDownloadWarning` instead. |
|
|
1902
|
+
| `RasterizationError` (`RuntimeError`) | Content the rasterizer cannot draw (a standard 14 font with no installed font to draw it, too many dashes, unsupported shadings or JPEGs). |
|
|
1903
|
+
| `ImageError` (`ValueError`) | Malformed or unsupported image data; the codecs' `JPEGError`, `JXLError`, `AVIFError` (`vec_io.image.codecs`) are `VecIOError`s too. |
|
|
1904
|
+
| `NativeLibraryError` (`RuntimeError`) | The C library is not built for this platform or failed to load. |
|
|
1658
1905
|
| `ValueError` | Invalid arguments: mismatched per-point lengths, marker names (markers are paths), invalid colors (components outside [0, 1] included), an unknown unit, cells whose `fill` does not match their edges, palette indices outside the palette, `quality` outside 1–100, `color_mode` other than `"rgb"`/`"cmyk"`, an unknown `pdf_a` level, PDF/A requirements that cannot be met (no font for a character, a missing or mismatched `icc_profile`, a CMYK JPEG in RGB mode, two spot colors with one name and different alternates, `attach` in PDF/A-2), `ink_limit` outside (0, 400], an `icc_profile` that is not a gray, RGB or CMYK ICC profile, a `Spot` alternate without 4 components, a link or bookmark to a page of another document or an out-of-range page index, non-finite page sizes or `arc` angles. |
|
|
1659
1906
|
|
|
1907
|
+
| Warning | Given for |
|
|
1908
|
+
|---|---|
|
|
1909
|
+
| `PDFReadWarning` | Content of a PDF left out, once per kind and file ([Reading PDF](#reading-pdf)). |
|
|
1910
|
+
| `FlattenWarning` | `Flatten(fallback="opaque")`: content drawn opaque because it could not be flattened, once per output ([Transparency flattening](#transparency-flattening)). |
|
|
1911
|
+
| `FontDownloadWarning` | A family text asked for could not be downloaded; the next source or family is used. |
|
|
1912
|
+
| `NetworkWarning` | A URL a document refers to could not be fetched, once per URL and document; what refers to it is drawn as missing ([Network and other files](#network-and-other-files)). |
|
|
1913
|
+
| `ImageWarning` | WebP, AVIF or JPEG XL images without their library, once per format; drawn as missing. |
|
|
1914
|
+
|
|
1660
1915
|
## 20. Modules
|
|
1661
1916
|
|
|
1662
1917
|
| Module | Role |
|
|
@@ -1670,10 +1925,14 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
|
|
|
1670
1925
|
| `filter.py` | `Filter` and its primitives: the filter graph, run on a group's pixels |
|
|
1671
1926
|
| `geometry.py` | `Matrix`, the packed `Path`, path data, arcs |
|
|
1672
1927
|
| `lines.py`, `shapes.py`, `cells.py` | lines, segments and areas; rectangles and polygons; cells |
|
|
1673
|
-
| `text/` | shaping, measuring and layout from a font database (`Font`, `GlyphRun`, `Span`, `shape`, `measure`, `layout`); `text/breaking.py`: line breaking of paragraphs; `text/path.py`: glyphs along a path |
|
|
1928
|
+
| `text/` | shaping, measuring and layout from a font database (`Font`, `GlyphRun`, `Span`, `shape`, `measure`, `layout`); `text/breaking.py`: line breaking of paragraphs; `text/path.py`: glyphs along a path; `text/shaping.py`: features, scripts, the built-in shaper; `text/bidi.py`: the bidi algorithm; `text/harfbuzz.py`: HarfBuzz through ctypes |
|
|
1674
1929
|
| `fonts/` | standard and embedded fonts; `fontdb` (discovery and matching), `download` (font downloads: switch, cache, network), `google`, `urw`, `ctan`, `fontsource`, `fontshare` (the download sources), `sfnt`, `cff`, `cff2`, `variations`, `opentype`, `woff2` |
|
|
1675
|
-
| `
|
|
1676
|
-
| `
|
|
1930
|
+
| `convert.py` | `convert`, and the options of each output kind (`output_kind`, `output_settings`, `write_pages`) |
|
|
1931
|
+
| `options.py` | the option objects (`Fonts`, `Flatten`, `View`, `ImagePolicy`, `PNG`, `JPEG`, `JXL`, `AVIF`) and `OptionError` |
|
|
1932
|
+
| `errors.py` | `VecIOError`, `VecIOWarning` |
|
|
1933
|
+
| `svg/` | SVG reading and writing: `parse` (XML, CSS cascade, `SVGDocument`), `css`, `render` (SVG semantics drawn through a `Canvas`), `filters` (`<filter>` as a `Filter`), `writer` (SVG output of scenes, written by the C library) |
|
|
1934
|
+
| `image/` | `Image`; `codecs`, `jxl`, `avif`, `webp`, `gif`, `bmp` (BMP and ICO), `resource` (decoding, loading, `ImageResource`) |
|
|
1935
|
+
| `network.py` | fetching http(s) URLs: a document's `Fetcher` and its limits, the font downloads' requests |
|
|
1677
1936
|
| `pdf/` | `objects` (PDF values, numbered when written), `writer`, `images` (image XObjects), `pdfa` |
|
|
1678
1937
|
| `eps/` | EPS output: header, prolog and resources (`__init__`; the content written by the C library), fonts as Type 42, CFF or glyph outlines (`fonts`) |
|
|
1679
1938
|
| `pdfread/` | reading PDF: `file` (cross-reference, objects, filters, encryption), `content` (the interpreter), `resources`, `colors`, `functions`, `shadings`, `images`, `fonts`, `reader` (pages, annotations, links, outlines) |
|