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

Side by Side Diff: src/ports/SkFontConfigTypeface.h

Issue 227693003: Factory methods for heap-allocated SkTypeface objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comment Created 6 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 unified diff | Download patch
« no previous file with comments | « src/fonts/SkFontMgr_fontconfig.cpp ('k') | src/ports/SkFontHost_fontconfig.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 FontConfigTypeface(Style 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 : INHERITED(style, SkTypefaceCache::NewFontID(), false) 24 return SkNEW_ARGS(FontConfigTypeface, (style, fi, familyName));
25 , fIdentity(fi) 25 }
26 , fFamilyName(familyName)
27 , fLocalStream(NULL) {}
28 26
29 FontConfigTypeface(Style style, bool fixedWidth, SkStream* localStream) 27 static FontConfigTypeface* Create(Style style, bool fixedWidth, SkStream* lo calStream) {
30 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) { 28 return SkNEW_ARGS(FontConfigTypeface, (style, fixedWidth, localStream));
31 // we default to empty fFamilyName and fIdentity
32 fLocalStream = localStream;
33 SkSafeRef(localStream);
34 } 29 }
35 30
36 virtual ~FontConfigTypeface() { 31 virtual ~FontConfigTypeface() {
37 SkSafeUnref(fLocalStream); 32 SkSafeUnref(fLocalStream);
38 } 33 }
39 34
40 const SkFontConfigInterface::FontIdentity& getIdentity() const { 35 const SkFontConfigInterface::FontIdentity& getIdentity() const {
41 return fIdentity; 36 return fIdentity;
42 } 37 }
43 38
44 const char* getFamilyName() const { return fFamilyName.c_str(); } 39 const char* getFamilyName() const { return fFamilyName.c_str(); }
45 SkStream* getLocalStream() const { return fLocalStream; } 40 SkStream* getLocalStream() const { return fLocalStream; }
46 41
47 bool isFamilyName(const char* name) const { 42 bool isFamilyName(const char* name) const {
48 return fFamilyName.equals(name); 43 return fFamilyName.equals(name);
49 } 44 }
50 45
51 static SkTypeface* LegacyCreateTypeface(const SkTypeface* family, 46 static SkTypeface* LegacyCreateTypeface(const SkTypeface* family,
52 const char familyName[], 47 const char familyName[],
53 SkTypeface::Style); 48 SkTypeface::Style);
54 49
55 protected: 50 protected:
56 friend class SkFontHost; // hack until we can make public versions 51 friend class SkFontHost; // hack until we can make public versions
57 52
53 FontConfigTypeface(Style style,
54 const SkFontConfigInterface::FontIdentity& fi,
55 const SkString& familyName)
56 : INHERITED(style, SkTypefaceCache::NewFontID(), false)
57 , fIdentity(fi)
58 , fFamilyName(familyName)
59 , fLocalStream(NULL) {}
60
61 FontConfigTypeface(Style style, bool fixedWidth, SkStream* localStream)
62 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) {
63 // we default to empty fFamilyName and fIdentity
64 fLocalStream = localStream;
65 SkSafeRef(localStream);
66 }
67
58 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ; 68 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ;
59 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; 69 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
60 70
61 private: 71 private:
62 typedef SkTypeface_FreeType INHERITED; 72 typedef SkTypeface_FreeType INHERITED;
63 }; 73 };
OLDNEW
« no previous file with comments | « src/fonts/SkFontMgr_fontconfig.cpp ('k') | src/ports/SkFontHost_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698