typst 0.14.2.2 → 0.15.0.0
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 +78 -21
- data/README.typ +83 -21
- data/ext/typst/Cargo.toml +16 -13
- data/ext/typst/src/compiler.rs +28 -19
- data/ext/typst/src/download.rs +3 -15
- data/ext/typst/src/lib.rs +10 -85
- data/ext/typst/src/query.rs +10 -6
- data/ext/typst/src/world.rs +92 -59
- data/lib/base.rb +5 -5
- data/lib/query.rb +2 -2
- data/lib/typst.rb +3 -3
- metadata +4 -19
- data/ext/typst/src/fonts.rs +0 -86
- data/lib/fonts/DejaVuSansMono-Bold.ttf +0 -0
- data/lib/fonts/DejaVuSansMono-BoldOblique.ttf +0 -0
- data/lib/fonts/DejaVuSansMono-Oblique.ttf +0 -0
- data/lib/fonts/DejaVuSansMono.ttf +0 -0
- data/lib/fonts/LinLibertine_R.ttf +0 -0
- data/lib/fonts/LinLibertine_RB.ttf +0 -0
- data/lib/fonts/LinLibertine_RBI.ttf +0 -0
- data/lib/fonts/LinLibertine_RI.ttf +0 -0
- data/lib/fonts/NewCM10-Bold.otf +0 -0
- data/lib/fonts/NewCM10-BoldItalic.otf +0 -0
- data/lib/fonts/NewCM10-Italic.otf +0 -0
- data/lib/fonts/NewCM10-Regular.otf +0 -0
- data/lib/fonts/NewCMMath-Book.otf +0 -0
- data/lib/fonts/NewCMMath-Regular.otf +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a438a6f795f22c5957eeaefbde3b825e7bf8e8634d75bc402de95321bc0e28d
|
|
4
|
+
data.tar.gz: 192a0dafec2d0b226674eabda64cc71926cc491444f2c2f391a868936c68f044
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2df9d3457d9e2293132e1b528c646c74f00974cc27cb1d3d35801fc8989ee9d9c5fe1b83a615cc245a8ca3f04349f356d385d1dd653b6dba8d4d5ac77ab285ee
|
|
7
|
+
data.tar.gz: 447e18da8b0678394bcde2f5ef6fe25235e8d4d3c9e484375944a0f1054786739dec77bcce2291a252360dc284d40062dcac4dcd2de94e73fa4f190741887401
|
data/README.md
CHANGED
|
@@ -16,53 +16,82 @@ require "typst"
|
|
|
16
16
|
|
|
17
17
|
# Compile a typst file and write the output to a PDF file
|
|
18
18
|
Typst("readme.typ").compile(:pdf).write("readme.pdf")
|
|
19
|
+
```
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
### Use a typst file `readme.typ`
|
|
22
|
+
```ruby
|
|
21
23
|
t = Typst("readme.typ")
|
|
24
|
+
```
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
### Use a typst string
|
|
27
|
+
```ruby
|
|
24
28
|
t = Typst(body: %{hello world})
|
|
29
|
+
```
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
### Use a typst file in a zip file
|
|
32
|
+
```ruby
|
|
27
33
|
t = Typst(zip: "test/main.typ.zip")
|
|
34
|
+
```
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
### Compile to PDF
|
|
37
|
+
```ruby
|
|
30
38
|
doc = t.compile(:pdf)
|
|
39
|
+
```
|
|
31
40
|
|
|
32
|
-
|
|
41
|
+
### Compile to PDF selecting the typst supported PdfStandard
|
|
42
|
+
```ruby
|
|
33
43
|
doc = t.compile(:pdf, pdf_standards: ["2.0"])
|
|
44
|
+
```
|
|
34
45
|
|
|
35
|
-
|
|
46
|
+
### Compile to SVG
|
|
47
|
+
```ruby
|
|
36
48
|
doc = t.compile(:svg)
|
|
49
|
+
```
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
### Compile to PNG
|
|
52
|
+
```ruby
|
|
39
53
|
doc = t.compile(:png)
|
|
54
|
+
```
|
|
40
55
|
|
|
41
|
-
|
|
56
|
+
### Compile to PNG and set PPI
|
|
57
|
+
```ruby
|
|
42
58
|
doc = t.compile(:png, ppi: 72)
|
|
59
|
+
```
|
|
43
60
|
|
|
44
|
-
|
|
61
|
+
### Compile to HTML (using Typst expirmental HTML)
|
|
62
|
+
```ruby
|
|
45
63
|
doc = t.compile(:html_experimental)
|
|
64
|
+
```
|
|
46
65
|
|
|
47
|
-
|
|
66
|
+
### Or return content as an array of bytes
|
|
67
|
+
```ruby
|
|
48
68
|
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
|
49
69
|
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
|
70
|
+
```
|
|
50
71
|
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
### Write the output to a file
|
|
73
|
+
Note: for multi-page documents using formats other than PDF and HTML, pages write to multiple files, e.g. `readme_0.png`, `readme_1.png`
|
|
74
|
+
```ruby
|
|
53
75
|
doc.write("filename.pdf")
|
|
76
|
+
```
|
|
54
77
|
|
|
55
|
-
|
|
78
|
+
### Return PDF, SVG, PNG or HTML content as an array of pages
|
|
79
|
+
```ruby
|
|
56
80
|
Typst("readme.typ").compile(:pdf).pages
|
|
57
81
|
# => ["%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 ...
|
|
82
|
+
|
|
58
83
|
Typst("readme.typ").compile(:svg).pages
|
|
59
84
|
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ...
|
|
85
|
+
|
|
60
86
|
Typst("readme.typ").compile(:png).pages
|
|
61
87
|
# => ["\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x04\xA7\x00\x00\x06\x94\b\ ...
|
|
88
|
+
|
|
62
89
|
Typst("readme.typ").compile(:html_experimental).pages
|
|
63
90
|
# => ["<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" ...
|
|
91
|
+
```
|
|
64
92
|
|
|
65
|
-
|
|
93
|
+
### Pass values into typst using sys_inputs
|
|
94
|
+
```ruby
|
|
66
95
|
sys_inputs_example = %{
|
|
67
96
|
#let persons = json(bytes(sys.inputs.persons))
|
|
68
97
|
|
|
@@ -73,15 +102,18 @@ sys_inputs_example = %{
|
|
|
73
102
|
people = [{"name" => "John", "age" => 35}, {"name" => "Xoliswa", "age" => 45}]
|
|
74
103
|
data = { "persons" => people.to_json }
|
|
75
104
|
Typst(body: sys_inputs_example, sys_inputs: data).compile(:pdf).write("sys_inputs_example.pdf")
|
|
105
|
+
```
|
|
76
106
|
|
|
77
|
-
|
|
78
|
-
|
|
107
|
+
### Apply inputs to typst to product multiple PDFs
|
|
108
|
+
```ruby
|
|
79
109
|
t = Typst(body: sys_inputs_example)
|
|
80
110
|
people.each do |person|
|
|
81
111
|
t.with_inputs({ "persons" => [person].to_json }).compile(:pdf).write("#{person['name']}.pdf")
|
|
82
112
|
end
|
|
113
|
+
```
|
|
83
114
|
|
|
84
|
-
|
|
115
|
+
### A more complex example of compiling from string using other dependency typst template, svg and font resources all in memory
|
|
116
|
+
```ruby
|
|
85
117
|
main = %{
|
|
86
118
|
#import "template.typ": *
|
|
87
119
|
|
|
@@ -103,10 +135,33 @@ icon = File.read("icon.svg")
|
|
|
103
135
|
font_bytes = File.read("Example.ttf")
|
|
104
136
|
|
|
105
137
|
Typst(body: main, dependencies: { "template.typ" => template, "icon.svg" => icon }, fonts: { "Example.ttf" => font_bytes }).compile(:pdf)
|
|
138
|
+
```
|
|
106
139
|
|
|
107
|
-
|
|
140
|
+
### From a zip with a named main typst file
|
|
141
|
+
```ruby
|
|
108
142
|
Typst(zip: "test/main.typ.zip", main_file: "hello.typ").compile(:pdf)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Use a package from the [Typst Universe](https://typst.app/universe)
|
|
146
|
+
Your package_example.typ file...
|
|
147
|
+
```typst
|
|
148
|
+
#import "@preview/wordometer:0.1.5": word-count, total-words
|
|
149
|
+
#show: word-count
|
|
109
150
|
|
|
151
|
+
In this document, there are #total-words words all up.
|
|
152
|
+
|
|
153
|
+
#word-count(total => [
|
|
154
|
+
The number of words in this block is #total.words
|
|
155
|
+
and there are #total.characters letters.
|
|
156
|
+
])
|
|
157
|
+
```
|
|
158
|
+
...compiles just like anything else
|
|
159
|
+
```ruby
|
|
160
|
+
Typst("package_example.typ").compile(:pdf).write("package_example.pdf")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Query a typst document
|
|
164
|
+
```ruby
|
|
110
165
|
Typst("readme.typ").query("heading").result
|
|
111
166
|
# =>
|
|
112
167
|
# [{"func" => "heading",
|
|
@@ -122,13 +177,15 @@ Typst("readme.typ").query("heading", format: "yaml").result(raw: true)
|
|
|
122
177
|
|
|
123
178
|
# Query results as JSON string
|
|
124
179
|
Typst("test/test.typ").query("heading").to_s
|
|
125
|
-
=> "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
180
|
+
# => "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
126
181
|
|
|
127
182
|
# Query results as YAML string
|
|
128
183
|
Typst("test/test.typ").query("heading", format: "yaml").to_s
|
|
129
|
-
=> "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
184
|
+
# => "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
185
|
+
```
|
|
130
186
|
|
|
131
|
-
|
|
187
|
+
### clear the compilation cache
|
|
188
|
+
```ruby
|
|
132
189
|
# Evict all entries whose age is larger than or equal to `max_age`
|
|
133
190
|
max_age = 10
|
|
134
191
|
Typst::clear_cache(max_age)
|
data/README.typ
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#set document(title: [typst.rb README])
|
|
2
2
|
#show link: underline
|
|
3
3
|
#show link: set text(blue)
|
|
4
|
+
#show raw.where(block: true): block.with(
|
|
5
|
+
fill: luma(240),
|
|
6
|
+
inset: 10pt,
|
|
7
|
+
radius: 4pt,
|
|
8
|
+
)
|
|
4
9
|
|
|
5
10
|
= typst-rb
|
|
6
11
|
|
|
@@ -19,53 +24,82 @@ require "typst"
|
|
|
19
24
|
|
|
20
25
|
# Compile a typst file and write the output to a PDF file
|
|
21
26
|
Typst("readme.typ").compile(:pdf).write("readme.pdf")
|
|
27
|
+
```
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
=== Use a typst file `readme.typ`
|
|
30
|
+
```ruby
|
|
24
31
|
t = Typst("readme.typ")
|
|
32
|
+
```
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
=== Use a typst string
|
|
35
|
+
```ruby
|
|
27
36
|
t = Typst(body: %{hello world})
|
|
37
|
+
```
|
|
28
38
|
|
|
29
|
-
|
|
39
|
+
=== Use a typst file in a zip file
|
|
40
|
+
```ruby
|
|
30
41
|
t = Typst(zip: "test/main.typ.zip")
|
|
42
|
+
```
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
=== Compile to PDF
|
|
45
|
+
```ruby
|
|
33
46
|
doc = t.compile(:pdf)
|
|
47
|
+
```
|
|
34
48
|
|
|
35
|
-
|
|
49
|
+
=== Compile to PDF selecting the typst supported PdfStandard
|
|
50
|
+
```ruby
|
|
36
51
|
doc = t.compile(:pdf, pdf_standards: ["2.0"])
|
|
52
|
+
```
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
=== Compile to SVG
|
|
55
|
+
```ruby
|
|
39
56
|
doc = t.compile(:svg)
|
|
57
|
+
```
|
|
40
58
|
|
|
41
|
-
|
|
59
|
+
=== Compile to PNG
|
|
60
|
+
```ruby
|
|
42
61
|
doc = t.compile(:png)
|
|
62
|
+
```
|
|
43
63
|
|
|
44
|
-
|
|
64
|
+
=== Compile to PNG and set PPI
|
|
65
|
+
```ruby
|
|
45
66
|
doc = t.compile(:png, ppi: 72)
|
|
67
|
+
```
|
|
46
68
|
|
|
47
|
-
|
|
69
|
+
=== Compile to HTML (using Typst expirmental HTML)
|
|
70
|
+
```ruby
|
|
48
71
|
doc = t.compile(:html_experimental)
|
|
72
|
+
```
|
|
49
73
|
|
|
50
|
-
|
|
74
|
+
=== Or return content as an array of bytes
|
|
75
|
+
```ruby
|
|
51
76
|
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
|
52
77
|
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
|
78
|
+
```
|
|
53
79
|
|
|
54
|
-
|
|
55
|
-
|
|
80
|
+
=== Write the output to a file
|
|
81
|
+
Note: for multi-page documents using formats other than PDF and HTML, pages write to multiple files, e.g. `readme_0.png`, `readme_1.png`
|
|
82
|
+
```ruby
|
|
56
83
|
doc.write("filename.pdf")
|
|
84
|
+
```
|
|
57
85
|
|
|
58
|
-
|
|
86
|
+
=== Return PDF, SVG, PNG or HTML content as an array of pages
|
|
87
|
+
```ruby
|
|
59
88
|
Typst("readme.typ").compile(:pdf).pages
|
|
60
89
|
# => ["%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 ...
|
|
90
|
+
|
|
61
91
|
Typst("readme.typ").compile(:svg).pages
|
|
62
92
|
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ...
|
|
93
|
+
|
|
63
94
|
Typst("readme.typ").compile(:png).pages
|
|
64
95
|
# => ["\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x04\xA7\x00\x00\x06\x94\b\ ...
|
|
96
|
+
|
|
65
97
|
Typst("readme.typ").compile(:html_experimental).pages
|
|
66
98
|
# => ["<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" ...
|
|
99
|
+
```
|
|
67
100
|
|
|
68
|
-
|
|
101
|
+
=== Pass values into typst using sys_inputs
|
|
102
|
+
```ruby
|
|
69
103
|
sys_inputs_example = %{
|
|
70
104
|
#let persons = json(bytes(sys.inputs.persons))
|
|
71
105
|
|
|
@@ -76,15 +110,18 @@ sys_inputs_example = %{
|
|
|
76
110
|
people = [{"name" => "John", "age" => 35}, {"name" => "Xoliswa", "age" => 45}]
|
|
77
111
|
data = { "persons" => people.to_json }
|
|
78
112
|
Typst(body: sys_inputs_example, sys_inputs: data).compile(:pdf).write("sys_inputs_example.pdf")
|
|
113
|
+
```
|
|
79
114
|
|
|
80
|
-
|
|
81
|
-
|
|
115
|
+
=== Apply inputs to typst to product multiple PDFs
|
|
116
|
+
```ruby
|
|
82
117
|
t = Typst(body: sys_inputs_example)
|
|
83
118
|
people.each do |person|
|
|
84
119
|
t.with_inputs({ "persons" => [person].to_json }).compile(:pdf).write("#{person['name']}.pdf")
|
|
85
120
|
end
|
|
121
|
+
```
|
|
86
122
|
|
|
87
|
-
|
|
123
|
+
=== A more complex example of compiling from string using other dependency typst template, svg and font resources all in memory
|
|
124
|
+
```ruby
|
|
88
125
|
main = %{
|
|
89
126
|
#import "template.typ": *
|
|
90
127
|
|
|
@@ -106,10 +143,33 @@ icon = File.read("icon.svg")
|
|
|
106
143
|
font_bytes = File.read("Example.ttf")
|
|
107
144
|
|
|
108
145
|
Typst(body: main, dependencies: { "template.typ" => template, "icon.svg" => icon }, fonts: { "Example.ttf" => font_bytes }).compile(:pdf)
|
|
146
|
+
```
|
|
109
147
|
|
|
110
|
-
|
|
148
|
+
=== From a zip with a named main typst file
|
|
149
|
+
```ruby
|
|
111
150
|
Typst(zip: "test/main.typ.zip", main_file: "hello.typ").compile(:pdf)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
=== Use a package from the #link("https://typst.app/universe")[Typst Universe]
|
|
154
|
+
Your package_example.typ file...
|
|
155
|
+
```typst
|
|
156
|
+
#import "@preview/wordometer:0.1.5": word-count, total-words
|
|
157
|
+
#show: word-count
|
|
112
158
|
|
|
159
|
+
In this document, there are #total-words words all up.
|
|
160
|
+
|
|
161
|
+
#word-count(total => [
|
|
162
|
+
The number of words in this block is #total.words
|
|
163
|
+
and there are #total.characters letters.
|
|
164
|
+
])
|
|
165
|
+
```
|
|
166
|
+
...compiles just like anything else
|
|
167
|
+
```ruby
|
|
168
|
+
Typst("package_example.typ").compile(:pdf).write("package_example.pdf")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
=== Query a typst document
|
|
172
|
+
```ruby
|
|
113
173
|
Typst("readme.typ").query("heading").result
|
|
114
174
|
# =>
|
|
115
175
|
# [{"func" => "heading",
|
|
@@ -125,13 +185,15 @@ Typst("readme.typ").query("heading", format: "yaml").result(raw: true)
|
|
|
125
185
|
|
|
126
186
|
# Query results as JSON string
|
|
127
187
|
Typst("test/test.typ").query("heading").to_s
|
|
128
|
-
=> "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
188
|
+
# => "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
129
189
|
|
|
130
190
|
# Query results as YAML string
|
|
131
191
|
Typst("test/test.typ").query("heading", format: "yaml").to_s
|
|
132
|
-
=> "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
192
|
+
# => "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
193
|
+
```
|
|
133
194
|
|
|
134
|
-
|
|
195
|
+
=== clear the compilation cache
|
|
196
|
+
```ruby
|
|
135
197
|
# Evict all entries whose age is larger than or equal to `max_age`
|
|
136
198
|
max_age = 10
|
|
137
199
|
Typst::clear_cache(max_age)
|
data/ext/typst/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "typst"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.15.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -12,7 +12,7 @@ chrono = { version = "0.4.42", default-features = false, features = [
|
|
|
12
12
|
"std",
|
|
13
13
|
] }
|
|
14
14
|
codespan-reporting = "0.13"
|
|
15
|
-
comemo = "0.5.
|
|
15
|
+
comemo = "0.5.1"
|
|
16
16
|
dirs = "5" #
|
|
17
17
|
ecow = "0.2"
|
|
18
18
|
env_logger = "0.10.1" #
|
|
@@ -29,18 +29,21 @@ tar = "0.4" #
|
|
|
29
29
|
serde = { version = "1.0.228", features = ["derive"] }
|
|
30
30
|
serde_json = "1"
|
|
31
31
|
serde_yaml = "0.9"
|
|
32
|
-
typst = "0.
|
|
33
|
-
typst-library = "0.
|
|
34
|
-
typst-kit = { version = "0.
|
|
35
|
-
"
|
|
36
|
-
"
|
|
32
|
+
typst = "0.15.0"
|
|
33
|
+
typst-library = "0.15.0"
|
|
34
|
+
typst-kit = { version = "0.15.0", features = [
|
|
35
|
+
"embedded-fonts",
|
|
36
|
+
"scan-fonts",
|
|
37
|
+
"system-downloader",
|
|
38
|
+
"system-packages",
|
|
37
39
|
"vendor-openssl",
|
|
38
40
|
] }
|
|
39
|
-
typst-pdf = "0.
|
|
40
|
-
typst-svg = "0.
|
|
41
|
-
typst-html = "0.
|
|
42
|
-
typst-render = "0.
|
|
43
|
-
typst-eval = "0.
|
|
41
|
+
typst-pdf = "0.15.0"
|
|
42
|
+
typst-svg = "0.15.0"
|
|
43
|
+
typst-html = "0.15.0"
|
|
44
|
+
typst-render = "0.15.0"
|
|
45
|
+
typst-eval = "0.15.0"
|
|
46
|
+
typst-layout = "0.15.0"
|
|
44
47
|
ureq = { version = "2", default-features = false, features = [
|
|
45
48
|
"gzip",
|
|
46
49
|
"socks-proxy",
|
|
@@ -49,4 +52,4 @@ walkdir = "2.4.0"
|
|
|
49
52
|
|
|
50
53
|
# enable rb-sys feature to test against Ruby head. This is only needed if you
|
|
51
54
|
# want to work with the unreleased, in-development, next version of Ruby
|
|
52
|
-
rb-sys = { version = "0.9.
|
|
55
|
+
rb-sys = { version = "0.9.128", default-features = false, features = ["stable-api-compiled-fallback"] }
|
data/ext/typst/src/compiler.rs
CHANGED
|
@@ -2,11 +2,11 @@ use chrono::{Datelike, Timelike};
|
|
|
2
2
|
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
|
3
3
|
use codespan_reporting::term::{self, termcolor};
|
|
4
4
|
use ecow::{eco_format, EcoString};
|
|
5
|
-
use typst::diag::{Severity, SourceDiagnostic, StrResult, Warned};
|
|
5
|
+
use typst::diag::{At, Severity, SourceDiagnostic, StrResult, Warned};
|
|
6
6
|
use typst::foundations::Datetime;
|
|
7
7
|
use typst_html::HtmlDocument;
|
|
8
|
-
use
|
|
9
|
-
use typst::syntax::{FileId, Lines, Span};
|
|
8
|
+
use typst_layout::PagedDocument;
|
|
9
|
+
use typst::syntax::{DiagSpan, FileId, Lines, Span};
|
|
10
10
|
use typst::{World, WorldExt};
|
|
11
11
|
|
|
12
12
|
use crate::world::SystemWorld;
|
|
@@ -45,7 +45,9 @@ impl SystemWorld {
|
|
|
45
45
|
"pdf" => Ok(vec![export_pdf(
|
|
46
46
|
&document,
|
|
47
47
|
self,
|
|
48
|
-
typst_pdf::PdfStandards::new(pdf_standards)
|
|
48
|
+
typst_pdf::PdfStandards::new(pdf_standards)
|
|
49
|
+
.map_err(|e| eco_format!("PDF standards error: {:?}", e))
|
|
50
|
+
.at(Span::detached()).unwrap()
|
|
49
51
|
)?]),
|
|
50
52
|
"png" => Ok(export_image(&document, ImageExportFormat::Png, ppi)?),
|
|
51
53
|
"svg" => Ok(export_image(&document, ImageExportFormat::Svg, ppi)?),
|
|
@@ -65,7 +67,7 @@ fn export_html(
|
|
|
65
67
|
document: &HtmlDocument,
|
|
66
68
|
world: &SystemWorld,
|
|
67
69
|
) -> StrResult<Vec<u8>> {
|
|
68
|
-
let html = typst_html::html(document)
|
|
70
|
+
let html = typst_html::html(document, &typst_html::HtmlOptions::default())
|
|
69
71
|
.map_err(|e| match format_diagnostics(world, &e, &[]) {
|
|
70
72
|
Ok(e) => EcoString::from(e),
|
|
71
73
|
Err(err) => eco_format!("failed to print diagnostics ({err})"),
|
|
@@ -81,11 +83,10 @@ fn export_pdf(
|
|
|
81
83
|
world: &SystemWorld,
|
|
82
84
|
standards: typst_pdf::PdfStandards,
|
|
83
85
|
) -> StrResult<Vec<u8>> {
|
|
84
|
-
let ident = world.input().to_string_lossy();
|
|
85
86
|
let buffer = typst_pdf::pdf(
|
|
86
87
|
document,
|
|
87
88
|
&typst_pdf::PdfOptions {
|
|
88
|
-
ident: typst::foundations::Smart::
|
|
89
|
+
ident: typst::foundations::Smart::Auto,
|
|
89
90
|
timestamp: now().map(typst_pdf::Timestamp::new_utc),
|
|
90
91
|
standards,
|
|
91
92
|
..Default::default()
|
|
@@ -95,7 +96,7 @@ fn export_pdf(
|
|
|
95
96
|
Ok(e) => EcoString::from(e),
|
|
96
97
|
Err(err) => eco_format!("failed to print diagnostics ({err})"),
|
|
97
98
|
})?;
|
|
98
|
-
Ok(buffer)
|
|
99
|
+
Ok(buffer.into())
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
/// Get the current date and time in UTC.
|
|
@@ -124,13 +125,19 @@ fn export_image(
|
|
|
124
125
|
ppi: Option<f32>,
|
|
125
126
|
) -> StrResult<Vec<Vec<u8>>> {
|
|
126
127
|
let mut buffers = Vec::new();
|
|
127
|
-
for page in
|
|
128
|
+
for page in document.pages() {
|
|
128
129
|
let buffer = match fmt {
|
|
129
|
-
ImageExportFormat::Png => typst_render::render(
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
ImageExportFormat::Png => typst_render::render(
|
|
131
|
+
page,
|
|
132
|
+
&typst_render::RenderOptions {
|
|
133
|
+
pixel_per_pt: typst::utils::Scalar::new(f64::from(ppi.unwrap_or(144.0) / 72.0)),
|
|
134
|
+
render_bleed: false,
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
.encode_png()
|
|
138
|
+
.map_err(|err| eco_format!("failed to write PNG file ({err})"))?,
|
|
132
139
|
ImageExportFormat::Svg => {
|
|
133
|
-
let svg = typst_svg::svg(page);
|
|
140
|
+
let svg = typst_svg::svg(page, &typst_svg::SvgOptions::default());
|
|
134
141
|
svg.as_bytes().to_vec()
|
|
135
142
|
}
|
|
136
143
|
};
|
|
@@ -162,7 +169,7 @@ pub fn format_diagnostics(
|
|
|
162
169
|
diagnostic
|
|
163
170
|
.hints
|
|
164
171
|
.iter()
|
|
165
|
-
.map(|e| (eco_format!("hint: {
|
|
172
|
+
.map(|e| (eco_format!("hint: {}", e.v)).into())
|
|
166
173
|
.collect(),
|
|
167
174
|
)
|
|
168
175
|
.with_labels(label(world, diagnostic.span).into_iter().collect());
|
|
@@ -185,7 +192,8 @@ pub fn format_diagnostics(
|
|
|
185
192
|
}
|
|
186
193
|
|
|
187
194
|
/// Create a label for a span.
|
|
188
|
-
fn label(world: &SystemWorld, span:
|
|
195
|
+
fn label(world: &SystemWorld, span: impl Into<DiagSpan>) -> Option<Label<FileId>> {
|
|
196
|
+
let span = span.into();
|
|
189
197
|
Some(Label::primary(span.id()?, world.range(span)?))
|
|
190
198
|
}
|
|
191
199
|
|
|
@@ -196,15 +204,16 @@ impl<'a> codespan_reporting::files::Files<'a> for SystemWorld {
|
|
|
196
204
|
|
|
197
205
|
fn name(&'a self, id: FileId) -> CodespanResult<Self::Name> {
|
|
198
206
|
let vpath = id.vpath();
|
|
199
|
-
Ok(if let
|
|
200
|
-
format!("{package}{}", vpath.
|
|
207
|
+
Ok(if let typst::syntax::VirtualRoot::Package(package) = id.root() {
|
|
208
|
+
format!("{package}{}", vpath.get_with_slash())
|
|
201
209
|
} else {
|
|
202
210
|
// Try to express the path relative to the working directory.
|
|
203
211
|
vpath
|
|
204
|
-
.
|
|
212
|
+
.realize(self.root())
|
|
213
|
+
.ok()
|
|
205
214
|
.and_then(|abs| pathdiff::diff_paths(abs, self.workdir()))
|
|
206
215
|
.as_deref()
|
|
207
|
-
.unwrap_or_else(|| vpath.
|
|
216
|
+
.unwrap_or_else(|| std::path::Path::new(vpath.get_without_slash()))
|
|
208
217
|
.to_string_lossy()
|
|
209
218
|
.into()
|
|
210
219
|
})
|
data/ext/typst/src/download.rs
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
use
|
|
2
|
-
|
|
3
|
-
use typst_kit::download::{DownloadState, Downloader, Progress};
|
|
4
|
-
|
|
5
|
-
pub struct SlientDownload<T>(pub T);
|
|
6
|
-
|
|
7
|
-
impl<T: Display> Progress for SlientDownload<T> {
|
|
8
|
-
fn print_start(&mut self) {}
|
|
9
|
-
|
|
10
|
-
fn print_progress(&mut self, _state: &DownloadState) {}
|
|
11
|
-
|
|
12
|
-
fn print_finish(&mut self, _state: &DownloadState) {}
|
|
13
|
-
}
|
|
1
|
+
use typst_kit::downloader::{Downloader, SystemDownloader};
|
|
14
2
|
|
|
15
3
|
/// Returns a new downloader.
|
|
16
|
-
pub fn downloader() -> Downloader {
|
|
4
|
+
pub fn downloader() -> impl Downloader {
|
|
17
5
|
let user_agent = concat!("typst-rb/", env!("CARGO_PKG_VERSION"));
|
|
18
|
-
|
|
6
|
+
SystemDownloader::new(user_agent)
|
|
19
7
|
}
|