| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkFontConfigInterface.h" | 8 #include "SkFontConfigInterface.h" |
| 9 #include "SkFontHost_FreeType_common.h" | 9 #include "SkFontHost_FreeType_common.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| 11 #include "SkTypefaceCache.h" | 11 #include "SkTypefaceCache.h" |
| 12 | 12 |
| 13 class SkFontDescriptor; | 13 class SkFontDescriptor; |
| 14 | 14 |
| 15 class FontConfigTypeface : public SkTypeface_FreeType { | 15 class FontConfigTypeface : public SkTypeface_FreeType { |
| 16 SkFontConfigInterface::FontIdentity fIdentity; | 16 SkFontConfigInterface::FontIdentity fIdentity; |
| 17 SkString fFamilyName; | 17 SkString fFamilyName; |
| 18 SkStream* fLocalStream; | 18 SkStream* fLocalStream; |
| 19 | 19 |
| 20 public: | 20 public: |
| 21 static FontConfigTypeface* Create(const SkFontStyle& style, | 21 static FontConfigTypeface* Create(Style style, |
| 22 const SkFontConfigInterface::FontIdentity&
fi, | 22 const SkFontConfigInterface::FontIdentity&
fi, |
| 23 const SkString& familyName) { | 23 const SkString& familyName) { |
| 24 return SkNEW_ARGS(FontConfigTypeface, (style, fi, familyName)); | 24 return SkNEW_ARGS(FontConfigTypeface, (style, fi, familyName)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 static FontConfigTypeface* Create(const SkFontStyle& style, bool fixedWidth, | 27 static FontConfigTypeface* Create(Style style, bool fixedWidth, SkStream* lo
calStream) { |
| 28 SkStream* localStream) { | |
| 29 return SkNEW_ARGS(FontConfigTypeface, (style, fixedWidth, localStream)); | 28 return SkNEW_ARGS(FontConfigTypeface, (style, fixedWidth, localStream)); |
| 30 } | 29 } |
| 31 | 30 |
| 32 virtual ~FontConfigTypeface() { | 31 virtual ~FontConfigTypeface() { |
| 33 SkSafeUnref(fLocalStream); | 32 SkSafeUnref(fLocalStream); |
| 34 } | 33 } |
| 35 | 34 |
| 36 const SkFontConfigInterface::FontIdentity& getIdentity() const { | 35 const SkFontConfigInterface::FontIdentity& getIdentity() const { |
| 37 return fIdentity; | 36 return fIdentity; |
| 38 } | 37 } |
| 39 | 38 |
| 40 const char* getFamilyName() const { return fFamilyName.c_str(); } | 39 const char* getFamilyName() const { return fFamilyName.c_str(); } |
| 41 SkStream* getLocalStream() const { return fLocalStream; } | 40 SkStream* getLocalStream() const { return fLocalStream; } |
| 42 | 41 |
| 43 bool isFamilyName(const char* name) const { | 42 bool isFamilyName(const char* name) const { |
| 44 return fFamilyName.equals(name); | 43 return fFamilyName.equals(name); |
| 45 } | 44 } |
| 46 | 45 |
| 47 static SkTypeface* LegacyCreateTypeface(const SkTypeface* family, | 46 static SkTypeface* LegacyCreateTypeface(const SkTypeface* family, |
| 48 const char familyName[], | 47 const char familyName[], |
| 49 SkTypeface::Style); | 48 SkTypeface::Style); |
| 50 | 49 |
| 51 protected: | 50 protected: |
| 52 friend class SkFontHost; // hack until we can make public versions | 51 friend class SkFontHost; // hack until we can make public versions |
| 53 | 52 |
| 54 FontConfigTypeface(const SkFontStyle& style, | 53 FontConfigTypeface(Style style, |
| 55 const SkFontConfigInterface::FontIdentity& fi, | 54 const SkFontConfigInterface::FontIdentity& fi, |
| 56 const SkString& familyName) | 55 const SkString& familyName) |
| 57 : INHERITED(style, SkTypefaceCache::NewFontID(), false) | 56 : INHERITED(style, SkTypefaceCache::NewFontID(), false) |
| 58 , fIdentity(fi) | 57 , fIdentity(fi) |
| 59 , fFamilyName(familyName) | 58 , fFamilyName(familyName) |
| 60 , fLocalStream(NULL) {} | 59 , fLocalStream(NULL) {} |
| 61 | 60 |
| 62 FontConfigTypeface(const SkFontStyle& style, bool fixedWidth, SkStream* loca
lStream) | 61 FontConfigTypeface(Style style, bool fixedWidth, SkStream* localStream) |
| 63 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) { | 62 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) { |
| 64 // we default to empty fFamilyName and fIdentity | 63 // we default to empty fFamilyName and fIdentity |
| 65 fLocalStream = localStream; | 64 fLocalStream = localStream; |
| 66 SkSafeRef(localStream); | 65 SkSafeRef(localStream); |
| 67 } | 66 } |
| 68 | 67 |
| 69 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; | 68 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; |
| 70 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; | 69 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
| 71 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 70 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
| 72 | 71 |
| 73 private: | 72 private: |
| 74 typedef SkTypeface_FreeType INHERITED; | 73 typedef SkTypeface_FreeType INHERITED; |
| 75 }; | 74 }; |
| OLD | NEW |