blitz-pdf 0.1.1 → 0.1.2

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.
Files changed (114) hide show
  1. package/README.md +266 -12
  2. package/THIRD_PARTY_NOTICES.md +4 -2
  3. package/dist/browser.d.ts +1 -1
  4. package/dist/browser.d.ts.map +1 -1
  5. package/dist/document-options.d.ts +36 -0
  6. package/dist/document-options.d.ts.map +1 -0
  7. package/dist/document-options.js +236 -0
  8. package/dist/document-options.js.map +1 -0
  9. package/dist/node.d.ts +1 -1
  10. package/dist/node.d.ts.map +1 -1
  11. package/dist/options.d.ts +35 -1
  12. package/dist/options.d.ts.map +1 -1
  13. package/dist/options.js +21 -14
  14. package/dist/options.js.map +1 -1
  15. package/dist/types.d.ts +71 -1
  16. package/dist/types.d.ts.map +1 -1
  17. package/dist/validation.d.ts +2 -0
  18. package/dist/validation.d.ts.map +1 -0
  19. package/dist/validation.js +7 -0
  20. package/dist/validation.js.map +1 -0
  21. package/examples/zugferd.mjs +41 -0
  22. package/licenses/RUST_DEPENDENCIES.txt +27 -0
  23. package/package.json +3 -2
  24. package/src/browser.ts +1 -1
  25. package/src/document-options.ts +218 -0
  26. package/src/node.ts +1 -1
  27. package/src/options.ts +18 -13
  28. package/src/types.ts +76 -1
  29. package/src/validation.ts +6 -0
  30. package/vendor/README.md +27 -2
  31. package/vendor/krilla/.cargo-ok +1 -0
  32. package/vendor/krilla/.cargo_vcs_info.json +6 -0
  33. package/vendor/krilla/Cargo.lock +1357 -0
  34. package/vendor/krilla/Cargo.toml +165 -0
  35. package/vendor/krilla/LICENSE_APACHE +202 -0
  36. package/vendor/krilla/LICENSE_MIT +21 -0
  37. package/vendor/krilla/README.md +156 -0
  38. package/vendor/krilla/examples/basic.rs +117 -0
  39. package/vendor/krilla/examples/empty_document.rs +25 -0
  40. package/vendor/krilla/examples/parley.rs +174 -0
  41. package/vendor/krilla/examples/simple_text.rs +118 -0
  42. package/vendor/krilla/examples/stream_builder.rs +93 -0
  43. package/vendor/krilla/icc/LICENSE +116 -0
  44. package/vendor/krilla/icc/README.md +1 -0
  45. package/vendor/krilla/icc/sGrey-v2-magic.icc +0 -0
  46. package/vendor/krilla/icc/sGrey-v4.icc +0 -0
  47. package/vendor/krilla/icc/sRGB-v2-magic.icc +0 -0
  48. package/vendor/krilla/icc/sRGB-v4.icc +0 -0
  49. package/vendor/krilla/src/chunk_container.rs +503 -0
  50. package/vendor/krilla/src/configure/PDF_A1.md +227 -0
  51. package/vendor/krilla/src/configure/PDF_A2.md +269 -0
  52. package/vendor/krilla/src/configure/PDF_A3.md +31 -0
  53. package/vendor/krilla/src/configure/PDF_A4.md +211 -0
  54. package/vendor/krilla/src/configure/PDF_UA1.md +202 -0
  55. package/vendor/krilla/src/configure/README.md +23 -0
  56. package/vendor/krilla/src/configure/mod.rs +197 -0
  57. package/vendor/krilla/src/configure/validate.rs +1244 -0
  58. package/vendor/krilla/src/configure/version.rs +134 -0
  59. package/vendor/krilla/src/content.rs +1352 -0
  60. package/vendor/krilla/src/data.rs +49 -0
  61. package/vendor/krilla/src/document.rs +156 -0
  62. package/vendor/krilla/src/error.rs +170 -0
  63. package/vendor/krilla/src/geom.rs +341 -0
  64. package/vendor/krilla/src/graphics/blend.rs +46 -0
  65. package/vendor/krilla/src/graphics/color.rs +552 -0
  66. package/vendor/krilla/src/graphics/graphic.rs +30 -0
  67. package/vendor/krilla/src/graphics/graphics_state.rs +251 -0
  68. package/vendor/krilla/src/graphics/icc.rs +218 -0
  69. package/vendor/krilla/src/graphics/image.rs +835 -0
  70. package/vendor/krilla/src/graphics/mask.rs +128 -0
  71. package/vendor/krilla/src/graphics/mod.rs +14 -0
  72. package/vendor/krilla/src/graphics/paint.rs +434 -0
  73. package/vendor/krilla/src/graphics/separation.rs +86 -0
  74. package/vendor/krilla/src/graphics/shading_function.rs +865 -0
  75. package/vendor/krilla/src/graphics/shading_pattern.rs +60 -0
  76. package/vendor/krilla/src/graphics/tiling_pattern.rs +119 -0
  77. package/vendor/krilla/src/graphics/xobject.rs +150 -0
  78. package/vendor/krilla/src/interactive/action.rs +68 -0
  79. package/vendor/krilla/src/interactive/annotation.rs +283 -0
  80. package/vendor/krilla/src/interactive/destination.rs +289 -0
  81. package/vendor/krilla/src/interactive/mod.rs +3 -0
  82. package/vendor/krilla/src/interchange/embed.rs +240 -0
  83. package/vendor/krilla/src/interchange/metadata.rs +564 -0
  84. package/vendor/krilla/src/interchange/mod.rs +4 -0
  85. package/vendor/krilla/src/interchange/outline.rs +263 -0
  86. package/vendor/krilla/src/interchange/tagging/fmt.rs +733 -0
  87. package/vendor/krilla/src/interchange/tagging/generate.toml +474 -0
  88. package/vendor/krilla/src/interchange/tagging/generated.rs +4754 -0
  89. package/vendor/krilla/src/interchange/tagging/mod.rs +1324 -0
  90. package/vendor/krilla/src/interchange/tagging/tag.rs +686 -0
  91. package/vendor/krilla/src/lib.rs +179 -0
  92. package/vendor/krilla/src/num.rs +26 -0
  93. package/vendor/krilla/src/page.rs +612 -0
  94. package/vendor/krilla/src/pdf.rs +313 -0
  95. package/vendor/krilla/src/resource.rs +436 -0
  96. package/vendor/krilla/src/serialize.rs +1101 -0
  97. package/vendor/krilla/src/stream.rs +368 -0
  98. package/vendor/krilla/src/surface.rs +664 -0
  99. package/vendor/krilla/src/text/cid.rs +488 -0
  100. package/vendor/krilla/src/text/font.rs +351 -0
  101. package/vendor/krilla/src/text/glyph/bitmap.rs +81 -0
  102. package/vendor/krilla/src/text/glyph/colr.rs +581 -0
  103. package/vendor/krilla/src/text/glyph/mod.rs +205 -0
  104. package/vendor/krilla/src/text/glyph/outline.rs +72 -0
  105. package/vendor/krilla/src/text/glyph/svg.rs +34 -0
  106. package/vendor/krilla/src/text/group.rs +463 -0
  107. package/vendor/krilla/src/text/mod.rs +232 -0
  108. package/vendor/krilla/src/text/shape.rs +102 -0
  109. package/vendor/krilla/src/text/type3.rs +514 -0
  110. package/vendor/krilla/src/util.rs +286 -0
  111. package/vendor/stylo/properties/longhands.toml +0 -1
  112. package/vendor/stylo/stylesheets/rule_parser.rs +1 -1
  113. package/wasm/blitz_pdf.js +10 -5
  114. package/wasm/blitz_pdf_bg.wasm +0 -0
