typst 0.13.3-aarch64-linux
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 +7 -0
- data/Cargo.toml +3 -0
- data/README.md +133 -0
- data/README.typ +136 -0
- data/Rakefile +34 -0
- data/ext/typst/Cargo.toml +54 -0
- data/ext/typst/extconf.rb +4 -0
- data/ext/typst/src/compiler-new.rs +771 -0
- data/ext/typst/src/compiler.rs +248 -0
- data/ext/typst/src/download.rs +19 -0
- data/ext/typst/src/fonts.rs +86 -0
- data/ext/typst/src/lib.rs +330 -0
- data/ext/typst/src/package.rs +64 -0
- data/ext/typst/src/query.rs +131 -0
- data/ext/typst/src/world.rs +351 -0
- data/lib/base.rb +169 -0
- data/lib/document.rb +29 -0
- 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
- data/lib/formats/html.rb +35 -0
- data/lib/formats/html_experimental.rb +11 -0
- data/lib/formats/pdf.rb +11 -0
- data/lib/formats/png.rb +11 -0
- data/lib/formats/svg.rb +11 -0
- data/lib/query.rb +19 -0
- data/lib/typst/typst.so +0 -0
- data/lib/typst.rb +31 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8f7743f59871d09e97d38d923214fc262c7f03c84f3d1c9710759d0d8d36b458
|
4
|
+
data.tar.gz: 4f4f8ca45978cd978f4f502ba7c9adec177bd00ba5d6a6a6b8fcd0b9c021bb37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdf28e7318b9429a2b9602c595dfeaf19c6f2f5240f807ddb4b70737d165d528ae6b23496e1d47b75c300a52c2902bbc304d02a35d4a8d29206044fab2810326
|
7
|
+
data.tar.gz: b3669793099c7c7ef6fada40fde0ea598f27fe64d02b870b6e7bca43b7b8901e94221736621970336526ab95223326c8dc706a08664b20941925631b83c754f8
|
data/Cargo.toml
ADDED
data/README.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# typst-rb
|
2
|
+
|
3
|
+
Ruby binding to [typst](https://github.com/typst/typst),
|
4
|
+
a new markup-based typesetting system that is powerful and easy to learn.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```bash
|
9
|
+
gem install typst
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require "typst"
|
16
|
+
|
17
|
+
# Compile a typst file and write the output to a PDF file
|
18
|
+
Typst("readme.typ").compile(:pdf).write("readme.pdf")
|
19
|
+
|
20
|
+
# Use a typst file `readme.typ`
|
21
|
+
t = Typst("readme.typ")
|
22
|
+
|
23
|
+
# Use a typst string
|
24
|
+
t = Typst(body: %{hello world})
|
25
|
+
|
26
|
+
# Use a typst file in a zip file
|
27
|
+
t = Typst(zip: "test/main.typ.zip")
|
28
|
+
|
29
|
+
# Compile to PDF
|
30
|
+
f = t.compile(:pdf)
|
31
|
+
|
32
|
+
# Compile to SVG
|
33
|
+
f = t.compile(:svg)
|
34
|
+
|
35
|
+
# Compile to PNG
|
36
|
+
f = t.compile(:png)
|
37
|
+
|
38
|
+
# Compile to SVGs enveloped in HTML
|
39
|
+
# Depracation warning: this feature will go away once Typst HTML moves out of experimental
|
40
|
+
f = t.compile(:html, title: "Typst+Ruby")
|
41
|
+
|
42
|
+
# Compile to HTML (using Typst expirmental HTML)
|
43
|
+
f = t.compile(:html_experimental)
|
44
|
+
|
45
|
+
# Access PDF or HTML output as a string
|
46
|
+
# Note: For PDF and PNG this will give data, for SVG and HTML this will give markup
|
47
|
+
Typst("readme.typ").compile(:pdf).document
|
48
|
+
# => "%PDF-1.7\n%\x80\x80\x80\x80\n\n4 0 obj\n<<\n /Type /Font\n /Subtype ..."
|
49
|
+
Typst("readme.typ").compile(:html).document
|
50
|
+
# => "\n<!DOCTYPE html>\n<html>\n<head>\n<title>main</title>\n</head>\n<body>\n<svg class=\"typst-doc\" ...
|
51
|
+
|
52
|
+
# Or return content as an array of bytes
|
53
|
+
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
54
|
+
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
55
|
+
|
56
|
+
# Write the output to a file
|
57
|
+
# Note: for multi-page documents using formats other than PDF, pages write to multiple files, e.g. `readme_0.png`, `readme_1.png`
|
58
|
+
f.write("filename.pdf")
|
59
|
+
|
60
|
+
# Return SVG, HTML or PNG content as an array of pages
|
61
|
+
Typst("readme.typ").compile(:svg).pages
|
62
|
+
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ..."
|
63
|
+
Typst("readme.typ").compile(:html).pages
|
64
|
+
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ..."
|
65
|
+
Typst("readme.typ").compile(:png).pages
|
66
|
+
# => ["\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x04\xA7\x00\x00\x06\x94\b\ ...
|
67
|
+
|
68
|
+
# Pass values into typst using sys_inputs
|
69
|
+
sys_inputs_example = %{
|
70
|
+
#let persons = json(bytes(sys.inputs.persons))
|
71
|
+
|
72
|
+
#for person in persons [
|
73
|
+
#person.name is #person.age years old.\\
|
74
|
+
]
|
75
|
+
}
|
76
|
+
people = [{"name" => "John", "age" => 35}, {"name" => "Xoliswa", "age" => 45}]
|
77
|
+
data = { "persons" => people.to_json }
|
78
|
+
Typst(body: sys_inputs_example, sys_inputs: data).compile(:pdf).write("sys_inputs_example.pdf")
|
79
|
+
|
80
|
+
# Apply inputs to typst to product multiple PDFs
|
81
|
+
|
82
|
+
t = Typst(body: sys_inputs_example)
|
83
|
+
people.each do |person|
|
84
|
+
t.with_inputs({ "persons" => [person].to_json }).compile(:pdf).write("#{person['name']}.pdf")
|
85
|
+
end
|
86
|
+
|
87
|
+
# A more complex example of compiling from string
|
88
|
+
main = %{
|
89
|
+
#import "template.typ": *
|
90
|
+
|
91
|
+
#show: template.with()
|
92
|
+
|
93
|
+
#lorem(50)
|
94
|
+
|
95
|
+
#image("icon.svg")
|
96
|
+
}
|
97
|
+
|
98
|
+
template = %{
|
99
|
+
#let template(body) = {
|
100
|
+
set text(12pt, font: "Example")
|
101
|
+
body
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
icon = File.read("icon.svg")
|
106
|
+
font_bytes = File.read("Example.ttf")
|
107
|
+
|
108
|
+
Typst(body: main, dependencies: { "template.typ" => template, "icon.svg" => icon }, fonts: { "Example.ttf" => font_bytes }).compile(:pdf)
|
109
|
+
|
110
|
+
# From a zip with a named main typst file
|
111
|
+
Typst(zip: "test/main.typ.zip", main_file: "hello.typ").compile(:pdf)
|
112
|
+
|
113
|
+
Typst::Query.new("heading", "readme.typ").result
|
114
|
+
# =>
|
115
|
+
# [{"func" => "heading",
|
116
|
+
# "level" => 1,
|
117
|
+
# "depth" => 1,
|
118
|
+
# ...
|
119
|
+
|
120
|
+
Typst::Query.new("heading", "readme.typ", format: "json").result(raw: true)
|
121
|
+
# => "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": ..."
|
122
|
+
|
123
|
+
Typst::Query.new("heading", "readme.typ", format: "yaml").result(raw: true)
|
124
|
+
# => "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: ..."
|
125
|
+
|
126
|
+
```
|
127
|
+
|
128
|
+
## Contributors & Acknowledgements
|
129
|
+
typst-rb is based on [typst-py](https://github.com/messense/typst-py) by [messense](https://github.com/messense)
|
130
|
+
|
131
|
+
## License
|
132
|
+
|
133
|
+
This work is released under the Apache-2.0 license. A copy of the license is provided in the [LICENSE](./LICENSE) file.
|
data/README.typ
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
|
2
|
+
#show link: underline
|
3
|
+
#show link: set text(blue)
|
4
|
+
|
5
|
+
= typst-rb
|
6
|
+
|
7
|
+
Ruby binding to #link("https://github.com/typst/typst")[typst], a new markup-based typesetting system that is powerful and easy to learn.
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install typst
|
13
|
+
```
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require "typst"
|
19
|
+
|
20
|
+
# Compile a typst file and write the output to a PDF file
|
21
|
+
Typst("readme.typ").compile(:pdf).write("readme.pdf")
|
22
|
+
|
23
|
+
# Use a typst file `readme.typ`
|
24
|
+
t = Typst("readme.typ")
|
25
|
+
|
26
|
+
# Use a typst string
|
27
|
+
t = Typst(body: %{hello world})
|
28
|
+
|
29
|
+
# Use a typst file in a zip file
|
30
|
+
t = Typst(zip: "test/main.typ.zip")
|
31
|
+
|
32
|
+
# Compile to PDF
|
33
|
+
f = t.compile(:pdf)
|
34
|
+
|
35
|
+
# Compile to SVG
|
36
|
+
f = t.compile(:svg)
|
37
|
+
|
38
|
+
# Compile to PNG
|
39
|
+
f = t.compile(:png)
|
40
|
+
|
41
|
+
# Compile to SVGs enveloped in HTML
|
42
|
+
# Depracation warning: this feature will go away once Typst HTML moves out of experimental
|
43
|
+
f = t.compile(:html, title: "Typst+Ruby")
|
44
|
+
|
45
|
+
# Compile to HTML (using Typst expirmental HTML)
|
46
|
+
f = t.compile(:html_experimental)
|
47
|
+
|
48
|
+
# Access PDF or HTML output as a string
|
49
|
+
# Note: For PDF and PNG this will give data, for SVG and HTML this will give markup
|
50
|
+
Typst("readme.typ").compile(:pdf).document
|
51
|
+
# => "%PDF-1.7\n%\x80\x80\x80\x80\n\n4 0 obj\n<<\n /Type /Font\n /Subtype ..."
|
52
|
+
Typst("readme.typ").compile(:html).document
|
53
|
+
# => "\n<!DOCTYPE html>\n<html>\n<head>\n<title>main</title>\n</head>\n<body>\n<svg class=\"typst-doc\" ...
|
54
|
+
|
55
|
+
# Or return content as an array of bytes
|
56
|
+
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
57
|
+
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
58
|
+
|
59
|
+
# Write the output to a file
|
60
|
+
# Note: for multi-page documents using formats other than PDF, pages write to multiple files, e.g. `readme_0.png`, `readme_1.png`
|
61
|
+
f.write("filename.pdf")
|
62
|
+
|
63
|
+
# Return SVG, HTML or PNG content as an array of pages
|
64
|
+
Typst("readme.typ").compile(:svg).pages
|
65
|
+
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ..."
|
66
|
+
Typst("readme.typ").compile(:html).pages
|
67
|
+
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ..."
|
68
|
+
Typst("readme.typ").compile(:png).pages
|
69
|
+
# => ["\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x04\xA7\x00\x00\x06\x94\b\ ...
|
70
|
+
|
71
|
+
# Pass values into typst using sys_inputs
|
72
|
+
sys_inputs_example = %{
|
73
|
+
#let persons = json(bytes(sys.inputs.persons))
|
74
|
+
|
75
|
+
#for person in persons [
|
76
|
+
#person.name is #person.age years old.\\
|
77
|
+
]
|
78
|
+
}
|
79
|
+
people = [{"name" => "John", "age" => 35}, {"name" => "Xoliswa", "age" => 45}]
|
80
|
+
data = { "persons" => people.to_json }
|
81
|
+
Typst(body: sys_inputs_example, sys_inputs: data).compile(:pdf).write("sys_inputs_example.pdf")
|
82
|
+
|
83
|
+
# Apply inputs to typst to product multiple PDFs
|
84
|
+
|
85
|
+
t = Typst(body: sys_inputs_example)
|
86
|
+
people.each do |person|
|
87
|
+
t.with_inputs({ "persons" => [person].to_json }).compile(:pdf).write("#{person['name']}.pdf")
|
88
|
+
end
|
89
|
+
|
90
|
+
# A more complex example of compiling from string
|
91
|
+
main = %{
|
92
|
+
#import "template.typ": *
|
93
|
+
|
94
|
+
#show: template.with()
|
95
|
+
|
96
|
+
#lorem(50)
|
97
|
+
|
98
|
+
#image("icon.svg")
|
99
|
+
}
|
100
|
+
|
101
|
+
template = %{
|
102
|
+
#let template(body) = {
|
103
|
+
set text(12pt, font: "Example")
|
104
|
+
body
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
icon = File.read("icon.svg")
|
109
|
+
font_bytes = File.read("Example.ttf")
|
110
|
+
|
111
|
+
Typst(body: main, dependencies: { "template.typ" => template, "icon.svg" => icon }, fonts: { "Example.ttf" => font_bytes }).compile(:pdf)
|
112
|
+
|
113
|
+
# From a zip with a named main typst file
|
114
|
+
Typst(zip: "test/main.typ.zip", main_file: "hello.typ").compile(:pdf)
|
115
|
+
|
116
|
+
Typst::Query.new("heading", "readme.typ").result
|
117
|
+
# =>
|
118
|
+
# [{"func" => "heading",
|
119
|
+
# "level" => 1,
|
120
|
+
# "depth" => 1,
|
121
|
+
# ...
|
122
|
+
|
123
|
+
Typst::Query.new("heading", "readme.typ", format: "json").result(raw: true)
|
124
|
+
# => "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": ..."
|
125
|
+
|
126
|
+
Typst::Query.new("heading", "readme.typ", format: "yaml").result(raw: true)
|
127
|
+
# => "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: ..."
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
== Contributors & Acknowledgements
|
132
|
+
typst-rb is based on #link("https://github.com/messense/typst-py")[typst-py] by #link("https://github.com/messense")[messense]
|
133
|
+
|
134
|
+
== License
|
135
|
+
|
136
|
+
This work is released under the Apache-2.0 license. A copy of the license is provided in the #link("https://github.com/actsasflinn/typst-rb/blob/main/LICENSE")[LICENSE] file.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/extensiontask"
|
3
|
+
require "rake/testtask"
|
4
|
+
require 'rake_compiler_dock'
|
5
|
+
require "rubygems/package_task"
|
6
|
+
require "bundler"
|
7
|
+
|
8
|
+
CROSS_PLATFORMS = %w[
|
9
|
+
aarch64-linux
|
10
|
+
arm64-darwin
|
11
|
+
x64-mingw32
|
12
|
+
x86_64-darwin
|
13
|
+
x86_64-linux
|
14
|
+
x86_64-linux-musl
|
15
|
+
]
|
16
|
+
|
17
|
+
spec = Bundler.load_gemspec("typst.gemspec")
|
18
|
+
|
19
|
+
Gem::PackageTask.new(spec).define
|
20
|
+
|
21
|
+
RakeCompilerDock.set_ruby_cc_version("~> 3.4")
|
22
|
+
|
23
|
+
Rake::ExtensionTask.new("typst", spec) do |ext|
|
24
|
+
ext.lib_dir = "lib/typst"
|
25
|
+
ext.source_pattern = "*.{rs,toml}"
|
26
|
+
ext.cross_compile = true
|
27
|
+
ext.cross_platform = CROSS_PLATFORMS
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::TestTask.new do |t|
|
31
|
+
t.libs << "test"
|
32
|
+
t.test_files = FileList['test/*_test.rb']
|
33
|
+
t.verbose = true
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
[package]
|
2
|
+
name = "typst"
|
3
|
+
version = "0.13.0"
|
4
|
+
edition = "2021"
|
5
|
+
|
6
|
+
[lib]
|
7
|
+
crate-type = ["cdylib"]
|
8
|
+
|
9
|
+
[dependencies]
|
10
|
+
chrono = { version = "0.4.38", default-features = false, features = [
|
11
|
+
"clock",
|
12
|
+
"std",
|
13
|
+
] }
|
14
|
+
codespan-reporting = "0.11"
|
15
|
+
comemo = "0.4"
|
16
|
+
dirs = "5" #
|
17
|
+
ecow = "0.2"
|
18
|
+
env_logger = "0.10.1" #
|
19
|
+
env_proxy = "0.4" #
|
20
|
+
filetime = "0.2.22" #
|
21
|
+
flate2 = "1" #
|
22
|
+
fontdb = "0.15.0" #
|
23
|
+
log = "0.4.20" #
|
24
|
+
magnus = { version = "0.7.1" }
|
25
|
+
pathdiff = "0.2"
|
26
|
+
same-file = "1" #
|
27
|
+
siphasher = "1.0" #
|
28
|
+
tar = "0.4" #
|
29
|
+
#typst = { git = "https://github.com/typst/typst.git", tag = "v0.13.0" }
|
30
|
+
#typst-library = { git = "https://github.com/typst/typst.git", tag = "v0.13.0" }
|
31
|
+
serde = { version = "1.0.217", features = ["derive"] }
|
32
|
+
serde_json = "1"
|
33
|
+
serde_yaml = "0.9"
|
34
|
+
typst = "0.13.0"
|
35
|
+
typst-library = "0.13.0"
|
36
|
+
typst-kit = { version = "0.13.0", features = [
|
37
|
+
"downloads",
|
38
|
+
"embed-fonts",
|
39
|
+
"vendor-openssl",
|
40
|
+
] }
|
41
|
+
typst-pdf = "0.13.0"
|
42
|
+
typst-svg = "0.13.0"
|
43
|
+
typst-html = "0.13.0"
|
44
|
+
typst-render = "0.13.0"
|
45
|
+
typst-eval = "0.13.0"
|
46
|
+
ureq = { version = "2", default-features = false, features = [
|
47
|
+
"gzip",
|
48
|
+
"socks-proxy",
|
49
|
+
] }
|
50
|
+
walkdir = "2.4.0"
|
51
|
+
|
52
|
+
# enable rb-sys feature to test against Ruby head. This is only needed if you
|
53
|
+
# want to work with the unreleased, in-development, next version of Ruby
|
54
|
+
rb-sys = { version = "*", default-features = false, features = ["stable-api-compiled-fallback"] }
|