From 1689c7f4706be90f99a9cbf8324bc91520872574 Mon Sep 17 00:00:00 2001 From: Aloxaf Date: Fri, 14 Oct 2022 15:36:35 +0800 Subject: [PATCH] fix: introduce harfbuzz feature --- .github/workflows/ci.yml | 3 ++- .github/workflows/release.yml | 2 +- Cargo.toml | 15 +++++---------- README.md | 2 ++ src/font.rs | 13 ++++++------- src/lib.rs | 2 +- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 599cacc..4ca55aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,12 +77,13 @@ jobs: uses: actions-rs/cargo@v1 with: command: check + args: --no-default-features --features=bin - name: Cargo test uses: actions-rs/cargo@v1 with: command: test - args: -- --nocapture + args: --no-default-features --features=bin -- --nocapture test-macos: name: x86_64-apple-darwin diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 66c8e6f..86fab98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -95,7 +95,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: build - args: --release + args: --release --no-default-features --features=bin - id: get_name shell: bash run: | diff --git a/Cargo.toml b/Cargo.toml index 1398cfd..ee411aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,11 @@ license = "MIT" edition = "2018" [features] -# fearures required for silicon as a application +# bin fearure is required for silicon as a application # disable it when using as a library -default = ["bin"] +default = ["bin", "harfbuzz"] bin = ["structopt", "env_logger", "anyhow", "shell-words"] +harfbuzz = ["harfbuzz-sys", "font-kit/loader-freetype-default", "font-kit/source-fontconfig-default"] [dependencies] dirs = "4.0" @@ -26,6 +27,8 @@ log = "0.4.11" lazy_static = "1.4.0" shell-words = { version = "1.0.0", optional = true } rayon = "1.5.1" +font-kit = "0.11" +harfbuzz-sys = { version = "0.5.0", optional = true } [dependencies.image] version = "0.24" @@ -53,14 +56,6 @@ default-features = false features = ["termcolor", "atty", "humantime"] optional = true -[dependencies.font-kit] -version= "0.11" -features= ["loader-freetype-default"] - -[target.'cfg(not(target_os = "windows"))'.dependencies] -harfbuzz-sys = "0.5.0" -font-kit = { version = "0.11", features = ["loader-freetype-default", "source-fontconfig-default"] } - [target.'cfg(target_os = "macos")'.dependencies] pasteboard = "0.1.3" diff --git a/README.md b/README.md index 87cae0e..0a07bf8 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ It's not as beautiful as Carbon... cargo install silicon ``` +NOTE: harfbuzz feature is enabled by default. If you are using Windows, I suggest you disable it to get it build easier. + ### AUR Silicon is available in the official repository: diff --git a/src/font.rs b/src/font.rs index b2ba177..7f8e43c 100644 --- a/src/font.rs +++ b/src/font.rs @@ -12,7 +12,7 @@ //! font.draw_text_mut(&mut image, Rgb([255, 0, 0]), 0, 0, FontStyle::REGULAR, "Hello, world"); //! ``` use crate::error::FontError; -#[cfg(not(target_os = "windows"))] +#[cfg(feature = "harfbuzz")] use crate::hb_wrapper::{feature_from_tag, HBBuffer, HBFont}; use anyhow::Result; use conv::ValueInto; @@ -24,7 +24,6 @@ use font_kit::source::SystemSource; use image::{GenericImage, Pixel}; use imageproc::definitions::Clamp; use imageproc::pixelops::weighted_sum; -use log::trace; use pathfinder_geometry::transform2d::Transform2F; use std::collections::HashMap; use std::sync::Arc; @@ -215,7 +214,7 @@ impl FontCollection { .unwrap() } - #[cfg(not(target_os = "windows"))] + #[cfg(feature = "harfbuzz")] fn shape_text(&self, font: &mut HBFont, text: &str) -> Result> { // feature tags let features = vec![ @@ -235,7 +234,7 @@ impl FontCollection { Ok(glyph_ids) } - #[cfg(not(target_os = "windows"))] + #[cfg(feature = "harfbuzz")] fn split_by_font(&self, text: &str, style: FontStyle) -> Vec<(&ImageFont, &Font, String)> { let mut result: Vec<(&ImageFont, &Font, String)> = vec![]; for c in text.chars() { @@ -248,11 +247,11 @@ impl FontCollection { } } } - trace!("{:#?}", &result); + log::trace!("{:#?}", &result); result } - #[cfg(not(target_os = "windows"))] + #[cfg(feature = "harfbuzz")] fn layout(&self, text: &str, style: FontStyle) -> (Vec, u32) { let mut delta_x = 0; let height = self.get_font_height(); @@ -288,7 +287,7 @@ impl FontCollection { (glyphs, delta_x) } - #[cfg(target_os = "windows")] + #[cfg(not(feature = "harfbuzz"))] fn layout(&self, text: &str, style: FontStyle) -> (Vec, u32) { let mut delta_x = 0; let height = self.get_font_height(); diff --git a/src/lib.rs b/src/lib.rs index 80cf76f..67551d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,6 @@ pub mod directories; pub mod error; pub mod font; pub mod formatter; -#[cfg(not(target_os = "windows"))] +#[cfg(feature = "harfbuzz")] pub mod hb_wrapper; pub mod utils;