Bug 1397458 - part 1 - expose font variations directly in ScaledFont/DrawTargetRecording r=kats

MozReview-Commit-ID: 28egBaMImO8

--HG--
extra : rebase_source : cc2e870507e7ac7ccbd666d4ed6ca61c8cd373fa
This commit is contained in:
Lee Salzman 2017-09-17 21:21:15 -04:00
Родитель 656ba29569
Коммит 4467a6148b
10 изменённых файлов: 56 добавлений и 26 удалений

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

@ -770,7 +770,9 @@ public:
virtual already_AddRefed<ScaledFont>
CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength)
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations)
{
return nullptr;
}
@ -820,7 +822,9 @@ public:
*/
virtual void GetGlyphDesignMetrics(const uint16_t* aGlyphIndices, uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics) = 0;
typedef void (*FontInstanceDataOutput)(const uint8_t* aData, uint32_t aLength, void* aBaton);
typedef void (*FontInstanceDataOutput)(const uint8_t* aData, uint32_t aLength,
const FontVariation* aVariations, uint32_t aNumVariations,
void* aBaton);
virtual bool GetFontInstanceData(FontInstanceDataOutput, void *) { return false; }

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

@ -1023,10 +1023,12 @@ private:
class RecordedScaledFontCreation : public RecordedEventDerived<RecordedScaledFontCreation> {
public:
static void FontInstanceDataProc(const uint8_t* aData, uint32_t aSize, void* aBaton)
static void FontInstanceDataProc(const uint8_t* aData, uint32_t aSize,
const FontVariation* aVariations, uint32_t aNumVariations,
void* aBaton)
{
auto recordedScaledFontCreation = static_cast<RecordedScaledFontCreation*>(aBaton);
recordedScaledFontCreation->SetFontInstanceData(aData, aSize);
recordedScaledFontCreation->SetFontInstanceData(aData, aSize, aVariations, aNumVariations);
}
RecordedScaledFontCreation(ScaledFont* aScaledFont,
@ -1047,7 +1049,8 @@ public:
virtual std::string GetName() const { return "ScaledFont Creation"; }
virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
void SetFontInstanceData(const uint8_t *aData, uint32_t aSize);
void SetFontInstanceData(const uint8_t *aData, uint32_t aSize,
const FontVariation* aVariations, uint32_t aNumVariations);
private:
friend class RecordedEvent;
@ -1056,6 +1059,7 @@ private:
ReferencePtr mUnscaledFont;
Float mGlyphSize;
std::vector<uint8_t> mInstanceData;
std::vector<FontVariation> mVariations;
template<class S>
MOZ_IMPLICIT RecordedScaledFontCreation(S &aStream);
@ -2895,7 +2899,9 @@ RecordedScaledFontCreation::PlayEvent(Translator *aTranslator) const
}
RefPtr<ScaledFont> scaledFont =
unscaledFont->CreateScaledFont(mGlyphSize, mInstanceData.data(), mInstanceData.size());
unscaledFont->CreateScaledFont(mGlyphSize,
mInstanceData.data(), mInstanceData.size(),
mVariations.data(), mVariations.size());
aTranslator->AddScaledFont(mRefPtr, scaledFont);
return true;
}
@ -2909,6 +2915,8 @@ RecordedScaledFontCreation::Record(S &aStream) const
WriteElement(aStream, mGlyphSize);
WriteElement(aStream, (size_t)mInstanceData.size());
aStream.write((char*)mInstanceData.data(), mInstanceData.size());
WriteElement(aStream, (size_t)mVariations.size());
aStream.write((char*)mVariations.data(), sizeof(FontVariation) * mVariations.size());
}
inline void
@ -2918,9 +2926,11 @@ RecordedScaledFontCreation::OutputSimpleEventInfo(std::stringstream &aStringStre
}
inline void
RecordedScaledFontCreation::SetFontInstanceData(const uint8_t *aData, uint32_t aSize)
RecordedScaledFontCreation::SetFontInstanceData(const uint8_t *aData, uint32_t aSize,
const FontVariation* aVariations, uint32_t aNumVariations)
{
mInstanceData.assign(aData, aData + aSize);
mVariations.assign(aVariations, aVariations + aNumVariations);
}
template<class S>
@ -2935,6 +2945,10 @@ RecordedScaledFontCreation::RecordedScaledFontCreation(S &aStream)
ReadElement(aStream, size);
mInstanceData.resize(size);
aStream.read((char*)mInstanceData.data(), size);
size_t numVariations;
ReadElement(aStream, numVariations);
mVariations.resize(numVariations);
aStream.read((char*)mVariations.data(), sizeof(FontVariation) * numVariations);
}
inline bool

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

