зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset e0f1d94942ce (bug 1757449) for causing build bustages on macOs. CLOSED TREE
This commit is contained in:
Родитель
441f38b43e
Коммит
b13da6025c
|
@ -5753,6 +5753,8 @@ dependencies = [
|
|||
"app_units",
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"core-foundation",
|
||||
"core-graphics",
|
||||
"crossbeam-channel",
|
||||
"derive_more",
|
||||
"euclid",
|
||||
|
|
|
@ -46,6 +46,11 @@ use webrender::{
|
|||
};
|
||||
use wr_malloc_size_of::MallocSizeOfOps;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use core_foundation::string::CFString;
|
||||
#[cfg(target_os = "macos")]
|
||||
use core_graphics::font::CGFont;
|
||||
|
||||
extern "C" {
|
||||
#[cfg(target_os = "android")]
|
||||
fn __android_log_write(prio: c_int, tag: *const c_char, text: *const c_char) -> c_int;
|
||||
|
@ -2293,9 +2298,20 @@ fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle {
|
|||
#[cfg(target_os = "macos")]
|
||||
fn read_font_descriptor(bytes: &mut WrVecU8, _index: u32) -> NativeFontHandle {
|
||||
let chars = bytes.flush_into_vec();
|
||||
NativeFontHandle {
|
||||
name: String::from_utf8(chars).unwrap()
|
||||
}
|
||||
let name = String::from_utf8(chars).unwrap();
|
||||
let font = match CGFont::from_name(&CFString::new(&*name)) {
|
||||
Ok(font) => font,
|
||||
Err(_) => {
|
||||
// If for some reason we failed to load a font descriptor, then our
|
||||
// only options are to either abort or substitute a fallback font.
|
||||
// It is preferable to use a fallback font instead so that rendering
|
||||
// can at least still proceed in some fashion without erroring.
|
||||
// Lucida Grande is the fallback font in Gecko, so use that here.
|
||||
CGFont::from_name(&CFString::from_static_string("Lucida Grande"))
|
||||
.expect("Failed reading font descriptor and could not load fallback font")
|
||||
},
|
||||
};
|
||||
NativeFontHandle(font)
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
||||
|
|
|
@ -32,10 +32,6 @@ use std::sync::Arc;
|
|||
#[cfg(target_os = "windows")]
|
||||
use dwrote;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use core_foundation::string::CFString;
|
||||
#[cfg(target_os = "macos")]
|
||||
use core_graphics::font::CGFont;
|
||||
#[cfg(target_os = "macos")]
|
||||
use foreign_types::ForeignType;
|
||||
|
||||
|
@ -786,19 +782,7 @@ impl Moz2dBlobImageHandler {
|
|||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) {
|
||||
let font = match CGFont::from_name(&CFString::new(&handle.name)) {
|
||||
Ok(font) => font,
|
||||
Err(_) => {
|
||||
// If for some reason we failed to load a font descriptor, then our
|
||||
// only options are to either abort or substitute a fallback font.
|
||||
// It is preferable to use a fallback font instead so that rendering
|
||||
// can at least still proceed in some fashion without erroring.
|
||||
// Lucida Grande is the fallback font in Gecko, so use that here.
|
||||
CGFont::from_name(&CFString::from_static_string("Lucida Grande"))
|
||||
.expect("Failed reading font descriptor and could not load fallback font")
|
||||
},
|
||||
};
|
||||
unsafe { AddNativeFontHandle(key, font.as_ptr() as *mut c_void, 0) };
|
||||
unsafe { AddNativeFontHandle(key, handle.0.as_ptr() as *mut c_void, 0) };
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
||||
|
|
|
@ -1719,6 +1719,8 @@ dependencies = [
|
|||
"app_units",
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"core-foundation 0.9.2",
|
||||
"core-graphics 0.22.3",
|
||||
"crossbeam-channel",
|
||||
"derive_more",
|
||||
"euclid",
|
||||
|
|
|
@ -276,28 +276,16 @@ impl FontContext {
|
|||
// and use the descriptor for that. Normally we'd try to avoid new_from_CGFont
|
||||
// because that adds the CGFont to the descriptor cache which can keep the CGFont
|
||||
// around for a long time, but that should be ok for non-web (native) fonts.
|
||||
let cf_name = CFString::new(&native_font_handle.name);
|
||||
|
||||
let name = native_font_handle.0.postscript_name();
|
||||
// For "hidden" system fonts, whose names start with a period,
|
||||
// we can't instantiate CTFonts via a descriptor. We're really
|
||||
// supposed to use CTFontCreateUIFontForLanguage, but for now
|
||||
// we just use the CGFont.
|
||||
let desc = if native_font_handle.name.starts_with('.') {
|
||||
let cg_font = match CGFont::from_name(&cf_name) {
|
||||
Ok(cg_font) => cg_font,
|
||||
Err(_) => {
|
||||
// If for some reason we failed to load a font descriptor, then our
|
||||
// only options are to either abort or substitute a fallback font.
|
||||
// It is preferable to use a fallback font instead so that rendering
|
||||
// can at least still proceed in some fashion without erroring.
|
||||
// Lucida Grande is the fallback font in Gecko, so use that here.
|
||||
CGFont::from_name(&CFString::from_static_string("Lucida Grande"))
|
||||
.expect("couldn't find font with postscript name and couldn't load fallback font")
|
||||
}
|
||||
};
|
||||
core_text::font::new_from_CGFont(&cg_font, 0.).copy_descriptor()
|
||||
let desc = if name.to_string().starts_with('.') {
|
||||
core_text::font::new_from_CGFont(&native_font_handle.0, 0.).copy_descriptor()
|
||||
} else {
|
||||
core_text::font_descriptor::new_from_postscript_name(&cf_name)
|
||||
core_text::font_descriptor::new_from_postscript_name(&name)
|
||||
};
|
||||
|
||||
self.ct_font_descs
|
||||
|
|
|
@ -1970,7 +1970,7 @@ impl ResourceCache {
|
|||
#[cfg(target_os = "macos")]
|
||||
FontTemplate::Native(ref native) => {
|
||||
PlainFontTemplate {
|
||||
data: native.name.clone(),
|
||||
data: native.0.postscript_name().to_string(),
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,3 +27,7 @@ time = "0.1"
|
|||
malloc_size_of = { version = "0.0.1", path = "../wr_malloc_size_of", package = "wr_malloc_size_of" }
|
||||
peek-poke = { version = "0.2", path = "../peek-poke", features = ["extras"] }
|
||||
crossbeam-channel = "0.5"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
core-foundation = "0.9"
|
||||
core-graphics = "0.22"
|
||||
|
|
|
@ -2,7 +2,15 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use core_foundation::string::CFString;
|
||||
#[cfg(target_os = "macos")]
|
||||
use core_graphics::font::CGFont;
|
||||
use peek_poke::PeekPoke;
|
||||
#[cfg(target_os = "macos")]
|
||||
use serde::de::{self, Deserialize, Deserializer};
|
||||
#[cfg(target_os = "macos")]
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
use std::cmp::Ordering;
|
||||
use std::hash::{Hash, Hasher};
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
|
@ -198,9 +206,37 @@ pub struct NativeFontHandle {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct NativeFontHandle {
|
||||
pub name: String,
|
||||
#[derive(Clone)]
|
||||
pub struct NativeFontHandle(pub CGFont);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
impl Serialize for NativeFontHandle {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.0
|
||||
.postscript_name()
|
||||
.to_string()
|
||||
.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
impl<'de> Deserialize<'de> for NativeFontHandle {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let postscript_name: String = Deserialize::deserialize(deserializer)?;
|
||||
|
||||
match CGFont::from_name(&CFString::new(&*postscript_name)) {
|
||||
Ok(font) => Ok(NativeFontHandle(font)),
|
||||
Err(_) => Err(de::Error::custom(
|
||||
"Couldn't find a font with that PostScript name!",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
|
@ -24,6 +24,10 @@ extern crate bitflags;
|
|||
extern crate byteorder;
|
||||
#[cfg(feature = "nightly")]
|
||||
extern crate core;
|
||||
#[cfg(target_os = "macos")]
|
||||
extern crate core_foundation;
|
||||
#[cfg(target_os = "macos")]
|
||||
extern crate core_graphics;
|
||||
extern crate derive_more;
|
||||
#[macro_use]
|
||||
extern crate malloc_size_of_derive;
|
||||
|
|
Загрузка…
Ссылка в новой задаче