Skip to content

Commit

Permalink
dev(compiler): new font distribute strategy (#362)
Browse files Browse the repository at this point in the history
* dev(compiler): new font distribute strategy

* build: update submodule index

* fix(cli): specify cjk,emoji fonts
  • Loading branch information
Myriad-Dreamin authored Sep 20, 2023
1 parent aa86373 commit 59066c3
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 34 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Download Repo
- name: Checkout Repo
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Mold
uses: rui314/setup-mold@v1
- name: Install Rust
Expand All @@ -36,14 +38,6 @@ jobs:
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | bash
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- name: Prepare fonts
run: cargo run --profile release-ci --bin typst-ts-fontctl
- name: Prepare assets
run: |
git clone https://github.com/Myriad-Dreamin/typst fuzzers/typst
cd fuzzers/typst
git reset --hard 20a988e48374675f7d0d05c4822cd297a3293f41
cp -r ./assets/files/ ../../assets/files/
- name: Fmt check
run: cargo fmt --check --all
- name: Clippy check
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ jobs:
packages: write

steps:
- name: Checkout repository
- name: Checkout Repo
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2.5.0
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/gh_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
- name: Checkout Repo
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Mold
uses: rui314/setup-mold@v1
- name: Install Rust
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ jobs:
env:
target: ${{ matrix.platform }}-${{ matrix.arch }}
steps:
- uses: actions/checkout@v3
- name: Checkout Repo
uses: actions/checkout@v3
with:
submodules: recursive
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- name: rust toolchain
Expand Down Expand Up @@ -104,7 +107,10 @@ jobs:
env:
target: ${{ matrix.platform }}-${{ matrix.arch }}
steps:
- uses: actions/checkout@v3
- name: Checkout Repo
uses: actions/checkout@v3
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
with:
target: ${{ matrix.rust-target }}
Expand Down Expand Up @@ -187,7 +193,10 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Checkout Repo
uses: actions/checkout@v3
with:
submodules: recursive
with:
fetch-depth: 0
- uses: actions/download-artifact@v2
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

target/
out/
/assets/
/assets
/assets/profile
dist/
node_modules/
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[submodule "TypstFontAssets"]
path = assets/fonts
url = https://github.com/Myriad-Dreamin/typst.git
branch = assets-fonts
[submodule "TypstFileAssets"]
path = assets/files
url = https://github.com/Myriad-Dreamin/typst.git
branch = assets-files
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Note: Since we use turborepo for `>=v0.4.0` development, if you are the earlier

```shell
# Optional: download the font assets if you haven't done so.
$ cargo run --bin typst-ts-fontctl
$ git submodule update --init --recursive .
# build all of typescript packages
$ yarn install && npx turbo run build
# compile typst document for demo
Expand Down
1 change: 1 addition & 0 deletions assets/files
Submodule files added at dcddda
1 change: 1 addition & 0 deletions assets/fonts
Submodule fonts added at 0149f1
11 changes: 10 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ raster = ["typst-ts-raster-exporter"]
serde-json = ["typst-ts-serde-exporter", "typst-ts-serde-exporter/json"]
serde-rmp = ["typst-ts-serde-exporter", "typst-ts-serde-exporter/rmp"]
svg = ["typst-ts-svg-exporter"]
default = ["pdf", "raster", "serde-json", "serde-rmp", "svg", "embedded-fonts"]
default = [
"pdf",
"raster",
"serde-json",
"serde-rmp",
"svg",
"embedded-fonts",
"embedded-cjk-fonts",
"embedded-emoji-fonts",
]
10 changes: 3 additions & 7 deletions compiler/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,18 @@ impl TypstSystemWorld {
searcher.search_file(&path);
}
}
// Source2: add the fonts from vanilla paths.
if !opts.no_vanilla_fonts {
searcher.search_vanilla();
}
// Source3: add the fonts from system paths.
// Source2: add the fonts from system paths.
if !opts.no_system_fonts {
searcher.search_system();
}
// Source4: add the fonts in memory.
// Source3: add the fonts in memory.
for font_data in opts.with_embedded_fonts {
searcher.add_memory_font(match font_data {
Cow::Borrowed(data) => Bytes::from_static(data),
Cow::Owned(data) => Bytes::from(data),
});
}
// Source5: add the fonts from the profile cache.
// Source4: add the fonts from the profile cache.
for profile_path in opts.font_profile_paths {
searcher.add_profile_by_path(&profile_path);
}
Expand Down
18 changes: 18 additions & 0 deletions docs/download-font-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ There are several ways to downloading the font files:

- Download the font files from [Typst repository](https://github.com/typst/typst/tree/main/assets/fonts).

- Download the font files via `git`:

Please use following command inside of `typst.ts` repo:

```shell
# init inside typst.ts repository
$ git submodule update --init --recursive .
# update inside typst.ts repository
$ git submodule update --recursive
```

Please use following command outside of `typst.ts` repo:

```shell
# outside typst.ts repository
$ git clone https://github.com/Myriad-Dreamin/typst/ fonts --single-branch --branch assets-fonts --depth 1
```

- Download font files from our [Release Page](https://github.com/Myriad-Dreamin/typst.ts/releases/tag/v0.1.0).

- Download font files using `tools/fontctl`
Expand Down
9 changes: 0 additions & 9 deletions tools/fontctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@ fn download_fonts(opts: Opts) {
println!("downloading...");
repo.exec().unwrap();

std::fs::create_dir_all("github-pages/assets/fonts").unwrap();
for font in FONT_LISTS {
std::fs::copy(
format!("assets/fonts/{}", font.0),
format!("github-pages/assets/fonts/{}", font.0),
)
.unwrap();
}

println!("done");
}

Expand Down

0 comments on commit 59066c3

Please sign in to comment.