@ -296,14 +296,16 @@ bool
ScaledFontDWrite::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
{
InstanceData instance(this);
aCb(reinterpret_cast<uint8_t*>(&instance), sizeof(instance), aBaton);
aCb(reinterpret_cast<uint8_t*>(&instance), sizeof(instance), nullptr, 0, aBaton);
return true;
}
already_AddRefed<ScaledFont>
UnscaledFontDWrite::CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength)
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations)
{
if (aInstanceDataLength < sizeof(ScaledFontDWrite::InstanceData)) {
gfxWarning() << "DWrite scaled font instance data is truncated.";

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

@ -227,14 +227,16 @@ ScaledFontFontconfig::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBat
{
InstanceData instance(GetCairoScaledFont(), mPattern);
aCb(reinterpret_cast<uint8_t*>(&instance), sizeof(instance), aBaton);
aCb(reinterpret_cast<uint8_t*>(&instance), sizeof(instance), nullptr, 0, aBaton);
return true;
}
already_AddRefed<ScaledFont>
UnscaledFontFontconfig::CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength)
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations)
{
if (aInstanceDataLength < sizeof(ScaledFontFontconfig::InstanceData)) {
gfxWarning() << "Fontconfig scaled font instance data is truncated.";

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

@ -351,7 +351,7 @@ ScaledFontMac::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
}
}
aCb(reinterpret_cast<uint8_t*>(variations), variationCount * sizeof(FontVariation), aBaton);
aCb(nullptr, 0, variations, variationCount, aBaton);
delete[] variations;
return true;
@ -478,17 +478,15 @@ UnscaledFontMac::CreateCGFontWithVariations(CGFontRef aFont,
already_AddRefed<ScaledFont>
UnscaledFontMac::CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength)
{
uint32_t variationCount =
aInstanceDataLength / sizeof(FontVariation);
const FontVariation* variations =
reinterpret_cast<const FontVariation*>(aInstanceData);
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations)
{
CGFontRef fontRef = mFont;
if (variationCount > 0) {
if (aNumVariations > 0) {
CGFontRef varFont =
CreateCGFontWithVariations(mFont, variationCount, variations);
CreateCGFontWithVariations(mFont, aNumVariations, aVariations);
if (varFont) {
fontRef = varFont;
}

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

@ -64,7 +64,7 @@ UnscaledFontGDI::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
bool
ScaledFontWin::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
{
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), nullptr, 0, aBaton);
return true;
}
@ -98,7 +98,9 @@ UnscaledFontGDI::CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLe
already_AddRefed<ScaledFont>
UnscaledFontGDI::CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength)
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations)
{
if (aInstanceDataLength < sizeof(LOGFONT)) {
gfxWarning() << "GDI unscaled font instance data is truncated.";

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

@ -36,7 +36,9 @@ public:
already_AddRefed<ScaledFont>
CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength) override;
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations) override;
private:
RefPtr<IDWriteFontFace> mFontFace;

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

@ -87,7 +87,9 @@ public:
already_AddRefed<ScaledFont>
CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength) override;
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations) override;
private:
RefPtr<NativeFontResource> mNativeFontResource;

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

@ -36,7 +36,9 @@ public:
already_AddRefed<ScaledFont>
CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength) override;
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations) override;
private:
LOGFONT mLogFont;

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

@ -41,7 +41,9 @@ public:
already_AddRefed<ScaledFont>
CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength) override;
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
uint32_t aNumVariations) override;
static CGFontRef
CreateCGFontWithVariations(CGFontRef aFont,