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.
- package/README.md +266 -12
- package/THIRD_PARTY_NOTICES.md +4 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/document-options.d.ts +36 -0
- package/dist/document-options.d.ts.map +1 -0
- package/dist/document-options.js +236 -0
- package/dist/document-options.js.map +1 -0
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/options.d.ts +35 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +21 -14
- package/dist/options.js.map +1 -1
- package/dist/types.d.ts +71 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +7 -0
- package/dist/validation.js.map +1 -0
- package/examples/zugferd.mjs +41 -0
- package/licenses/RUST_DEPENDENCIES.txt +27 -0
- package/package.json +3 -2
- package/src/browser.ts +1 -1
- package/src/document-options.ts +218 -0
- package/src/node.ts +1 -1
- package/src/options.ts +18 -13
- package/src/types.ts +76 -1
- package/src/validation.ts +6 -0
- package/vendor/README.md +27 -2
- package/vendor/krilla/.cargo-ok +1 -0
- package/vendor/krilla/.cargo_vcs_info.json +6 -0
- package/vendor/krilla/Cargo.lock +1357 -0
- package/vendor/krilla/Cargo.toml +165 -0
- package/vendor/krilla/LICENSE_APACHE +202 -0
- package/vendor/krilla/LICENSE_MIT +21 -0
- package/vendor/krilla/README.md +156 -0
- package/vendor/krilla/examples/basic.rs +117 -0
- package/vendor/krilla/examples/empty_document.rs +25 -0
- package/vendor/krilla/examples/parley.rs +174 -0
- package/vendor/krilla/examples/simple_text.rs +118 -0
- package/vendor/krilla/examples/stream_builder.rs +93 -0
- package/vendor/krilla/icc/LICENSE +116 -0
- package/vendor/krilla/icc/README.md +1 -0
- package/vendor/krilla/icc/sGrey-v2-magic.icc +0 -0
- package/vendor/krilla/icc/sGrey-v4.icc +0 -0
- package/vendor/krilla/icc/sRGB-v2-magic.icc +0 -0
- package/vendor/krilla/icc/sRGB-v4.icc +0 -0
- package/vendor/krilla/src/chunk_container.rs +503 -0
- package/vendor/krilla/src/configure/PDF_A1.md +227 -0
- package/vendor/krilla/src/configure/PDF_A2.md +269 -0
- package/vendor/krilla/src/configure/PDF_A3.md +31 -0
- package/vendor/krilla/src/configure/PDF_A4.md +211 -0
- package/vendor/krilla/src/configure/PDF_UA1.md +202 -0
- package/vendor/krilla/src/configure/README.md +23 -0
- package/vendor/krilla/src/configure/mod.rs +197 -0
- package/vendor/krilla/src/configure/validate.rs +1244 -0
- package/vendor/krilla/src/configure/version.rs +134 -0
- package/vendor/krilla/src/content.rs +1352 -0
- package/vendor/krilla/src/data.rs +49 -0
- package/vendor/krilla/src/document.rs +156 -0
- package/vendor/krilla/src/error.rs +170 -0
- package/vendor/krilla/src/geom.rs +341 -0
- package/vendor/krilla/src/graphics/blend.rs +46 -0
- package/vendor/krilla/src/graphics/color.rs +552 -0
- package/vendor/krilla/src/graphics/graphic.rs +30 -0
- package/vendor/krilla/src/graphics/graphics_state.rs +251 -0
- package/vendor/krilla/src/graphics/icc.rs +218 -0
- package/vendor/krilla/src/graphics/image.rs +835 -0
- package/vendor/krilla/src/graphics/mask.rs +128 -0
- package/vendor/krilla/src/graphics/mod.rs +14 -0
- package/vendor/krilla/src/graphics/paint.rs +434 -0
- package/vendor/krilla/src/graphics/separation.rs +86 -0
- package/vendor/krilla/src/graphics/shading_function.rs +865 -0
- package/vendor/krilla/src/graphics/shading_pattern.rs +60 -0
- package/vendor/krilla/src/graphics/tiling_pattern.rs +119 -0
- package/vendor/krilla/src/graphics/xobject.rs +150 -0
- package/vendor/krilla/src/interactive/action.rs +68 -0
- package/vendor/krilla/src/interactive/annotation.rs +283 -0
- package/vendor/krilla/src/interactive/destination.rs +289 -0
- package/vendor/krilla/src/interactive/mod.rs +3 -0
- package/vendor/krilla/src/interchange/embed.rs +240 -0
- package/vendor/krilla/src/interchange/metadata.rs +564 -0
- package/vendor/krilla/src/interchange/mod.rs +4 -0
- package/vendor/krilla/src/interchange/outline.rs +263 -0
- package/vendor/krilla/src/interchange/tagging/fmt.rs +733 -0
- package/vendor/krilla/src/interchange/tagging/generate.toml +474 -0
- package/vendor/krilla/src/interchange/tagging/generated.rs +4754 -0
- package/vendor/krilla/src/interchange/tagging/mod.rs +1324 -0
- package/vendor/krilla/src/interchange/tagging/tag.rs +686 -0
- package/vendor/krilla/src/lib.rs +179 -0
- package/vendor/krilla/src/num.rs +26 -0
- package/vendor/krilla/src/page.rs +612 -0
- package/vendor/krilla/src/pdf.rs +313 -0
- package/vendor/krilla/src/resource.rs +436 -0
- package/vendor/krilla/src/serialize.rs +1101 -0
- package/vendor/krilla/src/stream.rs +368 -0
- package/vendor/krilla/src/surface.rs +664 -0
- package/vendor/krilla/src/text/cid.rs +488 -0
- package/vendor/krilla/src/text/font.rs +351 -0
- package/vendor/krilla/src/text/glyph/bitmap.rs +81 -0
- package/vendor/krilla/src/text/glyph/colr.rs +581 -0
- package/vendor/krilla/src/text/glyph/mod.rs +205 -0
- package/vendor/krilla/src/text/glyph/outline.rs +72 -0
- package/vendor/krilla/src/text/glyph/svg.rs +34 -0
- package/vendor/krilla/src/text/group.rs +463 -0
- package/vendor/krilla/src/text/mod.rs +232 -0
- package/vendor/krilla/src/text/shape.rs +102 -0
- package/vendor/krilla/src/text/type3.rs +514 -0
- package/vendor/krilla/src/util.rs +286 -0
- package/vendor/stylo/properties/longhands.toml +0 -1
- package/vendor/stylo/stylesheets/rule_parser.rs +1 -1
- package/wasm/blitz_pdf.js +10 -5
- package/wasm/blitz_pdf_bg.wasm +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
//! This example shows how to use parley to create advanced layouted text.
|
|
2
|
+
|
|
3
|
+
use std::borrow::Cow;
|
|
4
|
+
use std::collections::HashMap;
|
|
5
|
+
use std::path;
|
|
6
|
+
|
|
7
|
+
use krilla::color::rgb;
|
|
8
|
+
use krilla::geom::Point;
|
|
9
|
+
use krilla::num::NormalizedF32;
|
|
10
|
+
use krilla::page::PageSettings;
|
|
11
|
+
use krilla::paint::Fill;
|
|
12
|
+
use krilla::text::Font;
|
|
13
|
+
use krilla::text::{GlyphId, KrillaGlyph};
|
|
14
|
+
use krilla::Document;
|
|
15
|
+
use parley::layout::Alignment;
|
|
16
|
+
use parley::style::{FontFamily, FontFamilyName, FontWeight, LineHeight, StyleProperty};
|
|
17
|
+
use parley::{FontContext, LayoutContext};
|
|
18
|
+
|
|
19
|
+
fn main() {
|
|
20
|
+
// The text that we want to insert into the PDF.
|
|
21
|
+
let text = String::from(
|
|
22
|
+
"This is a long text. We want it to not be wider than 200pt, \
|
|
23
|
+
so that it fits on the page. Let's intersperse some emojis 💩👻💀emojis🦩🌚😁😆\
|
|
24
|
+
as well as complex scripts: हैलो वर्ल्ड and مرحبا بالعالم",
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Set up the properties of the text. See the documentation of parley for more information
|
|
28
|
+
// on how you can configure its behavior.
|
|
29
|
+
let max_advance = Some(200.0);
|
|
30
|
+
let text_color = rgb::Color::new(0, 0, 0);
|
|
31
|
+
let mut font_cx = FontContext::default();
|
|
32
|
+
let mut layout_cx = LayoutContext::new();
|
|
33
|
+
let mut builder = layout_cx.ranged_builder(&mut font_cx, &text, 1.0, false);
|
|
34
|
+
let brush_style = StyleProperty::Brush(text_color);
|
|
35
|
+
builder.push_default(brush_style);
|
|
36
|
+
|
|
37
|
+
let font_stack = FontFamily::List(Cow::Borrowed(&[
|
|
38
|
+
FontFamilyName::Named(Cow::Borrowed("Noto Sans")),
|
|
39
|
+
FontFamilyName::Named(Cow::Borrowed("Noto Sans Arabic")),
|
|
40
|
+
FontFamilyName::Named(Cow::Borrowed("Noto Sans Devanagari")),
|
|
41
|
+
FontFamilyName::Named(Cow::Borrowed("Noto Color Emoji")),
|
|
42
|
+
]));
|
|
43
|
+
let font_stack_style = StyleProperty::FontFamily(font_stack);
|
|
44
|
+
builder.push_default(font_stack_style);
|
|
45
|
+
builder.push_default(StyleProperty::LineHeight(LineHeight::FontSizeRelative(1.3)));
|
|
46
|
+
builder.push_default(StyleProperty::FontSize(16.0));
|
|
47
|
+
|
|
48
|
+
// In our case, we set the first four characters to bold and also make some
|
|
49
|
+
// part of the text red.
|
|
50
|
+
let bold = FontWeight::new(600.0);
|
|
51
|
+
let bold_style = StyleProperty::FontWeight(bold);
|
|
52
|
+
builder.push(bold_style, 0..4);
|
|
53
|
+
|
|
54
|
+
let color_style = StyleProperty::Brush(rgb::Color::new(255, 0, 0));
|
|
55
|
+
builder.push(color_style, 2..12);
|
|
56
|
+
|
|
57
|
+
let mut layout = builder.build(&text);
|
|
58
|
+
layout.break_all_lines(max_advance);
|
|
59
|
+
layout.align(max_advance, Alignment::Start, Default::default());
|
|
60
|
+
|
|
61
|
+
// After setting up everything, now starts the actual part where we use krilla to write
|
|
62
|
+
// the text to a PDF.
|
|
63
|
+
// We need to set up a font cache that converts from parley fonts to krilla fonts.
|
|
64
|
+
let mut font_cache = HashMap::new();
|
|
65
|
+
|
|
66
|
+
// The usual page setup.
|
|
67
|
+
let mut document = Document::new();
|
|
68
|
+
let mut page = document.start_page_with(PageSettings::from_wh(200.0, 300.0).unwrap());
|
|
69
|
+
let mut surface = page.surface();
|
|
70
|
+
|
|
71
|
+
for line in layout.lines() {
|
|
72
|
+
let y = line.metrics().baseline;
|
|
73
|
+
let mut x = 0.0;
|
|
74
|
+
for run in line.runs() {
|
|
75
|
+
let mut cur_x = x;
|
|
76
|
+
let font = run.font().clone();
|
|
77
|
+
let (font_data, id) = font.data.into_raw_parts();
|
|
78
|
+
// Get the krilla font.
|
|
79
|
+
let krilla_font = font_cache
|
|
80
|
+
.entry(id)
|
|
81
|
+
.or_insert_with(|| Font::new(font_data.into(), font.index).unwrap());
|
|
82
|
+
let font_size = run.font_size();
|
|
83
|
+
|
|
84
|
+
// This is part is somewhat convoluted, the reason being that each glyph might
|
|
85
|
+
// have a different style than the previous one. So we always need to keep track
|
|
86
|
+
// of the current style, and whenever we encounter a new style we "flush" all
|
|
87
|
+
// current glyphs into the PDF, and build the next sequence of consecutive
|
|
88
|
+
// glyphs.
|
|
89
|
+
let mut cur_style = None;
|
|
90
|
+
let mut glyphs = Vec::<KrillaGlyph>::new();
|
|
91
|
+
|
|
92
|
+
for cluster in run.visual_clusters() {
|
|
93
|
+
if cluster.is_ligature_continuation() {
|
|
94
|
+
if let Some(glyph) = glyphs.last_mut() {
|
|
95
|
+
glyph.text_range.end = cluster.text_range().end;
|
|
96
|
+
}
|
|
97
|
+
// Ligature continuations have no glyphs of their own.
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for glyph in cluster.glyphs() {
|
|
102
|
+
let glyph_style = glyph.style_index;
|
|
103
|
+
|
|
104
|
+
if let Some(style) = cur_style {
|
|
105
|
+
if style != glyph_style {
|
|
106
|
+
// If style doesn't match, flush all glyphs up to now.
|
|
107
|
+
cur_style = Some(glyph_style);
|
|
108
|
+
let style = layout.styles()[style as usize].brush;
|
|
109
|
+
surface.set_fill(Some(Fill {
|
|
110
|
+
paint: style.into(),
|
|
111
|
+
opacity: NormalizedF32::ONE,
|
|
112
|
+
rule: Default::default(),
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
surface.draw_glyphs(
|
|
116
|
+
Point { x: cur_x, y },
|
|
117
|
+
&glyphs,
|
|
118
|
+
krilla_font.clone(),
|
|
119
|
+
&text,
|
|
120
|
+
font_size,
|
|
121
|
+
false,
|
|
122
|
+
);
|
|
123
|
+
glyphs.clear();
|
|
124
|
+
cur_x = x;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
cur_style = Some(glyph_style);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Add the current glyph to our buffer of glyphs.
|
|
131
|
+
glyphs.push(KrillaGlyph::new(
|
|
132
|
+
GlyphId::new(glyph.id as u32),
|
|
133
|
+
glyph.advance / font_size,
|
|
134
|
+
glyph.x / font_size,
|
|
135
|
+
glyph.y / font_size,
|
|
136
|
+
0.0,
|
|
137
|
+
cluster.text_range(),
|
|
138
|
+
None,
|
|
139
|
+
));
|
|
140
|
+
// And make sure keep track of the current x position.
|
|
141
|
+
x += glyph.advance;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Flush all remaining glyphs, if existing.
|
|
146
|
+
if !glyphs.is_empty() {
|
|
147
|
+
surface.set_fill(Some(Fill {
|
|
148
|
+
paint: layout.styles()[cur_style.unwrap() as usize].brush.into(),
|
|
149
|
+
opacity: NormalizedF32::ONE,
|
|
150
|
+
rule: Default::default(),
|
|
151
|
+
}));
|
|
152
|
+
surface.draw_glyphs(
|
|
153
|
+
Point::from_xy(cur_x, y),
|
|
154
|
+
&glyphs,
|
|
155
|
+
krilla_font.clone(),
|
|
156
|
+
&text,
|
|
157
|
+
font_size,
|
|
158
|
+
false,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
surface.finish();
|
|
165
|
+
page.finish();
|
|
166
|
+
|
|
167
|
+
let pdf = document.finish().unwrap();
|
|
168
|
+
|
|
169
|
+
let path = path::absolute("parley.pdf").unwrap();
|
|
170
|
+
eprintln!("Saved PDF to '{}'", path.display());
|
|
171
|
+
|
|
172
|
+
// Write the PDF to a file.
|
|
173
|
+
std::fs::write(path, &pdf).unwrap();
|
|
174
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//! This example shows how to use `simple_text` API to draw simple text in a single line. It
|
|
2
|
+
//! also demonstrates how you can use non-default variation coordinates.
|
|
3
|
+
//!
|
|
4
|
+
//! Note that simple text in this case does not mean that complex scripts aren't supported
|
|
5
|
+
//! (they are, including RTL text!), but the text itself must not contain mixed scripts. And
|
|
6
|
+
//! the font must contain all necessary glyphs, otherwise the `.notdef` glyph will be emitted
|
|
7
|
+
//! instead of font fallback.
|
|
8
|
+
|
|
9
|
+
use std::path;
|
|
10
|
+
use std::path::PathBuf;
|
|
11
|
+
use std::sync::{Arc, LazyLock};
|
|
12
|
+
|
|
13
|
+
use krilla::color::rgb;
|
|
14
|
+
use krilla::geom::Point;
|
|
15
|
+
use krilla::num::NormalizedF32;
|
|
16
|
+
use krilla::page::PageSettings;
|
|
17
|
+
use krilla::paint::{Fill, LinearGradient, SpreadMethod, Stop, Stroke};
|
|
18
|
+
use krilla::text::{Font, TextDirection};
|
|
19
|
+
use krilla::Document;
|
|
20
|
+
pub(crate) static WORKSPACE_PATH: LazyLock<PathBuf> =
|
|
21
|
+
LazyLock::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../"));
|
|
22
|
+
|
|
23
|
+
pub(crate) static ASSETS_PATH: LazyLock<PathBuf> = LazyLock::new(|| WORKSPACE_PATH.join("assets"));
|
|
24
|
+
|
|
25
|
+
fn main() {
|
|
26
|
+
// The usual page setup.
|
|
27
|
+
let mut document = Document::new();
|
|
28
|
+
let mut page = document.start_page_with(PageSettings::from_wh(600.0, 280.0).unwrap());
|
|
29
|
+
let mut surface = page.surface();
|
|
30
|
+
|
|
31
|
+
let noto_font = Font::new(
|
|
32
|
+
Arc::new(std::fs::read(ASSETS_PATH.join("fonts/NotoSans-Regular.ttf")).unwrap()).into(),
|
|
33
|
+
0,
|
|
34
|
+
)
|
|
35
|
+
.unwrap();
|
|
36
|
+
|
|
37
|
+
let gradient = LinearGradient {
|
|
38
|
+
x1: 30.0,
|
|
39
|
+
y1: 0.0,
|
|
40
|
+
x2: 50.0,
|
|
41
|
+
y2: 0.0,
|
|
42
|
+
transform: Default::default(),
|
|
43
|
+
spread_method: SpreadMethod::Reflect,
|
|
44
|
+
stops: vec![
|
|
45
|
+
Stop {
|
|
46
|
+
offset: NormalizedF32::new(0.2).unwrap(),
|
|
47
|
+
color: rgb::Color::new(255, 0, 0).into(),
|
|
48
|
+
opacity: NormalizedF32::ONE,
|
|
49
|
+
},
|
|
50
|
+
Stop {
|
|
51
|
+
offset: NormalizedF32::new(0.8).unwrap(),
|
|
52
|
+
color: rgb::Color::new(255, 255, 0).into(),
|
|
53
|
+
opacity: NormalizedF32::ONE,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
anti_alias: true,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
surface.set_fill(Some(Fill {
|
|
60
|
+
paint: gradient.into(),
|
|
61
|
+
opacity: NormalizedF32::new(0.5).unwrap(),
|
|
62
|
+
rule: Default::default(),
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
// Let's first write some red-colored text with some English text.
|
|
66
|
+
surface.draw_text(
|
|
67
|
+
Point::from_xy(0.0, 25.0),
|
|
68
|
+
noto_font.clone(),
|
|
69
|
+
25.0,
|
|
70
|
+
"z͈̤̭͖̉͑́a̳ͫ́̇͑̽͒ͯlͨ͗̍̀̍̔̀ģ͔̫̫̄o̗̠͔͆̏̓͢",
|
|
71
|
+
false,
|
|
72
|
+
TextDirection::Auto,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
surface.set_fill(None);
|
|
76
|
+
surface.set_stroke(Some(Stroke {
|
|
77
|
+
paint: rgb::Color::new(0, 255, 0).into(),
|
|
78
|
+
..Default::default()
|
|
79
|
+
}));
|
|
80
|
+
// Instead of applying fills, we can also apply strokes!
|
|
81
|
+
surface.draw_text(
|
|
82
|
+
Point::from_xy(0.0, 50.0),
|
|
83
|
+
noto_font.clone(),
|
|
84
|
+
25.0,
|
|
85
|
+
"This text is stroked green!",
|
|
86
|
+
false,
|
|
87
|
+
TextDirection::Auto,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
let noto_arabic_font = Font::new(
|
|
91
|
+
Arc::new(std::fs::read(ASSETS_PATH.join("fonts/NotoSansArabic-Regular.ttf")).unwrap())
|
|
92
|
+
.into(),
|
|
93
|
+
0,
|
|
94
|
+
)
|
|
95
|
+
.unwrap();
|
|
96
|
+
|
|
97
|
+
surface.set_fill(None);
|
|
98
|
+
// As mentioned above, complex scripts are supported, you just can't mix them in
|
|
99
|
+
// one run.
|
|
100
|
+
surface.draw_text(
|
|
101
|
+
Point::from_xy(0.0, 75.0),
|
|
102
|
+
noto_arabic_font.clone(),
|
|
103
|
+
25.0,
|
|
104
|
+
"هذا هو السطر الثاني من النص.",
|
|
105
|
+
false,
|
|
106
|
+
TextDirection::Auto,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
surface.finish();
|
|
110
|
+
page.finish();
|
|
111
|
+
let pdf = document.finish().unwrap();
|
|
112
|
+
|
|
113
|
+
let path = path::absolute("simple_text.pdf").unwrap();
|
|
114
|
+
eprintln!("Saved PDF to '{}'", path.display());
|
|
115
|
+
|
|
116
|
+
// Write the PDF to a file.
|
|
117
|
+
std::fs::write(path, &pdf).unwrap();
|
|
118
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//! This example introduces the concept of a `StreamBuilder`, which allows you to
|
|
2
|
+
//! define graphics content on a separate context than the main page surface. This is necessary
|
|
3
|
+
//! when defining patterns or mask.
|
|
4
|
+
|
|
5
|
+
use std::path;
|
|
6
|
+
|
|
7
|
+
use krilla::color::rgb;
|
|
8
|
+
use krilla::geom::{Path, PathBuilder, Rect, Transform};
|
|
9
|
+
use krilla::page::PageSettings;
|
|
10
|
+
use krilla::paint::{Fill, Pattern, Stroke};
|
|
11
|
+
use krilla::Document;
|
|
12
|
+
|
|
13
|
+
fn main() {
|
|
14
|
+
let mut document = Document::new();
|
|
15
|
+
let mut page = document.start_page_with(PageSettings::from_wh(200.0, 200.0).unwrap());
|
|
16
|
+
let mut surface = page.surface();
|
|
17
|
+
|
|
18
|
+
// We want to define a pattern with a red rectangle on the top-left and a
|
|
19
|
+
// blue rectangle on the bottom-right. Then we want to apply this pattern to
|
|
20
|
+
// a rectangle that is rotated by 45 degrees in the center.
|
|
21
|
+
|
|
22
|
+
// First, let's define the pattern by creating a new stream builder.
|
|
23
|
+
let mut stream_builder = surface.stream_builder();
|
|
24
|
+
let mut pattern_surface = stream_builder.surface();
|
|
25
|
+
|
|
26
|
+
pattern_surface.set_fill(Some(Fill {
|
|
27
|
+
paint: rgb::Color::new(255, 0, 0).into(),
|
|
28
|
+
..Default::default()
|
|
29
|
+
}));
|
|
30
|
+
// Draw the top-left rectangle.
|
|
31
|
+
pattern_surface.draw_path(&rect_to_path(0.0, 0.0, 10.0, 10.0));
|
|
32
|
+
|
|
33
|
+
pattern_surface.set_fill(Some(Fill {
|
|
34
|
+
paint: rgb::Color::new(0, 0, 255).into(),
|
|
35
|
+
..Default::default()
|
|
36
|
+
}));
|
|
37
|
+
// Draw the bottom-right rectangle.
|
|
38
|
+
pattern_surface.draw_path(&rect_to_path(10.0, 10.0, 20.0, 20.0));
|
|
39
|
+
pattern_surface.finish();
|
|
40
|
+
|
|
41
|
+
// Get the pattern stream
|
|
42
|
+
let pattern_stream = stream_builder.finish();
|
|
43
|
+
|
|
44
|
+
// Define the actual pattern
|
|
45
|
+
let pattern = Pattern {
|
|
46
|
+
stream: pattern_stream,
|
|
47
|
+
transform: Default::default(),
|
|
48
|
+
width: 20.0,
|
|
49
|
+
height: 20.0,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Now we draw the actual transformed rectangle.
|
|
53
|
+
// First, push a transform so that the rectangle will be rotated.
|
|
54
|
+
surface.push_transform(&Transform::from_rotate_at(45.0, 100.0, 100.0));
|
|
55
|
+
|
|
56
|
+
let rect_path = rect_to_path(30.0, 30.0, 170.0, 170.0);
|
|
57
|
+
|
|
58
|
+
surface.set_fill(Some(Fill {
|
|
59
|
+
paint: pattern.into(),
|
|
60
|
+
..Default::default()
|
|
61
|
+
}));
|
|
62
|
+
// Draw the rectangle.
|
|
63
|
+
surface.draw_path(&rect_path);
|
|
64
|
+
|
|
65
|
+
surface.set_fill(None);
|
|
66
|
+
surface.set_stroke(Some(Stroke {
|
|
67
|
+
paint: rgb::Color::black().into(),
|
|
68
|
+
..Default::default()
|
|
69
|
+
}));
|
|
70
|
+
// Let's also add a stroke, makes it look a bit nicer.
|
|
71
|
+
surface.draw_path(&rect_path);
|
|
72
|
+
|
|
73
|
+
// Don't forget to pop! Each `push_` method must have a corresponding pop.
|
|
74
|
+
surface.pop();
|
|
75
|
+
|
|
76
|
+
surface.finish();
|
|
77
|
+
page.finish();
|
|
78
|
+
|
|
79
|
+
let pdf = document.finish().unwrap();
|
|
80
|
+
|
|
81
|
+
let path = path::absolute("stream_builder.pdf").unwrap();
|
|
82
|
+
eprintln!("Saved PDF to '{}'", path.display());
|
|
83
|
+
|
|
84
|
+
// Write the PDF to a file.
|
|
85
|
+
std::fs::write(path, &pdf).unwrap();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A simple convenience function that allow us to generate rectangle paths.
|
|
89
|
+
pub fn rect_to_path(x1: f32, y1: f32, x2: f32, y2: f32) -> Path {
|
|
90
|
+
let mut builder = PathBuilder::new();
|
|
91
|
+
builder.push_rect(Rect::from_ltrb(x1, y1, x2, y2).unwrap());
|
|
92
|
+
builder.finish().unwrap()
|
|
93
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
Statement of Purpose
|
|
4
|
+
|
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
6
|
+
exclusive Copyright and Related Rights (defined below) upon the creator and
|
|
7
|
+
subsequent owner(s) (each and all, an "owner") of an original work of
|
|
8
|
+
authorship and/or a database (each, a "Work").
|
|
9
|
+
|
|
10
|
+
Certain owners wish to permanently relinquish those rights to a Work for the
|
|
11
|
+
purpose of contributing to a commons of creative, cultural and scientific
|
|
12
|
+
works ("Commons") that the public can reliably and without fear of later
|
|
13
|
+
claims of infringement build upon, modify, incorporate in other works, reuse
|
|
14
|
+
and redistribute as freely as possible in any form whatsoever and for any
|
|
15
|
+
purposes, including without limitation commercial purposes. These owners may
|
|
16
|
+
contribute to the Commons to promote the ideal of a free culture and the
|
|
17
|
+
further production of creative, cultural and scientific works, or to gain
|
|
18
|
+
reputation or greater distribution for their Work in part through the use and
|
|
19
|
+
efforts of others.
|
|
20
|
+
|
|
21
|
+
For these and/or other purposes and motivations, and without any expectation
|
|
22
|
+
of additional consideration or compensation, the person associating CC0 with a
|
|
23
|
+
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
|
24
|
+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
|
25
|
+
and publicly distribute the Work under its terms, with knowledge of his or her
|
|
26
|
+
Copyright and Related Rights in the Work and the meaning and intended legal
|
|
27
|
+
effect of CC0 on those rights.
|
|
28
|
+
|
|
29
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
30
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
31
|
+
Related Rights"). Copyright and Related Rights include, but are not limited
|
|
32
|
+
to, the following:
|
|
33
|
+
|
|
34
|
+
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
|
35
|
+
and translate a Work;
|
|
36
|
+
|
|
37
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
38
|
+
|
|
39
|
+
iii. publicity and privacy rights pertaining to a person's image or likeness
|
|
40
|
+
depicted in a Work;
|
|
41
|
+
|
|
42
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
43
|
+
subject to the limitations in paragraph 4(a), below;
|
|
44
|
+
|
|
45
|
+
v. rights protecting the extraction, dissemination, use and reuse of data in
|
|
46
|
+
a Work;
|
|
47
|
+
|
|
48
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
49
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
50
|
+
protection of databases, and under any national implementation thereof,
|
|
51
|
+
including any amended or successor version of such directive); and
|
|
52
|
+
|
|
53
|
+
vii. other similar, equivalent or corresponding rights throughout the world
|
|
54
|
+
based on applicable law or treaty, and any national implementations thereof.
|
|
55
|
+
|
|
56
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
|
57
|
+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
|
58
|
+
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
|
59
|
+
and Related Rights and associated claims and causes of action, whether now
|
|
60
|
+
known or unknown (including existing as well as future claims and causes of
|
|
61
|
+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
|
62
|
+
duration provided by applicable law or treaty (including future time
|
|
63
|
+
extensions), (iii) in any current or future medium and for any number of
|
|
64
|
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
|
65
|
+
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
|
66
|
+
the Waiver for the benefit of each member of the public at large and to the
|
|
67
|
+
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
|
68
|
+
shall not be subject to revocation, rescission, cancellation, termination, or
|
|
69
|
+
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
|
70
|
+
by the public as contemplated by Affirmer's express Statement of Purpose.
|
|
71
|
+
|
|
72
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be
|
|
73
|
+
judged legally invalid or ineffective under applicable law, then the Waiver
|
|
74
|
+
shall be preserved to the maximum extent permitted taking into account
|
|
75
|
+
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
|
76
|
+
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
|
77
|
+
non transferable, non sublicensable, non exclusive, irrevocable and
|
|
78
|
+
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
|
79
|
+
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
|
80
|
+
provided by applicable law or treaty (including future time extensions), (iii)
|
|
81
|
+
in any current or future medium and for any number of copies, and (iv) for any
|
|
82
|
+
purpose whatsoever, including without limitation commercial, advertising or
|
|
83
|
+
promotional purposes (the "License"). The License shall be deemed effective as
|
|
84
|
+
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
|
85
|
+
License for any reason be judged legally invalid or ineffective under
|
|
86
|
+
applicable law, such partial invalidity or ineffectiveness shall not
|
|
87
|
+
invalidate the remainder of the License, and in such case Affirmer hereby
|
|
88
|
+
affirms that he or she will not (i) exercise any of his or her remaining
|
|
89
|
+
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
|
90
|
+
and causes of action with respect to the Work, in either case contrary to
|
|
91
|
+
Affirmer's express Statement of Purpose.
|
|
92
|
+
|
|
93
|
+
4. Limitations and Disclaimers.
|
|
94
|
+
|
|
95
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
96
|
+
surrendered, licensed or otherwise affected by this document.
|
|
97
|
+
|
|
98
|
+
b. Affirmer offers the Work as-is and makes no representations or warranties
|
|
99
|
+
of any kind concerning the Work, express, implied, statutory or otherwise,
|
|
100
|
+
including without limitation warranties of title, merchantability, fitness
|
|
101
|
+
for a particular purpose, non infringement, or the absence of latent or
|
|
102
|
+
other defects, accuracy, or the present or absence of errors, whether or not
|
|
103
|
+
discoverable, all to the greatest extent permissible under applicable law.
|
|
104
|
+
|
|
105
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
106
|
+
that may apply to the Work or any use thereof, including without limitation
|
|
107
|
+
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
|
108
|
+
disclaims responsibility for obtaining any necessary consents, permissions
|
|
109
|
+
or other rights required for any use of the Work.
|
|
110
|
+
|
|
111
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
112
|
+
party to this document and has no duty or obligation with respect to this
|
|
113
|
+
CC0 or use of the Work.
|
|
114
|
+
|
|
115
|
+
For more information, please see
|
|
116
|
+
http://creativecommons.org/publicdomain/zero/1.0/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ICC profiles are from: https://github.com/saucecontrol/Compact-ICC-Profiles
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|