@@ -0,0 +1,341 @@
1
+ //! Path geometry.
2
+
3
+ use std::hash::{Hash, Hasher};
4
+
5
+ /// A point.
6
+ #[allow(missing_docs)]
7
+ #[derive(Copy, Clone, PartialEq, Default, Debug)]
8
+ pub struct Point {
9
+ pub x: f32,
10
+ pub y: f32,
11
+ }
12
+
13
+ impl Point {
14
+ /// Create a new point with the given x and y coordinates.
15
+ pub fn from_xy(x: f32, y: f32) -> Self {
16
+ Self { x, y }
17
+ }
18
+
19
+ pub(crate) fn to_tsp(self) -> tiny_skia_path::Point {
20
+ tiny_skia_path::Point::from_xy(self.x, self.y)
21
+ }
22
+ }
23
+
24
+ /// A size.
25
+ #[derive(Copy, Clone, PartialEq, Debug)]
26
+ pub struct Size(tiny_skia_path::Size);
27
+
28
+ impl Size {
29
+ /// Creates a new `Size` from width and height.
30
+ ///
31
+ /// Returns `None` if either the width or the height is not > 0.
32
+ pub fn from_wh(width: f32, height: f32) -> Option<Self> {
33
+ Some(Self(tiny_skia_path::Size::from_wh(width, height)?))
34
+ }
35
+
36
+ /// Returns the width of the size.
37
+ pub fn width(&self) -> f32 {
38
+ self.0.width()
39
+ }
40
+
41
+ /// Returns the height of the size.
42
+ pub fn height(&self) -> f32 {
43
+ self.0.height()
44
+ }
45
+ }
46
+
47
+ /// A rectangle defined by left, top, right and bottom edges.
48
+ #[allow(missing_docs)]
49
+ #[derive(Copy, Clone, PartialEq, Debug)]
50
+ pub struct Rect(tiny_skia_path::Rect);
51
+
52
+ impl Eq for Rect {}
53
+
54
+ impl Hash for Rect {
55
+ fn hash<H: Hasher>(&self, state: &mut H) {
56
+ self.0.left().to_bits().hash(state);
57
+ self.0.top().to_bits().hash(state);
58
+ self.0.right().to_bits().hash(state);
59
+ self.0.bottom().to_bits().hash(state);
60
+ }
61
+ }
62
+
63
+ impl Rect {
64
+ /// Creates new `Rect`.
65
+ pub fn from_ltrb(left: f32, top: f32, right: f32, bottom: f32) -> Option<Self> {
66
+ Some(Self(tiny_skia_path::Rect::from_ltrb(
67
+ left, top, right, bottom,
68
+ )?))
69
+ }
70
+
71
+ /// Apply a transform to the rect.
72
+ pub fn transform(self, transform: Transform) -> Option<Self> {
73
+ Some(Self(self.0.transform(transform.to_tsp())?))
74
+ }
75
+
76
+ /// Creates new `Rect`.
77
+ pub fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Option<Self> {
78
+ Some(Self(tiny_skia_path::Rect::from_xywh(x, y, w, h)?))
79
+ }
80
+
81
+ /// Returns the left edge.
82
+ pub fn left(&self) -> f32 {
83
+ self.0.left()
84
+ }
85
+
86
+ /// Returns the top edge.
87
+ pub fn top(&self) -> f32 {
88
+ self.0.top()
89
+ }
90
+
91
+ /// Returns the right edge.
92
+ pub fn right(&self) -> f32 {
93
+ self.0.right()
94
+ }
95
+
96
+ /// Returns the bottom edge.
97
+ pub fn bottom(&self) -> f32 {
98
+ self.0.bottom()
99
+ }
100
+
101
+ /// Returns rect's width.
102
+ pub fn width(&self) -> f32 {
103
+ self.0.width()
104
+ }
105
+
106
+ /// Returns rect's height.
107
+ pub fn height(&self) -> f32 {
108
+ self.0.height()
109
+ }
110
+
111
+ pub(crate) fn to_tsp(self) -> tiny_skia_path::Rect {
112
+ self.0
113
+ }
114
+
115
+ pub(crate) fn from_tsp(rect: tiny_skia_path::Rect) -> Self {
116
+ Self(rect)
117
+ }
118
+
119
+ pub(crate) fn expand(&mut self, other: &Rect) {
120
+ let left = self.left().min(other.left());
121
+ let top = self.top().min(other.top());
122
+ let right = self.right().max(other.right());
123
+ let bottom = self.bottom().max(other.bottom());
124
+ *self = Rect::from_ltrb(left, top, right, bottom).unwrap();
125
+ }
126
+
127
+ pub(crate) fn to_pdf_rect(self) -> pdf_writer::Rect {
128
+ pdf_writer::Rect::new(
129
+ self.left(),
130
+ self.top(),
131
+ self.left() + self.width(),
132
+ self.top() + self.height(),
133
+ )
134
+ }
135
+ }
136
+
137
+ /// A quadrilateral.
138
+ ///
139
+ /// The points should be given in the following order:
140
+ /// 1. bottom-left
141
+ /// 2. bottom-right
142
+ /// 3. top-right
143
+ /// 4. top-left
144
+ ///
145
+ /// Where the coordinate system is Y-down:
146
+ /// ```md
147
+ /// |
148
+ /// |
149
+ /// -----+----> X
150
+ /// |
151
+ /// |
152
+ /// v
153
+ ///
154
+ /// Y
155
+ /// ```
156
+ #[derive(Clone, Copy, PartialEq)]
157
+ pub struct Quadrilateral(pub [Point; 4]);
158
+
159
+ impl From<Rect> for Quadrilateral {
160
+ fn from(r: Rect) -> Self {
161
+ Self([
162
+ Point::from_xy(r.left(), r.bottom()),
163
+ Point::from_xy(r.right(), r.bottom()),
164
+ Point::from_xy(r.right(), r.top()),
165
+ Point::from_xy(r.left(), r.top()),
166
+ ])
167
+ }
168
+ }
169
+
170
+ /// An affine transformation matrix.
171
+ ///
172
+ /// Unlike other types, doesn't guarantee to be valid. This is Skia quirk.
173
+ /// Meaning Transform(0, 0, 0, 0, 0, 0) is ok, while it's technically not.
174
+ /// Non-finite values are also not an error.
175
+ #[allow(missing_docs)]
176
+ #[derive(Copy, Clone, PartialEq, Debug, Default)]
177
+ pub struct Transform(tiny_skia_path::Transform);
178
+
179
+ impl Transform {
180
+ /// Creates an identity transform.
181
+ pub fn identity() -> Self {
182
+ Self(tiny_skia_path::Transform::default())
183
+ }
184
+
185
+ /// Creates a new `Transform`.
186
+ pub fn from_row(sx: f32, ky: f32, kx: f32, sy: f32, tx: f32, ty: f32) -> Self {
187
+ Self(tiny_skia_path::Transform::from_row(sx, ky, kx, sy, tx, ty))
188
+ }
189
+
190
+ /// Creates a new translating `Transform`.
191
+ pub fn from_translate(tx: f32, ty: f32) -> Self {
192
+ Self(tiny_skia_path::Transform::from_translate(tx, ty))
193
+ }
194
+
195
+ /// Creates a new scaling `Transform`.
196
+ pub fn from_scale(sx: f32, sy: f32) -> Self {
197
+ Self(tiny_skia_path::Transform::from_scale(sx, sy))
198
+ }
199
+
200
+ /// Creates a new skewing `Transform`.
201
+ pub fn from_skew(kx: f32, ky: f32) -> Self {
202
+ Self(tiny_skia_path::Transform::from_skew(kx, ky))
203
+ }
204
+
205
+ /// Creates a new rotating `Transform`.
206
+ ///
207
+ /// `angle` in degrees.
208
+ pub fn from_rotate(angle: f32) -> Self {
209
+ Self(tiny_skia_path::Transform::from_rotate(angle))
210
+ }
211
+
212
+ /// Creates a new rotating `Transform` at the specified position.
213
+ ///
214
+ /// `angle` in degrees.
215
+ pub fn from_rotate_at(angle: f32, tx: f32, ty: f32) -> Self {
216
+ Self(tiny_skia_path::Transform::from_rotate_at(angle, tx, ty))
217
+ }
218
+
219
+ /// Return the `sx` component
220
+ pub fn sx(&self) -> f32 {
221
+ self.0.sx
222
+ }
223
+
224
+ /// Return the `sy` component
225
+ pub fn sy(&self) -> f32 {
226
+ self.0.sy
227
+ }
228
+
229
+ /// Return the `kx` component
230
+ pub fn kx(&self) -> f32 {
231
+ self.0.kx
232
+ }
233
+
234
+ /// Return the `kx` component
235
+ pub fn ky(&self) -> f32 {
236
+ self.0.ky
237
+ }
238
+
239
+ /// Return the `tx` component
240
+ pub fn tx(&self) -> f32 {
241
+ self.0.tx
242
+ }
243
+
244
+ /// Return the `ty` component
245
+ pub fn ty(&self) -> f32 {
246
+ self.0.ty
247
+ }
248
+
249
+ /// Returns the inverted transform.
250
+ pub fn invert(&self) -> Option<Self> {
251
+ Some(Self(self.0.invert()?))
252
+ }
253
+
254
+ pub(crate) fn pre_concat(&self, other: Self) -> Self {
255
+ Self(self.0.pre_concat(other.0))
256
+ }
257
+
258
+ pub(crate) fn post_concat(&self, other: Self) -> Self {
259
+ Self(self.0.post_concat(other.0))
260
+ }
261
+
262
+ pub(crate) fn to_tsp(self) -> tiny_skia_path::Transform {
263
+ self.0
264
+ }
265
+
266
+ pub(crate) fn from_tsp(ts: tiny_skia_path::Transform) -> Self {
267
+ Self(ts)
268
+ }
269
+
270
+ pub(crate) fn to_pdf_transform(self) -> [f32; 6] {
271
+ [
272
+ self.0.sx, self.0.ky, self.0.kx, self.0.sy, self.0.tx, self.0.ty,
273
+ ]
274
+ }
275
+ }
276
+
277
+ impl Hash for Transform {
278
+ fn hash<H: Hasher>(&self, state: &mut H) {
279
+ self.0.tx.to_bits().hash(state);
280
+ self.0.ty.to_bits().hash(state);
281
+ self.0.sx.to_bits().hash(state);
282
+ self.0.sy.to_bits().hash(state);
283
+ self.0.kx.to_bits().hash(state);
284
+ self.0.ky.to_bits().hash(state);
285
+ }
286
+ }
287
+
288
+ /// A path.
289
+ pub struct Path(pub(crate) tiny_skia_path::Path);
290
+
291
+ impl Path {
292
+ /// Apply a transformation to the path.
293
+ pub fn transform(self, transform: Transform) -> Option<Self> {
294
+ Some(Self(self.0.transform(transform.to_tsp())?))
295
+ }
296
+ }
297
+
298
+ /// A path builder.
299
+ #[derive(Default)]
300
+ pub struct PathBuilder(tiny_skia_path::PathBuilder);
301
+
302
+ impl PathBuilder {
303
+ /// Create a new path.
304
+ pub fn new() -> Self {
305
+ Self::default()
306
+ }
307
+
308
+ /// Adds beginning of a contour.
309
+ pub fn move_to(&mut self, x: f32, y: f32) {
310
+ self.0.move_to(x, y)
311
+ }
312
+
313
+ /// Adds a line from the last point.
314
+ pub fn line_to(&mut self, x: f32, y: f32) {
315
+ self.0.line_to(x, y)
316
+ }
317
+
318
+ /// Adds a quad curve from the last point to `x`, `y`.
319
+ pub fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) {
320
+ self.0.quad_to(x1, y1, x, y)
321
+ }
322
+ /// Adds a cubic curve from the last point to `x`, `y`.
323
+ pub fn cubic_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) {
324
+ self.0.cubic_to(x1, y1, x2, y2, x, y)
325
+ }
326
+
327
+ /// Close the current contour.
328
+ pub fn close(&mut self) {
329
+ self.0.close()
330
+ }
331
+
332
+ /// Push a rectangle to the path.
333
+ pub fn push_rect(&mut self, rect: Rect) {
334
+ self.0.push_rect(rect.to_tsp())
335
+ }
336
+
337
+ /// Finish the current path.
338
+ pub fn finish(self) -> Option<Path> {
339
+ Some(Path(self.0.finish()?))
340
+ }
341
+ }
@@ -0,0 +1,46 @@
1
+ //! Blending.
2
+
3
+ /// How to blend source and backdrop.
4
+ #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
5
+ #[allow(missing_docs)]
6
+ pub enum BlendMode {
7
+ Normal,
8
+ Multiply,
9
+ Screen,
10
+ Overlay,
11
+ Darken,
12
+ Lighten,
13
+ ColorDodge,
14
+ ColorBurn,
15
+ HardLight,
16
+ SoftLight,
17
+ Difference,
18
+ Exclusion,
19
+ Hue,
20
+ Saturation,
21
+ Color,
22
+ Luminosity,
23
+ }
24
+
25
+ impl BlendMode {
26
+ pub(crate) fn to_pdf(self) -> pdf_writer::types::BlendMode {
27
+ match self {
28
+ BlendMode::Normal => pdf_writer::types::BlendMode::Normal,
29
+ BlendMode::Multiply => pdf_writer::types::BlendMode::Multiply,
30
+ BlendMode::Screen => pdf_writer::types::BlendMode::Screen,
31
+ BlendMode::Overlay => pdf_writer::types::BlendMode::Overlay,
32
+ BlendMode::Darken => pdf_writer::types::BlendMode::Darken,
33
+ BlendMode::Lighten => pdf_writer::types::BlendMode::Lighten,
34
+ BlendMode::ColorDodge => pdf_writer::types::BlendMode::ColorDodge,
35
+ BlendMode::ColorBurn => pdf_writer::types::BlendMode::ColorBurn,
36
+ BlendMode::HardLight => pdf_writer::types::BlendMode::HardLight,
37
+ BlendMode::SoftLight => pdf_writer::types::BlendMode::SoftLight,
38
+ BlendMode::Difference => pdf_writer::types::BlendMode::Difference,
39
+ BlendMode::Exclusion => pdf_writer::types::BlendMode::Exclusion,
40
+ BlendMode::Hue => pdf_writer::types::BlendMode::Hue,
41
+ BlendMode::Saturation => pdf_writer::types::BlendMode::Saturation,
42
+ BlendMode::Color => pdf_writer::types::BlendMode::Color,
43
+ BlendMode::Luminosity => pdf_writer::types::BlendMode::Luminosity,
44
+ }
45
+ }
46
+ }