typst 0.15.1.9 → 0.15.1.10
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.
- checksums.yaml +4 -4
- data/README.md +14 -3
- data/README.typ +16 -4
- data/ext/typst/src/compiler.rs +4 -0
- data/ext/typst/src/lib.rs +75 -28
- data/lib/base.rb +9 -2
- data/lib/document.rb +27 -5
- data/lib/query.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e229c930144facc3e61ab7b615f536cb2c4a19ab1802ecd4c08e3e6e55ddb7f
|
|
4
|
+
data.tar.gz: '09873f076e39a832fba35a764beba5196083e2a580d7b0762213f3ec90397474'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 83edbce843bb5d1886e50f9a2f066c854b3bad9549a3a7edb7cc471d069754e8c6eeecb33d1772bdbd676e3791c1cca6efa526cdaaf93ed77f8e0257c6c0026e
|
|
7
|
+
data.tar.gz: 21ac5af1b9d2b06931c108ea7c351b16f63a52c4b389d440624baf737e31651ce5bea3b4dd564172955dea589f577b09856f3db77b24eff7121e1df9b8c156c6
|
data/README.md
CHANGED
|
@@ -11,7 +11,7 @@ a new markup-based typesetting system that is powerful and easy to learn.
|
|
|
11
11
|
|
|
12
12
|
Add the following to your gemfile and `bundle install`
|
|
13
13
|
```ruby
|
|
14
|
-
gem 'typst', '>= 0.15.1.
|
|
14
|
+
gem 'typst', '>= 0.15.1.10'
|
|
15
15
|
```
|
|
16
16
|
or install from the command line:
|
|
17
17
|
```bash
|
|
@@ -92,6 +92,12 @@ doc = t.compile(:pdf)
|
|
|
92
92
|
doc = t.compile(:pdf, pdf_standards: ["2.0"])
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
#### Compile to PDF without tags
|
|
96
|
+
Typst tags PDFs by default so that screen readers and other assistive technology can read them. The tags can make up much of a large document's size; like the CLI's `--no-pdf-tags`, `tagged: false` leaves them out. The PDF/A-1a, A-2a, A-3a and UA-1 standards require tags.
|
|
97
|
+
```ruby
|
|
98
|
+
doc = t.compile(:pdf, tagged: false)
|
|
99
|
+
```
|
|
100
|
+
|
|
95
101
|
#### Compile to SVG
|
|
96
102
|
```ruby
|
|
97
103
|
doc = t.compile(:svg)
|
|
@@ -115,9 +121,10 @@ doc = t.compile(:html_experimental)
|
|
|
115
121
|
### Output
|
|
116
122
|
|
|
117
123
|
#### Return compiled content as an array of bytes
|
|
124
|
+
One array of integers per page. For large output prefer `pages` (below), which returns binary Strings: `bytes` makes a Ruby Integer of every byte.
|
|
118
125
|
```ruby
|
|
119
126
|
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
|
120
|
-
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
|
127
|
+
# => [[37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]]
|
|
121
128
|
```
|
|
122
129
|
|
|
123
130
|
#### Write compiled output to a file
|
|
@@ -127,6 +134,7 @@ doc.write("filename.pdf")
|
|
|
127
134
|
```
|
|
128
135
|
|
|
129
136
|
#### Return PDF, SVG, PNG or HTML content as an array of pages
|
|
137
|
+
Each page is a binary (ASCII-8BIT) String; PDF and HTML output is a single page.
|
|
130
138
|
```ruby
|
|
131
139
|
Typst("readme.typ").compile(:pdf).pages
|
|
132
140
|
# => ["%PDF-1.7\n%\x80\x80\x80\x80\n\n1 0 obj\n<<\n /Type /Pages\n /Count 3\n /Kids [160 0 R 162 ...
|
|
@@ -323,7 +331,10 @@ Defect resolutions by [adam12](https://github.com/adam12) and [walterdavis](http
|
|
|
323
331
|
Design suggestions by [alec-c4](https://github.com/alec-c4)\
|
|
324
332
|
Compiler warnings were contributed by [TheSoloHacker47](https://github.com/TheSoloHacker47) \
|
|
325
333
|
Font optimization patches were contributed by [dmke](https://github.com/dmke) \
|
|
326
|
-
Concurrency patches were contributed by [dmke](https://github.com/dmke)
|
|
334
|
+
Concurrency patches were contributed by [dmke](https://github.com/dmke) \
|
|
335
|
+
Fix for sys_inputs in query by [vitaliiorlov](https://github.com/vitaliiorlov) \
|
|
336
|
+
Ability to optionally disable PDF tags by [vitaliiorlov](https://github.com/vitaliiorlov) \
|
|
337
|
+
Reducing memory of typst compiled output from rust to ruby by [vitaliiorlov](https://github.com/vitaliiorlov)
|
|
327
338
|
|
|
328
339
|
## License
|
|
329
340
|
|
data/README.typ
CHANGED
|
@@ -19,7 +19,7 @@ Ruby language binding to #link("https://github.com/typst/typst")[typst], a new m
|
|
|
19
19
|
|
|
20
20
|
Add the following to your gemfile and `bundle install`
|
|
21
21
|
```ruby
|
|
22
|
-
gem 'typst', '>= 0.15.1.
|
|
22
|
+
gem 'typst', '>= 0.15.1.10'
|
|
23
23
|
```
|
|
24
24
|
or install from the command line:
|
|
25
25
|
```bash
|
|
@@ -99,6 +99,12 @@ doc = t.compile(:pdf)
|
|
|
99
99
|
doc = t.compile(:pdf, pdf_standards: ["2.0"])
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
==== Compile to PDF without tags
|
|
103
|
+
Typst tags PDFs by default so that screen readers and other assistive technology can read them. The tags can make up much of a large document's size; like the CLI's `--no-pdf-tags`, `tagged: false` leaves them out. The PDF/A-1a, A-2a, A-3a and UA-1 standards require tags.
|
|
104
|
+
```ruby
|
|
105
|
+
doc = t.compile(:pdf, tagged: false)
|
|
106
|
+
```
|
|
107
|
+
|
|
102
108
|
==== Compile to SVG
|
|
103
109
|
```ruby
|
|
104
110
|
doc = t.compile(:svg)
|
|
@@ -122,9 +128,10 @@ doc = t.compile(:html_experimental)
|
|
|
122
128
|
=== Output
|
|
123
129
|
|
|
124
130
|
==== Return compiled content as an array of bytes
|
|
131
|
+
One array of integers per page. For large output prefer `pages` (below), which returns binary Strings: `bytes` makes a Ruby Integer of every byte.
|
|
125
132
|
```ruby
|
|
126
133
|
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
|
127
|
-
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
|
134
|
+
# => [[37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]]
|
|
128
135
|
```
|
|
129
136
|
|
|
130
137
|
==== Write compiled output to a file
|
|
@@ -134,6 +141,7 @@ doc.write("filename.pdf")
|
|
|
134
141
|
```
|
|
135
142
|
|
|
136
143
|
==== Return PDF, SVG, PNG or HTML content as an array of pages
|
|
144
|
+
Each page is a binary (ASCII-8BIT) String; PDF and HTML output is a single page.
|
|
137
145
|
```ruby
|
|
138
146
|
Typst("readme.typ").compile(:pdf).pages
|
|
139
147
|
# => ["%PDF-1.7\n%\x80\x80\x80\x80\n\n1 0 obj\n<<\n /Type /Pages\n /Count 3\n /Kids [160 0 R 162 ...
|
|
@@ -331,8 +339,12 @@ clear_cache was contributed by #link("https://github.com/NRicciVestmark")[NRicci
|
|
|
331
339
|
CI improvements were contributed by #link("https://github.com/am1006")[am1006]\
|
|
332
340
|
Defect resolutions by #link("https://github.com/adam12")[adam12] and #link("https://github.com/walterdavis")[walterdavis]\
|
|
333
341
|
Design suggestions by #link("https://github.com/alec-c4")[alec-c4]\
|
|
334
|
-
Compiler warnings were contributed by #link("https://github.com/TheSoloHacker47")[TheSoloHacker47]
|
|
335
|
-
|
|
342
|
+
Compiler warnings were contributed by #link("https://github.com/TheSoloHacker47")[TheSoloHacker47] \
|
|
343
|
+
Font optimization patches were contributed by #link("https://github.com/dmke")[dmke] \
|
|
344
|
+
Concurrency patches were contributed by #link("https://github.com/dmke")[dmke] \
|
|
345
|
+
Fix for sys_inputs in query by #link("https://github.com/vitaliiorlov")[vitaliiorlov] \
|
|
346
|
+
Ability to optionally disable PDF tags by #link("https://github.com/vitaliiorlov")[vitaliiorlov] \
|
|
347
|
+
Reducing memory of typst compiled output from rust to ruby by #link("https://github.com/vitaliiorlov")
|
|
336
348
|
|
|
337
349
|
== License
|
|
338
350
|
|
data/ext/typst/src/compiler.rs
CHANGED
|
@@ -20,6 +20,7 @@ impl SystemWorld {
|
|
|
20
20
|
format: Option<&str>,
|
|
21
21
|
ppi: Option<f32>,
|
|
22
22
|
pdf_standards: &[typst_pdf::PdfStandard],
|
|
23
|
+
tagged: bool,
|
|
23
24
|
pretty: bool,
|
|
24
25
|
render_bleed: bool,
|
|
25
26
|
) -> StrResult<(Vec<Vec<u8>>, Vec<String>)> {
|
|
@@ -50,6 +51,7 @@ impl SystemWorld {
|
|
|
50
51
|
typst_pdf::PdfStandards::new(pdf_standards)
|
|
51
52
|
.map_err(|e| eco_format!("PDF standards error: {:?}", e))
|
|
52
53
|
.at(Span::detached()).unwrap(),
|
|
54
|
+
tagged,
|
|
53
55
|
pretty,
|
|
54
56
|
)?],
|
|
55
57
|
"png" => export_image(&document, ImageExportFormat::Png, ppi, pretty, render_bleed)?,
|
|
@@ -106,6 +108,7 @@ fn export_pdf(
|
|
|
106
108
|
document: &PagedDocument,
|
|
107
109
|
world: &SystemWorld,
|
|
108
110
|
standards: typst_pdf::PdfStandards,
|
|
111
|
+
tagged: bool,
|
|
109
112
|
pretty: bool,
|
|
110
113
|
) -> StrResult<Vec<u8>> {
|
|
111
114
|
let buffer = typst_pdf::pdf(
|
|
@@ -114,6 +117,7 @@ fn export_pdf(
|
|
|
114
117
|
ident: typst::foundations::Smart::Auto,
|
|
115
118
|
timestamp: now().map(typst_pdf::Timestamp::new_utc),
|
|
116
119
|
standards,
|
|
120
|
+
tagged,
|
|
117
121
|
pretty,
|
|
118
122
|
..Default::default()
|
|
119
123
|
},
|
data/ext/typst/src/lib.rs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
use std::path::PathBuf;
|
|
2
2
|
|
|
3
|
-
use magnus::{function, prelude::*, Error, Ruby};
|
|
3
|
+
use magnus::{function, prelude::*, Error, RArray, Ruby};
|
|
4
4
|
|
|
5
5
|
use std::collections::HashMap;
|
|
6
6
|
use query::{query as typst_query, QueryCommand, SerializationFormat};
|
|
@@ -16,6 +16,13 @@ mod nogvl;
|
|
|
16
16
|
mod query;
|
|
17
17
|
mod world;
|
|
18
18
|
|
|
19
|
+
/// Hands the compiled pages to Ruby as binary (ASCII-8BIT) Strings, one per
|
|
20
|
+
/// page. Returned as they are, each `Vec<u8>` would become an Array holding
|
|
21
|
+
/// an Integer per byte.
|
|
22
|
+
fn binary_pages(ruby: &Ruby, pages: Vec<Vec<u8>>) -> RArray {
|
|
23
|
+
ruby.ary_from_iter(pages.into_iter().map(|page| ruby.str_from_slice(&page)))
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
fn to_html(
|
|
20
27
|
input: PathBuf,
|
|
21
28
|
root: Option<PathBuf>,
|
|
@@ -63,11 +70,11 @@ fn to_html(
|
|
|
63
70
|
.build()
|
|
64
71
|
.map_err(|msg| msg.to_string())?;
|
|
65
72
|
|
|
66
|
-
let
|
|
67
|
-
.compile(Some("html"), None, &Vec::new(), pretty, render_bleed)
|
|
73
|
+
let (pages, warnings) = world
|
|
74
|
+
.compile(Some("html"), None, &Vec::new(), true, pretty, render_bleed)
|
|
68
75
|
.map_err(|msg| msg.to_string())?;
|
|
69
76
|
|
|
70
|
-
Ok(
|
|
77
|
+
Ok((pages, warnings))
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
fn route_to_html(
|
|
@@ -81,15 +88,20 @@ fn route_to_html(
|
|
|
81
88
|
render_bleed: bool,
|
|
82
89
|
pretty: bool,
|
|
83
90
|
sys_inputs: HashMap<String, String>,
|
|
84
|
-
) -> Result<(
|
|
85
|
-
if concurrent {
|
|
91
|
+
) -> Result<(RArray, Vec<String>), Error> {
|
|
92
|
+
let result = if concurrent {
|
|
86
93
|
without_gvl(move || -> Result<(Vec<Vec<u8>>, Vec<String>), String> {
|
|
87
94
|
to_html(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, render_bleed, pretty, sys_inputs)
|
|
88
95
|
})
|
|
89
96
|
} else {
|
|
90
97
|
to_html(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, render_bleed, pretty, sys_inputs)
|
|
91
98
|
}
|
|
92
|
-
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg))
|
|
99
|
+
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg));
|
|
100
|
+
|
|
101
|
+
match result {
|
|
102
|
+
Ok((pages, warnings)) => Ok((binary_pages(ruby, pages), warnings)),
|
|
103
|
+
Err(msg) => Err(magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))
|
|
104
|
+
}
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
fn to_svg(
|
|
@@ -126,11 +138,11 @@ fn to_svg(
|
|
|
126
138
|
.build()
|
|
127
139
|
.map_err(|msg| msg.to_string())?;
|
|
128
140
|
|
|
129
|
-
let
|
|
130
|
-
.compile(Some("svg"), None, &Vec::new(), pretty, render_bleed)
|
|
141
|
+
let (pages, warnings) = world
|
|
142
|
+
.compile(Some("svg"), None, &Vec::new(), true, pretty, render_bleed)
|
|
131
143
|
.map_err(|msg| msg.to_string())?;
|
|
132
144
|
|
|
133
|
-
Ok(
|
|
145
|
+
Ok((pages, warnings))
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
fn route_to_svg(
|
|
@@ -144,15 +156,20 @@ fn route_to_svg(
|
|
|
144
156
|
render_bleed: bool,
|
|
145
157
|
pretty: bool,
|
|
146
158
|
sys_inputs: HashMap<String, String>,
|
|
147
|
-
) -> Result<(
|
|
148
|
-
if concurrent {
|
|
159
|
+
) -> Result<(RArray, Vec<String>), Error> {
|
|
160
|
+
let result = if concurrent {
|
|
149
161
|
without_gvl(move || -> Result<(Vec<Vec<u8>>, Vec<String>), String> {
|
|
150
162
|
to_svg(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, render_bleed, pretty, sys_inputs)
|
|
151
163
|
})
|
|
152
164
|
} else {
|
|
153
165
|
to_svg(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, render_bleed, pretty, sys_inputs)
|
|
154
166
|
}
|
|
155
|
-
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg))
|
|
167
|
+
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg));
|
|
168
|
+
|
|
169
|
+
match result {
|
|
170
|
+
Ok((pages, warnings)) => Ok((binary_pages(ruby, pages), warnings)),
|
|
171
|
+
Err(msg) => Err(magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))
|
|
172
|
+
}
|
|
156
173
|
}
|
|
157
174
|
|
|
158
175
|
fn to_png(
|
|
@@ -189,11 +206,11 @@ fn to_png(
|
|
|
189
206
|
.build()
|
|
190
207
|
.map_err(|msg| msg.to_string())?;
|
|
191
208
|
|
|
192
|
-
let
|
|
193
|
-
.compile(Some("png"), ppi, &Vec::new(), false, render_bleed)
|
|
209
|
+
let (pages, warnings) = world
|
|
210
|
+
.compile(Some("png"), ppi, &Vec::new(), true, false, render_bleed)
|
|
194
211
|
.map_err(|msg| msg.to_string())?;
|
|
195
212
|
|
|
196
|
-
Ok(
|
|
213
|
+
Ok((pages, warnings))
|
|
197
214
|
}
|
|
198
215
|
|
|
199
216
|
fn route_to_png(
|
|
@@ -207,15 +224,20 @@ fn route_to_png(
|
|
|
207
224
|
render_bleed: bool,
|
|
208
225
|
sys_inputs: HashMap<String, String>,
|
|
209
226
|
ppi: Option<f32>,
|
|
210
|
-
) -> Result<(
|
|
211
|
-
if concurrent {
|
|
227
|
+
) -> Result<(RArray, Vec<String>), Error> {
|
|
228
|
+
let result = if concurrent {
|
|
212
229
|
without_gvl(move || -> Result<(Vec<Vec<u8>>, Vec<String>), String> {
|
|
213
230
|
to_png(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, render_bleed, sys_inputs, ppi)
|
|
214
231
|
})
|
|
215
232
|
} else {
|
|
216
233
|
to_png(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, render_bleed, sys_inputs, ppi)
|
|
217
234
|
}
|
|
218
|
-
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg))
|
|
235
|
+
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg));
|
|
236
|
+
|
|
237
|
+
match result {
|
|
238
|
+
Ok((pages, warnings)) => Ok((binary_pages(ruby, pages), warnings)),
|
|
239
|
+
Err(msg) => Err(magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))
|
|
240
|
+
}
|
|
219
241
|
}
|
|
220
242
|
|
|
221
243
|
fn to_pdf(
|
|
@@ -227,6 +249,7 @@ fn to_pdf(
|
|
|
227
249
|
pretty: bool,
|
|
228
250
|
sys_inputs: HashMap<String, String>,
|
|
229
251
|
pdf_standards: Vec<String>,
|
|
252
|
+
tagged: bool,
|
|
230
253
|
) -> Result<(Vec<Vec<u8>>, Vec<String>), String> {
|
|
231
254
|
let input = input.canonicalize()
|
|
232
255
|
.map_err(|msg| msg.to_string())?;
|
|
@@ -281,11 +304,29 @@ fn to_pdf(
|
|
|
281
304
|
}
|
|
282
305
|
}
|
|
283
306
|
|
|
284
|
-
|
|
285
|
-
|
|
307
|
+
// These standards require a tagged PDF. Typst would still write one that
|
|
308
|
+
// claims the standard, with none of its content tagged, so refuse as the
|
|
309
|
+
// CLI does for --no-pdf-tags.
|
|
310
|
+
if !tagged {
|
|
311
|
+
const ACCESSIBLE: &[(PdfStandard, &str)] = &[
|
|
312
|
+
(PdfStandard::A_1a, "PDF/A-1a"),
|
|
313
|
+
(PdfStandard::A_2a, "PDF/A-2a"),
|
|
314
|
+
(PdfStandard::A_3a, "PDF/A-3a"),
|
|
315
|
+
(PdfStandard::Ua_1, "PDF/UA-1"),
|
|
316
|
+
];
|
|
317
|
+
|
|
318
|
+
for (standard, name) in ACCESSIBLE {
|
|
319
|
+
if pdf_standards_vec.contains(standard) {
|
|
320
|
+
return Err(format!("cannot disable PDF tags when exporting a {name} document").to_string());
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
let (pages, warnings) = world
|
|
326
|
+
.compile(Some("pdf"), None, &pdf_standards_vec, tagged, pretty, true)
|
|
286
327
|
.map_err(|msg| msg.to_string())?;
|
|
287
328
|
|
|
288
|
-
Ok(
|
|
329
|
+
Ok((pages, warnings))
|
|
289
330
|
}
|
|
290
331
|
|
|
291
332
|
fn route_to_pdf(
|
|
@@ -299,15 +340,21 @@ fn route_to_pdf(
|
|
|
299
340
|
pretty: bool,
|
|
300
341
|
sys_inputs: HashMap<String, String>,
|
|
301
342
|
pdf_standards: Vec<String>,
|
|
302
|
-
|
|
303
|
-
|
|
343
|
+
tagged: bool,
|
|
344
|
+
) -> Result<(RArray, Vec<String>), Error> {
|
|
345
|
+
let result = if concurrent {
|
|
304
346
|
without_gvl(move || -> Result<(Vec<Vec<u8>>, Vec<String>), String> {
|
|
305
|
-
to_pdf(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, pretty, sys_inputs, pdf_standards)
|
|
347
|
+
to_pdf(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, pretty, sys_inputs, pdf_standards, tagged)
|
|
306
348
|
})
|
|
307
349
|
} else {
|
|
308
|
-
to_pdf(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, pretty, sys_inputs, pdf_standards)
|
|
350
|
+
to_pdf(input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, pretty, sys_inputs, pdf_standards, tagged)
|
|
351
|
+
}
|
|
352
|
+
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg));
|
|
353
|
+
|
|
354
|
+
match result {
|
|
355
|
+
Ok((pages, warnings)) => Ok((binary_pages(ruby, pages), warnings)),
|
|
356
|
+
Err(msg) => Err(magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))
|
|
309
357
|
}
|
|
310
|
-
.map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg))
|
|
311
358
|
}
|
|
312
359
|
|
|
313
360
|
fn query(
|
|
@@ -405,7 +452,7 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
405
452
|
env_logger::init();
|
|
406
453
|
|
|
407
454
|
let module = ruby.define_module("Typst")?;
|
|
408
|
-
module.define_singleton_method("_to_pdf", function!(route_to_pdf,
|
|
455
|
+
module.define_singleton_method("_to_pdf", function!(route_to_pdf, 10))?;
|
|
409
456
|
module.define_singleton_method("_to_svg", function!(route_to_svg, 9))?;
|
|
410
457
|
module.define_singleton_method("_to_png", function!(route_to_png, 9))?;
|
|
411
458
|
module.define_singleton_method("_to_html", function!(route_to_html, 9))?;
|
data/lib/base.rb
CHANGED
|
@@ -48,7 +48,13 @@ module Typst
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def typst_args(opts)
|
|
51
|
-
options.values_at(*opts).append(options[:sys_inputs]
|
|
51
|
+
options.values_at(*opts).append(typst_sys_inputs(options[:sys_inputs]))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# sys.inputs holds only strings, as the CLI's --input key=value does, so
|
|
55
|
+
# keys and values are converted.
|
|
56
|
+
def typst_sys_inputs(sys_inputs)
|
|
57
|
+
sys_inputs.map{ |k,v| [k.to_s,v.to_s] }.to_h
|
|
52
58
|
end
|
|
53
59
|
|
|
54
60
|
def typst_pretty_args
|
|
@@ -57,9 +63,10 @@ module Typst
|
|
|
57
63
|
|
|
58
64
|
def typst_pdf_args
|
|
59
65
|
options[:pdf_standards] ||= []
|
|
66
|
+
options[:tagged] = true if options[:tagged].nil?
|
|
60
67
|
opts = typst_options - [:render_bleed] + [:pretty]
|
|
61
68
|
args = typst_args(opts)
|
|
62
|
-
[*args, options[:pdf_standards]]
|
|
69
|
+
[*args, options[:pdf_standards], options[:tagged]]
|
|
63
70
|
end
|
|
64
71
|
|
|
65
72
|
def typst_png_args
|
data/lib/document.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
module Typst
|
|
2
2
|
class Document
|
|
3
|
-
attr_accessor :bytes
|
|
4
|
-
|
|
5
3
|
# Diagnostics the compiler emitted while *succeeding*. An unknown font
|
|
6
4
|
# family is the common one: Typst substitutes another face, the document
|
|
7
5
|
# generates, and nothing tells you unless you look here.
|
|
8
6
|
attr_accessor :warnings
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
# One binary String per page, as the extension returns them. An Array of
|
|
9
|
+
# Integers per page, what it returned before, is still accepted.
|
|
10
|
+
def initialize(pages, warnings = [])
|
|
11
|
+
@pages = binary_pages(pages)
|
|
12
12
|
@warnings = warnings
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -36,12 +36,34 @@ module Typst
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
# One binary (ASCII-8BIT) String per page; PDF and HTML output is a
|
|
40
|
+
# single page. Each call returns new Strings, as it did when it packed
|
|
41
|
+
# them every time. They share their bytes with the document until
|
|
42
|
+
# changed, so changing one (force_encoding, say) leaves the document as
|
|
43
|
+
# it was compiled.
|
|
39
44
|
def pages
|
|
40
|
-
|
|
45
|
+
@pages.collect(&:dup)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The pages as arrays of Integers. Prefer #pages: this makes a Ruby
|
|
49
|
+
# Integer of every byte.
|
|
50
|
+
def bytes
|
|
51
|
+
@pages.collect(&:bytes)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Replaces the pages, given as #bytes returns them or as Strings.
|
|
55
|
+
def bytes=(pages)
|
|
56
|
+
@pages = binary_pages(pages)
|
|
41
57
|
end
|
|
42
58
|
|
|
43
59
|
def document
|
|
44
60
|
pages.size == 1 ? pages.first : pages
|
|
45
61
|
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def binary_pages(pages)
|
|
66
|
+
pages.collect { |page| page.is_a?(Array) ? page.pack("C*") : page }
|
|
67
|
+
end
|
|
46
68
|
end
|
|
47
69
|
end
|
data/lib/query.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Typst
|
|
|
4
4
|
|
|
5
5
|
def initialize(selector, input, field: nil, one: false, format: "json", root: ".", font_paths: [], ignore_system_fonts: false, ignore_embedded_fonts: false, concurrent: false, sys_inputs: {})
|
|
6
6
|
self.format = format
|
|
7
|
-
@result = Typst::_query(selector, field, one, format, input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, concurrent, sys_inputs)
|
|
7
|
+
@result = Typst::_query(selector, field, one, format, input, root, font_paths, ignore_system_fonts, ignore_embedded_fonts, concurrent, typst_sys_inputs(sys_inputs))
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def result(raw: false)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typst
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.15.1.
|
|
4
|
+
version: 0.15.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Flinn
|
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
118
118
|
- !ruby/object:Gem::Version
|
|
119
119
|
version: '0'
|
|
120
120
|
requirements: []
|
|
121
|
-
rubygems_version: 4.0.
|
|
121
|
+
rubygems_version: 4.0.23
|
|
122
122
|
specification_version: 4
|
|
123
123
|
summary: Ruby binding to typst, a new markup-based typesetting system that is powerful
|
|
124
124
|
and easy to learn.
|