Chromium Code Reviews| Index: src/ports/SkFontHost_mac.cpp |
| diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp |
| index e00b87b59b4b6d62a8e13c8dc80cc8444ad435fa..e1a60c4b5b0415c8088a15578b459b997808513c 100755 |
| --- a/src/ports/SkFontHost_mac.cpp |
| +++ b/src/ports/SkFontHost_mac.cpp |
| @@ -426,21 +426,23 @@ static SkTypeface::Style fontstyle2stylebits(const SkFontStyle& fs) { |
| class SkTypeface_Mac : public SkTypeface { |
| public: |
| SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch, |
| - CTFontRef fontRef, const char name[]) |
| + CTFontRef fontRef, const char name[], bool isLocalStream) |
| : SkTypeface(style, fontID, isFixedPitch) |
| , fName(name) |
| , fFontRef(fontRef) // caller has already called CFRetain for us |
| , fFontStyle(stylebits2fontstyle(style)) |
| + , fIsLocalStream(isLocalStream) |
| { |
| SkASSERT(fontRef); |
| } |
| SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch, |
| - CTFontRef fontRef, const char name[]) |
| + CTFontRef fontRef, const char name[], bool isLocalStream) |
| : SkTypeface(fontstyle2stylebits(fs), fontID, isFixedPitch) |
| , fName(name) |
| , fFontRef(fontRef) // caller has already called CFRetain for us |
| , fFontStyle(fs) |
| + , fIsLocalStream(isLocalStream) |
| { |
| SkASSERT(fontRef); |
| } |
| @@ -469,17 +471,18 @@ protected: |
| virtual int onCountGlyphs() const SK_OVERRIDE; |
| private: |
| + bool fIsLocalStream; |
| typedef SkTypeface INHERITED; |
| }; |
| -static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { |
| +static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isLocalStream) { |
| SkASSERT(fontRef); |
| bool isFixedPitch; |
| SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); |
| SkFontID fontID = CTFontRef_to_SkFontID(fontRef); |
| - return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name); |
| + return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name, isLocalStream); |
| } |
| static SkTypeface* NewFromName(const char familyName[], SkTypeface::Style theStyle) { |
| @@ -524,7 +527,7 @@ static SkTypeface* NewFromName(const char familyName[], SkTypeface::Style theSty |
| } |
| } |
| - return ctFont ? NewFromFontRef(ctFont, familyName) : NULL; |
| + return ctFont ? NewFromFontRef(ctFont, familyName, false) : NULL; |
| } |
| static SkTypeface* GetDefaultFace() { |
| @@ -548,16 +551,13 @@ CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { |
| return macface ? macface->fFontRef.get() : NULL; |
| } |
| -/* This function is visible on the outside. It first searches the cache, and if |
| - * not found, returns a new entry (after adding it to the cache). |
| - */ |
| -SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { |
| +static SkTypeface* internalCreateTypefaceFromCTFont(CTFontRef fontRef, bool isLocalStream) { |
| SkFontID fontID = CTFontRef_to_SkFontID(fontRef); |
| SkTypeface* face = SkTypefaceCache::FindByID(fontID); |
| if (face) { |
| face->ref(); |
| } else { |
| - face = NewFromFontRef(fontRef, NULL); |
| + face = NewFromFontRef(fontRef, NULL, isLocalStream); |
| SkTypefaceCache::Add(face, face->style()); |
| // NewFromFontRef doesn't retain the parameter, but the typeface it |
| // creates does release it in its destructor, so we balance that with |
| @@ -568,6 +568,13 @@ SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { |
| return face; |
| } |
| +/* This function is visible on the outside. It first searches the cache, and if |
| + * not found, returns a new entry (after adding it to the cache). |
| + */ |
| +SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { |
| + return internalCreateTypefaceFromCTFont(fontRef, false); |
| +} |
| + |
| struct NameStyleRec { |
| const char* fName; |
| SkTypeface::Style fStyle; |
| @@ -1438,7 +1445,7 @@ static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { |
| return NULL; |
| } |
| CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); |
| - return cg ? SkCreateTypefaceFromCTFont(ct) : NULL; |
| + return cg ? internalCreateTypefaceFromCTFont(ct, true) : NULL; |
|
bungeman-skia
2014/06/30 15:10:23
I think this is incorrect, in that stream based ty
|
| } |
| // Web fonts added to the the CTFont registry do not return their character set. |
| @@ -1908,8 +1915,7 @@ void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, |
| desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); |
| desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); |
| desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)); |
| - // TODO: need to add support for local-streams (here and openStream) |
| - *isLocalStream = false; |
| + *isLocalStream = fIsLocalStream; |
| } |
| int SkTypeface_Mac::onCharsToGlyphs(const void* chars, Encoding encoding, |
| @@ -2128,7 +2134,7 @@ static SkTypeface* createFromDesc(CFStringRef cfFamilyName, |
| SkFontID fontID = CTFontRef_to_SkFontID(ctFont); |
| face = SkNEW_ARGS(SkTypeface_Mac, (rec.fFontStyle, fontID, isFixedPitch, |
| - ctFont, str.c_str())); |
| + ctFont, str.c_str(), false)); |
| SkTypefaceCache::Add(face, face->style()); |
| return face; |
| } |