From 4f05e183be9b388c6748d3c531c9ac332672fb86 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Fri, 19 Apr 2024 13:48:51 +0300 Subject: [PATCH] Add the standard Linebender CI script and satisfy Clippy. (#33) * Add the standard Linebender CI script. * Update dependencies and commit `Cargo.lock`. * Add `.clippy.toml` and `.rustfmt.toml`. * Add MSRV info to `README.md`. * Satisfy Clippy 1.77. * Rewrite bidi order sequencing with an enumerator. --- .clippy.toml | 5 + .github/copyright.sh | 23 + .github/workflows/ci.yml | 222 ++++++++ .gitignore | 1 - .rustfmt.toml | 2 + Cargo.lock | 877 +++++++++++++++++++++++++++++++ Cargo.toml | 26 +- README.md | 7 + src/bidi.rs | 21 +- src/context.rs | 13 +- src/font.rs | 6 +- src/fontique/collection/mod.rs | 16 +- src/fontique/collection/query.rs | 12 +- src/fontique/generic.rs | 2 +- src/layout/data.rs | 1 + src/layout/line/greedy.rs | 2 +- src/layout/line/mod.rs | 9 +- src/lib.rs | 3 + src/resolve/range.rs | 2 +- src/shape.rs | 14 +- src/swash_convert.rs | 2 +- 21 files changed, 1209 insertions(+), 57 deletions(-) create mode 100644 .clippy.toml create mode 100644 .github/copyright.sh create mode 100644 .github/workflows/ci.yml create mode 100644 .rustfmt.toml create mode 100644 Cargo.lock diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 00000000..aab49e8d --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,5 @@ +# The default Clippy value for this is 8 bytes, which is chosen to improve performance on 32-bit. +# Given that we're building for the future and even mobile phones have 64-bit CPUs, +# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit. +# 16 bytes is the number of bytes that fits into two 64-bit CPU registers. +trivial-copy-size-limit = 16 diff --git a/.github/copyright.sh b/.github/copyright.sh new file mode 100644 index 00000000..0fe3ad17 --- /dev/null +++ b/.github/copyright.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# If there are new files with headers that can't match the conditions here, +# then the files can be ignored by an additional glob argument via the -g flag. +# For example: +# -g "!src/special_file.rs" +# -g "!src/special_directory" + +# Check all the standard Rust source files +output=$(rg "^// Copyright (19|20)[\d]{2} (.+ and )?the Parley Authors( and .+)?$\n^// SPDX-License-Identifier: Apache-2\.0 OR MIT$\n\n" --files-without-match --multiline -g "*.rs" .) + +if [ -n "$output" ]; then + echo -e "The following files lack the correct copyright header:\n" + echo $output + echo -e "\n\nPlease add the following header:\n" + echo "// Copyright $(date +%Y) the Parley Authors" + echo "// SPDX-License-Identifier: Apache-2.0 OR MIT" + echo -e "\n... rest of the file ...\n" + exit 1 +fi + +echo "All files have correct copyright headers." +exit 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..63936e4d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,222 @@ +env: + # We aim to always test with the latest stable Rust toolchain, however we pin to a specific + # version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still + # come automatically. If the version specified here is no longer the latest stable version, + # then please feel free to submit a PR that adjusts it along with the potential clippy fixes. + RUST_STABLE_VER: "1.77" # In quotes because otherwise (e.g.) 1.70 would be interpreted as 1.7 + # The purpose of checking with the minimum supported Rust toolchain is to detect its staleness. + # If the compilation fails, then the version specified here needs to be bumped up to reality. + # Be sure to also update the rust-version property in the workspace Cargo.toml file, + # plus all the README.md files of the affected packages. + RUST_MIN_VER: "1.70" + # List of packages that will be checked with the minimum supported Rust version. + # This should be limited to packages that are intended for publishing. + RUST_MIN_VER_PKGS: "-p parley" + + +# Rationale +# +# We don't run clippy with --all-targets because then even --lib and --bins are compiled with +# dev dependencies enabled, which does not match how they would be compiled by users. +# A dev dependency might enable a feature that we need for a regular dependency, +# and checking with --all-targets would not find our feature requirements lacking. +# This problem still applies to cargo resolver version 2. +# Thus we split all the targets into two steps, one with --lib --bins +# and another with --tests --benches --examples. +# Also, we can't give --lib --bins explicitly because then cargo will error on binary-only packages. +# Luckily the default behavior of cargo with no explicit targets is the same but without the error. +# +# We use cargo-hack for a similar reason. Cargo's --workspace will do feature unification across +# the whole workspace. While cargo-hack will instead check each workspace package separately. +# +# Using cargo-hack also allows us to more easily test the feature matrix of our packages. +# We use --each-feature & --optional-deps which will run a separate check for every feature. +# +# We use macos-14 explictly instead of macos-latest because: +# * macos-latest currently points to macos-12 +# * macos-14 comes with the M1 CPU which compiles our code much faster than the older runners +# This explicit dependency can be switched back to macos-latest once it points to macos-14, +# which is expected to happen sometime in Q2 FY24 (April – June 2024). +# https://github.blog/changelog/2024-01-30-github-actions-macos-14-sonoma-is-now-available/ +# +# The MSRV jobs run only cargo check because different clippy versions can disagree on goals and +# running tests introduces dev dependencies which may require a higher MSRV than the bare package. + +name: CI + +on: + pull_request: + merge_group: + +jobs: + fmt: + name: cargo fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_STABLE_VER }} + components: rustfmt + + - name: cargo fmt + run: cargo fmt --all --check + + - name: install ripgrep + run: | + sudo apt update + sudo apt install ripgrep + + - name: check copyright headers + run: bash .github/copyright.sh + + clippy-stable: + name: cargo clippy + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-14, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_STABLE_VER }} + components: clippy + + - name: install cargo-hack + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack + + - name: cargo clippy + run: cargo hack clippy --workspace --locked --each-feature --optional-deps -- -D warnings + + - name: cargo clippy (auxiliary) + run: cargo hack clippy --workspace --locked --each-feature --optional-deps --tests --benches --examples -- -D warnings + + clippy-stable-android: + name: cargo clippy (android) + runs-on: ubuntu-latest + strategy: + matrix: + target: [armv7-linux-androideabi, aarch64-linux-android, x86_64-linux-android] + steps: + - uses: actions/checkout@v4 + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_STABLE_VER }} + targets: ${{ matrix.target }} + components: clippy + + - name: install cargo-hack + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack + + - name: cargo clippy + run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --each-feature --optional-deps -- -D warnings + + - name: cargo clippy (auxiliary) + run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --each-feature --optional-deps --tests --benches --examples -- -D warnings + + test-stable: + name: cargo test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-14, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_STABLE_VER }} + + - name: cargo test + run: cargo test --workspace --locked --all-features + + check-msrv: + name: cargo check (msrv) + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-14, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: install msrv toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_MIN_VER }} + + - name: install cargo-hack + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack + + - name: cargo check + run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --each-feature --optional-deps + + check-msrv-android: + name: cargo check (msrv) (android) + runs-on: ubuntu-latest + strategy: + matrix: + target: [armv7-linux-androideabi, aarch64-linux-android, x86_64-linux-android] + steps: + - uses: actions/checkout@v4 + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: install msrv toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_MIN_VER }} + targets: ${{ matrix.target }} + + - name: install cargo-hack + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack + + - name: cargo check + run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --target ${{ matrix.target }} --each-feature --optional-deps + + doc: + name: cargo doc + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-14, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: install nightly toolchain + uses: dtolnay/rust-toolchain@nightly + + # We test documentation using nightly to match docs.rs. This prevents potential breakages + - name: cargo doc + run: cargo doc --workspace --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples diff --git a/.gitignore b/.gitignore index 96ef6c0b..ea8c4bf7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /target -Cargo.lock diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..a4607a5f --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,2 @@ +use_field_init_shorthand = true +newline_style = "Unix" diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..2ad27a50 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,877 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytemuck" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "core-graphics" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" +dependencies = [ + "bitflags", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" +dependencies = [ + "bitflags", + "core-foundation", + "libc", +] + +[[package]] +name = "core-text" +version = "20.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d2790b5c08465d49f8dc05c8bcae9fea467855947db39b0f8145c091aaced5" +dependencies = [ + "core-foundation", + "core-graphics", + "foreign-types", + "libc", +] + +[[package]] +name = "core_maths" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b02505ccb8c50b0aa21ace0fc08c3e53adebd4e58caa18a36152803c7709a3" +dependencies = [ + "libm", +] + +[[package]] +name = "displaydoc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dwrote" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439a1c2ba5611ad3ed731280541d36d2e9c4ac5e7fb818a27b604bdc5a6aa65b" +dependencies = [ + "lazy_static", + "libc", + "serde", + "serde_derive", + "winapi", + "wio", +] + +[[package]] +name = "font-types" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6784a76a9c2b136ea3b8462391e9328252e938eb706eb44d752723b4c3a533" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "fontconfig-cache-parser" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0413877146e4ea3a9f56c12917a1754418b518ac7a6982838eabafa8a92260" +dependencies = [ + "anyhow", + "bytemuck", + "clap", + "thiserror", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "icu_collections" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "137d96353afc8544d437e8a99eceb10ab291352699573b0de5b08bda38c78c60" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0aa2536adc14c07e2a521e95512b75ed8ef832f0fdf9299d4a0a45d2be2a9d" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c17d8f6524fdca4471101dd71f0a132eb6382b5d6d7f2970441cb25f6f435a" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "545c6c3e8bf9580e2dafee8de6f9ec14826aaf359787789c7724f1f85f47d3dc" + +[[package]] +name = "icu_properties" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976e296217453af983efa25f287a4c1da04b9a63bf1ed63719455068e4453eb5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6a86c0e384532b06b6c104814f9c1b13bcd5b64409001c0d05713a1f3529d99" + +[[package]] +name = "icu_provider" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba58e782287eb6950247abbf11719f83f5d4e4a5c1f2cd490d30a334bc47c2f4" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2abdd3a62551e8337af119c5899e600ca0c88ec8f23a46c60ba216c803dcf1a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "kurbo" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e5aa9f0f96a938266bdb12928a67169e8d22c6a786fda8ed984b85e6ba93c3c" +dependencies = [ + "arrayvec", + "libm", + "smallvec", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "litemap" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d642685b028806386b2b6e75685faadd3eb65a85fff7df711ce18446a422da" + +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parley" +version = "0.0.1" +dependencies = [ + "anyhow", + "bytemuck", + "core-foundation", + "core-foundation-sys", + "core-text", + "dwrote", + "fontconfig-cache-parser", + "hashbrown", + "icu_locid", + "icu_properties", + "memmap2", + "peniko", + "roxmltree", + "skrifa", + "smallvec", + "swash", + "thiserror", + "unicode-script", + "winapi", + "wio", +] + +[[package]] +name = "peniko" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaf7fec601d640555d9a4cab7343eba1e1c7a5a71c9993ff63b4c26bc5d50c5" +dependencies = [ + "kurbo", + "smallvec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "read-fonts" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea75b5ec052843434d263ef7a4c31cf86db5908c729694afb1ad3c884252a1b6" +dependencies = [ + "bytemuck", + "font-types", +] + +[[package]] +name = "roxmltree" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862340e351ce1b271a378ec53f304a5558f7db87f3769dc655a8f6ecbb68b302" +dependencies = [ + "xmlparser", +] + +[[package]] +name = "serde" +version = "1.0.198" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.198" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "skrifa" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3f54c6ecbad34b55ea1779389e334fe0d260f2f0c80964a926ffb47918c26e9" +dependencies = [ + "bytemuck", + "core_maths", + "read-fonts", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "swash" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ec889a8e0a6fcb91041996c8f1f6be0fe1a09e94478785e07c32ce2bca2d2b" +dependencies = [ + "read-fonts", + "yazi", + "zeno", +] + +[[package]] +name = "syn" +version = "2.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c02bf3c538ab32ba913408224323915f4ef9a6d61c0e85d493f355921c0ece" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-script" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8d71f5726e5f285a935e9fe8edfd53f0491eb6e9a5774097fdabee7cd8c9cd" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "wio" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" +dependencies = [ + "winapi", +] + +[[package]] +name = "writeable" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad7bb64b8ef9c0aa27b6da38b452b0ee9fd82beaf276a87dd796fb55cbae14e" + +[[package]] +name = "xmlparser" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" + +[[package]] +name = "yazi" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c94451ac9513335b5e23d7a8a2b61a7102398b8cca5160829d313e84c9d98be1" + +[[package]] +name = "yoke" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e71b2e4f287f467794c671e2b8f8a5f3716b3c829079a1c44740148eff07e4" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e6936f0cce458098a201c245a11bef556c6a0181129c7034d10d76d1ec3a2b8" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeno" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd15f8e0dbb966fd9245e7498c7e9e5055d9e5c8b676b95bd67091cd11a1e697" + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "655b0814c5c0b19ade497851070c640773304939a6c0fd5f5fb43da0696d05b7" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6a647510471d372f2e6c2e6b7219e44d8c574d24fdc11c610a61455782f18c3" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff4439ae91fb5c72b8abc12f3f2dbf51bd27e6eadb9f8a5bc8898dddb0e27ea" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4e5997cbf58990550ef1f0e5124a05e47e1ebd33a84af25739be6031a62c20" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 11caaa02..6c68c764 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,8 @@ version = "0.0.1" authors = ["Chad Brokaw "] license = "Apache-2.0 OR MIT" edition = "2021" +# Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml and with the relevant README.md files. +rust-version = "1.70" [features] default = ["system"] @@ -14,9 +16,9 @@ std = ["dep:memmap2"] [dependencies] swash = "0.1.15" skrifa = { version = "0.19.0", default-features = false, features = ["libm"] } -smallvec = "1.10.0" -memmap2 = { version = "0.5", optional = true } -unicode-script = { version = "0.5.5", optional = true } +smallvec = "1.13.2" +memmap2 = { version = "0.5.10", optional = true } +unicode-script = { version = "0.5.6", optional = true } peniko = { version = "0.1.0", default-features = false, features = ["libm"] } icu_properties = "1.4.0" icu_locid = "1.4.0" @@ -24,17 +26,17 @@ hashbrown = "0.14.3" [target.'cfg(target_family="windows")'.dependencies] dwrote = "0.11.0" -winapi = { version = "0.3.6", features = ["dwrite", "dwrite_1", "dwrite_3", "winnt", "unknwnbase", "libloaderapi", "winnls"] } -wio = "0.2" +winapi = { version = "0.3.9", features = ["dwrite", "dwrite_1", "dwrite_3", "winnt", "unknwnbase", "libloaderapi", "winnls"] } +wio = "0.2.2" [target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies] -core-text = "20.0.0" -core-foundation = "0.9" -core-foundation-sys = "0.8" +core-text = "20.1.0" +core-foundation = "0.9.4" +core-foundation-sys = "0.8.6" [target.'cfg(not(any(target_os="macos", target_os="ios", target_family="windows")))'.dependencies] -anyhow = "1.0.66" -bytemuck = { version = "1.12.2", features = ["derive"] } +anyhow = "1.0.82" +bytemuck = { version = "1.15.0", features = ["derive"] } fontconfig-cache-parser = "0.1.1" -thiserror = "1.0.37" -roxmltree = "0.18.0" +thiserror = "1.0.58" +roxmltree = "0.18.1" diff --git a/README.md b/README.md index 7a46fcd2..776fd7af 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,13 @@ Parley provides an API for implementing rich text layout. It is backed by [Swash](https://github.com/dfrg/swash). +## Minimum supported Rust Version (MSRV) + +This version of Parley has been verified to compile with **Rust 1.70** and later. + +Future versions of Parley might increase the Rust version requirement. +It will not be treated as a breaking change and as such can even happen with small patch releases. + ## Community Discussion of Parley development happens in the [Linebender Zulip](https://xi.zulipchat.com/), specifically the [#text stream](https://xi.zulipchat.com/#narrow/stream/205635-text). diff --git a/src/bidi.rs b/src/bidi.rs index 94978688..a709e7a3 100644 --- a/src/bidi.rs +++ b/src/bidi.rs @@ -249,14 +249,10 @@ impl BidiResolver { }, is_isolate, ); - } else { - if is_isolate { - overflow_isolates += 1; - } else { - if overflow_isolates == 0 { - overflow_embedding += 1; - } - } + } else if is_isolate { + overflow_isolates += 1; + } else if overflow_isolates == 0 { + overflow_embedding += 1; } } else if t == PDI { if overflow_isolates > 0 { @@ -384,6 +380,7 @@ impl BidiResolver { } } + #[allow(clippy::needless_range_loop)] fn resolve_sequence(&mut self, level: u8, sos: BidiClass, eos: BidiClass, len: usize) { if len == 0 { return; @@ -658,9 +655,8 @@ where { let mut max_level = 0; let mut lowest_odd_level = 255; - let mut idx = 0; - let len = order.len(); - for i in 0..len { + for (i, o) in order.iter_mut().enumerate() { + *o = i; let level = levels(i); if level > max_level { max_level = level; @@ -668,9 +664,8 @@ where if level & 1 != 0 && level < lowest_odd_level { lowest_odd_level = level; } - order[idx] = idx; - idx += 1; } + let len = order.len(); for level in (lowest_odd_level..=max_level).rev() { let mut i = 0; while i < len { diff --git a/src/context.rs b/src/context.rs index 5ee10fd3..5fb3d74a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -4,12 +4,14 @@ //! Context for layout. use super::bidi; -use super::layout::Layout; use super::resolve::range::*; use super::resolve::*; use super::style::*; use super::FontContext; +#[cfg(feature = "std")] +use super::layout::Layout; + use swash::shape::ShapeContext; use swash::text::cluster::CharInfo; @@ -44,6 +46,7 @@ impl LayoutContext { scale: f32, ) -> RangedBuilder { self.begin(text); + #[cfg(feature = "std")] fcx.source_cache.prune(128, false); RangedBuilder { text, @@ -97,15 +100,16 @@ pub struct RangedBuilder<'a, B: Brush, T: TextSource> { impl<'a, B: Brush, T: TextSource> RangedBuilder<'a, B, T> { pub fn push_default(&mut self, property: &StyleProperty) { - let resolved = self.lcx.rcx.resolve(self.fcx, &property, self.scale); + let resolved = self.lcx.rcx.resolve(self.fcx, property, self.scale); self.lcx.rsb.push_default(resolved); } pub fn push(&mut self, property: &StyleProperty, range: impl RangeBounds) { - let resolved = self.lcx.rcx.resolve(&mut self.fcx, &property, self.scale); + let resolved = self.lcx.rcx.resolve(self.fcx, property, self.scale); self.lcx.rsb.push(resolved, range); } + #[cfg(feature = "std")] pub fn build_into(&mut self, layout: &mut Layout) { layout.data.clear(); layout.data.scale = self.scale; @@ -175,6 +179,7 @@ impl<'a, B: Brush, T: TextSource> RangedBuilder<'a, B, T> { } } + #[cfg(feature = "std")] pub fn build(&mut self) -> Layout { let mut layout = Layout::default(); self.build_into(&mut layout); @@ -189,6 +194,6 @@ pub trait TextSource { impl<'a> TextSource for &'a str { fn as_str(&self) -> &str { - *self + self } } diff --git a/src/font.rs b/src/font.rs index fe0d6f3c..805d6d5f 100644 --- a/src/font.rs +++ b/src/font.rs @@ -1,10 +1,14 @@ // Copyright 2021 the Parley Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -use crate::fontique::{Collection, SourceCache}; +use crate::fontique::Collection; + +#[cfg(feature = "std")] +use crate::fontique::SourceCache; #[derive(Default)] pub struct FontContext { pub collection: Collection, + #[cfg(feature = "std")] pub source_cache: SourceCache, } diff --git a/src/fontique/collection/mod.rs b/src/fontique/collection/mod.rs index 54db6250..0efa0410 100644 --- a/src/fontique/collection/mod.rs +++ b/src/fontique/collection/mod.rs @@ -7,6 +7,7 @@ mod query; pub use query::{Query, QueryFamily, QueryFont, QueryStatus}; +#[cfg(feature = "std")] use super::SourceCache; use super::{ @@ -156,6 +157,7 @@ impl Collection { } /// Returns an object for selecting fonts from this collection. + #[cfg(feature = "std")] pub fn query<'a>(&'a mut self, source_cache: &'a mut SourceCache) -> Query<'a> { Query::new(self, source_cache) } @@ -247,7 +249,7 @@ impl Inner { if let Some(family) = self.data.families.get(&id) { family.as_ref().cloned() } else { - #[cfg(feature = "std")] + #[cfg(feature = "system")] if let Some(system) = &self.system { let family = system.fonts.lock().unwrap().family(id); self.data.families.insert(id, family.clone()); @@ -255,7 +257,7 @@ impl Inner { } else { None } - #[cfg(not(feature = "std"))] + #[cfg(not(feature = "system"))] { None } @@ -346,7 +348,7 @@ impl Inner { if self.fallback_cache.script != Some(script) || self.fallback_cache.language != lang_key { self.sync_shared(); self.fallback_cache.reset(); - #[cfg(feature = "std")] + #[cfg(feature = "system")] if let Some(families) = self.data.fallbacks.get(selector) { self.fallback_cache.set(script, lang_key, families); } else if let Some(system) = self.system.as_ref() { @@ -356,7 +358,7 @@ impl Inner { self.fallback_cache.set(script, lang_key, &[family]); } } - #[cfg(not(feature = "std"))] + #[cfg(not(feature = "system"))] if let Some(families) = self.data.fallbacks.get(selector) { self.fallback_cache.set(script, lang_key, families); } @@ -502,7 +504,7 @@ impl FallbackCache { /// Data taken from the system font collection. #[derive(Clone)] struct System { - #[cfg(feature = "std")] + #[cfg(feature = "system")] fonts: Arc>, family_names: Arc, generic_families: Arc, @@ -513,10 +515,10 @@ impl System { let fonts = SystemFonts::new(); let family_names = fonts.name_map.clone(); let generic_families = fonts.generic_families.clone(); - #[cfg(feature = "std")] + #[cfg(feature = "system")] let fonts = Arc::new(Mutex::new(fonts)); Self { - #[cfg(feature = "std")] + #[cfg(feature = "system")] fonts, family_names, generic_families, diff --git a/src/fontique/collection/query.rs b/src/fontique/collection/query.rs index 5c0eae46..9ba0c953 100644 --- a/src/fontique/collection/query.rs +++ b/src/fontique/collection/query.rs @@ -3,11 +3,11 @@ //! Query support. -use super::super::SourceCache; +#[cfg(feature = "std")] +use super::super::{Collection, SourceCache}; + use super::{ - super::{ - Attributes, Blob, Collection, FallbackKey, FamilyId, FamilyInfo, GenericFamily, Synthesis, - }, + super::{Attributes, Blob, FallbackKey, FamilyId, FamilyInfo, GenericFamily, Synthesis}, Inner, }; @@ -28,12 +28,14 @@ impl QueryState { pub struct Query<'a> { collection: &'a mut Inner, state: &'a mut QueryState, + #[cfg(feature = "std")] source_cache: &'a mut SourceCache, attributes: Attributes, fallbacks: Option, } impl<'a> Query<'a> { + #[cfg(feature = "std")] pub(super) fn new(collection: &'a mut Collection, source_cache: &'a mut SourceCache) -> Self { collection.query_state.clear(); Self { @@ -98,6 +100,7 @@ impl<'a> Query<'a> { /// Invokes the given callback with all fonts that match the current /// settings. + #[cfg(feature = "std")] pub fn matches_with(&mut self, mut f: impl FnMut(&QueryFont) -> QueryStatus) { for family in self .state @@ -210,6 +213,7 @@ pub struct QueryFont { pub synthesis: Synthesis, } +#[cfg(feature = "std")] fn load_font<'a>( family: &FamilyInfo, attributes: &Attributes, diff --git a/src/fontique/generic.rs b/src/fontique/generic.rs index 6d4be4ca..b5316add 100644 --- a/src/fontique/generic.rs +++ b/src/fontique/generic.rs @@ -57,7 +57,7 @@ impl GenericFamily { /// /// # Example /// ``` - /// # use fontique::GenericFamily; + /// # use parley::fontique::GenericFamily; /// assert_eq!(GenericFamily::parse("sans-serif"), Some(GenericFamily::SansSerif)); /// assert_eq!(GenericFamily::parse("Arial"), None); /// ``` diff --git a/src/layout/data.rs b/src/layout/data.rs index 9f961ee2..faf25948 100644 --- a/src/layout/data.rs +++ b/src/layout/data.rs @@ -222,6 +222,7 @@ impl LayoutData { } #[allow(unused_assignments)] + #[allow(clippy::too_many_arguments)] pub fn push_run( &mut self, font: Font, diff --git a/src/layout/line/greedy.rs b/src/layout/line/greedy.rs index af8d0a14..42d904d9 100644 --- a/src/layout/line/greedy.rs +++ b/src/layout/line/greedy.rs @@ -311,7 +311,7 @@ impl<'a, B: Brush> BreakLines<'a, B> { .iter() .map(|c| c.advance) .sum(); - let line_height = line_run.compute_line_height(&self.layout); + let line_height = line_run.compute_line_height(self.layout); let run = &self.layout.runs[line_run.run_index]; line.metrics.ascent = line.metrics.ascent.max(run.metrics.ascent * line_height); line.metrics.descent = line.metrics.descent.max(run.metrics.descent * line_height); diff --git a/src/layout/line/mod.rs b/src/layout/line/mod.rs index a21a566a..91c5d46e 100644 --- a/src/layout/line/mod.rs +++ b/src/layout/line/mod.rs @@ -130,8 +130,7 @@ impl<'a, B: Brush> GlyphRun<'a, B> { pub fn glyphs(&'a self) -> impl Iterator + 'a + Clone { self.run .visual_clusters() - .map(|cluster| cluster.glyphs()) - .flatten() + .flat_map(|cluster| cluster.glyphs()) .skip(self.glyph_start) .take(self.glyph_count) } @@ -142,8 +141,7 @@ impl<'a, B: Brush> GlyphRun<'a, B> { let baseline = self.baseline; self.run .visual_clusters() - .map(|cluster| cluster.glyphs()) - .flatten() + .flat_map(|cluster| cluster.glyphs()) .skip(self.glyph_start) .take(self.glyph_count) .map(move |mut g| { @@ -171,8 +169,7 @@ impl<'a, B: Brush> Iterator for GlyphRunIter<'a, B> { let run = self.line.get(self.run_index)?; let mut iter = run .visual_clusters() - .map(|c| c.glyphs()) - .flatten() + .flat_map(|c| c.glyphs()) .skip(self.glyph_start); if let Some(first) = iter.next() { let mut advance = first.advance; diff --git a/src/lib.rs b/src/lib.rs index 01d11bc0..0e64a727 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,9 @@ // Copyright 2021 the Parley Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +// TODO: Remove this dead code allowance and hide the offending code behind the std feature gate. +#![cfg_attr(not(feature = "std"), allow(dead_code))] + extern crate alloc; pub use swash; diff --git a/src/resolve/range.rs b/src/resolve/range.rs index a6386dd3..325ea42c 100644 --- a/src/resolve/range.rs +++ b/src/resolve/range.rs @@ -62,7 +62,7 @@ impl RangedStyleBuilder { if prop.range.start > prop.range.end { continue; } - let split_range = split_range(prop, &styles); + let split_range = split_range(prop, styles); let mut inserted = 0; if let Some(first) = split_range.first { let original_span = &mut styles[first]; diff --git a/src/shape.rs b/src/shape.rs index 1a1c3dd3..a630e301 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -1,14 +1,18 @@ // Copyright 2021 the Parley Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +#[cfg(feature = "std")] use super::layout::Layout; use super::resolve::range::RangedStyle; use super::resolve::{ResolveContext, Resolved}; use super::style::{Brush, FontFeature, FontVariation}; use crate::fontique::{self, Attributes, Query, QueryFont}; +#[cfg(feature = "std")] use crate::util::nearly_eq; +#[cfg(feature = "std")] use crate::Font; use swash::shape::*; +#[cfg(feature = "std")] use swash::text::cluster::{CharCluster, CharInfo, Token}; use swash::text::{Language, Script}; use swash::{FontRef, Synthesis}; @@ -25,6 +29,8 @@ struct Item { letter_spacing: f32, } +#[cfg(feature = "std")] +#[allow(clippy::too_many_arguments)] pub fn shape_text<'a, B: Brush>( rcx: &'a ResolveContext, mut fq: Query<'a>, @@ -42,7 +48,7 @@ pub fn shape_text<'a, B: Brush>( let mut item = Item { style_index: 0, size: style.font_size, - level: levels.get(0).copied().unwrap_or(0), + level: levels.first().copied().unwrap_or(0), script: infos .iter() .map(|x| x.0.script()) @@ -107,7 +113,6 @@ pub fn shape_text<'a, B: Brush>( ); }, ); - std::mem::drop(fs); }; } for ((char_index, ch), (info, style_index)) in text.chars().enumerate().zip(infos) { @@ -185,9 +190,7 @@ impl<'a, 'b, B: Brush> FontSelector<'a, 'b, B> { let features = rcx.features(style.font_features).unwrap_or(&[]); query.set_families(fonts.iter().copied()); let fb_script = crate::swash_convert::script_to_fontique(script); - let fb_language = locale - .map(|locale| crate::swash_convert::locale_to_fontique(locale)) - .flatten(); + let fb_language = locale.and_then(crate::swash_convert::locale_to_fontique); query.set_fallbacks(fontique::FallbackKey::new(fb_script, fb_language.as_ref())); query.set_attributes(attrs); Self { @@ -203,6 +206,7 @@ impl<'a, 'b, B: Brush> FontSelector<'a, 'b, B> { } } +#[cfg(feature = "std")] impl<'a, 'b, B: Brush> partition::Selector for FontSelector<'a, 'b, B> { type SelectedFont = SelectedFont; diff --git a/src/swash_convert.rs b/src/swash_convert.rs index c3b07271..85891208 100644 --- a/src/swash_convert.rs +++ b/src/swash_convert.rs @@ -47,7 +47,7 @@ pub fn synthesis_to_swash(synthesis: fontique::Synthesis) -> swash::Synthesis { ) } -#[cfg_attr(rustfmt, rustfmt_skip)] +#[rustfmt::skip] const SCRIPT_TAGS: [[u8; 4]; 157] = [ *b"Adlm", *b"Aghb", *b"Ahom", *b"Arab", *b"Armi", *b"Armn", *b"Avst", *b"Bali", *b"Bamu", *b"Bass", *b"Batk", *b"Beng", *b"Bhks", *b"Bopo", *b"Brah", *b"Brai", *b"Bugi", *b"Buhd",