Skip to content

Commit c084375

Browse files
Do better with platform (font engine) features. (#217)
* freetype: Make optional, rename feature. Now, the feature for this is called `freetype` rather than `build-native-freetype`. This was never building FreeType but just saying to build with FreeType and to use `freetype-sys`. The default features were disabled for `freetype` and then enabling the `freetype-sys` feature, but that's exactly what the `freetype` crate does by default, so simplify by not trying to do it again. Partial fix for #184 (this doesn't handle the `coretext` side). * Add `directwrite` feature. This controls whether or not `winapi` is used to support the DirectWrite code on Windows. * Add `coretext` feature. This controls whether or not the CoreText APIs are supported on Apple platforms. Fixes #184. * Add features list to crate docs and READMEs. * Add notes to functions about feature required.
1 parent 280f9e9 commit c084375

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

harfbuzz-sys/Cargo.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,21 @@ pkg-config = { version = "0.3", optional = true }
2828
cc = { version = "1", optional = true }
2929

3030
[target.'cfg(target_vendor = "apple")'.dependencies]
31-
core-graphics = "0.22"
32-
core-text = "19"
33-
foreign-types = "0.3"
31+
core-graphics = { version = "0.22", optional = true }
32+
core-text = { version = "19", optional = true }
33+
foreign-types = { version = "0.3", optional = true }
3434

3535
[target.'cfg(target_family = "windows")'.dependencies.winapi]
3636
version = "0.3"
37+
optional = true
3738
features = ["dwrite"]
3839

39-
[target.'cfg(any(target_os = "android", all(unix, not(target_vendor = "apple"))))'.dependencies]
40-
freetype = { version = "0.7", default-features = false }
41-
4240
[dependencies.freetype]
4341
version = "0.7"
44-
default-features = false
4542
optional = true
4643

4744
[features]
48-
default = ["build-native-harfbuzz", "build-native-freetype"]
45+
default = ["build-native-harfbuzz", "coretext", "directwrite", "freetype"]
46+
coretext = ["core-graphics", "core-text", "foreign-types"]
47+
directwrite = ["winapi"]
4948
build-native-harfbuzz = ["cc", "pkg-config"]
50-
build-native-freetype = ["freetype", "freetype/freetype-sys"]

harfbuzz-sys/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ given a Unicode string.
1414

1515
This crate provides low-level bindings to the C API.
1616

17+
## Features
18+
19+
- `freetype` - Enables bindings to the FreeType font engine. (Enabled by default.)
20+
- `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
21+
- `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
22+
1723
## License
1824

1925
Licensed under the MIT license ([LICENSE](LICENSE) or <https://opensource.org/licenses/MIT>).

harfbuzz-sys/src/coretext.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ use foreign_types::ForeignType;
77
type CGFontRef = *mut <CGFont as ForeignType>::CType;
88

99
extern "C" {
10+
/// This requires that the `coretext` feature is enabled.
1011
pub fn hb_coretext_face_create(cg_font: CGFontRef) -> *mut hb_face_t;
12+
/// This requires that the `coretext` feature is enabled.
1113
pub fn hb_coretext_font_create(ct_font: CTFontRef) -> *mut hb_font_t;
14+
/// This requires that the `coretext` feature is enabled.
1215
pub fn hb_coretext_face_get_cg_font(face: *mut hb_face_t) -> CGFontRef;
16+
/// This requires that the `coretext` feature is enabled.
1317
pub fn hb_coretext_font_get_ct_font(font: *mut hb_font_t) -> CTFontRef;
1418
}

harfbuzz-sys/src/directwrite.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ use crate::hb_face_t;
33
use winapi::um::dwrite::IDWriteFontFace;
44

55
extern "C" {
6+
/// This requires that the `directwrite` feature is enabled.
67
pub fn hb_directwrite_face_create(font_face: *mut IDWriteFontFace) -> *mut hb_face_t;
78
}

harfbuzz-sys/src/lib.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
#[cfg(target_vendor = "apple")]
1+
//! # harfbuzz-sys
2+
//!
3+
//! This crate provides raw bindings to the [HarfBuzz](https://harfbuzz.github.io/)
4+
//! text shaping library.
5+
//!
6+
//! ## Features
7+
//!
8+
//! - `freetype` - Enables bindings to the FreeType font engine. (Enabled by default.)
9+
//! - `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
10+
//! - `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
11+
12+
#[cfg(all(target_vendor = "apple", feature = "coretext"))]
213
pub mod coretext;
314

4-
#[cfg(target_family = "windows")]
15+
#[cfg(all(target_family = "windows", feature = "directwrite"))]
516
pub mod directwrite;
617

7-
#[cfg(any(
8-
target_os = "android",
9-
all(unix, not(target_vendor = "apple")),
10-
feature = "build-native-freetype"
11-
))]
18+
#[cfg(feature = "freetype")]
1219
extern "C" {
20+
/// This requires that the `freetype` feature is enabled.
1321
pub fn hb_ft_font_create_referenced(face: freetype::freetype::FT_Face) -> *mut hb_font_t;
1422
}
1523

harfbuzz/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ version = "0.5.0"
1919
default-features = false
2020

2121
[features]
22-
default = ["build-native-harfbuzz", "build-native-freetype"]
22+
default = ["build-native-harfbuzz", "coretext", "directwrite", "freetype"]
2323
build-native-harfbuzz = ["harfbuzz-sys/build-native-harfbuzz"]
24-
build-native-freetype = ["harfbuzz-sys/build-native-freetype"]
24+
coretext = ["harfbuzz-sys/coretext"]
25+
directwrite = ["harfbuzz-sys/directwrite"]
26+
freetype = ["harfbuzz-sys/freetype"]

harfbuzz/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ given a Unicode string.
1515
This crate provides a higher level API (than the
1616
[raw C bindings](https://crates.io/crates/harfbuzz-sys)).
1717

18+
## Features
19+
20+
- `freetype` - Enables bindings to the FreeType font engine. (Enabled by default.)
21+
- `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
22+
- `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
23+
1824
## License
1925

2026
Licensed under either of

harfbuzz/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
//! HarfBuzz is a text shaping engine. It solves the problem of selecting
1111
//! and positioning glyphs from a font given a Unicode string.
12+
//!
13+
//! ## Features
14+
//!
15+
//! - `freetype` - Enables bindings to the FreeType font engine. (Enabled by default.)
16+
//! - `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
17+
//! - `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
1218
1319
#![warn(missing_docs)]
1420
#![deny(

0 commit comments

Comments
 (0)