Remove user specified typeface id.
Now that there may be multiple font managers in a process the typeface ids must be unique across all typefaces, not just unique within a font manager. If two typefaces have the same id there will be issues in the glyph cache. All existing font managers were already doing this by calling SkFontCache::NewFontID, so centralize this in SkTypeface. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2147733002 Review-Url: https://codereview.chromium.org/2147733002
This commit is contained in:
parent
ba3880fa6d
commit
e3aea10428
@ -341,7 +341,7 @@ protected:
|
||||
|
||||
/** uniqueID must be unique and non-zero
|
||||
*/
|
||||
SkTypeface(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch = false);
|
||||
SkTypeface(const SkFontStyle& style, bool isFixedPitch = false);
|
||||
virtual ~SkTypeface();
|
||||
|
||||
/** Sets the fixedPitch bit. If used, must be called in the constructor. */
|
||||
|
@ -14,9 +14,10 @@
|
||||
#include "SkOnce.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "SkTypefaceCache.h"
|
||||
|
||||
SkTypeface::SkTypeface(const SkFontStyle& style, SkFontID fontID, bool isFixedPitch)
|
||||
: fUniqueID(fontID), fStyle(style), fIsFixedPitch(isFixedPitch) { }
|
||||
SkTypeface::SkTypeface(const SkFontStyle& style, bool isFixedPitch)
|
||||
: fUniqueID(SkTypefaceCache::NewFontID()), fStyle(style), fIsFixedPitch(isFixedPitch) { }
|
||||
|
||||
SkTypeface::~SkTypeface() { }
|
||||
|
||||
@ -40,7 +41,7 @@ class SkEmptyTypeface : public SkTypeface {
|
||||
public:
|
||||
static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
|
||||
protected:
|
||||
SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { }
|
||||
SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
|
||||
|
||||
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
|
@ -152,7 +152,7 @@ void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
|
||||
#include "SkTypefaceCache.h"
|
||||
|
||||
SkGTypeface::SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint)
|
||||
: SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
|
||||
: SkTypeface(proxy->fontStyle(), false)
|
||||
, fProxy(std::move(proxy))
|
||||
, fPaint(paint)
|
||||
{}
|
||||
|
@ -191,7 +191,7 @@ void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
|
||||
#include "SkTypefaceCache.h"
|
||||
|
||||
SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint, bool fakeIt)
|
||||
: SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
|
||||
: SkTypeface(proxy->fontStyle(), false)
|
||||
, fProxy(std::move(proxy))
|
||||
, fPaint(paint)
|
||||
, fFakeIt(fakeIt) {}
|
||||
|
@ -115,7 +115,7 @@ void SkTestFont::init(const SkScalar* pts, const unsigned char* verbs) {
|
||||
}
|
||||
|
||||
SkTestTypeface::SkTestTypeface(SkTestFont* testFont, const SkFontStyle& style)
|
||||
: SkTypeface(style, SkTypefaceCache::NewFontID(), false)
|
||||
: SkTypeface(style, false)
|
||||
, fTestFont(testFont) {
|
||||
}
|
||||
|
||||
|
@ -50,14 +50,14 @@ protected:
|
||||
const SkFontConfigInterface::FontIdentity& fi,
|
||||
const SkString& familyName,
|
||||
const SkFontStyle& style)
|
||||
: INHERITED(style, SkTypefaceCache::NewFontID(), false)
|
||||
: INHERITED(style, false)
|
||||
, fFCI(SkRef(fci))
|
||||
, fIdentity(fi)
|
||||
, fFamilyName(familyName)
|
||||
, fLocalStream(nullptr) {}
|
||||
|
||||
SkTypeface_FCI(const SkFontStyle& style, bool fixedWidth, SkStreamAsset* localStream, int index)
|
||||
: INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
|
||||
: INHERITED(style, fixedWidth)
|
||||
, fLocalStream(localStream)
|
||||
{
|
||||
fIdentity.fTTCIndex = index;
|
||||
|
@ -71,8 +71,8 @@ public:
|
||||
};
|
||||
|
||||
protected:
|
||||
SkTypeface_FreeType(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch)
|
||||
: INHERITED(style, uniqueID, isFixedPitch)
|
||||
SkTypeface_FreeType(const SkFontStyle& style, bool isFixedPitch)
|
||||
: INHERITED(style, isFixedPitch)
|
||||
{}
|
||||
|
||||
virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
|
@ -436,7 +436,7 @@ public:
|
||||
SkTypeface_Mac(CTFontRef fontRef, CFTypeRef resourceRef,
|
||||
const SkFontStyle& fs, bool isFixedPitch,
|
||||
bool isLocalStream)
|
||||
: SkTypeface(fs, SkTypefaceCache::NewFontID(), isFixedPitch)
|
||||
: SkTypeface(fs, isFixedPitch)
|
||||
, fFontRef(fontRef) // caller has already called CFRetain for us
|
||||
, fOriginatingCFTypeRef(resourceRef) // caller has already called CFRetain for us
|
||||
, fHasColorGlyphs(SkToBool(CTFontGetSymbolicTraits(fFontRef) & SkCTFontColorGlyphsTrait))
|
||||
|
@ -206,7 +206,7 @@ static unsigned calculateUPEM(HDC hdc, const LOGFONT& lf) {
|
||||
class LogFontTypeface : public SkTypeface {
|
||||
public:
|
||||
LogFontTypeface(const SkFontStyle& style, const LOGFONT& lf, bool serializeAsStream)
|
||||
: SkTypeface(style, SkTypefaceCache::NewFontID(), false)
|
||||
: SkTypeface(style, false)
|
||||
, fLogFont(lf)
|
||||
, fSerializeAsStream(serializeAsStream)
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
SkTypeface_Android(const SkFontStyle& style,
|
||||
bool isFixedPitch,
|
||||
const SkString& familyName)
|
||||
: INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
|
||||
: INHERITED(style, isFixedPitch)
|
||||
, fFamilyName(familyName)
|
||||
{ }
|
||||
|
||||
|
@ -30,7 +30,7 @@ class SkTypeface_Custom : public SkTypeface_FreeType {
|
||||
public:
|
||||
SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch,
|
||||
bool sysFont, const SkString familyName, int index)
|
||||
: INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
|
||||
: INHERITED(style, isFixedPitch)
|
||||
, fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index)
|
||||
{ }
|
||||
|
||||
|
@ -405,7 +405,7 @@ class SkTypeface_stream : public SkTypeface_FreeType {
|
||||
public:
|
||||
/** @param data takes ownership of the font data.*/
|
||||
SkTypeface_stream(SkFontData* data, const SkFontStyle& style, bool fixedWidth)
|
||||
: INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
|
||||
: INHERITED(style, fixedWidth)
|
||||
, fData(data)
|
||||
{ };
|
||||
|
||||
@ -493,7 +493,6 @@ private:
|
||||
/** @param pattern takes ownership of the reference. */
|
||||
SkTypeface_fontconfig(FcPattern* pattern)
|
||||
: INHERITED(skfontstyle_from_fcpattern(pattern),
|
||||
SkTypefaceCache::NewFontID(),
|
||||
FC_PROPORTIONAL != get_int(pattern, FC_SPACING, FC_PROPORTIONAL))
|
||||
, fPattern(pattern)
|
||||
{ };
|
||||
|
@ -39,14 +39,14 @@ static SkFontStyle get_style(IDWriteFont* font) {
|
||||
|
||||
class DWriteFontTypeface : public SkTypeface {
|
||||
private:
|
||||
DWriteFontTypeface(const SkFontStyle& style, SkFontID fontID,
|
||||
DWriteFontTypeface(const SkFontStyle& style,
|
||||
IDWriteFactory* factory,
|
||||
IDWriteFontFace* fontFace,
|
||||
IDWriteFont* font,
|
||||
IDWriteFontFamily* fontFamily,
|
||||
IDWriteFontFileLoader* fontFileLoader = nullptr,
|
||||
IDWriteFontCollectionLoader* fontCollectionLoader = nullptr)
|
||||
: SkTypeface(style, fontID, false)
|
||||
: SkTypeface(style, false)
|
||||
, fFactory(SkRefComPtr(factory))
|
||||
, fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader))
|
||||
, fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader))
|
||||
@ -80,8 +80,7 @@ public:
|
||||
IDWriteFontFamily* fontFamily,
|
||||
IDWriteFontFileLoader* fontFileLoader = nullptr,
|
||||
IDWriteFontCollectionLoader* fontCollectionLoader = nullptr) {
|
||||
SkFontID fontID = SkTypefaceCache::NewFontID();
|
||||
return new DWriteFontTypeface(get_style(font), fontID, factory, fontFace, font, fontFamily,
|
||||
return new DWriteFontTypeface(get_style(font), factory, fontFace, font, fontFamily,
|
||||
fontFileLoader, fontCollectionLoader);
|
||||
}
|
||||
|
||||
|
@ -115,12 +115,11 @@ static void test_fontiter(skiatest::Reporter* reporter, bool verbose) {
|
||||
}
|
||||
|
||||
static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
|
||||
static const SkFontID invalidFontID = std::numeric_limits<SkFontID>::max();
|
||||
static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
|
||||
|
||||
class TestTypeface : public SkTypeface {
|
||||
public:
|
||||
TestTypeface(const SkFontStyle& fontStyle, SkFontID id) : SkTypeface(fontStyle, id, false){}
|
||||
TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){}
|
||||
protected:
|
||||
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
@ -168,9 +167,9 @@ static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
|
||||
}
|
||||
SkTypeface* createTypeface(int index) override {
|
||||
if (index < 0 || this->count() <= index) {
|
||||
return new TestTypeface(invalidFontStyle, invalidFontID);
|
||||
return new TestTypeface(invalidFontStyle);
|
||||
}
|
||||
return new TestTypeface(fStyles[index], index);
|
||||
return new TestTypeface(fStyles[index]);
|
||||
}
|
||||
SkTypeface* matchStyle(const SkFontStyle& pattern) override {
|
||||
return this->matchStyleCSS3(pattern);
|
||||
|
@ -31,9 +31,9 @@ namespace {
|
||||
|
||||
class SkEmptyTypeface : public SkTypeface {
|
||||
public:
|
||||
static sk_sp<SkTypeface> Create(SkFontID id) { return sk_sp<SkTypeface>(new SkEmptyTypeface(id)); }
|
||||
static sk_sp<SkTypeface> Create() { return sk_sp<SkTypeface>(new SkEmptyTypeface()); }
|
||||
protected:
|
||||
SkEmptyTypeface(SkFontID id) : SkTypeface(SkFontStyle(), id, true) { }
|
||||
SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
|
||||
|
||||
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
@ -76,12 +76,12 @@ static int count(skiatest::Reporter* reporter, const SkTypefaceCache& cache) {
|
||||
}
|
||||
|
||||
DEF_TEST(TypefaceCache, reporter) {
|
||||
sk_sp<SkTypeface> t1(SkEmptyTypeface::Create(1));
|
||||
sk_sp<SkTypeface> t1(SkEmptyTypeface::Create());
|
||||
{
|
||||
SkTypefaceCache cache;
|
||||
REPORTER_ASSERT(reporter, count(reporter, cache) == 0);
|
||||
{
|
||||
sk_sp<SkTypeface> t0(SkEmptyTypeface::Create(0));
|
||||
sk_sp<SkTypeface> t0(SkEmptyTypeface::Create());
|
||||
cache.add(t0.get());
|
||||
REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
|
||||
cache.add(t1.get());
|
||||
|
Loading…
Reference in New Issue
Block a user