vec-io 0.1.0__tar.gz → 0.2.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 (313) hide show
  1. {vec_io-0.1.0 → vec_io-0.2.0}/API.md +323 -41
  2. {vec_io-0.1.0 → vec_io-0.2.0}/EXAMPLES.md +26 -2
  3. {vec_io-0.1.0 → vec_io-0.2.0}/PKG-INFO +22 -9
  4. {vec_io-0.1.0 → vec_io-0.2.0}/README.md +21 -8
  5. vec_io-0.2.0/tests/fuzz_pdfread.py +83 -0
  6. {vec_io-0.1.0 → vec_io-0.2.0}/tests/helpers.py +4 -1
  7. vec_io-0.2.0/tests/jbig2_encoder.py +247 -0
  8. vec_io-0.2.0/tests/jpx_fixtures.py +190 -0
  9. vec_io-0.2.0/tests/make_crypt_fixtures.py +123 -0
  10. vec_io-0.2.0/tests/pdfbuild.py +150 -0
  11. vec_io-0.2.0/tests/pdfread/cmyk8.j2k +0 -0
  12. vec_io-0.2.0/tests/pdfread/cmyk8.jp2 +0 -0
  13. vec_io-0.2.0/tests/pdfread/gray12.j2k +0 -0
  14. vec_io-0.2.0/tests/pdfread/gray16.jp2 +0 -0
  15. vec_io-0.2.0/tests/pdfread/gray4-signed.j2k +0 -0
  16. vec_io-0.2.0/tests/pdfread/graya16.jp2 +0 -0
  17. vec_io-0.2.0/tests/pdfread/gs-r2.pdf +93 -0
  18. vec_io-0.2.0/tests/pdfread/gs-r3.pdf +0 -0
  19. vec_io-0.2.0/tests/pdfread/icc-gray8.jp2 +0 -0
  20. vec_io-0.2.0/tests/pdfread/qpdf-r2.pdf +39 -0
  21. vec_io-0.2.0/tests/pdfread/qpdf-r3.pdf +39 -0
  22. vec_io-0.2.0/tests/pdfread/qpdf-r4-aes-nometa.pdf +39 -0
  23. vec_io-0.2.0/tests/pdfread/qpdf-r4-aes.pdf +39 -0
  24. vec_io-0.2.0/tests/pdfread/qpdf-r4-pdfdoc.pdf +40 -0
  25. vec_io-0.2.0/tests/pdfread/qpdf-r4-rc4.pdf +39 -0
  26. vec_io-0.2.0/tests/pdfread/qpdf-r5.pdf +39 -0
  27. vec_io-0.2.0/tests/pdfread/qpdf-r6-empty.pdf +39 -0
  28. vec_io-0.2.0/tests/pdfread/qpdf-r6-utf8.pdf +39 -0
  29. vec_io-0.2.0/tests/pdfread/qpdf-r6.pdf +39 -0
  30. vec_io-0.2.0/tests/pdfread/rgb8.j2k +0 -0
  31. vec_io-0.2.0/tests/pdfread/rgb8.jp2 +0 -0
  32. vec_io-0.2.0/tests/pdfread/rgba8.jp2 +0 -0
  33. vec_io-0.2.0/tests/pdfread/ycc420.jp2 +0 -0
  34. vec_io-0.2.0/tests/pdfread/ycc422-offset.jp2 +0 -0
  35. vec_io-0.2.0/tests/test_ccitt.py +222 -0
  36. vec_io-0.2.0/tests/test_cmap.py +378 -0
  37. vec_io-0.2.0/tests/test_encodings.py +101 -0
  38. vec_io-0.2.0/tests/test_eps.py +459 -0
  39. vec_io-0.2.0/tests/test_flatten.py +325 -0
  40. vec_io-0.2.0/tests/test_font_sources.py +517 -0
  41. vec_io-0.2.0/tests/test_google_fonts.py +529 -0
  42. vec_io-0.2.0/tests/test_jpx_jbig2.py +295 -0
  43. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_output.py +38 -0
  44. vec_io-0.2.0/tests/test_pdf_security.py +353 -0
  45. vec_io-0.2.0/tests/test_pdfread.py +797 -0
  46. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_text.py +17 -0
  47. vec_io-0.2.0/tests/test_text_as_paths.py +127 -0
  48. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_textlayout.py +25 -0
  49. vec_io-0.2.0/tests/test_type1.py +482 -0
  50. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/__init__.py +4 -2
  51. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/__main__.py +88 -9
  52. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/canvas.py +130 -4
  53. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/document.py +140 -30
  54. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/draw.py +42 -15
  55. vec_io-0.2.0/vec_io/eps/__init__.py +497 -0
  56. vec_io-0.2.0/vec_io/eps/fonts.py +309 -0
  57. vec_io-0.2.0/vec_io/flatten.py +2629 -0
  58. vec_io-0.2.0/vec_io/fonts/ctan.py +74 -0
  59. vec_io-0.2.0/vec_io/fonts/download.py +793 -0
  60. vec_io-0.2.0/vec_io/fonts/encodings.py +255 -0
  61. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/fontdb.py +98 -18
  62. vec_io-0.2.0/vec_io/fonts/fontshare.py +109 -0
  63. vec_io-0.2.0/vec_io/fonts/fontshare_families.txt +102 -0
  64. vec_io-0.2.0/vec_io/fonts/fontsource.py +70 -0
  65. vec_io-0.2.0/vec_io/fonts/fontsource_families.txt +121 -0
  66. vec_io-0.2.0/vec_io/fonts/glyphlist.txt +3764 -0
  67. vec_io-0.2.0/vec_io/fonts/google.py +483 -0
  68. vec_io-0.2.0/vec_io/fonts/google_families.txt +1961 -0
  69. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/sfnt.py +4 -0
  70. vec_io-0.2.0/vec_io/fonts/type1.py +972 -0
  71. vec_io-0.2.0/vec_io/fonts/urw.py +141 -0
  72. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/variations.py +3 -0
  73. vec_io-0.2.0/vec_io/image/jbig2.py +271 -0
  74. vec_io-0.2.0/vec_io/image/jpx.py +343 -0
  75. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/image/jxl.py +6 -4
  76. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/README.md +6 -1
  77. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/_api.py +208 -0
  78. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/bin/linux-aarch64.so +0 -0
  79. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/bin/linux-x86_64.so +0 -0
  80. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/bin/macos-arm64.dylib +0 -0
  81. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/bin/windows-arm64.dll +0 -0
  82. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/bin/windows-x86_64.dll +0 -0
  83. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/manifest.json +11 -11
  84. vec_io-0.2.0/vec_io/native/pdfread.py +75 -0
  85. vec_io-0.2.0/vec_io/native/src/ccitt.c +497 -0
  86. vec_io-0.2.0/vec_io/native/src/crypt.c +340 -0
  87. vec_io-0.2.0/vec_io/native/src/epsw.c +1454 -0
  88. vec_io-0.2.0/vec_io/native/src/flat.c +643 -0
  89. vec_io-0.2.0/vec_io/native/src/jpx.c +120 -0
  90. vec_io-0.2.0/vec_io/native/src/mesh.c +454 -0
  91. vec_io-0.2.0/vec_io/native/src/pdfread.c +1012 -0
  92. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/pio_api.h +220 -0
  93. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/raster.h +7 -3
  94. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/res.c +11 -0
  95. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/shade.c +9 -2
  96. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/shade.h +6 -0
  97. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/signatures.c +34 -1
  98. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/stroke.c +53 -12
  99. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/pdf/images.py +2 -0
  100. vec_io-0.2.0/vec_io/pdfread/__init__.py +177 -0
  101. vec_io-0.2.0/vec_io/pdfread/_native.py +95 -0
  102. vec_io-0.2.0/vec_io/pdfread/ccitt.py +36 -0
  103. vec_io-0.2.0/vec_io/pdfread/cffinfo.py +177 -0
  104. vec_io-0.2.0/vec_io/pdfread/cmap.py +629 -0
  105. vec_io-0.2.0/vec_io/pdfread/cmap_resources.txt +210 -0
  106. vec_io-0.2.0/vec_io/pdfread/colors.py +450 -0
  107. vec_io-0.2.0/vec_io/pdfread/content.py +800 -0
  108. vec_io-0.2.0/vec_io/pdfread/convert.py +57 -0
  109. vec_io-0.2.0/vec_io/pdfread/errors.py +34 -0
  110. vec_io-0.2.0/vec_io/pdfread/file.py +649 -0
  111. vec_io-0.2.0/vec_io/pdfread/fonts.py +1066 -0
  112. vec_io-0.2.0/vec_io/pdfread/functions.py +445 -0
  113. vec_io-0.2.0/vec_io/pdfread/images.py +571 -0
  114. vec_io-0.2.0/vec_io/pdfread/meshes.py +47 -0
  115. vec_io-0.2.0/vec_io/pdfread/parser.py +246 -0
  116. vec_io-0.2.0/vec_io/pdfread/reader.py +527 -0
  117. vec_io-0.2.0/vec_io/pdfread/resources.py +368 -0
  118. vec_io-0.2.0/vec_io/pdfread/security.py +313 -0
  119. vec_io-0.2.0/vec_io/pdfread/shadings.py +505 -0
  120. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/raster/__init__.py +23 -13
  121. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/raster/resources.py +6 -1
  122. vec_io-0.2.0/vec_io/svg/__init__.py +167 -0
  123. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/svg/css.py +17 -6
  124. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/svg/parse.py +3 -1
  125. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/svg/render.py +24 -11
  126. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/svg/writer.py +20 -6
  127. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/text/__init__.py +59 -21
  128. vec_io-0.1.0/vec_io/svg/__init__.py +0 -104
  129. {vec_io-0.1.0 → vec_io-0.2.0}/LICENSE +0 -0
  130. {vec_io-0.1.0 → vec_io-0.2.0}/examples/bubble_chart.py +0 -0
  131. {vec_io-0.1.0 → vec_io-0.2.0}/examples/canvas_demo.py +0 -0
  132. {vec_io-0.1.0 → vec_io-0.2.0}/examples/drawing_demo.py +0 -0
  133. {vec_io-0.1.0 → vec_io-0.2.0}/examples/heatmap.py +0 -0
  134. {vec_io-0.1.0 → vec_io-0.2.0}/examples/scatter_plot.py +0 -0
  135. {vec_io-0.1.0 → vec_io-0.2.0}/examples/showcase.svg +0 -0
  136. {vec_io-0.1.0 → vec_io-0.2.0}/examples/text.svg +0 -0
  137. {vec_io-0.1.0 → vec_io-0.2.0}/examples/text_layout.py +0 -0
  138. {vec_io-0.1.0 → vec_io-0.2.0}/pyproject.toml +0 -0
  139. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/abc.br +0 -0
  140. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/abc.out.z +0 -0
  141. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/big.br +0 -0
  142. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/big.out.z +0 -0
  143. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/binary.br +0 -0
  144. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/binary.out.z +0 -0
  145. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/bits2.br +0 -0
  146. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/bits2.out.z +0 -0
  147. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/dictwords.br +0 -0
  148. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/dictwords.out.z +0 -0
  149. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/empty.br +0 -0
  150. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/empty.out.z +0 -0
  151. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/four.br +0 -0
  152. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/four.out.z +0 -0
  153. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/handmade.br +0 -0
  154. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/handmade.out.z +0 -0
  155. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/ints.br +0 -0
  156. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/ints.out.z +0 -0
  157. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/mixed.br +0 -0
  158. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/mixed.out.z +0 -0
  159. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/multi.br +0 -0
  160. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/multi.out.z +0 -0
  161. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/one.br +0 -0
  162. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/one.out.z +0 -0
  163. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/random.br +0 -0
  164. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/random.out.z +0 -0
  165. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/text11.br +0 -0
  166. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/text11.out.z +0 -0
  167. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/text_q2.br +0 -0
  168. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/text_q2.out.z +0 -0
  169. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/three.br +0 -0
  170. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/three.out.z +0 -0
  171. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/w10.br +0 -0
  172. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/w10.out.z +0 -0
  173. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/w24.br +0 -0
  174. {vec_io-0.1.0 → vec_io-0.2.0}/tests/brotli/w24.out.z +0 -0
  175. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/clipping.svg +0 -0
  176. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/css.svg +0 -0
  177. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/empty.svg +0 -0
  178. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/filters.svg +0 -0
  179. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/fonts_face.svg +0 -0
  180. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/gradients.svg +0 -0
  181. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/images.svg +0 -0
  182. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/markers.svg +0 -0
  183. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/masks.svg +0 -0
  184. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/opacity.svg +0 -0
  185. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/paths.svg +0 -0
  186. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/patterns.svg +0 -0
  187. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/rasterized.svg +0 -0
  188. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/shapes.svg +0 -0
  189. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/strokes.svg +0 -0
  190. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/structure.svg +0 -0
  191. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/text-wrap.svg +0 -0
  192. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/text_basic.svg +0 -0
  193. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/text_layout.svg +0 -0
  194. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/text_path.svg +0 -0
  195. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/text_unicode.svg +0 -0
  196. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/transforms.svg +0 -0
  197. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/units.svg +0 -0
  198. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/use_symbol.svg +0 -0
  199. {vec_io-0.1.0 → vec_io-0.2.0}/tests/corpus/viewbox.svg +0 -0
  200. {vec_io-0.1.0 → vec_io-0.2.0}/tests/fonts/PioTest-Bold.ttf +0 -0
  201. {vec_io-0.1.0 → vec_io-0.2.0}/tests/fonts/PioTest-Regular.ttf +0 -0
  202. {vec_io-0.1.0 → vec_io-0.2.0}/tests/fuzz_native.py +0 -0
  203. {vec_io-0.1.0 → vec_io-0.2.0}/tests/maps.py +0 -0
  204. {vec_io-0.1.0 → vec_io-0.2.0}/tests/scene_oracle.py +0 -0
  205. {vec_io-0.1.0 → vec_io-0.2.0}/tests/shapes.py +0 -0
  206. {vec_io-0.1.0 → vec_io-0.2.0}/tests/svg_oracle.py +0 -0
  207. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_api.py +0 -0
  208. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_avif.py +0 -0
  209. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_canvas_features.py +0 -0
  210. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_cells.py +0 -0
  211. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_cmyk.py +0 -0
  212. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_codecs.py +0 -0
  213. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_compile.py +0 -0
  214. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_convert.py +0 -0
  215. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_deflate.py +0 -0
  216. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_features.py +0 -0
  217. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_filters.py +0 -0
  218. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_fonts_io.py +0 -0
  219. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_jxl.py +0 -0
  220. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_marker_runs.py +0 -0
  221. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_native.py +0 -0
  222. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_native_emit.py +0 -0
  223. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_native_jpeg.py +0 -0
  224. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_native_png.py +0 -0
  225. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_parsing.py +0 -0
  226. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_pdfa.py +0 -0
  227. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_raster.py +0 -0
  228. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_scene.py +0 -0
  229. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_shapes.py +0 -0
  230. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_simplify.py +0 -0
  231. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_svg_semantics.py +0 -0
  232. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_svg_writer.py +0 -0
  233. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_threads.py +0 -0
  234. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_units.py +0 -0
  235. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_varfonts.py +0 -0
  236. {vec_io-0.1.0 → vec_io-0.2.0}/tests/test_woff2.py +0 -0
  237. {vec_io-0.1.0 → vec_io-0.2.0}/tests/testfont.py +0 -0
  238. {vec_io-0.1.0 → vec_io-0.2.0}/tests/varfonts/VarTest.otf +0 -0
  239. {vec_io-0.1.0 → vec_io-0.2.0}/tests/varfonts/VarTest.ttf +0 -0
  240. {vec_io-0.1.0 → vec_io-0.2.0}/tests/woff2/make.py +0 -0
  241. {vec_io-0.1.0 → vec_io-0.2.0}/tests/woff2/pair.woff2 +0 -0
  242. {vec_io-0.1.0 → vec_io-0.2.0}/tests/woff2/rich-null.woff2 +0 -0
  243. {vec_io-0.1.0 → vec_io-0.2.0}/tests/woff2/rich.ttf +0 -0
  244. {vec_io-0.1.0 → vec_io-0.2.0}/tests/woff2/rich.woff2 +0 -0
  245. {vec_io-0.1.0 → vec_io-0.2.0}/tools/build_native.py +0 -0
  246. {vec_io-0.1.0 → vec_io-0.2.0}/tools/gen_api.py +0 -0
  247. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/arrays.py +0 -0
  248. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/cells.py +0 -0
  249. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/filter.py +0 -0
  250. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/flate.py +0 -0
  251. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/__init__.py +0 -0
  252. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/cff.py +0 -0
  253. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/cff2.py +0 -0
  254. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/opentype.py +0 -0
  255. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/fonts/woff2.py +0 -0
  256. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/geometry.py +0 -0
  257. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/image/__init__.py +0 -0
  258. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/image/avif.py +0 -0
  259. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/image/codecs.py +0 -0
  260. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/image/resource.py +0 -0
  261. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/items.py +0 -0
  262. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/lines.py +0 -0
  263. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/__init__.py +0 -0
  264. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/brotli.py +0 -0
  265. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/deflate.py +0 -0
  266. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/emit.py +0 -0
  267. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/filters.py +0 -0
  268. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/jpeg.py +0 -0
  269. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/png.py +0 -0
  270. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/alloc.c +0 -0
  271. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/brotli.c +0 -0
  272. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/brotli.h +0 -0
  273. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/brotli_dict.c +0 -0
  274. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/crowding.c +0 -0
  275. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/cull.c +0 -0
  276. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/data.c +0 -0
  277. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/deflate.c +0 -0
  278. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/emit.c +0 -0
  279. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/filters.c +0 -0
  280. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/image.c +0 -0
  281. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/interp.c +0 -0
  282. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/items.c +0 -0
  283. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/jpeg.h +0 -0
  284. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/jpeg_dec.c +0 -0
  285. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/jpeg_enc.c +0 -0
  286. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/math.c +0 -0
  287. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/paint.c +0 -0
  288. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/path.c +0 -0
  289. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/pio.h +0 -0
  290. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/png.c +0 -0
  291. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/quant.c +0 -0
  292. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/rt.c +0 -0
  293. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/scan.c +0 -0
  294. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/scene.c +0 -0
  295. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/scene.h +0 -0
  296. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/svgw.c +0 -0
  297. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/src/woff2.c +0 -0
  298. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/native/woff2.py +0 -0
  299. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/paint.py +0 -0
  300. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/pdf/__init__.py +0 -0
  301. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/pdf/objects.py +0 -0
  302. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/pdf/pdfa.py +0 -0
  303. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/pdf/writer.py +0 -0
  304. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/py.typed +0 -0
  305. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/raster/groups.py +0 -0
  306. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/scene.py +0 -0
  307. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/shapes.py +0 -0
  308. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/simplify.py +0 -0
  309. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/svg/filters.py +0 -0
  310. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/text/breaking.py +0 -0
  311. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/text/path.py +0 -0
  312. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/threads.py +0 -0
  313. {vec_io-0.1.0 → vec_io-0.2.0}/vec_io/units.py +0 -0
@@ -59,7 +59,8 @@ Complete reference. Worked examples are in [EXAMPLES.md](EXAMPLES.md).
59
59
  Relative references resolve against `base_dir`; without it only `data:` URIs are loaded.
60
60
  With it, any local file the process can read may be embedded (`../` paths, absolute
61
61
  paths, `file:` URLs on this machine), so pass `base_dir=None` for untrusted SVG. Remote
62
- URLs and `file:` URLs naming another host are never fetched.
62
+ URLs and `file:` URLs naming another host are never fetched, except fonts from the
63
+ download sources ([Font downloads](#font-downloads)).
63
64
  * **Types.** The package is typed (`py.typed`). Aliases: `vec_io.Color` (a color argument),
64
65
  `vec_io.Paint` (a color, gradient, pattern or `None`), `vec_io.Content` (text layout
65
66
  content). Chainable methods return the object's own type.
@@ -76,24 +77,27 @@ Complete reference. Worked examples are in [EXAMPLES.md](EXAMPLES.md).
76
77
 
77
78
  ```python
78
79
  convert(source, output=None, *, format=None, base_dir=None, font_db=None, font_dirs=None,
79
- system_fonts=True, filters=False, pdf_a=None, compress=True, compression="balanced",
80
- simplify=None, images=None, dpi=96, background=None, png=None, jpeg=None, jxl=None,
81
- avif=None) -> bytes
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
82
85
  ```
83
86
 
84
- Converts an SVG document to PDF, PNG, JPEG, JPEG XL or AVIF, returns the bytes and writes
87
+ Converts an SVG document to PDF, EPS, PNG, JPEG, JPEG XL or AVIF, returns the bytes and writes
85
88
  them to `output` (a path or a binary file object) when given. It is a `Document` in CSS
86
89
  pixels with the SVG on its page, saved or rendered with the options below.
87
90
 
88
91
  | Parameter | Meaning |
89
92
  |---|---|
90
93
  | `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. |
91
- | `format` | `"pdf"`, `"png"`, `"jpeg"`, `"jxl"` or `"avif"`; default: the extension of an `output` path, else `"pdf"`. |
94
+ | `format` | `"pdf"`, `"eps"`, `"png"`, `"jpeg"`, `"jxl"` or `"avif"`; default: the extension of an `output` path, else `"pdf"`. |
92
95
  | `base_dir` | Directory of relative `<image>` and `@font-face` URLs; default: a source path's directory. |
93
- | `font_db`, `font_dirs`, `system_fonts` | Fonts: a `FontDB`, or extra directories searched first and whether to use installed fonts ([Fonts](#16-fonts)). |
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)). |
94
97
  | `filters` | Apply SVG filters (rasterizes filtered elements; [Filters](#14-filters)). |
98
+ | `text_as_paths` | Text drawn as glyph outlines, no font written ([Fonts](#16-fonts)). |
95
99
  | `pdf_a` | PDF: `"2b"`, `"2u"` or `"3b"` ([PDF/A](#pdfa)). |
96
- | `compress`, `compression`, `simplify`, `images` | PDF: the options of `Document.to_bytes` ([4](#4-document-and-page)). |
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)). |
97
101
  | `dpi`, `simplify`, `background` | Images: resolution (96: one pixel per CSS pixel), decimation, a color under the page (`None`: transparent, white for JPEG). |
98
102
  | `png`, `jpeg`, `jxl`, `avif` | Images: the options of the format (`PNG(…)`, `JPEG(…)`, …; [5.9](#59-rendering-and-image-output)). |
99
103
 
@@ -105,40 +109,100 @@ vec_io.convert("drawing.svg", "drawing.pdf")
105
109
  png = vec_io.convert(text, format="png", dpi=192, png=vec_io.PNG(quality=90))
106
110
  ```
107
111
 
112
+ ### Reading PDF
113
+
114
+ ```python
115
+ open_pdf(source, password=None, pages=None, annotations=True) -> Document
116
+ ```
117
+
118
+ Reads a PDF file into a new `Document` (unit `pt`): each page drawn by vec_io's canvas,
119
+ the size of its crop box (rotated by `Rotate`, scaled by `UserUnit`), so it can be written
120
+ as PDF, SVG or images, simplified, drawn on. `source`: a path, bytes or a binary file;
121
+ `password`: the user or owner password of an encrypted file; `pages`: page indices
122
+ (default all, negative from the end); `annotations=False`: page content only (otherwise
123
+ visible annotations are drawn from their appearance streams, as viewers print them). Links
124
+ (to URLs, and between the pages read) and the outline are kept; the document information
125
+ becomes the metadata. Forms, actions other than links, JavaScript and embedded files are
126
+ not read. Illustrator files (`.ai`, Illustrator 9 and later) are PDF files and read as
127
+ such; their private data is ignored.
128
+
129
+ `convert` and the command line read PDF input (data starting with `%PDF-`): every page
130
+ (or `page`) as PDF, page `page` (default 0) as an image; `password` and `annotations` as
131
+ above. `Canvas.draw_pdf` places a page ([5.5](#55-images-and-svg)).
132
+
133
+ | Read | |
134
+ |---|---|
135
+ | File | cross-reference tables and streams, incremental updates, object streams; a damaged table rebuilt by scanning the file; encryption (standard handler, RC4 and AES, revisions 2–6) |
136
+ | Filters | Flate, LZW (PNG and TIFF predictors), ASCII85, ASCIIHex, RunLength, CCITT fax; DCT, JPEG 2000, JBIG2 and JPEG XL images kept encoded for PDF output |
137
+ | Content | paths, clips, device colours, graphics states (alpha, soft masks, blend modes: kept in PDF output, composited normally in images), forms and transparency groups, images (masks, soft masks, colour keys, `Decode`, 1–16 bits), tiling patterns, shadings 1–7, optional content (the default configuration), Type 3 glyphs |
138
+ | Colour | Gray, RGB, CMYK; ICC by component count; CalGray, CalRGB and Lab to sRGB; Indexed; Separation (a spot colour when its alternate is CMYK) and DeviceN through their tint transforms; functions 0, 2, 3, 4 |
139
+ | Fonts | TrueType, Type 1, Type 1C, OpenType and Type 3 simple fonts; CID fonts (CFF, TrueType, `CIDToGIDMap`), embedded and predefined CMaps; glyphs placed by the PDF's widths; fonts that are not embedded drawn with an installed or downloaded family of their name (the standard 14 with URW's metric-compatible families) |
140
+
141
+ Text stays text (the fonts written again as subsets, `ToUnicode` kept). Shadings 4–7 are
142
+ written to PDF as meshes and to SVG as images. Images in JPEG 2000 and JBIG2 need OpenJPEG
143
+ and jbig2dec, JPEG XL libjxl, for image and SVG output (PDF output keeps them as they are);
144
+ without the library such an image is left out there, with a `PDFReadWarning`.
145
+
146
+ `PDFReadError` (a `ValueError`): a file vec_io cannot read, a wrong or missing password, a
147
+ file past a limit (`vec_io.pdfread.Limits`: 256 MB per decoded stream, forms, patterns and
148
+ glyphs nested 32 deep, 50 million operators per page), an Illustrator file saved without
149
+ PDF content (save it again with "Create PDF Compatible File"), PostScript (an Illustrator
150
+ 8 or earlier `.ai` or EPS file: convert it with `ps2pdf`). `PDFReadWarning`: content left
151
+ out (an unknown operator, a broken object, an image without its library…), once per kind
152
+ and file.
153
+
154
+ ```python
155
+ doc = vec_io.open_pdf("report.pdf", pages=[0, 1])
156
+ doc.pages[0].render(dpi=150).save("page1.png")
157
+ doc.save("first-two.pdf")
158
+ ```
159
+
108
160
  ## 3. Command line
109
161
 
110
162
  ```
111
163
  vec_io INPUT [OUTPUT] (or: python -m vec_io …)
164
+ vec_io --download-font FAMILY …
112
165
  ```
113
166
 
114
167
  | Argument | Meaning |
115
168
  |---|---|
116
- | `INPUT` | SVG file, or `-` for stdin. |
117
- | `OUTPUT` | Output file, or `-` for stdout. Default: `INPUT` with the extension of `--format` (`.pdf`, `.png`, `.jpg`, `.jxl`, `.avif`). |
118
- | `--format FORMAT` | `pdf` (default), `png`, `jpeg`, `jxl` or `avif`. |
119
- | `--no-compress` | Uncompressed content streams. |
169
+ | `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). |
120
173
  | `--compression LEVEL` | `fast`, `balanced` (default) or `best`: the encoder's effort. |
121
174
  | `--font-dir DIR` | Extra font directory (repeatable). |
122
175
  | `--no-system-fonts` | Ignore installed fonts. |
176
+ | `--font-downloads MODE` | Downloads of families that are not installed: `on` (default, or `VEC_IO_FONT_DOWNLOADS`), `off`, or `cache` (downloaded families only) ([Font downloads](#font-downloads)). |
177
+ | `--no-font-downloads` | Same as `--font-downloads off`. |
178
+ | `--download-font FAMILY` | Download every style of a family into the cache from the first source that has it and print its files, without converting (repeatable; no `INPUT`). Exit status 1 when one fails. |
123
179
  | `--filters` | Apply SVG filters. |
180
+ | `--text-as-paths` | Text drawn as glyph outlines, no font written. |
124
181
  | `--quality N` | PDF: store rasterized content as JPEG (JPEG XL with `--jxl`) of quality N (1–100); images: the quality of the image (JPEG default 90, JPEG XL and AVIF default lossless, PNG a lossy palette). |
125
182
  | `--jxl` | Write the PDF's images as JPEG XL ([JPEG XL](#jpeg-xl)). |
126
183
  | `--pdf-a LEVEL` | Write PDF/A: `2b`, `2u` or `3b`. |
127
184
  | `--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`. |
187
+ | `--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). |
128
188
  | `--dpi N` | Image resolution (default 96). |
189
+ | `--page N` | PDF input: the page (from 0; default every page for PDF output, the first for images). |
190
+ | `--password P` | PDF input: the password of an encrypted file. |
191
+ | `--no-annotations` | PDF input: page content only. |
129
192
  | `--version` | Print the version. |
130
193
 
131
- Exit status 1 on unreadable input, invalid SVG, malformed fonts or write errors (including
194
+ Exit status 1 on unreadable input, invalid SVG, PDF that cannot be read, malformed fonts or write errors (including
132
195
  a closed standard output); status 2 on invalid arguments: `--dpi` or `--simplify` not
133
- positive, `--quality` outside 1–100, or an image `--format` with `--pdf-a`, `--jxl` or
134
- `--no-compress`.
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`.
135
198
 
136
199
  ## 4. Document and Page
137
200
 
138
201
  ```python
139
202
  Document(unit="pt", title=None, author=None, subject=None, keywords=None, creator=None,
140
203
  font_dirs=None, system_fonts=True, base_dir=None, font_db=None, filters=False,
141
- color_mode="rgb", ink_limit=None, icc_profile=None, pdf_a=None, creation_date=None)
204
+ color_mode="rgb", ink_limit=None, icc_profile=None, pdf_a=None, creation_date=None,
205
+ font_downloads=None, text_as_paths=False)
142
206
  ```
143
207
 
144
208
  A document records what is drawn on its pages: commands, the images and fonts as they were
@@ -153,7 +217,9 @@ The constructor takes document-level choices. `unit` is the document's unit
153
217
  `base_dir` resolves relative paths given to `draw_image`, `draw_svg`, `add_font`, `attach`
154
218
  and `icc_profile` (default: the working directory), and the references of SVGs placed from
155
219
  text or bytes. `filters` applies to SVGs placed with `draw_svg`. `font_db` shares a
156
- `FontDB` between documents. `creation_date` (a `datetime`; naive means local time) is
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
157
223
  written as the creation and modification date; PDF/A files default to the current time,
158
224
  other files have no date unless one is given.
159
225
 
@@ -174,8 +240,10 @@ mode: only its luminosity matters, and viewers disagree on the luminosity of ink
174
240
  | `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`. |
175
241
  | `add_font(data_or_path, family=None, weight=None, italic=None)` | Register a font file (path or bytes) under `family` (default: its own name). |
176
242
  | `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. |
177
- | `to_bytes(*, compress=True, compression="balanced", simplify=None, images=None, font_hinting=False)` | The PDF as `bytes` (a document without pages gets an empty A4 page), with this output's options. |
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. |
178
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`. |
179
247
  | `pages` | The pages, in order. |
180
248
 
181
249
  | PDF option | Meaning |
@@ -185,6 +253,7 @@ mode: only its luminosity matters, and viewers disagree on the luminosity of ink
185
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)). |
186
254
  | `images` | An `ImagePolicy`: how images are stored ([Image encoding](#image-encoding)). |
187
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)). |
188
257
 
189
258
  ```python
190
259
  ImagePolicy(quality=None, jxl=False)
@@ -353,7 +422,7 @@ where the path is under its middle, rotated with the path there (a kerned glyph'
353
422
  counts its kerning, as in SVG); glyphs whose middle is past either end are left out.
354
423
  `side="right"` runs the path the other way, `method="stretch"` bends the glyph outlines
355
424
  along it (drawn as paths, not text). A span's `baseline_shift` moves its glyphs off the
356
- path; underlines and links of spans are not drawn.
425
+ path; underlines, strikethroughs and links of spans are not drawn.
357
426
 
358
427
  ### 5.5 Images and SVG
359
428
 
@@ -361,6 +430,7 @@ path; underlines and links of spans are not drawn.
361
430
  |---|---|
362
431
  | `draw_image(source, x, y, width=None, height=None, preserve_aspect_ratio="xMidYMid meet", opacity=1.0, smooth=None)` | PNG, JPEG or JPEG XL from a path, bytes or `data:` URI. Without a size, one pixel per unit; with one dimension the aspect ratio is kept. `smooth=False` keeps pixels sharp when scaled. Returns `False` if the image cannot be loaded. |
363
432
  | `draw_svg(svg, x=0, y=0, width=None, height=None, base_dir=None, clip=True)` | Place SVG text, bytes, a path or an `SVGDocument`. Default size: its CSS pixel size. `clip` clips to its viewport. |
433
+ | `draw_pdf(source, page=0, x=0, y=0, width=None, height=None, box="crop", annotations=True, password=None)` | Place a page of a PDF (a path, bytes or a binary file) as a form, clipped to its `box` (`crop`, `media`, `bleed`, `trim`, `art`). Default size: the box's, in points (rotated); one dimension keeps the aspect ratio. A page placed again in the document is the same form ([Reading PDF](#reading-pdf)). |
364
434
 
365
435
  A `vec_io.draw` drawing draws itself: `drawing.draw(page, x, y, width=None, height=None)`
366
436
  ([11](#11-drawings-vec_iodraw)).
@@ -490,13 +560,15 @@ The text style comes from the canvas state: `font`, `fill_style` (or `text_box`'
490
560
  ```python
491
561
  Span(text, font_family=None, font_size=None, font_weight=None, font_style=None,
492
562
  color=None, url=None, letter_spacing=None, word_spacing=None, underline=False,
493
- baseline_shift=None, font_scale=None)
563
+ baseline_shift=None, font_scale=None, strikethrough=False)
494
564
  ```
495
565
 
496
566
  A run of text with its own style; `None` inherits the canvas state. `url` makes the run a
497
- link; `underline` draws a line under it. `font_scale` multiplies the size. `baseline_shift`
498
- raises the run: `"super"` (0.33 em of the canvas font size), `"sub"` (−0.2 em) or a number
499
- of em (positive up). Exponents: `["10", Span("5", baseline_shift="super", font_scale=0.7)]`.
567
+ link; `underline` draws a line under it; `strikethrough` draws one through it at the font's
568
+ strikeout position and thickness (OS/2 `yStrikeoutPosition`, `yStrikeoutSize`; without them
569
+ 0.28 em up, as thick as the underline), as SVG's `line-through` is drawn. `font_scale`
570
+ multiplies the size. `baseline_shift` raises the run: `"super"` (0.33 em of the canvas font
571
+ size), `"sub"` (−0.2 em) or a number of em (positive up). Exponents: `["10", Span("5", baseline_shift="super", font_scale=0.7)]`.
500
572
 
501
573
  | `TextLayout` member | |
502
574
  |---|---|
@@ -535,7 +607,7 @@ para.draw(page, x, y, fill="black")
535
607
  | `measure(content, font, db=None, **options)` | `Extent(width, ascent, descent)` of that run. |
536
608
  | `layout(content, font, width, height=None, db=None, *, align, line_height, overflow, breaking, kerning, ligatures, paragraph_spacing, first_indent, letter_spacing, word_spacing)` | `Paragraphs`: the [layout](#6-text-layout) options; `draw(canvas, x, y, fill=None)`, `width`, `height`, `lines`, `baselines`, `overflow`, `remainder`, `line_text(k)`, `line_cells()` (placed `Line`s). |
537
609
  | `GlyphRun` | `text`, `width`, `ascent`, `descent`, `extent`; `segments` (`Segment`: one face and style, with `gids`, `texts`, `chars`, `advances`, `adjusts`); `glyphs` (`Glyph`: `face`, `gid`, `advance`, `adjust`, `text`, `char`, `style`, `synth`). |
538
- | `default_db()` | The process-wide `FontDB` (installed fonts and `VEC_IO_FONT_DIRS`). |
610
+ | `default_db()` | The process-wide `FontDB` (installed fonts, `VEC_IO_FONT_DIRS`, and font downloads as `VEC_IO_FONT_DOWNLOADS` says). |
539
611
  | `NoFontError` | `ValueError`: no outline font at all for the text. |
540
612
 
541
613
  Lengths are in the unit of `size` (on a page: `page.font` carries the document's unit).
@@ -774,8 +846,9 @@ centered).
774
846
  | `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. |
775
847
  | `document(**options)` | A new `Document` in the drawing's unit with one page holding the drawing; `options`: of the `Document`. |
776
848
  | `render(dpi=96, simplify=None, background=None, **options)` | The drawing as an `Image` ([5.9](#59-rendering-and-image-output)). |
777
- | `to_svg(**options)` | SVG source of what the drawing draws. |
778
- | `save(file, format=None, **options)` | PDF, SVG, 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` for PDF; `dpi`, `simplify`, `background`, `png`, `jpeg`, `jxl`, `avif` for images). |
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). |
779
852
 
780
853
  ### 11.3 Elements
781
854
 
@@ -788,7 +861,7 @@ centered).
788
861
  | `Polyline`, `Polygon` | `Polyline(points, …)`; `points` as `[(x, y), …]` or flat numbers |
789
862
  | `Path` | `Path(d="", …)`: SVG path data or a `vec_io.Path`, with the builder methods `M m L l H h V v C c S s Q q T t A a Z` (SVG semantics); `d` is the path data, `outline()` the `vec_io.Path` |
790
863
  | `Text` | `Text(text, font_size, x=0, y=0, line_height=1.2, path=None, offset=0, side="left", method="align", …)`: a string (`\n` stacks lines `line_height` em apart) or rich content (strings, `TSpan`, `Span`) on one line; with `path` (a shape element, `Path` or path data), along it ([5.4](#54-text)) |
791
- | `TSpan` | `TSpan(text, font_family=…, font_size=…, font_weight=…, font_style=…, fill=…, underline=…, baseline_shift=…, url=…)`: a styled run (a `Span`) |
864
+ | `TSpan` | `TSpan(text, font_family=…, font_size=…, font_weight=…, font_style=…, fill=…, underline=…, strikethrough=…, baseline_shift=…, url=…)`: a styled run (a `Span`) |
792
865
  | `TextBox` | `TextBox(content, x, y, width, height=None, …)`: wrapped text, box top-left at `(x, y)`; the [layout](#6-text-layout) options as keywords |
793
866
  | `Image` | `Image(x, y, width, height, path=None, data=None, preserve_aspect_ratio="xMidYMid meet", smooth=None, …)`: PNG, JPEG or JPEG XL |
794
867
  | `SVG` | `SVG(source, x=0, y=0, width=None, height=None, base_dir=None, …)`: an SVG document drawn in the box, with everything SVG has, CSS style sheets included (filters when enabled) |
@@ -869,7 +942,8 @@ quality=None)`, on 8-bit interleaved samples. An A4 page at 300 dpi encodes as J
869
942
  ### JPEG XL
870
943
 
871
944
  JPEG XL goes through the system's libjxl, 0.9 or later, loaded on first use
872
- (`VEC_IO_LIBJXL` gives its path when it is not found by name);
945
+ (`VEC_IO_LIBJXL` gives its path when it is not found by name, `VEC_IO_NO_LIBJXL=1`
946
+ turns it off);
873
947
  `vec_io.image.codecs.jxl_available()` tells whether it was found.
874
948
 
875
949
  **Reading.** JPEG XL images (`draw_image`, `<image>`, `feImage`,
@@ -924,6 +998,19 @@ Alpha is always lossless. Encoder speed follows `compression`: 8 (`fast`),
924
998
  is 26 KB at quality 90 and 12 KB at 70, but 115 KB lossless, more than its
925
999
  81 KB PNG.
926
1000
 
1001
+ ### JPEG 2000 and JBIG2
1002
+
1003
+ JPEG 2000 and JBIG2 are decoded through the system's OpenJPEG 2.x (`libopenjp2`) and
1004
+ jbig2dec (`libjbig2dec`), loaded on first use; neither is required.
1005
+ `vec_io.image.jpx.available()` and `vec_io.image.jbig2.available()` tell whether they
1006
+ were found; `VEC_IO_OPENJPEG` and `VEC_IO_JBIG2DEC` give their paths when they are not
1007
+ found by name, `VEC_IO_NO_OPENJPEG=1` and `VEC_IO_NO_JBIG2DEC=1` turn them off.
1008
+ `jpx.decode(data, max_pixels=2**28)` reads JP2 files and codestreams into a `JPXImage`
1009
+ (8- or 16-bit interleaved samples at full size, alpha apart, color space and ICC
1010
+ profile); `jbig2.decode(data, globals_=None)` reads embedded JBIG2 streams into
1011
+ `(width, height, rows)` of packed bits, 1 = black. Sizes in the headers are checked
1012
+ against the limit before decoding; errors raise `JPXError` and `JBIG2Error`.
1013
+
927
1014
  ### Rendering
928
1015
 
929
1016
  The rasterizer runs what a page records, the scene its PDF content is written
@@ -985,7 +1072,10 @@ that resolution:
985
1072
  included. Content that paints nothing on the page (outside it, or clipped
986
1073
  away) goes too.
987
1074
  * Lines and areas whose x values increase are decimated (M4, see
988
- [Lines, segments and areas](#9-lines-segments-and-areas)).
1075
+ [Lines, segments and areas](#9-lines-segments-and-areas)). A decimated line
1076
+ keeps the extent of every column. In images, a dense line drawn in full can look
1077
+ heavier at the pixels it covers only in part (its overlapping pieces add up
1078
+ there), most at its ends.
989
1079
 
990
1080
  It is a choice of the output. Drawing records everything, with what each piece
991
1081
  of content asks for; writing the PDF decides what to leave out (culling runs
@@ -1168,12 +1258,12 @@ elements are transparent; `kernelUnitLength` is ignored) and drawn through
1168
1258
  | Shapes | `rect` (rounded), `circle`, `ellipse`, `line`, `polyline`, `polygon`, `path` (all commands, arcs) |
1169
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) |
1170
1260
  | 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` |
1171
- | CSS | `@media` evaluated for print; `<style media="…">` |
1261
+ | CSS | `@media` evaluated for print; `<style media="…">`; `@font-face`; `@import` of Google Fonts CSS ([Font downloads](#font-downloads)) |
1172
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` |
1173
1263
  | Paint servers | `linearGradient`, `radialGradient` (focal point, `href` inheritance, `gradientTransform`, `spreadMethod`, `stop-opacity`), `pattern` |
1174
1264
  | Compositing | group opacity, `clipPath` (any shapes and text, `objectBoundingBox`, nested), luminance `mask` |
1175
1265
  | Markers | `marker-start`/`-mid`/`-end`, `orient` (`auto`, `auto-start-reverse`, angles), `viewBox`, `markerUnits`, `overflow`; drawn through `PathMarker` |
1176
- | 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), `dominant-baseline`, `baseline-shift` (`sub`, `super`, lengths, percentages; nested shifts add up), `xml:space` (inherited) |
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) |
1177
1267
  | 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` |
1178
1268
  | Filters | see [Filters](#14-filters) |
1179
1269
  | vec_io attributes | `data-rasterize`, `data-simplify`, `data-quality`, `data-filters` |
@@ -1192,14 +1282,19 @@ Fonts are embedded as subsets, always. For each character, the font is the first
1192
1282
  and italic faces are synthesized). A family that is not installed resolves to its
1193
1283
  first installed metric alias: Helvetica and Arial to Liberation Sans, Arimo, Nimbus
1194
1284
  Sans, TeX Gyre Heros…; Times and Times New Roman to Liberation Serif, Tinos, Nimbus
1195
- Roman…; Courier and Courier New to Liberation Mono, Cousine, Nimbus Mono…; else the
1285
+ Roman…; Courier and Courier New to Liberation Mono, Cousine, Nimbus Mono… (not when
1286
+ the list names one of them later: `Helvetica, Nimbus Sans, Liberation Sans` keeps
1287
+ its order); else, when a download source has a family of that name, to that family
1288
+ downloaded ([Font downloads](#font-downloads)); else the
1196
1289
  next family. Generic families resolve to the first installed family of their list
1197
1290
  (`serif`: Times New Roman, Liberation Serif, DejaVu Serif, …; `sans-serif`: Arial,
1198
1291
  Helvetica, Liberation Sans, DejaVu Sans, …; `monospace`: Courier New, Liberation Mono,
1199
- DejaVu Sans Mono, …), else to the best installed face of all.
1292
+ DejaVu Sans Mono, …), else to the best installed face of all; for text with no font at
1293
+ all, to Noto Sans, Noto Serif or Noto Sans Mono from Google Fonts.
1200
1294
  2. The generic family the list implies (`serif` for Times-like names, `monospace` for
1201
1295
  Courier-like ones, else `sans-serif`).
1202
- 3. Any installed font that has the character (Greek, Cyrillic, CJK, …).
1296
+ 3. Any installed font that has the character (Greek, Cyrillic, CJK, …), then any family
1297
+ downloaded for this font database that has it.
1203
1298
  4. The first font's `.notdef` glyph (a character no font has).
1204
1299
 
1205
1300
  The standard 14 PDF fonts are used only when asked for: a family naming one (`Helvetica`,
@@ -1209,9 +1304,10 @@ WinAnsi (Symbol and ZapfDingbats theirs) with the Adobe metrics, and is not kern
1209
1304
  characters take steps 1–4. SVG text is always embedded.
1210
1305
 
1211
1306
  Text needs an outline font. With none available at all (no installed font, or
1212
- `system_fonts=False` without `font_dirs`, `VEC_IO_FONT_DIRS`, `@font-face` or `add_font`),
1213
- drawing or measuring text raises `NoFontError` (`vec_io.fonts.fontdb`, a `ValueError`) naming
1214
- these remedies; documents without text need no font. A silent fallback to the standard 14
1307
+ `system_fonts=False` without `font_dirs`, `VEC_IO_FONT_DIRS`, `@font-face` or `add_font`,
1308
+ 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
1310
+ no font. A silent fallback to the standard 14
1215
1311
  fonts would make the PDF depend on the viewer's fonts, differ from vec_io's own images,
1216
1312
  and fail anyway in image output and PDF/A, which need outlines.
1217
1313
 
@@ -1226,7 +1322,17 @@ CFF outlines,
1226
1322
  name-keyed or CID-keyed, as a CID-keyed CFF (`FontFile3/CIDFontType0C`) with
1227
1323
  unused subroutines emptied. A 5 MB CJK OpenType font typically adds a few
1228
1324
  kilobytes.
1229
- Text remains selectable and searchable (ToUnicode maps).
1325
+ Text remains selectable and searchable (ToUnicode maps). EPS output embeds the same subsets
1326
+ as Type 42 and CFF fonts ([EPS output](#eps-output)).
1327
+
1328
+ `Document(text_as_paths=True)` (`convert(…, text_as_paths=True)`, CLI `--text-as-paths`)
1329
+ draws text as the outlines of its glyphs instead: filled, stroked or clipped paths, placed
1330
+ as the text would be (kerning, spacing, synthetic bold and italic), the same pixels within
1331
+ rounding. No font is written, so PDF and SVG output look the same without the fonts, and
1332
+ their text cannot be selected or searched. Text filled with a flat color draws each glyph
1333
+ from a form defined once (SVG: a `<use>` of a definition); text with a gradient or pattern,
1334
+ stroked or clipping text are paths. A page of 4,500 characters in Liberation Sans is about
1335
+ 11 KB this way (4.5 KB as text); a plot's few labels add a few KB.
1230
1336
  Pair kerning (GPOS `kern`, else the `kern` table) applies to every text: one-line text,
1231
1337
  paragraphs and SVG text (`font-kerning: none` and `font_kerning="none"` turn it off).
1232
1338
  Standard ligatures (GSUB `liga`) apply to paragraphs and to `vec_io.text.shape` with
@@ -1259,10 +1365,101 @@ others are named after Adobe TN 5902 (`RobotoFlex_26.667opsz_650wght_85wdth`). A
1259
1365
  `@font-face` with a `font-weight` range (`100 900`) takes the font's own axis.
1260
1366
  Malformed variation data raises `FontError` when the font is used.
1261
1367
 
1368
+ ### Font downloads
1369
+
1370
+ A named family that is neither installed nor replaced by an installed metric alias is
1371
+ downloaded when a source has a family of that name, kept in a cache, and used like an
1372
+ installed font. The sources, in order:
1373
+
1374
+ | Source | Families | Files |
1375
+ |---|---|---|
1376
+ | Google Fonts | the 1,959 of the bundled list `google_families.txt` | variable files when the family has them, else the static file of each style used |
1377
+ | URW base 35 | Nimbus Sans, Nimbus Sans Narrow, Nimbus Roman, Nimbus Mono PS, C059, P052, URW Bookman, URW Gothic, Z003, Standard Symbols PS, D050000L | the TrueType file of each face used, from `github.com/ArtifexSoftware/urw-base35-fonts` at tag `20200910`, checked against the SHA-256 in `vec_io/fonts/urw.py` |
1378
+ | CTAN | TeX Gyre Adventor, Bonum, Chorus, Cursor, Heros, Pagella, Schola, Termes; Latin Modern Roman, Sans, Mono (the 10 pt designs); CMU Serif, CMU Sans Serif, CMU Typewriter Text | the OpenType (CFF) file of each face used, from `mirrors.ctan.org` |
1379
+ | Fontsource | the 119 families of `fontsource_families.txt` that are not Google's (DejaVu, Iosevka, Monaspace, Geist Sans, FiraGO…) | the TrueType files of each style used, one per unicode subset, from `cdn.jsdelivr.net` |
1380
+ | Fontshare | the 100 families of `fontshare_families.txt` (Satoshi, General Sans, Clash Display…) | variable files when the family has them, else the static file of each style used, from `cdn.fontshare.com` |
1381
+
1382
+ Downloads are on by default:
1383
+
1384
+ | Setting | Effect |
1385
+ |---|---|
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. |
1389
+
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`.
1392
+
1393
+ * **Names.** A family is fetched by its own name only, from the first source that lists
1394
+ it (Google first, so `Anton` comes from Google, not Fontshare); when that download fails,
1395
+ the next source that lists it is tried. Metric aliases are never downloaded: `Helvetica`
1396
+ fetches nothing (no source has a family of that name; the URW and TeX Gyre families
1397
+ named after it are stand-ins only when installed), `Nimbus Sans` fetches Nimbus Sans.
1398
+ Other names ("SF Pro", a typo) never cause a request. In SVG, the families of an
1399
+ `@import url(https://fonts.googleapis.com/css2?family=…)` count as Google families, and
1400
+ `@font-face` sources on `fonts.gstatic.com` are fetched into the cache; other remote URLs
1401
+ are never fetched.
1402
+ * **Styles.** A static face is chosen by CSS matching among the faces the source has
1403
+ (Lato at weight 450 fetches Lato Regular); a variable file serves every weight, width,
1404
+ slant and optical size exactly as an installed copy. A Fontsource style is several files,
1405
+ one per unicode subset (`latin`, `cyrillic`…): they act as one face, a character taking
1406
+ the first file that has it, the family's default subset first.
1407
+ * **Generic families.** For text with no font at all (a container, CI), `serif` uses Noto
1408
+ Serif, `monospace` Noto Sans Mono, and the other generic families Noto Sans, from Google,
1409
+ instead of raising `NoFontError`. Per-script families (Noto Sans JP, …) are fetched only
1410
+ when named.
1411
+ * **Precedence.** An installed copy of a family always wins. In the per-character fallback,
1412
+ downloaded families come after the installed fonts.
1413
+ * **Cache.** vec_io's user cache directory (beside `fonts.json`), or
1414
+ `VEC_IO_FONT_DOWNLOADS_DIR`: a folder per source (`google-fonts`, `urw-base35`, `ctan`,
1415
+ `fontsource`, `fontshare`; `cmap-resources`: Adobe's predefined CJK CMaps, fetched for
1416
+ PDF input the same way), in it a folder per family and version (`inter/v20/`,
1417
+ `nimbussans/20200910/`, `dejavusans/5.3.0/`; CTAN: the date of the first download) with
1418
+ the font files, the licence and `source.json` (URLs, SHA-256, date, licence). A cached
1419
+ family is used as it is, with no network check, until its folder is deleted (Google:
1420
+ also `refresh`): the same machine draws the same glyphs every time, and a copied cache
1421
+ folder gives other machines the same. Files are written atomically, and a lock file per
1422
+ family keeps two processes from downloading it at once.
1423
+ * **Network.** `urllib` over HTTPS with certificate checks, to `fonts.google.com`,
1424
+ `fonts.googleapis.com`, `fonts.gstatic.com`, `raw.githubusercontent.com`,
1425
+ `mirrors.ctan.org`, `api.fontsource.org`, `cdn.jsdelivr.net`, `api.fontshare.com` and
1426
+ `cdn.fontshare.com` only (redirects within them; `mirrors.ctan.org` also to the HTTPS
1427
+ mirror it picks, for the same path); 20 s per request, 40 MB per download (a style's
1428
+ files, or a family's variable files). Every file is checked to be a font vec_io can
1429
+ embed. A family that fails (offline, an HTTP error, a corrupt, oversized or, for URW,
1430
+ mismatched file) is skipped, with one `FontDownloadWarning` per family and process naming
1431
+ the reason, and is not tried again in the process.
1432
+ * **Licences.** Google Fonts families are under the OFL, Apache 2.0 or the Ubuntu Font
1433
+ Licence; Fontsource's under the OFL, Apache 2.0, MIT, CC0 or the Unlicense; CTAN's under
1434
+ the GUST Font License (TeX Gyre, Latin Modern) or the OFL (CMU); the URW fonts under the
1435
+ AGPL-3.0 with an exception for fonts embedded in PostScript or PDF files (the
1436
+ repository's `LICENSE` and `COPYING` are kept beside them). Fontshare families are under
1437
+ the OFL or the ITF Free Font License (FFL), which allows embedding in PDF files but not
1438
+ subsetting; vec_io embeds them as subsets like any font. The licence is recorded in
1439
+ `source.json`, and its text written beside the files (Fontshare: from the family's
1440
+ download archive, when it can be read). vec_io bundles no font.
1441
+
1442
+ `vec_io.fonts.download`:
1443
+
1444
+ | Function | |
1445
+ |---|---|
1446
+ | `download(family)` | Download every style of a family into the cache from the first source that lists it (a name no list has: Google Fonts), unless it is there; returns the paths of its font files. Raises `FontDownloadError` (an `OSError`). |
1447
+ | `source_of(family)` | The first source module that lists the family, or `None`. |
1448
+ | `sources()` | The source modules in order: `google`, `urw`, `ctan`, `fontsource`, `fontshare`. |
1449
+ | `cached()` | The cached families of each source, by source name. |
1450
+ | `cache_root()` | The cache folder (`None` without a user cache directory). |
1451
+
1452
+ Each source module (`vec_io.fonts.google`, `urw`, `ctan`, `fontsource`, `fontshare`) has
1453
+ `download(family)`, `cached()`, `cache_dir()` and `listed(name)`. `google.download(family,
1454
+ styles=None)` also takes any name the bundled list lacks, and `styles` of a static family
1455
+ (`"400"`, `"700i"`, …; default all); `google.refresh(family)` downloads a cached family
1456
+ again (the styles it has), replacing the cached version.
1457
+
1262
1458
  ### Installed fonts
1263
1459
 
1264
- For machine-independent output, pass `system_fonts=False` and provide fonts
1265
- with `font_dirs`, `@font-face` or `add_font`. `VEC_IO_FONT_DIRS` (directories separated by
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
1266
1463
  `os.pathsep`) adds font directories to every `FontDB`, also with `system_fonts=False`; the
1267
1464
  tests point it at their own font.
1268
1465
 
@@ -1359,12 +1556,92 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
1359
1556
  options gives the same bytes. PDF/A files carry the current date (taken when the
1360
1557
  document is made) unless `creation_date` is given.
1361
1558
  * PDF/A-2b, 2u and 3b: see [PDF/A](#pdfa).
1559
+ * Transparency: see [Transparency flattening](#transparency-flattening).
1560
+ * EPS: see [EPS output](#eps-output).
1362
1561
  * CMYK (`Document(color_mode="cmyk")`): see [Document](#4-document-and-page).
1363
1562
  Limits: the conversion is naive (not ICC-managed); JPEG files are kept
1364
1563
  in their own color space; a spot color in a gradient uses its CMYK
1365
1564
  alternate; inside masks, images (including heatmaps in `image` mode)
1366
1565
  stay in CMYK.
1367
1566
 
1567
+ ### Transparency flattening
1568
+
1569
+ `flatten_transparency=True` (`Document.to_bytes`/`save`, `Drawing.to_svg`, `convert`,
1570
+ `--flatten-transparency`) writes pages without transparency: no `/ca` or `/CA` below 1, no
1571
+ soft mask, no transparency group (SVG: no `opacity`, no `<mask>`). Off by default; pages
1572
+ without transparency are written as they are.
1573
+
1574
+ * A translucent shape T is drawn opaque in its color composited over what lies under it
1575
+ (the opaque shape that covers it whole, else the white page), then once for each shape U
1576
+ under it that its box meets, in drawing order, clipped to U, in T's color composited over
1577
+ U's. These pieces are opaque shapes for the translucent shapes after them; later ones
1578
+ paint over earlier ones. Only clips are used (`W n`, `<clipPath>`), no polygon booleans.
1579
+ * Strokes under translucent content are clipped to by their outline (vec_io's stroker).
1580
+ * Flat colors, gradients (a gradient with composited stops, also for gradients whose stops
1581
+ have alpha), images (new samples) and text are flattened; group opacity flattens the
1582
+ group as one layer, then composites it. Forms placed under or as translucent content are
1583
+ drawn per placement; others keep their reuse.
1584
+ * Fallback (`flatten_fallback`): for content that cannot be flattened (a gradient over a
1585
+ 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`
1589
+ (default 600), lossless, 2 pixels wider than its cells and clipped to them and to the
1590
+ outline of what it shows (up to 2,000 shapes); content drawn after it stays vectors, over
1591
+ it. `"opaque"` draws that content as if its alpha were 1 (one
1592
+ `vec_io.flatten.FlattenWarning` per output); `"error"` raises `ValueError` naming the
1593
+ page and what failed. A dense translucent scatter is the expected over-budget case.
1594
+ * Anti-aliasing: where a translucent shape's edge lies over another shape, its opaque draw
1595
+ and the piece over that shape each cover the edge pixel in part, as viewers draw them:
1596
+ a faint seam of up to a quarter of the color difference.
1597
+ * Simplification (`simplify`) does not apply to the pages that change.
1598
+
1599
+ ### EPS output
1600
+
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).
1604
+
1605
+ * Header: `%%BoundingBox` and `%%HiResBoundingBox` of the page (points), `%%Creator:
1606
+ vec_io`, `%%Title` (the document's), `%%LanguageLevel: 3`, `%%DocumentData: Clean7Bit`,
1607
+ `%%DocumentNeededResources` for standard 14 fonts; then a prolog (`VecIO` dictionary of
1608
+ short procedures), the setup (fonts, images, shadings, forms), the page and `showpage`.
1609
+ Every byte is 7-bit ASCII and lines stay under 256 characters: binary data is ASCII85.
1610
+ * 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`).
1613
+ * The page is written as the PDF has it (its content streams, with the output's
1614
+ `simplify`), translated by the C library (`src/epsw.c`): paths, fills (nonzero, even-odd),
1615
+ strokes, dashes, caps, joins, miter limits, clips and transforms; DeviceGray, DeviceRGB
1616
+ and DeviceCMYK colors, spot colors as `Separation` color spaces; axial and radial
1617
+ gradients as shadings (types 2 and 3, `shfill`, or shading patterns), smooth cells'
1618
+ lattice mesh as type 5; tiling patterns through `makepattern`; images (`image`, Flate or
1619
+ DCT data read from a `ReusableStreamDecode` file defined once); forms drawn more than once
1620
+ (marker shapes) as procedures, the others in place. PostScript has one current color:
1621
+ the fill and stroke colors are set where they paint.
1622
+ * Fonts: TrueType subsets as CID-keyed Type 42 fonts (`CIDFontType 2`, glyph ids as CIDs,
1623
+ `sfnts` strings of at most 65,534 bytes cut at table and glyph boundaries), CFF subsets
1624
+ (CID-keyed, as in the PDF) through the `FontSetInit` ProcSet's `StartData`
1625
+ (`CIDFontType 0`), both in Type 0 fonts of `Identity-H` (defined when the interpreter
1626
+ has none). `StartData` reads binary data: the call and the font are ASCII85 and executed
1627
+ through a filter (`currentfile /ASCII85Decode filter cvx exec`, and `/FlateDecode` when
1628
+ compressed). Glyphs are placed by
1629
+ `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,
1632
+ stroked or clipped as the text's render mode asks; no font in the file). Standard 14
1633
+ 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`.
1640
+ * Ghostscript (`gs -dEPSCrop`) draws an EPS as it draws the flattened PDF (tests: the same
1641
+ pixels for paths, colors, gradients, images, forms and patterns; text within its edge
1642
+ pixels). Sizes, compressed: 1–3× the PDF on the SVG corpus (ASCII85 adds a quarter, and
1643
+ a prolog of 1.8 KB); uncompressed, the content as PostScript text.
1644
+
1368
1645
  ## 19. Errors
1369
1646
 
1370
1647
  | Exception | Raised for |
@@ -1372,7 +1649,10 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
1372
1649
  | `vec_io.SVGParseError` (`ValueError`) | Input that is not a usable SVG document. |
1373
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. |
1374
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. |
1375
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)). |
1376
1656
  | `vec_io.native.NativeLibraryError` | The C library is not built for this platform or failed to load. |
1377
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`. |
1378
1658
  | `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. |
@@ -1391,10 +1671,12 @@ to 1/10,000 of the path's size; 0 for paths that fill nothing.
1391
1671
  | `geometry.py` | `Matrix`, the packed `Path`, path data, arcs |
1392
1672
  | `lines.py`, `shapes.py`, `cells.py` | lines, segments and areas; rectangles and polygons; cells |
1393
1673
  | `text/` | shaping, measuring and layout from a font database (`Font`, `GlyphRun`, `Span`, `shape`, `measure`, `layout`); `text/breaking.py`: line breaking of paragraphs; `text/path.py`: glyphs along a path |
1394
- | `fonts/` | standard and embedded fonts; `fontdb` (discovery and matching), `sfnt`, `cff`, `cff2`, `variations`, `opentype`, `woff2` |
1674
+ | `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` |
1395
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) |
1396
1676
  | `image/` | `Image` and the output options (`PNG`, `JPEG`, `JXL`, `AVIF`, `ImagePolicy`); `codecs`, `jxl`, `avif`, `resource` (loading, `ImageResource`) |
1397
1677
  | `pdf/` | `objects` (PDF values, numbered when written), `writer`, `images` (image XObjects), `pdfa` |
1678
+ | `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
+ | `pdfread/` | reading PDF: `file` (cross-reference, objects, filters, encryption), `content` (the interpreter), `resources`, `colors`, `functions`, `shadings`, `images`, `fonts`, `reader` (pages, annotations, links, outlines) |
1398
1680
  | `raster/` | rasterizer bindings, resource tables, rasterized groups |
1399
1681
  | `draw.py` | drawings of elements |
1400
1682
  | `arrays.py`, `flate.py`, `threads.py` | array arguments ([§21](#21-array-arguments)); parallel zlib; worker threads (`VEC_IO_THREADS`) |