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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 SkFontStyle requestedStyle(style); | 98 SkFontStyle requestedStyle(style); |
99 NameStyle nameStyle(familyName, requestedStyle); | 99 NameStyle nameStyle(familyName, requestedStyle); |
100 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &nam
eStyle); | 100 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &nam
eStyle); |
101 if (face) { | 101 if (face) { |
102 //SkDebugf("found cached face <%s> <%s> %p [%d]\n", | 102 //SkDebugf("found cached face <%s> <%s> %p [%d]\n", |
103 // familyName, ((FontConfigTypeface*)face)->getFamilyName(), | 103 // familyName, ((FontConfigTypeface*)face)->getFamilyName(), |
104 // face, face->getRefCnt()); | 104 // face, face->getRefCnt()); |
105 return face; | 105 return face; |
106 } | 106 } |
107 | 107 |
108 SkFontConfigInterface::FontIdentity indentity; | 108 SkFontConfigInterface::FontIdentity identity; |
109 SkString outFamilyName; | 109 SkString outFamilyName; |
110 SkTypeface::Style outStyle; | 110 SkTypeface::Style outStyle; |
111 if (!fci->matchFamilyName(familyName, style, &indentity, &outFamilyName, &ou
tStyle)) { | 111 if (!fci->matchFamilyName(familyName, style, &identity, &outFamilyName, &out
Style)) { |
112 return NULL; | 112 return NULL; |
113 } | 113 } |
114 | 114 |
115 // Check if a typeface with this FontIdentity is already in the FontIdentity
cache. | 115 // Check if a typeface with this outFamily is already in the FontIdentity ca
che. |
116 face = SkTypefaceCache::FindByProcAndRef(find_by_FontIdentity, &indentity); | 116 face = SkTypefaceCache::FindByProcAndRef(find_by_FontIdentity, &identity); |
117 if (!face) { | 117 if (!face) { |
118 face = FontConfigTypeface::Create(SkFontStyle(outStyle), indentity, outF
amilyName); | 118 face = FontConfigTypeface::Create(SkFontStyle(outStyle), identity, outFa
milyName); |
119 // Add this FontIdentity to the FontIdentity cache. | 119 // Add this FontIdentity to the FontIdentity cache. |
120 SkTypefaceCache::Add(face, requestedStyle); | 120 SkTypefaceCache::Add(face, requestedStyle); |
121 } | 121 } |
122 // TODO: Ensure requested NameStyle and resolved NameStyle are both in the N
ameStyle cache. | 122 // TODO: Ensure requested NameStyle and resolved NameStyle are both in the N
ameStyle cache. |
123 | 123 |
124 //SkDebugf("add face <%s> <%s> %p [%d]\n", | 124 //SkDebugf("add face <%s> <%s> %p [%d]\n", |
125 // familyName, outFamilyName.c_str(), | 125 // familyName, outFamilyName.c_str(), |
126 // face, face->getRefCnt()); | 126 // face, face->getRefCnt()); |
| 127 |
| 128 // If any aliased name is returned for the requested family, cache SkTypefac
e |
| 129 // with the original family name so the following lookups will hit the cache
. |
| 130 if (!outFamilyName.equals(familyName)) { |
| 131 SkTypeface* face_orig = |
| 132 FontConfigTypeface::Create(SkFontStyle(outStyle), identity, SkSt
ring(familyName)); |
| 133 SkTypefaceCache::Add(face_orig, requestedStyle); |
| 134 //SkDebugf("add face <%s> %p [%d]\n", |
| 135 // familyName, face_orig, face_orig->getRefCnt()); |
| 136 } |
127 return face; | 137 return face; |
128 } | 138 } |
129 | 139 |
130 /////////////////////////////////////////////////////////////////////////////// | 140 /////////////////////////////////////////////////////////////////////////////// |
131 | 141 |
132 SkStreamAsset* FontConfigTypeface::onOpenStream(int* ttcIndex) const { | 142 SkStreamAsset* FontConfigTypeface::onOpenStream(int* ttcIndex) const { |
133 SkStreamAsset* stream = this->getLocalStream(); | 143 SkStreamAsset* stream = this->getLocalStream(); |
134 if (stream) { | 144 if (stream) { |
135 // TODO: should have been provided by CreateFromStream() | 145 // TODO: should have been provided by CreateFromStream() |
136 *ttcIndex = 0; | 146 *ttcIndex = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
150 *familyName = fFamilyName; | 160 *familyName = fFamilyName; |
151 } | 161 } |
152 | 162 |
153 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 163 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
154 bool* isLocalStream) const { | 164 bool* isLocalStream) const { |
155 SkString name; | 165 SkString name; |
156 this->getFamilyName(&name); | 166 this->getFamilyName(&name); |
157 desc->setFamilyName(name.c_str()); | 167 desc->setFamilyName(name.c_str()); |
158 *isLocalStream = SkToBool(this->getLocalStream()); | 168 *isLocalStream = SkToBool(this->getLocalStream()); |
159 } | 169 } |
OLD | NEW |