Skip to content

Commit

Permalink
Use yeslogic-fontconfig-sys instead of servo
Browse files Browse the repository at this point in the history
The servo crate is not maintained anymore.

This also bumps freetype-rs along the way, since it had circular
dependency.
  • Loading branch information
kchibisov committed Feb 19, 2024
1 parent e59e1d0 commit 9461760
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ foreign-types = "0.5"
log = "0.4"

[target.'cfg(not(any(target_os = "macos", windows)))'.dependencies]
servo-fontconfig = "0.5.1"
freetype-rs = "0.26"
yeslogic-fontconfig-sys = "5.0.0"
freetype-rs = "0.36.0"

[target.'cfg(not(any(target_os = "macos", windows)))'.build-dependencies]
pkg-config = "0.3"
Expand All @@ -36,6 +36,3 @@ once_cell = "1.12"
[target.'cfg(windows)'.dependencies]
dwrote = { version = "0.11" }
winapi = { version = "0.3", features = ["impl-default"] }

[features]
force_system_fontconfig = ["servo-fontconfig/force_system_lib"]
10 changes: 5 additions & 5 deletions src/ft/fc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use std::ptr;

use foreign_types::{ForeignType, ForeignTypeRef};

use fontconfig::fontconfig as ffi;
use fontconfig_sys as ffi;

use ffi::constants::{FC_SLANT_ITALIC, FC_SLANT_OBLIQUE, FC_SLANT_ROMAN};
use ffi::constants::{FC_WEIGHT_BLACK, FC_WEIGHT_BOLD, FC_WEIGHT_EXTRABLACK, FC_WEIGHT_EXTRABOLD};
use ffi::constants::{FC_WEIGHT_BOOK, FC_WEIGHT_MEDIUM, FC_WEIGHT_REGULAR, FC_WEIGHT_SEMIBOLD};
use ffi::constants::{FC_WEIGHT_EXTRALIGHT, FC_WEIGHT_LIGHT, FC_WEIGHT_THIN};
use ffi::FcInitBringUptoDate;
use ffi::FcResultNoMatch;
use ffi::{FcFontList, FcFontMatch, FcFontSort};
use ffi::{FcMatchFont, FcMatchPattern, FcMatchScan};
use ffi::{FcSetApplication, FcSetSystem};
use ffi::{FC_SLANT_ITALIC, FC_SLANT_OBLIQUE, FC_SLANT_ROMAN};
use ffi::{FC_WEIGHT_BLACK, FC_WEIGHT_BOLD, FC_WEIGHT_EXTRABLACK, FC_WEIGHT_EXTRABOLD};
use ffi::{FC_WEIGHT_BOOK, FC_WEIGHT_MEDIUM, FC_WEIGHT_REGULAR, FC_WEIGHT_SEMIBOLD};
use ffi::{FC_WEIGHT_EXTRALIGHT, FC_WEIGHT_LIGHT, FC_WEIGHT_THIN};

pub mod config;
pub use config::{Config, ConfigRef};
Expand Down
15 changes: 6 additions & 9 deletions src/ft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl fmt::Debug for FaceLoadingProperties {
freetype::RenderMode::Lcd => "Lcd",
freetype::RenderMode::LcdV => "LcdV",
freetype::RenderMode::Max => "Max",
freetype::RenderMode::Sdf => "Sdf",
})
.field("lcd_filter", &self.lcd_filter)
.finish()
Expand Down Expand Up @@ -201,7 +202,7 @@ impl Rasterize for FreeTypeRasterizer {
fn get_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> {
let font_key = self.face_for_glyph(glyph_key);
let face = &self.loader.faces[&font_key];
let index = face.ft_face.get_char_index(glyph_key.character as usize);
let index = face.ft_face.get_char_index(glyph_key.character as usize).unwrap_or_default();
let pixelsize = face.non_scalable.unwrap_or_else(|| glyph_key.size.as_px());

if !face.colored_bitmap {
Expand Down Expand Up @@ -292,8 +293,8 @@ impl Rasterize for FreeTypeRasterizer {
return (0., 0.);
}

let left = ft_face.get_char_index(left.character as usize);
let right = ft_face.get_char_index(right.character as usize);
let left = ft_face.get_char_index(left.character as usize).unwrap_or_default();
let right = ft_face.get_char_index(right.character as usize).unwrap_or_default();

let mut kerning = freetype_sys::FT_Vector::default();
let mode = freetype_sys::FT_KERNING_DEFAULT;
Expand Down Expand Up @@ -423,9 +424,7 @@ impl FreeTypeRasterizer {

fn face_for_glyph(&mut self, glyph_key: GlyphKey) -> FontKey {
if let Some(face) = self.loader.faces.get(&glyph_key.font_key) {
let index = face.ft_face.get_char_index(glyph_key.character as usize);

if index != 0 {
if face.ft_face.get_char_index(glyph_key.character as usize).is_some() {
return glyph_key.font_key;
}
}
Expand All @@ -446,10 +445,8 @@ impl FreeTypeRasterizer {
let font_pattern = &fallback_font.pattern;
match self.loader.faces.get(&font_key) {
Some(face) => {
let index = face.ft_face.get_char_index(glyph.character as usize);

// We found something in a current face, so let's use it.
if index != 0 {
if face.ft_face.get_char_index(glyph.character as usize).is_some() {
return Ok(font_key);
}
},
Expand Down

0 comments on commit 9461760

Please sign in to comment.