| 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(Style style, | 21 static FontConfigTypeface* Create(const SkFontStyle& 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(Style style, bool fixedWidth, SkStream* lo
calStream) { | 27 static FontConfigTypeface* Create(const SkFontStyle& style, bool fixedWidth, |
| 28 SkStream* localStream) { |
| 28 return SkNEW_ARGS(FontConfigTypeface, (style, fixedWidth, localStream)); | 29 return SkNEW_ARGS(FontConfigTypeface, (style, fixedWidth, localStream)); |
| 29 } | 30 } |
| 30 | 31 |
| 31 virtual ~FontConfigTypeface() { | 32 virtual ~FontConfigTypeface() { |
| 32 SkSafeUnref(fLocalStream); | 33 SkSafeUnref(fLocalStream); |
| 33 } | 34 } |
| 34 | 35 |
| 35 const SkFontConfigInterface::FontIdentity& getIdentity() const { | 36 const SkFontConfigInterface::FontIdentity& getIdentity() const { |
| 36 return fIdentity; | 37 return fIdentity; |
| 37 } | 38 } |
| 38 | 39 |
| 39 const char* getFamilyName() const { return fFamilyName.c_str(); } | 40 const char* getFamilyName() const { return fFamilyName.c_str(); } |
| 40 SkStream* getLocalStream() const { return fLocalStream; } | 41 SkStream* getLocalStream() const { return fLocalStream; } |
| 41 | 42 |
| 42 bool isFamilyName(const char* name) const { | 43 bool isFamilyName(const char* name) const { |
| 43 return fFamilyName.equals(name); | 44 return fFamilyName.equals(name); |
| 44 } | 45 } |
| 45 | 46 |
| 46 static SkTypeface* LegacyCreateTypeface(const SkTypeface* family, | 47 static SkTypeface* LegacyCreateTypeface(const SkTypeface* family, |
| 47 const char familyName[], | 48 const char familyName[], |
| 48 SkTypeface::Style); | 49 SkTypeface::Style); |
| 49 | 50 |
| 50 protected: | 51 protected: |
| 51 friend class SkFontHost; // hack until we can make public versions | 52 friend class SkFontHost; // hack until we can make public versions |
| 52 | 53 |
| 53 FontConfigTypeface(Style style, | 54 FontConfigTypeface(const SkFontStyle& style, |
| 54 const SkFontConfigInterface::FontIdentity& fi, | 55 const SkFontConfigInterface::FontIdentity& fi, |
| 55 const SkString& familyName) | 56 const SkString& familyName) |
| 56 : INHERITED(style, SkTypefaceCache::NewFontID(), false) | 57 : INHERITED(style, SkTypefaceCache::NewFontID(), false) |
| 57 , fIdentity(fi) | 58 , fIdentity(fi) |
| 58 , fFamilyName(familyName) | 59 , fFamilyName(familyName) |
| 59 , fLocalStream(NULL) {} | 60 , fLocalStream(NULL) {} |
| 60 | 61 |
| 61 FontConfigTypeface(Style style, bool fixedWidth, SkStream* localStream) | 62 FontConfigTypeface(const SkFontStyle& style, bool fixedWidth, SkStream* loca
lStream) |
| 62 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) { | 63 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) { |
| 63 // we default to empty fFamilyName and fIdentity | 64 // we default to empty fFamilyName and fIdentity |
| 64 fLocalStream = localStream; | 65 fLocalStream = localStream; |
| 65 SkSafeRef(localStream); | 66 SkSafeRef(localStream); |
| 66 } | 67 } |
| 67 | 68 |
| 68 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; | 69 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; |
| 69 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; | 70 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
| 70 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 71 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 typedef SkTypeface_FreeType INHERITED; | 74 typedef SkTypeface_FreeType INHERITED; |
| 74 }; | 75 }; |
| OLD | NEW |