зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1435984 - patch 5 - Apply variation settings from the font entry when instantiating fonts on macOS. r=lsalzman
--HG-- extra : source : ec70fb9a28ac4952b15f1acd4890d727067788ca
This commit is contained in:
Родитель
8cc473a34a
Коммит
8fe372bf90
|
@ -1944,6 +1944,24 @@ gfxFontUtils::GetVariationInstances(gfxFontEntry* aFontEntry,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
gfxFontUtils::MergeVariations(const nsTArray<gfxFontVariation>& aEntrySettings,
|
||||
const nsTArray<gfxFontVariation>& aStyleSettings,
|
||||
nsTArray<gfxFontVariation>* aMerged)
|
||||
{
|
||||
MOZ_ASSERT(!aEntrySettings.IsEmpty() &&
|
||||
!aStyleSettings.IsEmpty() &&
|
||||
aMerged->IsEmpty());
|
||||
// Settings from the CSS style will take precedence over those from the
|
||||
// font entry (i.e. from the @font-face descriptor).
|
||||
aMerged->AppendElements(aStyleSettings);
|
||||
for (auto& setting : aEntrySettings) {
|
||||
if (!aMerged->Contains(setting.mTag, VariationTagComparator())) {
|
||||
aMerged->AppendElement(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
||||
/* static */
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#ifndef GFX_FONT_UTILS_H
|
||||
#define GFX_FONT_UTILS_H
|
||||
|
||||
#include "gfxFontVariations.h"
|
||||
#include "gfxPlatform.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -26,8 +27,6 @@
|
|||
|
||||
typedef struct hb_blob_t hb_blob_t;
|
||||
|
||||
struct gfxFontVariationInstance;
|
||||
|
||||
class gfxSparseBitSet {
|
||||
private:
|
||||
enum { BLOCK_SIZE = 32 }; // ==> 256 codepoints per block
|
||||
|
@ -1011,6 +1010,22 @@ public:
|
|||
GetVariationInstances(gfxFontEntry* aFontEntry,
|
||||
nsTArray<gfxFontVariationInstance>& aInstances);
|
||||
|
||||
// Merge a list of font-variation-settings from a font entry and a list
|
||||
// from a gfxFontStyle, to get a combined collection of settings that can
|
||||
// be used to instantiate a font.
|
||||
static void
|
||||
MergeVariations(const nsTArray<gfxFontVariation>& aEntrySettings,
|
||||
const nsTArray<gfxFontVariation>& aStyleSettings,
|
||||
nsTArray<gfxFontVariation>* aMerged);
|
||||
|
||||
// Helper used by MergeVariations, and other code that wants to check
|
||||
// whether an array of variation settings includes a particular tag.
|
||||
struct VariationTagComparator {
|
||||
bool Equals(const gfxFontVariation& aVariation, uint32_t aTag) const {
|
||||
return aVariation.mTag == aTag;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
friend struct MacCharsetMappingComparator;
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#define GFX_FONT_VARIATIONS_H
|
||||
|
||||
#include "mozilla/gfx/FontVariation.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
typedef mozilla::gfx::FontVariation gfxFontVariation;
|
||||
|
||||
|
|
|
@ -36,17 +36,34 @@ gfxMacFont::gfxMacFont(const RefPtr<UnscaledFontMac>& aUnscaledFont,
|
|||
{
|
||||
mApplySyntheticBold = aNeedsBold;
|
||||
|
||||
if (mVariationFont && aFontStyle->variationSettings.Length() > 0) {
|
||||
if (mVariationFont && (!aFontStyle->variationSettings.IsEmpty() ||
|
||||
!aFontEntry->mVariationSettings.IsEmpty())) {
|
||||
CGFontRef baseFont = aUnscaledFont->GetFont();
|
||||
if (!baseFont) {
|
||||
mIsValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Probably one of the lists of variations, either from the @font-face
|
||||
// descriptor or from the property, will be empty. So skip merging them
|
||||
// unless really necessary.
|
||||
const nsTArray<gfxFontVariation>* vars;
|
||||
AutoTArray<gfxFontVariation,4> mergedSettings;
|
||||
if (aFontStyle->variationSettings.IsEmpty()) {
|
||||
vars = &aFontEntry->mVariationSettings;
|
||||
} else if (aFontEntry->mVariationSettings.IsEmpty()) {
|
||||
vars = &aFontStyle->variationSettings;
|
||||
} else {
|
||||
gfxFontUtils::MergeVariations(aFontEntry->mVariationSettings,
|
||||
aFontStyle->variationSettings,
|
||||
&mergedSettings);
|
||||
vars = &mergedSettings;
|
||||
}
|
||||
|
||||
mCGFont =
|
||||
UnscaledFontMac::CreateCGFontWithVariations(
|
||||
baseFont,
|
||||
aFontStyle->variationSettings.Length(),
|
||||
aFontStyle->variationSettings.Elements());
|
||||
UnscaledFontMac::CreateCGFontWithVariations(baseFont,
|
||||
vars->Length(),
|
||||
vars->Elements());
|
||||
if (!mCGFont) {
|
||||
::CFRetain(baseFont);
|
||||
mCGFont = baseFont;
|
||||
|
|
Загрузка…
Ссылка в новой задаче