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

Sync all changes from servo/font-kit up to version 0.12.0 #13

Merged
merged 29 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bd6b39d
Fix panic when parsing invalid `usWidthClass`
CryZe Nov 22, 2021
59213db
Auto merge of #189 - CryZe:fix-freetype-panic, r=jdm
bors-servo Nov 23, 2021
07181e1
Fix panic when converting from Rgb24 to Rgba32
PossiblyAShrub Jan 4, 2022
9d657cc
remove unnecesary parentheses
Be-ing Feb 15, 2022
c359470
Auto merge of #191 - PossiblyAShrub:convert-rgb24-rgba32, r=jdm
bors-servo Mar 27, 2022
4130e14
switch to yeslogic-fontconfig-sys
Be-ing Feb 15, 2022
75f99cf
Auto merge of #192 - Be-ing:dlopen, r=jdm
bors-servo Mar 28, 2022
0893ab9
fix compilation errors in tests
alexanderkjall Jun 18, 2022
5a2eb1c
Add FsSouce::in_path
Jesse-Bakker Jul 31, 2022
75b3702
Auto merge of #196 - alexanderkjall:fix-compilation-error-in-tests, r…
bors-servo Aug 15, 2022
4ec4978
Auto merge of #200 - Jesse-Bakker:fs-from_path, r=jdm
bors-servo Aug 15, 2022
b9d986d
Derive hash for `FamilyName` and `Style`
tealsnow Nov 26, 2022
82758fe
Auto merge of #202 - tealsnow:master, r=jdm
bors-servo Nov 27, 2022
77e1844
Switch to GitHub Actions badge and use SPDX license format
atouchet Nov 29, 2022
c72ca29
Auto merge of #203 - atouchet:cfg, r=jdm
bors-servo Nov 29, 2022
e5a591f
Bump prettytable to 0.10
pinkforest Dec 27, 2022
efa7739
Update linux test expectations.
jdm Dec 28, 2022
e402aa2
Auto merge of #205 - pinkforest:bump-prettytable, r=jdm
bors-servo Dec 28, 2022
787b68f
Bail out from rendering when bitmap_buffer is null
saethlin Jun 18, 2022
d183178
Merge pull request #197 from saethlin/master
Manishearth May 25, 2023
bdc6553
Enable the GitHub merge queue (#213)
mrobinson Jul 10, 2023
f9b1876
Fix thread-local freetype library memory leak (#214)
messense Aug 13, 2023
24324b0
Use font-config-sys 5.0 (#218)
jayvdb Nov 21, 2023
2ea57b3
Bump float-ord and some dev-dependencies (#219)
jayvdb Nov 21, 2023
0cd3d8b
Use bitflags 2.4 (#220)
jayvdb Nov 21, 2023
1b92b0c
Clippy fixes (#221)
jayvdb Nov 21, 2023
ec17086
Update dev-dependency clap to v4 (#223)
jayvdb Nov 21, 2023
25e2319
Update to version 0.12 in preparation for release (#222)
mrobinson Dec 1, 2023
8cd3bbf
Merge tag 'v0.12.0' into dan/sync-up-to-0.12
daprahamian Dec 15, 2023
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
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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 +17,7 @@ env:

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

ci-macos:
name: CI (macOS)
runs-on: macos-10.15
name: macOS
runs-on: macos-12
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -56,7 +59,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 +77,7 @@ jobs:
run: cargo test

build_result:
name: homu build finished
name: Result
runs-on: ubuntu-latest
needs:
- "ci-linux"
Expand Down
23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "font-kit"
version = "0.10.1"
version = "0.12.0"
authors = ["Patrick Walton <[email protected]>"]
description = "A cross-platform font loading library"
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/servo/font-kit"
homepage = "https://github.com/servo/font-kit"
Expand All @@ -14,14 +14,15 @@ edition = "2018"
default = ["source"]
loader-freetype = ["freetype"]
loader-freetype-default = ["loader-freetype"]
source-fontconfig = ["servo-fontconfig"]
source-fontconfig = ["yeslogic-fontconfig-sys"]
source-fontconfig-dlopen = ["yeslogic-fontconfig-sys/dlopen"]
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 @@ -32,15 +33,15 @@ pathfinder_simd = "0.5.1"
version = "0.7"
optional = true

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

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

[target.'cfg(target_family = "windows")'.dependencies]
dwrote = { version = "0.11", default-features = false }
Expand All @@ -62,7 +63,7 @@ core-text = {git = "https://github.com/warpdotdev/core-foundation-rs", rev = "37
freetype = "0.7"

[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32")))'.dependencies]
servo-fontconfig = "0.5"
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# font-kit
[![Build Status](https://travis-ci.org/servo/font-kit.svg?branch=master)](https://travis-ci.org/servo/font-kit)
[![Crates.io](https://img.shields.io/crates/v/font-kit.svg)](https://crates.io/crates/font-kit)

[![Build Status](https://github.com/servo/font-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/servo/font-kit/actions)
[![crates.io](https://img.shields.io/crates/v/font-kit.svg)](https://crates.io/crates/font-kit)
[![Documentation](https://docs.rs/font-kit/badge.svg)](https://docs.rs/font-kit)

`font-kit` provides a common interface to the various system font libraries and provides
Expand Down Expand Up @@ -106,7 +107,7 @@ included.

## Dependencies

**Ubuntu Linux**
**Ubuntu**

`sudo apt install pkg-config libfreetype6-dev libfontconfig1-dev`

Expand Down
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
println!("cargo:rerun-if-env-changed=RUST_FONTCONFIG_DLOPEN");
let dlopen = std::env::var("RUST_FONTCONFIG_DLOPEN").is_ok();
if dlopen {
println!("cargo:rustc-cfg=feature=\"source-fontconfig-dlopen\"");
}
}
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
87 changes: 51 additions & 36 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::{AntialiasingStrategy, Canvas, Format, RasterizationOptions};
use font_kit::hinting::HintingOptions;
Expand All @@ -24,51 +24,52 @@ 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"]);
let thin_strokes_arg = Arg::with_name("use_thin_strokes")
ArgGroup::new("rasterization-mode").args(&["grayscale", "bilevel", "subpixel"]);
let thin_strokes_arg = Arg::new("use_thin_strokes")
.help("Use thin strokes when rasterizing glyphs")
.long("use_thin_strokes");
App::new("render-glyph")
Command::new("render-glyph")
.version("0.1")
.author("The Pathfinder Project Developers")
.about("Simple example tool to render glyphs with `font-kit`")
Expand All @@ -88,38 +89,52 @@ 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, antialiasing_strategy) = if matches.is_present("bilevel") {
let (canvas_format, antialiasing_strategy) = if matches.get_flag("bilevel") {
(Format::A8, AntialiasingStrategy::Bilevel)
} else if matches.is_present("subpixel") {
} else if matches.get_flag("subpixel") {
(Format::Rgb24, AntialiasingStrategy::SubpixelAa)
} else {
(Format::A8, AntialiasingStrategy::GrayscaleAa)
};

let rasterization_options = RasterizationOptions {
antialiasing_strategy,
use_thin_strokes: matches.is_present("use_thin_strokes"),
use_thin_strokes: matches.get_flag("use_thin_strokes"),
};

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 @@ -158,7 +173,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
19 changes: 16 additions & 3 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ impl Canvas {
}
(Format::Rgb24, Format::Rgba32) => self
.blit_from_with::<BlitRgba32ToRgb24>(dst_rect, src_bytes, src_stride, src_format),
(Format::Rgba32, Format::Rgb24)
| (Format::Rgba32, Format::A8)
| (Format::A8, Format::Rgba32) => unimplemented!(),
(Format::Rgba32, Format::Rgb24) => self
.blit_from_with::<BlitRgb24ToRgba32>(dst_rect, src_bytes, src_stride, src_format),
(Format::Rgba32, Format::A8) | (Format::A8, Format::Rgba32) => unimplemented!(),
}
}

Expand Down Expand Up @@ -318,3 +318,16 @@ impl Blit for BlitRgba32ToRgb24 {
}
}
}

struct BlitRgb24ToRgba32;

impl Blit for BlitRgb24ToRgba32 {
fn blit(dest: &mut [u8], src: &[u8]) {
for (dest, src) in dest.chunks_mut(4).zip(src.chunks(3)) {
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
dest[3] = 255;
}
}
}
Loading
Loading