From c3b6a8c3c79e5283b424cf18d458b1b617a8e7ae Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Sat, 20 Apr 2024 14:30:00 +0300 Subject: [PATCH] Split `fontique` into its own package. --- .github/workflows/ci.yml | 31 ++++++-- AUTHORS | 1 + Cargo.lock | 46 +++++++----- Cargo.toml | 73 ++++++++++--------- README.md | 2 +- fontique/Cargo.toml | 48 ++++++++++++ fontique/README.md | 54 ++++++++++++++ {src/fontique => fontique/src}/attributes.rs | 3 + .../src}/backend/android.rs | 0 .../src}/backend/coretext.rs | 0 .../src}/backend/dwrite.rs | 2 +- .../src}/backend/fontconfig/cache.rs | 0 .../src}/backend/fontconfig/config.rs | 0 .../src}/backend/fontconfig/mod.rs | 2 +- {src/fontique => fontique/src}/backend/mod.rs | 0 .../src}/collection/mod.rs | 12 +-- .../src}/collection/query.rs | 3 + {src/fontique => fontique/src}/fallback.rs | 2 +- {src/fontique => fontique/src}/family.rs | 0 {src/fontique => fontique/src}/family_name.rs | 2 +- {src/fontique => fontique/src}/font.rs | 0 {src/fontique => fontique/src}/generic.rs | 4 +- src/fontique/mod.rs => fontique/src/lib.rs | 9 +++ {src/fontique => fontique/src}/matching.rs | 8 +- {src/fontique => fontique/src}/scan.rs | 3 + {src/fontique => fontique/src}/script.rs | 0 {src/fontique => fontique/src}/source.rs | 0 .../fontique => fontique/src}/source_cache.rs | 0 src/bidi.rs | 3 + src/context.rs | 5 +- src/font.rs | 4 +- src/layout/data.rs | 3 + src/layout/line/greedy.rs | 3 + src/layout/mod.rs | 2 +- src/lib.rs | 8 +- src/resolve/mod.rs | 5 +- src/resolve/range.rs | 7 +- src/shape.rs | 2 +- src/style/font.rs | 2 +- src/swash_convert.rs | 2 - 40 files changed, 263 insertions(+), 88 deletions(-) create mode 100644 fontique/Cargo.toml create mode 100644 fontique/README.md rename {src/fontique => fontique/src}/attributes.rs (99%) rename {src/fontique => fontique/src}/backend/android.rs (100%) rename {src/fontique => fontique/src}/backend/coretext.rs (100%) rename {src/fontique => fontique/src}/backend/dwrite.rs (99%) rename {src/fontique => fontique/src}/backend/fontconfig/cache.rs (100%) rename {src/fontique => fontique/src}/backend/fontconfig/config.rs (100%) rename {src/fontique => fontique/src}/backend/fontconfig/mod.rs (99%) rename {src/fontique => fontique/src}/backend/mod.rs (100%) rename {src/fontique => fontique/src}/collection/mod.rs (98%) rename {src/fontique => fontique/src}/collection/query.rs (99%) rename {src/fontique => fontique/src}/fallback.rs (99%) rename {src/fontique => fontique/src}/family.rs (100%) rename {src/fontique => fontique/src}/family_name.rs (99%) rename {src/fontique => fontique/src}/font.rs (100%) rename {src/fontique => fontique/src}/generic.rs (98%) rename src/fontique/mod.rs => fontique/src/lib.rs (69%) rename {src/fontique => fontique/src}/matching.rs (98%) rename {src/fontique => fontique/src}/scan.rs (99%) rename {src/fontique => fontique/src}/script.rs (100%) rename {src/fontique => fontique/src}/source.rs (100%) rename {src/fontique => fontique/src}/source_cache.rs (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b67525c..2f5ecefe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,12 @@ env: # 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.74" + 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" + RUST_MIN_VER_PKGS: "-p parley -p fontique" + # List of features that depend on the standard library and will be excluded from no_std checks. + FEATURES_DEPENDING_ON_STD: "std,default,system" # Rationale @@ -41,6 +43,10 @@ env: # # 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. +# +# For no_std checks we target x86_64-unknown-none, because this target doesn't support std +# and as such will error out if our dependency tree accidentally tries to use std. +# https://doc.rust-lang.org/stable/rustc/platform-support/x86_64-unknown-none.html name: CI @@ -88,6 +94,7 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.RUST_STABLE_VER }} + targets: x86_64-unknown-none components: clippy - name: install cargo-hack @@ -95,11 +102,15 @@ jobs: with: tool: cargo-hack + # TODO: Add --target x86_64-unknown-none to the no_std check once we solve the compilation issues with it + - name: cargo clippy (no_std) + run: cargo hack clippy --workspace --locked --optional-deps --each-feature --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} -- -D warnings + - name: cargo clippy - run: cargo hack clippy --workspace --locked --each-feature --optional-deps -- -D warnings + run: cargo hack clippy --workspace --locked --optional-deps --each-feature --features std -- -D warnings - name: cargo clippy (auxiliary) - run: cargo hack clippy --workspace --locked --each-feature --optional-deps --tests --benches --examples -- -D warnings + run: cargo hack clippy --workspace --locked --optional-deps --each-feature --features std --tests --benches --examples -- -D warnings clippy-stable-android: name: cargo clippy (android) @@ -126,10 +137,10 @@ jobs: tool: cargo-hack - name: cargo clippy - run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --each-feature --optional-deps -- -D warnings + run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --optional-deps --each-feature --features std -- -D warnings - name: cargo clippy (auxiliary) - run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --each-feature --optional-deps --tests --benches --examples -- -D warnings + run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --optional-deps --each-feature --features std --tests --benches --examples -- -D warnings test-stable: name: cargo test @@ -173,8 +184,12 @@ jobs: with: tool: cargo-hack + # TODO: Add --target x86_64-unknown-none to the no_std check once we solve the compilation issues with it + - name: cargo check (no_std) + run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} + - name: cargo check - run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --each-feature --optional-deps + run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature --features std check-msrv-android: name: cargo check (msrv) (android) @@ -200,7 +215,7 @@ jobs: tool: cargo-hack - name: cargo check - run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --target ${{ matrix.target }} --each-feature --optional-deps + run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --target ${{ matrix.target }} --optional-deps --each-feature --features std doc: name: cargo doc diff --git a/AUTHORS b/AUTHORS index 071e8eb0..b86bc4a7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,4 @@ # source control. Google LLC Chad Brokaw +Kaur Kuut diff --git a/Cargo.lock b/Cargo.lock index 17bb55ab..a90d47d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -169,6 +169,32 @@ dependencies = [ "thiserror", ] +[[package]] +name = "fontique" +version = "0.1.0" +dependencies = [ + "anyhow", + "bytemuck", + "core-foundation", + "core-foundation-sys", + "core-text", + "core_maths", + "dwrote", + "fontconfig-cache-parser", + "hashbrown", + "icu_locid", + "icu_properties", + "memmap2", + "peniko", + "roxmltree", + "skrifa", + "smallvec", + "thiserror", + "unicode-script", + "winapi", + "wio", +] + [[package]] name = "foreign-types" version = "0.5.0" @@ -352,28 +378,12 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parley" -version = "0.0.1" +version = "0.1.0" dependencies = [ - "anyhow", - "bytemuck", - "core-foundation", - "core-foundation-sys", - "core-text", - "dwrote", - "fontconfig-cache-parser", - "hashbrown", - "icu_locid", - "icu_properties", - "memmap2", + "fontique", "peniko", - "roxmltree", "skrifa", - "smallvec", "swash", - "thiserror", - "unicode-script", - "winapi", - "wio", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2824a926..59954310 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,42 +1,49 @@ -[package] -name = "parley" -version = "0.0.1" -authors = ["Chad Brokaw "] -license = "Apache-2.0 OR MIT" +[workspace] +resolver = "2" +members = [ + "fontique" +] + +[workspace.package] edition = "2021" # Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml and with the relevant README.md files. -rust-version = "1.74" +rust-version = "1.70" +license = "Apache-2.0 OR MIT" +repository = "https://github.com/linebender/parley" + +[package] +name = "parley" +version = "0.1.0" +description = "Parley provides an API for implementing rich text layout." +keywords = ["text", "layout"] +categories = ["gui", "graphics"] +edition.workspace = true +rust-version.workspace = true +license.workspace = true +repository.workspace = true +exclude = ["/.github/", "/doc/", ".gitignore"] + +[workspace.lints] +clippy.doc_markdown = "warn" +clippy.semicolon_if_nothing_returned = "warn" + +[lints] +workspace = true [features] default = ["system"] -# Enabled support for system font backends -system = ["std"] -std = ["dep:memmap2"] +std = ["fontique/std", "skrifa/std", "peniko/std"] +libm = ["fontique/libm", "skrifa/libm", "peniko/libm"] +# Enables support for system font backends +system = ["std", "fontique/system"] [dependencies] swash = "0.1.15" -skrifa = { version = "0.19.0", default-features = false, features = ["libm"] } -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" -hashbrown = "0.14.3" - -[target.'cfg(target_family="windows")'.dependencies] -dwrote = "0.11.0" -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.1.0" -core-foundation = "0.9.4" -core-foundation-sys = "0.8.6" +skrifa = { workspace = true } +peniko = { workspace = true } +fontique = { workspace = true } -[target.'cfg(not(any(target_os="macos", target_os="ios", target_family="windows")))'.dependencies] -anyhow = "1.0.82" -bytemuck = { version = "1.15.0", features = ["derive"] } -fontconfig-cache-parser = "0.2" -thiserror = "1.0.58" -roxmltree = "0.18.1" +[workspace.dependencies] +fontique = { version = "0.1.0", default-features = false, path = "fontique" } +skrifa = { version = "0.19.0", default-features = false } +peniko = { version = "0.1.0", default-features = false } diff --git a/README.md b/README.md index 33b5330e..dfcdea08 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ 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.74** and later. +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. diff --git a/fontique/Cargo.toml b/fontique/Cargo.toml new file mode 100644 index 00000000..fb68b78b --- /dev/null +++ b/fontique/Cargo.toml @@ -0,0 +1,48 @@ +[package] +name = "fontique" +version = "0.1.0" # Keep in sync with workspace dependency specification +description = "Font enumeration and fallback." +keywords = ["font", "text"] +categories = ["gui", "os"] +edition.workspace = true +rust-version.workspace = true +license.workspace = true +repository.workspace = true + +[lints] +workspace = true + +[features] +default = ["system"] +std = ["skrifa/std", "peniko/std", "dep:memmap2"] +libm = ["skrifa/libm", "peniko/libm", "dep:core_maths"] +# Enabled support for system font backends +system = ["std"] + +[dependencies] +skrifa = { workspace = true } +peniko = { workspace = true } +smallvec = "1.13.2" +memmap2 = { version = "0.5.10", optional = true } +unicode-script = { version = "0.5.6", optional = true } +core_maths = { version = "0.1.0", optional = true } +icu_properties = "1.4.0" +icu_locid = "1.4.0" +hashbrown = "0.14.3" + +[target.'cfg(target_family="windows")'.dependencies] +dwrote = "0.11.0" +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.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.82" +bytemuck = { version = "1.15.0", features = ["derive"] } +fontconfig-cache-parser = "0.2.0" +thiserror = "1.0.58" +roxmltree = "0.18.1" diff --git a/fontique/README.md b/fontique/README.md new file mode 100644 index 00000000..4bdfaef2 --- /dev/null +++ b/fontique/README.md @@ -0,0 +1,54 @@ +
+ +# Fontique + +**Font enumeration and fallback** + +[![Latest published fontique version.](https://img.shields.io/crates/v/fontique.svg)](https://crates.io/crates/fontique) +[![Documentation build status.](https://img.shields.io/docsrs/fontique.svg)](https://docs.rs/fontique) +[![Dependency staleness status.](https://deps.rs/repo/github/linebender/fontique/status.svg)](https://deps.rs/repo/github/linebender/fontique) +[![Linebender Zulip chat.](https://img.shields.io/badge/Linebender-%23text-blue?logo=Zulip)](https://xi.zulipchat.com/#narrow/stream/205635-text) +[![Apache 2.0 or MIT license.](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](#license) + +
+ +Fontique provides font enumeration and fallback. + +## Minimum supported Rust Version (MSRV) + +This version of Fontique has been verified to compile with **Rust 1.70** and later. + +Future versions of Fontique 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. + +
+Click here if compiling fails. + +As time has passed, some of Fontique's dependencies could have released versions with a higher Rust requirement. +If you encounter a compilation issue due to a dependency and don't want to upgrade your Rust toolchain, then you could downgrade the dependency. + +```sh +# Use the problematic dependency's name and version +cargo update -p package_name --precise 0.1.1 +``` +
+ +## Community + +Discussion of Fontique development happens in the [Linebender Zulip](https://xi.zulipchat.com/), specifically the [#text stream](https://xi.zulipchat.com/#narrow/stream/205635-text). +All public content can be read without logging in. + +Contributions are welcome by pull request. The [Rust code of conduct] applies. + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache 2.0 license, shall be licensed as noted in the [License](#license) section, without any additional terms or conditions. + +## License + +Licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or ) +- MIT license ([LICENSE-MIT](../LICENSE-MIT) or ) + +at your option. + +[Rust code of conduct]: https://www.rust-lang.org/policies/code-of-conduct diff --git a/src/fontique/attributes.rs b/fontique/src/attributes.rs similarity index 99% rename from src/fontique/attributes.rs rename to fontique/src/attributes.rs index e2decd92..83954bae 100644 --- a/src/fontique/attributes.rs +++ b/fontique/src/attributes.rs @@ -3,6 +3,9 @@ //! Properties for specifying font weight, stretch and style. +#[cfg(not(feature = "std"))] +use core_maths::*; + use core::fmt; /// Primary attributes for font matching: stretch, style and weight. diff --git a/src/fontique/backend/android.rs b/fontique/src/backend/android.rs similarity index 100% rename from src/fontique/backend/android.rs rename to fontique/src/backend/android.rs diff --git a/src/fontique/backend/coretext.rs b/fontique/src/backend/coretext.rs similarity index 100% rename from src/fontique/backend/coretext.rs rename to fontique/src/backend/coretext.rs diff --git a/src/fontique/backend/dwrite.rs b/fontique/src/backend/dwrite.rs similarity index 99% rename from src/fontique/backend/dwrite.rs rename to fontique/src/backend/dwrite.rs index b35929d8..9bfc74b0 100644 --- a/src/fontique/backend/dwrite.rs +++ b/fontique/src/backend/dwrite.rs @@ -241,7 +241,7 @@ fn all_family_names(family: &dwrote::FontFamily) -> Option> { continue; } buf.pop(); - names.push(String::from_utf16_lossy(&buf)) + names.push(String::from_utf16_lossy(&buf)); } } Some(names) diff --git a/src/fontique/backend/fontconfig/cache.rs b/fontique/src/backend/fontconfig/cache.rs similarity index 100% rename from src/fontique/backend/fontconfig/cache.rs rename to fontique/src/backend/fontconfig/cache.rs diff --git a/src/fontique/backend/fontconfig/config.rs b/fontique/src/backend/fontconfig/config.rs similarity index 100% rename from src/fontique/backend/fontconfig/config.rs rename to fontique/src/backend/fontconfig/config.rs diff --git a/src/fontique/backend/fontconfig/mod.rs b/fontique/src/backend/fontconfig/mod.rs similarity index 99% rename from src/fontique/backend/fontconfig/mod.rs rename to fontique/src/backend/fontconfig/mod.rs index 04206c7e..69c03e7d 100644 --- a/src/fontique/backend/fontconfig/mod.rs +++ b/fontique/src/backend/fontconfig/mod.rs @@ -220,7 +220,7 @@ impl SystemFonts { } } -/// FontConfig seems to force RBIZ (regular, bold, italic, bold italic) when +/// Fontconfig seems to force RBIZ (regular, bold, italic, bold italic) when /// categorizing fonts. This removes those suffixes from family names so that /// we can match on all attributes. fn strip_rbiz(name: &str) -> &str { diff --git a/src/fontique/backend/mod.rs b/fontique/src/backend/mod.rs similarity index 100% rename from src/fontique/backend/mod.rs rename to fontique/src/backend/mod.rs diff --git a/src/fontique/collection/mod.rs b/fontique/src/collection/mod.rs similarity index 98% rename from src/fontique/collection/mod.rs rename to fontique/src/collection/mod.rs index 46c55866..a5601bf1 100644 --- a/src/fontique/collection/mod.rs +++ b/fontique/src/collection/mod.rs @@ -116,7 +116,7 @@ impl Collection { generic: GenericFamily, families: impl Iterator, ) { - self.inner.set_generic_families(generic, families) + self.inner.set_generic_families(generic, families); } /// Appends the set of family identifiers to the given generic family. @@ -125,7 +125,7 @@ impl Collection { generic: GenericFamily, families: impl Iterator, ) { - self.inner.append_generic_families(generic, families) + self.inner.append_generic_families(generic, families); } /// Returns an iterator over the fallback families for the given @@ -307,10 +307,10 @@ impl Inner { .set(generic, families); shared.bump_version(); } else { - self.data.generic_families.set(generic, families) + self.data.generic_families.set(generic, families); } #[cfg(not(feature = "std"))] - self.data.generic_families.set(generic, families) + self.data.generic_families.set(generic, families); } /// Appends the set of family identifiers to the given generic family. @@ -330,10 +330,10 @@ impl Inner { .append(generic, families); shared.bump_version(); } else { - self.data.generic_families.append(generic, families) + self.data.generic_families.append(generic, families); } #[cfg(not(feature = "std"))] - self.data.generic_families.append(generic, families) + self.data.generic_families.append(generic, families); } /// Returns an iterator over the fallback families for the given diff --git a/src/fontique/collection/query.rs b/fontique/src/collection/query.rs similarity index 99% rename from src/fontique/collection/query.rs rename to fontique/src/collection/query.rs index 9ba0c953..fbd6f38d 100644 --- a/src/fontique/collection/query.rs +++ b/fontique/src/collection/query.rs @@ -6,6 +6,9 @@ #[cfg(feature = "std")] use super::super::{Collection, SourceCache}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + use super::{ super::{Attributes, Blob, FallbackKey, FamilyId, FamilyInfo, GenericFamily, Synthesis}, Inner, diff --git a/src/fontique/fallback.rs b/fontique/src/fallback.rs similarity index 99% rename from src/fontique/fallback.rs rename to fontique/src/fallback.rs index 138ca2ef..39a81456 100644 --- a/src/fontique/fallback.rs +++ b/fontique/src/fallback.rs @@ -94,7 +94,7 @@ impl FallbackMap { } existing_families.extend(families); } else { - script_fallbacks.others.push((locale, families.collect())) + script_fallbacks.others.push((locale, families.collect())); } true } diff --git a/src/fontique/family.rs b/fontique/src/family.rs similarity index 100% rename from src/fontique/family.rs rename to fontique/src/family.rs diff --git a/src/fontique/family_name.rs b/fontique/src/family_name.rs similarity index 99% rename from src/fontique/family_name.rs rename to fontique/src/family_name.rs index 85e2e594..36bc10f5 100644 --- a/src/fontique/family_name.rs +++ b/fontique/src/family_name.rs @@ -107,7 +107,7 @@ impl NameKey { for ch in s.chars() { for ch in ch.to_lowercase() { res.data - .extend_from_slice(ch.encode_utf8(&mut buf).as_bytes()) + .extend_from_slice(ch.encode_utf8(&mut buf).as_bytes()); } } res diff --git a/src/fontique/font.rs b/fontique/src/font.rs similarity index 100% rename from src/fontique/font.rs rename to fontique/src/font.rs diff --git a/src/fontique/generic.rs b/fontique/src/generic.rs similarity index 98% rename from src/fontique/generic.rs rename to fontique/src/generic.rs index b5316add..50b959ac 100644 --- a/src/fontique/generic.rs +++ b/fontique/src/generic.rs @@ -57,7 +57,7 @@ impl GenericFamily { /// /// # Example /// ``` - /// # use parley::fontique::GenericFamily; + /// # use fontique::GenericFamily; /// assert_eq!(GenericFamily::parse("sans-serif"), Some(GenericFamily::SansSerif)); /// assert_eq!(GenericFamily::parse("Arial"), None); /// ``` @@ -140,7 +140,7 @@ impl GenericFamilyMap { pub fn set(&mut self, generic: GenericFamily, families: impl Iterator) { let map = &mut self.map[generic as usize]; map.clear(); - map.extend(families) + map.extend(families); } /// Appends the family identifiers to the list for the given generic family. diff --git a/src/fontique/mod.rs b/fontique/src/lib.rs similarity index 69% rename from src/fontique/mod.rs rename to fontique/src/lib.rs index 86b98655..ad6eaecb 100644 --- a/src/fontique/mod.rs +++ b/fontique/src/lib.rs @@ -3,6 +3,15 @@ //! Font enumeration and fallback. +// TODO: Remove this dead code allowance and hide the offending code behind the std feature gate. +#![cfg_attr(not(feature = "std"), allow(dead_code))] +#![cfg_attr(all(not(feature = "std"), not(test)), no_std)] + +#[cfg(not(any(feature = "std", feature = "libm")))] +compile_error!("fontique requires either the `std` or `libm` feature to be enabled"); + +extern crate alloc; + mod attributes; mod backend; mod collection; diff --git a/src/fontique/matching.rs b/fontique/src/matching.rs similarity index 98% rename from src/fontique/matching.rs rename to fontique/src/matching.rs index e72abc67..af708f3d 100644 --- a/src/fontique/matching.rs +++ b/fontique/src/matching.rs @@ -171,7 +171,7 @@ pub fn match_font( } else { // Choose an italic style if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic + use_style = Style::Italic; } // oblique values less than or equal to 0deg are checked in descending order else if let Some(found) = oblique_fonts @@ -224,7 +224,7 @@ pub fn match_font( } else { // Choose an italic style if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic + use_style = Style::Italic; } // oblique values less than or equal to 0deg are checked in descending order else if let Some(found) = oblique_fonts @@ -276,7 +276,7 @@ pub fn match_font( } else { // Choose an italic style if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic + use_style = Style::Italic; } // oblique values greater than or equal to 0deg are checked in ascending order else if let Some(found) = oblique_fonts @@ -328,7 +328,7 @@ pub fn match_font( } else { // Choose an italic style if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic + use_style = Style::Italic; } // oblique values greater than or equal to 0deg are checked in ascending order else if let Some(found) = oblique_fonts diff --git a/src/fontique/scan.rs b/fontique/src/scan.rs similarity index 99% rename from src/fontique/scan.rs rename to fontique/src/scan.rs index b57cac18..b6bcfc7f 100644 --- a/src/fontique/scan.rs +++ b/fontique/src/scan.rs @@ -17,6 +17,9 @@ use smallvec::SmallVec; #[cfg(feature = "std")] use {super::source::SourcePathMap, std::path::Path}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + #[cfg(feature = "std")] /// Font collection generated by scanning the file system. #[derive(Default)] diff --git a/src/fontique/script.rs b/fontique/src/script.rs similarity index 100% rename from src/fontique/script.rs rename to fontique/src/script.rs diff --git a/src/fontique/source.rs b/fontique/src/source.rs similarity index 100% rename from src/fontique/source.rs rename to fontique/src/source.rs diff --git a/src/fontique/source_cache.rs b/fontique/src/source_cache.rs similarity index 100% rename from src/fontique/source_cache.rs rename to fontique/src/source_cache.rs diff --git a/src/bidi.rs b/src/bidi.rs index a709e7a3..57335443 100644 --- a/src/bidi.rs +++ b/src/bidi.rs @@ -3,6 +3,9 @@ //! Unicode bidirectional algorithm. +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + use swash::text::{BidiClass, BracketType, Codepoint as _}; use BidiClass::*; diff --git a/src/context.rs b/src/context.rs index 5fb3d74a..7f358cdd 100644 --- a/src/context.rs +++ b/src/context.rs @@ -3,6 +3,9 @@ //! Context for layout. +#[cfg(not(feature = "std"))] +use alloc::{vec, vec::Vec}; + use super::bidi; use super::resolve::range::*; use super::resolve::*; @@ -15,7 +18,7 @@ use super::layout::Layout; use swash::shape::ShapeContext; use swash::text::cluster::CharInfo; -use std::ops::RangeBounds; +use core::ops::RangeBounds; /// Context for building a text layout. pub struct LayoutContext { diff --git a/src/font.rs b/src/font.rs index 805d6d5f..8aa06a23 100644 --- a/src/font.rs +++ b/src/font.rs @@ -1,10 +1,10 @@ // Copyright 2021 the Parley Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -use crate::fontique::Collection; +use fontique::Collection; #[cfg(feature = "std")] -use crate::fontique::SourceCache; +use fontique::SourceCache; #[derive(Default)] pub struct FontContext { diff --git a/src/layout/data.rs b/src/layout/data.rs index faf25948..0042abf7 100644 --- a/src/layout/data.rs +++ b/src/layout/data.rs @@ -10,6 +10,9 @@ use swash::shape::Shaper; use swash::text::cluster::{Boundary, ClusterInfo}; use swash::Synthesis; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + #[derive(Copy, Clone)] pub struct ClusterData { pub info: ClusterInfo, diff --git a/src/layout/line/greedy.rs b/src/layout/line/greedy.rs index 42d904d9..46585aae 100644 --- a/src/layout/line/greedy.rs +++ b/src/layout/line/greedy.rs @@ -3,6 +3,9 @@ //! Greedy line breaking. +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + use crate::layout::*; use crate::style::Brush; diff --git a/src/layout/mod.rs b/src/layout/mod.rs index abd3969c..89e39b4f 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -111,7 +111,7 @@ impl Layout { /// Breaks all lines with the specified maximum advance and alignment. pub fn break_all_lines(&mut self, max_advance: Option, alignment: Alignment) { self.break_lines() - .break_remaining(max_advance.unwrap_or(f32::MAX), alignment) + .break_remaining(max_advance.unwrap_or(f32::MAX), alignment); } /// Returns an iterator over the runs in the layout. diff --git a/src/lib.rs b/src/lib.rs index 0e64a727..c00d1bff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,18 @@ // Copyright 2021 the Parley Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +//! Rich text layout. + // TODO: Remove this dead code allowance and hide the offending code behind the std feature gate. #![cfg_attr(not(feature = "std"), allow(dead_code))] +#![cfg_attr(all(not(feature = "std"), not(test)), no_std)] + +#[cfg(not(any(feature = "std", feature = "libm")))] +compile_error!("parley requires either the `std` or `libm` feature to be enabled"); extern crate alloc; +pub use fontique; pub use swash; mod bidi; @@ -16,7 +23,6 @@ mod swash_convert; mod util; pub mod context; -pub mod fontique; pub mod layout; pub mod style; diff --git a/src/resolve/mod.rs b/src/resolve/mod.rs index 8430274c..eb1fbd31 100644 --- a/src/resolve/mod.rs +++ b/src/resolve/mod.rs @@ -6,13 +6,16 @@ pub mod range; pub mod tree; +#[cfg(not(feature = "std"))] +use alloc::{vec, vec::Vec}; + use super::style::{ Brush, FontFamily, FontFeature, FontSettings, FontStack, FontStretch, FontStyle, FontVariation, FontWeight, StyleProperty, }; use crate::font::FontContext; -use crate::fontique::FamilyId; use crate::util::nearly_eq; +use fontique::FamilyId; use swash::text::Language; use swash::Setting; diff --git a/src/resolve/range.rs b/src/resolve/range.rs index 325ea42c..6c3f6671 100644 --- a/src/resolve/range.rs +++ b/src/resolve/range.rs @@ -3,6 +3,9 @@ //! Range based style application. +#[cfg(not(feature = "std"))] +use alloc::vec; + use super::*; use core::ops::{Bound, Range, RangeBounds}; @@ -37,14 +40,14 @@ impl RangedStyleBuilder { /// Pushes a property that covers the full range of text. pub fn push_default(&mut self, property: ResolvedProperty) { assert!(self.len != !0); - self.default_style.apply(property) + self.default_style.apply(property); } /// Pushes a property that covers the specified range of text. pub fn push(&mut self, property: ResolvedProperty, range: impl RangeBounds) { let range = resolve_range(range, self.len); assert!(self.len != !0); - self.properties.push(RangedProperty { property, range }) + self.properties.push(RangedProperty { property, range }); } /// Computes the sequence of ranged styles. diff --git a/src/shape.rs b/src/shape.rs index a630e301..f7bcaac9 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -6,11 +6,11 @@ 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 fontique::{self, Attributes, Query, QueryFont}; use swash::shape::*; #[cfg(feature = "std")] use swash::text::cluster::{CharCluster, CharInfo, Token}; diff --git a/src/style/font.rs b/src/style/font.rs index cf1f1b7c..c84cced9 100644 --- a/src/style/font.rs +++ b/src/style/font.rs @@ -3,7 +3,7 @@ use core::fmt; -pub use crate::fontique::{ +pub use fontique::{ GenericFamily, Stretch as FontStretch, Style as FontStyle, Weight as FontWeight, }; diff --git a/src/swash_convert.rs b/src/swash_convert.rs index 85891208..acf911ea 100644 --- a/src/swash_convert.rs +++ b/src/swash_convert.rs @@ -1,8 +1,6 @@ // Copyright 2024 the Parley Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -use crate::fontique; - pub fn script_to_fontique(script: swash::text::Script) -> fontique::Script { fontique::Script(*SCRIPT_TAGS.get(script as usize).unwrap_or(b"Zzzz")) }