Move assets

This commit is contained in:
Laurenz 2023-01-31 15:05:42 +01:00
parent 9a99beec94
commit ec05ed7e06
58 changed files with 75 additions and 71 deletions

20
NOTICE
View File

@ -65,19 +65,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================================================ ================================================================================
The SIL Open Font License Version 1.1 applies to: The SIL Open Font License Version 1.1 applies to:
* IBM Plex fonts in tests/fonts/IBMPlex*.ttf * IBM Plex fonts in assets/fonts/IBMPlex*.ttf
Copyright © 2017 IBM Corp. with Reserved Font Name "Plex" Copyright © 2017 IBM Corp. with Reserved Font Name "Plex"
(https://github.com/IBM/plex) (https://github.com/IBM/plex)
* Noto fonts in tests/fonts/Noto*.ttf * Noto fonts in assets/fonts/Noto*.ttf
Copyright 2018 The Noto Project Authors Copyright 2018 The Noto Project Authors
(https://github.com/googlei18n/noto-fonts) (https://github.com/googlei18n/noto-fonts)
* PT Sans fonts in tests/fonts/PTSans*.ttf * PT Sans fonts in assets/fonts/PTSans*.ttf
Copyright (c) 2010, ParaType Ltd. (http://www.paratype.com/public), Copyright (c) 2010, ParaType Ltd. (http://www.paratype.com/public),
with Reserved Font Names "PT Sans" and "ParaType". with Reserved Font Names "PT Sans" and "ParaType".
* Fira math fonts in tests/fonts/FiraMath*.otf * Fira math fonts in assets/fonts/FiraMath*.otf
Copyright (C) 2018--2021 by Xiangdong Zeng <xdzeng96@gmail.com> Copyright (C) 2018--2021 by Xiangdong Zeng <xdzeng96@gmail.com>
(https://github.com/firamath/firamath) (https://github.com/firamath/firamath)
@ -172,7 +172,7 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
================================================================================ ================================================================================
The Apache License Version 2.0 applies to: The Apache License Version 2.0 applies to:
* Roboto fonts in tests/fonts/Roboto*.ttf * Roboto fonts in assets/fonts/Roboto*.ttf
(https://github.com/googlefonts/roboto) (https://github.com/googlefonts/roboto)
Apache License Apache License
@ -356,7 +356,7 @@ The Apache License Version 2.0 applies to:
================================================================================ ================================================================================
The Ubuntu Font License Version 1.0 applies to: The Ubuntu Font License Version 1.0 applies to:
* Ubuntu fonts in tests/fonts/Ubuntu*.ttf * Ubuntu fonts in assets/fonts/Ubuntu*.ttf
(https://design.ubuntu.com/font/) (https://design.ubuntu.com/font/)
------------------------------- -------------------------------
@ -461,10 +461,10 @@ DEALINGS IN THE FONT SOFTWARE.
================================================================================ ================================================================================
The GUST Font License Version 1.0 applies to: The GUST Font License Version 1.0 applies to:
* Latin Modern fonts in tests/fonts/LatinModern*.otf * Latin Modern fonts in assets/fonts/LatinModern*.otf
(http://www.gust.org.pl/projects/e-foundry/lm-math) (http://www.gust.org.pl/projects/e-foundry/lm-math)
* NewComputerModern fonts in tests/fonts/NewCM*.otf * NewComputerModern fonts in assets/fonts/NewCM*.otf
% This is version 1.0, dated 22 June 2009, of the GUST Font License. % This is version 1.0, dated 22 June 2009, of the GUST Font License.
% (GUST is the Polish TeX Users Group, http://www.gust.org.pl) % (GUST is the Polish TeX Users Group, http://www.gust.org.pl)
@ -499,7 +499,7 @@ The GUST Font License Version 1.0 applies to:
================================================================================ ================================================================================
The Creative Commons Attribution 4.0 International License applies to: The Creative Commons Attribution 4.0 International License applies to:
* Twitter Color Emoji font in tests/fonts/TwitterColorEmoji.ttf * Twitter Color Emoji font in assets/fonts/TwitterColorEmoji.ttf
Copyright 2016 Brad Erickson Copyright 2016 Brad Erickson
Copyright 2016 Twitter, Inc. Copyright 2016 Twitter, Inc.
(https://github.com/eosrei/twemoji-color-font) (https://github.com/eosrei/twemoji-color-font)
@ -509,7 +509,7 @@ The Creative Commons Attribution 4.0 International License applies to:
Copyright 2020 Twitter, Inc and other contributors Copyright 2020 Twitter, Inc and other contributors
(https://github.com/twitter/twemoji) (https://github.com/twitter/twemoji)
* Monkey emoji in tests/res/monkey.svg * Monkey emoji in assets/files/monkey.svg
Copyright 2018 Vincent Le Moign, Streamline Emoji Project Copyright 2018 Vincent Le Moign, Streamline Emoji Project
Via Wikimedia Commons Via Wikimedia Commons
(https://commons.wikimedia.org/wiki/File:440-monkey.svg) (https://commons.wikimedia.org/wiki/File:440-monkey.svg)

View File

Before

Width:  |  Height:  |  Size: 118 B

After

Width:  |  Height:  |  Size: 118 B

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 983 B

After

Width:  |  Height:  |  Size: 983 B

View File

Before

Width:  |  Height:  |  Size: 227 KiB

After

Width:  |  Height:  |  Size: 227 KiB

View File

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 114 KiB

View File

@ -75,7 +75,11 @@ pub fn compile(world: &(dyn World + 'static), source: &Source) -> SourceResult<D
#[comemo::track] #[comemo::track]
pub trait World { pub trait World {
/// The path relative to which absolute paths are. /// The path relative to which absolute paths are.
fn root(&self) -> &Path; ///
/// Defaults to the empty path.
fn root(&self) -> &Path {
Path::new("")
}
/// The standard library. /// The standard library.
fn library(&self) -> &Prehashed<Library>; fn library(&self) -> &Prehashed<Library>;

View File

@ -10,8 +10,6 @@ Top level directory structure:
a test passed or failed. a test passed or failed.
- `png`: PNG files produced by tests. - `png`: PNG files produced by tests.
- `pdf`: PDF files produced by tests. - `pdf`: PDF files produced by tests.
- `res`: Resource files used by tests.
- `fonts`: Font files used for tests.
## Running the tests ## Running the tests
Running all tests (including unit tests): Running all tests (including unit tests):

View File

@ -11,7 +11,7 @@ use typst::World;
use unscanny::Scanner; use unscanny::Scanner;
const TEXT: &str = include_str!("../typ/compiler/bench.typ"); const TEXT: &str = include_str!("../typ/compiler/bench.typ");
const FONT: &[u8] = include_bytes!("../fonts/IBMPlexSans-Regular.ttf"); const FONT: &[u8] = include_bytes!("../../assets/fonts/IBMPlexSans-Regular.ttf");
main!( main!(
bench_decode, bench_decode,
@ -124,10 +124,6 @@ impl BenchWorld {
} }
impl World for BenchWorld { impl World for BenchWorld {
fn root(&self) -> &Path {
Path::new("")
}
fn library(&self) -> &Prehashed<Library> { fn library(&self) -> &Prehashed<Library> {
&self.library &self.library
} }

View File

@ -28,7 +28,8 @@ const TYP_DIR: &str = "typ";
const REF_DIR: &str = "ref"; const REF_DIR: &str = "ref";
const PNG_DIR: &str = "png"; const PNG_DIR: &str = "png";
const PDF_DIR: &str = "pdf"; const PDF_DIR: &str = "pdf";
const FONT_DIR: &str = "fonts"; const FONT_DIR: &str = "../assets/fonts";
const FILE_DIR: &str = "../assets/files";
fn main() { fn main() {
let args = Args::new(env::args().skip(1)); let args = Args::new(env::args().skip(1));
@ -240,7 +241,7 @@ impl TestWorld {
impl World for TestWorld { impl World for TestWorld {
fn root(&self) -> &Path { fn root(&self) -> &Path {
Path::new("") Path::new(FILE_DIR)
} }
fn library(&self) -> &Prehashed<Library> { fn library(&self) -> &Prehashed<Library> {
@ -306,10 +307,15 @@ impl TestWorld {
} }
} }
/// Read a file. /// Read as file.
fn read(path: &Path) -> FileResult<Vec<u8>> { fn read(path: &Path) -> FileResult<Vec<u8>> {
let f = |e| FileError::from_io(e, path); let suffix = path
let mut file = File::open(path).map_err(f)?; .strip_prefix(FILE_DIR)
.map(|suffix| Path::new("/").join(suffix))
.unwrap_or_else(|_| path.into());
let f = |e| FileError::from_io(e, &suffix);
let mut file = File::open(&path).map_err(f)?;
if file.metadata().map_err(f)?.is_file() { if file.metadata().map_err(f)?.is_file() {
let mut data = vec![]; let mut data = vec![];
file.read_to_end(&mut data).map_err(f)?; file.read_to_end(&mut data).map_err(f)?;

View File

@ -21,4 +21,4 @@ Die Tiefe eines Knotens _v_ ist die Länge des eindeutigen Weges von der Wurzel
zu _v_, und die Höhe von _v_ ist die Länge eines längsten (absteigenden) Weges zu _v_, und die Höhe von _v_ ist die Länge eines längsten (absteigenden) Weges
von _v_ zu einem Blatt. Die Höhe des Baumes ist die Höhe der Wurzel. von _v_ zu einem Blatt. Die Höhe des Baumes ist die Höhe der Wurzel.
#align(center, image("../res/graph.png", width: 75%)) #align(center, image("/graph.png", width: 75%))

View File

@ -69,8 +69,8 @@
--- ---
// Some non-text stuff. // Some non-text stuff.
// Error: 9-30 file is not valid utf-8 // Error: 9-21 file is not valid utf-8
#import "../../res/rhino.png" #import "/rhino.png"
--- ---
// Unresolved import. // Unresolved import.

View File

@ -6,7 +6,7 @@
= Document = Document
// Include a file // Include a file
#include "/typ/compiler/modules/chap1.typ" #include "modules/chap1.typ"
// Expression as a file name. // Expression as a file name.
#let chap2 = include "modu" + "les/chap" + "2.typ" #let chap2 = include "modu" + "les/chap" + "2.typ"

View File

@ -40,7 +40,7 @@ Hello *#x*
// Test relative path resolving in layout phase. // Test relative path resolving in layout phase.
#let choice = ("monkey.svg", "rhino.png", "tiger.jpg") #let choice = ("monkey.svg", "rhino.png", "tiger.jpg")
#set enum(numbering: n => { #set enum(numbering: n => {
let path = "../../res/" + choice.at(n - 1) let path = "/" + choice.at(n - 1)
move(dy: -0.15em, image(path, width: 1em, height: 1em)) move(dy: -0.15em, image(path, width: 1em, height: 1em))
}) })

View File

@ -54,6 +54,6 @@ World
--- ---
// Test absolute path in layout phase. // Test absolute path in layout phase.
#show "GRAPH": image("/res/graph.png") #show "GRAPH": image("/graph.png")
The GRAPH has nodes. The GRAPH has nodes.

View File

@ -3,22 +3,22 @@
--- ---
// Test reading plain text files // Test reading plain text files
#let data = read("../../res/hello.txt") #let data = read("/hello.txt")
#test(data, "Hello, world!") #test(data, "Hello, world!")
--- ---
// Error: 18-41 file not found (searched at res/missing.txt) // Error: 18-32 file not found (searched at /missing.txt)
#let data = read("../../res/missing.txt") #let data = read("/missing.txt")
--- ---
// Error: 18-46 file is not valid utf-8 // Error: 18-37 file is not valid utf-8
#let data = read("../../res/invalid-utf8.txt") #let data = read("/invalid-utf8.txt")
--- ---
// Test reading CSV data. // Test reading CSV data.
// Ref: true // Ref: true
#set page(width: auto) #set page(width: auto)
#let data = csv("/res/zoo.csv") #let data = csv("/zoo.csv")
#let cells = data.at(0).map(strong) + data.slice(1).flatten() #let cells = data.at(0).map(strong) + data.slice(1).flatten()
#table(columns: data.at(0).len(), ..cells) #table(columns: data.at(0).len(), ..cells)
@ -27,23 +27,23 @@
#csv("nope.csv") #csv("nope.csv")
--- ---
// Error: 6-20 failed to parse csv file: found 3 instead of 2 fields in line 3 // Error: 6-16 failed to parse csv file: found 3 instead of 2 fields in line 3
#csv("/res/bad.csv") #csv("/bad.csv")
--- ---
// Test reading JSON data. // Test reading JSON data.
#let data = json("/res/zoo.json") #let data = json("/zoo.json")
#test(data.len(), 3) #test(data.len(), 3)
#test(data.at(0).name, "Debby") #test(data.at(0).name, "Debby")
#test(data.at(2).weight, 150) #test(data.at(2).weight, 150)
--- ---
// Error: 7-22 failed to parse json file: syntax error in line 3 // Error: 7-18 failed to parse json file: syntax error in line 3
#json("/res/bad.json") #json("/bad.json")
--- ---
// Test reading XML data. // Test reading XML data.
#let data = xml("/res/data.xml") #let data = xml("/data.xml")
#test(data, (( #test(data, ((
tag: "data", tag: "data",
attrs: (:), attrs: (:),
@ -67,5 +67,5 @@
),)) ),))
--- ---
// Error: 6-20 failed to parse xml file: found closing tag 'data' instead of 'hello' in line 3 // Error: 6-16 failed to parse xml file: found closing tag 'data' instead of 'hello' in line 3
#xml("/res/bad.xml") #xml("/bad.xml")

View File

@ -51,15 +51,15 @@ Blue #move(dy: -0.15em)[🌊]
#eval("#include \"../coma.typ\"") #eval("#include \"../coma.typ\"")
--- ---
// Error: 7-35 cannot access file system from here // Error: 7-31 cannot access file system from here
#eval("#image(\"/res/tiger.jpg\")") #eval("#image(\"/tiger.jpg\")")
--- ---
// Error: 23-30 cannot access file system from here // Error: 23-30 cannot access file system from here
#show raw: it => eval(it.text) #show raw: it => eval(it.text)
``` ```
#image("/res/tiger.jpg") #image("/tiger.jpg")
``` ```
--- ---
@ -67,7 +67,7 @@ Blue #move(dy: -0.15em)[🌊]
#show raw: it => eval(it.text) #show raw: it => eval(it.text)
``` ```
#show emph: _ => image("../../res/giraffe.jpg") #show emph: _ => image("/giraffe.jpg")
_No relative giraffe!_ _No relative giraffe!_
``` ```

View File

@ -23,7 +23,7 @@
columns: 4 * (1fr,), columns: 4 * (1fr,),
row-gutter: 10pt, row-gutter: 10pt,
column-gutter: (0pt, 10%), column-gutter: (0pt, 10%),
align(top, image("/res/rhino.png")), align(top, image("/rhino.png")),
align(top, rect(inset: 0pt, fill: eastern, align(right)[LoL])), align(top, rect(inset: 0pt, fill: eastern, align(right)[LoL])),
[rofl], [rofl],
[\ A] * 3, [\ A] * 3,

View File

@ -22,7 +22,7 @@ Hi #box(pad(left: 10pt)[A]) there
// Test that the pad node doesn't consume the whole region. // Test that the pad node doesn't consume the whole region.
#set page(height: 6cm) #set page(height: 6cm)
#align(left)[Before] #align(left)[Before]
#pad(10pt, image("/res/tiger.jpg")) #pad(10pt, image("/tiger.jpg"))
#align(right)[After] #align(right)[After]
--- ---

View File

@ -43,7 +43,7 @@ Lריווח #h(1cm) R
--- ---
// Test inline object. // Test inline object.
#set text(lang: "he", "IBM Plex Serif") #set text(lang: "he", "IBM Plex Serif")
קרנפיםRh#image("/res/rhino.png", height: 11pt)inoחיים קרנפיםRh#image("/rhino.png", height: 11pt)inoחיים
--- ---
// Test whether L1 whitespace resetting destroys stuff. // Test whether L1 whitespace resetting destroys stuff.

View File

@ -9,10 +9,10 @@ The first paragraph has no indent.
But the second one does. But the second one does.
#image("/res/tiger.jpg", height: 6pt) #image("/tiger.jpg", height: 6pt)
starts a paragraph without indent. starts a paragraph without indent.
#align(center, image("/res/rhino.png", width: 1cm)) #align(center, image("/rhino.png", width: 1cm))
= Headings = Headings
- And lists. - And lists.

View File

@ -7,7 +7,7 @@
dx: -10pt, dx: -10pt,
dy: -10pt, dy: -10pt,
image( image(
"/res/tiger.jpg", "/tiger.jpg",
fit: "cover", fit: "cover",
width: 100% + 20pt, width: 100% + 20pt,
height: 100% + 20pt, height: 100% + 20pt,

View File

@ -5,7 +5,7 @@
#place(bottom + center)[© Typst] #place(bottom + center)[© Typst]
= Placement = Placement
#place(right, image("/res/tiger.jpg", width: 1.8cm)) #place(right, image("/tiger.jpg", width: 1.8cm))
Hi there. This is \ Hi there. This is \
a placed node. \ a placed node. \
Unfortunately, \ Unfortunately, \

View File

@ -31,13 +31,13 @@ nor #xetex!
// Test combination of scaling and rotation. // Test combination of scaling and rotation.
#set page(height: 80pt) #set page(height: 80pt)
#align(center + horizon, #align(center + horizon,
rotate(20deg, scale(70%, image("/res/tiger.jpg"))) rotate(20deg, scale(70%, image("/tiger.jpg")))
) )
--- ---
// Test setting rotation origin. // Test setting rotation origin.
#rotate(10deg, origin: top + left, #rotate(10deg, origin: top + left,
image("/res/tiger.jpg", width: 50%) image("/tiger.jpg", width: 50%)
) )
--- ---

View File

@ -38,7 +38,7 @@ My cool #move(dx: 0.7cm, dy: 0.7cm, rotate(10deg, scale(200%, mylink)))
// Link containing a block. // Link containing a block.
#link("https://example.com/", block[ #link("https://example.com/", block[
My cool rhino My cool rhino
#move(dx: 10pt, image("/res/rhino.png", width: 1cm)) #move(dx: 10pt, image("/rhino.png", width: 1cm))
]) ])
--- ---

View File

@ -4,24 +4,24 @@
// Test loading different image formats. // Test loading different image formats.
// Load an RGBA PNG image. // Load an RGBA PNG image.
#image("/res/rhino.png") #image("/rhino.png")
// Load an RGB JPEG image. // Load an RGB JPEG image.
#set page(height: 60pt) #set page(height: 60pt)
#image("../../res/tiger.jpg") #image("/tiger.jpg")
--- ---
// Test configuring the size and fitting behaviour of images. // Test configuring the size and fitting behaviour of images.
// Set width and height explicitly. // Set width and height explicitly.
#image("/res/rhino.png", width: 30pt) #image("/rhino.png", width: 30pt)
#image("/res/rhino.png", height: 30pt) #image("/rhino.png", height: 30pt)
// Set width and height explicitly and force stretching. // Set width and height explicitly and force stretching.
#image("/res/monkey.svg", width: 100%, height: 20pt, fit: "stretch") #image("/monkey.svg", width: 100%, height: 20pt, fit: "stretch")
// Make sure the bounding-box of the image is correct. // Make sure the bounding-box of the image is correct.
#align(bottom + right, image("/res/tiger.jpg", width: 40pt)) #align(bottom + right, image("/tiger.jpg", width: 40pt))
--- ---
// Test all three fit modes. // Test all three fit modes.
@ -30,9 +30,9 @@
columns: (1fr, 1fr, 1fr), columns: (1fr, 1fr, 1fr),
rows: 100%, rows: 100%,
gutter: 3pt, gutter: 3pt,
image("/res/tiger.jpg", width: 100%, height: 100%, fit: "contain"), image("/tiger.jpg", width: 100%, height: 100%, fit: "contain"),
image("/res/tiger.jpg", width: 100%, height: 100%, fit: "cover"), image("/tiger.jpg", width: 100%, height: 100%, fit: "cover"),
image("/res/monkey.svg", width: 100%, height: 100%, fit: "stretch"), image("/monkey.svg", width: 100%, height: 100%, fit: "stretch"),
) )
--- ---
@ -40,15 +40,15 @@
#set page(height: 60pt) #set page(height: 60pt)
Stuff #parbreak() Stuff #parbreak()
Stuff Stuff
#image("/res/rhino.png") #image("/rhino.png")
--- ---
// Test baseline. // Test baseline.
A #image("/res/tiger.jpg", height: 1cm, width: 80%) B A #image("/tiger.jpg", height: 1cm, width: 80%) B
--- ---
// Test advanced SVG features. // Test advanced SVG features.
#image("/res/pattern.svg") #image("/pattern.svg")
--- ---
// Error: 8-29 file not found (searched at typ/visualize/path/does/not/exist) // Error: 8-29 file not found (searched at typ/visualize/path/does/not/exist)
@ -59,5 +59,5 @@ A #image("/res/tiger.jpg", height: 1cm, width: 80%) B
#image("./image.typ") #image("./image.typ")
--- ---
// Error: 8-22 failed to parse svg: found closing tag 'g' instead of 'style' in line 4 // Error: 8-18 failed to parse svg: found closing tag 'g' instead of 'style' in line 4
#image("/res/bad.svg") #image("/bad.svg")