Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce harfbuzz feature #209

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ jobs:
test-windows:
name: x86_64-pc-windows-msvc
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Install rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Cargo check
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: --no-default-features --features=bin -- --nocapture

test-macos:
name: x86_64-apple-darwin
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
14 changes: 5 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -53,13 +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"

[target.'cfg(target_os = "macos")'.dependencies]
pasteboard = "0.1.3"

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 6 additions & 7 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Vec<u32>> {
// feature tags
let features = vec![
Expand All @@ -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() {
Expand All @@ -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<PositionedGlyph>, u32) {
let mut delta_x = 0;
let height = self.get_font_height();
Expand Down Expand Up @@ -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<PositionedGlyph>, u32) {
let mut delta_x = 0;
let height = self.get_font_height();
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;