--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -666,16 +666,17 @@ struct GlyphMetrics
*/
class ScaledFont : public RefCounted<ScaledFont>
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFont)
virtual ~ScaledFont() {}
typedef void (*FontFileDataOutput)(const uint8_t *aData, uint32_t aLength, uint32_t aIndex, Float aGlyphSize, void *aBaton);
+ typedef void (*FontInstanceDataOutput)(const uint8_t* aData, uint32_t aLength, void* aBaton);
typedef void (*FontDescriptorOutput)(const uint8_t *aData, uint32_t aLength, Float aFontSize, void *aBaton);
virtual FontType GetType() const = 0;
virtual AntialiasMode GetDefaultAAMode() {
if (gfxPrefs::DisableAllTextAA()) {
return AntialiasMode::NONE;
}
@@ -697,16 +698,18 @@ public:
virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, const Matrix *aTransformHint = nullptr) = 0;
/* This gets the metrics of a set of glyphs for the current font face.
*/
virtual void GetGlyphDesignMetrics(const uint16_t* aGlyphIndices, uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics) = 0;
virtual bool GetFontFileData(FontFileDataOutput, void *) { return false; }
+ virtual bool GetFontInstanceData(FontInstanceDataOutput, void *) { return false; }
+
virtual bool GetFontDescriptor(FontDescriptorOutput, void *) { return false; }
void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
mUserData.Add(key, userData, destroy);
}
void *GetUserData(UserDataKey *key) {
return mUserData.Get(key);
}
@@ -727,20 +730,23 @@ public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResource)
/**
* Creates a ScaledFont using the font corresponding to the index and
* the given glyph size.
*
* @param aIndex index for the font within the resource.
* @param aGlyphSize the size of ScaledFont required.
+ * @param aInstanceData pointer to read-only buffer of any available instance data.
+ * @param aInstanceDataLength the size of the instance data.
* @return an already_addrefed ScaledFont, containing nullptr if failed.
*/
virtual already_AddRefed<ScaledFont>
- CreateScaledFont(uint32_t aIndex, Float aGlyphSize) = 0;
+ CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
+ const uint8_t* aInstanceData, uint32_t aInstanceDataLength) = 0;
virtual ~NativeFontResource() {};
};
/** This class is designed to allow passing additional glyph rendering
* parameters to the glyph drawing functions. This is an empty wrapper class
* merely used to allow holding on to and passing around platform specific
* parameters. This is because different platforms have unique rendering
--- a/gfx/2d/NativeFontResourceDWrite.cpp
+++ b/gfx/2d/NativeFontResourceDWrite.cpp
@@ -254,17 +254,18 @@ NativeFontResourceDWrite::Create(uint8_t
RefPtr<NativeFontResourceDWrite> fontResource =
new NativeFontResourceDWrite(factory, fontFile.forget(), faceType,
numberOfFaces, aNeedsCairo);
return fontResource.forget();
}
already_AddRefed<ScaledFont>
-NativeFontResourceDWrite::CreateScaledFont(uint32_t aIndex, Float aGlyphSize)
+NativeFontResourceDWrite::CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
+ const uint8_t* aInstanceData, uint32_t aInstanceDataLength)
{
if (aIndex >= mNumberOfFaces) {
gfxWarning() << "Font face index is too high for font resource.";
return nullptr;
}
IDWriteFontFile *fontFile = mFontFile;
RefPtr<IDWriteFontFace> fontFace;
--- a/gfx/2d/NativeFontResourceDWrite.h
+++ b/gfx/2d/NativeFontResourceDWrite.h
@@ -27,17 +27,18 @@ public:
* @param aDataLength length of data.
* @param aNeedsCairo whether the ScaledFont created needs a cairo scaled font
* @return Referenced NativeFontResourceDWrite or nullptr if invalid.
*/
static already_AddRefed<NativeFontResourceDWrite>
Create(uint8_t *aFontData, uint32_t aDataLength, bool aNeedsCairo);
already_AddRefed<ScaledFont>
- CreateScaledFont(uint32_t aIndex, Float aGlyphSize) final;
+ CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
+ const uint8_t* aInstanceData, uint32_t aInstanceDataLength) final;
private:
NativeFontResourceDWrite(IDWriteFactory *aFactory,
already_AddRefed<IDWriteFontFile> aFontFile,
DWRITE_FONT_FACE_TYPE aFaceType,
uint32_t aNumberOfFaces, bool aNeedsCairo)
: mFactory(aFactory), mFontFile(aFontFile), mFaceType(aFaceType)
, mNumberOfFaces(aNumberOfFaces), mNeedsCairo(aNeedsCairo)
@@ -48,9 +49,9 @@ private:
DWRITE_FONT_FACE_TYPE mFaceType;
uint32_t mNumberOfFaces;
bool mNeedsCairo;
};
} // gfx
} // mozilla
-#endif // mozilla_gfx_NativeFontResourceDWrite_h
\ No newline at end of file
+#endif // mozilla_gfx_NativeFontResourceDWrite_h
--- a/gfx/2d/NativeFontResourceGDI.cpp
+++ b/gfx/2d/NativeFontResourceGDI.cpp
@@ -4,109 +4,60 @@
* 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/. */
#include "NativeFontResourceGDI.h"
#include "Logging.h"
#include "mozilla/RefPtr.h"
#include "ScaledFontWin.h"
-#include "SFNTData.h"
namespace mozilla {
namespace gfx {
/* static */
already_AddRefed<NativeFontResourceGDI>
NativeFontResourceGDI::Create(uint8_t *aFontData, uint32_t aDataLength,
bool aNeedsCairo)
{
- UniquePtr<SFNTData> sfntData = SFNTData::Create(aFontData, aDataLength);
- if (!sfntData) {
- gfxWarning() << "Failed to create SFNTData for ScaledFontWin.";
- return nullptr;
- }
-
- Vector<mozilla::u16string> fontNames;
- if (!sfntData->GetU16FullNames(fontNames)) {
- gfxWarning() << "Failed to get font names from font.";
- return nullptr;
- }
-
- // lfFaceName has a maximum length including null.
- for (size_t i = 0; i < fontNames.length(); ++i) {
- if (fontNames[i].size() > LF_FACESIZE - 1) {
- fontNames[i].resize(LF_FACESIZE - 1);
- }
- // Add null to end for easy copying later.
- fontNames[i].append(1, '\0');
- }
-
DWORD numberOfFontsAdded;
HANDLE fontResourceHandle = ::AddFontMemResourceEx(aFontData, aDataLength,
0, &numberOfFontsAdded);
if (!fontResourceHandle) {
gfxWarning() << "Failed to add memory font resource.";
return nullptr;
}
- if (numberOfFontsAdded != fontNames.length()) {
- gfxWarning() <<
- "Number of fonts added doesn't match number of names extracted.";
- }
-
RefPtr<NativeFontResourceGDI> fontResouce =
- new NativeFontResourceGDI(fontResourceHandle, Move(fontNames), aNeedsCairo);
+ new NativeFontResourceGDI(fontResourceHandle, aNeedsCairo);
return fontResouce.forget();
}
NativeFontResourceGDI::~NativeFontResourceGDI()
{
::RemoveFontMemResourceEx(mFontResourceHandle);
}
already_AddRefed<ScaledFont>
-NativeFontResourceGDI::CreateScaledFont(uint32_t aIndex, Float aGlyphSize)
+NativeFontResourceGDI::CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
+ const uint8_t* aInstanceData, uint32_t aInstanceDataLength)
{
- if (aIndex >= mFontNames.length()) {
- gfxWarning() << "Font index is too high for font resource.";
- return nullptr;
- }
-
- if (mFontNames[aIndex].empty()) {
- gfxWarning() << "Font name for index is empty.";
+ if (aInstanceDataLength < sizeof(LOGFONT)) {
+ gfxWarning() << "GDI scaled font instance data is truncated.";
return nullptr;
}
- LOGFONT logFont;
- logFont.lfHeight = 0;
- logFont.lfWidth = 0;
- logFont.lfEscapement = 0;
- logFont.lfOrientation = 0;
- logFont.lfWeight = FW_DONTCARE;
- logFont.lfItalic = FALSE;
- logFont.lfUnderline = FALSE;
- logFont.lfStrikeOut = FALSE;
- logFont.lfCharSet = DEFAULT_CHARSET;
- logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
- logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
- logFont.lfQuality = DEFAULT_QUALITY;
- logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
-
- // Copy name to mLogFont (null already included in font name). We cast here
- // because for VS2015 char16_t != wchar_t, even though they are both 16 bit.
- mFontNames[aIndex].copy(reinterpret_cast<char16_t*>(logFont.lfFaceName),
- mFontNames[aIndex].length());
+ const LOGFONT* logFont = reinterpret_cast<const LOGFONT*>(aInstanceData);
// Constructor for ScaledFontWin dereferences and copies the LOGFONT, so we
// are safe to pass this reference.
- RefPtr<ScaledFontBase> scaledFont = new ScaledFontWin(&logFont, aGlyphSize);
+ RefPtr<ScaledFontBase> scaledFont = new ScaledFontWin(logFont, aGlyphSize);
if (mNeedsCairo && !scaledFont->PopulateCairoScaledFont()) {
- gfxWarning() << "Unable to create cairo scaled font DWrite font.";
+ gfxWarning() << "Unable to create cairo scaled font GDI font.";
return nullptr;
}
return scaledFont.forget();
}
} // gfx
} // mozilla
--- a/gfx/2d/NativeFontResourceGDI.h
+++ b/gfx/2d/NativeFontResourceGDI.h
@@ -7,17 +7,16 @@
#ifndef mozilla_gfx_NativeFontResourceGDI_h
#define mozilla_gfx_NativeFontResourceGDI_h
#include <windows.h>
#include "2D.h"
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/Vector.h"
-#include "u16string.h"
namespace mozilla {
namespace gfx {
class NativeFontResourceGDI final : public NativeFontResource
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceGDI)
@@ -31,27 +30,26 @@ public:
* @return Referenced NativeFontResourceGDI or nullptr if invalid.
*/
static already_AddRefed<NativeFontResourceGDI>
Create(uint8_t *aFontData, uint32_t aDataLength, bool aNeedsCairo);
~NativeFontResourceGDI();
already_AddRefed<ScaledFont>
- CreateScaledFont(uint32_t aIndex, Float aGlyphSize) final;
+ CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
+ const uint8_t* aInstanceData, uint32_t aInstanceDataLength) final;
private:
NativeFontResourceGDI(HANDLE aFontResourceHandle,
- Vector<mozilla::u16string>&& aFontNames,
bool aNeedsCairo)
- : mFontResourceHandle(aFontResourceHandle), mFontNames(Move(aFontNames))
+ : mFontResourceHandle(aFontResourceHandle)
, mNeedsCairo(aNeedsCairo)
{}
HANDLE mFontResourceHandle;
- Vector<mozilla::u16string> mFontNames;
bool mNeedsCairo;
};
} // gfx
} // mozilla
-#endif // mozilla_gfx_NativeFontResourceGDI_h
\ No newline at end of file
+#endif // mozilla_gfx_NativeFontResourceGDI_h
--- a/gfx/2d/NativeFontResourceMac.cpp
+++ b/gfx/2d/NativeFontResourceMac.cpp
@@ -45,17 +45,18 @@ NativeFontResourceMac::Create(uint8_t *a
// passes ownership of fontRef to the NativeFontResourceMac instance
RefPtr<NativeFontResourceMac> fontResource =
new NativeFontResourceMac(fontRef);
return fontResource.forget();
}
already_AddRefed<ScaledFont>
-NativeFontResourceMac::CreateScaledFont(uint32_t aIndex, Float aGlyphSize)
+NativeFontResourceMac::CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
+ const uint8_t* aInstanceData, uint32_t aInstanceDataLength)
{
RefPtr<ScaledFontBase> scaledFont = new ScaledFontMac(mFontRef, aGlyphSize);
if (!scaledFont->PopulateCairoScaledFont()) {
gfxWarning() << "Unable to create cairo scaled Mac font.";
return nullptr;
}
--- a/gfx/2d/NativeFontResourceMac.h
+++ b/gfx/2d/NativeFontResourceMac.h
@@ -18,17 +18,18 @@ class NativeFontResourceMac final : publ
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceMac)
static already_AddRefed<NativeFontResourceMac>
Create(uint8_t *aFontData, uint32_t aDataLength);
already_AddRefed<ScaledFont>
- CreateScaledFont(uint32_t aIndex, Float aGlyphSize);
+ CreateScaledFont(uint32_t aIndex, Float aGlyphSize,
+ const uint8_t* aInstanceData, uint32_t aInstanceDataLength) final;
~NativeFontResourceMac()
{
CFRelease(mFontRef);
}
private:
explicit NativeFontResourceMac(CGFontRef aFontRef) : mFontRef(aFontRef) {}
--- a/gfx/2d/RecordedEvent.cpp
+++ b/gfx/2d/RecordedEvent.cpp
@@ -1654,43 +1654,57 @@ RecordedScaledFontCreation::PlayEvent(Tr
{
NativeFontResource *fontResource = aTranslator->LookupNativeFontResource(mFontDataKey);
if (!fontResource) {
gfxDevCrash(LogReason::NativeFontResourceNotFound) <<
"NativeFontResource lookup failed for key |" << hexa(mFontDataKey) << "|.";
return false;
}
- RefPtr<ScaledFont> scaledFont = fontResource->CreateScaledFont(mIndex, mGlyphSize);
+ RefPtr<ScaledFont> scaledFont =
+ fontResource->CreateScaledFont(mIndex, mGlyphSize, mInstanceData.data(), mInstanceData.size());
aTranslator->AddScaledFont(mRefPtr, scaledFont);
return true;
}
void
RecordedScaledFontCreation::RecordToStream(std::ostream &aStream) const
{
WriteElement(aStream, mRefPtr);
WriteElement(aStream, mFontDataKey);
WriteElement(aStream, mIndex);
WriteElement(aStream, mGlyphSize);
+ WriteElement(aStream, (size_t)mInstanceData.size());
+ aStream.write((char*)mInstanceData.data(), mInstanceData.size());
}
void
RecordedScaledFontCreation::OutputSimpleEventInfo(stringstream &aStringStream) const
{
aStringStream << "[" << mRefPtr << "] ScaledFont Created";
}
+void
+RecordedScaledFontCreation::SetFontInstanceData(const uint8_t *aData, uint32_t aSize)
+{
+ mInstanceData.assign(aData, aData + aSize);
+}
+
RecordedScaledFontCreation::RecordedScaledFontCreation(istream &aStream)
: RecordedEvent(SCALEDFONTCREATION)
{
ReadElement(aStream, mRefPtr);
ReadElement(aStream, mFontDataKey);
ReadElement(aStream, mIndex);
ReadElement(aStream, mGlyphSize);
+
+ size_t size;
+ ReadElement(aStream, size);
+ mInstanceData.resize(size);
+ aStream.read((char*)mInstanceData.data(), size);
}
bool
RecordedScaledFontDestruction::PlayEvent(Translator *aTranslator) const
{
aTranslator->RemoveScaledFont(mRefPtr);
return true;
}
--- a/gfx/2d/RecordedEvent.h
+++ b/gfx/2d/RecordedEvent.h
@@ -19,17 +19,17 @@ struct PathOp;
class PathRecording;
const uint32_t kMagicInt = 0xc001feed;
// A change in major revision means a change in event binary format, causing
// loss of backwards compatibility. Old streams will not work in a player
// using a newer major revision. And new streams will not work in a player
// using an older major revision.
-const uint16_t kMajorRevision = 5;
+const uint16_t kMajorRevision = 6;
// A change in minor revision means additions of new events. New streams will
// not play in older players.
const uint16_t kMinorRevision = 0;
struct ReferencePtr
{
ReferencePtr()
: mLongPtr(0)
@@ -1095,39 +1095,49 @@ private:
ReferencePtr mRefPtr;
MOZ_IMPLICIT RecordedFontDescriptor(std::istream &aStream);
};
class RecordedScaledFontCreation : public RecordedEvent {
public:
- RecordedScaledFontCreation(ReferencePtr aRefPtr,
+ static void FontInstanceDataProc(const uint8_t* aData, uint32_t aSize, void* aBaton)
+ {
+ auto recordedScaledFontCreation = static_cast<RecordedScaledFontCreation*>(aBaton);
+ recordedScaledFontCreation->SetFontInstanceData(aData, aSize);
+ }
+
+ RecordedScaledFontCreation(ScaledFont* aScaledFont,
RecordedFontDetails aFontDetails)
- : RecordedEvent(SCALEDFONTCREATION), mRefPtr(aRefPtr)
+ : RecordedEvent(SCALEDFONTCREATION), mRefPtr(aScaledFont)
, mFontDataKey(aFontDetails.fontDataKey)
, mGlyphSize(aFontDetails.glyphSize) , mIndex(aFontDetails.index)
{
+ aScaledFont->GetFontInstanceData(FontInstanceDataProc, this);
}
virtual bool PlayEvent(Translator *aTranslator) const;
virtual void RecordToStream(std::ostream &aStream) const;
virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
virtual std::string GetName() const { return "ScaledFont Creation"; }
virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
+ void SetFontInstanceData(const uint8_t *aData, uint32_t aSize);
+
private:
friend class RecordedEvent;
ReferencePtr mRefPtr;
uint64_t mFontDataKey;
Float mGlyphSize;
uint32_t mIndex;
+ std::vector<uint8_t> mInstanceData;
MOZ_IMPLICIT RecordedScaledFontCreation(std::istream &aStream);
};
class RecordedScaledFontDestruction : public RecordedEvent {
public:
MOZ_IMPLICIT RecordedScaledFontDestruction(ReferencePtr aRefPtr)
: RecordedEvent(SCALEDFONTDESTRUCTION), mRefPtr(aRefPtr)
--- a/gfx/2d/ScaledFontWin.cpp
+++ b/gfx/2d/ScaledFontWin.cpp
@@ -3,32 +3,31 @@
* 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/. */
#include "ScaledFontWin.h"
#include "AutoHelpersWin.h"
#include "Logging.h"
#include "nsString.h"
-#include "SFNTData.h"
#ifdef USE_SKIA
#include "skia/include/ports/SkTypeface_win.h"
#endif
#ifdef USE_CAIRO_SCALED_FONT
#include "cairo-win32.h"
#endif
#include "HelpersWinFonts.h"
namespace mozilla {
namespace gfx {
-ScaledFontWin::ScaledFontWin(LOGFONT* aFont, Float aSize)
+ScaledFontWin::ScaledFontWin(const LOGFONT* aFont, Float aSize)
: ScaledFontBase(aSize)
, mLogFont(*aFont)
{
}
bool
ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
{
@@ -50,39 +49,24 @@ ScaledFontWin::GetFontFileData(FontFileD
UniquePtr<uint8_t[]> fontData(new uint8_t[tableSize]);
uint32_t sizeGot =
::GetFontData(dc.GetDC(), table, 0, fontData.get(), tableSize);
if (sizeGot != tableSize) {
return false;
}
- // If it's a font collection then attempt to get the index.
- uint32_t index = 0;
- if (table != 0) {
- UniquePtr<SFNTData> sfntData = SFNTData::Create(fontData.get(),
- tableSize);
- if (!sfntData) {
- gfxWarning() << "Failed to create SFNTData for GetFontFileData.";
- return false;
- }
+ aDataCallback(fontData.get(), tableSize, 0, mSize, aBaton);
+ return true;
+}
- // We cast here because for VS2015 char16_t != wchar_t, even though they are
- // both 16 bit.
- if (!sfntData->GetIndexForU16Name(
- reinterpret_cast<char16_t*>(mLogFont.lfFaceName), &index, LF_FACESIZE - 1)) {
- gfxWarning() << "Failed to get index for face name.";
- gfxDevCrash(LogReason::GetFontFileDataFailed) <<
- "Failed to get index for face name |" <<
- NS_ConvertUTF16toUTF8(mLogFont.lfFaceName).get() << "|.";
- return false;
- }
- }
-
- aDataCallback(fontData.get(), tableSize, index, mSize, aBaton);
+bool
+ScaledFontWin::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
+{
+ aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), aBaton);
return true;
}
bool
ScaledFontWin::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton)
{
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), mSize, aBaton);
return true;
--- a/gfx/2d/ScaledFontWin.h
+++ b/gfx/2d/ScaledFontWin.h
@@ -11,22 +11,24 @@
namespace mozilla {
namespace gfx {
class ScaledFontWin : public ScaledFontBase
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontWin)
- ScaledFontWin(LOGFONT* aFont, Float aSize);
+ ScaledFontWin(const LOGFONT* aFont, Float aSize);
virtual FontType GetType() const { return FontType::GDI; }
bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) override;
+ bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override;
+
virtual bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
virtual AntialiasMode GetDefaultAAMode() override;
#ifdef USE_SKIA
virtual SkTypeface* GetSkTypeface();
#endif
protected: