Bug 1547063 - implement recording instance data for ScaledFontMac. r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D44495

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Lee Salzman 2019-09-16 16:45:26 +00:00
Родитель 286a7bbfff
Коммит 4f2be9076e
3 изменённых файлов: 69 добавлений и 3 удалений

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

@ -431,7 +431,10 @@ bool ScaledFontMac::GetFontInstanceData(FontInstanceDataOutput aCb,
if (!GetVariationsForCTFont(mCTFont, &variations)) {
return false;
}
aCb(nullptr, 0, variations.data(), variations.size(), aBaton);
InstanceData instance(this);
aCb(reinterpret_cast<uint8_t*>(&instance), sizeof(instance),
variations.data(), variations.size(), aBaton);
return true;
}
@ -457,6 +460,27 @@ bool ScaledFontMac::GetWRFontInstanceOptions(
return true;
}
ScaledFontMac::InstanceData::InstanceData(
const wr::FontInstanceOptions* aOptions,
const wr::FontInstancePlatformOptions* aPlatformOptions)
: mUseFontSmoothing(true), mApplySyntheticBold(false) {
if (aOptions) {
if (!(aOptions->flags & wr::FontInstanceFlags_FONT_SMOOTHING)) {
mUseFontSmoothing = false;
}
if (aOptions->flags & wr::FontInstanceFlags_SYNTHETIC_BOLD) {
mApplySyntheticBold = true;
}
if (aOptions->bg_color.a != 0) {
mFontSmoothingBackgroundColor =
Color(aOptions->bg_color.r * (1.0f / 255.0f),
aOptions->bg_color.g * (1.0f / 255.0f),
aOptions->bg_color.b * (1.0f / 255.0f),
aOptions->bg_color.a * (1.0f / 255.0f));
}
}
}
static CFDictionaryRef CreateVariationDictionaryOrNull(
CGFontRef aCGFont, uint32_t aVariationCount,
const FontVariation* aVariations) {
@ -578,6 +602,13 @@ already_AddRefed<ScaledFont> UnscaledFontMac::CreateScaledFont(
uint32_t aNumVariations)
{
if (aInstanceDataLength < sizeof(ScaledFontMac::InstanceData)) {
gfxWarning() << "Mac scaled font instance data is truncated.";
return nullptr;
}
const ScaledFontMac::InstanceData& instanceData =
*reinterpret_cast<const ScaledFontMac::InstanceData*>(aInstanceData);
CGFontRef fontRef = mFont;
if (aNumVariations > 0) {
CGFontRef varFont =
@ -587,8 +618,10 @@ already_AddRefed<ScaledFont> UnscaledFontMac::CreateScaledFont(
}
}
RefPtr<ScaledFontMac> scaledFont =
new ScaledFontMac(fontRef, this, aGlyphSize, fontRef != mFont);
RefPtr<ScaledFontMac> scaledFont = new ScaledFontMac(
fontRef, this, aGlyphSize, fontRef != mFont,
instanceData.mFontSmoothingBackgroundColor,
instanceData.mUseFontSmoothing, instanceData.mApplySyntheticBold);
if (mNeedsCairo && !scaledFont->PopulateCairoScaledFont()) {
gfxWarning() << "Unable to create cairo scaled Mac font.";
@ -598,6 +631,15 @@ already_AddRefed<ScaledFont> UnscaledFontMac::CreateScaledFont(
return scaledFont.forget();
}
already_AddRefed<ScaledFont> UnscaledFontMac::CreateScaledFontFromWRFont(
Float aGlyphSize, const wr::FontInstanceOptions* aOptions,
const wr::FontInstancePlatformOptions* aPlatformOptions,
const FontVariation* aVariations, uint32_t aNumVariations) {
ScaledFontMac::InstanceData instanceData(aOptions, aPlatformOptions);
return CreateScaledFont(aGlyphSize, reinterpret_cast<uint8_t*>(&instanceData),
sizeof(instanceData), aVariations, aNumVariations);
}
#ifdef USE_CAIRO_SCALED_FONT
cairo_font_face_t* ScaledFontMac::GetCairoFontFace() {
MOZ_ASSERT(mFont);

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

@ -21,6 +21,8 @@
namespace mozilla {
namespace gfx {
class UnscaledFontMac;
class ScaledFontMac : public ScaledFontBase {
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontMac, override)
@ -53,12 +55,29 @@ class ScaledFontMac : public ScaledFontBase {
private:
friend class DrawTargetSkia;
friend class UnscaledFontMac;
CGFontRef mFont;
CTFontRef mCTFont; // only created if CTFontDrawGlyphs is available, otherwise null
Color mFontSmoothingBackgroundColor;
bool mUseFontSmoothing;
bool mApplySyntheticBold;
struct InstanceData {
explicit InstanceData(ScaledFontMac* aScaledFont)
: mFontSmoothingBackgroundColor(aScaledFont->mFontSmoothingBackgroundColor),
mUseFontSmoothing(aScaledFont->mUseFontSmoothing),
mApplySyntheticBold(aScaledFont->mApplySyntheticBold) {}
InstanceData(const wr::FontInstanceOptions* aOptions,
const wr::FontInstancePlatformOptions* aPlatformOptions);
Color mFontSmoothingBackgroundColor;
bool mUseFontSmoothing;
bool mApplySyntheticBold;
};
typedef void(CTFontDrawGlyphsFuncT)(CTFontRef, const CGGlyph[], const CGPoint[], size_t,
CGContextRef);

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

@ -42,6 +42,11 @@ class UnscaledFontMac final : public UnscaledFont {
uint32_t aInstanceDataLength, const FontVariation* aVariations,
uint32_t aNumVariations) override;
already_AddRefed<ScaledFont> CreateScaledFontFromWRFont(
Float aGlyphSize, const wr::FontInstanceOptions* aOptions,
const wr::FontInstancePlatformOptions* aPlatformOptions,
const FontVariation* aVariations, uint32_t aNumVariations) override;
static CGFontRef CreateCGFontWithVariations(CGFontRef aFont,
uint32_t aVariationCount,
const FontVariation* aVariations);