OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 Google Inc. | 2 * Copyright 2008 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 "SkFontConfigTypeface.h" | 9 #include "SkFontConfigTypeface.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 // export this to SkFontMgr_fontconfig.cpp until this file just goes away. | 54 // export this to SkFontMgr_fontconfig.cpp until this file just goes away. |
55 SkFontConfigInterface* SkFontHost_fontconfig_ref_global(); | 55 SkFontConfigInterface* SkFontHost_fontconfig_ref_global(); |
56 SkFontConfigInterface* SkFontHost_fontconfig_ref_global() { | 56 SkFontConfigInterface* SkFontHost_fontconfig_ref_global() { |
57 return RefFCI(); | 57 return RefFCI(); |
58 } | 58 } |
59 | 59 |
60 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
61 | 61 |
62 struct FindRec { | 62 struct FindRec { |
63 FindRec(const char* name, SkTypeface::Style style) | 63 FindRec(const char* name, const SkFontStyle& style) |
64 : fFamilyName(name) // don't need to make a deep copy | 64 : fFamilyName(name) // don't need to make a deep copy |
65 , fStyle(style) {} | 65 , fStyle(style) {} |
66 | 66 |
67 const char* fFamilyName; | 67 const char* fFamilyName; |
68 SkTypeface::Style fStyle; | 68 SkFontStyle fStyle; |
69 }; | 69 }; |
70 | 70 |
71 static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) { | 71 static bool find_proc(SkTypeface* cachedTypeface, const SkFontStyle& cachedStyle
, void* ctx) { |
72 FontConfigTypeface* fci = (FontConfigTypeface*)face; | 72 FontConfigTypeface* cachedFCTypeface = (FontConfigTypeface*)cachedTypeface; |
73 const FindRec* rec = (const FindRec*)ctx; | 73 const FindRec* rec = static_cast<const FindRec*>(ctx); |
74 | 74 |
75 return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName); | 75 return rec->fStyle == cachedStyle && |
| 76 cachedFCTypeface->isFamilyName(rec->fFamilyName); |
76 } | 77 } |
77 | 78 |
78 SkTypeface* FontConfigTypeface::LegacyCreateTypeface( | 79 SkTypeface* FontConfigTypeface::LegacyCreateTypeface( |
79 const SkTypeface* familyFace, | 80 const SkTypeface* familyFace, |
80 const char familyName[], | 81 const char familyName[], |
81 SkTypeface::Style style) { | 82 SkTypeface::Style style) { |
82 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); | 83 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); |
83 if (NULL == fci.get()) { | 84 if (NULL == fci.get()) { |
84 return NULL; | 85 return NULL; |
85 } | 86 } |
86 | 87 |
87 if (familyFace) { | 88 if (familyFace) { |
88 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace; | 89 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace; |
89 familyName = fct->getFamilyName(); | 90 familyName = fct->getFamilyName(); |
90 } | 91 } |
91 | 92 |
92 FindRec rec(familyName, style); | 93 SkFontStyle requestedStyle(style); |
| 94 FindRec rec(familyName, requestedStyle); |
93 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); | 95 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); |
94 if (face) { | 96 if (face) { |
95 // SkDebugf("found cached face <%s> <%s> %p [%d]\n", familyName, ((FontCo
nfigTypeface*)face)->getFamilyName(), face, face->getRefCnt()); | 97 //SkDebugf("found cached face <%s> <%s> %p [%d]\n", |
| 98 // familyName, ((FontConfigTypeface*)face)->getFamilyName(), |
| 99 // face, face->getRefCnt()); |
96 return face; | 100 return face; |
97 } | 101 } |
98 | 102 |
99 SkFontConfigInterface::FontIdentity indentity; | 103 SkFontConfigInterface::FontIdentity indentity; |
100 SkString outFamilyName; | 104 SkString outFamilyName; |
101 SkTypeface::Style outStyle; | 105 SkTypeface::Style outStyle; |
102 | 106 if (!fci->matchFamilyName(familyName, style, &indentity, &outFamilyName, &ou
tStyle)) { |
103 if (!fci->matchFamilyName(familyName, style, | |
104 &indentity, &outFamilyName, &outStyle)) { | |
105 return NULL; | 107 return NULL; |
106 } | 108 } |
107 | 109 |
108 // check if we, in fact, already have this. perhaps fontconfig aliased the | 110 // check if we, in fact, already have this. perhaps fontconfig aliased the |
109 // requested name to some other name we actually have... | 111 // requested name to some other name we actually have... |
110 rec.fFamilyName = outFamilyName.c_str(); | 112 rec.fFamilyName = outFamilyName.c_str(); |
111 rec.fStyle = outStyle; | 113 rec.fStyle = SkFontStyle(outStyle); |
112 face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); | 114 face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); |
113 if (face) { | 115 if (face) { |
114 return face; | 116 return face; |
115 } | 117 } |
116 | 118 |
117 face = FontConfigTypeface::Create(outStyle, indentity, outFamilyName); | 119 face = FontConfigTypeface::Create(SkFontStyle(outStyle), indentity, outFamil
yName); |
118 SkTypefaceCache::Add(face, style); | 120 SkTypefaceCache::Add(face, requestedStyle); |
119 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str()
, face, face->getRefCnt()); | 121 //SkDebugf("add face <%s> <%s> %p [%d]\n", |
| 122 // familyName, outFamilyName.c_str(), |
| 123 // face, face->getRefCnt()); |
120 return face; | 124 return face; |
121 } | 125 } |
122 | 126 |
123 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
124 | 128 |
125 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { | 129 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { |
126 SkStream* stream = this->getLocalStream(); | 130 SkStream* stream = this->getLocalStream(); |
127 if (stream) { | 131 if (stream) { |
128 // should have been provided by CreateFromStream() | 132 // should have been provided by CreateFromStream() |
129 *ttcIndex = 0; | 133 *ttcIndex = 0; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { | 169 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { |
166 *familyName = this->getFamilyName(); | 170 *familyName = this->getFamilyName(); |
167 } | 171 } |
168 | 172 |
169 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 173 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
170 bool* isLocalStream) const { | 174 bool* isLocalStream) const { |
171 desc->setFamilyName(this->getFamilyName()); | 175 desc->setFamilyName(this->getFamilyName()); |
172 desc->setFontIndex(this->getIdentity().fTTCIndex); | 176 desc->setFontIndex(this->getIdentity().fTTCIndex); |
173 *isLocalStream = SkToBool(this->getLocalStream()); | 177 *isLocalStream = SkToBool(this->getLocalStream()); |
174 } | 178 } |
OLD | NEW |