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

support synthetic bold on Windows using DWrite font simulations #2120

Merged
merged 1 commit into from Nov 29, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -1,6 +1,6 @@
[package]
name = "webrender"
version = "0.54.0"
version = "0.55.0"
authors = ["Glenn Watson <gw@intuitionlibrary.com>"]
license = "MPL-2.0"
repository = "https://github.com/servo/webrender"
@@ -43,7 +43,7 @@ servo-glutin = "0.13" # for the example apps
freetype = { version = "0.3", default-features = false }

[target.'cfg(target_os = "windows")'.dependencies]
dwrote = "0.4"
dwrote = "0.4.1"

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.4"
@@ -1286,9 +1286,9 @@ impl FrameBuilder {
font.bg_color,
render_mode,
font.subpx_dir,
font.flags,
font.platform_options,
font.variations.clone(),
font.synthetic_italics,
);
let prim = TextRunPrimitiveCpu {
font: prim_font,
@@ -5,8 +5,9 @@
#[cfg(test)]
use api::{IdNamespace, LayoutPoint};
use api::{ColorF, ColorU, DevicePoint, DeviceUintSize};
use api::{FontInstancePlatformOptions, FontRenderMode, FontVariation};
use api::{FontKey, FontTemplate, GlyphDimensions, GlyphKey, SubpixelDirection};
use api::{FontInstanceFlags, FontInstancePlatformOptions};
use api::{FontKey, FontRenderMode, FontTemplate, FontVariation};
use api::{GlyphDimensions, GlyphKey, SubpixelDirection};
use api::{ImageData, ImageDescriptor, ImageFormat, LayerToWorldTransform};
use app_units::Au;
use device::TextureFilter;
@@ -139,9 +140,9 @@ pub struct FontInstance {
pub bg_color: ColorU,
pub render_mode: FontRenderMode,
pub subpx_dir: SubpixelDirection,
pub flags: FontInstanceFlags,
pub platform_options: Option<FontInstancePlatformOptions>,
pub variations: Vec<FontVariation>,
pub synthetic_italics: bool,
pub transform: FontTransform,
}

@@ -153,9 +154,9 @@ impl FontInstance {
bg_color: ColorU,
render_mode: FontRenderMode,
subpx_dir: SubpixelDirection,
flags: FontInstanceFlags,
platform_options: Option<FontInstancePlatformOptions>,
variations: Vec<FontVariation>,
synthetic_italics: bool,
) -> Self {
FontInstance {
font_key,
@@ -164,9 +165,9 @@ impl FontInstance {
bg_color,
render_mode,
subpx_dir,
flags,
platform_options,
variations,
synthetic_italics,
transform: FontTransform::identity(),
}
}
@@ -611,9 +612,9 @@ fn raterize_200_glyphs() {
ColorU::new(0, 0, 0, 0),
FontRenderMode::Subpixel,
SubpixelDirection::Horizontal,
Default::default(),
None,
Vec::new(),
false,
);

let mut glyph_keys = Vec::with_capacity(200);
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{ColorU, FontKey, FontRenderMode, GlyphDimensions};
use api::{FontVariation, NativeFontHandle};
use api::{FontInstanceFlags, FontVariation, NativeFontHandle};
use api::{GlyphKey, SubpixelDirection};
use app_units::Au;
use core_foundation::array::{CFArray, CFArrayRef};
@@ -282,7 +282,7 @@ impl FontContext {
Err(_) => return,
Ok(cg_font) => cg_font,
};
self.cg_fonts.insert((*font_key).clone(), cg_font);
self.cg_fonts.insert(*font_key, cg_font);
}

pub fn add_native_font(&mut self, font_key: &FontKey, native_font_handle: NativeFontHandle) {
@@ -291,21 +291,12 @@ impl FontContext {
}

self.cg_fonts
.insert((*font_key).clone(), native_font_handle.0);
.insert(*font_key, native_font_handle.0);
}

pub fn delete_font(&mut self, font_key: &FontKey) {
if let Some(_) = self.cg_fonts.remove(font_key) {
// Unstable Rust has a retain() method on HashMap that will
// let us do this in-place. https://github.com/rust-lang/rust/issues/36648
let ct_font_keys = self.ct_fonts
.keys()
.filter(|k| k.0 == *font_key)
.cloned()
.collect::<Vec<_>>();
for ct_font_key in ct_font_keys {
self.ct_fonts.remove(&ct_font_key);
}
self.ct_fonts.retain(|k, _| k.0 != *font_key);
}
}

@@ -425,7 +416,7 @@ impl FontContext {
font.subpx_dir = SubpixelDirection::None;
}
FontRenderMode::Alpha => {
font.color = if font.platform_options.unwrap_or_default().font_smoothing {
font.color = if font.flags.contains(FontInstanceFlags::FONT_SMOOTHING) {
// Only the G channel is used to index grayscale tables,
// so use R and B to preserve light/dark determination.
let ColorU { g, a, .. } = font.color.luminance_color().quantized_ceil();
@@ -545,7 +536,7 @@ impl FontContext {
// to both the Subpixel and the "Alpha + smoothing" modes, but not to
// the "Alpha without smoothing" and Mono modes.
let use_white_on_black = should_use_white_on_black(font.color);
let use_font_smoothing = font.platform_options.unwrap_or_default().font_smoothing;
let use_font_smoothing = font.flags.contains(FontInstanceFlags::FONT_SMOOTHING);
let (antialias, smooth, text_color, bg_color, bg_alpha, invert) =
match (font.render_mode, use_font_smoothing) {
(FontRenderMode::Subpixel, _) |
@@ -4,9 +4,7 @@

use api::{ColorU, GlyphDimensions, GlyphKey, FontKey, FontRenderMode};
use api::{FontInstancePlatformOptions, FontLCDFilter, FontHinting};
use api::{NativeFontHandle, SubpixelDirection};
use api::{FONT_FORCE_AUTOHINT, FONT_NO_AUTOHINT, FONT_EMBEDDED_BITMAP};
use api::{FONT_EMBOLDEN, FONT_VERTICAL_LAYOUT, FONT_SUBPIXEL_BGR};
use api::{FontInstanceFlags, NativeFontHandle, SubpixelDirection};
use freetype::freetype::{FT_BBox, FT_Outline_Translate, FT_Pixel_Mode, FT_Render_Mode};
use freetype::freetype::{FT_Done_Face, FT_Error, FT_Get_Char_Index, FT_Int32};
use freetype::freetype::{FT_Done_FreeType, FT_Library_SetLcdFilter, FT_Pos};
@@ -153,7 +151,7 @@ impl FontContext {
let face = self.faces.get(&font.font_key).unwrap();

let mut load_flags = FT_LOAD_DEFAULT;
let FontInstancePlatformOptions { flags, hinting, .. } = font.platform_options.unwrap_or_default();
let FontInstancePlatformOptions { hinting, .. } = font.platform_options.unwrap_or_default();
match (hinting, font.render_mode) {
(FontHinting::None, _) => load_flags |= FT_LOAD_NO_HINTING,
(FontHinting::Mono, _) => load_flags = FT_LOAD_TARGET_MONO,
@@ -163,24 +161,24 @@ impl FontContext {
SubpixelDirection::Vertical => FT_LOAD_TARGET_LCD_V,
_ => FT_LOAD_TARGET_LCD,
};
if (flags & FONT_FORCE_AUTOHINT) != 0 {
if font.flags.contains(FontInstanceFlags::FORCE_AUTOHINT) {
load_flags |= FT_LOAD_FORCE_AUTOHINT;
}
}
_ => {
if (flags & FONT_FORCE_AUTOHINT) != 0 {
if font.flags.contains(FontInstanceFlags::FORCE_AUTOHINT) {
load_flags |= FT_LOAD_FORCE_AUTOHINT;
}
}
}

if (flags & FONT_NO_AUTOHINT) != 0 {
if font.flags.contains(FontInstanceFlags::NO_AUTOHINT) {
load_flags |= FT_LOAD_NO_AUTOHINT;
}
if (flags & FONT_EMBEDDED_BITMAP) == 0 {
if font.flags.contains(FontInstanceFlags::EMBEDDED_BITMAPS) {
load_flags |= FT_LOAD_NO_BITMAP;
}
if (flags & FONT_VERTICAL_LAYOUT) != 0 {
if font.flags.contains(FontInstanceFlags::VERTICAL_LAYOUT) {
load_flags |= FT_LOAD_VERTICAL_LAYOUT;
}

@@ -224,7 +222,7 @@ impl FontContext {
let slot = unsafe { (*face.face).glyph };
assert!(slot != ptr::null_mut());

if (flags & FONT_EMBOLDEN) != 0 {
if font.flags.contains(FontInstanceFlags::SYNTHETIC_BOLD) {
unsafe { FT_GlyphSlot_Embolden(slot) };
}

@@ -385,15 +383,9 @@ impl FontContext {
let face_flags = unsafe { (*face.face).face_flags };
// If the face has embedded bitmaps, they should only be used if either
// embedded bitmaps are explicitly requested or if the face has no outline.
if (face_flags & (FT_FACE_FLAG_FIXED_SIZES as FT_Long)) != 0 {
let FontInstancePlatformOptions { flags, .. } = font.platform_options.unwrap_or_default();
if (flags & FONT_EMBEDDED_BITMAP) != 0 {
return true;
}
(face_flags & (FT_FACE_FLAG_SCALABLE as FT_Long)) == 0
} else {
false
}
(face_flags & (FT_FACE_FLAG_FIXED_SIZES as FT_Long)) != 0 &&
(font.flags.contains(FontInstanceFlags::EMBEDDED_BITMAPS) ||
(face_flags & (FT_FACE_FLAG_SCALABLE as FT_Long)) == 0)
}

fn choose_bitmap_size(&self, face: FT_Face, requested_size: f64) -> FT_Error {
@@ -451,7 +443,7 @@ impl FontContext {
dy - ((cbox.yMin + dy) & !63),
);

if font.synthetic_italics {
if font.flags.contains(FontInstanceFlags::SYNTHETIC_ITALICS) {
FT_GlyphSlot_Oblique(slot);
}
}
@@ -555,8 +547,7 @@ impl FontContext {

// Extract the final glyph from FT format into RGBA8 format, which is
// what WR expects.
let FontInstancePlatformOptions { flags, .. } = font.platform_options.unwrap_or_default();
let subpixel_bgr = (flags & FONT_SUBPIXEL_BGR) != 0;
let subpixel_bgr = font.flags.contains(FontInstanceFlags::SUBPIXEL_BGR);
let mut src_row = bitmap.buffer;
let mut dest: usize = 0;
while dest < final_buffer.len() {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.