vec-io 0.2.0__tar.gz → 0.3.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.

Files changed (339) hide show
  1. {vec_io-0.2.0 → vec_io-0.3.0}/API.md +343 -172
  2. {vec_io-0.2.0 → vec_io-0.3.0}/EXAMPLES.md +52 -16
  3. {vec_io-0.2.0 → vec_io-0.3.0}/PKG-INFO +14 -9
  4. {vec_io-0.2.0 → vec_io-0.3.0}/README.md +13 -8
  5. {vec_io-0.2.0 → vec_io-0.3.0}/examples/canvas_demo.py +2 -2
  6. {vec_io-0.2.0 → vec_io-0.3.0}/tests/fuzz_native.py +400 -28
  7. {vec_io-0.2.0 → vec_io-0.3.0}/tests/fuzz_pdfread.py +2 -2
  8. {vec_io-0.2.0 → vec_io-0.3.0}/tests/helpers.py +6 -6
  9. {vec_io-0.2.0 → vec_io-0.3.0}/tests/svg_oracle.py +48 -54
  10. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_api.py +48 -51
  11. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_canvas_features.py +6 -7
  12. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_cells.py +4 -4
  13. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_cmyk.py +5 -5
  14. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_compile.py +15 -15
  15. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_convert.py +57 -5
  16. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_deflate.py +1 -1
  17. vec_io-0.3.0/tests/test_document_write.py +360 -0
  18. vec_io-0.3.0/tests/test_dpi.py +205 -0
  19. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_eps.py +42 -42
  20. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_features.py +10 -10
  21. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_filters.py +4 -4
  22. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_flatten.py +39 -24
  23. vec_io-0.3.0/tests/test_font_fixes.py +159 -0
  24. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_font_sources.py +2 -3
  25. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_fonts_io.py +18 -17
  26. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_google_fonts.py +12 -12
  27. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_jxl.py +3 -3
  28. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_marker_runs.py +1 -1
  29. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_native.py +1 -1
  30. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_native_emit.py +1 -1
  31. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_native_jpeg.py +4 -4
  32. vec_io-0.3.0/tests/test_native_limits.py +357 -0
  33. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_native_png.py +2 -2
  34. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_output.py +45 -45
  35. vec_io-0.3.0/tests/test_output_fixes.py +314 -0
  36. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_pdf_security.py +1 -1
  37. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_pdfa.py +5 -5
  38. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_pdfread.py +16 -16
  39. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_raster.py +51 -43
  40. vec_io-0.3.0/tests/test_reader_fixes.py +237 -0
  41. vec_io-0.3.0/tests/test_resize.py +230 -0
  42. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_scene.py +10 -10
  43. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_shapes.py +7 -7
  44. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_simplify.py +62 -28
  45. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_svg_semantics.py +3 -5
  46. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_svg_writer.py +46 -10
  47. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_text.py +3 -3
  48. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_text_as_paths.py +3 -4
  49. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_textlayout.py +10 -10
  50. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_threads.py +9 -10
  51. vec_io-0.3.0/tests/test_trim.py +225 -0
  52. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_type1.py +3 -3
  53. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_units.py +26 -9
  54. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_varfonts.py +2 -2
  55. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_woff2.py +1 -1
  56. {vec_io-0.2.0 → vec_io-0.3.0}/tools/gen_api.py +36 -10
  57. vec_io-0.3.0/vec_io/__init__.py +54 -0
  58. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/__main__.py +127 -52
  59. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/canvas.py +351 -347
  60. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/cells.py +21 -21
  61. vec_io-0.3.0/vec_io/convert.py +232 -0
  62. vec_io-0.3.0/vec_io/document.py +1181 -0
  63. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/draw.py +47 -102
  64. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/eps/__init__.py +29 -56
  65. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/eps/fonts.py +12 -20
  66. vec_io-0.3.0/vec_io/errors.py +11 -0
  67. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/flatten.py +98 -111
  68. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/__init__.py +14 -5
  69. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/cff.py +146 -56
  70. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/cff2.py +15 -95
  71. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/download.py +181 -147
  72. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/fontdb.py +65 -39
  73. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/google.py +46 -65
  74. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/sfnt.py +223 -148
  75. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/type1.py +22 -138
  76. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/variations.py +4 -85
  77. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/geometry.py +0 -4
  78. vec_io-0.3.0/vec_io/image/__init__.py +131 -0
  79. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/image/avif.py +2 -1
  80. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/image/codecs.py +6 -13
  81. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/image/jbig2.py +2 -1
  82. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/image/jpx.py +2 -1
  83. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/image/jxl.py +2 -1
  84. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/image/resource.py +23 -11
  85. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/lines.py +19 -19
  86. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/README.md +36 -14
  87. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/__init__.py +2 -1
  88. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/_api.py +23 -6
  89. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/bin/linux-aarch64.so +0 -0
  90. vec_io-0.3.0/vec_io/native/bin/linux-x86_64.so +0 -0
  91. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/bin/macos-arm64.dylib +0 -0
  92. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/bin/windows-arm64.dll +0 -0
  93. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/bin/windows-x86_64.dll +0 -0
  94. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/deflate.py +1 -1
  95. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/emit.py +34 -17
  96. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/jpeg.py +5 -4
  97. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/manifest.json +12 -12
  98. vec_io-0.3.0/vec_io/native/pdfread.py +166 -0
  99. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/png.py +7 -7
  100. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/alloc.c +1 -3
  101. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/ccitt.c +19 -5
  102. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/cull.c +6 -6
  103. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/emit.c +21 -2
  104. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/epsw.c +31 -137
  105. vec_io-0.3.0/vec_io/native/src/image.c +324 -0
  106. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/interp.c +224 -483
  107. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/items.c +30 -30
  108. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/jpx.c +3 -5
  109. vec_io-0.3.0/vec_io/native/src/lex.h +182 -0
  110. vec_io-0.3.0/vec_io/native/src/matrix.h +33 -0
  111. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/paint.c +4 -4
  112. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/path.c +0 -7
  113. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/pdfread.c +52 -172
  114. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/pio.h +8 -1
  115. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/pio_api.h +20 -7
  116. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/png.c +11 -6
  117. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/raster.h +7 -33
  118. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/res.c +7 -3
  119. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/scene.c +162 -314
  120. vec_io-0.3.0/vec_io/native/src/scene.h +716 -0
  121. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/shade.c +3 -1
  122. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/signatures.c +5 -16
  123. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/stroke.c +21 -5
  124. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/svgw.c +320 -414
  125. vec_io-0.3.0/vec_io/options.py +362 -0
  126. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/paint.py +51 -25
  127. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdf/images.py +6 -6
  128. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdf/objects.py +6 -3
  129. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdf/writer.py +3 -3
  130. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/__init__.py +13 -13
  131. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/ccitt.py +2 -1
  132. vec_io-0.3.0/vec_io/pdfread/cffinfo.py +116 -0
  133. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/cmap.py +2 -1
  134. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/colors.py +4 -4
  135. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/content.py +44 -54
  136. vec_io-0.3.0/vec_io/pdfread/convert.py +42 -0
  137. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/errors.py +3 -2
  138. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/file.py +14 -22
  139. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/fonts.py +77 -219
  140. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/functions.py +18 -11
  141. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/images.py +10 -32
  142. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/meshes.py +1 -1
  143. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/parser.py +2 -1
  144. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/reader.py +20 -36
  145. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/resources.py +25 -39
  146. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/security.py +5 -22
  147. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/shadings.py +11 -23
  148. vec_io-0.3.0/vec_io/pdfread/strings.py +44 -0
  149. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/raster/__init__.py +29 -15
  150. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/raster/groups.py +10 -8
  151. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/raster/resources.py +5 -4
  152. vec_io-0.3.0/vec_io/resample.py +238 -0
  153. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/scene.py +61 -3
  154. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/shapes.py +14 -14
  155. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/simplify.py +75 -47
  156. vec_io-0.3.0/vec_io/svg/__init__.py +7 -0
  157. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/svg/filters.py +3 -36
  158. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/svg/parse.py +16 -54
  159. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/svg/render.py +152 -145
  160. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/svg/writer.py +111 -72
  161. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/text/__init__.py +72 -77
  162. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/text/breaking.py +4 -5
  163. vec_io-0.3.0/vec_io/trim.py +151 -0
  164. vec_io-0.3.0/vec_io/units.py +184 -0
  165. vec_io-0.2.0/vec_io/__init__.py +0 -40
  166. vec_io-0.2.0/vec_io/document.py +0 -889
  167. vec_io-0.2.0/vec_io/image/__init__.py +0 -232
  168. vec_io-0.2.0/vec_io/native/bin/linux-x86_64.so +0 -0
  169. vec_io-0.2.0/vec_io/native/pdfread.py +0 -75
  170. vec_io-0.2.0/vec_io/native/src/image.c +0 -150
  171. vec_io-0.2.0/vec_io/native/src/scene.h +0 -228
  172. vec_io-0.2.0/vec_io/pdfread/_native.py +0 -95
  173. vec_io-0.2.0/vec_io/pdfread/cffinfo.py +0 -177
  174. vec_io-0.2.0/vec_io/pdfread/convert.py +0 -57
  175. vec_io-0.2.0/vec_io/svg/__init__.py +0 -167
  176. vec_io-0.2.0/vec_io/units.py +0 -105
  177. {vec_io-0.2.0 → vec_io-0.3.0}/LICENSE +0 -0
  178. {vec_io-0.2.0 → vec_io-0.3.0}/examples/bubble_chart.py +0 -0
  179. {vec_io-0.2.0 → vec_io-0.3.0}/examples/drawing_demo.py +0 -0
  180. {vec_io-0.2.0 → vec_io-0.3.0}/examples/heatmap.py +0 -0
  181. {vec_io-0.2.0 → vec_io-0.3.0}/examples/scatter_plot.py +0 -0
  182. {vec_io-0.2.0 → vec_io-0.3.0}/examples/showcase.svg +0 -0
  183. {vec_io-0.2.0 → vec_io-0.3.0}/examples/text.svg +0 -0
  184. {vec_io-0.2.0 → vec_io-0.3.0}/examples/text_layout.py +0 -0
  185. {vec_io-0.2.0 → vec_io-0.3.0}/pyproject.toml +0 -0
  186. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/abc.br +0 -0
  187. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/abc.out.z +0 -0
  188. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/big.br +0 -0
  189. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/big.out.z +0 -0
  190. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/binary.br +0 -0
  191. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/binary.out.z +0 -0
  192. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/bits2.br +0 -0
  193. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/bits2.out.z +0 -0
  194. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/dictwords.br +0 -0
  195. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/dictwords.out.z +0 -0
  196. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/empty.br +0 -0
  197. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/empty.out.z +0 -0
  198. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/four.br +0 -0
  199. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/four.out.z +0 -0
  200. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/handmade.br +0 -0
  201. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/handmade.out.z +0 -0
  202. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/ints.br +0 -0
  203. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/ints.out.z +0 -0
  204. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/mixed.br +0 -0
  205. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/mixed.out.z +0 -0
  206. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/multi.br +0 -0
  207. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/multi.out.z +0 -0
  208. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/one.br +0 -0
  209. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/one.out.z +0 -0
  210. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/random.br +0 -0
  211. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/random.out.z +0 -0
  212. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/text11.br +0 -0
  213. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/text11.out.z +0 -0
  214. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/text_q2.br +0 -0
  215. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/text_q2.out.z +0 -0
  216. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/three.br +0 -0
  217. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/three.out.z +0 -0
  218. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/w10.br +0 -0
  219. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/w10.out.z +0 -0
  220. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/w24.br +0 -0
  221. {vec_io-0.2.0 → vec_io-0.3.0}/tests/brotli/w24.out.z +0 -0
  222. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/clipping.svg +0 -0
  223. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/css.svg +0 -0
  224. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/empty.svg +0 -0
  225. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/filters.svg +0 -0
  226. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/fonts_face.svg +0 -0
  227. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/gradients.svg +0 -0
  228. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/images.svg +0 -0
  229. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/markers.svg +0 -0
  230. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/masks.svg +0 -0
  231. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/opacity.svg +0 -0
  232. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/paths.svg +0 -0
  233. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/patterns.svg +0 -0
  234. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/rasterized.svg +0 -0
  235. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/shapes.svg +0 -0
  236. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/strokes.svg +0 -0
  237. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/structure.svg +0 -0
  238. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/text-wrap.svg +0 -0
  239. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/text_basic.svg +0 -0
  240. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/text_layout.svg +0 -0
  241. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/text_path.svg +0 -0
  242. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/text_unicode.svg +0 -0
  243. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/transforms.svg +0 -0
  244. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/units.svg +0 -0
  245. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/use_symbol.svg +0 -0
  246. {vec_io-0.2.0 → vec_io-0.3.0}/tests/corpus/viewbox.svg +0 -0
  247. {vec_io-0.2.0 → vec_io-0.3.0}/tests/fonts/PioTest-Bold.ttf +0 -0
  248. {vec_io-0.2.0 → vec_io-0.3.0}/tests/fonts/PioTest-Regular.ttf +0 -0
  249. {vec_io-0.2.0 → vec_io-0.3.0}/tests/jbig2_encoder.py +0 -0
  250. {vec_io-0.2.0 → vec_io-0.3.0}/tests/jpx_fixtures.py +0 -0
  251. {vec_io-0.2.0 → vec_io-0.3.0}/tests/make_crypt_fixtures.py +0 -0
  252. {vec_io-0.2.0 → vec_io-0.3.0}/tests/maps.py +0 -0
  253. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfbuild.py +0 -0
  254. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/cmyk8.j2k +0 -0
  255. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/cmyk8.jp2 +0 -0
  256. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/gray12.j2k +0 -0
  257. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/gray16.jp2 +0 -0
  258. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/gray4-signed.j2k +0 -0
  259. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/graya16.jp2 +0 -0
  260. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/gs-r2.pdf +0 -0
  261. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/gs-r3.pdf +0 -0
  262. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/icc-gray8.jp2 +0 -0
  263. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r2.pdf +0 -0
  264. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r3.pdf +0 -0
  265. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r4-aes-nometa.pdf +0 -0
  266. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r4-aes.pdf +0 -0
  267. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r4-pdfdoc.pdf +0 -0
  268. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r4-rc4.pdf +0 -0
  269. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r5.pdf +0 -0
  270. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r6-empty.pdf +0 -0
  271. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r6-utf8.pdf +0 -0
  272. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/qpdf-r6.pdf +0 -0
  273. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/rgb8.j2k +0 -0
  274. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/rgb8.jp2 +0 -0
  275. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/rgba8.jp2 +0 -0
  276. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/ycc420.jp2 +0 -0
  277. {vec_io-0.2.0 → vec_io-0.3.0}/tests/pdfread/ycc422-offset.jp2 +0 -0
  278. {vec_io-0.2.0 → vec_io-0.3.0}/tests/scene_oracle.py +0 -0
  279. {vec_io-0.2.0 → vec_io-0.3.0}/tests/shapes.py +0 -0
  280. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_avif.py +0 -0
  281. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_ccitt.py +0 -0
  282. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_cmap.py +0 -0
  283. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_codecs.py +0 -0
  284. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_encodings.py +0 -0
  285. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_jpx_jbig2.py +0 -0
  286. {vec_io-0.2.0 → vec_io-0.3.0}/tests/test_parsing.py +0 -0
  287. {vec_io-0.2.0 → vec_io-0.3.0}/tests/testfont.py +0 -0
  288. {vec_io-0.2.0 → vec_io-0.3.0}/tests/varfonts/VarTest.otf +0 -0
  289. {vec_io-0.2.0 → vec_io-0.3.0}/tests/varfonts/VarTest.ttf +0 -0
  290. {vec_io-0.2.0 → vec_io-0.3.0}/tests/woff2/make.py +0 -0
  291. {vec_io-0.2.0 → vec_io-0.3.0}/tests/woff2/pair.woff2 +0 -0
  292. {vec_io-0.2.0 → vec_io-0.3.0}/tests/woff2/rich-null.woff2 +0 -0
  293. {vec_io-0.2.0 → vec_io-0.3.0}/tests/woff2/rich.ttf +0 -0
  294. {vec_io-0.2.0 → vec_io-0.3.0}/tests/woff2/rich.woff2 +0 -0
  295. {vec_io-0.2.0 → vec_io-0.3.0}/tools/build_native.py +0 -0
  296. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/arrays.py +0 -0
  297. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/filter.py +0 -0
  298. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/flate.py +0 -0
  299. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/ctan.py +0 -0
  300. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/encodings.py +0 -0
  301. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/fontshare.py +0 -0
  302. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/fontshare_families.txt +0 -0
  303. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/fontsource.py +0 -0
  304. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/fontsource_families.txt +0 -0
  305. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/glyphlist.txt +0 -0
  306. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/google_families.txt +0 -0
  307. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/opentype.py +0 -0
  308. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/urw.py +0 -0
  309. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/fonts/woff2.py +0 -0
  310. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/items.py +0 -0
  311. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/brotli.py +0 -0
  312. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/filters.py +0 -0
  313. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/brotli.c +0 -0
  314. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/brotli.h +0 -0
  315. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/brotli_dict.c +0 -0
  316. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/crowding.c +0 -0
  317. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/crypt.c +0 -0
  318. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/data.c +0 -0
  319. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/deflate.c +0 -0
  320. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/filters.c +0 -0
  321. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/flat.c +0 -0
  322. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/jpeg.h +0 -0
  323. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/jpeg_dec.c +0 -0
  324. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/jpeg_enc.c +0 -0
  325. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/math.c +0 -0
  326. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/mesh.c +0 -0
  327. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/quant.c +0 -0
  328. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/rt.c +0 -0
  329. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/scan.c +0 -0
  330. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/shade.h +0 -0
  331. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/src/woff2.c +0 -0
  332. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/native/woff2.py +0 -0
  333. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdf/__init__.py +0 -0
  334. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdf/pdfa.py +0 -0
  335. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/pdfread/cmap_resources.txt +0 -0
  336. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/py.typed +0 -0
  337. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/svg/css.py +0 -0
  338. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/text/path.py +0 -0
  339. {vec_io-0.2.0 → vec_io-0.3.0}/vec_io/threads.py +0 -0
