Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(914)

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 1860993004: Test CTFonts for equality, not just name and style. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix adding to cache. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_mac.cpp
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 53d5610575b1f4867a7ae13188823a0b78bb4dbf..ca6c24d50df82fa9c4632dbde8f2cfa0787a140d 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -558,10 +558,11 @@ static SkTypeface* NewFromName(const char familyName[], const SkFontStyle& theSt
}
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (void*)ctFont.get());
- if (!face) {
- face = NewFromFontRef(ctFont.release(), nullptr, nullptr, false);
- SkTypefaceCache::Add(face, face->fontStyle());
+ if (face) {
+ return face;
}
+ face = NewFromFontRef(ctFont.release(), nullptr, nullptr, false);
+ SkTypefaceCache::Add(face, face->fontStyle());
return face;
}
@@ -573,7 +574,6 @@ static SkTypeface* GetDefaultFace() {
if (nullptr == gDefaultFace) {
gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkFontStyle());
- SkTypefaceCache::Add(gDefaultFace, SkFontStyle());
}
return gDefaultFace;
}
@@ -591,14 +591,15 @@ CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) {
*/
SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef) {
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (void*)fontRef);
- if (!face) {
- CFRetain(fontRef);
- if (resourceRef) {
- CFRetain(resourceRef);
- }
- face = NewFromFontRef(fontRef, resourceRef, nullptr, false);
- SkTypefaceCache::Add(face, face->fontStyle());
+ if (face) {
+ return face;
}
+ CFRetain(fontRef);
+ if (resourceRef) {
+ CFRetain(resourceRef);
+ }
+ face = NewFromFontRef(fontRef, resourceRef, nullptr, false);
+ SkTypefaceCache::Add(face, face->fontStyle());
return face;
}
@@ -2180,27 +2181,20 @@ static int compute_metric(const SkFontStyle& a, const SkFontStyle& b) {
}
static SkTypeface* createFromDesc(CFStringRef cfFamilyName, CTFontDescriptorRef desc) {
- NameStyle cacheRequest;
SkString skFamilyName;
CFStringToSkString(cfFamilyName, &skFamilyName);
- cacheRequest.fName = skFamilyName.c_str();
- cacheRequest.fStyle = fontstyle_from_descriptor(desc);
-
- SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &cacheRequest);
- if (face) {
- return face;
- }
AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, nullptr));
if (!ctFont) {
return nullptr;
}
- bool isFixedPitch;
- (void)computeStyleBits(ctFont, &isFixedPitch);
+ SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (void*)ctFont.get());
+ if (face) {
+ return face;
+ }
- face = new SkTypeface_Mac(ctFont.release(), nullptr, cacheRequest.fStyle, isFixedPitch,
- skFamilyName.c_str(), false);
+ face = NewFromFontRef(ctFont.release(), nullptr, skFamilyName.c_str(), false);
SkTypefaceCache::Add(face, face->fontStyle());
return face;
}
@@ -2612,17 +2606,16 @@ protected:
NameStyle cacheRequest = { familyName, style };
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &cacheRequest);
bungeman-skia 2016/04/05 22:03:26 Leaving this find_by_NameStyle here is trouble, wh
+ if (face) {
+ return face;
+ }
- if (nullptr == face) {
- face = NewFromName(familyName, style);
- if (face) {
- SkTypefaceCache::Add(face, style);
- } else {
- face = GetDefaultFace();
- face->ref();
- }
+ face = NewFromName(familyName, style);
+ if (face) {
+ return face;
}
- return face;
+
+ return SkSafeRef(GetDefaultFace());
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698