Skip to content

Commit

Permalink
Merge remote-tracking branch 'servo/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
osiewicz committed Jul 23, 2024
2 parents 5a5c4d4 + 6dbec44 commit d639dfb
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 135 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Run CI
on:
push:
branches: ["**"]
branches: ["master"]
pull_request:
branches: ["**"]
merge_group:
types: [checks_requested]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -14,7 +16,7 @@ env:

jobs:
ci-linux:
name: CI (Linux)
name: Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -38,7 +40,7 @@ jobs:
run: cargo fmt --all -- --check

ci-macos:
name: CI (macOS)
name: macOS
runs-on: macos-12
steps:
- uses: actions/checkout@v2
Expand All @@ -56,7 +58,7 @@ jobs:
run: cargo test

ci-win:
name: CI (Windows)
name: Windows
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
Expand All @@ -74,7 +76,7 @@ jobs:
run: cargo test

build_result:
name: homu build finished
name: Result
runs-on: ubuntu-latest
needs:
- "ci-linux"
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "font-kit"
version = "0.11.0"
version = "0.12.0"
authors = ["Patrick Walton <pcwalton@mimiga.net>"]
description = "A cross-platform font loading library"
license = "MIT OR Apache-2.0"
Expand All @@ -20,9 +20,9 @@ source-fontconfig-default = ["source-fontconfig"]
source = []

[dependencies]
bitflags = "1"
bitflags = "2.4"
byteorder = "1.2"
float-ord = "0.2"
float-ord = "0.3"
lazy_static = "1.1"
libc = "0.2"
log = "0.4.4"
Expand All @@ -34,12 +34,12 @@ version = "0.7"
optional = true

[dependencies.yeslogic-fontconfig-sys]
version = "3.0.0"
version = "5.0"
optional = true

[dev-dependencies]
clap = "2.32"
colored = "1.6"
clap = "4"
colored = "2"
pbr = "1.0"
prettytable-rs = "0.10"

Expand All @@ -59,7 +59,7 @@ core-text = "20.1"
freetype = "0.7"

[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32")))'.dependencies]
yeslogic-fontconfig-sys = "3.0.0"
yeslogic-fontconfig-sys = "5.0"

[target.'cfg(not(any(target_arch = "wasm32", target_family = "windows", target_os = "android")))'.dependencies]
dirs-next = "2.0"
Expand Down
31 changes: 20 additions & 11 deletions examples/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@
extern crate clap;
extern crate font_kit;

use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgMatches, Command};

use font_kit::loader::Loader;
use font_kit::source::SystemSource;

#[cfg(any(target_family = "windows", target_os = "macos"))]
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &'static str = "ArialMT";
#[cfg(not(any(target_family = "windows", target_os = "macos")))]
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &'static str = "DejaVuSans";
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &str = "DejaVuSans";

