blitz-pdf 0.1.0 → 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 +300 -10
  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,179 @@
1
+ /*!
2
+ A high-level, ergonomic Rust library creating PDF documents.
3
+
4
+ [krilla] is a high-level Rust crate that allows for the creation of PDF files. It builds
5
+ on top of the [pdf-writer] crate, but abstracts away all complexities that are
6
+ involved in creating a PDF file, instead providing an interface with high-level primitives, such
7
+ as fills, strokes, gradient, glyphs and images which can be used and combined easily
8
+ without having to worry about low-level details.
9
+
10
+ To get started, take a look at the [`document`] module that explains how you can create
11
+ a document using krilla.
12
+
13
+ # Example
14
+
15
+ The following example shows some of the features of krilla in action.
16
+
17
+ The example creates a PDF file with two pages. On the first page,
18
+ we add two small pieces of text, and on the second page we draw a triangle
19
+ with a gradient fill.
20
+
21
+ For more examples, feel free to take a look at the [examples] directory of the GitHub repository.
22
+
23
+ ```
24
+ use std::path::{self, PathBuf};
25
+
26
+ use krilla::color::rgb;
27
+ use krilla::text::Font;
28
+ use krilla::geom::{Point, PathBuilder};
29
+ use krilla::paint::{SpreadMethod, LinearGradient, Stop, FillRule};
30
+ use krilla::text::TextDirection;
31
+ use krilla::paint::Fill;
32
+ use krilla::Document;
33
+ use krilla::page::PageSettings;
34
+ use krilla::num::NormalizedF32;
35
+
36
+ // Create a new document.
37
+ let mut document = Document::new();
38
+ // Load a font.
39
+ let font = {
40
+ let path =
41
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets/fonts/NotoSans-Regular.ttf");
42
+ let data = std::fs::read(&path).unwrap();
43
+ Font::new(data.into(), 0).unwrap()
44
+ };
45
+
46
+ // Add a new page with dimensions 200x200.
47
+ let mut page = document.start_page_with(PageSettings::from_wh(200.0, 200.0).unwrap());
48
+ // Get the surface of the page.
49
+ let mut surface = page.surface();
50
+ // Draw some text.
51
+ surface.draw_text(
52
+ Point::from_xy(0.0, 25.0),
53
+ font.clone(),
54
+ 14.0,
55
+ "This text has font size 14!",
56
+ false,
57
+ TextDirection::Auto
58
+ );
59
+
60
+ surface.set_fill(Some(Fill {
61
+ paint: rgb::Color::new(255, 0, 0).into(),
62
+ opacity: NormalizedF32::new(0.5).unwrap(),
63
+ rule: Default::default(),
64
+ }));
65
+ // Draw some more text, in a different color with an opacity and bigger font size.
66
+ surface.draw_text(
67
+ Point::from_xy(0.0, 50.0),
68
+ font.clone(),
69
+ 16.0,
70
+ "This text has font size 16!",
71
+ false,
72
+ TextDirection::Auto
73
+ );
74
+
75
+ // Finish the page.
76
+ surface.finish();
77
+ page.finish();
78
+
79
+ // Start a new page.
80
+ let mut page = document.start_page_with(PageSettings::from_wh(200.0, 200.0).unwrap());
81
+ // Create the triangle.
82
+ let triangle = {
83
+ let mut pb = PathBuilder::new();
84
+ pb.move_to(100.0, 20.0);
85
+ pb.line_to(160.0, 160.0);
86
+ pb.line_to(40.0, 160.0);
87
+ pb.close();
88
+
89
+ pb.finish().unwrap()
90
+ };
91
+
92
+ // Create the linear gradient.
93
+ let lg = LinearGradient {
94
+ x1: 60.0,
95
+ y1: 0.0,
96
+ x2: 140.0,
97
+ y2: 0.0,
98
+ transform: Default::default(),
99
+ spread_method: SpreadMethod::Repeat,
100
+ stops: vec![
101
+ Stop {
102
+ offset: NormalizedF32::new(0.2).unwrap(),
103
+ color: rgb::Color::new(255, 0, 0).into(),
104
+ opacity: NormalizedF32::ONE,
105
+ },
106
+ Stop {
107
+ offset: NormalizedF32::new(0.8).unwrap(),
108
+ color: rgb::Color::new(255, 255, 0).into(),
109
+ opacity: NormalizedF32::ONE,
110
+ },
111
+ ],
112
+ anti_alias: false,
113
+ };
114
+ let mut surface = page.surface();
115
+
116
+ // Set the fill.
117
+ surface.set_fill(Some(Fill {
118
+ paint: lg.into(),
119
+ rule: FillRule::EvenOdd,
120
+ opacity: NormalizedF32::ONE
121
+ }));
122
+
123
+ // Fill the path.
124
+ surface.draw_path(&triangle);
125
+
126
+ // Finish up and write the resulting PDF.
127
+ surface.finish();
128
+ page.finish();
129
+
130
+ let pdf = document.finish().unwrap();
131
+ let path = path::absolute("basic.pdf").unwrap();
132
+ eprintln!("Saved PDF to '{}'", path.display());
133
+
134
+ // Write the PDF to a file.
135
+ std::fs::write(path, &pdf).unwrap();
136
+ ```
137
+
138
+ # Minimum Supported Rust Version (MSRV)
139
+
140
+ The minimum supported Rust version is **1.92**.
141
+
142
+ [krilla]: https://github.com/LaurenzV/krilla
143
+ [pdf-writer]: https://github.com/typst/pdf-writer
144
+ [examples]: https://github.com/LaurenzV/krilla/tree/main/crates/krilla/examples
145
+ [`document`]: crate::document
146
+ */
147
+
148
+ #![deny(missing_docs)]
149
+ #![forbid(unsafe_code)]
150
+
151
+ mod chunk_container;
152
+ mod graphics;
153
+ mod interactive;
154
+ mod interchange;
155
+ mod resource;
156
+ mod serialize;
157
+ mod util;
158
+
159
+ pub(crate) mod content;
160
+ pub(crate) mod data;
161
+
162
+ pub mod configure;
163
+ pub mod document;
164
+ pub mod error;
165
+ pub mod geom;
166
+ pub mod num;
167
+ pub mod page;
168
+ #[cfg(feature = "pdf")]
169
+ pub mod pdf;
170
+ pub mod stream;
171
+ pub mod surface;
172
+ pub mod text;
173
+
174
+ pub use data::*;
175
+ pub use document::*;
176
+ pub use graphics::*;
177
+ pub use interactive::*;
178
+ pub use interchange::*;
179
+ pub use serialize::SerializeSettings;
@@ -0,0 +1,26 @@
1
+ //! Numerical types.
2
+
3
+ /// An immutable, finite `f32` in a 0..=1 range.
4
+ #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
5
+ #[repr(transparent)]
6
+ pub struct NormalizedF32(tiny_skia_path::NormalizedF32);
7
+
8
+ impl NormalizedF32 {
9
+ /// A `NormalizedF32` value initialized with zero.
10
+ pub const ZERO: Self = NormalizedF32(tiny_skia_path::NormalizedF32::ZERO);
11
+ /// A `NormalizedF32` value initialized with one.
12
+ pub const ONE: Self = NormalizedF32(tiny_skia_path::NormalizedF32::ONE);
13
+
14
+ /// Create a new normalized f32.
15
+ ///
16
+ /// Panics if the number is not normalized.
17
+ pub fn new(num: f32) -> Option<Self> {
18
+ Some(Self(tiny_skia_path::NormalizedF32::new(num)?))
19
+ }
20
+
21
+ /// Returns the value as a primitive type.
22
+ #[inline]
23
+ pub const fn get(self) -> f32 {
24
+ self.0.get()
25
+ }
26
+ }