typst 0.14.2.3 → 0.15.1.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.
data/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
data/README.md CHANGED
@@ -193,7 +193,8 @@ Typst::clear_cache(max_age)
193
193
 
194
194
  ## Contributors & Acknowledgements
195
195
  typst-rb is based on [typst-py](https://github.com/messense/typst-py) by [messense](https://github.com/messense)\
196
- clear_cache was contributed by [NRicciVestmark](https://github.com/NRicciVestmark)
196
+ clear_cache was contributed by [NRicciVestmark](https://github.com/NRicciVestmark)\
197
+ CI improvements were contributed by [am1006](https://github.com/am1006)
197
198
 
198
199
  ## License
199
200
 
data/README.typ CHANGED
@@ -201,7 +201,8 @@ Typst::clear_cache(max_age)
201
201
 
202
202
  == Contributors & Acknowledgements
203
203
  typst-rb is based on #link("https://github.com/messense/typst-py")[typst-py] by #link("https://github.com/messense")[messense]\
204
- clear_cache was contributed by #link("https://github.com/NRicciVestmark")[NRicciVestmark]
204
+ clear_cache was contributed by #link("https://github.com/NRicciVestmark")[NRicciVestmark]\
205
+ CI improvements were contributed by #link("https://github.com/am1006")[am1006]
205
206
 
206
207
  == License
207
208
 
data/ext/typst/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "typst"
3
- version = "0.14.2"
3
+ version = "0.15.1"
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.0"
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.14.2"
33
- typst-library = "0.14.2"
34
- typst-kit = { version = "0.14.2", features = [
35
- "downloads",
36
- "embed-fonts",
32
+ typst = "0.15.1"
33
+ typst-library = "0.15.1"
34
+ typst-kit = { version = "0.15.1", features = [
35
+ "embedded-fonts",
36
+ "scan-fonts",
37
+ "system-downloader",
38
+ "system-packages",
37
39
  "vendor-openssl",
38
40
  ] }
39
- typst-pdf = "0.14.2"
40
- typst-svg = "0.14.2"
41
- typst-html = "0.14.2"
42
- typst-render = "0.14.2"
43
- typst-eval = "0.14.2"
41
+ typst-pdf = "0.15.1"
42
+ typst-svg = "0.15.1"
43
+ typst-html = "0.15.1"
44
+ typst-render = "0.15.1"
45
+ typst-eval = "0.15.1"
46
+ typst-layout = "0.15.1"
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.124", default-features = false, features = ["stable-api-compiled-fallback"] }
55
+ rb-sys = { version = "0.9.128", default-features = false, features = ["stable-api-compiled-fallback"] }
@@ -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 typst::layout::PagedDocument;
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;
@@ -20,6 +20,7 @@ impl SystemWorld {
20
20
  format: Option<&str>,
21
21
  ppi: Option<f32>,
22
22
  pdf_standards: &[typst_pdf::PdfStandard],
23
+ pretty: bool,
23
24
  ) -> StrResult<Vec<Vec<u8>>> {
24
25
  // Reset everything and ensure that the main file is present.
25
26
  self.reset();
@@ -30,7 +31,7 @@ impl SystemWorld {
30
31
  let Warned { output, warnings } = typst::compile::<HtmlDocument>(self);
31
32
  match output {
32
33
  Ok(document) => {
33
- Ok(vec![export_html(&document, self)?])
34
+ Ok(vec![export_html(&document, self, pretty)?])
34
35
  }
35
36
  Err(errors) => Err(format_diagnostics(self, &errors, &warnings).unwrap().into()),
36
37
  }
@@ -45,10 +46,13 @@ impl SystemWorld {
45
46
  "pdf" => Ok(vec![export_pdf(
46
47
  &document,
47
48
  self,
48
- typst_pdf::PdfStandards::new(pdf_standards)?,
49
+ typst_pdf::PdfStandards::new(pdf_standards)
50
+ .map_err(|e| eco_format!("PDF standards error: {:?}", e))
51
+ .at(Span::detached()).unwrap(),
52
+ pretty
49
53
  )?]),
50
- "png" => Ok(export_image(&document, ImageExportFormat::Png, ppi)?),
51
- "svg" => Ok(export_image(&document, ImageExportFormat::Svg, ppi)?),
54
+ "png" => Ok(export_image(&document, ImageExportFormat::Png, ppi, pretty)?),
55
+ "svg" => Ok(export_image(&document, ImageExportFormat::Svg, ppi, pretty)?),
52
56
  fmt => Err(eco_format!("unknown format: {fmt}")),
53
57
  }
54
58
  }
@@ -64,8 +68,9 @@ impl SystemWorld {
64
68
  fn export_html(
65
69
  document: &HtmlDocument,
66
70
  world: &SystemWorld,
71
+ pretty: bool,
67
72
  ) -> StrResult<Vec<u8>> {
68
- let html = typst_html::html(document)
73
+ let html = typst_html::html(document, &typst_html::HtmlOptions{ pretty: pretty })
69
74
  .map_err(|e| match format_diagnostics(world, &e, &[]) {
70
75
  Ok(e) => EcoString::from(e),
71
76
  Err(err) => eco_format!("failed to print diagnostics ({err})"),
@@ -80,14 +85,15 @@ fn export_pdf(
80
85
  document: &PagedDocument,
81
86
  world: &SystemWorld,
82
87
  standards: typst_pdf::PdfStandards,
88
+ pretty: bool,
83
89
  ) -> StrResult<Vec<u8>> {
84
- let ident = world.input().to_string_lossy();
85
90
  let buffer = typst_pdf::pdf(
86
91
  document,
87
92
  &typst_pdf::PdfOptions {
88
- ident: typst::foundations::Smart::Custom(&ident),
93
+ ident: typst::foundations::Smart::Auto,
89
94
  timestamp: now().map(typst_pdf::Timestamp::new_utc),
90
95
  standards,
96
+ pretty,
91
97
  ..Default::default()
92
98
  },
93
99
  )
@@ -95,7 +101,7 @@ fn export_pdf(
95
101
  Ok(e) => EcoString::from(e),
96
102
  Err(err) => eco_format!("failed to print diagnostics ({err})"),
97
103
  })?;
98
- Ok(buffer)
104
+ Ok(buffer.into())
99
105
  }
100
106
 
101
107
  /// Get the current date and time in UTC.
@@ -122,15 +128,22 @@ fn export_image(
122
128
  document: &PagedDocument,
123
129
  fmt: ImageExportFormat,
124
130
  ppi: Option<f32>,
131
+ pretty: bool,
125
132
  ) -> StrResult<Vec<Vec<u8>>> {
126
133
  let mut buffers = Vec::new();
127
- for page in &document.pages {
134
+ for page in document.pages() {
128
135
  let buffer = match fmt {
129
- ImageExportFormat::Png => typst_render::render(page, ppi.unwrap_or(144.0) / 72.0)
130
- .encode_png()
131
- .map_err(|err| eco_format!("failed to write PNG file ({err})"))?,
136
+ ImageExportFormat::Png => typst_render::render(
137
+ page,
138
+ &typst_render::RenderOptions {
139
+ pixel_per_pt: typst::utils::Scalar::new(f64::from(ppi.unwrap_or(144.0) / 72.0)),
140
+ render_bleed: false,
141
+ },
142
+ )
143
+ .encode_png()
144
+ .map_err(|err| eco_format!("failed to write PNG file ({err})"))?,
132
145
  ImageExportFormat::Svg => {
133
- let svg = typst_svg::svg(page);
146
+ let svg = typst_svg::svg(page, &typst_svg::SvgOptions{ render_bleed: false, pretty: pretty });
134
147
  svg.as_bytes().to_vec()
135
148
  }
136
149
  };
@@ -162,7 +175,7 @@ pub fn format_diagnostics(
162
175
  diagnostic
163
176
  .hints
164
177
  .iter()
165
- .map(|e| (eco_format!("hint: {e}")).into())
178
+ .map(|e| (eco_format!("hint: {}", e.v)).into())
166
179
  .collect(),
167
180
  )
168
181
  .with_labels(label(world, diagnostic.span).into_iter().collect());
@@ -185,7 +198,8 @@ pub fn format_diagnostics(
185
198
  }
186
199
 
187
200
  /// Create a label for a span.
188
- fn label(world: &SystemWorld, span: Span) -> Option<Label<FileId>> {
201
+ fn label(world: &SystemWorld, span: impl Into<DiagSpan>) -> Option<Label<FileId>> {
202
+ let span = span.into();
189
203
  Some(Label::primary(span.id()?, world.range(span)?))
190
204
  }
191
205
 
@@ -196,15 +210,16 @@ impl<'a> codespan_reporting::files::Files<'a> for SystemWorld {
196
210
 
197
211
  fn name(&'a self, id: FileId) -> CodespanResult<Self::Name> {
198
212
  let vpath = id.vpath();
199
- Ok(if let Some(package) = id.package() {
200
- format!("{package}{}", vpath.as_rooted_path().display())
213
+ Ok(if let typst::syntax::VirtualRoot::Package(package) = id.root() {
214
+ format!("{package}{}", vpath.get_with_slash())
201
215
  } else {
202
216
  // Try to express the path relative to the working directory.
203
217
  vpath
204
- .resolve(self.root())
218
+ .realize(self.root())
219
+ .ok()
205
220
  .and_then(|abs| pathdiff::diff_paths(abs, self.workdir()))
206
221
  .as_deref()
207
- .unwrap_or_else(|| vpath.as_rootless_path())
222
+ .unwrap_or_else(|| std::path::Path::new(vpath.get_without_slash()))
208
223
  .to_string_lossy()
209
224
  .into()
210
225
  })
@@ -1,19 +1,7 @@
1
- use std::fmt::Display;
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
- Downloader::new(user_agent)
6
+ SystemDownloader::new(user_agent)
19
7
  }
data/ext/typst/src/lib.rs CHANGED
@@ -19,8 +19,9 @@ fn to_html(
19
19
  input: PathBuf,
20
20
  root: Option<PathBuf>,
21
21
  font_paths: Vec<PathBuf>,
22
- resource_path: PathBuf,
23
22
  ignore_system_fonts: bool,
23
+ ignore_embedded_fonts: bool,
24
+ pretty: bool,
24
25
  sys_inputs: HashMap<String, String>,
25
26
  ) -> Result<Vec<Vec<u8>>, Error> {
26
27
  let input = input.canonicalize()
@@ -35,22 +36,6 @@ fn to_html(
35
36
  PathBuf::new()
36
37
  };
37
38
 
38
- let resource_path = resource_path.canonicalize()
39
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?;
40
-
41
- let mut default_fonts = Vec::new();
42
- for entry in walkdir::WalkDir::new(resource_path.join("fonts")) {
43
- let path = entry
44
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?
45
- .into_path();
46
- let Some(extension) = path.extension() else {
47
- continue;
48
- };
49
- if extension == "ttf" || extension == "otf" {
50
- default_fonts.push(path);
51
- }
52
- }
53
-
54
39
  let mut features = Vec::new();
55
40
  features.push(Feature::Html);
56
41
 
@@ -72,11 +57,12 @@ fn to_html(
72
57
  .features(feat)
73
58
  .font_paths(font_paths)
74
59
  .ignore_system_fonts(ignore_system_fonts)
60
+ .ignore_embedded_fonts(ignore_embedded_fonts)
75
61
  .build()
76
62
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
77
63
 
78
64
  let bytes = world
79
- .compile(Some("html"), None, &Vec::new())
65
+ .compile(Some("html"), None, &Vec::new(), pretty)
80
66
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
81
67
 
82
68
  Ok(bytes)
@@ -87,8 +73,9 @@ fn to_svg(
87
73
  input: PathBuf,
88
74
  root: Option<PathBuf>,
89
75
  font_paths: Vec<PathBuf>,
90
- resource_path: PathBuf,
91
76
  ignore_system_fonts: bool,
77
+ ignore_embedded_fonts: bool,
78
+ pretty: bool,
92
79
  sys_inputs: HashMap<String, String>,
93
80
  ) -> Result<Vec<Vec<u8>>, Error> {
94
81
  let input = input.canonicalize()
@@ -103,22 +90,6 @@ fn to_svg(
103
90
  PathBuf::new()
104
91
  };
105
92
 
106
- let resource_path = resource_path.canonicalize()
107
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?;
108
-
109
- let mut default_fonts = Vec::new();
110
- for entry in walkdir::WalkDir::new(resource_path.join("fonts")) {
111
- let path = entry
112
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?
113
- .into_path();
114
- let Some(extension) = path.extension() else {
115
- continue;
116
- };
117
- if extension == "ttf" || extension == "otf" {
118
- default_fonts.push(path);
119
- }
120
- }
121
-
122
93
  let mut world = SystemWorld::builder(root, input)
123
94
  .inputs(Dict::from_iter(
124
95
  sys_inputs
@@ -127,11 +98,12 @@ fn to_svg(
127
98
  ))
128
99
  .font_paths(font_paths)
129
100
  .ignore_system_fonts(ignore_system_fonts)
101
+ .ignore_embedded_fonts(ignore_embedded_fonts)
130
102
  .build()
131
103
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
132
104
 
133
105
  let svg_bytes = world
134
- .compile(Some("svg"), None, &Vec::new())
106
+ .compile(Some("svg"), None, &Vec::new(), pretty)
135
107
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
136
108
 
137
109
  Ok(svg_bytes)
@@ -142,8 +114,8 @@ fn to_png(
142
114
  input: PathBuf,
143
115
  root: Option<PathBuf>,
144
116
  font_paths: Vec<PathBuf>,
145
- resource_path: PathBuf,
146
117
  ignore_system_fonts: bool,
118
+ ignore_embedded_fonts: bool,
147
119
  sys_inputs: HashMap<String, String>,
148
120
  ppi: Option<f32>,
149
121
  ) -> Result<Vec<Vec<u8>>, Error> {
@@ -159,22 +131,6 @@ fn to_png(
159
131
  PathBuf::new()
160
132
  };
161
133
 
162
- let resource_path = resource_path.canonicalize()
163
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?;
164
-
165
- let mut default_fonts = Vec::new();
166
- for entry in walkdir::WalkDir::new(resource_path.join("fonts")) {
167
- let path = entry
168
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?
169
- .into_path();
170
- let Some(extension) = path.extension() else {
171
- continue;
172
- };
173
- if extension == "ttf" || extension == "otf" {
174
- default_fonts.push(path);
175
- }
176
- }
177
-
178
134
  let mut world = SystemWorld::builder(root, input)
179
135
  .inputs(Dict::from_iter(
180
136
  sys_inputs
@@ -183,11 +139,12 @@ fn to_png(
183
139
  ))
184
140
  .font_paths(font_paths)
185
141
  .ignore_system_fonts(ignore_system_fonts)
142
+ .ignore_embedded_fonts(ignore_embedded_fonts)
186
143
  .build()
187
144
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
188
145
 
189
146
  let bytes = world
190
- .compile(Some("png"), ppi, &Vec::new())
147
+ .compile(Some("png"), ppi, &Vec::new(), false)
191
148
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
192
149
 
193
150
  Ok(bytes)
@@ -198,8 +155,9 @@ fn to_pdf(
198
155
  input: PathBuf,
199
156
  root: Option<PathBuf>,
200
157
  font_paths: Vec<PathBuf>,
201
- resource_path: PathBuf,
202
158
  ignore_system_fonts: bool,
159
+ ignore_embedded_fonts: bool,
160
+ pretty: bool,
203
161
  sys_inputs: HashMap<String, String>,
204
162
  pdf_standards: Vec<String>,
205
163
  ) -> Result<Vec<Vec<u8>>, Error> {
@@ -215,22 +173,6 @@ fn to_pdf(
215
173
  PathBuf::new()
216
174
  };
217
175
 
218
- let resource_path = resource_path.canonicalize()
219
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?;
220
-
221
- let mut default_fonts = Vec::new();
222
- for entry in walkdir::WalkDir::new(resource_path.join("fonts")) {
223
- let path = entry
224
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?
225
- .into_path();
226
- let Some(extension) = path.extension() else {
227
- continue;
228
- };
229
- if extension == "ttf" || extension == "otf" {
230
- default_fonts.push(path);
231
- }
232
- }
233
-
234
176
  let mut world = SystemWorld::builder(root, input)
235
177
  .inputs(Dict::from_iter(
236
178
  sys_inputs
@@ -239,6 +181,7 @@ fn to_pdf(
239
181
  ))
240
182
  .font_paths(font_paths)
241
183
  .ignore_system_fonts(ignore_system_fonts)
184
+ .ignore_embedded_fonts(ignore_embedded_fonts)
242
185
  .build()
243
186
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
244
187
 
@@ -272,7 +215,7 @@ fn to_pdf(
272
215
  }
273
216
 
274
217
  let pdf_bytes = world
275
- .compile(Some("pdf"), None, &pdf_standards_vec)
218
+ .compile(Some("pdf"), None, &pdf_standards_vec, pretty)
276
219
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
277
220
 
278
221
  Ok(pdf_bytes)
@@ -287,8 +230,8 @@ fn query(
287
230
  input: PathBuf,
288
231
  root: Option<PathBuf>,
289
232
  font_paths: Vec<PathBuf>,
290
- resource_path: PathBuf,
291
233
  ignore_system_fonts: bool,
234
+ ignore_embedded_fonts: bool,
292
235
  sys_inputs: HashMap<String, String>,
293
236
  ) -> Result<String, Error> {
294
237
  let format = match format.unwrap().to_ascii_lowercase().as_str() {
@@ -309,22 +252,6 @@ fn query(
309
252
  PathBuf::new()
310
253
  };
311
254
 
312
- let resource_path = resource_path.canonicalize()
313
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?;
314
-
315
- let mut default_fonts = Vec::new();
316
- for entry in walkdir::WalkDir::new(resource_path.join("fonts")) {
317
- let path = entry
318
- .map_err(|err| magnus::Error::new(ruby.exception_arg_error(), err.to_string()))?
319
- .into_path();
320
- let Some(extension) = path.extension() else {
321
- continue;
322
- };
323
- if extension == "ttf" || extension == "otf" {
324
- default_fonts.push(path);
325
- }
326
- }
327
-
328
255
  let mut world = SystemWorld::builder(root, input)
329
256
  .inputs(Dict::from_iter(
330
257
  sys_inputs
@@ -333,6 +260,7 @@ fn query(
333
260
  ))
334
261
  .font_paths(font_paths)
335
262
  .ignore_system_fonts(ignore_system_fonts)
263
+ .ignore_embedded_fonts(ignore_embedded_fonts)
336
264
  .build()
337
265
  .map_err(|msg| magnus::Error::new(ruby.exception_arg_error(), msg.to_string()))?;
338
266
 
@@ -361,10 +289,10 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
361
289
  env_logger::init();
362
290
 
363
291
  let module = ruby.define_module("Typst")?;
364
- module.define_singleton_method("_to_pdf", function!(to_pdf, 7))?;
365
- module.define_singleton_method("_to_svg", function!(to_svg, 6))?;
292
+ module.define_singleton_method("_to_pdf", function!(to_pdf, 8))?;
293
+ module.define_singleton_method("_to_svg", function!(to_svg, 7))?;
366
294
  module.define_singleton_method("_to_png", function!(to_png, 7))?;
367
- module.define_singleton_method("_to_html", function!(to_html, 6))?;
295
+ module.define_singleton_method("_to_html", function!(to_html, 7))?;
368
296
  module.define_singleton_method("_query", function!(query, 10))?;
369
297
  module.define_singleton_method("_clear_cache", function!(clear_cache, 1))?;
370
298
  Ok(())