fn get_args() -> ArgMatches<'static> {
let postscript_name_arg = Arg::with_name("POSTSCRIPT-NAME")
fn get_args() -> ArgMatches {
let postscript_name_arg = Arg::new("POSTSCRIPT-NAME")
.help("PostScript name of the font")
.default_value(SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME)
.index(1);
let text_arg = Arg::with_name("TEXT")
let text_arg = Arg::new("TEXT")
.help("Text to query")
.default_value("A")
.index(2);
let locale_arg = Arg::with_name("LOCALE")
let locale_arg = Arg::new("LOCALE")
.help("Locale for fallback query")
.default_value("en-US")
.index(3);
App::new("fallback")
Command::new("fallback")
.version("0.1")
.arg(postscript_name_arg)
.arg(text_arg)
Expand All @@ -44,11 +44,20 @@ fn get_args() -> ArgMatches<'static> {

fn main() {
let matches = get_args();
let postscript_name = matches.value_of("POSTSCRIPT-NAME").unwrap();
let text = matches.value_of("TEXT").unwrap();
let locale = matches.value_of("LOCALE").unwrap();
let postscript_name = matches
.get_one::<String>("POSTSCRIPT-NAME")
.map(|s| s.as_str())
.unwrap();
let text = matches
.get_one::<String>("TEXT")
.map(|s| s.as_str())
.unwrap();
let locale = matches
.get_one::<String>("LOCALE")
.map(|s| s.as_str())
.unwrap();
let font = SystemSource::new()
.select_by_postscript_name(&postscript_name)
.select_by_postscript_name(postscript_name)
.expect("Font not found")
.load()
.unwrap();
Expand Down
83 changes: 49 additions & 34 deletions examples/render-glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern crate colored;
extern crate font_kit;
extern crate pathfinder_geometry;

use clap::{App, Arg, ArgGroup, ArgMatches};
use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command};
use colored::Colorize;
use font_kit::canvas::{Canvas, Format, RasterizationOptions};
use font_kit::hinting::HintingOptions;
Expand All @@ -24,48 +24,49 @@ use std::fmt::Write;
#[cfg(any(target_family = "windows", target_os = "macos"))]
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &'static str = "ArialMT";
#[cfg(not(any(target_family = "windows", target_os = "macos")))]
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &'static str = "DejaVuSans";
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &str = "DejaVuSans";

fn get_args() -> ArgMatches<'static> {
let postscript_name_arg = Arg::with_name("POSTSCRIPT-NAME")
fn get_args() -> ArgMatches {
let postscript_name_arg = Arg::new("POSTSCRIPT-NAME")
.help("PostScript name of the font")
.default_value(SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME)
.index(1);
let glyph_arg = Arg::with_name("GLYPH")
let glyph_arg = Arg::new("GLYPH")
.help("Character to render")
.default_value("A")
.index(2);
let size_arg = Arg::with_name("SIZE")
let size_arg = Arg::new("SIZE")
.help("Font size in blocks")
.default_value("32")
.index(3);
let grayscale_arg = Arg::with_name("grayscale")
let grayscale_arg = Arg::new("grayscale")
.long("grayscale")
.help("Use grayscale antialiasing (default)");
let bilevel_arg = Arg::with_name("bilevel")
let bilevel_arg = Arg::new("bilevel")
.help("Use bilevel (black & white) rasterization")
.short("b")
.long("bilevel");
let subpixel_arg = Arg::with_name("subpixel")
.short('b')
.long("bilevel")
.action(ArgAction::SetTrue);
let subpixel_arg = Arg::new("subpixel")
.help("Use subpixel (LCD) rasterization")
.short("s")
.long("subpixel");
let hinting_arg = Arg::with_name("hinting")
.short('s')
.long("subpixel")
.action(ArgAction::SetTrue);
let hinting_value_parser =
clap::builder::PossibleValuesParser::new(["none", "vertical", "full"]);
let hinting_arg = Arg::new("hinting")
.help("Select hinting type")
.short("H")
.short('H')
.long("hinting")
.takes_value(true)
.possible_value("none")
.possible_value("vertical")
.possible_value("full")
.value_parser(hinting_value_parser)
.value_names(&["TYPE"]);
let transform_arg = Arg::with_name("transform")
let transform_arg = Arg::new("transform")
.help("Transform to apply to glyph when rendering")
.long("transform")
.number_of_values(4);
.num_args(4);
let rasterization_mode_group =
ArgGroup::with_name("rasterization-mode").args(&["grayscale", "bilevel", "subpixel"]);
App::new("render-glyph")
ArgGroup::new("rasterization-mode").args(&["grayscale", "bilevel", "subpixel"]);
Command::new("render-glyph")
.version("0.1")
.author("The Pathfinder Project Developers")
.about("Simple example tool to render glyphs with `font-kit`")
Expand All @@ -84,33 +85,47 @@ fn get_args() -> ArgMatches<'static> {
fn main() {
let matches = get_args();

let postscript_name = matches.value_of("POSTSCRIPT-NAME").unwrap();
let character = matches.value_of("GLYPH").unwrap().chars().next().unwrap();
let size: f32 = matches.value_of("SIZE").unwrap().parse().unwrap();
let postscript_name = matches
.get_one::<String>("POSTSCRIPT-NAME")
.map(|s| s.as_str())
.unwrap();
let character = matches
.get_one::<String>("GLYPH")
.map(|s| s.as_str())
.unwrap()
.chars()
.next()
.unwrap();
let size: f32 = matches
.get_one::<String>("SIZE")
.map(|s| s.as_str())
.unwrap()
.parse()
.unwrap();

let (canvas_format, rasterization_options) = if matches.is_present("bilevel") {
let (canvas_format, rasterization_options) = if matches.get_flag("bilevel") {
(Format::A8, RasterizationOptions::Bilevel)
} else if matches.is_present("subpixel") {
} else if matches.get_flag("subpixel") {
(Format::Rgb24, RasterizationOptions::SubpixelAa)
} else {
(Format::A8, RasterizationOptions::GrayscaleAa)
};

let mut transform = Transform2F::default();
if let Some(values) = matches.values_of("transform") {
if let Some(values) = matches.get_many::<String>("transform") {
if let [Ok(a), Ok(b), Ok(c), Ok(d)] = values.map(|x| x.parse()).collect::<Vec<_>>()[..] {
transform = Transform2F::row_major(a, b, c, d, 0.0, 0.0)
}
}

let hinting_options = match matches.value_of("hinting") {
Some(value) if value == "vertical" => HintingOptions::Vertical(size),
Some(value) if value == "full" => HintingOptions::Full(size),
let hinting_options = match matches.get_one::<String>("hinting").map(|s| s.as_str()) {
Some("vertical") => HintingOptions::Vertical(size),
Some("full") => HintingOptions::Full(size),
_ => HintingOptions::None,
};

let font = SystemSource::new()
.select_by_postscript_name(&postscript_name)
.select_by_postscript_name(postscript_name)
.unwrap()
.load()
.unwrap();
Expand Down Expand Up @@ -149,7 +164,7 @@ fn main() {
write!(
&mut line,
"{}{}{}",
shade(row[x as usize * 3 + 0]).to_string().red(),
shade(row[x as usize * 3]).to_string().red(),
shade(row[x as usize * 3 + 1]).to_string().green(),
shade(row[x as usize * 3 + 2]).to_string().blue()
)
Expand Down
6 changes: 6 additions & 0 deletions src/family_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct FamilyHandle {
pub(crate) fonts: Vec<Handle>,
}

impl Default for FamilyHandle {
fn default() -> Self {
Self::new()
}
}

impl FamilyHandle {
/// Creates an empty set of family handles.
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
//! * Looking up glyph advances and origins.
//!
//! * Rasterizing glyphs using the native rasterizer, optionally using hinting. (Custom
//! rasterizers, such as Pathfinder, can be used in conjuction with the outline API.)
//! rasterizers, such as Pathfinder, can be used in conjunction with the outline API.)
//!
//! * Looking up all fonts on the system.
//!
Expand Down
2 changes: 1 addition & 1 deletion src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub trait Loader: Clone + Sized {

/// Returns true if and only if the font loader can perform hinting in the requested way.
///
/// Some APIs support only rasterizing glyphs with hinting, not retriving hinted outlines. If
/// Some APIs support only rasterizing glyphs with hinting, not retrieving hinted outlines. If
/// `for_rasterization` is false, this function returns true if and only if the loader supports
/// retrieval of hinted *outlines*. If `for_rasterization` is true, this function returns true
/// if and only if the loader supports *rasterizing* hinted glyphs.
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/core_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl Font {

/// Returns true if and only if the font loader can perform hinting in the requested way.
///
/// Some APIs support only rasterizing glyphs with hinting, not retriving hinted outlines. If
/// Some APIs support only rasterizing glyphs with hinting, not retrieving hinted outlines. If
/// `for_rasterization` is false, this function returns true if and only if the loader supports
/// retrieval of hinted *outlines*. If `for_rasterization` is true, this function returns true
/// if and only if the loader supports *rasterizing* hinted glyphs.
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/directwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl Font {

/// Returns true if and only if the font loader can perform hinting in the requested way.
///
/// Some APIs support only rasterizing glyphs with hinting, not retriving hinted outlines. If
/// Some APIs support only rasterizing glyphs with hinting, not retrieving hinted outlines. If
/// `for_rasterization` is false, this function returns true if and only if the loader supports
/// retrieval of hinted *outlines*. If `for_rasterization` is true, this function returns true
/// if and only if the loader supports *rasterizing* hinted glyphs.
Expand Down
Loading

0 comments on commit d639dfb

Please sign in to comment.