@@ -33,16 +33,28 @@ 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
- `to_px(number, unit)` converts absolute units; `parse_angle(value, strict=False)` gives
37
- degrees; `parse_length` is the lenient SVG form. Tables: `PX_PER_UNIT`, `ANGLE_UNITS`.
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. Tables:
38
+ `PX_PER_UNIT`, `ANGLE_UNITS`.
39
+ * **Lengths.** A number is in the unit of its context, a string carries its unit (`"2in"`,
40
+ `"5mm"`, `"12pt"`; a paper size's side, `"a4"`, where a width or height is asked): on a
41
+ `Page`, the document's unit; in a `View` (so in `convert` and on the command line), CSS
42
+ pixels, for SVG and PDF input alike. `%` and `em` are refused where a length is not
43
+ relative to something. Every length goes through `vec_io.units.to_points`.
44
+ * **Opacity and alpha.** *Opacity* is a multiplier applied when drawing (0–1): the canvas
45
+ state `opacity`, `group(opacity=…)`, the bulk calls' `opacity`, `fill_opacity` and
46
+ `stroke_opacity` of drawings, a gradient stop's `opacity`. *Alpha* is the alpha channel of a
47
+ color or pixel: `Color(r, g, b, alpha)`, `CMYK(…, alpha)`, `Spot(…, alpha)`,
48
+ `with_alpha`, CSS `/ alpha`, `Image.alpha`.
38
49
  * **Colors.** A color is a CSS string (`"red"`, `"#rgb[a]"`, `"#rrggbb[aa]"`,
39
50
  `"transparent"`, and the CSS Color 4 functions in modern or comma syntax: `rgb[a]()`,
40
51
  `hsl[a]()`, `hwb()`, `lab()`, `lch()`, `oklab()`, `oklch()`, `color(<space> r g b)` with
41
52
  `srgb`, `srgb-linear`, `display-p3`, `a98-rgb`, `prophoto-rgb`, `rec2020`, `xyz`,
42
53
  `xyz-d50`, `xyz-d65`, and `device-cmyk(c m y k)`; each takes `/ alpha` and `none`); a
43
54
  tuple `(r, g, b)` or `(r, g, b, a)` of numbers in [0, 1]; or a print color below.
55
+ `Color(r, g, b, alpha=1)` is such a tuple, checked, with `alpha` and `with_alpha(alpha)`.
44
56
  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
57
+ `Color.rgb255(r, g, b, alpha=1)` or a CSS string. Colors outside sRGB are gamut mapped as
46
58
  CSS Color 4 specifies (chroma reduced in OKLCh).
47
59
  * **Print colors.** `CMYK(c, m, y, k, alpha=1)` is a device CMYK color, components in
48
60
  [0, 1]. `Spot(name, cmyk, tint=1, alpha=1)` is a spot ink: `cmyk` (a `CMYK` or 4-tuple)
@@ -61,7 +73,7 @@ Complete reference. Worked examples are in [EXAMPLES.md](EXAMPLES.md).
61
73
  paths, `file:` URLs on this machine), so pass `base_dir=None` for untrusted SVG. Remote
62
74
  URLs and `file:` URLs naming another host are never fetched, except fonts from the
