mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Compare commits
1 Commits
main
...
v0.13.0-rc
Author | SHA1 | Date | |
---|---|---|---|
|
56d8188c61 |
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
@ -5,7 +5,6 @@ env:
|
||||
RUSTFLAGS: "-Dwarnings"
|
||||
RUSTDOCFLAGS: "-Dwarnings"
|
||||
TYPST_TESTS_EXTENDED: true
|
||||
PKG_CONFIG_i686-unknown-linux-gnu: /usr/bin/i686-linux-gnu-pkgconf
|
||||
|
||||
jobs:
|
||||
# This allows us to have one branch protection rule for the full test matrix.
|
||||
@ -28,43 +27,30 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
bits: [64]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
bits: 32
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- if: startsWith(matrix.os, 'ubuntu-') && matrix.bits == 32
|
||||
run: |
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo apt update
|
||||
sudo apt install -y gcc-multilib libssl-dev:i386 pkg-config:i386
|
||||
- uses: dtolnay/rust-toolchain@1.85.0
|
||||
with:
|
||||
targets: ${{ matrix.bits == 32 && 'i686-unknown-linux-gnu' || '' }}
|
||||
- uses: dtolnay/rust-toolchain@1.83.0
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
key: ${{ matrix.bits }}
|
||||
- run: cargo test --workspace --no-run ${{ matrix.bits == 32 && '--target i686-unknown-linux-gnu' || '' }}
|
||||
- run: cargo test --workspace --no-fail-fast ${{ matrix.bits == 32 && '--target i686-unknown-linux-gnu' || '' }}
|
||||
- run: cargo test --workspace --no-run
|
||||
- run: cargo test --workspace --no-fail-fast
|
||||
- name: Upload rendered test output
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: tests-rendered-${{ matrix.os }}-${{ matrix.bits }}
|
||||
name: tests-rendered-${{ matrix.os }}
|
||||
path: tests/store/render/**
|
||||
retention-days: 3
|
||||
- name: Update test artifacts
|
||||
if: failure()
|
||||
run: |
|
||||
cargo test --workspace --test tests ${{ matrix.bits == 32 && '--target i686-unknown-linux-gnu' || '' }} -- --update
|
||||
cargo test --workspace --test tests -- --update
|
||||
echo 'updated_artifacts=1' >> "$GITHUB_ENV"
|
||||
- name: Upload updated reference output (for use if the test changes are desired)
|
||||
if: failure() && env.updated_artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: tests-updated-${{ matrix.os }}-${{ matrix.bits }}
|
||||
name: tests-updated-${{ matrix.os }}
|
||||
path: tests/ref/**
|
||||
retention-days: 3
|
||||
|
||||
@ -73,7 +59,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@1.85.0
|
||||
- uses: dtolnay/rust-toolchain@1.83.0
|
||||
with:
|
||||
components: clippy, rustfmt
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
@ -87,7 +73,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@1.83.0
|
||||
- uses: dtolnay/rust-toolchain@1.80.0
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo check --workspace
|
||||
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -44,7 +44,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@1.85.0
|
||||
- uses: dtolnay/rust-toolchain@1.83.0
|
||||
with:
|
||||
target: ${{ matrix.target }}
|
||||
|
||||
|
323
Cargo.lock
generated
323
Cargo.lock
generated
@ -1,6 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler2"
|
||||
@ -217,20 +217,6 @@ name = "bytemuck"
|
||||
version = "1.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3"
|
||||
dependencies = [
|
||||
"bytemuck_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck_derive"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fa76293b4f7bb636ab88fd78228235b5248b4d05cc589aed610f954af5d7c7a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
@ -749,12 +735,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.0"
|
||||
version = "1.0.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc"
|
||||
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"libz-rs-sys",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
@ -764,15 +749,6 @@ version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
|
||||
[[package]]
|
||||
name = "float-cmp"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b09cf3155332e944990140d967ff5eceb70df778b34f77d8075db46e4704e6d8"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
@ -785,15 +761,6 @@ version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
|
||||
|
||||
[[package]]
|
||||
name = "font-types"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fa6a5e5a77b5f3f7f9e32879f484aa5b3632ddfbe568a16266c904a6f32cdaf"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fontconfig-parser"
|
||||
version = "0.5.7"
|
||||
@ -805,9 +772,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fontdb"
|
||||
version = "0.23.0"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "457e789b3d1202543297a350643cf459f836cade38934e7a4cf6a39e7cde2905"
|
||||
checksum = "37be9fc20d966be438cd57a45767f73349477fb0f85ce86e000557f787298afb"
|
||||
dependencies = [
|
||||
"fontconfig-parser",
|
||||
"log",
|
||||
@ -862,15 +829,6 @@ version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||
|
||||
[[package]]
|
||||
name = "fxhash"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getopts"
|
||||
version = "0.2.21"
|
||||
@ -913,12 +871,6 @@ dependencies = [
|
||||
"weezl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glidesort"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2e102e6eb644d3e0b186fc161e4460417880a0a0b87d235f2e5b8fb30f2e9e0"
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.4.1"
|
||||
@ -1014,7 +966,7 @@ checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526"
|
||||
dependencies = [
|
||||
"displaydoc",
|
||||
"serde",
|
||||
"yoke 0.7.5",
|
||||
"yoke",
|
||||
"zerofrom",
|
||||
"zerovec",
|
||||
]
|
||||
@ -1112,7 +1064,7 @@ dependencies = [
|
||||
"stable_deref_trait",
|
||||
"tinystr",
|
||||
"writeable",
|
||||
"yoke 0.7.5",
|
||||
"yoke",
|
||||
"zerofrom",
|
||||
"zerovec",
|
||||
]
|
||||
@ -1223,9 +1175,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "image-webp"
|
||||
version = "0.2.1"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b77d01e822461baa8409e156015a1d91735549f0f2c17691bd2d996bef238f7f"
|
||||
checksum = "f79afb8cbee2ef20f59ccd477a218c12a93943d075b492015ecb1bb81f8ee904"
|
||||
dependencies = [
|
||||
"byteorder-lite",
|
||||
"quick-error",
|
||||
@ -1259,12 +1211,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "infer"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a588916bfdfd92e71cacef98a63d9b1f0d74d6599980d11894290e7ddefffcf7"
|
||||
|
||||
[[package]]
|
||||
name = "inotify"
|
||||
version = "0.11.0"
|
||||
@ -1364,50 +1310,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "krilla"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69ee6128ebf52d7ce684613b6431ead2959f2be9ff8cf776eeaaad0427c953e9"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bumpalo",
|
||||
"comemo",
|
||||
"flate2",
|
||||
"float-cmp 0.10.0",
|
||||
"fxhash",
|
||||
"gif",
|
||||
"image-webp",
|
||||
"imagesize",
|
||||
"once_cell",
|
||||
"pdf-writer",
|
||||
"png",
|
||||
"rayon",
|
||||
"rustybuzz",
|
||||
"siphasher",
|
||||
"skrifa",
|
||||
"subsetter",
|
||||
"tiny-skia-path",
|
||||
"xmp-writer",
|
||||
"yoke 0.8.0",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "krilla-svg"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3462989578155cf620ef8035f8921533cc95c28e2a0c75de172f7219e6aba84e"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"fontdb",
|
||||
"krilla",
|
||||
"png",
|
||||
"resvg",
|
||||
"tiny-skia",
|
||||
"usvg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kurbo"
|
||||
version = "0.11.1"
|
||||
@ -1469,15 +1371,6 @@ dependencies = [
|
||||
"redox_syscall",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-rs-sys"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "902bc563b5d65ad9bba616b490842ef0651066a1a1dc3ce1087113ffcb873c8d"
|
||||
dependencies = [
|
||||
"zlib-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
@ -1565,9 +1458,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.5"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5"
|
||||
checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
@ -1708,9 +1601,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.72"
|
||||
version = "0.10.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da"
|
||||
checksum = "61cfb4e166a8bb8c9b55c500bc2308550148ece889be90f609377e58140f42c6"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"cfg-if",
|
||||
@ -1749,9 +1642,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.107"
|
||||
version = "0.9.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8288979acd84749c744a9014b4382d42b8f7b2592847b5afb2ed29e5d16ede07"
|
||||
checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@ -1845,9 +1738,9 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||
|
||||
[[package]]
|
||||
name = "pdf-writer"
|
||||
version = "0.13.0"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ea27c5015ab81753fc61e49f8cde74999346605ee148bb20008ef3d3150e0dc"
|
||||
checksum = "5df03c7d216de06f93f398ef06f1385a60f2c597bb96f8195c8d98e08a26b1d5"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"itoa",
|
||||
@ -1911,9 +1804,9 @@ checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315"
|
||||
|
||||
[[package]]
|
||||
name = "pixglyph"
|
||||
version = "0.6.0"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c1106193bc18a4b840eb075ff6664c8a0b0270f0531bb12a7e9c803e53b55c5"
|
||||
checksum = "d15afa937836bf3d876f5a04ce28810c06045857bf46c3d0d31073b8aada5494"
|
||||
dependencies = [
|
||||
"ttf-parser",
|
||||
]
|
||||
@ -2104,16 +1997,6 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "read-fonts"
|
||||
version = "0.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "600e807b48ac55bad68a8cb75cc3c7739f139b9248f7e003e01e080f589b5288"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"font-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.8"
|
||||
@ -2165,9 +2048,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "resvg"
|
||||
version = "0.45.0"
|
||||
version = "0.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd43d1c474e9dadf09a8fdf22d713ba668b499b5117b9b9079500224e26b5b29"
|
||||
checksum = "c7314563c59c7ce31c18e23ad3dd092c37b928a0fa4e1c0a1a6504351ab411d1"
|
||||
dependencies = [
|
||||
"gif",
|
||||
"image-webp",
|
||||
@ -2238,9 +2121,9 @@ checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
|
||||
|
||||
[[package]]
|
||||
name = "rustybuzz"
|
||||
version = "0.20.1"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd3c7c96f8a08ee34eff8857b11b49b07d71d1c3f4e88f8a88d4c9e9f90b1702"
|
||||
checksum = "c85d1ccd519e61834798eb52c4e886e8c2d7d698dd3d6ce0b1b47eb8557f1181"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"bytemuck",
|
||||
@ -2432,16 +2315,6 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
|
||||
|
||||
[[package]]
|
||||
name = "skrifa"
|
||||
version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fa1e5622e4f7b98877e8a19890efddcac1230cec6198bd9de91ec0e00010dc8"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"read-fonts",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slotmap"
|
||||
version = "1.0.7"
|
||||
@ -2488,7 +2361,7 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
|
||||
dependencies = [
|
||||
"float-cmp 0.9.0",
|
||||
"float-cmp",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2531,11 +2404,28 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "subsetter"
|
||||
version = "0.2.1"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35539e8de3dcce8dd0c01f3575f85db1e5ac1aea1b996d2d09d89f148bc91497"
|
||||
checksum = "74f98178f34057d4d4de93d68104007c6dea4dfac930204a69ab4622daefa648"
|
||||
|
||||
[[package]]
|
||||
name = "svg2pdf"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5014c9dadcf318fb7ef8c16438e95abcc9de1ae24d60d5bccc64c55100c50364"
|
||||
dependencies = [
|
||||
"fxhash",
|
||||
"fontdb",
|
||||
"image",
|
||||
"log",
|
||||
"miniz_oxide",
|
||||
"once_cell",
|
||||
"pdf-writer",
|
||||
"resvg",
|
||||
"siphasher",
|
||||
"subsetter",
|
||||
"tiny-skia",
|
||||
"ttf-parser",
|
||||
"usvg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2819,9 +2709,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
version = "0.25.1"
|
||||
version = "0.24.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
||||
checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a"
|
||||
dependencies = [
|
||||
"core_maths",
|
||||
]
|
||||
@ -2845,7 +2735,7 @@ checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a"
|
||||
|
||||
[[package]]
|
||||
name = "typst"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"comemo",
|
||||
"ecow",
|
||||
@ -2862,12 +2752,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-assets"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/typst/typst-assets?rev=ab1295f#ab1295ff896444e51902e03c2669955e1d73604a"
|
||||
version = "0.13.0-rc1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e364df2dd61caf35f959a879e55654922a8cea77d4886103ed735c45c888445"
|
||||
|
||||
[[package]]
|
||||
name = "typst-cli"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
@ -2912,12 +2803,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-dev-assets"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/typst/typst-dev-assets?rev=fddbf8b#fddbf8b99506bc370ac0edcd4959add603a7fc92"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/typst/typst-dev-assets?rev=7f8999d#7f8999d19907cd6e1148b295efbc844921c0761c"
|
||||
|
||||
[[package]]
|
||||
name = "typst-docs"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"ecow",
|
||||
@ -2940,7 +2831,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-eval"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"comemo",
|
||||
"ecow",
|
||||
@ -2958,7 +2849,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-fuzz"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"comemo",
|
||||
"libfuzzer-sys",
|
||||
@ -2970,7 +2861,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-html"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"comemo",
|
||||
"ecow",
|
||||
@ -2984,7 +2875,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-ide"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"comemo",
|
||||
"ecow",
|
||||
@ -3001,19 +2892,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-kit"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"ecow",
|
||||
"env_proxy",
|
||||
"fastrand",
|
||||
"flate2",
|
||||
"fontdb",
|
||||
"native-tls",
|
||||
"once_cell",
|
||||
"openssl",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tar",
|
||||
"typst-assets",
|
||||
"typst-library",
|
||||
@ -3025,7 +2913,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-layout"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"az",
|
||||
"bumpalo",
|
||||
@ -3055,7 +2943,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-library"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"az",
|
||||
"bitflags 2.8.0",
|
||||
@ -3068,7 +2956,6 @@ dependencies = [
|
||||
"ecow",
|
||||
"flate2",
|
||||
"fontdb",
|
||||
"glidesort",
|
||||
"hayagriva",
|
||||
"icu_properties",
|
||||
"icu_provider",
|
||||
@ -3078,7 +2965,6 @@ dependencies = [
|
||||
"kamadak-exif",
|
||||
"kurbo",
|
||||
"lipsum",
|
||||
"memchr",
|
||||
"palette",
|
||||
"phf",
|
||||
"png",
|
||||
@ -3107,7 +2993,6 @@ dependencies = [
|
||||
"typst-timing",
|
||||
"typst-utils",
|
||||
"unicode-math-class",
|
||||
"unicode-normalization",
|
||||
"unicode-segmentation",
|
||||
"unscanny",
|
||||
"usvg",
|
||||
@ -3117,7 +3002,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-macros"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@ -3127,27 +3012,33 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-pdf"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"base64",
|
||||
"bytemuck",
|
||||
"comemo",
|
||||
"ecow",
|
||||
"image",
|
||||
"infer",
|
||||
"krilla",
|
||||
"krilla-svg",
|
||||
"indexmap 2.7.1",
|
||||
"miniz_oxide",
|
||||
"pdf-writer",
|
||||
"serde",
|
||||
"subsetter",
|
||||
"svg2pdf",
|
||||
"ttf-parser",
|
||||
"typst-assets",
|
||||
"typst-library",
|
||||
"typst-macros",
|
||||
"typst-syntax",
|
||||
"typst-timing",
|
||||
"typst-utils",
|
||||
"xmp-writer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typst-realize"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bumpalo",
|
||||
@ -3163,7 +3054,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-render"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"comemo",
|
||||
@ -3179,7 +3070,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-svg"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"comemo",
|
||||
@ -3197,7 +3088,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-syntax"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"ecow",
|
||||
"serde",
|
||||
@ -3213,7 +3104,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-tests"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"comemo",
|
||||
@ -3238,7 +3129,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-timing"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"parking_lot",
|
||||
"serde",
|
||||
@ -3248,7 +3139,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "typst-utils"
|
||||
version = "0.13.1"
|
||||
version = "0.13.0-rc1"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"portable-atomic",
|
||||
@ -3291,15 +3182,15 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi-mirroring"
|
||||
version = "0.4.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dfa6e8c60bb66d49db113e0125ee8711b7647b5579dc7f5f19c42357ed039fe"
|
||||
checksum = "64af057ad7466495ca113126be61838d8af947f41d93a949980b2389a118082f"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ccc"
|
||||
version = "0.4.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce61d488bcdc9bc8b5d1772c404828b17fc481c0a582b5581e95fb233aef503e"
|
||||
checksum = "260bc6647b3893a9a90668360803a15f96b85a5257b1c3a0c3daf6ae2496de42"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
@ -3394,9 +3285,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "usvg"
|
||||
version = "0.45.0"
|
||||
version = "0.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ac8e0e3e4696253dc06167990b3fe9a2668ab66270adf949a464db4088cb354"
|
||||
checksum = "6803057b5cbb426e9fb8ce2216f3a9b4ca1dd2c705ba3cbebc13006e437735fd"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"data-url",
|
||||
@ -3766,9 +3657,9 @@ checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
|
||||
|
||||
[[package]]
|
||||
name = "xmp-writer"
|
||||
version = "0.3.2"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce9e2f4a404d9ebffc0a9832cf4f50907220ba3d7fffa9099261a5cab52f2dd7"
|
||||
checksum = "7eb5954c9ca6dcc869e98d3e42760ed9dab08f3e70212b31d7ab8ae7f3b7a487"
|
||||
|
||||
[[package]]
|
||||
name = "xz2"
|
||||
@ -3806,19 +3697,7 @@ checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"stable_deref_trait",
|
||||
"yoke-derive 0.7.5",
|
||||
"zerofrom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yoke"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"stable_deref_trait",
|
||||
"yoke-derive 0.8.0",
|
||||
"yoke-derive",
|
||||
"zerofrom",
|
||||
]
|
||||
|
||||
@ -3834,18 +3713,6 @@ dependencies = [
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yoke-derive"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.35"
|
||||
@ -3907,7 +3774,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"yoke 0.7.5",
|
||||
"yoke",
|
||||
"zerofrom",
|
||||
"zerovec-derive",
|
||||
]
|
||||
@ -3925,25 +3792,21 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "2.5.0"
|
||||
version = "2.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27c03817464f64e23f6f37574b4fdc8cf65925b5bfd2b0f2aedf959791941f88"
|
||||
checksum = "ae9c1ea7b3a5e1f4b922ff856a129881167511563dc219869afe3787fc0c1a45"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"crc32fast",
|
||||
"crossbeam-utils",
|
||||
"displaydoc",
|
||||
"flate2",
|
||||
"indexmap 2.7.1",
|
||||
"memchr",
|
||||
"thiserror 2.0.11",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zlib-rs"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b20717f0917c908dc63de2e44e97f1e6b126ca58d0e391cee86d504eb8fbd05"
|
||||
|
||||
[[package]]
|
||||
name = "zopfli"
|
||||
version = "0.8.1"
|
||||
|
68
Cargo.toml
68
Cargo.toml
@ -4,8 +4,8 @@ default-members = ["crates/typst-cli"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.13.1"
|
||||
rust-version = "1.83" # also change in ci.yml
|
||||
version = "0.13.0-rc1"
|
||||
rust-version = "1.80" # also change in ci.yml
|
||||
authors = ["The Typst Project Developers"]
|
||||
edition = "2021"
|
||||
homepage = "https://typst.app"
|
||||
@ -16,24 +16,24 @@ keywords = ["typst"]
|
||||
readme = "README.md"
|
||||
|
||||
[workspace.dependencies]
|
||||
typst = { path = "crates/typst", version = "0.13.1" }
|
||||
typst-cli = { path = "crates/typst-cli", version = "0.13.1" }
|
||||
typst-eval = { path = "crates/typst-eval", version = "0.13.1" }
|
||||
typst-html = { path = "crates/typst-html", version = "0.13.1" }
|
||||
typst-ide = { path = "crates/typst-ide", version = "0.13.1" }
|
||||
typst-kit = { path = "crates/typst-kit", version = "0.13.1" }
|
||||
typst-layout = { path = "crates/typst-layout", version = "0.13.1" }
|
||||
typst-library = { path = "crates/typst-library", version = "0.13.1" }
|
||||
typst-macros = { path = "crates/typst-macros", version = "0.13.1" }
|
||||
typst-pdf = { path = "crates/typst-pdf", version = "0.13.1" }
|
||||
typst-realize = { path = "crates/typst-realize", version = "0.13.1" }
|
||||
typst-render = { path = "crates/typst-render", version = "0.13.1" }
|
||||
typst-svg = { path = "crates/typst-svg", version = "0.13.1" }
|
||||
typst-syntax = { path = "crates/typst-syntax", version = "0.13.1" }
|
||||
typst-timing = { path = "crates/typst-timing", version = "0.13.1" }
|
||||
typst-utils = { path = "crates/typst-utils", version = "0.13.1" }
|
||||
typst-assets = { git = "https://github.com/typst/typst-assets", rev = "ab1295f" }
|
||||
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "fddbf8b" }
|
||||
typst = { path = "crates/typst", version = "0.13.0-rc1" }
|
||||
typst-cli = { path = "crates/typst-cli", version = "0.13.0-rc1" }
|
||||
typst-eval = { path = "crates/typst-eval", version = "0.13.0-rc1" }
|
||||
typst-html = { path = "crates/typst-html", version = "0.13.0-rc1" }
|
||||
typst-ide = { path = "crates/typst-ide", version = "0.13.0-rc1" }
|
||||
typst-kit = { path = "crates/typst-kit", version = "0.13.0-rc1" }
|
||||
typst-layout = { path = "crates/typst-layout", version = "0.13.0-rc1" }
|
||||
typst-library = { path = "crates/typst-library", version = "0.13.0-rc1" }
|
||||
typst-macros = { path = "crates/typst-macros", version = "0.13.0-rc1" }
|
||||
typst-pdf = { path = "crates/typst-pdf", version = "0.13.0-rc1" }
|
||||
typst-realize = { path = "crates/typst-realize", version = "0.13.0-rc1" }
|
||||
typst-render = { path = "crates/typst-render", version = "0.13.0-rc1" }
|
||||
typst-svg = { path = "crates/typst-svg", version = "0.13.0-rc1" }
|
||||
typst-syntax = { path = "crates/typst-syntax", version = "0.13.0-rc1" }
|
||||
typst-timing = { path = "crates/typst-timing", version = "0.13.0-rc1" }
|
||||
typst-utils = { path = "crates/typst-utils", version = "0.13.0-rc1" }
|
||||
typst-assets = "0.13.0-rc1"
|
||||
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "7f8999d" }
|
||||
arrayvec = "0.7.4"
|
||||
az = "1.2"
|
||||
base64 = "0.22"
|
||||
@ -55,11 +55,9 @@ ctrlc = "3.4.1"
|
||||
dirs = "6"
|
||||
ecow = { version = "0.2", features = ["serde"] }
|
||||
env_proxy = "0.4"
|
||||
fastrand = "2.3"
|
||||
flate2 = "1"
|
||||
fontdb = { version = "0.23", default-features = false }
|
||||
fontdb = { version = "0.21", default-features = false }
|
||||
fs_extra = "1.3"
|
||||
glidesort = "0.1.2"
|
||||
hayagriva = "0.8.1"
|
||||
heck = "0.5"
|
||||
hypher = "0.1.4"
|
||||
@ -71,25 +69,23 @@ icu_segmenter = { version = "1.4", features = ["serde"] }
|
||||
if_chain = "1"
|
||||
image = { version = "0.25.5", default-features = false, features = ["png", "jpeg", "gif"] }
|
||||
indexmap = { version = "2", features = ["serde"] }
|
||||
infer = { version = "0.19.0", default-features = false }
|
||||
kamadak-exif = "0.6"
|
||||
krilla = { version = "0.4.0", default-features = false, features = ["raster-images", "comemo", "rayon"] }
|
||||
krilla-svg = "0.1.0"
|
||||
kurbo = "0.11"
|
||||
libfuzzer-sys = "0.4"
|
||||
lipsum = "0.9"
|
||||
memchr = "2"
|
||||
miniz_oxide = "0.8"
|
||||
native-tls = "0.2"
|
||||
notify = "8"
|
||||
once_cell = "1"
|
||||
open = "5.0.1"
|
||||
openssl = "0.10.72"
|
||||
openssl = "0.10"
|
||||
oxipng = { version = "9.0", default-features = false, features = ["filetime", "parallel", "zopfli"] }
|
||||
palette = { version = "0.7.3", default-features = false, features = ["approx", "libm"] }
|
||||
parking_lot = "0.12.1"
|
||||
pathdiff = "0.2"
|
||||
pdf-writer = "0.12.1"
|
||||
phf = { version = "0.11", features = ["macros"] }
|
||||
pixglyph = "0.6"
|
||||
pixglyph = "0.5.1"
|
||||
png = "0.17"
|
||||
portable-atomic = "1.6"
|
||||
proc-macro2 = "1"
|
||||
@ -99,10 +95,10 @@ quote = "1"
|
||||
rayon = "1.7.0"
|
||||
regex = "1"
|
||||
regex-syntax = "0.8"
|
||||
resvg = { version = "0.45", default-features = false, features = ["raster-images"] }
|
||||
resvg = { version = "0.43", default-features = false, features = ["raster-images"] }
|
||||
roxmltree = "0.20"
|
||||
rust_decimal = { version = "1.36.0", default-features = false, features = ["maths"] }
|
||||
rustybuzz = "0.20"
|
||||
rustybuzz = "0.18"
|
||||
same-file = "1"
|
||||
self-replace = "1.3.7"
|
||||
semver = "1"
|
||||
@ -114,6 +110,8 @@ sigpipe = "0.1"
|
||||
siphasher = "1"
|
||||
smallvec = { version = "1.11.1", features = ["union", "const_generics", "const_new"] }
|
||||
stacker = "0.1.15"
|
||||
subsetter = "0.2"
|
||||
svg2pdf = "0.12"
|
||||
syn = { version = "2", features = ["full", "extra-traits"] }
|
||||
syntect = { version = "5", default-features = false, features = ["parsing", "regex-fancy", "plist-load", "yaml-load"] }
|
||||
tar = "0.4"
|
||||
@ -123,26 +121,26 @@ time = { version = "0.3.20", features = ["formatting", "macros", "parsing"] }
|
||||
tiny_http = "0.12"
|
||||
tiny-skia = "0.11"
|
||||
toml = { version = "0.8", default-features = false, features = ["parse", "display"] }
|
||||
ttf-parser = "0.25.0"
|
||||
ttf-parser = "0.24.1"
|
||||
two-face = { version = "0.4.3", default-features = false, features = ["syntect-fancy"] }
|
||||
typed-arena = "2"
|
||||
unicode-bidi = "0.3.18"
|
||||
unicode-ident = "1.0"
|
||||
unicode-math-class = "0.1"
|
||||
unicode-script = "0.5"
|
||||
unicode-normalization = "0.1.24"
|
||||
unicode-segmentation = "1"
|
||||
unscanny = "0.1"
|
||||
ureq = { version = "2", default-features = false, features = ["native-tls", "gzip", "json"] }
|
||||
usvg = { version = "0.45", default-features = false, features = ["text"] }
|
||||
usvg = { version = "0.43", default-features = false, features = ["text"] }
|
||||
walkdir = "2"
|
||||
wasmi = "0.40.0"
|
||||
web-sys = "0.3"
|
||||
xmlparser = "0.13.5"
|
||||
xmlwriter = "0.1.0"
|
||||
xmp-writer = "0.3.1"
|
||||
xz2 = { version = "0.1", features = ["static"] }
|
||||
yaml-front-matter = "0.1"
|
||||
zip = { version = "2.5", default-features = false, features = ["deflate"] }
|
||||
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 2
|
||||
|
29
README.md
29
README.md
@ -113,9 +113,7 @@ Typst's CLI is available from different sources:
|
||||
|
||||
- You can install Typst through different package managers. Note that the
|
||||
versions in the package managers might lag behind the latest release.
|
||||
- Linux:
|
||||
- View [Typst on Repology][repology]
|
||||
- View [Typst's Snap][snap]
|
||||
- Linux: View [Typst on Repology][repology]
|
||||
- macOS: `brew install typst`
|
||||
- Windows: `winget install --id Typst.Typst`
|
||||
|
||||
@ -177,22 +175,22 @@ If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||
preview, you can also check out [Typst's free web app][app].
|
||||
|
||||
## Community
|
||||
The main places where the community gathers are our [Forum][forum] and our
|
||||
[Discord server][discord]. The Forum is a great place to ask questions, help
|
||||
others, and share cool things you created with Typst. The Discord server is more
|
||||
suitable for quicker questions, discussions about contributing, or just to chat.
|
||||
We'd be happy to see you there!
|
||||
The main place where the community gathers is our [Discord server][discord].
|
||||
Feel free to join there to ask questions, help out others, share cool things
|
||||
you created with Typst, or just to chat.
|
||||
|
||||
[Typst Universe][universe] is where the community shares templates and packages.
|
||||
If you want to share your own creations, you can submit them to our
|
||||
[package repository][packages].
|
||||
Aside from that there are a few places where you can find things built by
|
||||
the community:
|
||||
|
||||
- The official [package list](https://typst.app/docs/packages)
|
||||
- The [Awesome Typst](https://github.com/qjcg/awesome-typst) repository
|
||||
|
||||
If you had a bad experience in our community, please [reach out to us][contact].
|
||||
|
||||
## Contributing
|
||||
We love to see contributions from the community. If you experience bugs, feel
|
||||
free to open an issue. If you would like to implement a new feature or bug fix,
|
||||
please follow the steps outlined in the [contribution guide][contributing].
|
||||
We would love to see contributions from the community. If you experience bugs,
|
||||
feel free to open an issue. If you would like to implement a new feature or bug
|
||||
fix, please follow the steps outlined in the [contribution guide][contributing].
|
||||
|
||||
To build Typst yourself, first ensure that you have the
|
||||
[latest stable Rust][rust] installed. Then, clone this repository and build the
|
||||
@ -243,8 +241,6 @@ instant preview. To achieve these goals, we follow three core design principles:
|
||||
[docs]: https://typst.app/docs/
|
||||
[app]: https://typst.app/
|
||||
[discord]: https://discord.gg/2uDybryKPe
|
||||
[forum]: https://forum.typst.app/
|
||||
[universe]: https://typst.app/universe/
|
||||
[tutorial]: https://typst.app/docs/tutorial/
|
||||
[show]: https://typst.app/docs/reference/styling/#show-rules
|
||||
[math]: https://typst.app/docs/reference/math/
|
||||
@ -258,4 +254,3 @@ instant preview. To achieve these goals, we follow three core design principles:
|
||||
[contributing]: https://github.com/typst/typst/blob/main/CONTRIBUTING.md
|
||||
[packages]: https://github.com/typst/packages/
|
||||
[`comemo`]: https://github.com/typst/comemo/
|
||||
[snap]: https://snapcraft.io/typst
|
||||
|
@ -361,7 +361,7 @@ pub struct FontArgs {
|
||||
|
||||
/// Ensures system fonts won't be searched, unless explicitly included via
|
||||
/// `--font-path`.
|
||||
#[arg(long, env = "TYPST_IGNORE_SYSTEM_FONTS")]
|
||||
#[arg(long)]
|
||||
pub ignore_system_fonts: bool,
|
||||
}
|
||||
|
||||
@ -467,45 +467,15 @@ display_possible_values!(Feature);
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, ValueEnum)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum PdfStandard {
|
||||
/// PDF 1.4.
|
||||
#[value(name = "1.4")]
|
||||
V_1_4,
|
||||
/// PDF 1.5.
|
||||
#[value(name = "1.5")]
|
||||
V_1_5,
|
||||
/// PDF 1.5.
|
||||
#[value(name = "1.6")]
|
||||
V_1_6,
|
||||
/// PDF 1.7.
|
||||
#[value(name = "1.7")]
|
||||
V_1_7,
|
||||
/// PDF 2.0.
|
||||
#[value(name = "2.0")]
|
||||
V_2_0,
|
||||
/// PDF/A-1b.
|
||||
#[value(name = "a-1b")]
|
||||
A_1b,
|
||||
/// PDF/A-2b.
|
||||
#[value(name = "a-2b")]
|
||||
A_2b,
|
||||
/// PDF/A-2u.
|
||||
#[value(name = "a-2u")]
|
||||
A_2u,
|
||||
/// PDF/A-3u.
|
||||
/// PDF/A-3b.
|
||||
#[value(name = "a-3b")]
|
||||
A_3b,
|
||||
/// PDF/A-3u.
|
||||
#[value(name = "a-3u")]
|
||||
A_3u,
|
||||
/// PDF/A-4.
|
||||
#[value(name = "a-4")]
|
||||
A_4,
|
||||
/// PDF/A-4f.
|
||||
#[value(name = "a-4f")]
|
||||
A_4f,
|
||||
/// PDF/A-4e.
|
||||
#[value(name = "a-4e")]
|
||||
A_4e,
|
||||
}
|
||||
|
||||
display_possible_values!(PdfStandard);
|
||||
|
@ -6,9 +6,8 @@ use std::path::{Path, PathBuf};
|
||||
use chrono::{DateTime, Datelike, Timelike, Utc};
|
||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||
use codespan_reporting::term;
|
||||
use ecow::eco_format;
|
||||
use ecow::{eco_format, EcoString};
|
||||
use parking_lot::RwLock;
|
||||
use pathdiff::diff_paths;
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
use typst::diag::{
|
||||
bail, At, Severity, SourceDiagnostic, SourceResult, StrResult, Warned,
|
||||
@ -63,7 +62,8 @@ pub struct CompileConfig {
|
||||
/// Opens the output file with the default viewer or a specific program after
|
||||
/// compilation.
|
||||
pub open: Option<Option<String>>,
|
||||
/// A list of standards the PDF should conform to.
|
||||
/// One (or multiple comma-separated) PDF standards that Typst will enforce
|
||||
/// conformance with.
|
||||
pub pdf_standards: PdfStandards,
|
||||
/// A path to write a Makefile rule describing the current compilation.
|
||||
pub make_deps: Option<PathBuf>,
|
||||
@ -129,9 +129,18 @@ impl CompileConfig {
|
||||
PageRanges::new(export_ranges.iter().map(|r| r.0.clone()).collect())
|
||||
});
|
||||
|
||||
let pdf_standards = PdfStandards::new(
|
||||
&args.pdf_standard.iter().copied().map(Into::into).collect::<Vec<_>>(),
|
||||
)?;
|
||||
let pdf_standards = {
|
||||
let list = args
|
||||
.pdf_standard
|
||||
.iter()
|
||||
.map(|standard| match standard {
|
||||
PdfStandard::V_1_7 => typst_pdf::PdfStandard::V_1_7,
|
||||
PdfStandard::A_2b => typst_pdf::PdfStandard::A_2b,
|
||||
PdfStandard::A_3b => typst_pdf::PdfStandard::A_3b,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
PdfStandards::new(&list)?
|
||||
};
|
||||
|
||||
#[cfg(feature = "http-server")]
|
||||
let server = match watch {
|
||||
@ -179,7 +188,7 @@ pub fn compile_once(
|
||||
|
||||
match output {
|
||||
// Export the PDF / PNG.
|
||||
Ok(outputs) => {
|
||||
Ok(()) => {
|
||||
let duration = start.elapsed();
|
||||
|
||||
if config.watching {
|
||||
@ -193,7 +202,7 @@ pub fn compile_once(
|
||||
print_diagnostics(world, &[], &warnings, config.diagnostic_format)
|
||||
.map_err(|err| eco_format!("failed to print diagnostics ({err})"))?;
|
||||
|
||||
write_make_deps(world, config, outputs)?;
|
||||
write_make_deps(world, config)?;
|
||||
open_output(config)?;
|
||||
}
|
||||
|
||||
@ -217,15 +226,12 @@ pub fn compile_once(
|
||||
fn compile_and_export(
|
||||
world: &mut SystemWorld,
|
||||
config: &mut CompileConfig,
|
||||
) -> Warned<SourceResult<Vec<Output>>> {
|
||||
) -> Warned<SourceResult<()>> {
|
||||
match config.output_format {
|
||||
OutputFormat::Html => {
|
||||
let Warned { output, warnings } = typst::compile::<HtmlDocument>(world);
|
||||
let result = output.and_then(|document| export_html(&document, config));
|
||||
Warned {
|
||||
output: result.map(|()| vec![config.output.clone()]),
|
||||
warnings,
|
||||
}
|
||||
Warned { output: result, warnings }
|
||||
}
|
||||
_ => {
|
||||
let Warned { output, warnings } = typst::compile::<PagedDocument>(world);
|
||||
@ -251,14 +257,9 @@ fn export_html(document: &HtmlDocument, config: &CompileConfig) -> SourceResult<
|
||||
}
|
||||
|
||||
/// Export to a paged target format.
|
||||
fn export_paged(
|
||||
document: &PagedDocument,
|
||||
config: &CompileConfig,
|
||||
) -> SourceResult<Vec<Output>> {
|
||||
fn export_paged(document: &PagedDocument, config: &CompileConfig) -> SourceResult<()> {
|
||||
match config.output_format {
|
||||
OutputFormat::Pdf => {
|
||||
export_pdf(document, config).map(|()| vec![config.output.clone()])
|
||||
}
|
||||
OutputFormat::Pdf => export_pdf(document, config),
|
||||
OutputFormat::Png => {
|
||||
export_image(document, config, ImageExportFormat::Png).at(Span::detached())
|
||||
}
|
||||
@ -285,7 +286,6 @@ fn export_pdf(document: &PagedDocument, config: &CompileConfig) -> SourceResult<
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
let options = PdfOptions {
|
||||
ident: Smart::Auto,
|
||||
timestamp,
|
||||
@ -327,7 +327,7 @@ fn export_image(
|
||||
document: &PagedDocument,
|
||||
config: &CompileConfig,
|
||||
fmt: ImageExportFormat,
|
||||
) -> StrResult<Vec<Output>> {
|
||||
) -> StrResult<()> {
|
||||
// Determine whether we have indexable templates in output
|
||||
let can_handle_multiple = match config.output {
|
||||
Output::Stdout => false,
|
||||
@ -341,7 +341,7 @@ fn export_image(
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(i, _)| {
|
||||
config.pages.as_ref().is_none_or(|exported_page_ranges| {
|
||||
config.pages.as_ref().map_or(true, |exported_page_ranges| {
|
||||
exported_page_ranges.includes_page_index(*i)
|
||||
})
|
||||
})
|
||||
@ -383,7 +383,7 @@ fn export_image(
|
||||
&& config.export_cache.is_cached(*i, &page.frame)
|
||||
&& path.exists()
|
||||
{
|
||||
return Ok(Output::Path(path.to_path_buf()));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Output::Path(path.to_owned())
|
||||
@ -392,9 +392,11 @@ fn export_image(
|
||||
};
|
||||
|
||||
export_image_page(config, page, &output, fmt)?;
|
||||
Ok(output)
|
||||
Ok(())
|
||||
})
|
||||
.collect::<StrResult<Vec<Output>>>()
|
||||
.collect::<Result<Vec<()>, EcoString>>()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
mod output_template {
|
||||
@ -499,25 +501,14 @@ impl ExportCache {
|
||||
/// Writes a Makefile rule describing the relationship between the output and
|
||||
/// its dependencies to the path specified by the --make-deps argument, if it
|
||||
/// was provided.
|
||||
fn write_make_deps(
|
||||
world: &mut SystemWorld,
|
||||
config: &CompileConfig,
|
||||
outputs: Vec<Output>,
|
||||
) -> StrResult<()> {
|
||||
fn write_make_deps(world: &mut SystemWorld, config: &CompileConfig) -> StrResult<()> {
|
||||
let Some(ref make_deps_path) = config.make_deps else { return Ok(()) };
|
||||
let Ok(output_paths) = outputs
|
||||
.into_iter()
|
||||
.filter_map(|o| match o {
|
||||
Output::Path(path) => Some(path.into_os_string().into_string()),
|
||||
Output::Stdout => None,
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
else {
|
||||
let Output::Path(output_path) = &config.output else {
|
||||
bail!("failed to create make dependencies file because output was stdout")
|
||||
};
|
||||
let Some(output_path) = output_path.as_os_str().to_str() else {
|
||||
bail!("failed to create make dependencies file because output path was not valid unicode")
|
||||
};
|
||||
if output_paths.is_empty() {
|
||||
bail!("failed to create make dependencies file because output was stdout")
|
||||
}
|
||||
|
||||
// Based on `munge` in libcpp/mkdeps.cc from the GCC source code. This isn't
|
||||
// perfect as some special characters can't be escaped.
|
||||
@ -531,10 +522,6 @@ fn write_make_deps(
|
||||
res.push('$');
|
||||
slashes = 0;
|
||||
}
|
||||
':' => {
|
||||
res.push('\\');
|
||||
slashes = 0;
|
||||
}
|
||||
' ' | '\t' => {
|
||||
// `munge`'s source contains a comment here that says: "A
|
||||
// space or tab preceded by 2N+1 backslashes represents N
|
||||
@ -557,29 +544,18 @@ fn write_make_deps(
|
||||
|
||||
fn write(
|
||||
make_deps_path: &Path,
|
||||
output_paths: Vec<String>,
|
||||
output_path: &str,
|
||||
root: PathBuf,
|
||||
dependencies: impl Iterator<Item = PathBuf>,
|
||||
) -> io::Result<()> {
|
||||
let mut file = File::create(make_deps_path)?;
|
||||
let current_dir = std::env::current_dir()?;
|
||||
let relative_root = diff_paths(&root, ¤t_dir).unwrap_or(root.clone());
|
||||
|
||||
for (i, output_path) in output_paths.into_iter().enumerate() {
|
||||
if i != 0 {
|
||||
file.write_all(b" ")?;
|
||||
}
|
||||
file.write_all(munge(&output_path).as_bytes())?;
|
||||
}
|
||||
file.write_all(munge(output_path).as_bytes())?;
|
||||
file.write_all(b":")?;
|
||||
for dependency in dependencies {
|
||||
let relative_dependency = match dependency.strip_prefix(&root) {
|
||||
Ok(root_relative_dependency) => {
|
||||
relative_root.join(root_relative_dependency)
|
||||
}
|
||||
Err(_) => dependency,
|
||||
};
|
||||
let Some(relative_dependency) = relative_dependency.to_str() else {
|
||||
let Some(dependency) =
|
||||
dependency.strip_prefix(&root).unwrap_or(&dependency).to_str()
|
||||
else {
|
||||
// Silently skip paths that aren't valid unicode so we still
|
||||
// produce a rule that will work for the other paths that can be
|
||||
// processed.
|
||||
@ -587,14 +563,14 @@ fn write_make_deps(
|
||||
};
|
||||
|
||||
file.write_all(b" ")?;
|
||||
file.write_all(munge(relative_dependency).as_bytes())?;
|
||||
file.write_all(munge(dependency).as_bytes())?;
|
||||
}
|
||||
file.write_all(b"\n")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
write(make_deps_path, output_paths, world.root().to_owned(), world.dependencies())
|
||||
write(make_deps_path, output_path, world.root().to_owned(), world.dependencies())
|
||||
.map_err(|err| {
|
||||
eco_format!("failed to create make dependencies file due to IO error ({err})")
|
||||
})
|
||||
@ -756,23 +732,3 @@ impl<'a> codespan_reporting::files::Files<'a> for SystemWorld {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PdfStandard> for typst_pdf::PdfStandard {
|
||||
fn from(standard: PdfStandard) -> Self {
|
||||
match standard {
|
||||
PdfStandard::V_1_4 => typst_pdf::PdfStandard::V_1_4,
|
||||
PdfStandard::V_1_5 => typst_pdf::PdfStandard::V_1_5,
|
||||
PdfStandard::V_1_6 => typst_pdf::PdfStandard::V_1_6,
|
||||
PdfStandard::V_1_7 => typst_pdf::PdfStandard::V_1_7,
|
||||
PdfStandard::V_2_0 => typst_pdf::PdfStandard::V_2_0,
|
||||
PdfStandard::A_1b => typst_pdf::PdfStandard::A_1b,
|
||||
PdfStandard::A_2b => typst_pdf::PdfStandard::A_2b,
|
||||
PdfStandard::A_2u => typst_pdf::PdfStandard::A_2u,
|
||||
PdfStandard::A_3b => typst_pdf::PdfStandard::A_3b,
|
||||
PdfStandard::A_3u => typst_pdf::PdfStandard::A_3u,
|
||||
PdfStandard::A_4 => typst_pdf::PdfStandard::A_4,
|
||||
PdfStandard::A_4f => typst_pdf::PdfStandard::A_4f,
|
||||
PdfStandard::A_4e => typst_pdf::PdfStandard::A_4e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ use comemo::Track;
|
||||
use ecow::{eco_format, EcoString};
|
||||
use serde::Serialize;
|
||||
use typst::diag::{bail, HintedStrResult, StrResult, Warned};
|
||||
use typst::engine::Sink;
|
||||
use typst::foundations::{Content, IntoValue, LocatableSelector, Scope};
|
||||
use typst::layout::PagedDocument;
|
||||
use typst::syntax::Span;
|
||||
@ -59,8 +58,6 @@ fn retrieve(
|
||||
let selector = eval_string(
|
||||
&typst::ROUTINES,
|
||||
world.track(),
|
||||
// TODO: propagate warnings
|
||||
Sink::new().track_mut(),
|
||||
&command.selector,
|
||||
Span::detached(),
|
||||
EvalMode::Code,
|
||||
|
@ -55,11 +55,11 @@ pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> {
|
||||
// Perform initial compilation.
|
||||
timer.record(&mut world, |world| compile_once(world, &mut config))??;
|
||||
|
||||
// Watch all dependencies of the initial compilation.
|
||||
watcher.update(world.dependencies())?;
|
||||
|
||||
// Recompile whenever something relevant happens.
|
||||
loop {
|
||||
// Watch all dependencies of the most recent compilation.
|
||||
watcher.update(world.dependencies())?;
|
||||
|
||||
// Wait until anything relevant happens.
|
||||
watcher.wait()?;
|
||||
|
||||
@ -71,6 +71,9 @@ pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> {
|
||||
|
||||
// Evict the cache.
|
||||
comemo::evict(10);
|
||||
|
||||
// Adjust the file watching.
|
||||
watcher.update(world.dependencies())?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,10 +204,6 @@ impl Watcher {
|
||||
let event = event
|
||||
.map_err(|err| eco_format!("failed to watch dependencies ({err})"))?;
|
||||
|
||||
if !is_relevant_event_kind(&event.kind) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Workaround for notify-rs' implicit unwatch on remove/rename
|
||||
// (triggered by some editors when saving files) with the
|
||||
// inotify backend. By keeping track of the potentially
|
||||
@ -225,17 +224,7 @@ impl Watcher {
|
||||
}
|
||||
}
|
||||
|
||||
// Don't recompile because the output file changed.
|
||||
// FIXME: This doesn't work properly for multifile image export.
|
||||
if event
|
||||
.paths
|
||||
.iter()
|
||||
.all(|path| is_same_file(path, &self.output).unwrap_or(false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
relevant = true;
|
||||
relevant |= self.is_event_relevant(&event);
|
||||
}
|
||||
|
||||
// If we found a relevant event or if any of the missing files now
|
||||
@ -245,23 +234,32 @@ impl Watcher {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a kind of watch event is relevant for compilation.
|
||||
fn is_relevant_event_kind(kind: ¬ify::EventKind) -> bool {
|
||||
match kind {
|
||||
notify::EventKind::Any => true,
|
||||
notify::EventKind::Access(_) => false,
|
||||
notify::EventKind::Create(_) => true,
|
||||
notify::EventKind::Modify(kind) => match kind {
|
||||
notify::event::ModifyKind::Any => true,
|
||||
notify::event::ModifyKind::Data(_) => true,
|
||||
notify::event::ModifyKind::Metadata(_) => false,
|
||||
notify::event::ModifyKind::Name(_) => true,
|
||||
notify::event::ModifyKind::Other => false,
|
||||
},
|
||||
notify::EventKind::Remove(_) => true,
|
||||
notify::EventKind::Other => false,
|
||||
/// Whether a watch event is relevant for compilation.
|
||||
fn is_event_relevant(&self, event: ¬ify::Event) -> bool {
|
||||
// Never recompile because the output file changed.
|
||||
if event
|
||||
.paths
|
||||
.iter()
|
||||
.all(|path| is_same_file(path, &self.output).unwrap_or(false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
match &event.kind {
|
||||
notify::EventKind::Any => true,
|
||||
notify::EventKind::Access(_) => false,
|
||||
notify::EventKind::Create(_) => true,
|
||||
notify::EventKind::Modify(kind) => match kind {
|
||||
notify::event::ModifyKind::Any => true,
|
||||
notify::event::ModifyKind::Data(_) => true,
|
||||
notify::event::ModifyKind::Metadata(_) => false,
|
||||
notify::event::ModifyKind::Name(_) => true,
|
||||
notify::event::ModifyKind::Other => false,
|
||||
},
|
||||
notify::EventKind::Remove(_) => true,
|
||||
notify::EventKind::Other => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,9 +210,7 @@ impl World for SystemWorld {
|
||||
}
|
||||
|
||||
fn font(&self, index: usize) -> Option<Font> {
|
||||
// comemo's validation may invoke this function with an invalid index. This is
|
||||
// impossible in typst-cli but possible if a custom tool mutates the fonts.
|
||||
self.fonts.get(index)?.get()
|
||||
self.fonts[index].get()
|
||||
}
|
||||
|
||||
fn today(&self, offset: Option<i64>) -> Option<Datetime> {
|
||||
|
@ -466,7 +466,7 @@ impl<'a> CapturesVisitor<'a> {
|
||||
}
|
||||
|
||||
// Code and content blocks create a scope.
|
||||
Some(ast::Expr::CodeBlock(_) | ast::Expr::ContentBlock(_)) => {
|
||||
Some(ast::Expr::Code(_) | ast::Expr::Content(_)) => {
|
||||
self.internal.enter();
|
||||
for child in node.children() {
|
||||
self.visit(child);
|
||||
@ -516,7 +516,7 @@ impl<'a> CapturesVisitor<'a> {
|
||||
|
||||
// A let expression contains a binding, but that binding is only
|
||||
// active after the body is evaluated.
|
||||
Some(ast::Expr::LetBinding(expr)) => {
|
||||
Some(ast::Expr::Let(expr)) => {
|
||||
if let Some(init) = expr.init() {
|
||||
self.visit(init.to_untyped());
|
||||
}
|
||||
@ -529,7 +529,7 @@ impl<'a> CapturesVisitor<'a> {
|
||||
// A for loop contains one or two bindings in its pattern. These are
|
||||
// active after the iterable is evaluated but before the body is
|
||||
// evaluated.
|
||||
Some(ast::Expr::ForLoop(expr)) => {
|
||||
Some(ast::Expr::For(expr)) => {
|
||||
self.visit(expr.iterable().to_untyped());
|
||||
self.internal.enter();
|
||||
|
||||
@ -544,7 +544,7 @@ impl<'a> CapturesVisitor<'a> {
|
||||
|
||||
// An import contains items, but these are active only after the
|
||||
// path is evaluated.
|
||||
Some(ast::Expr::ModuleImport(expr)) => {
|
||||
Some(ast::Expr::Import(expr)) => {
|
||||
self.visit(expr.source().to_untyped());
|
||||
if let Some(ast::Imports::Items(items)) = expr.imports() {
|
||||
for item in items.iter() {
|
||||
|
@ -30,7 +30,7 @@ fn eval_code<'a>(
|
||||
while let Some(expr) = exprs.next() {
|
||||
let span = expr.span();
|
||||
let value = match expr {
|
||||
ast::Expr::SetRule(set) => {
|
||||
ast::Expr::Set(set) => {
|
||||
let styles = set.eval(vm)?;
|
||||
if vm.flow.is_some() {
|
||||
break;
|
||||
@ -39,7 +39,7 @@ fn eval_code<'a>(
|
||||
let tail = eval_code(vm, exprs)?.display();
|
||||
Value::Content(tail.styled_with_map(styles))
|
||||
}
|
||||
ast::Expr::ShowRule(show) => {
|
||||
ast::Expr::Show(show) => {
|
||||
let recipe = show.eval(vm)?;
|
||||
if vm.flow.is_some() {
|
||||
break;
|
||||
@ -94,9 +94,9 @@ impl Eval for ast::Expr<'_> {
|
||||
Self::Label(v) => v.eval(vm),
|
||||
Self::Ref(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Heading(v) => v.eval(vm).map(Value::Content),
|
||||
Self::ListItem(v) => v.eval(vm).map(Value::Content),
|
||||
Self::EnumItem(v) => v.eval(vm).map(Value::Content),
|
||||
Self::TermItem(v) => v.eval(vm).map(Value::Content),
|
||||
Self::List(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Enum(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Term(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Equation(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Math(v) => v.eval(vm).map(Value::Content),
|
||||
Self::MathText(v) => v.eval(vm).map(Value::Content),
|
||||
@ -116,8 +116,8 @@ impl Eval for ast::Expr<'_> {
|
||||
Self::Float(v) => v.eval(vm),
|
||||
Self::Numeric(v) => v.eval(vm),
|
||||
Self::Str(v) => v.eval(vm),
|
||||
Self::CodeBlock(v) => v.eval(vm),
|
||||
Self::ContentBlock(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Code(v) => v.eval(vm),
|
||||
Self::Content(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Array(v) => v.eval(vm).map(Value::Array),
|
||||
Self::Dict(v) => v.eval(vm).map(Value::Dict),
|
||||
Self::Parenthesized(v) => v.eval(vm),
|
||||
@ -126,19 +126,19 @@ impl Eval for ast::Expr<'_> {
|
||||
Self::Closure(v) => v.eval(vm),
|
||||
Self::Unary(v) => v.eval(vm),
|
||||
Self::Binary(v) => v.eval(vm),
|
||||
Self::LetBinding(v) => v.eval(vm),
|
||||
Self::DestructAssignment(v) => v.eval(vm),
|
||||
Self::SetRule(_) => bail!(forbidden("set")),
|
||||
Self::ShowRule(_) => bail!(forbidden("show")),
|
||||
Self::Let(v) => v.eval(vm),
|
||||
Self::DestructAssign(v) => v.eval(vm),
|
||||
Self::Set(_) => bail!(forbidden("set")),
|
||||
Self::Show(_) => bail!(forbidden("show")),
|
||||
Self::Contextual(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Conditional(v) => v.eval(vm),
|
||||
Self::WhileLoop(v) => v.eval(vm),
|
||||
Self::ForLoop(v) => v.eval(vm),
|
||||
Self::ModuleImport(v) => v.eval(vm),
|
||||
Self::ModuleInclude(v) => v.eval(vm).map(Value::Content),
|
||||
Self::LoopBreak(v) => v.eval(vm),
|
||||
Self::LoopContinue(v) => v.eval(vm),
|
||||
Self::FuncReturn(v) => v.eval(vm),
|
||||
Self::While(v) => v.eval(vm),
|
||||
Self::For(v) => v.eval(vm),
|
||||
Self::Import(v) => v.eval(vm),
|
||||
Self::Include(v) => v.eval(vm).map(Value::Content),
|
||||
Self::Break(v) => v.eval(vm),
|
||||
Self::Continue(v) => v.eval(vm),
|
||||
Self::Return(v) => v.eval(vm),
|
||||
}?
|
||||
.spanned(span);
|
||||
|
||||
|
@ -44,10 +44,11 @@ impl Eval for ast::ModuleImport<'_> {
|
||||
}
|
||||
|
||||
// If there is a rename, import the source itself under that name.
|
||||
let bare_name = self.bare_name();
|
||||
let new_name = self.new_name();
|
||||
if let Some(new_name) = new_name {
|
||||
if let ast::Expr::Ident(ident) = self.source() {
|
||||
if ident.as_str() == new_name.as_str() {
|
||||
if let Ok(source_name) = &bare_name {
|
||||
if source_name == new_name.as_str() {
|
||||
// Warn on `import x as x`
|
||||
vm.engine.sink.warn(warning!(
|
||||
new_name.span(),
|
||||
@ -56,7 +57,6 @@ impl Eval for ast::ModuleImport<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
// Define renamed module on the scope.
|
||||
vm.define(new_name, source.clone());
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,6 @@ pub fn eval(
|
||||
pub fn eval_string(
|
||||
routines: &Routines,
|
||||
world: Tracked<dyn World + '_>,
|
||||
sink: TrackedMut<Sink>,
|
||||
string: &str,
|
||||
span: Span,
|
||||
mode: EvalMode,
|
||||
@ -122,6 +121,7 @@ pub fn eval_string(
|
||||
}
|
||||
|
||||
// Prepare the engine.
|
||||
let mut sink = Sink::new();
|
||||
let introspector = Introspector::default();
|
||||
let traced = Traced::default();
|
||||
let engine = Engine {
|
||||
@ -129,7 +129,7 @@ pub fn eval_string(
|
||||
world,
|
||||
introspector: introspector.track(),
|
||||
traced: traced.track(),
|
||||
sink,
|
||||
sink: sink.track_mut(),
|
||||
route: Route::default(),
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ fn eval_markup<'a>(
|
||||
|
||||
while let Some(expr) = exprs.next() {
|
||||
match expr {
|
||||
ast::Expr::SetRule(set) => {
|
||||
ast::Expr::Set(set) => {
|
||||
let styles = set.eval(vm)?;
|
||||
if vm.flow.is_some() {
|
||||
break;
|
||||
@ -41,7 +41,7 @@ fn eval_markup<'a>(
|
||||
|
||||
seq.push(eval_markup(vm, exprs)?.styled_with_map(styles))
|
||||
}
|
||||
ast::Expr::ShowRule(show) => {
|
||||
ast::Expr::Show(show) => {
|
||||
let recipe = show.eval(vm)?;
|
||||
if vm.flow.is_some() {
|
||||
break;
|
||||
|
@ -45,7 +45,7 @@ impl Eval for ast::ShowRule<'_> {
|
||||
|
||||
let transform = self.transform();
|
||||
let transform = match transform {
|
||||
ast::Expr::SetRule(set) => Transformation::Style(set.eval(vm)?),
|
||||
ast::Expr::Set(set) => Transformation::Style(set.eval(vm)?),
|
||||
expr => expr.eval(vm)?.cast::<Transformation>().at(transform.span())?,
|
||||
};
|
||||
|
||||
|
@ -83,8 +83,8 @@ fn html_document_impl(
|
||||
)?;
|
||||
|
||||
let output = handle_list(&mut engine, &mut locator, children.iter().copied())?;
|
||||
let introspector = Introspector::html(&output);
|
||||
let root = root_element(output, &info)?;
|
||||
let introspector = Introspector::html(&root);
|
||||
|
||||
Ok(HtmlDocument { info, root, introspector })
|
||||
}
|
||||
@ -263,13 +263,13 @@ fn handle(
|
||||
/// Wrap the nodes in `<html>` and `<body>` if they are not yet rooted,
|
||||
/// supplying a suitable `<head>`.
|
||||
fn root_element(output: Vec<HtmlNode>, info: &DocumentInfo) -> SourceResult<HtmlElement> {
|
||||
let head = head_element(info);
|
||||
let body = match classify_output(output)? {
|
||||
OutputKind::Html(element) => return Ok(element),
|
||||
OutputKind::Body(body) => body,
|
||||
OutputKind::Leafs(leafs) => HtmlElement::new(tag::body).with_children(leafs),
|
||||
};
|
||||
Ok(HtmlElement::new(tag::html).with_children(vec![head.into(), body.into()]))
|
||||
Ok(HtmlElement::new(tag::html)
|
||||
.with_children(vec![head_element(info).into(), body.into()]))
|
||||
}
|
||||
|
||||
/// Generate a `<head>` element.
|
||||
@ -302,41 +302,23 @@ fn head_element(info: &DocumentInfo) -> HtmlElement {
|
||||
);
|
||||
}
|
||||
|
||||
if !info.author.is_empty() {
|
||||
children.push(
|
||||
HtmlElement::new(tag::meta)
|
||||
.with_attr(attr::name, "authors")
|
||||
.with_attr(attr::content, info.author.join(", "))
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
if !info.keywords.is_empty() {
|
||||
children.push(
|
||||
HtmlElement::new(tag::meta)
|
||||
.with_attr(attr::name, "keywords")
|
||||
.with_attr(attr::content, info.keywords.join(", "))
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
HtmlElement::new(tag::head).with_children(children)
|
||||
}
|
||||
|
||||
/// Determine which kind of output the user generated.
|
||||
fn classify_output(mut output: Vec<HtmlNode>) -> SourceResult<OutputKind> {
|
||||
let count = output.iter().filter(|node| !matches!(node, HtmlNode::Tag(_))).count();
|
||||
let len = output.len();
|
||||
for node in &mut output {
|
||||
let HtmlNode::Element(elem) = node else { continue };
|
||||
let tag = elem.tag;
|
||||
let mut take = || std::mem::replace(elem, HtmlElement::new(tag::html));
|
||||
match (tag, count) {
|
||||
match (tag, len) {
|
||||
(tag::html, 1) => return Ok(OutputKind::Html(take())),
|
||||
(tag::body, 1) => return Ok(OutputKind::Body(take())),
|
||||
(tag::html | tag::body, _) => bail!(
|
||||
elem.span,
|
||||
"`{}` element must be the only element in the document",
|
||||
elem.tag,
|
||||
elem.tag
|
||||
),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ pub fn analyze_expr(
|
||||
ast::Expr::Str(v) => Value::Str(v.get().into()),
|
||||
_ => {
|
||||
if node.kind() == SyntaxKind::Contextual {
|
||||
if let Some(child) = node.children().next_back() {
|
||||
if let Some(child) = node.children().last() {
|
||||
return analyze_expr(world, &child);
|
||||
}
|
||||
}
|
||||
|
@ -306,10 +306,7 @@ fn complete_math(ctx: &mut CompletionContext) -> bool {
|
||||
}
|
||||
|
||||
// Behind existing atom or identifier: "$a|$" or "$abc|$".
|
||||
if matches!(
|
||||
ctx.leaf.kind(),
|
||||
SyntaxKind::Text | SyntaxKind::MathText | SyntaxKind::MathIdent
|
||||
) {
|
||||
if matches!(ctx.leaf.kind(), SyntaxKind::Text | SyntaxKind::MathIdent) {
|
||||
ctx.from = ctx.leaf.offset();
|
||||
math_completions(ctx);
|
||||
return true;
|
||||
@ -361,7 +358,7 @@ fn complete_field_accesses(ctx: &mut CompletionContext) -> bool {
|
||||
// Behind an expression plus dot: "emoji.|".
|
||||
if_chain! {
|
||||
if ctx.leaf.kind() == SyntaxKind::Dot
|
||||
|| (matches!(ctx.leaf.kind(), SyntaxKind::Text | SyntaxKind::MathText)
|
||||
|| (ctx.leaf.kind() == SyntaxKind::Text
|
||||
&& ctx.leaf.text() == ".");
|
||||
if ctx.leaf.range().end == ctx.cursor;
|
||||
if let Some(prev) = ctx.leaf.prev_sibling();
|
||||
@ -401,26 +398,8 @@ fn field_access_completions(
|
||||
value: &Value,
|
||||
styles: &Option<Styles>,
|
||||
) {
|
||||
let scopes = {
|
||||
let ty = value.ty().scope();
|
||||
let elem = match value {
|
||||
Value::Content(content) => Some(content.elem().scope()),
|
||||
_ => None,
|
||||
};
|
||||
elem.into_iter().chain(Some(ty))
|
||||
};
|
||||
|
||||
// Autocomplete methods from the element's or type's scope. We only complete
|
||||
// those which have a `self` parameter.
|
||||
for (name, binding) in scopes.flat_map(|scope| scope.iter()) {
|
||||
let Ok(func) = binding.read().clone().cast::<Func>() else { continue };
|
||||
if func
|
||||
.params()
|
||||
.and_then(|params| params.first())
|
||||
.is_some_and(|param| param.name == "self")
|
||||
{
|
||||
ctx.call_completion(name.clone(), binding.read());
|
||||
}
|
||||
for (name, binding) in value.ty().scope().iter() {
|
||||
ctx.call_completion(name.clone(), binding.read());
|
||||
}
|
||||
|
||||
if let Some(scope) = value.scope() {
|
||||
@ -517,7 +496,7 @@ fn complete_imports(ctx: &mut CompletionContext) -> bool {
|
||||
// "#import "path.typ": a, b, |".
|
||||
if_chain! {
|
||||
if let Some(prev) = ctx.leaf.prev_sibling();
|
||||
if let Some(ast::Expr::ModuleImport(import)) = prev.get().cast();
|
||||
if let Some(ast::Expr::Import(import)) = prev.get().cast();
|
||||
if let Some(ast::Imports::Items(items)) = import.imports();
|
||||
if let Some(source) = prev.children().find(|child| child.is::<ast::Expr>());
|
||||
then {
|
||||
@ -536,7 +515,7 @@ fn complete_imports(ctx: &mut CompletionContext) -> bool {
|
||||
if let Some(grand) = parent.parent();
|
||||
if grand.kind() == SyntaxKind::ImportItems;
|
||||
if let Some(great) = grand.parent();
|
||||
if let Some(ast::Expr::ModuleImport(import)) = great.get().cast();
|
||||
if let Some(ast::Expr::Import(import)) = great.get().cast();
|
||||
if let Some(ast::Imports::Items(items)) = import.imports();
|
||||
if let Some(source) = great.children().find(|child| child.is::<ast::Expr>());
|
||||
then {
|
||||
@ -677,10 +656,10 @@ fn complete_params(ctx: &mut CompletionContext) -> bool {
|
||||
if let Some(args) = parent.get().cast::<ast::Args>();
|
||||
if let Some(grand) = parent.parent();
|
||||
if let Some(expr) = grand.get().cast::<ast::Expr>();
|
||||
let set = matches!(expr, ast::Expr::SetRule(_));
|
||||
let set = matches!(expr, ast::Expr::Set(_));
|
||||
if let Some(callee) = match expr {
|
||||
ast::Expr::FuncCall(call) => Some(call.callee()),
|
||||
ast::Expr::SetRule(set) => Some(set.target()),
|
||||
ast::Expr::Set(set) => Some(set.target()),
|
||||
_ => None,
|
||||
};
|
||||
then {
|
||||
@ -1463,7 +1442,7 @@ impl<'a> CompletionContext<'a> {
|
||||
let mut defined = BTreeMap::<EcoString, Option<Value>>::new();
|
||||
named_items(self.world, self.leaf.clone(), |item| {
|
||||
let name = item.name();
|
||||
if !name.is_empty() && item.value().as_ref().is_none_or(filter) {
|
||||
if !name.is_empty() && item.value().as_ref().map_or(true, filter) {
|
||||
defined.insert(name.clone(), item.value());
|
||||
}
|
||||
|
||||
@ -1768,26 +1747,4 @@ mod tests {
|
||||
.must_include(["this", "that"])
|
||||
.must_exclude(["*", "figure"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autocomplete_type_methods() {
|
||||
test("#\"hello\".", -1).must_include(["len", "contains"]);
|
||||
test("#table().", -1).must_exclude(["cell"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autocomplete_content_methods() {
|
||||
test("#show outline.entry: it => it.\n#outline()\n= Hi", 30)
|
||||
.must_include(["indented", "body", "page"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autocomplete_symbol_variants() {
|
||||
test("#sym.arrow.", -1)
|
||||
.must_include(["r", "dashed"])
|
||||
.must_exclude(["cases"]);
|
||||
test("$ arrow. $", -3)
|
||||
.must_include(["r", "dashed"])
|
||||
.must_exclude(["cases"]);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::num::NonZeroUsize;
|
||||
use typst::layout::{Frame, FrameItem, PagedDocument, Point, Position, Size};
|
||||
use typst::model::{Destination, Url};
|
||||
use typst::syntax::{FileId, LinkedNode, Side, Source, Span, SyntaxKind};
|
||||
use typst::visualize::{Curve, CurveItem, FillRule, Geometry};
|
||||
use typst::visualize::Geometry;
|
||||
use typst::WorldExt;
|
||||
|
||||
use crate::IdeWorld;
|
||||
@ -53,20 +53,10 @@ pub fn jump_from_click(
|
||||
for (mut pos, item) in frame.items().rev() {
|
||||
match item {
|
||||
FrameItem::Group(group) => {
|
||||
let pos = click - pos;
|
||||
if let Some(clip) = &group.clip {
|
||||
if !clip.contains(FillRule::NonZero, pos) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Realistic transforms should always be invertible.
|
||||
// An example of one that isn't is a scale of 0, which would
|
||||
// not be clickable anyway.
|
||||
let Some(inv_transform) = group.transform.invert() else {
|
||||
continue;
|
||||
};
|
||||
let pos = pos.transform_inf(inv_transform);
|
||||
if let Some(span) = jump_from_click(world, document, &group.frame, pos) {
|
||||
// TODO: Handle transformation.
|
||||
if let Some(span) =
|
||||
jump_from_click(world, document, &group.frame, click - pos)
|
||||
{
|
||||
return Some(span);
|
||||
}
|
||||
}
|
||||
@ -83,10 +73,7 @@ pub fn jump_from_click(
|
||||
let Some(id) = span.id() else { continue };
|
||||
let source = world.source(id).ok()?;
|
||||
let node = source.find(span)?;
|
||||
let pos = if matches!(
|
||||
node.kind(),
|
||||
SyntaxKind::Text | SyntaxKind::MathText
|
||||
) {
|
||||
let pos = if node.kind() == SyntaxKind::Text {
|
||||
let range = node.range();
|
||||
let mut offset = range.start + usize::from(span_offset);
|
||||
if (click.x - pos.x) > width / 2.0 {
|
||||
@ -104,32 +91,9 @@ pub fn jump_from_click(
|
||||
}
|
||||
|
||||
FrameItem::Shape(shape, span) => {
|
||||
if shape.fill.is_some() {
|
||||
let within = match &shape.geometry {
|
||||
Geometry::Line(..) => false,
|
||||
Geometry::Rect(size) => is_in_rect(pos, *size, click),
|
||||
Geometry::Curve(curve) => {
|
||||
curve.contains(shape.fill_rule, click - pos)
|
||||
}
|
||||
};
|
||||
if within {
|
||||
return Jump::from_span(world, *span);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(stroke) = &shape.stroke {
|
||||
let within = !stroke.thickness.approx_empty() && {
|
||||
// This curve is rooted at (0, 0), not `pos`.
|
||||
let base_curve = match &shape.geometry {
|
||||
Geometry::Line(to) => &Curve(vec![CurveItem::Line(*to)]),
|
||||
Geometry::Rect(size) => &Curve::rect(*size),
|
||||
Geometry::Curve(curve) => curve,
|
||||
};
|
||||
base_curve.stroke_contains(stroke, click - pos)
|
||||
};
|
||||
if within {
|
||||
return Jump::from_span(world, *span);
|
||||
}
|
||||
let Geometry::Rect(size) = shape.geometry else { continue };
|
||||
if is_in_rect(pos, size, click) {
|
||||
return Jump::from_span(world, *span);
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,7 +115,7 @@ pub fn jump_from_cursor(
|
||||
cursor: usize,
|
||||
) -> Vec<Position> {
|
||||
fn is_text(node: &LinkedNode) -> bool {
|
||||
matches!(node.kind(), SyntaxKind::Text | SyntaxKind::MathText)
|
||||
node.get().kind() == SyntaxKind::Text
|
||||
}
|
||||
|
||||
let root = LinkedNode::new(source.root());
|
||||
@ -179,8 +143,9 @@ pub fn jump_from_cursor(
|
||||
fn find_in_frame(frame: &Frame, span: Span) -> Option<Point> {
|
||||
for (mut pos, item) in frame.items() {
|
||||
if let FrameItem::Group(group) = item {
|
||||
// TODO: Handle transformation.
|
||||
if let Some(point) = find_in_frame(&group.frame, span) {
|
||||
return Some(pos + point.transform(group.transform));
|
||||
return Some(point + pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,102 +261,6 @@ mod tests {
|
||||
test_click(s, point(21.0, 12.0), cursor(56));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jump_from_click_math() {
|
||||
test_click("$a + b$", point(28.0, 14.0), cursor(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jump_from_click_transform_clip() {
|
||||
let margin = point(10.0, 10.0);
|
||||
test_click(
|
||||
"#rect(width: 20pt, height: 20pt, fill: black)",
|
||||
point(10.0, 10.0) + margin,
|
||||
cursor(1),
|
||||
);
|
||||
test_click(
|
||||
"#rect(width: 60pt, height: 10pt, fill: black)",
|
||||
point(5.0, 30.0) + margin,
|
||||
None,
|
||||
);
|
||||
test_click(
|
||||
"#rotate(90deg, origin: bottom + left, rect(width: 60pt, height: 10pt, fill: black))",
|
||||
point(5.0, 30.0) + margin,
|
||||
cursor(38),
|
||||
);
|
||||
test_click(
|
||||
"#scale(x: 300%, y: 300%, origin: top + left, rect(width: 10pt, height: 10pt, fill: black))",
|
||||
point(20.0, 20.0) + margin,
|
||||
cursor(45),
|
||||
);
|
||||
test_click(
|
||||
"#box(width: 10pt, height: 10pt, clip: true, scale(x: 300%, y: 300%, \
|
||||
origin: top + left, rect(width: 10pt, height: 10pt, fill: black)))",
|
||||
point(20.0, 20.0) + margin,
|
||||
None,
|
||||
);
|
||||
test_click(
|
||||
"#box(width: 10pt, height: 10pt, clip: false, rect(width: 30pt, height: 30pt, fill: black))",
|
||||
point(20.0, 20.0) + margin,
|
||||
cursor(45),
|
||||
);
|
||||
test_click(
|
||||
"#box(width: 10pt, height: 10pt, clip: true, rect(width: 30pt, height: 30pt, fill: black))",
|
||||
point(20.0, 20.0) + margin,
|
||||
None,
|
||||
);
|
||||
test_click(
|
||||
"#rotate(90deg, origin: bottom + left)[hello world]",
|
||||
point(5.0, 15.0) + margin,
|
||||
cursor(40),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jump_from_click_shapes() {
|
||||
let margin = point(10.0, 10.0);
|
||||
|
||||
test_click(
|
||||
"#rect(width: 30pt, height: 30pt, fill: black)",
|
||||
point(15.0, 15.0) + margin,
|
||||
cursor(1),
|
||||
);
|
||||
|
||||
let circle = "#circle(width: 30pt, height: 30pt, fill: black)";
|
||||
test_click(circle, point(15.0, 15.0) + margin, cursor(1));
|
||||
test_click(circle, point(1.0, 1.0) + margin, None);
|
||||
|
||||
let bowtie =
|
||||
"#polygon(fill: black, (0pt, 0pt), (20pt, 20pt), (20pt, 0pt), (0pt, 20pt))";
|
||||
test_click(bowtie, point(1.0, 2.0) + margin, cursor(1));
|
||||
test_click(bowtie, point(2.0, 1.0) + margin, None);
|
||||
test_click(bowtie, point(19.0, 10.0) + margin, cursor(1));
|
||||
|
||||
let evenodd = r#"#polygon(fill: black, fill-rule: "even-odd",
|
||||
(0pt, 10pt), (30pt, 10pt), (30pt, 20pt), (20pt, 20pt),
|
||||
(20pt, 0pt), (10pt, 0pt), (10pt, 30pt), (20pt, 30pt),
|
||||
(20pt, 20pt), (0pt, 20pt))"#;
|
||||
test_click(evenodd, point(15.0, 15.0) + margin, None);
|
||||
test_click(evenodd, point(5.0, 15.0) + margin, cursor(1));
|
||||
test_click(evenodd, point(15.0, 5.0) + margin, cursor(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jump_from_click_shapes_stroke() {
|
||||
let margin = point(10.0, 10.0);
|
||||
|
||||
let rect =
|
||||
"#place(dx: 10pt, dy: 10pt, rect(width: 10pt, height: 10pt, stroke: 5pt))";
|
||||
test_click(rect, point(15.0, 15.0) + margin, None);
|
||||
test_click(rect, point(10.0, 15.0) + margin, cursor(27));
|
||||
|
||||
test_click(
|
||||
"#line(angle: 45deg, length: 10pt, stroke: 2pt)",
|
||||
point(2.0, 2.0) + margin,
|
||||
cursor(1),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jump_from_cursor() {
|
||||
let s = "*Hello* #box[ABC] World";
|
||||
@ -399,20 +268,6 @@ mod tests {
|
||||
test_cursor(s, 14, pos(1, 37.55, 16.58));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jump_from_cursor_math() {
|
||||
test_cursor("$a + b$", -3, pos(1, 27.51, 16.83));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jump_from_cursor_transform() {
|
||||
test_cursor(
|
||||
r#"#rotate(90deg, origin: bottom + left, [hello world])"#,
|
||||
-5,
|
||||
pos(1, 10.0, 16.58),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backlink() {
|
||||
let s = "#footnote[Hi]";
|
||||
|
@ -232,9 +232,7 @@ pub fn deref_target(node: LinkedNode) -> Option<DerefTarget<'_>> {
|
||||
ast::Expr::FuncCall(call) => {
|
||||
DerefTarget::Callee(expr_node.find(call.callee().span())?)
|
||||
}
|
||||
ast::Expr::SetRule(set) => {
|
||||
DerefTarget::Callee(expr_node.find(set.target().span())?)
|
||||
}
|
||||
ast::Expr::Set(set) => DerefTarget::Callee(expr_node.find(set.target().span())?),
|
||||
ast::Expr::Ident(_) | ast::Expr::MathIdent(_) | ast::Expr::FieldAccess(_) => {
|
||||
DerefTarget::VarAccess(expr_node)
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ impl World for TestWorld {
|
||||
}
|
||||
|
||||
fn font(&self, index: usize) -> Option<Font> {
|
||||
self.base.fonts.get(index).cloned()
|
||||
Some(self.base.fonts[index].clone())
|
||||
}
|
||||
|
||||
fn today(&self, _: Option<i64>) -> Option<Datetime> {
|
||||
|
@ -201,7 +201,7 @@ fn named_param_tooltip(world: &dyn IdeWorld, leaf: &LinkedNode) -> Option<Toolti
|
||||
if let Some(expr) = grand_grand.cast::<ast::Expr>();
|
||||
if let Some(ast::Expr::Ident(callee)) = match expr {
|
||||
ast::Expr::FuncCall(call) => Some(call.callee()),
|
||||
ast::Expr::SetRule(set) => Some(set.target()),
|
||||
ast::Expr::Set(set) => Some(set.target()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -19,13 +19,10 @@ typst-utils = { workspace = true }
|
||||
dirs = { workspace = true, optional = true }
|
||||
ecow = { workspace = true }
|
||||
env_proxy = { workspace = true, optional = true }
|
||||
fastrand = { workspace = true, optional = true }
|
||||
flate2 = { workspace = true, optional = true }
|
||||
fontdb = { workspace = true, optional = true }
|
||||
native-tls = { workspace = true, optional = true }
|
||||
once_cell = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tar = { workspace = true, optional = true }
|
||||
ureq = { workspace = true, optional = true }
|
||||
|
||||
@ -44,7 +41,7 @@ fonts = ["dep:fontdb", "fontdb/memmap", "fontdb/fontconfig"]
|
||||
downloads = ["dep:env_proxy", "dep:native-tls", "dep:ureq", "dep:openssl"]
|
||||
|
||||
# Add package downloading utilities, implies `downloads`
|
||||
packages = ["downloads", "dep:dirs", "dep:flate2", "dep:tar", "dep:fastrand"]
|
||||
packages = ["downloads", "dep:dirs", "dep:flate2", "dep:tar"]
|
||||
|
||||
# Embeds some fonts into the binary:
|
||||
# - For text: Libertinus Serif, New Computer Modern
|
||||
|
@ -1,14 +1,14 @@
|
||||
//! Download and unpack packages and package indices.
|
||||
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use ecow::eco_format;
|
||||
use once_cell::sync::OnceCell;
|
||||
use serde::Deserialize;
|
||||
use typst_library::diag::{bail, PackageError, PackageResult, StrResult};
|
||||
use typst_syntax::package::{PackageSpec, PackageVersion, VersionlessPackageSpec};
|
||||
use typst_syntax::package::{
|
||||
PackageInfo, PackageSpec, PackageVersion, VersionlessPackageSpec,
|
||||
};
|
||||
|
||||
use crate::download::{Downloader, Progress};
|
||||
|
||||
@ -32,7 +32,7 @@ pub struct PackageStorage {
|
||||
/// The downloader used for fetching the index and packages.
|
||||
downloader: Downloader,
|
||||
/// The cached index of the default namespace.
|
||||
index: OnceCell<Vec<serde_json::Value>>,
|
||||
index: OnceCell<Vec<PackageInfo>>,
|
||||
}
|
||||
|
||||
impl PackageStorage {
|
||||
@ -42,18 +42,6 @@ impl PackageStorage {
|
||||
package_cache_path: Option<PathBuf>,
|
||||
package_path: Option<PathBuf>,
|
||||
downloader: Downloader,
|
||||
) -> Self {
|
||||
Self::with_index(package_cache_path, package_path, downloader, OnceCell::new())
|
||||
}
|
||||
|
||||
/// Creates a new package storage with a pre-defined index.
|
||||
///
|
||||
/// Useful for testing.
|
||||
fn with_index(
|
||||
package_cache_path: Option<PathBuf>,
|
||||
package_path: Option<PathBuf>,
|
||||
downloader: Downloader,
|
||||
index: OnceCell<Vec<serde_json::Value>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
package_cache_path: package_cache_path.or_else(|| {
|
||||
@ -63,7 +51,7 @@ impl PackageStorage {
|
||||
dirs::data_dir().map(|data_dir| data_dir.join(DEFAULT_PACKAGES_SUBDIR))
|
||||
}),
|
||||
downloader,
|
||||
index,
|
||||
index: OnceCell::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,8 +66,7 @@ impl PackageStorage {
|
||||
self.package_path.as_deref()
|
||||
}
|
||||
|
||||
/// Makes a package available on-disk and returns the path at which it is
|
||||
/// located (will be either in the cache or package directory).
|
||||
/// Make a package available in the on-disk.
|
||||
pub fn prepare_package(
|
||||
&self,
|
||||
spec: &PackageSpec,
|
||||
@ -102,7 +89,7 @@ impl PackageStorage {
|
||||
|
||||
// Download from network if it doesn't exist yet.
|
||||
if spec.namespace == DEFAULT_NAMESPACE {
|
||||
self.download_package(spec, cache_dir, progress)?;
|
||||
self.download_package(spec, &dir, progress)?;
|
||||
if dir.exists() {
|
||||
return Ok(dir);
|
||||
}
|
||||
@ -112,7 +99,7 @@ impl PackageStorage {
|
||||
Err(PackageError::NotFound(spec.clone()))
|
||||
}
|
||||
|
||||
/// Tries to determine the latest version of a package.
|
||||
/// Try to determine the latest version of a package.
|
||||
pub fn determine_latest_version(
|
||||
&self,
|
||||
spec: &VersionlessPackageSpec,
|
||||
@ -122,7 +109,6 @@ impl PackageStorage {
|
||||
// version.
|
||||
self.download_index()?
|
||||
.iter()
|
||||
.filter_map(|value| MinimalPackageInfo::deserialize(value).ok())
|
||||
.filter(|package| package.name == spec.name)
|
||||
.map(|package| package.version)
|
||||
.max()
|
||||
@ -145,7 +131,7 @@ impl PackageStorage {
|
||||
}
|
||||
|
||||
/// Download the package index. The result of this is cached for efficiency.
|
||||
fn download_index(&self) -> StrResult<&[serde_json::Value]> {
|
||||
pub fn download_index(&self) -> StrResult<&[PackageInfo]> {
|
||||
self.index
|
||||
.get_or_try_init(|| {
|
||||
let url = format!("{DEFAULT_REGISTRY}/{DEFAULT_NAMESPACE}/index.json");
|
||||
@ -166,10 +152,10 @@ impl PackageStorage {
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if the package spec namespace isn't `DEFAULT_NAMESPACE`.
|
||||
fn download_package(
|
||||
pub fn download_package(
|
||||
&self,
|
||||
spec: &PackageSpec,
|
||||
cache_dir: &Path,
|
||||
package_dir: &Path,
|
||||
progress: &mut dyn Progress,
|
||||
) -> PackageResult<()> {
|
||||
assert_eq!(spec.namespace, DEFAULT_NAMESPACE);
|
||||
@ -193,132 +179,10 @@ impl PackageStorage {
|
||||
}
|
||||
};
|
||||
|
||||
// The directory in which the package's version lives.
|
||||
let base_dir = cache_dir.join(format!("{}/{}", spec.namespace, spec.name));
|
||||
|
||||
// The place at which the specific package version will live in the end.
|
||||
let package_dir = base_dir.join(format!("{}", spec.version));
|
||||
|
||||
// To prevent multiple Typst instances from interferring, we download
|
||||
// into a temporary directory first and then move this directory to
|
||||
// its final destination.
|
||||
//
|
||||
// In the `rename` function's documentation it is stated:
|
||||
// > This will not work if the new name is on a different mount point.
|
||||
//
|
||||
// By locating the temporary directory directly next to where the
|
||||
// package directory will live, we are (trying our best) making sure
|
||||
// that `tempdir` and `package_dir` are on the same mount point.
|
||||
let tempdir = Tempdir::create(base_dir.join(format!(
|
||||
".tmp-{}-{}",
|
||||
spec.version,
|
||||
fastrand::u32(..),
|
||||
)))
|
||||
.map_err(|err| error("failed to create temporary package directory", err))?;
|
||||
|
||||
// Decompress the archive into the temporary directory.
|
||||
let decompressed = flate2::read::GzDecoder::new(data.as_slice());
|
||||
tar::Archive::new(decompressed)
|
||||
.unpack(&tempdir)
|
||||
.map_err(|err| PackageError::MalformedArchive(Some(eco_format!("{err}"))))?;
|
||||
|
||||
// When trying to move (i.e., `rename`) the directory from one place to
|
||||
// another and the target/destination directory is empty, then the
|
||||
// operation will succeed (if it's atomic, or hardware doesn't fail, or
|
||||
// power doesn't go off, etc.). If however the target directory is not
|
||||
// empty, i.e., another instance already successfully moved the package,
|
||||
// then we can safely ignore the `DirectoryNotEmpty` error.
|
||||
//
|
||||
// This means that we do not check the integrity of an existing moved
|
||||
// package, just like we don't check the integrity if the package
|
||||
// directory already existed in the first place. If situations with
|
||||
// broken packages still occur even with the rename safeguard, we might
|
||||
// consider more complex solutions like file locking or checksums.
|
||||
match fs::rename(&tempdir, &package_dir) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(err) if err.kind() == io::ErrorKind::DirectoryNotEmpty => Ok(()),
|
||||
Err(err) => Err(error("failed to move downloaded package directory", err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Minimal information required about a package to determine its latest
|
||||
/// version.
|
||||
#[derive(Deserialize)]
|
||||
struct MinimalPackageInfo {
|
||||
name: String,
|
||||
version: PackageVersion,
|
||||
}
|
||||
|
||||
/// A temporary directory that is a automatically cleaned up.
|
||||
struct Tempdir(PathBuf);
|
||||
|
||||
impl Tempdir {
|
||||
/// Creates a directory at the path and auto-cleans it.
|
||||
fn create(path: PathBuf) -> io::Result<Self> {
|
||||
std::fs::create_dir_all(&path)?;
|
||||
Ok(Self(path))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Tempdir {
|
||||
fn drop(&mut self) {
|
||||
_ = fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Path> for Tempdir {
|
||||
fn as_ref(&self) -> &Path {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Enriches an I/O error with a message and turns it into a
|
||||
/// `PackageError::Other`.
|
||||
#[cold]
|
||||
fn error(message: &str, err: io::Error) -> PackageError {
|
||||
PackageError::Other(Some(eco_format!("{message}: {err}")))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn lazy_deser_index() {
|
||||
let storage = PackageStorage::with_index(
|
||||
None,
|
||||
None,
|
||||
Downloader::new("typst/test"),
|
||||
OnceCell::with_value(vec![
|
||||
serde_json::json!({
|
||||
"name": "charged-ieee",
|
||||
"version": "0.1.0",
|
||||
"entrypoint": "lib.typ",
|
||||
}),
|
||||
serde_json::json!({
|
||||
"name": "unequivocal-ams",
|
||||
// This version number is currently not valid, so this package
|
||||
// can't be parsed.
|
||||
"version": "0.2.0-dev",
|
||||
"entrypoint": "lib.typ",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
let ieee_version = storage.determine_latest_version(&VersionlessPackageSpec {
|
||||
namespace: "preview".into(),
|
||||
name: "charged-ieee".into(),
|
||||
});
|
||||
assert_eq!(ieee_version, Ok(PackageVersion { major: 0, minor: 1, patch: 0 }));
|
||||
|
||||
let ams_version = storage.determine_latest_version(&VersionlessPackageSpec {
|
||||
namespace: "preview".into(),
|
||||
name: "unequivocal-ams".into(),
|
||||
});
|
||||
assert_eq!(
|
||||
ams_version,
|
||||
Err("failed to find package @preview/unequivocal-ams".into())
|
||||
)
|
||||
tar::Archive::new(decompressed).unpack(package_dir).map_err(|err| {
|
||||
fs::remove_dir_all(package_dir).ok();
|
||||
PackageError::MalformedArchive(Some(eco_format!("{err}")))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +124,7 @@ impl<'a> Collector<'a, '_, '_> {
|
||||
styles,
|
||||
self.base,
|
||||
self.expand,
|
||||
None,
|
||||
)?
|
||||
.into_frames();
|
||||
|
||||
@ -132,8 +133,7 @@ impl<'a> Collector<'a, '_, '_> {
|
||||
self.output.push(Child::Tag(&elem.tag));
|
||||
}
|
||||
|
||||
let leading = ParElem::leading_in(styles);
|
||||
self.lines(lines, leading, styles);
|
||||
self.lines(lines, styles);
|
||||
|
||||
for (c, _) in &self.children[end..] {
|
||||
let elem = c.to_packed::<TagElem>().unwrap();
|
||||
@ -169,12 +169,10 @@ impl<'a> Collector<'a, '_, '_> {
|
||||
)?
|
||||
.into_frames();
|
||||
|
||||
let spacing = elem.spacing(styles);
|
||||
let leading = elem.leading(styles);
|
||||
|
||||
let spacing = ParElem::spacing_in(styles);
|
||||
self.output.push(Child::Rel(spacing.into(), 4));
|
||||
|
||||
self.lines(lines, leading, styles);
|
||||
self.lines(lines, styles);
|
||||
|
||||
self.output.push(Child::Rel(spacing.into(), 4));
|
||||
self.par_situation = ParSituation::Consecutive;
|
||||
@ -183,8 +181,9 @@ impl<'a> Collector<'a, '_, '_> {
|
||||
}
|
||||
|
||||
/// Collect laid-out lines.
|
||||
fn lines(&mut self, lines: Vec<Frame>, leading: Abs, styles: StyleChain<'a>) {
|
||||
fn lines(&mut self, lines: Vec<Frame>, styles: StyleChain<'a>) {
|
||||
let align = AlignElem::alignment_in(styles).resolve(styles);
|
||||
let leading = ParElem::leading_in(styles);
|
||||
let costs = TextElem::costs_in(styles);
|
||||
|
||||
// Determine whether to prevent widow and orphans.
|
||||
|
@ -115,7 +115,7 @@ impl<'a, 'b> Composer<'a, 'b, '_, '_> {
|
||||
let column_height = regions.size.y;
|
||||
let backlog: Vec<_> = std::iter::once(&column_height)
|
||||
.chain(regions.backlog)
|
||||
.flat_map(|&h| std::iter::repeat_n(h, self.config.columns.count))
|
||||
.flat_map(|&h| std::iter::repeat(h).take(self.config.columns.count))
|
||||
.skip(1)
|
||||
.collect();
|
||||
|
||||
|
@ -197,50 +197,7 @@ pub fn layout_flow<'a>(
|
||||
mode: FlowMode,
|
||||
) -> SourceResult<Fragment> {
|
||||
// Prepare configuration that is shared across the whole flow.
|
||||
let config = configuration(shared, regions, columns, column_gutter, mode);
|
||||
|
||||
// Collect the elements into pre-processed children. These are much easier
|
||||
// to handle than the raw elements.
|
||||
let bump = Bump::new();
|
||||
let children = collect(
|
||||
engine,
|
||||
&bump,
|
||||
children,
|
||||
locator.next(&()),
|
||||
Size::new(config.columns.width, regions.full),
|
||||
regions.expand.x,
|
||||
mode,
|
||||
)?;
|
||||
|
||||
let mut work = Work::new(&children);
|
||||
let mut finished = vec![];
|
||||
|
||||
// This loop runs once per region produced by the flow layout.
|
||||
loop {
|
||||
let frame = compose(engine, &mut work, &config, locator.next(&()), regions)?;
|
||||
finished.push(frame);
|
||||
|
||||
// Terminate the loop when everything is processed, though draining the
|
||||
// backlog if necessary.
|
||||
if work.done() && (!regions.expand.y || regions.backlog.is_empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
regions.next();
|
||||
}
|
||||
|
||||
Ok(Fragment::frames(finished))
|
||||
}
|
||||
|
||||
/// Determine the flow's configuration.
|
||||
fn configuration<'x>(
|
||||
shared: StyleChain<'x>,
|
||||
regions: Regions,
|
||||
columns: NonZeroUsize,
|
||||
column_gutter: Rel<Abs>,
|
||||
mode: FlowMode,
|
||||
) -> Config<'x> {
|
||||
Config {
|
||||
let config = Config {
|
||||
mode,
|
||||
shared,
|
||||
columns: {
|
||||
@ -278,7 +235,39 @@ fn configuration<'x>(
|
||||
)
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
// Collect the elements into pre-processed children. These are much easier
|
||||
// to handle than the raw elements.
|
||||
let bump = Bump::new();
|
||||
let children = collect(
|
||||
engine,
|
||||
&bump,
|
||||
children,
|
||||
locator.next(&()),
|
||||
Size::new(config.columns.width, regions.full),
|
||||
regions.expand.x,
|
||||
mode,
|
||||
)?;
|
||||
|
||||
let mut work = Work::new(&children);
|
||||
let mut finished = vec![];
|
||||
|
||||
// This loop runs once per region produced by the flow layout.
|
||||
loop {
|
||||
let frame = compose(engine, &mut work, &config, locator.next(&()), regions)?;
|
||||
finished.push(frame);
|
||||
|
||||
// Terminate the loop when everything is processed, though draining the
|
||||
// backlog if necessary.
|
||||
if work.done() && (!regions.expand.y || regions.backlog.is_empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
regions.next();
|
||||
}
|
||||
|
||||
Ok(Fragment::frames(finished))
|
||||
}
|
||||
|
||||
/// The work that is left to do by flow layout.
|
||||
|
@ -11,7 +11,7 @@ use typst_library::layout::{
|
||||
use typst_library::text::TextElem;
|
||||
use typst_library::visualize::Geometry;
|
||||
use typst_syntax::Span;
|
||||
use typst_utils::Numeric;
|
||||
use typst_utils::{MaybeReverseIter, Numeric};
|
||||
|
||||
use super::{
|
||||
generate_line_segments, hline_stroke_at_column, layout_cell, vline_stroke_at_row,
|
||||
@ -574,7 +574,7 @@ impl<'a> GridLayouter<'a> {
|
||||
|
||||
// Reverse with RTL so that later columns start first.
|
||||
let mut dx = Abs::zero();
|
||||
for (x, &col) in self.rcols.iter().enumerate() {
|
||||
for (x, &col) in self.rcols.iter().enumerate().rev_if(self.is_rtl) {
|
||||
let mut dy = Abs::zero();
|
||||
for row in rows {
|
||||
// We want to only draw the fill starting at the parent
|
||||
@ -643,13 +643,18 @@ impl<'a> GridLayouter<'a> {
|
||||
.sum()
|
||||
};
|
||||
let width = self.cell_spanned_width(cell, x);
|
||||
let mut pos = Point::new(dx, dy);
|
||||
if self.is_rtl {
|
||||
// In RTL cells expand to the left, thus the
|
||||
// position must additionally be offset by the
|
||||
// cell's width.
|
||||
pos.x = self.width - (dx + width);
|
||||
}
|
||||
// In the grid, cell colspans expand to the right,
|
||||
// so we're at the leftmost (lowest 'x') column
|
||||
// spanned by the cell. However, in RTL, cells
|
||||
// expand to the left. Therefore, without the
|
||||
// offset below, cell fills would start at the
|
||||
// rightmost visual position of a cell and extend
|
||||
// over to unrelated columns to the right in RTL.
|
||||
// We avoid this by ensuring the fill starts at the
|
||||
// very left of the cell, even with colspan > 1.
|
||||
let offset =
|
||||
if self.is_rtl { -width + col } else { Abs::zero() };
|
||||
let pos = Point::new(dx + offset, dy);
|
||||
let size = Size::new(width, height);
|
||||
let rect = Geometry::Rect(size).filled(fill);
|
||||
fills.push((pos, FrameItem::Shape(rect, self.span)));
|
||||
@ -1231,9 +1236,10 @@ impl<'a> GridLayouter<'a> {
|
||||
}
|
||||
|
||||
let mut output = Frame::soft(Size::new(self.width, height));
|
||||
let mut offset = Point::zero();
|
||||
let mut pos = Point::zero();
|
||||
|
||||
for (x, &rcol) in self.rcols.iter().enumerate() {
|
||||
// Reverse the column order when using RTL.
|
||||
for (x, &rcol) in self.rcols.iter().enumerate().rev_if(self.is_rtl) {
|
||||
if let Some(cell) = self.grid.cell(x, y) {
|
||||
// Rowspans have a separate layout step
|
||||
if cell.rowspan.get() == 1 {
|
||||
@ -1251,17 +1257,25 @@ impl<'a> GridLayouter<'a> {
|
||||
let frame =
|
||||
layout_cell(cell, engine, disambiguator, self.styles, pod)?
|
||||
.into_frame();
|
||||
let mut pos = offset;
|
||||
let mut pos = pos;
|
||||
if self.is_rtl {
|
||||
// In RTL cells expand to the left, thus the position
|
||||
// must additionally be offset by the cell's width.
|
||||
pos.x = self.width - (pos.x + width);
|
||||
// In the grid, cell colspans expand to the right,
|
||||
// so we're at the leftmost (lowest 'x') column
|
||||
// spanned by the cell. However, in RTL, cells
|
||||
// expand to the left. Therefore, without the
|
||||
// offset below, the cell's contents would be laid out
|
||||
// starting at its rightmost visual position and extend
|
||||
// over to unrelated cells to its right in RTL.
|
||||
// We avoid this by ensuring the rendered cell starts at
|
||||
// the very left of the cell, even with colspan > 1.
|
||||
let offset = -width + rcol;
|
||||
pos.x += offset;
|
||||
}
|
||||
output.push_frame(pos, frame);
|
||||
}
|
||||
}
|
||||
|
||||
offset.x += rcol;
|
||||
pos.x += rcol;
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
@ -1288,8 +1302,8 @@ impl<'a> GridLayouter<'a> {
|
||||
pod.backlog = &heights[1..];
|
||||
|
||||
// Layout the row.
|
||||
let mut offset = Point::zero();
|
||||
for (x, &rcol) in self.rcols.iter().enumerate() {
|
||||
let mut pos = Point::zero();
|
||||
for (x, &rcol) in self.rcols.iter().enumerate().rev_if(self.is_rtl) {
|
||||
if let Some(cell) = self.grid.cell(x, y) {
|
||||
// Rowspans have a separate layout step
|
||||
if cell.rowspan.get() == 1 {
|
||||
@ -1300,19 +1314,17 @@ impl<'a> GridLayouter<'a> {
|
||||
let fragment =
|
||||
layout_cell(cell, engine, disambiguator, self.styles, pod)?;
|
||||
for (output, frame) in outputs.iter_mut().zip(fragment) {
|
||||
let mut pos = offset;
|
||||
let mut pos = pos;
|
||||
if self.is_rtl {
|
||||
// In RTL cells expand to the left, thus the
|
||||
// position must additionally be offset by the
|
||||
// cell's width.
|
||||
pos.x = self.width - (offset.x + width);
|
||||
let offset = -width + rcol;
|
||||
pos.x += offset;
|
||||
}
|
||||
output.push_frame(pos, frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
offset.x += rcol;
|
||||
pos.x += rcol;
|
||||
}
|
||||
|
||||
Ok(Fragment::frames(outputs))
|
||||
@ -1365,7 +1377,7 @@ impl<'a> GridLayouter<'a> {
|
||||
.footer
|
||||
.as_ref()
|
||||
.and_then(Repeatable::as_repeated)
|
||||
.is_none_or(|footer| footer.start != header.end)
|
||||
.map_or(true, |footer| footer.start != header.end)
|
||||
&& self.lrows.last().is_some_and(|row| row.index() < header.end)
|
||||
&& !in_last_with_offset(
|
||||
self.regions,
|
||||
@ -1434,7 +1446,7 @@ impl<'a> GridLayouter<'a> {
|
||||
.iter_mut()
|
||||
.filter(|rowspan| (rowspan.y..rowspan.y + rowspan.rowspan).contains(&y))
|
||||
.filter(|rowspan| {
|
||||
rowspan.max_resolved_row.is_none_or(|max_row| y > max_row)
|
||||
rowspan.max_resolved_row.map_or(true, |max_row| y > max_row)
|
||||
})
|
||||
{
|
||||
// If the first region wasn't defined yet, it will have the
|
||||
@ -1457,7 +1469,7 @@ impl<'a> GridLayouter<'a> {
|
||||
// last height is the one for the current region.
|
||||
rowspan
|
||||
.heights
|
||||
.extend(std::iter::repeat_n(Abs::zero(), amount_missing_heights));
|
||||
.extend(std::iter::repeat(Abs::zero()).take(amount_missing_heights));
|
||||
|
||||
// Ensure that, in this region, the rowspan will span at least
|
||||
// this row.
|
||||
@ -1482,7 +1494,7 @@ impl<'a> GridLayouter<'a> {
|
||||
// laid out at the first frame of the row).
|
||||
// Any rowspans ending before this row are laid out even
|
||||
// on this row's first frame.
|
||||
if laid_out_footer_start.is_none_or(|footer_start| {
|
||||
if laid_out_footer_start.map_or(true, |footer_start| {
|
||||
// If this is a footer row, then only lay out this rowspan
|
||||
// if the rowspan is contained within the footer.
|
||||
y < footer_start || rowspan.y >= footer_start
|
||||
@ -1568,5 +1580,5 @@ pub(super) fn points(
|
||||
/// our case, headers).
|
||||
pub(super) fn in_last_with_offset(regions: Regions<'_>, offset: Abs) -> bool {
|
||||
regions.backlog.is_empty()
|
||||
&& regions.last.is_none_or(|height| regions.size.y + offset == height)
|
||||
&& regions.last.map_or(true, |height| regions.size.y + offset == height)
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ pub fn hline_stroke_at_column(
|
||||
// region, we have the last index, and (as a failsafe) we don't have the
|
||||
// last row of cells above us.
|
||||
let use_bottom_border_stroke = !in_last_region
|
||||
&& local_top_y.is_none_or(|top_y| top_y + 1 != grid.rows.len())
|
||||
&& local_top_y.map_or(true, |top_y| top_y + 1 != grid.rows.len())
|
||||
&& y == grid.rows.len();
|
||||
let bottom_y =
|
||||
if use_bottom_border_stroke { grid.rows.len().saturating_sub(1) } else { y };
|
||||
|
@ -3,6 +3,7 @@ use typst_library::engine::Engine;
|
||||
use typst_library::foundations::Resolve;
|
||||
use typst_library::layout::grid::resolve::Repeatable;
|
||||
use typst_library::layout::{Abs, Axes, Frame, Point, Region, Regions, Size, Sizing};
|
||||
use typst_utils::MaybeReverseIter;
|
||||
|
||||
use super::layouter::{in_last_with_offset, points, Row, RowPiece};
|
||||
use super::{layout_cell, Cell, GridLayouter};
|
||||
@ -22,10 +23,6 @@ pub struct Rowspan {
|
||||
/// specified for the parent cell's `breakable` field.
|
||||
pub is_effectively_unbreakable: bool,
|
||||
/// The horizontal offset of this rowspan in all regions.
|
||||
///
|
||||
/// This is the offset from the text direction start, meaning that, on RTL
|
||||
/// grids, this is the offset from the right of the grid, whereas, on LTR
|
||||
/// grids, it is the offset from the left.
|
||||
pub dx: Abs,
|
||||
/// The vertical offset of this rowspan in the first region.
|
||||
pub dy: Abs,
|
||||
@ -121,11 +118,10 @@ impl GridLayouter<'_> {
|
||||
// Nothing to layout.
|
||||
return Ok(());
|
||||
};
|
||||
let first_column = self.rcols[x];
|
||||
let cell = self.grid.cell(x, y).unwrap();
|
||||
let width = self.cell_spanned_width(cell, x);
|
||||
// In RTL cells expand to the left, thus the position
|
||||
// must additionally be offset by the cell's width.
|
||||
let dx = if self.is_rtl { self.width - (dx + width) } else { dx };
|
||||
let dx = if self.is_rtl { dx - width + first_column } else { dx };
|
||||
|
||||
// Prepare regions.
|
||||
let size = Size::new(width, *first_height);
|
||||
@ -189,8 +185,10 @@ impl GridLayouter<'_> {
|
||||
/// Checks if a row contains the beginning of one or more rowspan cells.
|
||||
/// If so, adds them to the rowspans vector.
|
||||
pub fn check_for_rowspans(&mut self, disambiguator: usize, y: usize) {
|
||||
let offsets = points(self.rcols.iter().copied());
|
||||
for (x, dx) in (0..self.rcols.len()).zip(offsets) {
|
||||
// We will compute the horizontal offset of each rowspan in advance.
|
||||
// For that reason, we must reverse the column order when using RTL.
|
||||
let offsets = points(self.rcols.iter().copied().rev_if(self.is_rtl));
|
||||
for (x, dx) in (0..self.rcols.len()).rev_if(self.is_rtl).zip(offsets) {
|
||||
let Some(cell) = self.grid.cell(x, y) else {
|
||||
continue;
|
||||
};
|
||||
@ -590,7 +588,7 @@ impl GridLayouter<'_> {
|
||||
measurement_data: &CellMeasurementData<'_>,
|
||||
) -> bool {
|
||||
if sizes.len() <= 1
|
||||
&& sizes.first().is_none_or(|&first_frame_size| {
|
||||
&& sizes.first().map_or(true, |&first_frame_size| {
|
||||
first_frame_size <= measurement_data.height_in_this_region
|
||||
})
|
||||
{
|
||||
|
@ -95,8 +95,6 @@ pub fn layout_image(
|
||||
} else {
|
||||
// If neither is forced, take the natural image size at the image's
|
||||
// DPI bounded by the available space.
|
||||
//
|
||||
// Division by DPI is fine since it's guaranteed to be positive.
|
||||
let dpi = image.dpi().unwrap_or(Image::DEFAULT_DPI);
|
||||
let natural = Axes::new(pxw, pxh).map(|v| Abs::inches(v / dpi));
|
||||
Size::new(
|
||||
|
@ -2,8 +2,10 @@ use typst_library::diag::warning;
|
||||
use typst_library::foundations::{Packed, Resolve};
|
||||
use typst_library::introspection::{SplitLocator, Tag, TagElem};
|
||||
use typst_library::layout::{
|
||||
Abs, BoxElem, Dir, Fr, Frame, HElem, InlineElem, InlineItem, Sizing, Spacing,
|
||||
Abs, AlignElem, BoxElem, Dir, Fr, Frame, HElem, InlineElem, InlineItem, Sizing,
|
||||
Spacing,
|
||||
};
|
||||
use typst_library::model::{EnumElem, ListElem, TermsElem};
|
||||
use typst_library::routines::Pair;
|
||||
use typst_library::text::{
|
||||
is_default_ignorable, LinebreakElem, SmartQuoteElem, SmartQuoter, SmartQuotes,
|
||||
@ -121,20 +123,40 @@ pub fn collect<'a>(
|
||||
children: &[Pair<'a>],
|
||||
engine: &mut Engine<'_>,
|
||||
locator: &mut SplitLocator<'a>,
|
||||
config: &Config,
|
||||
styles: StyleChain<'a>,
|
||||
region: Size,
|
||||
situation: Option<ParSituation>,
|
||||
) -> SourceResult<(String, Vec<Segment<'a>>, SpanMapper)> {
|
||||
let mut collector = Collector::new(2 + children.len());
|
||||
let mut quoter = SmartQuoter::new();
|
||||
|
||||
if !config.first_line_indent.is_zero() {
|
||||
collector.push_item(Item::Absolute(config.first_line_indent, false));
|
||||
collector.spans.push(1, Span::detached());
|
||||
}
|
||||
let outer_dir = TextElem::dir_in(styles);
|
||||
|
||||
if !config.hanging_indent.is_zero() {
|
||||
collector.push_item(Item::Absolute(-config.hanging_indent, false));
|
||||
collector.spans.push(1, Span::detached());
|
||||
if let Some(situation) = situation {
|
||||
let first_line_indent = ParElem::first_line_indent_in(styles);
|
||||
if !first_line_indent.amount.is_zero()
|
||||
&& match situation {
|
||||
// First-line indent for the first paragraph after a list bullet
|
||||
// just looks bad.
|
||||
ParSituation::First => first_line_indent.all && !in_list(styles),
|
||||
ParSituation::Consecutive => true,
|
||||
ParSituation::Other => first_line_indent.all,
|
||||
}
|
||||
&& AlignElem::alignment_in(styles).resolve(styles).x
|
||||
== outer_dir.start().into()
|
||||
{
|
||||
collector.push_item(Item::Absolute(
|
||||
first_line_indent.amount.resolve(styles),
|
||||
false,
|
||||
));
|
||||
collector.spans.push(1, Span::detached());
|
||||
}
|
||||
|
||||
let hang = ParElem::hanging_indent_in(styles);
|
||||
if !hang.is_zero() {
|
||||
collector.push_item(Item::Absolute(-hang, false));
|
||||
collector.spans.push(1, Span::detached());
|
||||
}
|
||||
}
|
||||
|
||||
for &(child, styles) in children {
|
||||
@ -145,7 +167,7 @@ pub fn collect<'a>(
|
||||
} else if let Some(elem) = child.to_packed::<TextElem>() {
|
||||
collector.build_text(styles, |full| {
|
||||
let dir = TextElem::dir_in(styles);
|
||||
if dir != config.dir {
|
||||
if dir != outer_dir {
|
||||
// Insert "Explicit Directional Embedding".
|
||||
match dir {
|
||||
Dir::LTR => full.push_str(LTR_EMBEDDING),
|
||||
@ -160,7 +182,7 @@ pub fn collect<'a>(
|
||||
full.push_str(&elem.text);
|
||||
}
|
||||
|
||||
if dir != config.dir {
|
||||
if dir != outer_dir {
|
||||
// Insert "Pop Directional Formatting".
|
||||
full.push_str(POP_EMBEDDING);
|
||||
}
|
||||
@ -243,6 +265,16 @@ pub fn collect<'a>(
|
||||
Ok((collector.full, collector.segments, collector.spans))
|
||||
}
|
||||
|
||||
/// Whether we have a list ancestor.
|
||||
///
|
||||
/// When we support some kind of more general ancestry mechanism, this can
|
||||
/// become more elegant.
|
||||
fn in_list(styles: StyleChain) -> bool {
|
||||
ListElem::depth_in(styles).0 > 0
|
||||
|| !EnumElem::parents_in(styles).is_empty()
|
||||
|| TermsElem::within_in(styles)
|
||||
}
|
||||
|
||||
/// Collects segments.
|
||||
struct Collector<'a> {
|
||||
full: String,
|
||||
|
@ -9,6 +9,7 @@ pub fn finalize(
|
||||
engine: &mut Engine,
|
||||
p: &Preparation,
|
||||
lines: &[Line],
|
||||
styles: StyleChain,
|
||||
region: Size,
|
||||
expand: bool,
|
||||
locator: &mut SplitLocator<'_>,
|
||||
@ -18,10 +19,9 @@ pub fn finalize(
|
||||
let width = if !region.x.is_finite()
|
||||
|| (!expand && lines.iter().all(|line| line.fr().is_zero()))
|
||||
{
|
||||
region.x.min(
|
||||
p.config.hanging_indent
|
||||
+ lines.iter().map(|line| line.width).max().unwrap_or_default(),
|
||||
)
|
||||
region
|
||||
.x
|
||||
.min(p.hang + lines.iter().map(|line| line.width).max().unwrap_or_default())
|
||||
} else {
|
||||
region.x
|
||||
};
|
||||
@ -29,7 +29,7 @@ pub fn finalize(
|
||||
// Stack the lines into one frame per region.
|
||||
lines
|
||||
.iter()
|
||||
.map(|line| commit(engine, p, line, width, region.y, locator))
|
||||
.map(|line| commit(engine, p, line, width, region.y, locator, styles))
|
||||
.collect::<SourceResult<_>>()
|
||||
.map(Fragment::frames)
|
||||
}
|
||||
|
@ -2,9 +2,10 @@ use std::fmt::{self, Debug, Formatter};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use typst_library::engine::Engine;
|
||||
use typst_library::foundations::NativeElement;
|
||||
use typst_library::introspection::{SplitLocator, Tag};
|
||||
use typst_library::layout::{Abs, Dir, Em, Fr, Frame, FrameItem, Point};
|
||||
use typst_library::model::ParLineMarker;
|
||||
use typst_library::model::{ParLine, ParLineMarker};
|
||||
use typst_library::text::{Lang, TextElem};
|
||||
use typst_utils::Numeric;
|
||||
|
||||
@ -134,7 +135,7 @@ pub fn line<'a>(
|
||||
|
||||
// Whether the line is justified.
|
||||
let justify = full.ends_with(LINE_SEPARATOR)
|
||||
|| (p.config.justify && breakpoint != Breakpoint::Mandatory);
|
||||
|| (p.justify && breakpoint != Breakpoint::Mandatory);
|
||||
|
||||
// Process dashes.
|
||||
let dash = if breakpoint.is_hyphen() || full.ends_with(SHY) {
|
||||
@ -154,16 +155,16 @@ pub fn line<'a>(
|
||||
let mut items = collect_items(engine, p, range, trim);
|
||||
|
||||
// Add a hyphen at the line start, if a previous dash should be repeated.
|
||||
if pred.is_some_and(|pred| should_repeat_hyphen(pred, full)) {
|
||||
if pred.map_or(false, |pred| should_repeat_hyphen(pred, full)) {
|
||||
if let Some(shaped) = items.first_text_mut() {
|
||||
shaped.prepend_hyphen(engine, p.config.fallback);
|
||||
shaped.prepend_hyphen(engine, p.fallback);
|
||||
}
|
||||
}
|
||||
|
||||
// Add a hyphen at the line end, if we ended on a soft hyphen.
|
||||
if dash == Some(Dash::Soft) {
|
||||
if let Some(shaped) = items.last_text_mut() {
|
||||
shaped.push_hyphen(engine, p.config.fallback);
|
||||
shaped.push_hyphen(engine, p.fallback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,13 +234,13 @@ where
|
||||
{
|
||||
// If there is nothing bidirectional going on, skip reordering.
|
||||
let Some(bidi) = &p.bidi else {
|
||||
f(range, p.config.dir == Dir::RTL);
|
||||
f(range, p.dir == Dir::RTL);
|
||||
return;
|
||||
};
|
||||
|
||||
// The bidi crate panics for empty lines.
|
||||
if range.is_empty() {
|
||||
f(range, p.config.dir == Dir::RTL);
|
||||
f(range, p.dir == Dir::RTL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -307,13 +308,13 @@ fn collect_range<'a>(
|
||||
/// punctuation marks at line start or line end.
|
||||
fn adjust_cj_at_line_boundaries(p: &Preparation, text: &str, items: &mut Items) {
|
||||
if text.starts_with(BEGIN_PUNCT_PAT)
|
||||
|| (p.config.cjk_latin_spacing && text.starts_with(is_of_cj_script))
|
||||
|| (p.cjk_latin_spacing && text.starts_with(is_of_cj_script))
|
||||
{
|
||||
adjust_cj_at_line_start(p, items);
|
||||
}
|
||||
|
||||
if text.ends_with(END_PUNCT_PAT)
|
||||
|| (p.config.cjk_latin_spacing && text.ends_with(is_of_cj_script))
|
||||
|| (p.cjk_latin_spacing && text.ends_with(is_of_cj_script))
|
||||
{
|
||||
adjust_cj_at_line_end(p, items);
|
||||
}
|
||||
@ -331,10 +332,7 @@ fn adjust_cj_at_line_start(p: &Preparation, items: &mut Items) {
|
||||
let shrink = glyph.shrinkability().0;
|
||||
glyph.shrink_left(shrink);
|
||||
shaped.width -= shrink.at(shaped.size);
|
||||
} else if p.config.cjk_latin_spacing
|
||||
&& glyph.is_cj_script()
|
||||
&& glyph.x_offset > Em::zero()
|
||||
{
|
||||
} else if p.cjk_latin_spacing && glyph.is_cj_script() && glyph.x_offset > Em::zero() {
|
||||
// If the first glyph is a CJK character adjusted by
|
||||
// [`add_cjk_latin_spacing`], restore the original width.
|
||||
let glyph = shaped.glyphs.to_mut().first_mut().unwrap();
|
||||
@ -361,7 +359,7 @@ fn adjust_cj_at_line_end(p: &Preparation, items: &mut Items) {
|
||||
let punct = shaped.glyphs.to_mut().last_mut().unwrap();
|
||||
punct.shrink_right(shrink);
|
||||
shaped.width -= shrink.at(shaped.size);
|
||||
} else if p.config.cjk_latin_spacing
|
||||
} else if p.cjk_latin_spacing
|
||||
&& glyph.is_cj_script()
|
||||
&& (glyph.x_advance - glyph.x_offset) > Em::one()
|
||||
{
|
||||
@ -406,7 +404,7 @@ fn should_repeat_hyphen(pred_line: &Line, text: &str) -> bool {
|
||||
//
|
||||
// See § 4.1.1.1.2.e on the "Ortografía de la lengua española"
|
||||
// https://www.rae.es/ortografía/como-signo-de-división-de-palabras-a-final-de-línea
|
||||
Lang::SPANISH => text.chars().next().is_some_and(|c| !c.is_uppercase()),
|
||||
Lang::SPANISH => text.chars().next().map_or(false, |c| !c.is_uppercase()),
|
||||
|
||||
_ => false,
|
||||
}
|
||||
@ -426,15 +424,16 @@ pub fn commit(
|
||||
width: Abs,
|
||||
full: Abs,
|
||||
locator: &mut SplitLocator<'_>,
|
||||
styles: StyleChain,
|
||||
) -> SourceResult<Frame> {
|
||||
let mut remaining = width - line.width - p.config.hanging_indent;
|
||||
let mut remaining = width - line.width - p.hang;
|
||||
let mut offset = Abs::zero();
|
||||
|
||||
// We always build the line from left to right. In an LTR paragraph, we must
|
||||
// thus add the hanging indent to the offset. In an RTL paragraph, the
|
||||
// hanging indent arises naturally due to the line width.
|
||||
if p.config.dir == Dir::LTR {
|
||||
offset += p.config.hanging_indent;
|
||||
if p.dir == Dir::LTR {
|
||||
offset += p.hang;
|
||||
}
|
||||
|
||||
// Handle hanging punctuation to the left.
|
||||
@ -555,13 +554,11 @@ pub fn commit(
|
||||
let mut output = Frame::soft(size);
|
||||
output.set_baseline(top);
|
||||
|
||||
if let Some(marker) = &p.config.numbering_marker {
|
||||
add_par_line_marker(&mut output, marker, engine, locator, top);
|
||||
}
|
||||
add_par_line_marker(&mut output, styles, engine, locator, top);
|
||||
|
||||
// Construct the line's frame.
|
||||
for (offset, frame) in frames {
|
||||
let x = offset + p.config.align.position(remaining);
|
||||
let x = offset + p.align.position(remaining);
|
||||
let y = top - frame.baseline();
|
||||
output.push_frame(Point::new(x, y), frame);
|
||||
}
|
||||
@ -578,18 +575,26 @@ pub fn commit(
|
||||
/// number in the margin, is aligned to the line's baseline.
|
||||
fn add_par_line_marker(
|
||||
output: &mut Frame,
|
||||
marker: &Packed<ParLineMarker>,
|
||||
styles: StyleChain,
|
||||
engine: &mut Engine,
|
||||
locator: &mut SplitLocator,
|
||||
top: Abs,
|
||||
) {
|
||||
let Some(numbering) = ParLine::numbering_in(styles) else { return };
|
||||
let margin = ParLine::number_margin_in(styles);
|
||||
let align = ParLine::number_align_in(styles);
|
||||
|
||||
// Delay resolving the number clearance until line numbers are laid out to
|
||||
// avoid inconsistent spacing depending on varying font size.
|
||||
let clearance = ParLine::number_clearance_in(styles);
|
||||
|
||||
// Elements in tags must have a location for introspection to work. We do
|
||||
// the work here instead of going through all of the realization process
|
||||
// just for this, given we don't need to actually place the marker as we
|
||||
// manually search for it in the frame later (when building a root flow,
|
||||
// where line numbers can be displayed), so we just need it to be in a tag
|
||||
// and to be valid (to have a location).
|
||||
let mut marker = marker.clone();
|
||||
let mut marker = ParLineMarker::new(numbering, align, margin, clearance).pack();
|
||||
let key = typst_utils::hash128(&marker);
|
||||
let loc = locator.next_location(engine.introspector, key);
|
||||
marker.set_location(loc);
|
||||
@ -601,7 +606,7 @@ fn add_par_line_marker(
|
||||
// line's general baseline. However, the line number will still need to
|
||||
// manually adjust its own 'y' position based on its own baseline.
|
||||
let pos = Point::with_y(top);
|
||||
output.push(pos, FrameItem::Tag(Tag::Start(marker.pack())));
|
||||
output.push(pos, FrameItem::Tag(Tag::Start(marker)));
|
||||
output.push(pos, FrameItem::Tag(Tag::End(loc, key)));
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,15 @@ pub fn linebreak<'a>(
|
||||
p: &'a Preparation<'a>,
|
||||
width: Abs,
|
||||
) -> Vec<Line<'a>> {
|
||||
match p.config.linebreaks {
|
||||
let linebreaks = p.linebreaks.unwrap_or_else(|| {
|
||||
if p.justify {
|
||||
Linebreaks::Optimized
|
||||
} else {
|
||||
Linebreaks::Simple
|
||||
}
|
||||
});
|
||||
|
||||
match linebreaks {
|
||||
Linebreaks::Simple => linebreak_simple(engine, p, width),
|
||||
Linebreaks::Optimized => linebreak_optimized(engine, p, width),
|
||||
}
|
||||
@ -290,7 +298,7 @@ fn linebreak_optimized_bounded<'a>(
|
||||
}
|
||||
|
||||
// If this attempt is better than what we had before, take it!
|
||||
if best.as_ref().is_none_or(|best| best.total >= total) {
|
||||
if best.as_ref().map_or(true, |best| best.total >= total) {
|
||||
best = Some(Entry { pred: pred_index, total, line: attempt, end });
|
||||
}
|
||||
}
|
||||
@ -376,7 +384,7 @@ fn linebreak_optimized_approximate(
|
||||
|
||||
// Whether the line is justified. This is not 100% accurate w.r.t
|
||||
// to line()'s behaviour, but good enough.
|
||||
let justify = p.config.justify && breakpoint != Breakpoint::Mandatory;
|
||||
let justify = p.justify && breakpoint != Breakpoint::Mandatory;
|
||||
|
||||
// We don't really know whether the line naturally ends with a dash
|
||||
// here, so we can miss that case, but it's ok, since all of this
|
||||
@ -423,7 +431,7 @@ fn linebreak_optimized_approximate(
|
||||
let total = pred.total + line_cost;
|
||||
|
||||
// If this attempt is better than what we had before, take it!
|
||||
if best.as_ref().is_none_or(|best| best.total >= total) {
|
||||
if best.as_ref().map_or(true, |best| best.total >= total) {
|
||||
best = Some(Entry {
|
||||
pred: pred_index,
|
||||
total,
|
||||
@ -565,7 +573,7 @@ fn raw_ratio(
|
||||
// calculate the extra amount. Also, don't divide by zero.
|
||||
let extra_stretch = (delta - adjustability) / justifiables.max(1) as f64;
|
||||
// Normalize the amount by half the em size.
|
||||
ratio = 1.0 + extra_stretch / (p.config.font_size / 2.0);
|
||||
ratio = 1.0 + extra_stretch / (p.size / 2.0);
|
||||
}
|
||||
|
||||
// The min value must be < MIN_RATIO, but how much smaller doesn't matter
|
||||
@ -655,9 +663,9 @@ fn breakpoints(p: &Preparation, mut f: impl FnMut(usize, Breakpoint)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let hyphenate = p.config.hyphenate != Some(false);
|
||||
let hyphenate = p.hyphenate != Some(false);
|
||||
let lb = LINEBREAK_DATA.as_borrowed();
|
||||
let segmenter = match p.config.lang {
|
||||
let segmenter = match p.lang {
|
||||
Some(Lang::CHINESE | Lang::JAPANESE) => &CJ_SEGMENTER,
|
||||
_ => &SEGMENTER,
|
||||
};
|
||||
@ -690,34 +698,13 @@ fn breakpoints(p: &Preparation, mut f: impl FnMut(usize, Breakpoint)) {
|
||||
let breakpoint = if point == text.len() {
|
||||
Breakpoint::Mandatory
|
||||
} else {
|
||||
const OBJ_REPLACE: char = '\u{FFFC}';
|
||||
match lb.get(c) {
|
||||
// Fix for: https://github.com/unicode-org/icu4x/issues/4146
|
||||
LineBreak::Glue | LineBreak::WordJoiner | LineBreak::ZWJ => continue,
|
||||
LineBreak::MandatoryBreak
|
||||
| LineBreak::CarriageReturn
|
||||
| LineBreak::LineFeed
|
||||
| LineBreak::NextLine => Breakpoint::Mandatory,
|
||||
|
||||
// https://github.com/typst/typst/issues/5489
|
||||
//
|
||||
// OBJECT-REPLACEMENT-CHARACTERs provide Contingent Break
|
||||
// opportunities before and after by default. This behaviour
|
||||
// is however tailorable, see:
|
||||
// https://www.unicode.org/reports/tr14/#CB
|
||||
// https://www.unicode.org/reports/tr14/#TailorableBreakingRules
|
||||
// https://www.unicode.org/reports/tr14/#LB20
|
||||
//
|
||||
// Don't provide a line breaking opportunity between a LTR-
|
||||
// ISOLATE (or any other Combining Mark) and an OBJECT-
|
||||
// REPLACEMENT-CHARACTER representing an inline item, if the
|
||||
// LTR-ISOLATE could end up as the only character on the
|
||||
// previous line.
|
||||
LineBreak::CombiningMark
|
||||
if text[point..].starts_with(OBJ_REPLACE)
|
||||
&& last + c.len_utf8() == point =>
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_ => Breakpoint::Normal,
|
||||
}
|
||||
};
|
||||
@ -843,18 +830,18 @@ fn linebreak_link(link: &str, mut f: impl FnMut(usize)) {
|
||||
|
||||
/// Whether hyphenation is enabled at the given offset.
|
||||
fn hyphenate_at(p: &Preparation, offset: usize) -> bool {
|
||||
p.config.hyphenate.unwrap_or_else(|| {
|
||||
let (_, item) = p.get(offset);
|
||||
match item.text() {
|
||||
Some(text) => TextElem::hyphenate_in(text.styles).unwrap_or(p.config.justify),
|
||||
None => false,
|
||||
}
|
||||
})
|
||||
p.hyphenate
|
||||
.or_else(|| {
|
||||
let (_, item) = p.get(offset);
|
||||
let styles = item.text()?.styles;
|
||||
Some(TextElem::hyphenate_in(styles))
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// The text language at the given offset.
|
||||
fn lang_at(p: &Preparation, offset: usize) -> Option<hypher::Lang> {
|
||||
let lang = p.config.lang.or_else(|| {
|
||||
let lang = p.lang.or_else(|| {
|
||||
let (_, item) = p.get(offset);
|
||||
let styles = item.text()?.styles;
|
||||
Some(TextElem::lang_in(styles))
|
||||
@ -878,13 +865,13 @@ impl CostMetrics {
|
||||
fn compute(p: &Preparation) -> Self {
|
||||
Self {
|
||||
// When justifying, we may stretch spaces below their natural width.
|
||||
min_ratio: if p.config.justify { MIN_RATIO } else { 0.0 },
|
||||
min_approx_ratio: if p.config.justify { MIN_APPROX_RATIO } else { 0.0 },
|
||||
min_ratio: if p.justify { MIN_RATIO } else { 0.0 },
|
||||
min_approx_ratio: if p.justify { MIN_APPROX_RATIO } else { 0.0 },
|
||||
// Approximate hyphen width for estimates.
|
||||
approx_hyphen_width: Em::new(0.33).at(p.config.font_size),
|
||||
approx_hyphen_width: Em::new(0.33).at(p.size),
|
||||
// Costs.
|
||||
hyph_cost: DEFAULT_HYPH_COST * p.config.costs.hyphenation().get(),
|
||||
runt_cost: DEFAULT_RUNT_COST * p.config.costs.runt().get(),
|
||||
hyph_cost: DEFAULT_HYPH_COST * p.costs.hyphenation().get(),
|
||||
runt_cost: DEFAULT_RUNT_COST * p.costs.runt().get(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,17 +13,12 @@ pub use self::box_::layout_box;
|
||||
use comemo::{Track, Tracked, TrackedMut};
|
||||
use typst_library::diag::SourceResult;
|
||||
use typst_library::engine::{Engine, Route, Sink, Traced};
|
||||
use typst_library::foundations::{Packed, Resolve, Smart, StyleChain};
|
||||
use typst_library::foundations::{Packed, StyleChain};
|
||||
use typst_library::introspection::{Introspector, Locator, LocatorLink, SplitLocator};
|
||||
use typst_library::layout::{Abs, AlignElem, Dir, FixedAlignment, Fragment, Size};
|
||||
use typst_library::model::{
|
||||
EnumElem, FirstLineIndent, Linebreaks, ListElem, ParElem, ParLine, ParLineMarker,
|
||||
TermsElem,
|
||||
};
|
||||
use typst_library::layout::{Fragment, Size};
|
||||
use typst_library::model::ParElem;
|
||||
use typst_library::routines::{Arenas, Pair, RealizationKind, Routines};
|
||||
use typst_library::text::{Costs, Lang, TextElem};
|
||||
use typst_library::World;
|
||||
use typst_utils::{Numeric, SliceExt};
|
||||
|
||||
use self::collect::{collect, Item, Segment, SpanMapper};
|
||||
use self::deco::decorate;
|
||||
@ -103,7 +98,7 @@ fn layout_par_impl(
|
||||
styles,
|
||||
)?;
|
||||
|
||||
layout_inline_impl(
|
||||
layout_inline(
|
||||
&mut engine,
|
||||
&children,
|
||||
&mut locator,
|
||||
@ -111,134 +106,33 @@ fn layout_par_impl(
|
||||
region,
|
||||
expand,
|
||||
Some(situation),
|
||||
&ConfigBase {
|
||||
justify: elem.justify(styles),
|
||||
linebreaks: elem.linebreaks(styles),
|
||||
first_line_indent: elem.first_line_indent(styles),
|
||||
hanging_indent: elem.hanging_indent(styles),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Lays out realized content with inline layout.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn layout_inline<'a>(
|
||||
engine: &mut Engine,
|
||||
children: &[Pair<'a>],
|
||||
locator: &mut SplitLocator<'a>,
|
||||
shared: StyleChain<'a>,
|
||||
region: Size,
|
||||
expand: bool,
|
||||
) -> SourceResult<Fragment> {
|
||||
layout_inline_impl(
|
||||
engine,
|
||||
children,
|
||||
locator,
|
||||
shared,
|
||||
region,
|
||||
expand,
|
||||
None,
|
||||
&ConfigBase {
|
||||
justify: ParElem::justify_in(shared),
|
||||
linebreaks: ParElem::linebreaks_in(shared),
|
||||
first_line_indent: ParElem::first_line_indent_in(shared),
|
||||
hanging_indent: ParElem::hanging_indent_in(shared),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// The internal implementation of [`layout_inline`].
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn layout_inline_impl<'a>(
|
||||
engine: &mut Engine,
|
||||
children: &[Pair<'a>],
|
||||
locator: &mut SplitLocator<'a>,
|
||||
shared: StyleChain<'a>,
|
||||
styles: StyleChain<'a>,
|
||||
region: Size,
|
||||
expand: bool,
|
||||
par: Option<ParSituation>,
|
||||
base: &ConfigBase,
|
||||
) -> SourceResult<Fragment> {
|
||||
// Prepare configuration that is shared across the whole inline layout.
|
||||
let config = configuration(base, children, shared, par);
|
||||
|
||||
// Collect all text into one string for BiDi analysis.
|
||||
let (text, segments, spans) = collect(children, engine, locator, &config, region)?;
|
||||
let (text, segments, spans) =
|
||||
collect(children, engine, locator, styles, region, par)?;
|
||||
|
||||
// Perform BiDi analysis and performs some preparation steps before we
|
||||
// proceed to line breaking.
|
||||
let p = prepare(engine, &config, &text, segments, spans)?;
|
||||
let p = prepare(engine, children, &text, segments, spans, styles, par)?;
|
||||
|
||||
// Break the text into lines.
|
||||
let lines = linebreak(engine, &p, region.x - config.hanging_indent);
|
||||
let lines = linebreak(engine, &p, region.x - p.hang);
|
||||
|
||||
// Turn the selected lines into frames.
|
||||
finalize(engine, &p, &lines, region, expand, locator)
|
||||
}
|
||||
|
||||
/// Determine the inline layout's configuration.
|
||||
fn configuration(
|
||||
base: &ConfigBase,
|
||||
children: &[Pair],
|
||||
shared: StyleChain,
|
||||
situation: Option<ParSituation>,
|
||||
) -> Config {
|
||||
let justify = base.justify;
|
||||
let font_size = TextElem::size_in(shared);
|
||||
let dir = TextElem::dir_in(shared);
|
||||
|
||||
Config {
|
||||
justify,
|
||||
linebreaks: base.linebreaks.unwrap_or_else(|| {
|
||||
if justify {
|
||||
Linebreaks::Optimized
|
||||
} else {
|
||||
Linebreaks::Simple
|
||||
}
|
||||
}),
|
||||
first_line_indent: {
|
||||
let FirstLineIndent { amount, all } = base.first_line_indent;
|
||||
if !amount.is_zero()
|
||||
&& match situation {
|
||||
// First-line indent for the first paragraph after a list
|
||||
// bullet just looks bad.
|
||||
Some(ParSituation::First) => all && !in_list(shared),
|
||||
Some(ParSituation::Consecutive) => true,
|
||||
Some(ParSituation::Other) => all,
|
||||
None => false,
|
||||
}
|
||||
&& AlignElem::alignment_in(shared).resolve(shared).x == dir.start().into()
|
||||
{
|
||||
amount.at(font_size)
|
||||
} else {
|
||||
Abs::zero()
|
||||
}
|
||||
},
|
||||
hanging_indent: if situation.is_some() {
|
||||
base.hanging_indent
|
||||
} else {
|
||||
Abs::zero()
|
||||
},
|
||||
numbering_marker: ParLine::numbering_in(shared).map(|numbering| {
|
||||
Packed::new(ParLineMarker::new(
|
||||
numbering,
|
||||
ParLine::number_align_in(shared),
|
||||
ParLine::number_margin_in(shared),
|
||||
// Delay resolving the number clearance until line numbers are
|
||||
// laid out to avoid inconsistent spacing depending on varying
|
||||
// font size.
|
||||
ParLine::number_clearance_in(shared),
|
||||
))
|
||||
}),
|
||||
align: AlignElem::alignment_in(shared).fix(dir).x,
|
||||
font_size,
|
||||
dir,
|
||||
hyphenate: shared_get(children, shared, TextElem::hyphenate_in)
|
||||
.map(|uniform| uniform.unwrap_or(justify)),
|
||||
lang: shared_get(children, shared, TextElem::lang_in),
|
||||
fallback: TextElem::fallback_in(shared),
|
||||
cjk_latin_spacing: TextElem::cjk_latin_spacing_in(shared).is_auto(),
|
||||
costs: TextElem::costs_in(shared),
|
||||
}
|
||||
finalize(engine, &p, &lines, styles, region, expand, locator)
|
||||
}
|
||||
|
||||
/// Distinguishes between a few different kinds of paragraphs.
|
||||
@ -254,66 +148,3 @@ pub enum ParSituation {
|
||||
/// Any other kind of paragraph.
|
||||
Other,
|
||||
}
|
||||
|
||||
/// Raw values from a `ParElem` or style chain. Used to initialize a [`Config`].
|
||||
struct ConfigBase {
|
||||
justify: bool,
|
||||
linebreaks: Smart<Linebreaks>,
|
||||
first_line_indent: FirstLineIndent,
|
||||
hanging_indent: Abs,
|
||||
}
|
||||
|
||||
/// Shared configuration for the whole inline layout.
|
||||
struct Config {
|
||||
/// Whether to justify text.
|
||||
justify: bool,
|
||||
/// How to determine line breaks.
|
||||
linebreaks: Linebreaks,
|
||||
/// The indent the first line of a paragraph should have.
|
||||
first_line_indent: Abs,
|
||||
/// The indent that all but the first line of a paragraph should have.
|
||||
hanging_indent: Abs,
|
||||
/// Configuration for line numbering.
|
||||
numbering_marker: Option<Packed<ParLineMarker>>,
|
||||
/// The resolved horizontal alignment.
|
||||
align: FixedAlignment,
|
||||
/// The text size.
|
||||
font_size: Abs,
|
||||
/// The dominant direction.
|
||||
dir: Dir,
|
||||
/// A uniform hyphenation setting (only `Some(_)` if it's the same for all
|
||||
/// children, otherwise `None`).
|
||||
hyphenate: Option<bool>,
|
||||
/// The text language (only `Some(_)` if it's the same for all
|
||||
/// children, otherwise `None`).
|
||||
lang: Option<Lang>,
|
||||
/// Whether font fallback is enabled.
|
||||
fallback: bool,
|
||||
/// Whether to add spacing between CJK and Latin characters.
|
||||
cjk_latin_spacing: bool,
|
||||
/// Costs for various layout decisions.
|
||||
costs: Costs,
|
||||
}
|
||||
|
||||
/// Get a style property, but only if it is the same for all of the children.
|
||||
fn shared_get<T: PartialEq>(
|
||||
children: &[Pair],
|
||||
styles: StyleChain<'_>,
|
||||
getter: fn(StyleChain) -> T,
|
||||
) -> Option<T> {
|
||||
let value = getter(styles);
|
||||
children
|
||||
.group_by_key(|&(_, s)| s)
|
||||
.all(|(s, _)| getter(s) == value)
|
||||
.then_some(value)
|
||||
}
|
||||
|
||||
/// Whether we have a list ancestor.
|
||||
///
|
||||
/// When we support some kind of more general ancestry mechanism, this can
|
||||
/// become more elegant.
|
||||
fn in_list(styles: StyleChain) -> bool {
|
||||
ListElem::depth_in(styles).0 > 0
|
||||
|| !EnumElem::parents_in(styles).is_empty()
|
||||
|| TermsElem::within_in(styles)
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
use typst_library::layout::{Dir, Em};
|
||||
use typst_library::foundations::{Resolve, Smart};
|
||||
use typst_library::layout::{Abs, AlignElem, Dir, Em, FixedAlignment};
|
||||
use typst_library::model::Linebreaks;
|
||||
use typst_library::routines::Pair;
|
||||
use typst_library::text::{Costs, Lang, TextElem};
|
||||
use typst_utils::SliceExt;
|
||||
use unicode_bidi::{BidiInfo, Level as BidiLevel};
|
||||
|
||||
use super::*;
|
||||
@ -12,8 +17,6 @@ use super::*;
|
||||
pub struct Preparation<'a> {
|
||||
/// The full text.
|
||||
pub text: &'a str,
|
||||
/// Configuration for inline layout.
|
||||
pub config: &'a Config,
|
||||
/// Bidirectional text embedding levels.
|
||||
///
|
||||
/// This is `None` if all text directions are uniform (all the base
|
||||
@ -25,6 +28,28 @@ pub struct Preparation<'a> {
|
||||
pub indices: Vec<usize>,
|
||||
/// The span mapper.
|
||||
pub spans: SpanMapper,
|
||||
/// Whether to hyphenate if it's the same for all children.
|
||||
pub hyphenate: Option<bool>,
|
||||
/// Costs for various layout decisions.
|
||||
pub costs: Costs,
|
||||
/// The dominant direction.
|
||||
pub dir: Dir,
|
||||
/// The text language if it's the same for all children.
|
||||
pub lang: Option<Lang>,
|
||||
/// The resolved horizontal alignment.
|
||||
pub align: FixedAlignment,
|
||||
/// Whether to justify text.
|
||||
pub justify: bool,
|
||||
/// Hanging indent to apply.
|
||||
pub hang: Abs,
|
||||
/// Whether to add spacing between CJK and Latin characters.
|
||||
pub cjk_latin_spacing: bool,
|
||||
/// Whether font fallback is enabled.
|
||||
pub fallback: bool,
|
||||
/// How to determine line breaks.
|
||||
pub linebreaks: Smart<Linebreaks>,
|
||||
/// The text size.
|
||||
pub size: Abs,
|
||||
}
|
||||
|
||||
impl<'a> Preparation<'a> {
|
||||
@ -55,12 +80,15 @@ impl<'a> Preparation<'a> {
|
||||
#[typst_macros::time]
|
||||
pub fn prepare<'a>(
|
||||
engine: &mut Engine,
|
||||
config: &'a Config,
|
||||
children: &[Pair<'a>],
|
||||
text: &'a str,
|
||||
segments: Vec<Segment<'a>>,
|
||||
spans: SpanMapper,
|
||||
styles: StyleChain<'a>,
|
||||
situation: Option<ParSituation>,
|
||||
) -> SourceResult<Preparation<'a>> {
|
||||
let default_level = match config.dir {
|
||||
let dir = TextElem::dir_in(styles);
|
||||
let default_level = match dir {
|
||||
Dir::RTL => BidiLevel::rtl(),
|
||||
_ => BidiLevel::ltr(),
|
||||
};
|
||||
@ -96,20 +124,51 @@ pub fn prepare<'a>(
|
||||
indices.extend(range.clone().map(|_| i));
|
||||
}
|
||||
|
||||
if config.cjk_latin_spacing {
|
||||
let cjk_latin_spacing = TextElem::cjk_latin_spacing_in(styles).is_auto();
|
||||
if cjk_latin_spacing {
|
||||
add_cjk_latin_spacing(&mut items);
|
||||
}
|
||||
|
||||
// Only apply hanging indent to real paragraphs.
|
||||
let hang = if situation.is_some() {
|
||||
ParElem::hanging_indent_in(styles)
|
||||
} else {
|
||||
Abs::zero()
|
||||
};
|
||||
|
||||
Ok(Preparation {
|
||||
config,
|
||||
text,
|
||||
bidi: is_bidi.then_some(bidi),
|
||||
items,
|
||||
indices,
|
||||
spans,
|
||||
hyphenate: shared_get(children, styles, TextElem::hyphenate_in),
|
||||
costs: TextElem::costs_in(styles),
|
||||
dir,
|
||||
lang: shared_get(children, styles, TextElem::lang_in),
|
||||
align: AlignElem::alignment_in(styles).resolve(styles).x,
|
||||
justify: ParElem::justify_in(styles),
|
||||
hang,
|
||||
cjk_latin_spacing,
|
||||
fallback: TextElem::fallback_in(styles),
|
||||
linebreaks: ParElem::linebreaks_in(styles),
|
||||
size: TextElem::size_in(styles),
|
||||
})
|
||||
}
|
||||
|
||||
/// Get a style property, but only if it is the same for all of the children.
|
||||
fn shared_get<T: PartialEq>(
|
||||
children: &[Pair],
|
||||
styles: StyleChain<'_>,
|
||||
getter: fn(StyleChain) -> T,
|
||||
) -> Option<T> {
|
||||
let value = getter(styles);
|
||||
children
|
||||
.group_by_key(|&(_, s)| s)
|
||||
.all(|(s, _)| getter(s) == value)
|
||||
.then_some(value)
|
||||
}
|
||||
|
||||
/// Add some spacing between Han characters and western characters. See
|
||||
/// Requirements for Chinese Text Layout, Section 3.2.2 Mixed Text Composition
|
||||
/// in Horizontal Written Mode
|
||||
|
@ -20,7 +20,7 @@ use unicode_bidi::{BidiInfo, Level as BidiLevel};
|
||||
use unicode_script::{Script, UnicodeScript};
|
||||
|
||||
use super::{decorate, Item, Range, SpanMapper};
|
||||
use crate::modifiers::FrameModifyText;
|
||||
use crate::modifiers::{FrameModifiers, FrameModify};
|
||||
|
||||
/// The result of shaping text.
|
||||
///
|
||||
@ -327,7 +327,7 @@ impl<'a> ShapedText<'a> {
|
||||
offset += width;
|
||||
}
|
||||
|
||||
frame.modify_text(self.styles);
|
||||
frame.modify(&FrameModifiers::get_in(self.styles));
|
||||
frame
|
||||
}
|
||||
|
||||
@ -465,7 +465,7 @@ impl<'a> ShapedText<'a> {
|
||||
None
|
||||
};
|
||||
let mut chain = families(self.styles)
|
||||
.filter(|family| family.covers().is_none_or(|c| c.is_match("-")))
|
||||
.filter(|family| family.covers().map_or(true, |c| c.is_match("-")))
|
||||
.map(|family| book.select(family.as_str(), self.variant))
|
||||
.chain(fallback_func.iter().map(|f| f()))
|
||||
.flatten();
|
||||
@ -570,7 +570,7 @@ impl<'a> ShapedText<'a> {
|
||||
// for the next line.
|
||||
let dec = if ltr { usize::checked_sub } else { usize::checked_add };
|
||||
while let Some(next) = dec(idx, 1) {
|
||||
if self.glyphs.get(next).is_none_or(|g| g.range.start != text_index) {
|
||||
if self.glyphs.get(next).map_or(true, |g| g.range.start != text_index) {
|
||||
break;
|
||||
}
|
||||
idx = next;
|
||||
@ -812,7 +812,7 @@ fn shape_segment<'a>(
|
||||
.nth(1)
|
||||
.map(|(i, _)| offset + i)
|
||||
.unwrap_or(text.len());
|
||||
covers.is_none_or(|cov| cov.is_match(&text[offset..end]))
|
||||
covers.map_or(true, |cov| cov.is_match(&text[offset..end]))
|
||||
};
|
||||
|
||||
// Collect the shaped glyphs, doing fallback and shaping parts again with
|
||||
@ -824,42 +824,12 @@ fn shape_segment<'a>(
|
||||
|
||||
// Add the glyph to the shaped output.
|
||||
if info.glyph_id != 0 && is_covered(cluster) {
|
||||
// Assume we have the following sequence of (glyph_id, cluster):
|
||||
// [(120, 0), (80, 0), (3, 3), (755, 4), (69, 4), (424, 13),
|
||||
// (63, 13), (193, 25), (80, 25), (3, 31)
|
||||
//
|
||||
// We then want the sequence of (glyph_id, text_range) to look as follows:
|
||||
// [(120, 0..3), (80, 0..3), (3, 3..4), (755, 4..13), (69, 4..13),
|
||||
// (424, 13..25), (63, 13..25), (193, 25..31), (80, 25..31), (3, 31..x)]
|
||||
//
|
||||
// Each glyph in the same cluster should be assigned the full text
|
||||
// range. This is necessary because only this way krilla can
|
||||
// properly assign `ActualText` attributes in complex shaping
|
||||
// scenarios.
|
||||
|
||||
// The start of the glyph's text range.
|
||||
// Determine the text range of the glyph.
|
||||
let start = base + cluster;
|
||||
|
||||
// Determine the end of the glyph's text range.
|
||||
let mut k = i;
|
||||
let step: isize = if ltr { 1 } else { -1 };
|
||||
let end = loop {
|
||||
// If we've reached the end of the glyphs, the `end` of the
|
||||
// range should be the end of the full text.
|
||||
let Some((next, next_info)) = k
|
||||
.checked_add_signed(step)
|
||||
.and_then(|n| infos.get(n).map(|info| (n, info)))
|
||||
else {
|
||||
break base + text.len();
|
||||
};
|
||||
|
||||
// If the cluster doesn't match anymore, we've reached the end.
|
||||
if next_info.cluster != info.cluster {
|
||||
break base + next_info.cluster as usize;
|
||||
}
|
||||
|
||||
k = next;
|
||||
};
|
||||
let end = base
|
||||
+ if ltr { i.checked_add(1) } else { i.checked_sub(1) }
|
||||
.and_then(|last| infos.get(last))
|
||||
.map_or(text.len(), |info| info.cluster as usize);
|
||||
|
||||
let c = text[cluster..].chars().next().unwrap();
|
||||
let script = c.script();
|
||||
|
@ -96,13 +96,9 @@ pub fn layout_enum(
|
||||
|
||||
let mut cells = vec![];
|
||||
let mut locator = locator.split();
|
||||
let mut number = elem.start(styles).unwrap_or_else(|| {
|
||||
if reversed {
|
||||
elem.children.len() as u64
|
||||
} else {
|
||||
1
|
||||
}
|
||||
});
|
||||
let mut number =
|
||||
elem.start(styles)
|
||||
.unwrap_or_else(|| if reversed { elem.children.len() } else { 1 });
|
||||
let mut parents = EnumElem::parents_in(styles);
|
||||
|
||||
let full = elem.full(styles);
|
||||
|
@ -19,10 +19,8 @@ pub fn layout_accent(
|
||||
let mut base = ctx.layout_into_fragment(&elem.base, styles.chain(&cramped))?;
|
||||
|
||||
// Try to replace a glyph with its dotless variant.
|
||||
if elem.dotless(styles) {
|
||||
if let MathFragment::Glyph(glyph) = &mut base {
|
||||
glyph.make_dotless_form(ctx);
|
||||
}
|
||||
if let MathFragment::Glyph(glyph) = &mut base {
|
||||
glyph.make_dotless_form(ctx);
|
||||
}
|
||||
|
||||
// Preserve class to preserve automatic spacing.
|
||||
@ -36,7 +34,7 @@ pub fn layout_accent(
|
||||
|
||||
// Try to replace accent glyph with flattened variant.
|
||||
let flattened_base_height = scaled!(ctx, styles, flattened_accent_base_height);
|
||||
if base.ascent() > flattened_base_height {
|
||||
if base.height() > flattened_base_height {
|
||||
glyph.make_flattened_accent_form(ctx);
|
||||
}
|
||||
|
||||
@ -52,7 +50,7 @@ pub fn layout_accent(
|
||||
// minus the accent base height. Only if the base is very small, we need
|
||||
// a larger gap so that the accent doesn't move too low.
|
||||
let accent_base_height = scaled!(ctx, styles, accent_base_height);
|
||||
let gap = -accent.descent() - base.ascent().min(accent_base_height);
|
||||
let gap = -accent.descent() - base.height().min(accent_base_height);
|
||||
let size = Size::new(base.width(), accent.height() + gap + base.height());
|
||||
let accent_pos = Point::with_x(base_attach - accent_attach);
|
||||
let base_pos = Point::with_y(accent.height() + gap);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use typst_library::diag::{bail, warning, SourceResult};
|
||||
use typst_library::diag::{bail, SourceResult};
|
||||
use typst_library::foundations::{Content, Packed, Resolve, StyleChain};
|
||||
use typst_library::layout::{
|
||||
Abs, Axes, Em, FixedAlignment, Frame, FrameItem, Point, Ratio, Rel, Size,
|
||||
@ -9,7 +9,7 @@ use typst_library::visualize::{FillRule, FixedStroke, Geometry, LineCap, Shape};
|
||||
use typst_syntax::Span;
|
||||
|
||||
use super::{
|
||||
alignments, delimiter_alignment, style_for_denominator, AlignmentResult,
|
||||
alignments, delimiter_alignment, stack, style_for_denominator, AlignmentResult,
|
||||
FrameFragment, GlyphFragment, LeftRightAlternator, MathContext, DELIM_SHORT_FALL,
|
||||
};
|
||||
|
||||
@ -23,51 +23,17 @@ pub fn layout_vec(
|
||||
ctx: &mut MathContext,
|
||||
styles: StyleChain,
|
||||
) -> SourceResult<()> {
|
||||
let span = elem.span();
|
||||
|
||||
let column: Vec<&Content> = elem.children.iter().collect();
|
||||
let frame = layout_body(
|
||||
let delim = elem.delim(styles);
|
||||
let frame = layout_vec_body(
|
||||
ctx,
|
||||
styles,
|
||||
&[column],
|
||||
&elem.children,
|
||||
elem.align(styles),
|
||||
elem.gap(styles),
|
||||
LeftRightAlternator::Right,
|
||||
None,
|
||||
Axes::with_y(elem.gap(styles)),
|
||||
span,
|
||||
"elements",
|
||||
)?;
|
||||
|
||||
let delim = elem.delim(styles);
|
||||
layout_delimiters(ctx, styles, frame, delim.open(), delim.close(), span)
|
||||
}
|
||||
|
||||
/// Lays out a [`CasesElem`].
|
||||
#[typst_macros::time(name = "math.cases", span = elem.span())]
|
||||
pub fn layout_cases(
|
||||
elem: &Packed<CasesElem>,
|
||||
ctx: &mut MathContext,
|
||||
styles: StyleChain,
|
||||
) -> SourceResult<()> {
|
||||
let span = elem.span();
|
||||
|
||||
let column: Vec<&Content> = elem.children.iter().collect();
|
||||
let frame = layout_body(
|
||||
ctx,
|
||||
styles,
|
||||
&[column],
|
||||
FixedAlignment::Start,
|
||||
LeftRightAlternator::None,
|
||||
None,
|
||||
Axes::with_y(elem.gap(styles)),
|
||||
span,
|
||||
"branches",
|
||||
)?;
|
||||
|
||||
let delim = elem.delim(styles);
|
||||
let (open, close) =
|
||||
if elem.reverse(styles) { (None, delim.close()) } else { (delim.open(), None) };
|
||||
layout_delimiters(ctx, styles, frame, open, close, span)
|
||||
layout_delimiters(ctx, styles, frame, delim.open(), delim.close(), elem.span())
|
||||
}
|
||||
|
||||
/// Lays out a [`MatElem`].
|
||||
@ -77,16 +43,14 @@ pub fn layout_mat(
|
||||
ctx: &mut MathContext,
|
||||
styles: StyleChain,
|
||||
) -> SourceResult<()> {
|
||||
let span = elem.span();
|
||||
let rows = &elem.rows;
|
||||
let ncols = rows.first().map_or(0, |row| row.len());
|
||||
|
||||
let augment = elem.augment(styles);
|
||||
let rows = &elem.rows;
|
||||
|
||||
if let Some(aug) = &augment {
|
||||
for &offset in &aug.hline.0 {
|
||||
if offset == 0 || offset.unsigned_abs() >= rows.len() {
|
||||
bail!(
|
||||
span,
|
||||
elem.span(),
|
||||
"cannot draw a horizontal line after row {} of a matrix with {} rows",
|
||||
if offset < 0 { rows.len() as isize + offset } else { offset },
|
||||
rows.len()
|
||||
@ -94,55 +58,95 @@ pub fn layout_mat(
|
||||
}
|
||||
}
|
||||
|
||||
let ncols = rows.first().map_or(0, |row| row.len());
|
||||
|
||||
for &offset in &aug.vline.0 {
|
||||
if offset == 0 || offset.unsigned_abs() >= ncols {
|
||||
bail!(
|
||||
span,
|
||||
"cannot draw a vertical line after column {} of a matrix with {} columns",
|
||||
if offset < 0 { ncols as isize + offset } else { offset },
|
||||
ncols
|
||||
);
|
||||
elem.span(),
|
||||
"cannot draw a vertical line after column {} of a matrix with {} columns",
|
||||
if offset < 0 { ncols as isize + offset } else { offset },
|
||||
ncols
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Transpose rows of the matrix into columns.
|
||||
let mut row_iters: Vec<_> = rows.iter().map(|i| i.iter()).collect();
|
||||
let columns: Vec<Vec<_>> = (0..ncols)
|
||||
.map(|_| row_iters.iter_mut().map(|i| i.next().unwrap()).collect())
|
||||
.collect();
|
||||
|
||||
let frame = layout_body(
|
||||
let delim = elem.delim(styles);
|
||||
let frame = layout_mat_body(
|
||||
ctx,
|
||||
styles,
|
||||
&columns,
|
||||
rows,
|
||||
elem.align(styles),
|
||||
LeftRightAlternator::Right,
|
||||
augment,
|
||||
Axes::new(elem.column_gap(styles), elem.row_gap(styles)),
|
||||
span,
|
||||
"cells",
|
||||
elem.span(),
|
||||
)?;
|
||||
|
||||
let delim = elem.delim(styles);
|
||||
layout_delimiters(ctx, styles, frame, delim.open(), delim.close(), span)
|
||||
layout_delimiters(ctx, styles, frame, delim.open(), delim.close(), elem.span())
|
||||
}
|
||||
|
||||
/// Layout the inner contents of a matrix, vector, or cases.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn layout_body(
|
||||
/// Lays out a [`CasesElem`].
|
||||
#[typst_macros::time(name = "math.cases", span = elem.span())]
|
||||
pub fn layout_cases(
|
||||
elem: &Packed<CasesElem>,
|
||||
ctx: &mut MathContext,
|
||||
styles: StyleChain,
|
||||
columns: &[Vec<&Content>],
|
||||
) -> SourceResult<()> {
|
||||
let delim = elem.delim(styles);
|
||||
let frame = layout_vec_body(
|
||||
ctx,
|
||||
styles,
|
||||
&elem.children,
|
||||
FixedAlignment::Start,
|
||||
elem.gap(styles),
|
||||
LeftRightAlternator::None,
|
||||
)?;
|
||||
|
||||
let (open, close) =
|
||||
if elem.reverse(styles) { (None, delim.close()) } else { (delim.open(), None) };
|
||||
|
||||
layout_delimiters(ctx, styles, frame, open, close, elem.span())
|
||||
}
|
||||
|
||||
/// Layout the inner contents of a vector.
|
||||
fn layout_vec_body(
|
||||
ctx: &mut MathContext,
|
||||
styles: StyleChain,
|
||||
column: &[Content],
|
||||
align: FixedAlignment,
|
||||
row_gap: Rel<Abs>,
|
||||
alternator: LeftRightAlternator,
|
||||
) -> SourceResult<Frame> {
|
||||
let gap = row_gap.relative_to(ctx.region.size.y);
|
||||
|
||||
let denom_style = style_for_denominator(styles);
|
||||
let mut flat = vec![];
|
||||
for child in column {
|
||||
// We allow linebreaks in cases and vectors, which are functionally
|
||||
// identical to commas.
|
||||
flat.extend(ctx.layout_into_run(child, styles.chain(&denom_style))?.rows());
|
||||
}
|
||||
// We pad ascent and descent with the ascent and descent of the paren
|
||||
// to ensure that normal vectors are aligned with others unless they are
|
||||
// way too big.
|
||||
let paren =
|
||||
GlyphFragment::new(ctx, styles.chain(&denom_style), '(', Span::detached());
|
||||
Ok(stack(flat, align, gap, 0, alternator, Some((paren.ascent, paren.descent))))
|
||||
}
|
||||
|
||||
/// Layout the inner contents of a matrix.
|
||||
fn layout_mat_body(
|
||||
ctx: &mut MathContext,
|
||||
styles: StyleChain,
|
||||
rows: &[Vec<Content>],
|
||||
align: FixedAlignment,
|
||||
augment: Option<Augment<Abs>>,
|
||||
gap: Axes<Rel<Abs>>,
|
||||
span: Span,
|
||||
children: &str,
|
||||
) -> SourceResult<Frame> {
|
||||
let nrows = columns.first().map_or(0, |col| col.len());
|
||||
let ncols = columns.len();
|
||||
let ncols = rows.first().map_or(0, |row| row.len());
|
||||
let nrows = rows.len();
|
||||
if ncols == 0 || nrows == 0 {
|
||||
return Ok(Frame::soft(Size::zero()));
|
||||
}
|
||||
@ -174,11 +178,16 @@ fn layout_body(
|
||||
// Before the full matrix body can be laid out, the
|
||||
// individual cells must first be independently laid out
|
||||
// so we can ensure alignment across rows and columns.
|
||||
let mut cols = vec![vec![]; ncols];
|
||||
|
||||
// This variable stores the maximum ascent and descent for each row.
|
||||
let mut heights = vec![(Abs::zero(), Abs::zero()); nrows];
|
||||
|
||||
// We want to transpose our data layout to columns
|
||||
// before final layout. For efficiency, the columns
|
||||
// variable is set up here and newly generated
|
||||
// individual cells are then added to it.
|
||||
let mut cols = vec![vec![]; ncols];
|
||||
|
||||
let denom_style = style_for_denominator(styles);
|
||||
// We pad ascent and descent with the ascent and descent of the paren
|
||||
// to ensure that normal matrices are aligned with others unless they are
|
||||
@ -186,22 +195,10 @@ fn layout_body(
|
||||
let paren =
|
||||
GlyphFragment::new(ctx, styles.chain(&denom_style), '(', Span::detached());
|
||||
|
||||
for (column, col) in columns.iter().zip(&mut cols) {
|
||||
for (cell, (ascent, descent)) in column.iter().zip(&mut heights) {
|
||||
let cell_span = cell.span();
|
||||
for (row, (ascent, descent)) in rows.iter().zip(&mut heights) {
|
||||
for (cell, col) in row.iter().zip(&mut cols) {
|
||||
let cell = ctx.layout_into_run(cell, styles.chain(&denom_style))?;
|
||||
|
||||
// We ignore linebreaks in the cells as we can't differentiate
|
||||
// alignment points for the whole body from ones for a specific
|
||||
// cell, and multiline cells don't quite make sense at the moment.
|
||||
if cell.is_multiline() {
|
||||
ctx.engine.sink.warn(warning!(
|
||||
cell_span,
|
||||
"linebreaks are ignored in {}", children;
|
||||
hint: "use commas instead to separate each line"
|
||||
));
|
||||
}
|
||||
|
||||
ascent.set_max(cell.ascent().max(paren.ascent));
|
||||
descent.set_max(cell.descent().max(paren.descent));
|
||||
|
||||
@ -225,7 +222,7 @@ fn layout_body(
|
||||
let mut y = Abs::zero();
|
||||
|
||||
for (cell, &(ascent, descent)) in col.into_iter().zip(&heights) {
|
||||
let cell = cell.into_line_frame(&points, alternator);
|
||||
let cell = cell.into_line_frame(&points, LeftRightAlternator::Right);
|
||||
let pos = Point::new(
|
||||
if points.is_empty() {
|
||||
x + align.position(rcol - cell.width())
|
||||
|
@ -85,15 +85,14 @@ pub fn layout_root(
|
||||
ascent.set_max(shift_up + index.ascent());
|
||||
}
|
||||
|
||||
let sqrt_x = sqrt_offset.max(Abs::zero());
|
||||
let radicand_x = sqrt_x + sqrt.width();
|
||||
let radicand_x = sqrt_offset + sqrt.width();
|
||||
let radicand_y = ascent - radicand.ascent();
|
||||
let width = radicand_x + radicand.width();
|
||||
let size = Size::new(width, ascent + descent);
|
||||
|
||||
// The extra "- thickness" comes from the fact that the sqrt is placed
|
||||
// in `push_frame` with respect to its top, not its baseline.
|
||||
let sqrt_pos = Point::new(sqrt_x, radicand_y - gap - thickness);
|
||||
let sqrt_pos = Point::new(sqrt_offset, radicand_y - gap - thickness);
|
||||
let line_pos = Point::new(radicand_x, radicand_y - gap - (thickness / 2.0));
|
||||
let radicand_pos = Point::new(radicand_x, radicand_y);
|
||||
|
||||
@ -101,8 +100,7 @@ pub fn layout_root(
|
||||
frame.set_baseline(ascent);
|
||||
|
||||
if let Some(index) = index {
|
||||
let index_x = -sqrt_offset.min(Abs::zero()) + kern_before;
|
||||
let index_pos = Point::new(index_x, ascent - index.ascent() - shift_up);
|
||||
let index_pos = Point::new(kern_before, ascent - index.ascent() - shift_up);
|
||||
frame.push_frame(index_pos, index);
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,7 @@ pub fn stack(
|
||||
gap: Abs,
|
||||
baseline: usize,
|
||||
alternator: LeftRightAlternator,
|
||||
minimum_ascent_descent: Option<(Abs, Abs)>,
|
||||
) -> Frame {
|
||||
let AlignmentResult { points, width } = alignments(&rows);
|
||||
let rows: Vec<_> = rows
|
||||
@ -124,9 +125,13 @@ pub fn stack(
|
||||
.map(|row| row.into_line_frame(&points, alternator))
|
||||
.collect();
|
||||
|
||||
let padded_height = |height: Abs| {
|
||||
height.max(minimum_ascent_descent.map_or(Abs::zero(), |(a, d)| a + d))
|
||||
};
|
||||
|
||||
let mut frame = Frame::soft(Size::new(
|
||||
width,
|
||||
rows.iter().map(|row| row.height()).sum::<Abs>()
|
||||
rows.iter().map(|row| padded_height(row.height())).sum::<Abs>()
|
||||
+ rows.len().saturating_sub(1) as f64 * gap,
|
||||
));
|
||||
|
||||
@ -137,11 +142,14 @@ pub fn stack(
|
||||
} else {
|
||||
Abs::zero()
|
||||
};
|
||||
let pos = Point::new(x, y);
|
||||
let ascent_padded_part = minimum_ascent_descent
|
||||
.map_or(Abs::zero(), |(a, _)| (a - row.ascent()))
|
||||
.max(Abs::zero());
|
||||
let pos = Point::new(x, y + ascent_padded_part);
|
||||
if i == baseline {
|
||||
frame.set_baseline(y + row.baseline());
|
||||
frame.set_baseline(y + row.baseline() + ascent_padded_part);
|
||||
}
|
||||
y += row.height() + gap;
|
||||
y += padded_height(row.height()) + gap;
|
||||
frame.push_frame(pos, row);
|
||||
}
|
||||
|
||||
|
@ -302,6 +302,6 @@ fn assemble(
|
||||
fn parts(assembly: GlyphAssembly, repeat: usize) -> impl Iterator<Item = GlyphPart> + '_ {
|
||||
assembly.parts.into_iter().flat_map(move |part| {
|
||||
let count = if part.part_flags.extender() { repeat } else { 1 };
|
||||
std::iter::repeat_n(part, count)
|
||||
std::iter::repeat(part).take(count)
|
||||
})
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ fn layout_inline_text(
|
||||
styles,
|
||||
Size::splat(Abs::inf()),
|
||||
false,
|
||||
None,
|
||||
)?
|
||||
.into_frame();
|
||||
|
||||
|
@ -312,8 +312,14 @@ fn layout_underoverspreader(
|
||||
}
|
||||
};
|
||||
|
||||
let frame =
|
||||
stack(rows, FixedAlignment::Center, gap, baseline, LeftRightAlternator::Right);
|
||||
let frame = stack(
|
||||
rows,
|
||||
FixedAlignment::Center,
|
||||
gap,
|
||||
baseline,
|
||||
LeftRightAlternator::Right,
|
||||
None,
|
||||
);
|
||||
ctx.push(FrameFragment::new(styles, frame).with_class(body_class));
|
||||
|
||||
Ok(())
|
||||
|
@ -1,6 +1,6 @@
|
||||
use typst_library::foundations::StyleChain;
|
||||
use typst_library::layout::{Abs, Fragment, Frame, FrameItem, HideElem, Point, Sides};
|
||||
use typst_library::model::{Destination, LinkElem, ParElem};
|
||||
use typst_library::layout::{Fragment, Frame, FrameItem, HideElem, Point};
|
||||
use typst_library::model::{Destination, LinkElem};
|
||||
|
||||
/// Frame-level modifications resulting from styles that do not impose any
|
||||
/// layout structure.
|
||||
@ -52,7 +52,14 @@ pub trait FrameModify {
|
||||
|
||||
impl FrameModify for Frame {
|
||||
fn modify(&mut self, modifiers: &FrameModifiers) {
|
||||
modify_frame(self, modifiers, None);
|
||||
if let Some(dest) = &modifiers.dest {
|
||||
let size = self.size();
|
||||
self.push(Point::zero(), FrameItem::Link(dest.clone(), size));
|
||||
}
|
||||
|
||||
if modifiers.hidden {
|
||||
self.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,41 +82,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FrameModifyText {
|
||||
/// Resolve and apply [`FrameModifiers`] for this text frame.
|
||||
fn modify_text(&mut self, styles: StyleChain);
|
||||
}
|
||||
|
||||
impl FrameModifyText for Frame {
|
||||
fn modify_text(&mut self, styles: StyleChain) {
|
||||
let modifiers = FrameModifiers::get_in(styles);
|
||||
let expand_y = 0.5 * ParElem::leading_in(styles);
|
||||
let outset = Sides::new(Abs::zero(), expand_y, Abs::zero(), expand_y);
|
||||
modify_frame(self, &modifiers, Some(outset));
|
||||
}
|
||||
}
|
||||
|
||||
fn modify_frame(
|
||||
frame: &mut Frame,
|
||||
modifiers: &FrameModifiers,
|
||||
link_box_outset: Option<Sides<Abs>>,
|
||||
) {
|
||||
if let Some(dest) = &modifiers.dest {
|
||||
let mut pos = Point::zero();
|
||||
let mut size = frame.size();
|
||||
if let Some(outset) = link_box_outset {
|
||||
pos.y -= outset.top;
|
||||
pos.x -= outset.left;
|
||||
size += outset.sum_by_axis();
|
||||
}
|
||||
frame.push(pos, FrameItem::Link(dest.clone(), size));
|
||||
}
|
||||
|
||||
if modifiers.hidden {
|
||||
frame.hide();
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs layout and modification in one step.
|
||||
///
|
||||
/// This just runs `layout(styles).modified(&FrameModifiers::get_in(styles))`,
|
||||
|
@ -284,7 +284,6 @@ impl<'a> CurveBuilder<'a> {
|
||||
self.last_point = point;
|
||||
self.last_control_from = point;
|
||||
self.is_started = true;
|
||||
self.is_empty = true;
|
||||
}
|
||||
|
||||
/// Add a line segment.
|
||||
@ -1282,7 +1281,7 @@ impl ControlPoints {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper to draw arcs with Bézier curves.
|
||||
/// Helper to draw arcs with bezier curves.
|
||||
trait CurveExt {
|
||||
fn arc(&mut self, start: Point, center: Point, end: Point);
|
||||
fn arc_move(&mut self, start: Point, center: Point, end: Point);
|
||||
@ -1306,7 +1305,7 @@ impl CurveExt for Curve {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the control points for a Bézier curve that approximates a circular arc for
|
||||
/// Get the control points for a bezier curve that approximates a circular arc for
|
||||
/// a start point, an end point and a center of the circle whose arc connects
|
||||
/// the two.
|
||||
fn bezier_arc_control(start: Point, center: Point, end: Point) -> [Point; 2] {
|
||||
|
@ -29,7 +29,6 @@ csv = { workspace = true }
|
||||
ecow = { workspace = true }
|
||||
flate2 = { workspace = true }
|
||||
fontdb = { workspace = true }
|
||||
glidesort = { workspace = true }
|
||||
hayagriva = { workspace = true }
|
||||
icu_properties = { workspace = true }
|
||||
icu_provider = { workspace = true }
|
||||
@ -39,7 +38,6 @@ indexmap = { workspace = true }
|
||||
kamadak-exif = { workspace = true }
|
||||
kurbo = { workspace = true }
|
||||
lipsum = { workspace = true }
|
||||
memchr = { workspace = true }
|
||||
palette = { workspace = true }
|
||||
phf = { workspace = true }
|
||||
png = { workspace = true }
|
||||
@ -62,7 +60,6 @@ ttf-parser = { workspace = true }
|
||||
two-face = { workspace = true }
|
||||
typed-arena = { workspace = true }
|
||||
unicode-math-class = { workspace = true }
|
||||
unicode-normalization = { workspace = true }
|
||||
unicode-segmentation = { workspace = true }
|
||||
unscanny = { workspace = true }
|
||||
usvg = { workspace = true }
|
||||
|
@ -312,8 +312,7 @@ impl Route<'_> {
|
||||
if !self.within(Route::MAX_SHOW_RULE_DEPTH) {
|
||||
bail!(
|
||||
"maximum show rule depth exceeded";
|
||||
hint: "maybe a show rule matches its own output";
|
||||
hint: "maybe there are too deeply nested elements"
|
||||
hint: "check whether the show rule matches its own output"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
|
@ -172,29 +172,17 @@ impl Array {
|
||||
}
|
||||
|
||||
/// Returns the first item in the array. May be used on the left-hand side
|
||||
/// an assignment. Returns the default value if the array is empty
|
||||
/// or fails with an error is no default value was specified.
|
||||
/// of an assignment. Fails with an error if the array is empty.
|
||||
#[func]
|
||||
pub fn first(
|
||||
&self,
|
||||
/// A default value to return if the array is empty.
|
||||
#[named]
|
||||
default: Option<Value>,
|
||||
) -> StrResult<Value> {
|
||||
self.0.first().cloned().or(default).ok_or_else(array_is_empty)
|
||||
pub fn first(&self) -> StrResult<Value> {
|
||||
self.0.first().cloned().ok_or_else(array_is_empty)
|
||||
}
|
||||
|
||||
/// Returns the last item in the array. May be used on the left-hand side of
|
||||
/// an assignment. Returns the default value if the array is empty
|
||||
/// or fails with an error is no default value was specified.
|
||||
/// an assignment. Fails with an error if the array is empty.
|
||||
#[func]
|
||||
pub fn last(
|
||||
&self,
|
||||
/// A default value to return if the array is empty.
|
||||
#[named]
|
||||
default: Option<Value>,
|
||||
) -> StrResult<Value> {
|
||||
self.0.last().cloned().or(default).ok_or_else(array_is_empty)
|
||||
pub fn last(&self) -> StrResult<Value> {
|
||||
self.0.last().cloned().ok_or_else(array_is_empty)
|
||||
}
|
||||
|
||||
/// Returns the item at the specified index in the array. May be used on the
|
||||
@ -763,7 +751,7 @@ impl Array {
|
||||
///
|
||||
/// ```example
|
||||
/// #let array = (1, 2, 3, 4, 5, 6, 7, 8)
|
||||
/// #array.chunks(3) \
|
||||
/// #array.chunks(3)
|
||||
/// #array.chunks(3, exact: true)
|
||||
/// ```
|
||||
#[func]
|
||||
@ -808,7 +796,7 @@ impl Array {
|
||||
/// function. The sorting algorithm used is stable.
|
||||
///
|
||||
/// Returns an error if two values could not be compared or if the key
|
||||
/// or comparison function (if given) yields an error.
|
||||
/// function (if given) yields an error.
|
||||
///
|
||||
/// To sort according to multiple criteria at once, e.g. in case of equality
|
||||
/// between some criteria, the key function can return an array. The results
|
||||
@ -832,134 +820,33 @@ impl Array {
|
||||
/// determine the keys to sort by.
|
||||
#[named]
|
||||
key: Option<Func>,
|
||||
/// If given, uses this function to compare elements in the array.
|
||||
///
|
||||
/// This function should return a boolean: `{true}` indicates that the
|
||||
/// elements are in order, while `{false}` indicates that they should be
|
||||
/// swapped. To keep the sort stable, if the two elements are equal, the
|
||||
/// function should return `{true}`.
|
||||
///
|
||||
/// If this function does not order the elements properly (e.g., by
|
||||
/// returning `{false}` for both `{(x, y)}` and `{(y, x)}`, or for
|
||||
/// `{(x, x)}`), the resulting array will be in unspecified order.
|
||||
///
|
||||
/// When used together with `key`, `by` will be passed the keys instead
|
||||
/// of the elements.
|
||||
///
|
||||
/// ```example
|
||||
/// #(
|
||||
/// "sorted",
|
||||
/// "by",
|
||||
/// "decreasing",
|
||||
/// "length",
|
||||
/// ).sorted(
|
||||
/// key: s => s.len(),
|
||||
/// by: (l, r) => l >= r,
|
||||
/// )
|
||||
/// ```
|
||||
#[named]
|
||||
by: Option<Func>,
|
||||
) -> SourceResult<Array> {
|
||||
match by {
|
||||
Some(by) => {
|
||||
let mut are_in_order = |mut x, mut y| {
|
||||
if let Some(f) = &key {
|
||||
// We rely on `comemo`'s memoization of function
|
||||
// evaluation to not excessively reevaluate the key.
|
||||
x = f.call(engine, context, [x])?;
|
||||
y = f.call(engine, context, [y])?;
|
||||
let mut result = Ok(());
|
||||
let mut vec = self.0;
|
||||
let mut key_of = |x: Value| match &key {
|
||||
// NOTE: We are relying on `comemo`'s memoization of function
|
||||
// evaluation to not excessively reevaluate the `key`.
|
||||
Some(f) => f.call(engine, context, [x]),
|
||||
None => Ok(x),
|
||||
};
|
||||
vec.make_mut().sort_by(|a, b| {
|
||||
// Until we get `try` blocks :)
|
||||
match (key_of(a.clone()), key_of(b.clone())) {
|
||||
(Ok(a), Ok(b)) => ops::compare(&a, &b).unwrap_or_else(|err| {
|
||||
if result.is_ok() {
|
||||
result = Err(err).at(span);
|
||||
}
|
||||
match by.call(engine, context, [x, y])? {
|
||||
Value::Bool(b) => Ok(b),
|
||||
x => {
|
||||
bail!(
|
||||
span,
|
||||
"expected boolean from `by` function, got {}",
|
||||
x.ty(),
|
||||
)
|
||||
}
|
||||
Ordering::Equal
|
||||
}),
|
||||
(Err(e), _) | (_, Err(e)) => {
|
||||
if result.is_ok() {
|
||||
result = Err(e);
|
||||
}
|
||||
};
|
||||
// If a comparison function is provided, we use `glidesort`
|
||||
// instead of the standard library sorting algorithm to prevent
|
||||
// panics in case the comparison function does not define a
|
||||
// valid order (see https://github.com/typst/typst/pull/5627).
|
||||
let mut result = Ok(());
|
||||
let mut vec = self.0.into_iter().enumerate().collect::<Vec<_>>();
|
||||
glidesort::sort_by(&mut vec, |(i, x), (j, y)| {
|
||||
// Because we use booleans for the comparison function, in
|
||||
// order to keep the sort stable, we need to compare in the
|
||||
// right order.
|
||||
if i < j {
|
||||
// If `x` and `y` appear in this order in the original
|
||||
// array, then we should change their order (i.e.,
|
||||
// return `Ordering::Greater`) iff `y` is strictly less
|
||||
// than `x` (i.e., `compare(x, y)` returns `false`).
|
||||
// Otherwise, we should keep them in the same order
|
||||
// (i.e., return `Ordering::Less`).
|
||||
match are_in_order(x.clone(), y.clone()) {
|
||||
Ok(false) => Ordering::Greater,
|
||||
Ok(true) => Ordering::Less,
|
||||
Err(err) => {
|
||||
if result.is_ok() {
|
||||
result = Err(err);
|
||||
}
|
||||
Ordering::Equal
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If `x` and `y` appear in the opposite order in the
|
||||
// original array, then we should change their order
|
||||
// (i.e., return `Ordering::Less`) iff `x` is strictly
|
||||
// less than `y` (i.e., `compare(y, x)` returns
|
||||
// `false`). Otherwise, we should keep them in the same
|
||||
// order (i.e., return `Ordering::Less`).
|
||||
match are_in_order(y.clone(), x.clone()) {
|
||||
Ok(false) => Ordering::Less,
|
||||
Ok(true) => Ordering::Greater,
|
||||
Err(err) => {
|
||||
if result.is_ok() {
|
||||
result = Err(err);
|
||||
}
|
||||
Ordering::Equal
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
result.map(|()| vec.into_iter().map(|(_, x)| x).collect())
|
||||
Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
None => {
|
||||
let mut key_of = |x: Value| match &key {
|
||||
// We rely on `comemo`'s memoization of function evaluation
|
||||
// to not excessively reevaluate the key.
|
||||
Some(f) => f.call(engine, context, [x]),
|
||||
None => Ok(x),
|
||||
};
|
||||
// If no comparison function is provided, we know the order is
|
||||
// valid, so we can use the standard library sort and prevent an
|
||||
// extra allocation.
|
||||
let mut result = Ok(());
|
||||
let mut vec = self.0;
|
||||
vec.make_mut().sort_by(|a, b| {
|
||||
match (key_of(a.clone()), key_of(b.clone())) {
|
||||
(Ok(a), Ok(b)) => ops::compare(&a, &b).unwrap_or_else(|err| {
|
||||
if result.is_ok() {
|
||||
result = Err(err).at(span);
|
||||
}
|
||||
Ordering::Equal
|
||||
}),
|
||||
(Err(e), _) | (_, Err(e)) => {
|
||||
if result.is_ok() {
|
||||
result = Err(e);
|
||||
}
|
||||
Ordering::Equal
|
||||
}
|
||||
}
|
||||
});
|
||||
result.map(|()| vec.into())
|
||||
}
|
||||
}
|
||||
});
|
||||
result.map(|_| vec.into())
|
||||
}
|
||||
|
||||
/// Deduplicates all items in the array.
|
||||
|
@ -21,7 +21,7 @@ use crate::foundations::{
|
||||
///
|
||||
/// Type casting works as follows:
|
||||
/// - [`Reflect for T`](Reflect) describes the possible Typst values for `T`
|
||||
/// (for documentation and autocomplete).
|
||||
/// (for documentation and autocomplete).
|
||||
/// - [`IntoValue for T`](IntoValue) is for conversion from `T -> Value`
|
||||
/// (infallible)
|
||||
/// - [`FromValue for T`](FromValue) is for conversion from `Value -> T`
|
||||
|
@ -3,7 +3,7 @@ use std::fmt::{self, Debug, Formatter};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::iter::{self, Sum};
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Add, AddAssign, ControlFlow, Deref, DerefMut};
|
||||
use std::ops::{Add, AddAssign, Deref, DerefMut};
|
||||
use std::sync::Arc;
|
||||
|
||||
use comemo::Tracked;
|
||||
@ -414,11 +414,10 @@ impl Content {
|
||||
/// Elements produced in `show` rules will not be included in the results.
|
||||
pub fn query(&self, selector: Selector) -> Vec<Content> {
|
||||
let mut results = Vec::new();
|
||||
self.traverse(&mut |element| -> ControlFlow<()> {
|
||||
self.traverse(&mut |element| {
|
||||
if selector.matches(&element, None) {
|
||||
results.push(element);
|
||||
}
|
||||
ControlFlow::Continue(())
|
||||
});
|
||||
results
|
||||
}
|
||||
@ -428,58 +427,54 @@ impl Content {
|
||||
///
|
||||
/// Elements produced in `show` rules will not be included in the results.
|
||||
pub fn query_first(&self, selector: &Selector) -> Option<Content> {
|
||||
self.traverse(&mut |element| -> ControlFlow<Content> {
|
||||
if selector.matches(&element, None) {
|
||||
ControlFlow::Break(element)
|
||||
} else {
|
||||
ControlFlow::Continue(())
|
||||
let mut result = None;
|
||||
self.traverse(&mut |element| {
|
||||
if result.is_none() && selector.matches(&element, None) {
|
||||
result = Some(element);
|
||||
}
|
||||
})
|
||||
.break_value()
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
/// Extracts the plain text of this content.
|
||||
pub fn plain_text(&self) -> EcoString {
|
||||
let mut text = EcoString::new();
|
||||
self.traverse(&mut |element| -> ControlFlow<()> {
|
||||
self.traverse(&mut |element| {
|
||||
if let Some(textable) = element.with::<dyn PlainText>() {
|
||||
textable.plain_text(&mut text);
|
||||
}
|
||||
ControlFlow::Continue(())
|
||||
});
|
||||
text
|
||||
}
|
||||
|
||||
/// Traverse this content.
|
||||
fn traverse<F, B>(&self, f: &mut F) -> ControlFlow<B>
|
||||
fn traverse<F>(&self, f: &mut F)
|
||||
where
|
||||
F: FnMut(Content) -> ControlFlow<B>,
|
||||
F: FnMut(Content),
|
||||
{
|
||||
f(self.clone());
|
||||
|
||||
self.inner
|
||||
.elem
|
||||
.fields()
|
||||
.into_iter()
|
||||
.for_each(|(_, value)| walk_value(value, f));
|
||||
|
||||
/// Walks a given value to find any content that matches the selector.
|
||||
///
|
||||
/// Returns early if the function gives `ControlFlow::Break`.
|
||||
fn walk_value<F, B>(value: Value, f: &mut F) -> ControlFlow<B>
|
||||
fn walk_value<F>(value: Value, f: &mut F)
|
||||
where
|
||||
F: FnMut(Content) -> ControlFlow<B>,
|
||||
F: FnMut(Content),
|
||||
{
|
||||
match value {
|
||||
Value::Content(content) => content.traverse(f),
|
||||
Value::Array(array) => {
|
||||
for value in array {
|
||||
walk_value(value, f)?;
|
||||
walk_value(value, f);
|
||||
}
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
_ => ControlFlow::Continue(()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Call f on the element itself before recursively iterating its fields.
|
||||
f(self.clone())?;
|
||||
for (_, value) in self.inner.elem.fields() {
|
||||
walk_value(value, f)?;
|
||||
}
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ impl f64 {
|
||||
f64::signum(self)
|
||||
}
|
||||
|
||||
/// Interprets bytes as a float.
|
||||
/// Converts bytes to a float.
|
||||
///
|
||||
/// ```example
|
||||
/// #float.from-bytes(bytes((0, 0, 0, 0, 0, 0, 240, 63))) \
|
||||
@ -120,10 +120,8 @@ impl f64 {
|
||||
pub fn from_bytes(
|
||||
/// The bytes that should be converted to a float.
|
||||
///
|
||||
/// Must have a length of either 4 or 8. The bytes are then
|
||||
/// interpreted in [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754)'s
|
||||
/// binary32 (single-precision) or binary64 (double-precision) format
|
||||
/// depending on the length of the bytes.
|
||||
/// Must be of length exactly 8 so that the result fits into a 64-bit
|
||||
/// float.
|
||||
bytes: Bytes,
|
||||
/// The endianness of the conversion.
|
||||
#[named]
|
||||
@ -160,13 +158,6 @@ impl f64 {
|
||||
#[named]
|
||||
#[default(Endianness::Little)]
|
||||
endian: Endianness,
|
||||
/// The size of the resulting bytes.
|
||||
///
|
||||
/// This must be either 4 or 8. The call will return the
|
||||
/// representation of this float in either
|
||||
/// [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754)'s binary32
|
||||
/// (single-precision) or binary64 (double-precision) format
|
||||
/// depending on the provided size.
|
||||
#[named]
|
||||
#[default(8)]
|
||||
size: u32,
|
||||
|
@ -112,7 +112,7 @@ use crate::foundations::{
|
||||
/// it into another file by writing `{import "foo.typ": alert}`.
|
||||
///
|
||||
/// # Unnamed functions { #unnamed }
|
||||
/// You can also create an unnamed function without creating a binding by
|
||||
/// You can also created an unnamed function without creating a binding by
|
||||
/// specifying a parameter list followed by `=>` and the function body. If your
|
||||
/// function has just one parameter, the parentheses around the parameter list
|
||||
/// are optional. Unnamed functions are mainly useful for show rules, but also
|
||||
@ -437,10 +437,10 @@ impl PartialEq for Func {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<&'static NativeFuncData> for Func {
|
||||
fn eq(&self, other: &&'static NativeFuncData) -> bool {
|
||||
impl PartialEq<&NativeFuncData> for Func {
|
||||
fn eq(&self, other: &&NativeFuncData) -> bool {
|
||||
match &self.repr {
|
||||
Repr::Native(native) => *native == Static(*other),
|
||||
Repr::Native(native) => native.function == other.function,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,6 @@ pub use {
|
||||
indexmap::IndexMap,
|
||||
};
|
||||
|
||||
use comemo::TrackedMut;
|
||||
use ecow::EcoString;
|
||||
use typst_syntax::Spanned;
|
||||
|
||||
@ -298,14 +297,5 @@ pub fn eval(
|
||||
for (key, value) in dict {
|
||||
scope.bind(key.into(), Binding::new(value, span));
|
||||
}
|
||||
|
||||
(engine.routines.eval_string)(
|
||||
engine.routines,
|
||||
engine.world,
|
||||
TrackedMut::reborrow_mut(&mut engine.sink),
|
||||
&text,
|
||||
span,
|
||||
mode,
|
||||
scope,
|
||||
)
|
||||
(engine.routines.eval_string)(engine.routines, engine.world, &text, span, mode, scope)
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use typst_syntax::FileId;
|
||||
use crate::diag::{bail, DeprecationSink, StrResult};
|
||||
use crate::foundations::{repr, ty, Content, Scope, Value};
|
||||
|
||||
/// A module of definitions.
|
||||
/// An module of definitions.
|
||||
///
|
||||
/// A module
|
||||
/// - be built-in
|
||||
|
@ -148,7 +148,9 @@ use crate::loading::{DataSource, Load};
|
||||
#[func(scope)]
|
||||
pub fn plugin(
|
||||
engine: &mut Engine,
|
||||
/// A [path]($syntax/#paths) to a WebAssembly file or raw WebAssembly bytes.
|
||||
/// A path to a WebAssembly file or raw WebAssembly bytes.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
source: Spanned<DataSource>,
|
||||
) -> SourceResult<Module> {
|
||||
let data = source.load(engine.world)?;
|
||||
|
@ -7,13 +7,12 @@ use comemo::Tracked;
|
||||
use ecow::EcoString;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typst_syntax::{Span, Spanned};
|
||||
use unicode_normalization::UnicodeNormalization;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::diag::{bail, At, SourceResult, StrResult};
|
||||
use crate::engine::Engine;
|
||||
use crate::foundations::{
|
||||
cast, dict, func, repr, scope, ty, Array, Bytes, Cast, Context, Decimal, Dict, Func,
|
||||
cast, dict, func, repr, scope, ty, Array, Bytes, Context, Decimal, Dict, Func,
|
||||
IntoValue, Label, Repr, Type, Value, Version,
|
||||
};
|
||||
use crate::layout::Alignment;
|
||||
@ -287,30 +286,6 @@ impl Str {
|
||||
Ok(c.into())
|
||||
}
|
||||
|
||||
/// Normalizes the string to the given Unicode normal form.
|
||||
///
|
||||
/// This is useful when manipulating strings containing Unicode combining
|
||||
/// characters.
|
||||
///
|
||||
/// ```typ
|
||||
/// #assert.eq("é".normalize(form: "nfd"), "e\u{0301}")
|
||||
/// #assert.eq("ſ́".normalize(form: "nfkc"), "ś")
|
||||
/// ```
|
||||
#[func]
|
||||
pub fn normalize(
|
||||
&self,
|
||||
#[named]
|
||||
#[default(UnicodeNormalForm::Nfc)]
|
||||
form: UnicodeNormalForm,
|
||||
) -> Str {
|
||||
match form {
|
||||
UnicodeNormalForm::Nfc => self.nfc().collect(),
|
||||
UnicodeNormalForm::Nfd => self.nfd().collect(),
|
||||
UnicodeNormalForm::Nfkc => self.nfkc().collect(),
|
||||
UnicodeNormalForm::Nfkd => self.nfkd().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the string contains the specified pattern.
|
||||
///
|
||||
/// This method also has dedicated syntax: You can write `{"bc" in "abcd"}`
|
||||
@ -813,25 +788,6 @@ cast! {
|
||||
v: Str => Self::Str(v),
|
||||
}
|
||||
|
||||
/// A Unicode normalization form.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
|
||||
pub enum UnicodeNormalForm {
|
||||
/// Canonical composition where e.g. accented letters are turned into a
|
||||
/// single Unicode codepoint.
|
||||
#[string("nfc")]
|
||||
Nfc,
|
||||
/// Canonical decomposition where e.g. accented letters are split into a
|
||||
/// separate base and diacritic.
|
||||
#[string("nfd")]
|
||||
Nfd,
|
||||
/// Like NFC, but using the Unicode compatibility decompositions.
|
||||
#[string("nfkc")]
|
||||
Nfkc,
|
||||
/// Like NFD, but using the Unicode compatibility decompositions.
|
||||
#[string("nfkd")]
|
||||
Nfkd,
|
||||
}
|
||||
|
||||
/// Convert an item of std's `match_indices` to a dictionary.
|
||||
fn match_to_dict((start, text): (usize, &str)) -> Dict {
|
||||
dict! {
|
||||
|
@ -471,8 +471,7 @@ impl Debug for Recipe {
|
||||
selector.fmt(f)?;
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
self.transform.fmt(f)?;
|
||||
f.write_str(")")
|
||||
self.transform.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ use crate::foundations::{
|
||||
/// be accessed using [field access notation]($scripting/#fields):
|
||||
///
|
||||
/// - General symbols are defined in the [`sym` module]($category/symbols/sym)
|
||||
/// and are accessible without the `sym.` prefix in math mode.
|
||||
/// - Emoji are defined in the [`emoji` module]($category/symbols/emoji)
|
||||
///
|
||||
/// Moreover, you can define custom symbols with this type's constructor
|
||||
@ -411,7 +410,7 @@ fn find<'a>(
|
||||
}
|
||||
|
||||
let score = (matching, Reverse(total));
|
||||
if best_score.is_none_or(|b| score > b) {
|
||||
if best_score.map_or(true, |b| score > b) {
|
||||
best = Some(candidate.1);
|
||||
best_score = Some(score);
|
||||
}
|
||||
|
@ -39,25 +39,11 @@ use crate::foundations::{
|
||||
/// #type(image("glacier.jpg")).
|
||||
/// ```
|
||||
///
|
||||
/// The type of `{10}` is `int`. Now, what is the type of `int` or even `type`?
|
||||
/// The type of `10` is `int`. Now, what is the type of `int` or even `type`?
|
||||
/// ```example
|
||||
/// #type(int) \
|
||||
/// #type(type)
|
||||
/// ```
|
||||
///
|
||||
/// Unlike other types like `int`, [none] and [auto] do not have a name
|
||||
/// representing them. To test if a value is one of these, compare your value to
|
||||
/// them directly, e.g:
|
||||
/// ```example
|
||||
/// #let val = none
|
||||
/// #if val == none [
|
||||
/// Yep, it's none.
|
||||
/// ]
|
||||
/// ```
|
||||
///
|
||||
/// Note that `type` will return [`content`] for all document elements. To
|
||||
/// programmatically determine which kind of content you are dealing with, see
|
||||
/// [`content.func`].
|
||||
#[ty(scope, cast)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Type(Static<NativeTypeData>);
|
||||
|
@ -229,10 +229,10 @@ impl Counter {
|
||||
if self.is_page() {
|
||||
let at_delta =
|
||||
engine.introspector.page(location).get().saturating_sub(at_page.get());
|
||||
at_state.step(NonZeroUsize::ONE, at_delta as u64);
|
||||
at_state.step(NonZeroUsize::ONE, at_delta);
|
||||
let final_delta =
|
||||
engine.introspector.pages().get().saturating_sub(final_page.get());
|
||||
final_state.step(NonZeroUsize::ONE, final_delta as u64);
|
||||
final_state.step(NonZeroUsize::ONE, final_delta);
|
||||
}
|
||||
Ok(CounterState(smallvec![at_state.first(), final_state.first()]))
|
||||
}
|
||||
@ -250,7 +250,7 @@ impl Counter {
|
||||
if self.is_page() {
|
||||
let delta =
|
||||
engine.introspector.page(location).get().saturating_sub(page.get());
|
||||
state.step(NonZeroUsize::ONE, delta as u64);
|
||||
state.step(NonZeroUsize::ONE, delta);
|
||||
}
|
||||
Ok(state)
|
||||
}
|
||||
@ -319,7 +319,7 @@ impl Counter {
|
||||
|
||||
let delta = page.get() - prev.get();
|
||||
if delta > 0 {
|
||||
state.step(NonZeroUsize::ONE, delta as u64);
|
||||
state.step(NonZeroUsize::ONE, delta);
|
||||
}
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ impl Counter {
|
||||
let (mut state, page) = sequence.last().unwrap().clone();
|
||||
if self.is_page() {
|
||||
let delta = engine.introspector.pages().get().saturating_sub(page.get());
|
||||
state.step(NonZeroUsize::ONE, delta as u64);
|
||||
state.step(NonZeroUsize::ONE, delta);
|
||||
}
|
||||
Ok(state)
|
||||
}
|
||||
@ -616,13 +616,13 @@ pub trait Count {
|
||||
|
||||
/// Counts through elements with different levels.
|
||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||
pub struct CounterState(pub SmallVec<[u64; 3]>);
|
||||
pub struct CounterState(pub SmallVec<[usize; 3]>);
|
||||
|
||||
impl CounterState {
|
||||
/// Get the initial counter state for the key.
|
||||
pub fn init(page: bool) -> Self {
|
||||
// Special case, because pages always start at one.
|
||||
Self(smallvec![u64::from(page)])
|
||||
Self(smallvec![usize::from(page)])
|
||||
}
|
||||
|
||||
/// Advance the counter and return the numbers for the given heading.
|
||||
@ -645,7 +645,7 @@ impl CounterState {
|
||||
}
|
||||
|
||||
/// Advance the number of the given level by the specified amount.
|
||||
pub fn step(&mut self, level: NonZeroUsize, by: u64) {
|
||||
pub fn step(&mut self, level: NonZeroUsize, by: usize) {
|
||||
let level = level.get();
|
||||
|
||||
while self.0.len() < level {
|
||||
@ -657,7 +657,7 @@ impl CounterState {
|
||||
}
|
||||
|
||||
/// Get the first number of the state.
|
||||
pub fn first(&self) -> u64 {
|
||||
pub fn first(&self) -> usize {
|
||||
self.0.first().copied().unwrap_or(1)
|
||||
}
|
||||
|
||||
@ -675,7 +675,7 @@ impl CounterState {
|
||||
cast! {
|
||||
CounterState,
|
||||
self => Value::Array(self.0.into_iter().map(IntoValue::into_value).collect()),
|
||||
num: u64 => Self(smallvec![num]),
|
||||
num: usize => Self(smallvec![num]),
|
||||
array: Array => Self(array
|
||||
.into_iter()
|
||||
.map(Value::cast)
|
||||
@ -758,7 +758,7 @@ impl Show for Packed<CounterDisplayElem> {
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct ManualPageCounter {
|
||||
physical: NonZeroUsize,
|
||||
logical: u64,
|
||||
logical: usize,
|
||||
}
|
||||
|
||||
impl ManualPageCounter {
|
||||
@ -773,7 +773,7 @@ impl ManualPageCounter {
|
||||
}
|
||||
|
||||
/// Get the current logical page counter state.
|
||||
pub fn logical(&self) -> u64 {
|
||||
pub fn logical(&self) -> usize {
|
||||
self.logical
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use typst_utils::NonZeroExt;
|
||||
|
||||
use crate::diag::{bail, StrResult};
|
||||
use crate::foundations::{Content, Label, Repr, Selector};
|
||||
use crate::html::HtmlNode;
|
||||
use crate::html::{HtmlElement, HtmlNode};
|
||||
use crate::introspection::{Location, Tag};
|
||||
use crate::layout::{Frame, FrameItem, Page, Point, Position, Transform};
|
||||
use crate::model::Numbering;
|
||||
@ -55,8 +55,8 @@ impl Introspector {
|
||||
|
||||
/// Creates an introspector for HTML.
|
||||
#[typst_macros::time(name = "introspect html")]
|
||||
pub fn html(output: &[HtmlNode]) -> Self {
|
||||
IntrospectorBuilder::new().build_html(output)
|
||||
pub fn html(root: &HtmlElement) -> Self {
|
||||
IntrospectorBuilder::new().build_html(root)
|
||||
}
|
||||
|
||||
/// Iterates over all locatable elements.
|
||||
@ -392,9 +392,9 @@ impl IntrospectorBuilder {
|
||||
}
|
||||
|
||||
/// Build an introspector for an HTML document.
|
||||
fn build_html(mut self, output: &[HtmlNode]) -> Introspector {
|
||||
fn build_html(mut self, root: &HtmlElement) -> Introspector {
|
||||
let mut elems = Vec::new();
|
||||
self.discover_in_html(&mut elems, output);
|
||||
self.discover_in_html(&mut elems, root);
|
||||
self.finalize(elems)
|
||||
}
|
||||
|
||||
@ -434,16 +434,16 @@ impl IntrospectorBuilder {
|
||||
}
|
||||
|
||||
/// Processes the tags in the HTML element.
|
||||
fn discover_in_html(&mut self, sink: &mut Vec<Pair>, nodes: &[HtmlNode]) {
|
||||
for node in nodes {
|
||||
match node {
|
||||
fn discover_in_html(&mut self, sink: &mut Vec<Pair>, elem: &HtmlElement) {
|
||||
for child in &elem.children {
|
||||
match child {
|
||||
HtmlNode::Tag(tag) => self.discover_in_tag(
|
||||
sink,
|
||||
tag,
|
||||
Position { page: NonZeroUsize::ONE, point: Point::zero() },
|
||||
),
|
||||
HtmlNode::Text(_, _) => {}
|
||||
HtmlNode::Element(elem) => self.discover_in_html(sink, &elem.children),
|
||||
HtmlNode::Element(elem) => self.discover_in_html(sink, elem),
|
||||
HtmlNode::Frame(frame) => self.discover_in_frame(
|
||||
sink,
|
||||
frame,
|
||||
|
@ -50,42 +50,6 @@ impl Dir {
|
||||
pub const TTB: Self = Self::TTB;
|
||||
pub const BTT: Self = Self::BTT;
|
||||
|
||||
/// Returns a direction from a starting point.
|
||||
///
|
||||
/// ```example
|
||||
/// direction.from(left) \
|
||||
/// direction.from(right) \
|
||||
/// direction.from(top) \
|
||||
/// direction.from(bottom)
|
||||
/// ```
|
||||
#[func]
|
||||
pub const fn from(side: Side) -> Dir {
|
||||
match side {
|
||||
Side::Left => Self::LTR,
|
||||
Side::Right => Self::RTL,
|
||||
Side::Top => Self::TTB,
|
||||
Side::Bottom => Self::BTT,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a direction from an end point.
|
||||
///
|
||||
/// ```example
|
||||
/// direction.to(left) \
|
||||
/// direction.to(right) \
|
||||
/// direction.to(top) \
|
||||
/// direction.to(bottom)
|
||||
/// ```
|
||||
#[func]
|
||||
pub const fn to(side: Side) -> Dir {
|
||||
match side {
|
||||
Side::Right => Self::LTR,
|
||||
Side::Left => Self::RTL,
|
||||
Side::Bottom => Self::TTB,
|
||||
Side::Top => Self::BTT,
|
||||
}
|
||||
}
|
||||
|
||||
/// The axis this direction belongs to, either `{"horizontal"}` or
|
||||
/// `{"vertical"}`.
|
||||
///
|
||||
@ -101,22 +65,6 @@ impl Dir {
|
||||
}
|
||||
}
|
||||
|
||||
/// The corresponding sign, for use in calculations.
|
||||
///
|
||||
/// ```example
|
||||
/// #ltr.sign() \
|
||||
/// #rtl.sign() \
|
||||
/// #ttb.sign() \
|
||||
/// #btt.sign()
|
||||
/// ```
|
||||
#[func]
|
||||
pub const fn sign(self) -> i64 {
|
||||
match self {
|
||||
Self::LTR | Self::TTB => 1,
|
||||
Self::RTL | Self::BTT => -1,
|
||||
}
|
||||
}
|
||||
|
||||
/// The start point of this direction, as an alignment.
|
||||
///
|
||||
/// ```example
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,8 +22,7 @@ use crate::layout::{BlockElem, Size};
|
||||
/// #let text = lorem(30)
|
||||
/// #layout(size => [
|
||||
/// #let (height,) = measure(
|
||||
/// width: size.width,
|
||||
/// text,
|
||||
/// block(width: size.width, text),
|
||||
/// )
|
||||
/// This text is #height high with
|
||||
/// the current page width: \
|
||||
|
@ -75,10 +75,9 @@ pub struct PageElem {
|
||||
/// The height of the page.
|
||||
///
|
||||
/// If this is set to `{auto}`, page breaks can only be triggered manually
|
||||
/// by inserting a [page break]($pagebreak) or by adding another non-empty
|
||||
/// page set rule. Most examples throughout this documentation use `{auto}`
|
||||
/// for the height of the page to dynamically grow and shrink to fit their
|
||||
/// content.
|
||||
/// by inserting a [page break]($pagebreak). Most examples throughout this
|
||||
/// documentation use `{auto}` for the height of the page to dynamically
|
||||
/// grow and shrink to fit their content.
|
||||
#[resolve]
|
||||
#[parse(
|
||||
args.named("height")?
|
||||
@ -484,7 +483,7 @@ pub struct Page {
|
||||
pub supplement: Content,
|
||||
/// The logical page number (controlled by `counter(page)` and may thus not
|
||||
/// match the physical number).
|
||||
pub number: u64,
|
||||
pub number: usize,
|
||||
}
|
||||
|
||||
impl Page {
|
||||
|
@ -8,35 +8,15 @@ use crate::foundations::{repr, ty, Repr};
|
||||
|
||||
/// A ratio of a whole.
|
||||
///
|
||||
/// A ratio is written as a number, followed by a percent sign. Ratios most
|
||||
/// often appear as part of a [relative length]($relative), to specify the size
|
||||
/// of some layout element relative to the page or some container.
|
||||
/// Written as a number, followed by a percent sign.
|
||||
///
|
||||
/// # Example
|
||||
/// ```example
|
||||
/// #rect(width: 25%)
|
||||
/// #set align(center)
|
||||
/// #scale(x: 150%)[
|
||||
/// Scaled apart.
|
||||
/// ]
|
||||
/// ```
|
||||
///
|
||||
/// However, they can also describe any other property that is relative to some
|
||||
/// base, e.g. an amount of [horizontal scaling]($scale.x) or the
|
||||
/// [height of parentheses]($math.lr.size) relative to the height of the content
|
||||
/// they enclose.
|
||||
///
|
||||
/// # Scripting
|
||||
/// Within your own code, you can use ratios as you like. You can multiply them
|
||||
/// with various other types as shown below:
|
||||
///
|
||||
/// | Multiply by | Example | Result |
|
||||
/// |-----------------|-------------------------|-----------------|
|
||||
/// | [`ratio`] | `{27% * 10%}` | `{2.7%}` |
|
||||
/// | [`length`] | `{27% * 100pt}` | `{27pt}` |
|
||||
/// | [`relative`] | `{27% * (10% + 100pt)}` | `{2.7% + 27pt}` |
|
||||
/// | [`angle`] | `{27% * 100deg}` | `{27deg}` |
|
||||
/// | [`int`] | `{27% * 2}` | `{54%}` |
|
||||
/// | [`float`] | `{27% * 0.37037}` | `{10%}` |
|
||||
/// | [`fraction`] | `{27% * 3fr}` | `{0.81fr}` |
|
||||
///
|
||||
/// When ratios are displayed in the document, they are rounded to two
|
||||
/// significant digits for readability.
|
||||
#[ty(cast)]
|
||||
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct Ratio(Scalar);
|
||||
|
@ -14,58 +14,17 @@ use crate::layout::{Abs, Em, Length, Ratio};
|
||||
/// addition and subtraction of a length and a ratio. Wherever a relative length
|
||||
/// is expected, you can also use a bare length or ratio.
|
||||
///
|
||||
/// # Relative to the page
|
||||
/// A common use case is setting the width or height of a layout element (e.g.,
|
||||
/// [block], [rect], etc.) as a certain percentage of the width of the page.
|
||||
/// Here, the rectangle's width is set to `{25%}`, so it takes up one fourth of
|
||||
/// the page's _inner_ width (the width minus margins).
|
||||
///
|
||||
/// # Example
|
||||
/// ```example
|
||||
/// #rect(width: 25%)
|
||||
/// #rect(width: 100% - 50pt)
|
||||
///
|
||||
/// #(100% - 50pt).length \
|
||||
/// #(100% - 50pt).ratio
|
||||
/// ```
|
||||
///
|
||||
/// Bare lengths or ratios are always valid where relative lengths are expected,
|
||||
/// but the two can also be freely mixed:
|
||||
/// ```example
|
||||
/// #rect(width: 25% + 1cm)
|
||||
/// ```
|
||||
///
|
||||
/// If you're trying to size an element so that it takes up the page's _full_
|
||||
/// width, you have a few options (this highly depends on your exact use case):
|
||||
///
|
||||
/// 1. Set page margins to `{0pt}` (`[#set page(margin: 0pt)]`)
|
||||
/// 2. Multiply the ratio by the known full page width (`{21cm * 69%}`)
|
||||
/// 3. Use padding which will negate the margins (`[#pad(x: -2.5cm, ...)]`)
|
||||
/// 4. Use the page [background](page.background) or
|
||||
/// [foreground](page.foreground) field as those don't take margins into
|
||||
/// account (note that it will render the content outside of the document
|
||||
/// flow, see [place] to control the content position)
|
||||
///
|
||||
/// # Relative to a container
|
||||
/// When a layout element (e.g. a [rect]) is nested in another layout container
|
||||
/// (e.g. a [block]) instead of being a direct descendant of the page, relative
|
||||
/// widths become relative to the container:
|
||||
///
|
||||
/// ```example
|
||||
/// #block(
|
||||
/// width: 100pt,
|
||||
/// fill: aqua,
|
||||
/// rect(width: 50%),
|
||||
/// )
|
||||
/// ```
|
||||
///
|
||||
/// # Scripting
|
||||
/// You can multiply relative lengths by [ratios]($ratio), [integers]($int), and
|
||||
/// [floats]($float).
|
||||
///
|
||||
/// A relative length has the following fields:
|
||||
/// - `length`: Its length component.
|
||||
/// - `ratio`: Its ratio component.
|
||||
///
|
||||
/// ```example
|
||||
/// #(100% - 50pt).length \
|
||||
/// #(100% - 50pt).ratio
|
||||
/// ```
|
||||
#[ty(cast, name = "relative", title = "Relative Length")]
|
||||
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Rel<T: Numeric = Length> {
|
||||
|
@ -307,20 +307,6 @@ impl Transform {
|
||||
Self { sx, sy, ..Self::identity() }
|
||||
}
|
||||
|
||||
/// A scale transform at a specific position.
|
||||
pub fn scale_at(sx: Ratio, sy: Ratio, px: Abs, py: Abs) -> Self {
|
||||
Self::translate(px, py)
|
||||
.pre_concat(Self::scale(sx, sy))
|
||||
.pre_concat(Self::translate(-px, -py))
|
||||
}
|
||||
|
||||
/// A rotate transform at a specific position.
|
||||
pub fn rotate_at(angle: Angle, px: Abs, py: Abs) -> Self {
|
||||
Self::translate(px, py)
|
||||
.pre_concat(Self::rotate(angle))
|
||||
.pre_concat(Self::translate(-px, -py))
|
||||
}
|
||||
|
||||
/// A rotate transform.
|
||||
pub fn rotate(angle: Angle) -> Self {
|
||||
let cos = Ratio::new(angle.cos());
|
||||
|
@ -20,7 +20,9 @@ use crate::loading::{DataSource, Load};
|
||||
#[func(scope, title = "CBOR")]
|
||||
pub fn cbor(
|
||||
engine: &mut Engine,
|
||||
/// A [path]($syntax/#paths) to a CBOR file or raw CBOR bytes.
|
||||
/// A path to a CBOR file or raw CBOR bytes.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
source: Spanned<DataSource>,
|
||||
) -> SourceResult<Value> {
|
||||
let data = source.load(engine.world)?;
|
||||
|
@ -26,7 +26,9 @@ use crate::loading::{DataSource, Load, Readable};
|
||||
#[func(scope, title = "CSV")]
|
||||
pub fn csv(
|
||||
engine: &mut Engine,
|
||||
/// A [path]($syntax/#paths) to a CSV file or raw CSV bytes.
|
||||
/// Path to a CSV file or raw CSV bytes.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
source: Spanned<DataSource>,
|
||||
/// The delimiter that separates columns in the CSV file.
|
||||
/// Must be a single ASCII character.
|
||||
|
@ -51,7 +51,9 @@ use crate::loading::{DataSource, Load, Readable};
|
||||
#[func(scope, title = "JSON")]
|
||||
pub fn json(
|
||||
engine: &mut Engine,
|
||||
/// A [path]($syntax/#paths) to a JSON file or raw JSON bytes.
|
||||
/// Path to a JSON file or raw JSON bytes.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
source: Spanned<DataSource>,
|
||||
) -> SourceResult<Value> {
|
||||
let data = source.load(engine.world)?;
|
||||
|
@ -29,7 +29,9 @@ use crate::loading::{DataSource, Load, Readable};
|
||||
#[func(scope, title = "TOML")]
|
||||
pub fn toml(
|
||||
engine: &mut Engine,
|
||||
/// A [path]($syntax/#paths) to a TOML file or raw TOML bytes.
|
||||
/// A path to a TOML file or raw TOML bytes.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
source: Spanned<DataSource>,
|
||||
) -> SourceResult<Value> {
|
||||
let data = source.load(engine.world)?;
|
||||
|
@ -34,14 +34,14 @@ use crate::loading::{DataSource, Load, Readable};
|
||||
/// let author = find-child(elem, "author")
|
||||
/// let pars = find-child(elem, "content")
|
||||
///
|
||||
/// [= #title.children.first()]
|
||||
/// heading(title.children.first())
|
||||
/// text(10pt, weight: "medium")[
|
||||
/// Published by
|
||||
/// #author.children.first()
|
||||
/// ]
|
||||
///
|
||||
/// for p in pars.children {
|
||||
/// if type(p) == dictionary {
|
||||
/// if (type(p) == "dictionary") {
|
||||
/// parbreak()
|
||||
/// p.children.first()
|
||||
/// }
|
||||
@ -50,7 +50,7 @@ use crate::loading::{DataSource, Load, Readable};
|
||||
///
|
||||
/// #let data = xml("example.xml")
|
||||
/// #for elem in data.first().children {
|
||||
/// if type(elem) == dictionary {
|
||||
/// if (type(elem) == "dictionary") {
|
||||
/// article(elem)
|
||||
/// }
|
||||
/// }
|
||||
@ -58,7 +58,9 @@ use crate::loading::{DataSource, Load, Readable};
|
||||
#[func(scope, title = "XML")]
|
||||
pub fn xml(
|
||||
engine: &mut Engine,
|
||||
/// A [path]($syntax/#paths) to an XML file or raw XML bytes.
|
||||
/// A path to an XML file or raw XML bytes.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
source: Spanned<DataSource>,
|
||||
) -> SourceResult<Value> {
|
||||
let data = source.load(engine.world)?;
|
||||
|
@ -41,7 +41,9 @@ use crate::loading::{DataSource, Load, Readable};
|
||||
#[func(scope, title = "YAML")]
|
||||
pub fn yaml(
|
||||
engine: &mut Engine,
|
||||
/// A [path]($syntax/#paths) to a YAML file or raw YAML bytes.
|
||||
/// A path to a YAML file or raw YAML bytes.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
source: Spanned<DataSource>,
|
||||
) -> SourceResult<Value> {
|
||||
let data = source.load(engine.world)?;
|
||||
|
@ -13,8 +13,8 @@ use crate::math::Mathy;
|
||||
/// ```
|
||||
#[elem(Mathy)]
|
||||
pub struct AccentElem {
|
||||
/// The base to which the accent is applied. May consist of multiple
|
||||
/// letters.
|
||||
/// The base to which the accent is applied.
|
||||
/// May consist of multiple letters.
|
||||
///
|
||||
/// ```example
|
||||
/// $arrow(A B C)$
|
||||
@ -51,24 +51,9 @@ pub struct AccentElem {
|
||||
pub accent: Accent,
|
||||
|
||||
/// The size of the accent, relative to the width of the base.
|
||||
///
|
||||
/// ```example
|
||||
/// $dash(A, size: #150%)$
|
||||
/// ```
|
||||
#[resolve]
|
||||
#[default(Rel::one())]
|
||||
pub size: Rel<Length>,
|
||||
|
||||
/// Whether to remove the dot on top of lowercase i and j when adding a top
|
||||
/// accent.
|
||||
///
|
||||
/// This enables the `dtls` OpenType feature.
|
||||
///
|
||||
/// ```example
|
||||
/// $hat(dotless: #false, i)$
|
||||
/// ```
|
||||
#[default(true)]
|
||||
pub dotless: bool,
|
||||
}
|
||||
|
||||
/// An accent character.
|
||||
@ -118,18 +103,11 @@ macro_rules! accents {
|
||||
/// The size of the accent, relative to the width of the base.
|
||||
#[named]
|
||||
size: Option<Rel<Length>>,
|
||||
/// Whether to remove the dot on top of lowercase i and j when
|
||||
/// adding a top accent.
|
||||
#[named]
|
||||
dotless: Option<bool>,
|
||||
) -> Content {
|
||||
let mut accent = AccentElem::new(base, Accent::new($primary));
|
||||
if let Some(size) = size {
|
||||
accent = accent.with_size(size);
|
||||
}
|
||||
if let Some(dotless) = dotless {
|
||||
accent = accent.with_dotless(dotless);
|
||||
}
|
||||
accent.pack()
|
||||
}
|
||||
)+
|
||||
|
@ -15,7 +15,7 @@ use crate::math::Mathy;
|
||||
/// # Syntax
|
||||
/// This function also has dedicated syntax: Use a slash to turn neighbouring
|
||||
/// expressions into a fraction. Multiple atoms can be grouped into a single
|
||||
/// expression using round grouping parentheses. Such parentheses are removed
|
||||
/// expression using round grouping parenthesis. Such parentheses are removed
|
||||
/// from the output, but you can nest multiple to force them.
|
||||
#[elem(title = "Fraction", Mathy)]
|
||||
pub struct FracElem {
|
||||
|
@ -6,7 +6,7 @@ use std::num::NonZeroUsize;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
use comemo::{Track, Tracked};
|
||||
use comemo::Tracked;
|
||||
use ecow::{eco_format, EcoString, EcoVec};
|
||||
use hayagriva::archive::ArchivedStyle;
|
||||
use hayagriva::io::BibLaTeXError;
|
||||
@ -20,7 +20,7 @@ use typst_syntax::{Span, Spanned};
|
||||
use typst_utils::{Get, ManuallyHash, NonZeroExt, PicoStr};
|
||||
|
||||
use crate::diag::{bail, error, At, FileError, HintedStrResult, SourceResult, StrResult};
|
||||
use crate::engine::{Engine, Sink};
|
||||
use crate::engine::Engine;
|
||||
use crate::foundations::{
|
||||
elem, Bytes, CastInfo, Content, Derived, FromValue, IntoValue, Label, NativeElement,
|
||||
OneOrMultiple, Packed, Reflect, Scope, Show, ShowSet, Smart, StyleChain, Styles,
|
||||
@ -94,7 +94,7 @@ pub struct BibliographyElem {
|
||||
/// - A path string to load a bibliography file from the given path. For
|
||||
/// more details about paths, see the [Paths section]($syntax/#paths).
|
||||
/// - Raw bytes from which the bibliography should be decoded.
|
||||
/// - An array where each item is one of the above.
|
||||
/// - An array where each item is one the above.
|
||||
#[required]
|
||||
#[parse(
|
||||
let sources = args.expect("sources")?;
|
||||
@ -999,8 +999,6 @@ impl ElemRenderer<'_> {
|
||||
(self.routines.eval_string)(
|
||||
self.routines,
|
||||
self.world,
|
||||
// TODO: propagate warnings
|
||||
Sink::new().track_mut(),
|
||||
math,
|
||||
self.span,
|
||||
EvalMode::Math,
|
||||
|
@ -129,7 +129,7 @@ pub struct EnumElem {
|
||||
/// [Ahead],
|
||||
/// )
|
||||
/// ```
|
||||
pub start: Smart<u64>,
|
||||
pub start: Smart<usize>,
|
||||
|
||||
/// Whether to display the full numbering, including the numbers of
|
||||
/// all parent enumerations.
|
||||
@ -217,7 +217,7 @@ pub struct EnumElem {
|
||||
#[internal]
|
||||
#[fold]
|
||||
#[ghost]
|
||||
pub parents: SmallVec<[u64; 4]>,
|
||||
pub parents: SmallVec<[usize; 4]>,
|
||||
}
|
||||
|
||||
#[scope]
|
||||
@ -259,11 +259,10 @@ impl Show for Packed<EnumElem> {
|
||||
.spanned(self.span());
|
||||
|
||||
if tight {
|
||||
let spacing = self
|
||||
.spacing(styles)
|
||||
.unwrap_or_else(|| ParElem::leading_in(styles).into());
|
||||
let v = VElem::new(spacing.into()).with_weak(true).with_attach(true).pack();
|
||||
realized = v + realized;
|
||||
let leading = ParElem::leading_in(styles);
|
||||
let spacing =
|
||||
VElem::new(leading.into()).with_weak(true).with_attach(true).pack();
|
||||
realized = spacing + realized;
|
||||
}
|
||||
|
||||
Ok(realized)
|
||||
@ -275,7 +274,7 @@ impl Show for Packed<EnumElem> {
|
||||
pub struct EnumItem {
|
||||
/// The item's number.
|
||||
#[positional]
|
||||
pub number: Option<u64>,
|
||||
pub number: Option<usize>,
|
||||
|
||||
/// The item's body.
|
||||
#[required]
|
||||
|
@ -457,7 +457,7 @@ impl Outlinable for Packed<FigureElem> {
|
||||
/// customize the appearance of captions for all figures or figures of a
|
||||
/// specific kind.
|
||||
///
|
||||
/// In addition to its `position` and `body`, the `caption` also provides the
|
||||
/// In addition to its `pos` and `body`, the `caption` also provides the
|
||||
/// figure's `kind`, `supplement`, `counter`, and `numbering` as fields. These
|
||||
/// parts can be used in [`where`]($function.where) selectors and show rules to
|
||||
/// build a completely custom caption.
|
||||
|
@ -11,7 +11,7 @@ use crate::foundations::{
|
||||
use crate::html::{attr, tag, HtmlElem};
|
||||
use crate::introspection::Location;
|
||||
use crate::layout::Position;
|
||||
use crate::text::TextElem;
|
||||
use crate::text::{Hyphenate, TextElem};
|
||||
|
||||
/// Links to a URL or a location in the document.
|
||||
///
|
||||
@ -138,7 +138,7 @@ impl Show for Packed<LinkElem> {
|
||||
impl ShowSet for Packed<LinkElem> {
|
||||
fn show_set(&self, _: StyleChain) -> Styles {
|
||||
let mut out = Styles::new();
|
||||
out.set(TextElem::set_hyphenate(Smart::Custom(false)));
|
||||
out.set(TextElem::set_hyphenate(Hyphenate(Smart::Custom(false))));
|
||||
out
|
||||
}
|
||||
}
|
||||
|
@ -166,11 +166,10 @@ impl Show for Packed<ListElem> {
|
||||
.spanned(self.span());
|
||||
|
||||
if tight {
|
||||
let spacing = self
|
||||
.spacing(styles)
|
||||
.unwrap_or_else(|| ParElem::leading_in(styles).into());
|
||||
let v = VElem::new(spacing.into()).with_weak(true).with_attach(true).pack();
|
||||
realized = v + realized;
|
||||
let leading = ParElem::leading_in(styles);
|
||||
let spacing =
|
||||
VElem::new(leading.into()).with_weak(true).with_attach(true).pack();
|
||||
realized = spacing + realized;
|
||||
}
|
||||
|
||||
Ok(realized)
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use chinese_number::{
|
||||
from_u64_to_chinese_ten_thousand as u64_to_chinese, ChineseCase, ChineseVariant,
|
||||
from_usize_to_chinese_ten_thousand as usize_to_chinese, ChineseCase, ChineseVariant,
|
||||
};
|
||||
use comemo::Tracked;
|
||||
use ecow::{eco_format, EcoString, EcoVec};
|
||||
@ -85,7 +85,7 @@ pub fn numbering(
|
||||
/// If `numbering` is a pattern and more numbers than counting symbols are
|
||||
/// given, the last counting symbol with its prefix is repeated.
|
||||
#[variadic]
|
||||
numbers: Vec<u64>,
|
||||
numbers: Vec<usize>,
|
||||
) -> SourceResult<Value> {
|
||||
numbering.apply(engine, context, &numbers)
|
||||
}
|
||||
@ -105,7 +105,7 @@ impl Numbering {
|
||||
&self,
|
||||
engine: &mut Engine,
|
||||
context: Tracked<Context>,
|
||||
numbers: &[u64],
|
||||
numbers: &[usize],
|
||||
) -> SourceResult<Value> {
|
||||
Ok(match self {
|
||||
Self::Pattern(pattern) => Value::Str(pattern.apply(numbers).into()),
|
||||
@ -156,7 +156,7 @@ pub struct NumberingPattern {
|
||||
|
||||
impl NumberingPattern {
|
||||
/// Apply the pattern to the given number.
|
||||
pub fn apply(&self, numbers: &[u64]) -> EcoString {
|
||||
pub fn apply(&self, numbers: &[usize]) -> EcoString {
|
||||
let mut fmt = EcoString::new();
|
||||
let mut numbers = numbers.iter();
|
||||
|
||||
@ -185,7 +185,7 @@ impl NumberingPattern {
|
||||
}
|
||||
|
||||
/// Apply only the k-th segment of the pattern to a number.
|
||||
pub fn apply_kth(&self, k: usize, number: u64) -> EcoString {
|
||||
pub fn apply_kth(&self, k: usize, number: usize) -> EcoString {
|
||||
let mut fmt = EcoString::new();
|
||||
if let Some((prefix, _)) = self.pieces.first() {
|
||||
fmt.push_str(prefix);
|
||||
@ -379,7 +379,7 @@ impl NumberingKind {
|
||||
}
|
||||
|
||||
/// Apply the numbering to the given number.
|
||||
pub fn apply(self, n: u64) -> EcoString {
|
||||
pub fn apply(self, n: usize) -> EcoString {
|
||||
match self {
|
||||
Self::Arabic => eco_format!("{n}"),
|
||||
Self::LowerRoman => roman_numeral(n, Case::Lower),
|
||||
@ -392,10 +392,9 @@ impl NumberingKind {
|
||||
}
|
||||
|
||||
const SYMBOLS: &[char] = &['*', '†', '‡', '§', '¶', '‖'];
|
||||
let n_symbols = SYMBOLS.len() as u64;
|
||||
let symbol = SYMBOLS[((n - 1) % n_symbols) as usize];
|
||||
let amount = ((n - 1) / n_symbols) + 1;
|
||||
std::iter::repeat_n(symbol, amount.try_into().unwrap()).collect()
|
||||
let symbol = SYMBOLS[(n - 1) % SYMBOLS.len()];
|
||||
let amount = ((n - 1) / SYMBOLS.len()) + 1;
|
||||
std::iter::repeat(symbol).take(amount).collect()
|
||||
}
|
||||
Self::Hebrew => hebrew_numeral(n),
|
||||
|
||||
@ -490,16 +489,18 @@ impl NumberingKind {
|
||||
}
|
||||
|
||||
Self::LowerSimplifiedChinese => {
|
||||
u64_to_chinese(ChineseVariant::Simple, ChineseCase::Lower, n).into()
|
||||
usize_to_chinese(ChineseVariant::Simple, ChineseCase::Lower, n).into()
|
||||
}
|
||||
Self::UpperSimplifiedChinese => {
|
||||
u64_to_chinese(ChineseVariant::Simple, ChineseCase::Upper, n).into()
|
||||
usize_to_chinese(ChineseVariant::Simple, ChineseCase::Upper, n).into()
|
||||
}
|
||||
Self::LowerTraditionalChinese => {
|
||||
u64_to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, n).into()
|
||||
usize_to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, n)
|
||||
.into()
|
||||
}
|
||||
Self::UpperTraditionalChinese => {
|
||||
u64_to_chinese(ChineseVariant::Traditional, ChineseCase::Upper, n).into()
|
||||
usize_to_chinese(ChineseVariant::Traditional, ChineseCase::Upper, n)
|
||||
.into()
|
||||
}
|
||||
|
||||
Self::EasternArabic => decimal('\u{0660}', n),
|
||||
@ -511,7 +512,7 @@ impl NumberingKind {
|
||||
}
|
||||
|
||||
/// Stringify an integer to a Hebrew number.
|
||||
fn hebrew_numeral(mut n: u64) -> EcoString {
|
||||
fn hebrew_numeral(mut n: usize) -> EcoString {
|
||||
if n == 0 {
|
||||
return '-'.into();
|
||||
}
|
||||
@ -565,7 +566,7 @@ fn hebrew_numeral(mut n: u64) -> EcoString {
|
||||
}
|
||||
|
||||
/// Stringify an integer to a Roman numeral.
|
||||
fn roman_numeral(mut n: u64, case: Case) -> EcoString {
|
||||
fn roman_numeral(mut n: usize, case: Case) -> EcoString {
|
||||
if n == 0 {
|
||||
return match case {
|
||||
Case::Lower => 'n'.into(),
|
||||
@ -621,7 +622,7 @@ fn roman_numeral(mut n: u64, case: Case) -> EcoString {
|
||||
///
|
||||
/// [converter]: https://www.russellcottrell.com/greek/utilities/GreekNumberConverter.htm
|
||||
/// [numbers]: https://mathshistory.st-andrews.ac.uk/HistTopics/Greek_numbers/
|
||||
fn greek_numeral(n: u64, case: Case) -> EcoString {
|
||||
fn greek_numeral(n: usize, case: Case) -> EcoString {
|
||||
let thousands = [
|
||||
["͵α", "͵Α"],
|
||||
["͵β", "͵Β"],
|
||||
@ -682,7 +683,7 @@ fn greek_numeral(n: u64, case: Case) -> EcoString {
|
||||
let mut decimal_digits: Vec<usize> = Vec::new();
|
||||
let mut n = n;
|
||||
while n > 0 {
|
||||
decimal_digits.push((n % 10) as usize);
|
||||
decimal_digits.push(n % 10);
|
||||
n /= 10;
|
||||
}
|
||||
|
||||
@ -777,16 +778,18 @@ fn greek_numeral(n: u64, case: Case) -> EcoString {
|
||||
///
|
||||
/// You might be familiar with this scheme from the way spreadsheet software
|
||||
/// tends to label its columns.
|
||||
fn zeroless<const N_DIGITS: usize>(alphabet: [char; N_DIGITS], mut n: u64) -> EcoString {
|
||||
fn zeroless<const N_DIGITS: usize>(
|
||||
alphabet: [char; N_DIGITS],
|
||||
mut n: usize,
|
||||
) -> EcoString {
|
||||
if n == 0 {
|
||||
return '-'.into();
|
||||
}
|
||||
let n_digits = N_DIGITS as u64;
|
||||
let mut cs = EcoString::new();
|
||||
while n > 0 {
|
||||
n -= 1;
|
||||
cs.push(alphabet[(n % n_digits) as usize]);
|
||||
n /= n_digits;
|
||||
cs.push(alphabet[n % N_DIGITS]);
|
||||
n /= N_DIGITS;
|
||||
}
|
||||
cs.chars().rev().collect()
|
||||
}
|
||||
@ -794,7 +797,7 @@ fn zeroless<const N_DIGITS: usize>(alphabet: [char; N_DIGITS], mut n: u64) -> Ec
|
||||
/// Stringify a number using a base-10 counting system with a zero digit.
|
||||
///
|
||||
/// This function assumes that the digits occupy contiguous codepoints.
|
||||
fn decimal(start: char, mut n: u64) -> EcoString {
|
||||
fn decimal(start: char, mut n: usize) -> EcoString {
|
||||
if n == 0 {
|
||||
return start.into();
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ pub struct OutlineEntry {
|
||||
/// space between the entry's body and the page number. When using show
|
||||
/// rules to override outline entries, it is thus recommended to wrap the
|
||||
/// fill in a [`box`] with fractional width, i.e.
|
||||
/// `{box(width: 1fr, it.fill)}`.
|
||||
/// `{box(width: 1fr, it.fill}`.
|
||||
///
|
||||
/// When using [`repeat`], the [`gap`]($repeat.gap) property can be useful
|
||||
/// to tweak the visual weight of the fill.
|
||||
@ -623,7 +623,7 @@ impl OutlineEntry {
|
||||
|
||||
/// The content which is displayed in place of the referred element at its
|
||||
/// entry in the outline. For a heading, this is its
|
||||
/// [`body`]($heading.body); for a figure a caption and for equations, it is
|
||||
/// [`body`]($heading.body), for a figure a caption, and for equations it is
|
||||
/// empty.
|
||||
#[func]
|
||||
pub fn body(&self) -> StrResult<Content> {
|
||||
|
@ -161,7 +161,7 @@ impl Show for Packed<QuoteElem> {
|
||||
let block = self.block(styles);
|
||||
let html = TargetElem::target_in(styles).is_html();
|
||||
|
||||
if self.quotes(styles).unwrap_or(!block) {
|
||||
if self.quotes(styles) == Smart::Custom(true) || !block {
|
||||
let quotes = SmartQuotes::get(
|
||||
SmartQuoteElem::quotes_in(styles),
|
||||
TextElem::lang_in(styles),
|
||||
|
@ -282,7 +282,7 @@ fn show_cell_html(tag: HtmlTag, cell: &Cell, styles: StyleChain) -> Content {
|
||||
|
||||
fn show_cellgrid_html(grid: CellGrid, styles: StyleChain) -> Content {
|
||||
let elem = |tag, body| HtmlElem::new(tag).with_body(Some(body)).pack();
|
||||
let mut rows: Vec<_> = grid.entries.chunks(grid.non_gutter_column_count()).collect();
|
||||
let mut rows: Vec<_> = grid.entries.chunks(grid.cols.len()).collect();
|
||||
|
||||
let tr = |tag, row: &[Entry]| {
|
||||
let row = row
|
||||
|
@ -189,15 +189,13 @@ impl Show for Packed<TermsElem> {
|
||||
.styled(TermsElem::set_within(true));
|
||||
|
||||
if tight {
|
||||
let spacing = self
|
||||
.spacing(styles)
|
||||
.unwrap_or_else(|| ParElem::leading_in(styles).into());
|
||||
let v = VElem::new(spacing.into())
|
||||
let leading = ParElem::leading_in(styles);
|
||||
let spacing = VElem::new(leading.into())
|
||||
.with_weak(true)
|
||||
.with_attach(true)
|
||||
.pack()
|
||||
.spanned(span);
|
||||
realized = v + realized;
|
||||
realized = spacing + realized;
|
||||
}
|
||||
|
||||
Ok(realized)
|
||||
|
@ -1,12 +1,9 @@
|
||||
use ecow::EcoString;
|
||||
use typst_library::foundations::Target;
|
||||
use typst_syntax::Spanned;
|
||||
|
||||
use crate::diag::{warning, At, SourceResult};
|
||||
use crate::diag::{At, SourceResult};
|
||||
use crate::engine::Engine;
|
||||
use crate::foundations::{
|
||||
elem, Bytes, Cast, Content, Derived, Packed, Show, StyleChain, TargetElem,
|
||||
};
|
||||
use crate::foundations::{elem, Bytes, Cast, Content, Derived, Packed, Show, StyleChain};
|
||||
use crate::introspection::Locatable;
|
||||
use crate::World;
|
||||
|
||||
@ -35,10 +32,12 @@ use crate::World;
|
||||
/// embedded file conforms to PDF/A-1 or PDF/A-2.
|
||||
#[elem(Show, Locatable)]
|
||||
pub struct EmbedElem {
|
||||
/// The [path]($syntax/#paths) of the file to be embedded.
|
||||
/// Path of the file to be embedded.
|
||||
///
|
||||
/// Must always be specified, but is only read from if no data is provided
|
||||
/// in the following argument.
|
||||
///
|
||||
/// For more details about paths, see the [Paths section]($syntax/#paths).
|
||||
#[required]
|
||||
#[parse(
|
||||
let Spanned { v: path, span } =
|
||||
@ -81,12 +80,7 @@ pub struct EmbedElem {
|
||||
}
|
||||
|
||||
impl Show for Packed<EmbedElem> {
|
||||
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
||||
if TargetElem::target_in(styles) == Target::Html {
|
||||
engine
|
||||
.sink
|
||||
.warn(warning!(self.span(), "embed was ignored during HTML export"));
|
||||
}
|
||||
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
|
||||
Ok(Content::empty())
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ routines! {
|
||||
fn eval_string(
|
||||
routines: &Routines,
|
||||
world: Tracked<dyn World + '_>,
|
||||
sink: TrackedMut<Sink>,
|
||||
string: &str,
|
||||
span: Span,
|
||||
mode: EvalMode,
|
||||
|
@ -160,7 +160,7 @@ impl FontBook {
|
||||
current.variant.weight.distance(variant.weight),
|
||||
);
|
||||
|
||||
if best_key.is_none_or(|b| key < b) {
|
||||
if best_key.map_or(true, |b| key < b) {
|
||||
best = Some(id);
|
||||
best_key = Some(key);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ macro_rules! translation {
|
||||
};
|
||||
}
|
||||
|
||||
const TRANSLATIONS: [(&str, &str); 39] = [
|
||||
const TRANSLATIONS: [(&str, &str); 38] = [
|
||||
translation!("ar"),
|
||||
translation!("bg"),
|
||||
translation!("ca"),
|
||||
@ -31,7 +31,6 @@ const TRANSLATIONS: [(&str, &str); 39] = [
|
||||
translation!("el"),
|
||||
translation!("he"),
|
||||
translation!("hu"),
|
||||
translation!("id"),
|
||||
translation!("is"),
|
||||
translation!("it"),
|
||||
translation!("ja"),
|
||||
@ -83,7 +82,6 @@ impl Lang {
|
||||
pub const HEBREW: Self = Self(*b"he ", 2);
|
||||
pub const HUNGARIAN: Self = Self(*b"hu ", 2);
|
||||
pub const ICELANDIC: Self = Self(*b"is ", 2);
|
||||
pub const INDONESIAN: Self = Self(*b"id ", 2);
|
||||
pub const ITALIAN: Self = Self(*b"it ", 2);
|
||||
pub const JAPANESE: Self = Self(*b"ja ", 2);
|
||||
pub const LATIN: Self = Self(*b"la ", 2);
|
||||
|
@ -42,7 +42,7 @@ use ttf_parser::Tag;
|
||||
use typst_syntax::Spanned;
|
||||
use typst_utils::singleton;
|
||||
|
||||
use crate::diag::{bail, warning, HintedStrResult, SourceResult, StrResult};
|
||||
use crate::diag::{bail, warning, HintedStrResult, SourceResult};
|
||||
use crate::engine::Engine;
|
||||
use crate::foundations::{
|
||||
cast, dict, elem, Args, Array, Cast, Construct, Content, Dict, Fold, IntoValue,
|
||||
@ -51,6 +51,7 @@ use crate::foundations::{
|
||||
};
|
||||
use crate::layout::{Abs, Axis, Dir, Em, Length, Ratio, Rel};
|
||||
use crate::math::{EquationElem, MathSize};
|
||||
use crate::model::ParElem;
|
||||
use crate::visualize::{Color, Paint, RelativeTo, Stroke};
|
||||
use crate::World;
|
||||
|
||||
@ -503,8 +504,9 @@ pub struct TextElem {
|
||||
/// enabling hyphenation can
|
||||
/// improve justification.
|
||||
/// ```
|
||||
#[resolve]
|
||||
#[ghost]
|
||||
pub hyphenate: Smart<bool>,
|
||||
pub hyphenate: Hyphenate,
|
||||
|
||||
/// The "cost" of various choices when laying out text. A higher cost means
|
||||
/// the layout engine will make the choice less often. Costs are specified
|
||||
@ -891,21 +893,9 @@ cast! {
|
||||
}
|
||||
|
||||
/// Font family fallback list.
|
||||
///
|
||||
/// Must contain at least one font.
|
||||
#[derive(Debug, Default, Clone, PartialEq, Hash)]
|
||||
pub struct FontList(pub Vec<FontFamily>);
|
||||
|
||||
impl FontList {
|
||||
pub fn new(fonts: Vec<FontFamily>) -> StrResult<Self> {
|
||||
if fonts.is_empty() {
|
||||
bail!("font fallback list must not be empty")
|
||||
} else {
|
||||
Ok(Self(fonts))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a FontList {
|
||||
type IntoIter = std::slice::Iter<'a, FontFamily>;
|
||||
type Item = &'a FontFamily;
|
||||
@ -923,7 +913,7 @@ cast! {
|
||||
self.0.into_value()
|
||||
},
|
||||
family: FontFamily => Self(vec![family]),
|
||||
values: Array => Self::new(values.into_iter().map(|v| v.cast()).collect::<HintedStrResult<_>>()?)?,
|
||||
values: Array => Self(values.into_iter().map(|v| v.cast()).collect::<HintedStrResult<_>>()?),
|
||||
}
|
||||
|
||||
/// Resolve a prioritized iterator over the font families.
|
||||
@ -1120,6 +1110,27 @@ impl Resolve for TextDir {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether to hyphenate text.
|
||||
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Hyphenate(pub Smart<bool>);
|
||||
|
||||
cast! {
|
||||
Hyphenate,
|
||||
self => self.0.into_value(),
|
||||
v: Smart<bool> => Self(v),
|
||||
}
|
||||
|
||||
impl Resolve for Hyphenate {
|
||||
type Output = bool;
|
||||
|
||||
fn resolve(self, styles: StyleChain) -> Self::Output {
|
||||
match self.0 {
|
||||
Smart::Auto => ParElem::justify_in(styles),
|
||||
Smart::Custom(v) => v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of stylistic sets to enable.
|
||||
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash)]
|
||||
pub struct StylisticSets(u32);
|
||||
@ -1392,7 +1403,24 @@ pub fn is_default_ignorable(c: char) -> bool {
|
||||
fn check_font_list(engine: &mut Engine, list: &Spanned<FontList>) {
|
||||
let book = engine.world.book();
|
||||
for family in &list.v {
|
||||
if !book.contains_family(family.as_str()) {
|
||||
let found = book.contains_family(family.as_str());
|
||||
if family.as_str() == "linux libertine" {
|
||||
let mut warning = warning!(
|
||||
list.span,
|
||||
"Typst's default font has changed from Linux Libertine to its successor Libertinus Serif";
|
||||
hint: "please set the font to `\"Libertinus Serif\"` instead"
|
||||
);
|
||||
|
||||
if found {
|
||||
warning.hint(
|
||||
"Linux Libertine is available on your system - \
|
||||
you can ignore this warning if you are sure you want to use it",
|
||||
);
|
||||
warning.hint("this warning will be removed in Typst 0.13");
|
||||
}
|
||||
|
||||
engine.sink.warn(warning);
|
||||
} else if !found {
|
||||
engine.sink.warn(warning!(
|
||||
list.span,
|
||||
"unknown font family: {}",
|
||||
|
@ -21,7 +21,9 @@ use crate::html::{tag, HtmlElem};
|
||||
use crate::layout::{BlockBody, BlockElem, Em, HAlignment};
|
||||
use crate::loading::{DataSource, Load};
|
||||
use crate::model::{Figurable, ParElem};
|
||||
use crate::text::{FontFamily, FontList, LinebreakElem, LocalName, TextElem, TextSize};
|
||||
use crate::text::{
|
||||
FontFamily, FontList, Hyphenate, LinebreakElem, LocalName, TextElem, TextSize,
|
||||
};
|
||||
use crate::visualize::Color;
|
||||
use crate::World;
|
||||
|
||||
@ -188,7 +190,7 @@ pub struct RawElem {
|
||||
/// - A path string to load a syntax file from the given path. For more
|
||||
/// details about paths, see the [Paths section]($syntax/#paths).
|
||||
/// - Raw bytes from which the syntax should be decoded.
|
||||
/// - An array where each item is one of the above.
|
||||
/// - An array where each item is one the above.
|
||||
///
|
||||
/// ````example
|
||||
/// #set raw(syntaxes: "SExpressions.sublime-syntax")
|
||||
@ -446,14 +448,10 @@ impl Show for Packed<RawElem> {
|
||||
let mut realized = Content::sequence(seq);
|
||||
|
||||
if TargetElem::target_in(styles).is_html() {
|
||||
return Ok(HtmlElem::new(if self.block(styles) {
|
||||
tag::pre
|
||||
} else {
|
||||
tag::code
|
||||
})
|
||||
.with_body(Some(realized))
|
||||
.pack()
|
||||
.spanned(self.span()));
|
||||
return Ok(HtmlElem::new(tag::pre)
|
||||
.with_body(Some(realized))
|
||||
.pack()
|
||||
.spanned(self.span()));
|
||||
}
|
||||
|
||||
if self.block(styles) {
|
||||
@ -474,7 +472,7 @@ impl ShowSet for Packed<RawElem> {
|
||||
let mut out = Styles::new();
|
||||
out.set(TextElem::set_overhang(false));
|
||||
out.set(TextElem::set_lang(Lang::ENGLISH));
|
||||
out.set(TextElem::set_hyphenate(Smart::Custom(false)));
|
||||
out.set(TextElem::set_hyphenate(Hyphenate(Smart::Custom(false))));
|
||||
out.set(TextElem::set_size(TextSize(Em::new(0.8).into())));
|
||||
out.set(TextElem::set_font(FontList(vec![FontFamily::new("DejaVu Sans Mono")])));
|
||||
out.set(TextElem::set_cjk_latin_spacing(Smart::Custom(None)));
|
||||
|
@ -159,7 +159,7 @@ fn is_shapable(engine: &Engine, text: &str, styles: StyleChain) -> bool {
|
||||
{
|
||||
let covers = family.covers();
|
||||
return text.chars().all(|c| {
|
||||
covers.is_none_or(|cov| cov.is_match(c.encode_utf8(&mut [0; 4])))
|
||||
covers.map_or(true, |cov| cov.is_match(c.encode_utf8(&mut [0; 4])))
|
||||
&& font.ttf().glyph_index(c).is_some()
|
||||
});
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ impl<'s> SmartQuotes<'s> {
|
||||
"cs" | "de" | "et" | "is" | "lt" | "lv" | "sk" | "sl" => low_high,
|
||||
"da" => ("‘", "’", "“", "”"),
|
||||
"fr" | "ru" if alternative => default,
|
||||
"fr" => ("“", "”", "«\u{202F}", "\u{202F}»"),
|
||||
"fr" => ("‹\u{00A0}", "\u{00A0}›", "«\u{00A0}", "\u{00A0}»"),
|
||||
"fi" | "sv" if alternative => ("’", "’", "»", "»"),
|
||||
"bs" | "fi" | "sv" => ("’", "’", "”", "”"),
|
||||
"it" if alternative => default,
|
||||
@ -251,7 +251,6 @@ impl<'s> SmartQuotes<'s> {
|
||||
"el" => ("‘", "’", "«", "»"),
|
||||
"he" => ("’", "’", "”", "”"),
|
||||
"hr" => ("‘", "’", "„", "”"),
|
||||
"bg" => ("’", "’", "„", "“"),
|
||||
_ if lang.dir() == Dir::RTL => ("’", "‘", "”", "“"),
|
||||
_ => default,
|
||||
};
|
||||
|
@ -130,7 +130,7 @@ static TO_SRGB: LazyLock<qcms::Transform> = LazyLock::new(|| {
|
||||
///
|
||||
/// # Predefined color maps
|
||||
/// Typst also includes a number of preset color maps that can be used for
|
||||
/// [gradients]($gradient/#stops). These are simply arrays of colors defined in
|
||||
/// [gradients]($gradient.linear). These are simply arrays of colors defined in
|
||||
/// the module `color.map`.
|
||||
///
|
||||
/// ```example
|
||||
@ -148,11 +148,11 @@ static TO_SRGB: LazyLock<qcms::Transform> = LazyLock::new(|| {
|
||||
/// | `magma` | A black to purple to yellow color map. |
|
||||
/// | `plasma` | A purple to pink to yellow color map. |
|
||||
/// | `rocket` | A black to red to white color map. |
|
||||
/// | `mako` | A black to teal to white color map. |
|
||||
/// | `mako` | A black to teal to yellow color map. |
|
||||
/// | `vlag` | A light blue to white to red color map. |
|
||||
/// | `icefire` | A light teal to black to orange color map. |
|
||||
/// | `icefire` | A light teal to black to yellow color map. |
|
||||
/// | `flare` | A orange to purple color map that is perceptually uniform. |
|
||||
/// | `crest` | A light green to blue color map. |
|
||||
/// | `crest` | A blue to white to red color map. |
|
||||
///
|
||||
/// Some popular presets are not included because they are not available under a
|
||||
/// free licence. Others, like
|
||||
|
@ -10,14 +10,12 @@ use crate::foundations::{
|
||||
use crate::layout::{Abs, Axes, BlockElem, Length, Point, Rel, Size};
|
||||
use crate::visualize::{FillRule, Paint, Stroke};
|
||||
|
||||
use super::FixedStroke;
|
||||
|
||||
/// A curve consisting of movements, lines, and Bézier segments.
|
||||
/// A curve consisting of movements, lines, and Beziér segments.
|
||||
///
|
||||
/// At any point in time, there is a conceptual pen or cursor.
|
||||
/// - Move elements move the cursor without drawing.
|
||||
/// - Line/Quadratic/Cubic elements draw a segment from the cursor to a new
|
||||
/// position, potentially with control point for a Bézier curve.
|
||||
/// position, potentially with control point for a Beziér curve.
|
||||
/// - Close elements draw a straight or smooth line back to the start of the
|
||||
/// curve or the latest preceding move segment.
|
||||
///
|
||||
@ -28,7 +26,7 @@ use super::FixedStroke;
|
||||
/// or relative to the current pen/cursor position, that is, the position where
|
||||
/// the previous segment ended.
|
||||
///
|
||||
/// Bézier curve control points can be skipped by passing `{none}` or
|
||||
/// Beziér curve control points can be skipped by passing `{none}` or
|
||||
/// automatically mirrored from the preceding segment by passing `{auto}`.
|
||||
///
|
||||
/// # Example
|
||||
@ -90,7 +88,7 @@ pub struct CurveElem {
|
||||
#[fold]
|
||||
pub stroke: Smart<Option<Stroke>>,
|
||||
|
||||
/// The components of the curve, in the form of moves, line and Bézier
|
||||
/// The components of the curve, in the form of moves, line and Beziér
|
||||
/// segment, and closes.
|
||||
#[variadic]
|
||||
pub components: Vec<CurveComponent>,
|
||||
@ -227,7 +225,7 @@ pub struct CurveLine {
|
||||
pub relative: bool,
|
||||
}
|
||||
|
||||
/// Adds a quadratic Bézier curve segment from the last point to `end`, using
|
||||
/// Adds a quadratic Beziér curve segment from the last point to `end`, using
|
||||
/// `control` as the control point.
|
||||
///
|
||||
/// ```example
|
||||
@ -247,9 +245,9 @@ pub struct CurveLine {
|
||||
/// ```
|
||||
#[elem(name = "quad", title = "Curve Quadratic Segment")]
|
||||
pub struct CurveQuad {
|
||||
/// The control point of the quadratic Bézier curve.
|
||||
/// The control point of the quadratic Beziér curve.
|
||||
///
|
||||
/// - If `{auto}` and this segment follows another quadratic Bézier curve,
|
||||
/// - If `{auto}` and this segment follows another quadratic Beziér curve,
|
||||
/// the previous control point will be mirrored.
|
||||
/// - If `{none}`, the control point defaults to `end`, and the curve will
|
||||
/// be a straight line.
|
||||
@ -274,7 +272,7 @@ pub struct CurveQuad {
|
||||
pub relative: bool,
|
||||
}
|
||||
|
||||
/// Adds a cubic Bézier curve segment from the last point to `end`, using
|
||||
/// Adds a cubic Beziér curve segment from the last point to `end`, using
|
||||
/// `control-start` and `control-end` as the control points.
|
||||
///
|
||||
/// ```example
|
||||
@ -390,7 +388,7 @@ pub enum CloseMode {
|
||||
Straight,
|
||||
}
|
||||
|
||||
/// A curve consisting of movements, lines, and Bézier segments.
|
||||
/// A curve consisting of movements, lines, and Beziér segments.
|
||||
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Curve(pub Vec<CurveItem>);
|
||||
|
||||
@ -532,65 +530,3 @@ impl Curve {
|
||||
Size::new(max_x - min_x, max_y - min_y)
|
||||
}
|
||||
}
|
||||
|
||||
impl Curve {
|
||||
fn to_kurbo(&self) -> impl Iterator<Item = kurbo::PathEl> + '_ {
|
||||
use kurbo::PathEl;
|
||||
|
||||
self.0.iter().map(|item| match *item {
|
||||
CurveItem::Move(point) => PathEl::MoveTo(point_to_kurbo(point)),
|
||||
CurveItem::Line(point) => PathEl::LineTo(point_to_kurbo(point)),
|
||||
CurveItem::Cubic(point, point1, point2) => PathEl::CurveTo(
|
||||
point_to_kurbo(point),
|
||||
point_to_kurbo(point1),
|
||||
point_to_kurbo(point2),
|
||||
),
|
||||
CurveItem::Close => PathEl::ClosePath,
|
||||
})
|
||||
}
|
||||
|
||||
/// When this curve is interpreted as a clip mask, would it contain `point`?
|
||||
pub fn contains(&self, fill_rule: FillRule, needle: Point) -> bool {
|
||||
let kurbo = kurbo::BezPath::from_vec(self.to_kurbo().collect());
|
||||
let windings = kurbo::Shape::winding(&kurbo, point_to_kurbo(needle));
|
||||
match fill_rule {
|
||||
FillRule::NonZero => windings != 0,
|
||||
FillRule::EvenOdd => windings % 2 != 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// When this curve is stroked with `stroke`, would the stroke contain
|
||||
/// `point`?
|
||||
pub fn stroke_contains(&self, stroke: &FixedStroke, needle: Point) -> bool {
|
||||
let width = stroke.thickness.to_raw();
|
||||
let cap = match stroke.cap {
|
||||
super::LineCap::Butt => kurbo::Cap::Butt,
|
||||
super::LineCap::Round => kurbo::Cap::Round,
|
||||
super::LineCap::Square => kurbo::Cap::Square,
|
||||
};
|
||||
let join = match stroke.join {
|
||||
super::LineJoin::Miter => kurbo::Join::Miter,
|
||||
super::LineJoin::Round => kurbo::Join::Round,
|
||||
super::LineJoin::Bevel => kurbo::Join::Bevel,
|
||||
};
|
||||
let miter_limit = stroke.miter_limit.get();
|
||||
let mut style = kurbo::Stroke::new(width)
|
||||
.with_caps(cap)
|
||||
.with_join(join)
|
||||
.with_miter_limit(miter_limit);
|
||||
if let Some(dash) = &stroke.dash {
|
||||
style = style.with_dashes(
|
||||
dash.phase.to_raw(),
|
||||
dash.array.iter().copied().map(Abs::to_raw),
|
||||
);
|
||||
}
|
||||
let opts = kurbo::StrokeOpts::default();
|
||||
let tolerance = 0.01;
|
||||
let expanded = kurbo::stroke(self.to_kurbo(), &style, &opts, tolerance);
|
||||
kurbo::Shape::contains(&expanded, point_to_kurbo(needle))
|
||||
}
|
||||
}
|
||||
|
||||
fn point_to_kurbo(point: Point) -> kurbo::Point {
|
||||
kurbo::Point::new(point.x.to_raw(), point.y.to_raw())
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user