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 changes from mozilla-central #3816

Merged
merged 3 commits into from Dec 18, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Bug 1600470 - Reduce the emboldening strength used for synthetic-bold…

  • Loading branch information
jfkthame authored and moz-gfx committed Dec 18, 2019
commit e27eb3a133c4fbfa70106bf04b3810de1f868d30
@@ -13,7 +13,7 @@ use freetype::freetype::{FT_GlyphSlot, FT_LcdFilter, FT_New_Face, FT_New_Memory_
use freetype::freetype::{FT_Init_FreeType, FT_Load_Glyph, FT_Render_Glyph};
use freetype::freetype::{FT_Library, FT_Outline_Get_CBox, FT_Set_Char_Size, FT_Select_Size};
use freetype::freetype::{FT_Fixed, FT_Matrix, FT_Set_Transform, FT_String, FT_ULong};
use freetype::freetype::{FT_Err_Unimplemented_Feature};
use freetype::freetype::{FT_Err_Unimplemented_Feature, FT_MulFix, FT_Outline_Embolden};
use freetype::freetype::{FT_LOAD_COLOR, FT_LOAD_DEFAULT, FT_LOAD_FORCE_AUTOHINT};
use freetype::freetype::{FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH, FT_LOAD_NO_AUTOHINT};
use freetype::freetype::{FT_LOAD_NO_BITMAP, FT_LOAD_NO_HINTING};
@@ -109,6 +109,46 @@ extern "C" {
fn FT_GlyphSlot_Embolden(slot: FT_GlyphSlot);
}

// Custom version of FT_GlyphSlot_Embolden to be less aggressive with outline
// fonts than the default implementation in FreeType.
#[no_mangle]
pub extern "C" fn mozilla_glyphslot_embolden_less(slot: FT_GlyphSlot) {
if slot.is_null() {
return;
}

let slot_ = unsafe { &mut *slot };
let format = slot_.format;
if format != FT_Glyph_Format::FT_GLYPH_FORMAT_OUTLINE {
// For non-outline glyphs, just fall back to FreeType's function.
unsafe { FT_GlyphSlot_Embolden(slot) };
return;
}

let face_ = unsafe { *slot_.face };

// FT_GlyphSlot_Embolden uses a divisor of 24 here; we'll be only half as
// bold.
let size_ = unsafe { *face_.size };
let strength =
unsafe { FT_MulFix(face_.units_per_EM as FT_Long,
size_.metrics.y_scale) / 48 };
unsafe { FT_Outline_Embolden(&mut slot_.outline, strength) };

// Adjust metrics to suit the fattened glyph.
if slot_.advance.x != 0 {
slot_.advance.x += strength;
}
if slot_.advance.y != 0 {
slot_.advance.y += strength;
}
slot_.metrics.width += strength;
slot_.metrics.height += strength;
slot_.metrics.horiAdvance += strength;
slot_.metrics.vertAdvance += strength;
slot_.metrics.horiBearingY += strength;
}

enum FontFile {
Pathname(CString),
Data(Arc<Vec<u8>>),
@@ -495,7 +535,7 @@ impl FontContext {
assert!(slot != ptr::null_mut());

if font.flags.contains(FontInstanceFlags::SYNTHETIC_BOLD) {
unsafe { FT_GlyphSlot_Embolden(slot) };
mozilla_glyphslot_embolden_less(slot);
}

let format = unsafe { (*slot).format };
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.