Bug 1403198 - support WR font descriptors on Mac. r=jrmuizel

MozReview-Commit-ID: BqN51yY88oJ
This commit is contained in:
Lee Salzman 2017-11-06 20:21:06 -05:00
Родитель 3e6f5e1180
Коммит 826eee8b2a
9 изменённых файлов: 61 добавлений и 3 удалений

Просмотреть файл

@ -57,7 +57,7 @@ NativeFontResourceMac::CreateUnscaledFont(uint32_t aIndex,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength)
{
RefPtr<UnscaledFont> unscaledFont = new UnscaledFontMac(mFontRef);
RefPtr<UnscaledFont> unscaledFont = new UnscaledFontMac(mFontRef, true);
return unscaledFont.forget();
}

Просмотреть файл

@ -325,6 +325,31 @@ UnscaledFontMac::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
return true;
}
bool
UnscaledFontMac::GetWRFontDescriptor(WRFontDescriptorOutput aCb, void* aBaton)
{
if (mIsDataFont) {
return false;
}
CFStringRef psname = CGFontCopyPostScriptName(mFont);
if (!psname) {
return false;
}
char buf[256];
const char* cstr = CFStringGetCStringPtr(psname, kCFStringEncodingUTF8);
if (!cstr) {
if (!CFStringGetCString(psname, buf, sizeof(buf), kCFStringEncodingUTF8)) {
return false;
}
cstr = buf;
}
aCb(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr), 0, aBaton);
return true;
}
static void
CollectVariationsFromDictionary(const void* aKey, const void* aValue, void* aContext)
{

Просмотреть файл

@ -23,8 +23,9 @@ class UnscaledFontMac final : public UnscaledFont
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(UnscaledFontMac, override)
explicit UnscaledFontMac(CGFontRef aFont)
explicit UnscaledFontMac(CGFontRef aFont, bool aIsDataFont = false)
: mFont(aFont)
, mIsDataFont(aIsDataFont)
{
CFRetain(mFont);
}
@ -51,8 +52,11 @@ public:
uint32_t aVariationCount,
const FontVariation* aVariations);
bool GetWRFontDescriptor(WRFontDescriptorOutput aCb, void* aBaton) override;
private:
CGFontRef mFont;
bool mIsDataFont;
};
} // namespace gfx

Просмотреть файл

@ -270,7 +270,7 @@ MacOSFontEntry::CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBo
if (!baseFont) {
return nullptr;
}
unscaledFont = new UnscaledFontMac(baseFont);
unscaledFont = new UnscaledFontMac(baseFont, mIsDataUserFont);
mUnscaledFont = unscaledFont;
}

Просмотреть файл

@ -21,3 +21,7 @@ default-features = false
[target.'cfg(target_os = "windows")'.dependencies]
dwrote = "0.4"
[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.4"
core-graphics = "0.9"

Просмотреть файл

@ -21,6 +21,11 @@ use log::{set_logger, shutdown_logger, LogLevelFilter, Log, LogLevel, LogMetadat
#[cfg(target_os = "windows")]
use dwrote::{FontDescriptor, FontWeight, FontStretch, FontStyle};
#[cfg(target_os = "macos")]
use core_foundation::string::CFString;
#[cfg(target_os = "macos")]
use core_graphics::font::CGFont;
extern crate webrender_api;
/// cbindgen:field-names=[mNamespace, mHandle]
@ -999,6 +1004,17 @@ fn read_font_descriptor(
}
}
#[cfg(target_os = "macos")]
fn read_font_descriptor(
bytes: &mut WrVecU8,
_index: u32
) -> NativeFontHandle {
let chars = bytes.flush_into_vec();
let name = String::from_utf8(chars).unwrap();
let font = CGFont::from_name(&CFString::new(&*name)).unwrap();
NativeFontHandle(font)
}
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
fn read_font_descriptor(
bytes: &mut WrVecU8,

Просмотреть файл

@ -16,6 +16,11 @@ extern crate log;
#[cfg(target_os = "windows")]
extern crate dwrote;
#[cfg(target_os = "macos")]
extern crate core_foundation;
#[cfg(target_os = "macos")]
extern crate core_graphics;
#[allow(non_snake_case)]
pub mod bindings;
pub mod moz2d_renderer;

2
toolkit/library/gtest/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -1517,6 +1517,8 @@ name = "webrender_bindings"
version = "0.1.0"
dependencies = [
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"dwrote 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",

2
toolkit/library/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -1529,6 +1529,8 @@ name = "webrender_bindings"
version = "0.1.0"
dependencies = [
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"dwrote 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",