63
75
  download sources ([Font downloads](#font-downloads)).
64
- * **Types.** The package is typed (`py.typed`). Aliases: `vec_io.Color` (a color argument),
76
+ * **Types.** The package is typed (`py.typed`). Aliases: `vec_io.ColorLike` (a color argument),
65
77
  `vec_io.Paint` (a color, gradient, pattern or `None`), `vec_io.Content` (text layout
66
78
  content). Chainable methods return the object's own type.
67
79
  * **Arrays.** Coordinates, sizes, per-item values and cell grids are sequences (`None`
@@ -70,43 +82,43 @@ Complete reference. Worked examples are in [EXAMPLES.md](EXAMPLES.md).
70
82
  * **C library.** Bulk work (writing content streams, rasterization, culling, PNG and JPEG
71
83
  coding, filters) runs in a bundled C library, prebuilt for Linux x86_64/aarch64, Windows
72
84
  x86_64/arm64 and macOS arm64. It releases the GIL. Elsewhere, features that need it
73
- raise `vec_io.native.NativeLibraryError` (build it with `tools/build_native.py` and set
85
+ raise `vec_io.NativeLibraryError` (build it with `tools/build_native.py` and set
74
86
  `VEC_IO_NATIVE_LIB`).
75
87
 
76
88
  ## 2. Converting SVG
77
89
 
78
90
  ```python
79
- convert(source, output=None, *, format=None, base_dir=None, font_db=None, font_dirs=None,
80
- system_fonts=True, font_downloads=None, filters=False, text_as_paths=False,
81
- pdf_a=None, compress=True, compression="balanced", simplify=None, images=None,
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
91
+ convert(source, output=None, *, format=None, base_dir=None, fonts=None, filters=False,
92
+ text_as_paths=False, pdf_a=None, default_dpi=None, page=None, password=None,
93
+ annotations=True, **options) -> bytes
85
94
  ```
86
95
 
87
- Converts an SVG document to PDF, EPS, PNG, JPEG, JPEG XL or AVIF, returns the bytes and writes
88
- them to `output` (a path or a binary file object) when given. It is a `Document` in CSS
89
- pixels with the SVG on its page, saved or rendered with the options below.
96
+ Converts an SVG (or PDF) document to PDF, EPS, SVG, PNG, JPEG, JPEG XL or AVIF, returns the
97
+ bytes and writes them to `output` (a path or a binary file object) when given. It is a
98
+ `Document` in CSS pixels with the SVG on its page, written by `Document.write` with
99
+ `options` ([Output options](#181-options)).
90
100
 
91
101
  | Parameter | Meaning |
92
102
  |---|---|
93
103
  | `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"`. |
104
+ | `format` | `"pdf"`, `"eps"`, `"svg"`, `"png"`, `"jpeg"`, `"jxl"` or `"avif"`; default: the extension of an `output` path (none: PDF; an unknown one: `OptionError`), else `"pdf"`. |
95
105
  | `base_dir` | Directory of relative `<image>` and `@font-face` URLs; default: a source path's directory. |
96
- | `font_db`, `font_dirs`, `system_fonts`, `font_downloads` | Fonts: a `FontDB`, or extra directories searched first, whether to use installed fonts, and whether to download families that are not installed ([Fonts](#16-fonts), [Font downloads](#font-downloads)). |
106
+ | `fonts` | A `Fonts` ([Fonts](#16-fonts)). |
97
107
  | `filters` | Apply SVG filters (rasterizes filtered elements; [Filters](#14-filters)). |
98
108
  | `text_as_paths` | Text drawn as glyph outlines, no font written ([Fonts](#16-fonts)). |
99
109
  | `pdf_a` | PDF: `"2b"`, `"2u"` or `"3b"` ([PDF/A](#pdfa)). |
100
- | `compress`, `compression`, `simplify`, `images`, `flatten_*` | PDF: the options of `Document.to_bytes` ([4](#4-document-and-page)). EPS: `compress`, `compression`, `simplify`, `images` and the `flatten_*` options but `flatten_transparency` (always on; [EPS output](#eps-output)). |
101
- | `dpi`, `simplify`, `background` | Images: resolution (96: one pixel per CSS pixel), decimation, a color under the page (`None`: transparent, white for JPEG). |
102
- | `png`, `jpeg`, `jxl`, `avif` | Images: the options of the format (`PNG(…)`, `JPEG(…)`, …; [5.9](#59-rendering-and-image-output)). |
110
+ | `default_dpi` | The document's `default_dpi`: the resolution of image output without `dpi` (default 96: one pixel per CSS pixel). |
111
+ | `page`, `password`, `annotations` | PDF input ([Reading PDF](#reading-pdf)). |
112
+ | `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
113
 
104
- `SVGDocument(source)` parses SVG once (`vec_io.svg.parse`); `SVGParseError` (a
105
- `ValueError`) reports input that is not usable SVG.
114
+ `SVGDocument(source)` parses SVG once (`vec_io.svg.parse`); `SVGParseError` reports input
115
+ that is not usable SVG, `OptionError` an option that cannot be used ([Errors](#19-errors)).
106
116
 
107
117
  ```python
108
118
  vec_io.convert("drawing.svg", "drawing.pdf")
109
119
  png = vec_io.convert(text, format="png", dpi=192, png=vec_io.PNG(quality=90))
120
+ vec_io.convert("figure.svg", "figure.pdf", view={"trim": True, "margin": "2mm"})
121
+ vec_io.convert("figure.svg", "figure.pdf", view=vec_io.View(size="us", margin="1in"))
110
122
  ```
111
123
 
112
124
  ### Reading PDF
@@ -126,7 +138,8 @@ becomes the metadata. Forms, actions other than links, JavaScript and embedded f
126
138
  not read. Illustrator files (`.ai`, Illustrator 9 and later) are PDF files and read as
127
139
  such; their private data is ignored.
128
140
 
129
- `convert` and the command line read PDF input (data starting with `%PDF-`): every page
141
+ `convert` and the command line read PDF input (data with `%PDF-` near its start, before any
142
+ `<`, not gzip): every page
130
143
  (or `page`) as PDF, page `page` (default 0) as an image; `password` and `annotations` as
131
144
  above. `Canvas.draw_pdf` places a page ([5.5](#55-images-and-svg)).
132
145
 
@@ -149,7 +162,9 @@ glyphs nested 32 deep, 50 million operators per page), an Illustrator file saved
149
162
  PDF content (save it again with "Create PDF Compatible File"), PostScript (an Illustrator
150
163
  8 or earlier `.ai` or EPS file: convert it with `ps2pdf`). `PDFReadWarning`: content left
151
164
  out (an unknown operator, a broken object, an image without its library…), once per kind
152
- and file.
165
+ and file. A stream naming an unknown crypt filter is left out with a `PDFReadWarning`; the
166
+ rest of the file is read. Text strings (document information, outline titles, link URIs)
167
+ are UTF-16 or UTF-8 with a byte order mark, else PDFDocEncoding.
153
168
 
154
169
  ```python
155
170
  doc = vec_io.open_pdf("report.pdf", pages=[0, 1])
@@ -167,10 +182,9 @@ vec_io --download-font FAMILY …
167
182
  | Argument | Meaning |
168
183
  |---|---|
169
184
  | `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` (default), `eps`, `png`, `jpeg`, `jxl` or `avif`. |
172
- | `--no-compress` | Uncompressed content streams (PDF, EPS). |
173
- | `--compression LEVEL` | `fast`, `balanced` (default) or `best`: the encoder's effort. |
185
+ | `OUTPUT` | Output file, or `-` for stdout. Default: `INPUT` with the extension of `--format` (`.pdf`, `.eps`, `.svg`, `.png`, `.jpg`, `.jxl`, `.avif`). |
186
+ | `--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`. |
187
+ | `--compression LEVEL` | `fast`, `balanced` (default) or `small`: the encoder's effort; `none`: uncompressed streams (PDF, EPS). |
174
188
  | `--font-dir DIR` | Extra font directory (repeatable). |
175
189
  | `--no-system-fonts` | Ignore installed fonts. |
176
190
  | `--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)). |
@@ -182,46 +196,69 @@ vec_io --download-font FAMILY …
182
196
  | `--jxl` | Write the PDF's images as JPEG XL ([JPEG XL](#jpeg-xl)). |
183
197
  | `--pdf-a LEVEL` | Write PDF/A: `2b`, `2u` or `3b`. |
184
198
  | `--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 EPS: what cannot be flattened becomes: `raster` (default), `opaque` or `error`. |
199
+ | `--flatten-transparency` | PDF and SVG: translucent content drawn as opaque vectors ([Transparency flattening](#transparency-flattening)); EPS always is. |
200
+ | `--flatten-fallback MODE` | PDF, EPS and SVG: what cannot be flattened becomes: `raster` (default), `opaque` or `error`. |
187
201
  | `--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
- | `--dpi N` | Image resolution (default 96). |
202
+ | `--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. |
203
+ | `--size SIZE` | Both sides: a paper size (`us`, `a4`, `a4-landscape`, …) or `"8.5in x 11in"` (`x`, `×` or `*`); not with `--width`, `--height` or `--scale`. |
204
+ | `--scale S` | The output zoomed by a factor (not with `--width`/`--height`). |
205
+ | `--aspect MODE` | With both sides only: `fit` (default: the page that size, the content fitted inside) or `stretch`. |
206
+ | `--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). |
207
+ | `--trim` | Cut to the content. Blank is transparent or white. |
208
+ | `--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. |
209
+ | `--dpi N` | The output's resolution: images rendered at it (default 96); PDF, EPS and SVG images resampled to it (default: kept as they are). |
210
+ | `--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). |
211
+ | `--dpi-threshold F` | PDF, EPS, SVG with `--dpi`: images within a factor F of `--dpi` kept (default 1.5; at least 1). |
212
+ | `--dpi-average MODE` | PDF, EPS, SVG with `--dpi`: `srgb` (default: the stored values averaged) or `linear` (light averaged) when images are shrunk. |
189
213
  | `--page N` | PDF input: the page (from 0; default every page for PDF output, the first for images). |
190
214
  | `--password P` | PDF input: the password of an encrypted file. |
191
215
  | `--no-annotations` | PDF input: page content only. |
192
216
  | `--version` | Print the version. |
193
217
 
194
- Exit status 1 on unreadable input, invalid SVG, PDF that cannot be read, malformed fonts or write errors (including
195
- a closed standard output); status 2 on invalid arguments: `--dpi` or `--simplify` not
196
- positive, `--quality` outside 1–100, an image or EPS `--format` with `--pdf-a` or `--jxl`,
197
- or an image `--format` with `--no-compress` or `--flatten-transparency`.
218
+ Exit status 1 on unreadable input, invalid SVG, PDF that cannot be read, malformed fonts,
219
+ an output that is the input file, or write errors (including a closed standard output);
220
+ status 2 on invalid arguments: `--dpi` or `--simplify` not positive, `--dpi-threshold`
221
+ below 1, `--flatten-dpi`, `--flatten-budget` or `--flatten-cell` not positive, a negative or
222
+ unreadable `--margin`, a `--width`/`--height` that is not a positive length or a known paper
223
+ size, an unreadable `--size` or one with `--width`/`--height`/`--scale`, `--scale` not
224
+ positive or with `--width`/`--height`, an unknown `--align`, `--aspect` or `--align`
225
+ without both sides, a margin that leaves no room at the size, `--quality` outside 1–100,
226
+ a `--format` that disagrees with the extension of `OUTPUT`, an image, EPS or SVG format
227
+ with `--pdf-a` or `--jxl`, or an image format with `--compression none` or
228
+ `--flatten-transparency` (SVG: `--compression none`).
229
+
230
+ The command line builds the option objects `convert` takes (`Fonts`, `View`, `Flatten`,
231
+ `ImagePolicy`, `PNG`, …): its output is `convert`'s for the same options, byte for byte.
198
232
 
199
233
  ## 4. Document and Page
200
234
 
201
235
  ```python
202
- Document(unit="pt", title=None, author=None, subject=None, keywords=None, creator=None,
203
- font_dirs=None, system_fonts=True, base_dir=None, font_db=None, filters=False,
204
- color_mode="rgb", ink_limit=None, icc_profile=None, pdf_a=None, creation_date=None,
205
- font_downloads=None, text_as_paths=False)
236
+ Document(unit="pt", *, title=None, author=None, subject=None, keywords=None, creator=None,
237
+ fonts=None, base_dir=None, filters=False, color_mode="rgb", ink_limit=None,
238
+ icc_profile=None, pdf_a=None, creation_date=None, text_as_paths=False,
239
+ default_dpi=96)
206
240
  ```
207
241
 
208
242
  A document records what is drawn on its pages: commands, the images and fonts as they were
209
243
  given, and what content asks of simplification. Outputs are made from that record when
210
- asked for, with their own options: `save`/`to_bytes` write the PDF, `Page.render` renders a
211
- page ([5.9](#59-rendering-and-image-output)). Both can be called any number of times, in
212
- any order, and drawing may go on after either; the same record written with the same
213
- options gives the same bytes.
244
+ asked for, with their own options: `write` and `save` write a file of any kind
245
+ ([Output](#18-output)), `Page.render` renders a page to an `Image`
246
+ ([5.9](#59-rendering-and-image-output)). They can be called any number of times, in any
247
+ order, and drawing may go on after any; the same record written with the same options gives
248
+ the same bytes.
214
249
 
215
250
  The constructor takes document-level choices. `unit` is the document's unit
216
251
  ([Conventions](#1-conventions)). The metadata arguments fill the PDF document information.
217
252
  `base_dir` resolves relative paths given to `draw_image`, `draw_svg`, `add_font`, `attach`
218
253
  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`. `font_db` shares a
220
- `FontDB` between documents; otherwise `font_dirs`, `system_fonts` and `font_downloads` make
221
- one ([Fonts](#16-fonts)). `text_as_paths=True` draws text as the outlines of its glyphs
222
- ([Fonts](#16-fonts)). `creation_date` (a `datetime`; naive means local time) is
254
+ text or bytes. `filters` applies to SVGs placed with `draw_svg`. `fonts` (a `Fonts`, or a
255
+ dict of its fields) says where fonts come from; `Fonts(db=…)` shares a `FontDB` between
256
+ documents ([Fonts](#16-fonts)). `text_as_paths=True` draws text as the outlines of its
257
+ glyphs ([Fonts](#16-fonts)). `creation_date` (a `datetime`; naive means local time) is
223
258
  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.
259
+ other files have no date unless one is given. `default_dpi` is the resolution of image
260
+ output when none is given (`Page.render`, `write` to an image format); PDF, EPS and SVG
261
+ output never use it.
225
262
 
226
263
  | Print parameter | Meaning |
227
264
  |---|---|
@@ -236,45 +273,79 @@ mode: only its luminosity matters, and viewers disagree on the luminosity of ink
236
273
 
237
274
  | Method | Description |
238
275
  |---|---|
239
- | `add_page(width=None, height=None, size="A4", landscape=False)` | New `Page`: `width` and `height` in the document's unit, or a named `size`. |
276
+ | `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
277
  | `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
278
  | `add_font(data_or_path, family=None, weight=None, italic=None)` | Register a font file (path or bytes) under `family` (default: its own name). |
279
+ | `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
280
  | `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
- | `to_bytes(*, compress=True, compression="balanced", simplify=None, images=None, font_hinting=False, flatten_transparency=False, flatten_fallback="raster", flatten_dpi=600, flatten_budget=256, flatten_cell=0.25)` | The PDF as `bytes` (a document without pages gets an empty A4 page), with this output's options. |
244
- | `save(file, **options)` | Write the PDF to a path or binary file object; `options` as `to_bytes`. |
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`. |
281
+ | `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. |
282
+ | `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
283
  | `pages` | The pages, in order. |
284
+ | `bookmarks` | The top-level `Bookmark`s (`title`, `page`, `y`, `parent`, `children`), also of a PDF read. |
285
+ | `font_db` | The `FontDB` text is shaped with (read-only). |
286
+ | `points_per_unit` | Points per document unit: `1` for `pt`, `0.75` for `px` (read-only). |
248
287
 
249
- | PDF option | Meaning |
250
- |---|---|
251
- | `compress` | Compressed PDF 1.5 (default); `False` writes a readable PDF 1.4 layout ([Output](#18-output)). |
252
- | `compression` | `"fast"`, `"balanced"` (default) or `"best"`: the effort of every compressed stream, of image samples and of JPEG and JPEG XL encoding. |
253
- | `simplify` | `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)). |
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.
288
+ The constructor's `unit`, `title`, `author`, `subject`, `keywords`, `creator`, `base_dir`,
289
+ `filters`, `color_mode`, `pdf_a`, `creation_date`, `text_as_paths` and `default_dpi` are
290
+ attributes of the same names. A document without pages gets an empty A4 page when written. A PDF of some of the pages
291
+ keeps the bookmarks and links of those pages (a bookmark of another page is left out, its
292
+ children kept).
266
293
 
267
294
  ```python
268
295
  doc = vec_io.Document(unit="mm")
269
296
  page = doc.add_page(size="A4") # 210 x 297, in mm
270
- doc.save("a.pdf", compression="best", simplify=True,
271
- images=vec_io.ImagePolicy(quality=85))
272
- page.render(dpi=192).save("a.png") # the same record, as an image
297
+ doc.save("a.pdf", compression="small", simplify=True, images={"quality": 85})
298
+ page.save("a.png", dpi=192) # the same record, as an image
299
+ svg = doc.write("svg", view=vec_io.View(trim=True)) # bytes
273
300
  ```
274
301
 
275
- `Page` is the `Canvas` of a page ([5](#5-canvas)) with `render` ([5.9](#59-rendering-and-image-output)),
276
- `document` and `index`. Named sizes (portrait): `A0`–`A6`, `B4`, `B5`, `Letter`, `Legal`,
277
- `Tabloid`, `Ledger`, `Executive`. `landscape=True` swaps width and height.
302
+ `Page` is the `Canvas` of a page ([5](#5-canvas)) with `render`
303
+ ([5.9](#59-rendering-and-image-output)), `write` and `save` (`Document.write`/`save` of that
304
+ page), `view`, `trim`, `resize`, `margin`, `box`, `view_scale`, `document`, `index` and
305
+ `page_width`, `page_height` (its size in points).
306
+ Named sizes (portrait): `A0`–`A6`, `B4`, `B5`, `Letter`, `Legal`, `Tabloid`, `Ledger`,
307
+ `Executive`. `landscape=True` swaps width and height.
308
+
309
+ `page.trim(margin=0) -> (width, height)` shows only what the page draws plus `margin` (a
310
+ number or numeric string in the document's unit, or a length such as `"2mm"`; not `%` or
311
+ `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).
312
+ The content is found on renders at 300 dpi, rounded outward inside the page: at most 1/300 in
313
+ is left beyond it, and nothing drawn on the page is cut. `page.box` is the part outputs show, `(x0, y0, x1, y1)` in
314
+ points from the bottom-left corner: every output (PDF, EPS, SVG, `render`) puts its top-left
315
+ corner at its origin, links and link targets included. The page keeps its coordinates:
316
+ drawing may go on after `trim`, and `width`/`height` stay the page's. A margin, or the room
317
+ a fit leaves, may show more than the page: content outside the page is clipped to it in
318
+ every output, so that room is blank. A page that draws nothing is unchanged;
319
+ `RuntimeError` inside `state()`.
320
+
321
+ ### Resizing
322
+
323
+ `page.resize(width=None, height=None, scale=None, *, size=None, aspect=None,
324
+ align=None, margin=0) -> (width, height)` shows the page, or what `trim` kept (without its
325
+ margin; each call starts from it), at another size, returned in the document's unit.
326
+ `width`/`height`: a number or numeric string in the document's unit, a length (`"85mm"`), or a paper size's side (`"a4"`,
327
+ `"letter"` or `"us"`, `"legal"`, `"tabloid"`, `"a0"`–`"a6"`, `"b4"`, `"b5"`, …;
328
+ `"a4-landscape"` swaps the sides); `size`: both sides (a paper size, `"8.5in x 11in"` with
329
+ `x`, `×` or `*`, or a pair); `scale`: a factor. One side keeps the aspect ratio. Both sides:
330
+ `aspect="fit"` (default) makes the page that size and fits the content inside its margins,
331
+ placed by `align` (`"start"`, `"center"`, `"end"`, or a pair: horizontal, vertical; start is
332
+ left and top); `aspect="stretch"` scales each axis to the size (text and circles stretched
333
+ when the ratio changes). `aspect` and `align` apply to both sides only. `margin`: blank
334
+ space inside the size, on each side. `page.margin(m)` adds blank space around what the page
335
+ shows. The whole page is zoomed
336
+ (lines, text, markers), as when a figure is scaled in a layout program; the page keeps its
337
+ coordinates and `view_scale` (read-only) gives `(sx, sy)`. What depends on resolution follows the
338
+ scale (the larger factor), so it is the same in the output as without resizing:
339
+ rasterized groups and filters, the output's `simplify` resolution, the flattening fallback,
340
+ and the placements `ImagePolicy(dpi=…)` measures. A trimmed or resized page's gradients and
341
+ patterns follow its view (a PDF page shows its content as a form whose matrix is the view).
342
+ `ValueError` for no size, `scale` or `size` with another size, a size that is not positive
343
+ or unknown, an unknown `aspect` or `align`, `aspect` or `align` without both sides, a
344
+ margin that leaves no room.
345
+
346
+ `page.view(view) -> (width, height)` applies a `View` (or a dict of its fields; numbers in
347
+ CSS pixels): `trim`, then the size or `margin`, as `write(view=…)` does for one output, but
348
+ kept on the page.
278
349
 
279
350
  ### PDF/A
280
351
 
@@ -307,10 +378,9 @@ paints nothing.
307
378
 
308
379
  ### 5.1 State
309
380
 
310
- `push()` saves the drawing attributes, the transform and the clip on a stack, `pop()`
311
- restores them; `with page.state():` does both around a body. Inside a group, mask or
312
- pattern every `push()` needs its `pop()` in the same body; an unbalanced one raises
313
- `RuntimeError`. `reset_state()` restores the defaults (not the transform).
381
+ `with page.state():` saves the drawing attributes, the transform and the clip before the
382
+ body and restores them after it. A page written while a `state()` is open, or a group, mask
383
+ or pattern closed inside one opened in it, raises `RuntimeError`.
314
384
 
315
385
  | Attribute | Default | Values |
316
386
  |---|---|---|
@@ -322,7 +392,7 @@ pattern every `push()` needs its `pop()` in the same body; an unbalanced one rai
322
392
  | `miter_limit` | `4.0` | |
323
393
  | `line_dash` | `None` | sequence of lengths |
324
394
  | `line_dash_offset` | `0.0` | |
325
- | `global_alpha` | `1.0` | multiplies every paint |
395
+ | `opacity` | `1.0` | multiplies every paint (0–1) |
326
396
  | `font_family` | `"sans-serif"` | CSS family list |
327
397
  | `font_size` | `12.0` | the document's unit |
328
398
  | `font_weight` | `"normal"` | `normal`, `bold`, `1`–`1000` |
@@ -369,7 +439,8 @@ The current path persists until `begin_path()`.
369
439
  | `fill(paint=<fill_style>, rule=None)` | Fill the path. |
370
440
  | `stroke(paint=<stroke_style>)` | Stroke the path (black when `stroke_style` is `None`). |
371
441
  | `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 `pop()`; `with page.clip(path):` clips the body only. |
442
+ | `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. |
443
+ | `clip_rect(x, y, width, height)` | Intersect the clip with a rectangle. |
373
444
  | `fill_rect(x, y, width, height, fill=<state>)`, `stroke_rect(x, y, width, height, stroke=<state>)` | Independent of the current path. |
374
445
  | `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
446
  | `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 +484,7 @@ page.draw_path("M10 10 L80 20", fill=None, stroke="black", markers=(None, None,
413
484
  `text` is a string, rich content (a list of strings and `Span` objects,
414
485
  [Text layout](#6-text-layout)) or a `GlyphRun`, drawn on one line (newlines become spaces).
415
486
  Spans without a color use the fill. One line is shaped as a paragraph is: fonts chosen per
416
- character, pairs kerned (`font_kerning`), words shaped one by one, so `measure_text(s)` is
487
+ character, pairs kerned (`font_kerning`), words shaped one by one, runs of spaces as one space, soft hyphens and U+200B not drawn, so `measure_text(s)` is
417
488
  the width of `s` laid out on one line. Fonts are embedded as needed ([Fonts](#16-fonts)).
418
489
 
419
490
  Text on a path is shaped the same way and starts at `offset` along the path (a length, or
@@ -453,16 +524,16 @@ Context managers; everything drawn in the body is affected.
453
524
  | `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. |
454
525
  | `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
526
  | `clip(path, rule=None)` | The body clipped to `path` ([5.3](#53-paths-and-painting)). |
456
- | `masked(mask)` | The body seen through a `Mask` ([7](#7-paints-and-recorded-content)): white shows it, black hides it. Drawing attributes are restored afterwards. |
527
+ | `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
528
 
458
- `mask()`, `pattern()` and `marker()` record content to be used elsewhere
529
+ `mask()` (no argument), `pattern()` and `marker()` record content to be used elsewhere
459
530
  ([7](#7-paints-and-recorded-content)).
460
531
 
461
532
  ```python
462
533
  with page.mask() as fade: # recorded, not drawn
463
534
  page.fill_rect(0, 0, 100, 50, fill=vec_io.LinearGradient(0, 0, 100, 0,
464
535
  [(0, "white"), (1, "black")]))
465
- with page.masked(fade):
536
+ with page.mask(fade):
466
537
  page.fill_rect(0, 0, 100, 50, fill="red")
467
538
  ```
468
539
 
@@ -475,11 +546,12 @@ page added later), optionally at `page_y`.
475
546
  ### 5.9 Rendering and image output
476
547
 
477
548
  ```python
478
- page.render(dpi=96, simplify=None, background=None) -> Image
549
+ page.render(dpi=None, simplify=None, background=None) -> Image
479
550
  ```
480
551
 
481
552
  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` (96: one pixel per CSS pixel).
553
+ decoded again), rasterized groups as vectors, at `dpi` (default the document's
554
+ `default_dpi`, 96: one pixel per CSS pixel).
483
555
  `background` is a color put under the page, or `None` (transparent). `simplify` decimates
484
556
  lines for this resolution; nothing is left out, since rasterizing hidden content costs less
485
557
  than finding it ([Simplification](#13-simplification)). `dpi` must be positive.
@@ -510,7 +582,7 @@ data = image.encode("jpeg", jpeg=vec_io.JPEG(quality=85))
510
582
 
511
583
  PNG: lossless by default, in the smallest layout that keeps every pixel (gray, palette of
512
584
  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, `"best"` adds a wider filter search
585
+ best; `compression="fast"` keeps the samples' layout, `"small"` adds a wider filter search
514
586
  and vec_io's Deflate. `quality` (1–100) writes a palette of at most 256 colors chosen in
515
587
  Oklab: colors covering at least 0.1% of the pixels stay exact, smooth areas are dithered,
516
588
  flat areas and edges are not, and an image that needs more colors for the quality, or that
@@ -519,7 +591,7 @@ is smaller lossless, is written lossless. On plots, `quality=90` halves the file
519
591
 
520
592
  JPEG: Robidoux's quantization tables, the quality scale calibrated so that each value looks
521
593
  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, `"best"` tries
594
+ trellis quantization, deringing of dark edges on white and sharp 4:2:0 color, `"small"` tries
523
595
  four progressive scan orders, `"fast"` quantizes plainly. Progressive files are about 5%
524
596
  smaller than baseline ones. On plots and photographs, balanced JPEGs are 9–14% smaller than
525
597
  with the specification's tables at the same quality, and 20–36% smaller at the same SSIM.
@@ -554,7 +626,7 @@ after opening brackets. A word wider than the line is split between glyphs.
554
626
  | `first_indent` | Indent of the first line of each paragraph. |
555
627
 
556
628
  The text style comes from the canvas state: `font`, `fill_style` (or `text_box`'s `fill`),
557
- `letter_spacing`, `word_spacing`, `global_alpha`; `font_kerning="none"` turns kerning off.
629
+ `letter_spacing`, `word_spacing`, `opacity`; `font_kerning="none"` turns kerning off.
558
630
  [`vec_io.text.layout`](#61-shaping-without-a-page-vec_iotext) does the same without a page.
559
631
 
560
632
  ```python
@@ -637,7 +709,7 @@ drawn on the page while it is recorded, and its body starts from the default dra
637
709
  | With | Records | Used as |
638
710
  |---|---|---|
639
711
  | `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.masked(mask):` |
712
+ | `with page.mask() as mask:` | a `Mask`: what the body draws is the luminance (white keeps, black hides) | `with page.mask(mask):` |
641
713
  | `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
714
 
643
715
  ## 8. Markers
@@ -796,9 +868,8 @@ it in its own C library).
796
868
  ## 11. Drawings: `vec_io.draw`
797
869
 
798
870
  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 SVG
800
- written from what it draws (`Drawing.to_svg`, through the scene's SVG writer,
801
- [18](#18-output)).
871
+ page of its own document (`Drawing.document`), any page or canvas (`Drawing.draw`), or a
872
+ file of any output kind (`Drawing.write`, `Drawing.save`, [18](#18-output)).
802
873
 
803
874
  ```python
804
875
  import vec_io.draw as draw
@@ -845,10 +916,9 @@ centered).
845
916
  | `append(*elements)`, `extend(elements)`, `group(**keywords)` | Children; `group` is a context manager appending and yielding a `Group` (also on `Group`). |
846
917
  | `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
918
  | `document(**options)` | A new `Document` in the drawing's unit with one page holding the drawing; `options`: of the `Document`. |
848
- | `render(dpi=96, simplify=None, background=None, **options)` | The drawing as an `Image` ([5.9](#59-rendering-and-image-output)). |
849
- | `to_svg(*, flatten_transparency=False, …, **options)` | SVG source of what the drawing draws; the `flatten_*` options as `Document.to_bytes`. |
850
- | `to_eps(*, simplify=None, …, **options)` | The drawing as EPS; the options of `Document.to_eps`, and of the `Document`. |
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). |
919
+ | `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)). |
920
+ | `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)). |
921
+ | `save(file, *, format=None, **options)` | `write` to a path (the format from its extension) or a binary file object. |
852
922
 
853
923
  ### 11.3 Elements
854
924
 
@@ -955,7 +1025,7 @@ an SMask. The first frame of an animation is used. Lossy images are decoded
955
1025
  to sRGB; lossless ones keep their color space, written as `ICCBased` when it
956
1026
  is not sRGB.
957
1027
 
958
- **Writing.** With `ImagePolicy(jxl=True)` (`save`/`to_bytes`, `convert`, `--jxl`) every image is written as JPEG XL, as PDFium's JPEG XL support reads it: the
1028
+ **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
1029
  JPEG XL file as the stream, `/Filter /JXLDecode`, `/ColorSpace /DeviceGray`
960
1030
  or `/DeviceRGB` (`ICCBased` for other color spaces), `/BitsPerComponent 8`,
961
1031
  alpha inside the JPEG XL rather than in an SMask:
@@ -969,7 +1039,7 @@ ISO 32000 has no JPEG XL filter yet; `/JXLDecode` is the name PDFium's
969
1039
  implementation uses, and viewers without it show nothing for these images.
970
1040
  `jxl` cannot be combined with `pdf_a` or `color_mode="cmyk"`, and raises
971
1041
  `ValueError` when the PDF is written without libjxl. The encoder effort follows `compression`: 5
972
- (`fast`), 7 (`balanced`) or 9 (`best`).
1042
+ (`fast`), 7 (`balanced`) or 9 (`small`).
973
1043
 
974
1044
  JPEG XL pays off most on photographs and flat graphics: a recompressed
975
1045
  JPEG file is about 25% smaller, and a 960 × 450 heatmap is 51 KB lossless
@@ -994,7 +1064,7 @@ layout as missing.
994
1064
  Images are 8-bit sRGB. Without `quality` they are lossless (4:4:4, identity
995
1065
  matrix); with it, lossy (BT.601, 4:4:4 from quality 90, 4:2:0 below).
996
1066
  Alpha is always lossless. Encoder speed follows `compression`: 8 (`fast`),
997
- 6 (`balanced`) or 4 (`best`). AVIF suits lossy output: a 960 × 450 heatmap
1067
+ 6 (`balanced`) or 4 (`small`). AVIF suits lossy output: a 960 × 450 heatmap
998
1068
  is 26 KB at quality 90 and 12 KB at 70, but 115 KB lossless, more than its
999
1069
  81 KB PNG.
1000
1070
 
@@ -1021,8 +1091,9 @@ clipping, transparency groups and soft masks are supported, and every platform
1021
1091
  computes identical pixels.
1022
1092
  As in PDF viewers, strokes are at least one device pixel wide; images are
1023
1093
  smoothed unless `smooth=False` (`/Interpolate false`) or magnified 4 times or
1024
- more, and minified images are averaged. A dash pattern with more than
1025
- 5,000,000 visible dashes in one subpath raises `RasterizationError`.
1094
+ more, and minified images are averaged. A stroke whose visible dashes make more
1095
+ than 2^24 (16,777,216) outline points, all its subpaths together, raises
1096
+ `RasterizationError`.
1026
1097
 
1027
1098
  The scene is compiled once into a display list: shapes scan converted, plain
1028
1099
  forms (markers) rendered once per 1/32-pixel phase, gradients, patterns and
@@ -1040,7 +1111,7 @@ Text is drawn from the outlines of its fonts (TrueType or CFF), the ones the PDF
1040
1111
  embeds (scenes hold glyph ids; their codes in each subset are written with the PDF),
1041
1112
  wherever it is: groups, masks, patterns, markers, clipping paths, images. A
1042
1113
  standard 14 font (`embed=False`) is drawn with the outlines of the installed font its name
1043
- resolves to as a family (metric aliases first, [Fonts](#16-fonts)) at the standard advance
1114
+ 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
1115
  widths; with no installed font at all that raises `RasterizationError`.
1045
1116
 
1046
1117
  Marker timings, 100,000 points on a 400 × 300 pt area:
@@ -1084,7 +1155,7 @@ decimates. The same page can be written with different settings.
1084
1155
 
1085
1156
  | API | Scope |
1086
1157
  |---|---|
1087
- | `Document.save(…, simplify=…)`, `to_bytes(simplify=…)` | every page, group, mask and pattern |
1158
+ | `Document.write(…, simplify=…)`, `save(…, simplify=…)` | every page, group, mask and pattern |
1088
1159
  | `Page.render(…, simplify=…)` | decimation of the page's lines |
1089
1160
  | `draw_markers`, `draw_segments`, `draw_lines`, `fill_between`, `draw_rects`, `fill_polygons` (`simplify=`) | the call |
1090
1161
  | `Canvas.group(simplify=…)` | the body, across calls |
@@ -1110,7 +1181,8 @@ decimates. The same page can be written with different settings.
1110
1181
  deleted when hidden but hides nothing; images, shadings and groups hide
1111
1182
  nothing either. Under a soft mask, a scope opened by a call or an inline
1112
1183
  group does nothing.
1113
- * SVG output ([18](#18-output)) writes content whole.
1184
+ * EPS and SVG output ([18](#18-output)) are simplified as the PDF is, with the same
1185
+ setting.
1114
1186
 
1115
1187
  What changes: in a renderer that composites shapes one by one with partial
1116
1188
  coverage (vec_io and PDF viewers), the deleted content changes no pixel by
@@ -1127,9 +1199,9 @@ At other resolutions the same holds up to slivers smaller than a pixel.
1127
1199
  | Scene | PDF | Time | Max change | Pixels changed ≥ 1 / ≥ 8 levels |
1128
1200
  |---|---|---|---|---|
1129
1201
  | Gaussian 60k, sizes 1–4, 3 colors, opaque | 790 → 188 KB | 0.10 → 0.16 s | 47 | 0.013 / 0.003 % |
1130
- | same, alpha 0.5 | 802 → 586 KB | 0.09 → 0.26 s | 1 | 0.37 / 0 % |
1202
+ | same, opacity 0.5 | 802 → 586 KB | 0.09 → 0.26 s | 1 | 0.37 / 0 % |
1131
1203
  | Binned 60k (duplicates), one color, opaque | 119 → 4 KB | 0.29 → 0.34 s | 212 | 1.0 / 0.94 % |
1132
- | Binned 60k, 3 colors, alpha 0.3 | 159 → 56 KB | 0.32 → 0.42 s | 114 | 1.3 / 0.12 % |
1204
+ | Binned 60k, 3 colors, opacity 0.3 | 159 → 56 KB | 0.32 → 0.42 s | 114 | 1.3 / 0.12 % |
1133
1205
  | Gaussian 60k, one color, white outline | 437 → 84 KB | 0.05 → 0.10 s | 1 | 0 / 0 % |
1134
1206
  | Segments 40k, one color | 528 → 313 KB | 0.08 → 0.12 s | 0 | 0 / 0 % |
1135
1207
  | Segments 40k, 3 colors | 582 → 365 KB | 0.08 → 0.13 s | 1 | 0.003 / 0 % |
@@ -1182,12 +1254,12 @@ calibrated to, cull exactly where culling saves at least 30 % of the bytes
1182
1254
  | Scene | PDF | Estimate | `"auto"` |
1183
1255
  |---|---|---|---|
1184
1256
  | Gaussian 60k, sizes 1–4, 3 colors, opaque | 790 → 188 KB (−76 %) | 0.79 | culls |
1185
- | same, alpha 0.5 | 802 → 586 KB (−27 %) | 0.14 | keeps |
1257
+ | same, opacity 0.5 | 802 → 586 KB (−27 %) | 0.14 | keeps |
1186
1258
  | Binned 60k (duplicates), one color, opaque | 119 → 4 KB (−97 %) | 0.99 | culls |
1187
- | Binned 60k, 3 colors, alpha 0.3 | 159 → 56 KB (−65 %) | 0.89 | culls |
1259
+ | Binned 60k, 3 colors, opacity 0.3 | 159 → 56 KB (−65 %) | 0.89 | culls |
1188
1260
  | Gaussian 60k, one color, white outline | 437 → 84 KB (−81 %) | 0.84 | culls |
1189
1261
  | Uniform 2k, one color, opaque | 17 → 16 KB (−1 %) | 0.00 | keeps |
1190
- | Uniform 200k, one color, alpha 0.3 | 1,490 → 1,432 KB (−4 %) | 0.00 | keeps |
1262
+ | Uniform 200k, one color, opacity 0.3 | 1,490 → 1,432 KB (−4 %) | 0.00 | keeps |
1191
1263
  | Binned 1M, one color, opaque | 1,957 → 6 KB (−100 %) | 1.00 | culls |
1192
1264
 
1193
1265
  On a million markers that it does not cull, `"auto"` adds 2 ms.
@@ -1256,28 +1328,29 @@ elements are transparent; `kernelUnitLength` is ignored) and drawn through
1256
1328
  | Area | Support |
1257
1329
  |---|---|
1258
1330
  | 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`; a zero-size `viewBox` disables rendering; at most 300,000 elements are instantiated through `<use>` per document (further instances are skipped) |
1331
+ | Structure | `g`, nested `svg`, `use`, `symbol`, `defs`, `a`, `switch`, `viewBox`, `preserveAspectRatio`, `transform`; a zero-size `viewBox` disables rendering; at most 300,000 elements are instantiated through `<use>` per document (further instances are skipped); references are within the document: an `href` or `url()` into another file (`other.svg#a`) is missing |
1260
1332
  | Styling | presentation attributes, `style`, `<style>` (type, class, id, attribute selectors; descendant, child, sibling combinators; `:first-child`, `:not()` (selector lists); specificity; `!important`), `font` and `marker` shorthands, inheritance, `inherit`, `currentColor` |
1261
1333
  | CSS | `@media` evaluated for print; `<style media="…">`; `@font-face`; `@import` of Google Fonts CSS ([Font downloads](#font-downloads)) |
1262
- | 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` |
1334
+ | 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) |
1263
1335
  | 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) |
1336
+ | Compositing | group opacity, `clipPath` (any shapes and text, `objectBoundingBox`, nested), luminance `mask`; a `clip-path` or `mask` naming a missing element, or an element of another kind, applies none |
1337
+ | 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` |
1338
+ | 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); `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
1339
  | Images | PNG (all color types and depths, interlacing, transparency), JPEG (embedded unchanged), [JPEG XL](#jpeg-xl) (with libjxl), SVG; `data:` URIs or local files; `image-rendering: pixelated`/`crisp-edges` |
1268
1340
  | Filters | see [Filters](#14-filters) |
1269
1341
  | vec_io attributes | `data-rasterize`, `data-simplify`, `data-quality`, `data-filters` |
1270
1342
  | Input | UTF-8 or declared encodings, SVGZ, common HTML entities |
1271
1343
 
1272
1344
  Document size: `width`/`height` in any CSS unit, else `viewBox`, else
1273
- 300 × 150. `rem` refers to the font size of the root `<svg>`.
1345
+ 300 × 150. `em`, `ex` and `rem` on the root `<svg>` refer to its own font size; elsewhere
1346
+ `rem` refers to the root's font size.
1274
1347
 
1275
1348
  ## 16. Fonts
1276
1349
 
1277
1350
  Fonts are embedded as subsets, always. For each character, the font is the first of:
1278
1351
 
1279
1352
  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 (`font_dirs`, then `VEC_IO_FONT_DIRS`, then the
1353
+ `Document.add_font`, or an installed font (`Fonts.dirs`, then `VEC_IO_FONT_DIRS`, then the
1281
1354
  system directories), weight, width and style matched as in CSS Fonts 4 (missing bold
1282
1355
  and italic faces are synthesized). A family that is not installed resolves to its
1283
1356
  first installed metric alias: Helvetica and Arial to Liberation Sans, Arimo, Nimbus
@@ -1304,9 +1377,9 @@ WinAnsi (Symbol and ZapfDingbats theirs) with the Adobe metrics, and is not kern
1304
1377
  characters take steps 1–4. SVG text is always embedded.
1305
1378
 
1306
1379
  Text needs an outline font. With none available at all (no installed font, or
1307
- `system_fonts=False` without `font_dirs`, `VEC_IO_FONT_DIRS`, `@font-face` or `add_font`,
1380
+ `Fonts(system=False)` without `dirs`, `VEC_IO_FONT_DIRS`, `@font-face` or `add_font`,
1308
1381
  and font downloads off or failing), drawing or measuring text raises `NoFontError`
1309
- (`vec_io.fonts.fontdb`, a `ValueError`) naming these remedies; documents without text need
1382
+ (a `ValueError`) naming these remedies; documents without text need
1310
1383
  no font. A silent fallback to the standard 14
1311
1384
  fonts would make the PDF depend on the viewer's fonts, differ from vec_io's own images,
1312
1385
  and fail anyway in image output and PDF/A, which need outlines.
@@ -1383,12 +1456,13 @@ Downloads are on by default:
1383
1456
 
1384
1457
  | Setting | Effect |
1385
1458
  |---|---|
1386
- | `font_downloads=None` (default) | `VEC_IO_FONT_DOWNLOADS`: `1`/`on` (default), `0`/`off`, or `cache` |
1387
- | `font_downloads=True` / `False` | Downloads on / off. |
1388
- | `font_downloads="cache"` | Families already downloaded only; no network. |
1459
+ | `Fonts(downloads=None)` (default) | `VEC_IO_FONT_DOWNLOADS`: `1`/`on` (default), `0`/`off`, or `cache` |
1460
+ | `Fonts(downloads=True)` / `False` | Downloads on / off. |
1461
+ | `Fonts(downloads="cache")` | Families already downloaded only; no network. |
1389
1462
 
1390
- `FontDB`, `Document` (for the `FontDB` it makes) and `convert` take `font_downloads`; the
1391
- CLI has `--font-downloads MODE`, `--no-font-downloads` and `--download-font FAMILY`.
1463
+ `Document(fonts=…)` and `convert(fonts=…)` take a `Fonts`; `FontDB` takes
1464
+ `font_downloads` itself. The CLI has `--font-downloads MODE`, `--no-font-downloads` and
1465
+ `--download-font FAMILY`.
1392
1466
 
1393
1467
  * **Names.** A family is fetched by its own name only, from the first source that lists
1394
1468
  it (Google first, so `Anton` comes from Google, not Fontshare); when that download fails,
@@ -1457,11 +1531,11 @@ again (the styles it has), replacing the cached version.
1457
1531
 
1458
1532
  ### Installed fonts
1459
1533
 
1460
- For machine-independent output, pass `system_fonts=False` and `font_downloads=False` and
1461
- provide fonts with `font_dirs`, `@font-face` or `add_font` (a copied cache folder of a
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 `system_fonts=False`; the
1464
- tests point it at their own font.
1534
+ For machine-independent output, pass `fonts=Fonts(dirs=…, system=False, downloads=False)`
1535
+ and provide fonts with those directories, `@font-face` or `add_font` (a copied cache folder
1536
+ of a downloaded family is a font directory). `VEC_IO_FONT_DIRS` (directories separated by
1537
+ `os.pathsep`) adds font directories to every `FontDB`, also with `system=False`; the tests
1538
+ point it at their own font.
1465
1539
 
1466
1540
  Font directories are scanned once per process. The name, weight and style of
1467
1541
  every font file are kept in a persistent index (`fonts.json` in
@@ -1501,24 +1575,96 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
1501
1575
 
1502
1576
  ## 18. Output
1503
1577
 
1578
+ Every output is written by `Document.write(kind, *, pages=None, **options)` (and
1579
+ `Document.save`, `Page.write`/`save`, `Drawing.write`/`save`, `convert`, the command line):
1580
+ one way to give each option, one set of options per kind.
1581
+
1582
+ ### 18.1 Options
1583
+
1584
+ | Option | Outputs | Meaning |
1585
+ |---|---|---|
1586
+ | `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). |
1587
+ | `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. |
1588
+ | `images` | PDF, EPS, SVG | An `ImagePolicy`: how images are stored (below; [Image encoding](#image-encoding)). |
1589
+ | `flatten` | PDF, EPS, SVG | A `Flatten`: translucent content drawn as opaque vectors ([Transparency flattening](#transparency-flattening)). |
1590
+ | `font_hinting` | PDF, EPS | Keep the TrueType hinting in embedded subsets (default: left out). |
1591
+ | `text_as_paths` | EPS | Every font drawn as glyph outlines. |
1592
+ | `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. |
1593
+ | `view` | all | A `View`: what each page shows and at what size, for this output only (the pages keep their own view). |
1594
+ | `background` | images | A color under the page; `None`: transparent (white for JPEG). |
1595
+ | `png`, `jpeg`, `jxl`, `avif` | that image format | The format's options: `PNG`, `JPEG`, `JXL`, `AVIF` ([5.9](#59-rendering-and-image-output)). |
1596
+
1597
+ An unknown option, an option of another output (`"compression applies to PDF and EPS
1598
+ output"`) or a value that cannot be used raises `OptionError`.
1599
+
1600
+ The options that group settings are objects of `vec_io.options` (also exported by
1601
+ `vec_io`): frozen dataclasses, checked when made (`OptionError`), with `replace(**changes)`.
1602
+ A dict of an object's fields is accepted wherever the object is (`flatten={"dpi": 300}`).
1603
+
1604
+ | Object | Fields |
1605
+ |---|---|
1606
+ | `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=…)`. |
1607
+ | `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. |
1608
+ | `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. |
1609
+ | `ImagePolicy(…)` | Below. |
1610
+ | `PNG`, `JPEG`, `JXL`, `AVIF` | Image formats ([5.9](#59-rendering-and-image-output)). |
1611
+
1612
+ ```python
1613
+ ImagePolicy(quality=None, jxl=False, dpi=None, dpi_mode="down", dpi_threshold=1.5,
1614
+ dpi_average="srgb")
1615
+ ```
1616
+
1617
+ `quality` (1–100): rasterized content (rasterized groups, filtered elements) is stored lossy
1618
+ at this quality, as JPEG, or as JPEG XL with `jxl`; `None`: lossless. A group's own
1619
+ `quality` overrides it. `jxl`: write images as JPEG XL ([JPEG XL](#jpeg-xl)). Other images
1620
+ keep their encoding.
1621
+
1622
+ `dpi`: the resolution of the output's images (PDF, EPS, SVG), in pixels per inch where they
1623
+ are placed; `None` (default): images as they are. Each image is measured at its largest
1624
+ placement (each axis; forms, markers, patterns and masks included):
1625
+
1626
+ | Setting | Meaning |
1627
+ |---|---|
1628
+ | `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). |
1629
+ | `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. |
1630
+ | `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). |
1631
+
1632
+ An image off its range on one axis is resampled on both, so its pixels keep their shape.
1633
+ Color is weighted by alpha (no fringes from colors under transparent pixels); alpha is
1634
+ resampled with it. A resampled JPEG is stored as JPEG at `quality` (else 90), resampled
1635
+ rasterized content as rasterized content is (lossy at its group's or `quality`); other images
1636
+ stay lossless. Rasterized groups and the flattening fallback are made at the resolution
1637
+ directly (`down`: the smaller of theirs and `dpi`; `match`: `dpi`). Image output does not use
1638
+ the policy: `dpi` there is the rendering's resolution.
1639
+
1640
+ ```python
1641
+ doc.write("pdf", compression="small", images={"quality": 85, "dpi": 300})
1642
+ doc.save("figure.svg", flatten=vec_io.Flatten(transparency=True), view={"trim": True})
1643
+ page.save("figure.png", dpi=192, png={"quality": 90}, view={"margin": "2mm"})
1644
+ policy = vec_io.ImagePolicy(quality=80)
1645
+ doc.write("eps", images=policy.replace(dpi=150))
1646
+ ```
1647
+
1648
+ ### 18.2 Files
1649
+
1504
1650
  * Compressed (default): PDF 1.5. Streams are zlib-compressed, small objects
1505
1651
  are packed into compressed object streams and the cross-reference table is
1506
1652
  a compressed xref stream; identical streams are written once. Tiny
1507
1653
  documents use whichever layout is smaller. On SVG files this halves the
1508
1654
  output size compared with a classic layout (median ratio 0.53).
1509
1655
  * `compression` of every compressed stream: `"fast"` (zlib level 1),
1510
- `"balanced"` (zlib 6, default) or `"best"`: vec_io's Deflate (binary-tree match
1656
+ `"balanced"` (zlib 6, default) or `"small"`: vec_io's Deflate (binary-tree match
1511
1657
  finder, near-optimal parsing iterated over the Huffman costs, block splitting),
1512
1658
  as small as libdeflate's best level and 3–6 % smaller than zlib's best (PNG rows,
1513
1659
  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 `best` writes 9 % less Flate
1660
+ than `balanced` and 16 % larger; on SVG conversions `small` writes 9 % less Flate
1515
1661
  data than `balanced`, in 1.6× the time of zlib's best. PNG data embedded as is is
1516
- recompressed at `best`.
1662
+ recompressed at `small`.
1517
1663
  * Streams of 1 MB or more are compressed in 1 MB chunks on worker threads
1518
1664
  (`VEC_IO_THREADS`, see [Rendering](#rendering)): each chunk is primed with
1519
1665
  the previous 32 KB, so the result is one zlib stream within 0.01 % of the
1520
1666
  serial size, and the same bytes for any number of threads.
1521
- * `compress=False`: classic, human-readable PDF 1.4 layout, for debugging.
1667
+ * `compression=None`: classic, human-readable PDF 1.4 layout, for debugging.
1522
1668
  * Every file carries a document `/ID` derived from its content.
1523
1669
  * Object numbers and resource names are given when a file is written: names per
1524
1670
  category in the order the resources were first used (`F1`, `GS1`, `Fm1`, `Im2`…),
@@ -1531,25 +1677,35 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
1531
1677
  (`font_hinting=True`); CFF subsets keep their hints (they are part of the
1532
1678
  charstrings).
1533
1679
  * SVG conversion: one page of the SVG's size, 1 px = 0.75 pt.
1534
- * SVG output: `vec_io.svg.writer.page_svg(page)` (and `Drawing.to_svg`) writes what a page
1535
- draws, read from its scene command by command by the C library, as the PDF writer reads
1536
- it: paths with their fills and strokes, `<text>` with every glyph placed (`<tspan>` where
1537
- kerning or adjustments move one; the faces named by family, weight and style), `<image>`
1538
- (PNG and JPEG files as given, other images as PNG), gradients and tiling patterns, clips
1680
+ * SVG output: `write("svg")` of a document, page or drawing (and `convert(…,
1681
+ format="svg")`) writes what a page draws, sized in the document's unit, read from its scene
1682
+ command by command by the C library, as the PDF writer reads it, with what the PDF keeps
1683
+ (`simplify`; rasterized groups as their images, stored by `images`; `flatten`): paths with their
1684
+ fills and strokes, `<text>` with every glyph placed (`<tspan>` where kerning or
1685
+ adjustments move one; the faces named by family, weight and style; characters XML 1.0
1686
+ does not allow left out), `<image>` (PNG and JPEG files as given; rasterized content as
1687
+ the PDF stores it: JPEG at the group's or `images`' quality, its alpha as a mask in an SVG
1688
+ image, else PNG; other images as PNG), gradients and tiling patterns, clips
1539
1689
  and soft masks (`<clipPath>`, `<mask>`), forms (marker shapes, groups) as `<defs>` reused
1540
1690
  by `<use>`, links as `<a>`; smooth cells' mesh becomes an image of about two samples per
1541
1691
  unit, and a filtered group the image it is drawn as. Colors are RGB (CMYK and spot colors
1542
- as their approximation); content asking for simplification is written whole. Read back
1692
+ as their approximation). Read back
1543
1693
  by vec_io, a page renders as it did (tests: mean difference under half an 8-bit level;
1544
1694
  marker sprites and meshes differ at edges). 200,000 markers take 20 ms (12 MB), a
1545
1695
  1M-point line 42 ms, 1.5–2.6× the PDF content writer.
1546
1696
  * Shapes and text stay vectors; only rasterized groups, filters and PNG
1547
1697
  output produce pixels.
1698
+ * A page whose view shows more than the page (a margin, a fit's room) has its content
1699
+ clipped to the page in every output. A trimmed or resized PDF page draws its content as
1700
+ one form XObject (`/Pg`) whose `/Matrix` is the view and `/BBox` what it shows; other
1701
+ pages write their content directly.
1548
1702
  * Numbers: coordinates (paths, rectangles, marker positions, lines, areas,
1549
1703
  segments, cells) are written to 1/1000 pt or finer on the page:
1550
1704
  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, line widths and
1552
- dashes have 6 decimals, colors 4. Drawing records a scene (`scene.py`) whose numbers
1705
+ user units in points, 5 for inches). Transform matrices have 6 decimals, more (up to
1706
+ 12) when a scale is below 0.1, so that it keeps 6 significant digits (`0.000360892`, the
1707
+ scales of exporters' large internal units); SVG output writes such scales with an
1708
+ exponent (`3.60892e-4`). Line widths and dashes have 6 decimals, colors 4. Drawing records a scene (`scene.py`) whose numbers
1553
1709
  are rounded to these decimals when they are captured; the C library writes the content
1554
1710
  streams from it.
1555
1711
  * Identical inputs give identical bytes, and a document written again with the same
@@ -1566,7 +1722,7 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
1566
1722
 
1567
1723
  ### Transparency flattening
1568
1724
 
1569
- `flatten_transparency=True` (`Document.to_bytes`/`save`, `Drawing.to_svg`, `convert`,
1725
+ `flatten=Flatten(transparency=True)` (PDF and SVG output of `write`, `save`, `convert`;
1570
1726
  `--flatten-transparency`) writes pages without transparency: no `/ca` or `/CA` below 1, no
1571
1727
  soft mask, no transparency group (SVG: no `opacity`, no `<mask>`). Off by default; pages
1572
1728
  without transparency are written as they are.
@@ -1581,15 +1737,16 @@ without transparency are written as they are.
1581
1737
  have alpha), images (new samples) and text are flattened; group opacity flattens the
1582
1738
  group as one layer, then composites it. Forms placed under or as translucent content are
1583
1739
  drawn per placement; others keep their reuse.
1584
- * Fallback (`flatten_fallback`): for content that cannot be flattened (a gradient over a
1740
+ * Fallback (`Flatten.fallback`): for content that cannot be flattened (a gradient over a
1585
1741
  different gradient, an image over an image or a gradient, a soft mask of varying alpha, a
1586
- tiling pattern) and for grid cells of `flatten_cell` inches (default 0.25) holding more
1587
- than `flatten_budget` pieces (default 256; adjacent cells form one region): `"raster"`
1588
- (default) draws the region as an image of what the page shows there, at `flatten_dpi`
1742
+ tiling pattern, a dashed stroke whose outline takes more than 2^24 points) and for grid
1743
+ cells of `cell` inches (default 0.25) holding more than `budget` pieces
1744
+ (default 256; adjacent cells form one region): `"raster"`
1745
+ (default) draws the region as an image of what the page shows there, at `dpi`
1589
1746
  (default 600), lossless, 2 pixels wider than its cells and clipped to them and to the
1590
1747
  outline of what it shows (up to 2,000 shapes); content drawn after it stays vectors, over
1591
1748
  it. `"opaque"` draws that content as if its alpha were 1 (one
1592
- `vec_io.flatten.FlattenWarning` per output); `"error"` raises `ValueError` naming the
1749
+ `FlattenWarning` per output); `"error"` raises `ValueError` naming the
1593
1750
  page and what failed. A dense translucent scatter is the expected over-budget case.
1594
1751
  * Anti-aliasing: where a translucent shape's edge lies over another shape, its opaque draw
1595
1752
  and the piece over that shape each cover the edge pixel in part, as viewers draw them:
@@ -1598,9 +1755,9 @@ without transparency are written as they are.
1598
1755
 
1599
1756
  ### EPS output
1600
1757
 
1601
- `Document.to_eps(page=0, **options)` / `save_eps(file, page=0, **options)`,
1602
- `Drawing.to_eps` and `save("….eps")`, `convert(…, format="eps")`, CLI `--format eps`: one
1603
- page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
1758
+ `write("eps", pages=…)` and `save("….eps")` of a document, page or drawing, `convert(…,
1759
+ format="eps")`, CLI `--format eps`: one page as an EPS file (EPSF-3.0, PostScript
1760
+ LanguageLevel 3).
1604
1761
 
1605
1762
  * Header: `%%BoundingBox` and `%%HiResBoundingBox` of the page (points), `%%Creator:
1606
1763
  vec_io`, `%%Title` (the document's), `%%LanguageLevel: 3`, `%%DocumentData: Clean7Bit`,
@@ -1608,8 +1765,8 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
1608
1765
  short procedures), the setup (fonts, images, shadings, forms), the page and `showpage`.
1609
1766
  Every byte is 7-bit ASCII and lines stay under 256 characters: binary data is ASCII85.
1610
1767
  * Transparency is always flattened ([Transparency flattening](#transparency-flattening)),
1611
- with the raster fallback by default; `flatten_fallback`, `flatten_dpi`, `flatten_budget`
1612
- and `flatten_cell` tune it (`flatten_transparency=False` raises `ValueError`).
1768
+ with the raster fallback by default; `Flatten`'s `fallback`, `dpi`, `budget` and `cell`
1769
+ tune it (`Flatten(transparency=False)` raises `OptionError`).
1613
1770
  * The page is written as the PDF has it (its content streams, with the output's
1614
1771
  `simplify`), translated by the C library (`src/epsw.c`): paths, fills (nonzero, even-odd),
1615
1772
  strokes, dashes, caps, joins, miter limits, clips and transforms; DeviceGray, DeviceRGB
@@ -1627,16 +1784,17 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
1627
1784
  through a filter (`currentfile /ASCII85Decode filter cvx exec`, and `/FlateDecode` when
1628
1785
  compressed). Glyphs are placed by
1629
1786
  `xshow`/`xyshow` at vec_io's positions; stroked and clipping text uses `charpath`.
1630
- Variable fonts (`fvar`, CFF2), fonts that cannot be subset, and every font with
1631
- `text_as_paths=True` are drawn as glyph outlines (a procedure per glyph, filled,
1787
+ Variable fonts are embedded as the static instance the PDF has (Type 42, or CFF from
1788
+ CFF2). Fonts that cannot be subset, and every font with `text_as_paths=True`, are drawn
1789
+ as glyph outlines (a procedure per glyph, filled,
1632
1790
  stroked or clipped as the text's render mode asks; no font in the file). Standard 14
1633
1791
  fonts that are not embedded are the interpreter's own, WinAnsi-encoded.
1634
- * `compress=True` (default): the page's content, the forms, glyph outlines and font
1635
- programs are Flate-compressed (at `compression`'s level), ASCII85, and run through a
1636
- filter (`currentfile /ASCII85Decode filter /FlateDecode filter cvx exec`); `False`
1637
- writes them as readable PostScript (fonts ASCII85).
1638
- * Options: `simplify`, `compression`, `images` (no JPEG XL), `font_hinting` as for
1639
- `to_bytes`; `text_as_paths`. PDF/A documents and `jxl` images raise `ValueError`.
1792
+ * `compression` (default `"balanced"`): the page's content, the forms, glyph outlines and
1793
+ font programs are Flate-compressed (at its level), ASCII85, and run through a filter
1794
+ (`currentfile /ASCII85Decode filter /FlateDecode filter cvx exec`); `None` writes them as
1795
+ readable PostScript (fonts ASCII85).
1796
+ * Options: `simplify`, `compression`, `images` (no JPEG XL), `font_hinting` as for PDF;
1797
+ `text_as_paths`. PDF/A documents and `jxl` images raise `ValueError`.
1640
1798
  * Ghostscript (`gs -dEPSCrop`) draws an EPS as it draws the flattened PDF (tests: the same
1641
1799
  pixels for paths, colors, gradients, images, forms and patterns; text within its edge
1642
1800
  pixels). Sizes, compressed: 1–3× the PDF on the SVG corpus (ASCII85 adds a quarter, and
@@ -1644,19 +1802,29 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
1644
1802
 
1645
1803
  ## 19. Errors
1646
1804
 
1805
+ Every error vec_io raises for what it cannot read, write or use derives from
1806
+ `vec_io.VecIOError`, every warning from `vec_io.VecIOWarning` (a `UserWarning`); all are
1807
+ exported by `vec_io`.
1808
+
1647
1809
  | Exception | Raised for |
1648
1810
  |---|---|
1649
- | `vec_io.SVGParseError` (`ValueError`) | Input that is not a usable SVG document. |
1650
- | `vec_io.fonts.sfnt.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. |
1651
- | `vec_io.fonts.fontdb.NoFontError` (`ValueError`) | Text with no outline font available at all ([Fonts](#16-fonts)). |
1652
- | `vec_io.fonts.download.FontDownloadError` (`OSError`) | `download` of a source or `google.refresh` failing ([Font downloads](#font-downloads)); while drawing, a failing family gives a `FontDownloadWarning` instead. |
1653
- | `vec_io.raster.RasterizationError` | Content the rasterizer cannot draw (a standard 14 font with no installed font to draw it, too many dashes, unsupported shadings or JPEGs). |
1654
- | `vec_io.flatten.FlattenWarning` (warning) | `flatten_fallback="opaque"`: content drawn opaque because it could not be flattened, once per output ([Transparency flattening](#transparency-flattening)). |
1655
- | `vec_io.PDFReadError` (`ValueError`) | A PDF that cannot be read, a wrong password, a file past a limit ([Reading PDF](#reading-pdf)). |
1656
- | `vec_io.native.NativeLibraryError` | The C library is not built for this platform or failed to load. |
1657
- | `vec_io.image.codecs.JPEGError`, `JXLError`, `AVIFError`, `vec_io.image.resource.ImageError` (all `ValueError`) | Malformed or unsupported image data given to `vec_io.image.codecs`. |
1811
+ | `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). |
1812
+ | `SVGParseError` (`ValueError`) | Input that is not a usable SVG document. |
1813
+ | `PDFReadError` (`ValueError`) | A PDF that cannot be read, a wrong password, a file past a limit ([Reading PDF](#reading-pdf)). |
1814
+ | `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. |
1815
+ | `NoFontError` (`ValueError`) | Text with no outline font available at all ([Fonts](#16-fonts)). |
1816
+ | `FontDownloadError` (`OSError`) | `download` of a source or `google.refresh` failing ([Font downloads](#font-downloads)); while drawing, a failing family gives a `FontDownloadWarning` instead. |
1817
+ | `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). |
1818
+ | `ImageError` (`ValueError`) | Malformed or unsupported image data; the codecs' `JPEGError`, `JXLError`, `AVIFError` (`vec_io.image.codecs`) are `VecIOError`s too. |
1819
+ | `NativeLibraryError` (`RuntimeError`) | The C library is not built for this platform or failed to load. |
1658
1820
  | `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
1821
 
1822
+ | Warning | Given for |
1823
+ |---|---|
1824
+ | `PDFReadWarning` | Content of a PDF left out, once per kind and file ([Reading PDF](#reading-pdf)). |
1825
+ | `FlattenWarning` | `Flatten(fallback="opaque")`: content drawn opaque because it could not be flattened, once per output ([Transparency flattening](#transparency-flattening)). |
1826
+ | `FontDownloadWarning` | A family text asked for could not be downloaded; the next source or family is used. |
1827
+
1660
1828
  ## 20. Modules
1661
1829
 
1662
1830
  | Module | Role |
@@ -1672,8 +1840,11 @@ page as an EPS file (EPSF-3.0, PostScript LanguageLevel 3).
1672
1840
  | `lines.py`, `shapes.py`, `cells.py` | lines, segments and areas; rectangles and polygons; cells |
1673
1841
  | `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 |
1674
1842
  | `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
- | `svg/` | `convert`; `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) |
1676
- | `image/` | `Image` and the output options (`PNG`, `JPEG`, `JXL`, `AVIF`, `ImagePolicy`); `codecs`, `jxl`, `avif`, `resource` (loading, `ImageResource`) |
1843
+ | `convert.py` | `convert`, and the options of each output kind (`output_kind`, `output_settings`, `write_pages`) |
1844
+ | `options.py` | the option objects (`Fonts`, `Flatten`, `View`, `ImagePolicy`, `PNG`, `JPEG`, `JXL`, `AVIF`) and `OptionError` |
1845
+ | `errors.py` | `VecIOError`, `VecIOWarning` |
1846
+ | `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) |
1847
+ | `image/` | `Image`; `codecs`, `jxl`, `avif`, `resource` (loading, `ImageResource`) |
1677
1848
  | `pdf/` | `objects` (PDF values, numbered when written), `writer`, `images` (image XObjects), `pdfa` |
1678
1849
  | `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
1850
  | `pdfread/` | reading PDF: `file` (cross-reference, objects, filters, encryption), `content` (the interpreter), `resources`, `colors`, `functions`, `shadings`, `images`, `fonts`, `reader` (pages, annotations, links, outlines) |