OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkScalerContext.h" | 10 #include "SkScalerContext.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 ctx = ctx->getNextContext(); | 171 ctx = ctx->getNextContext(); |
172 if (NULL == ctx) { | 172 if (NULL == ctx) { |
173 // SkDebugf("--- no context for glyph %x\n", glyph.getGlyphID()); | 173 // SkDebugf("--- no context for glyph %x\n", glyph.getGlyphID()); |
174 // just return the original context (this) | 174 // just return the original context (this) |
175 return this; | 175 return this; |
176 } | 176 } |
177 } | 177 } |
178 return ctx; | 178 return ctx; |
179 } | 179 } |
180 | 180 |
| 181 SkScalerContext* SkScalerContext::getContextFromChar(SkUnichar uni, |
| 182 uint16_t* glyphID) { |
| 183 SkScalerContext* ctx = this; |
| 184 for (;;) { |
| 185 const uint16_t glyph = ctx->generateCharToGlyph(uni); |
| 186 if (glyph) { |
| 187 if (NULL != glyphID) { |
| 188 *glyphID = glyph; |
| 189 } |
| 190 break; // found it |
| 191 } |
| 192 ctx = ctx->getNextContext(); |
| 193 if (NULL == ctx) { |
| 194 return NULL; |
| 195 } |
| 196 } |
| 197 return ctx; |
| 198 } |
| 199 |
181 #ifdef SK_BUILD_FOR_ANDROID | 200 #ifdef SK_BUILD_FOR_ANDROID |
| 201 SkFontID SkScalerContext::findTypefaceIdForChar(SkUnichar uni) { |
| 202 SkScalerContext* ctx = this->getContextFromChar(uni, NULL); |
| 203 if (NULL != ctx) { |
| 204 return ctx->fRec.fFontID; |
| 205 } else { |
| 206 return 0; |
| 207 } |
| 208 } |
| 209 |
182 /* This loops through all available fallback contexts (if needed) until it | 210 /* This loops through all available fallback contexts (if needed) until it |
183 finds some context that can handle the unichar and return it. | 211 finds some context that can handle the unichar and return it. |
184 | 212 |
185 As this is somewhat expensive operation, it should only be done on the first | 213 As this is somewhat expensive operation, it should only be done on the first |
186 char of a run. | 214 char of a run. |
187 */ | 215 */ |
188 unsigned SkScalerContext::getBaseGlyphCount(SkUnichar uni) { | 216 unsigned SkScalerContext::getBaseGlyphCount(SkUnichar uni) { |
189 SkScalerContext* ctx = this; | 217 SkScalerContext* ctx = this->getContextFromChar(uni, NULL); |
190 unsigned glyphID; | 218 if (NULL != ctx) { |
191 for (;;) { | 219 return ctx->fBaseGlyphCount; |
192 glyphID = ctx->generateCharToGlyph(uni); | 220 } else { |
193 if (glyphID) { | 221 SkDEBUGF(("--- no context for char %x\n", uni)); |
194 break; // found it | 222 return this->fBaseGlyphCount; |
195 } | |
196 ctx = ctx->getNextContext(); | |
197 if (NULL == ctx) { | |
198 SkDebugf("--- no context for char %x\n", uni); | |
199 // just return the original context (this) | |
200 return this->fBaseGlyphCount; | |
201 } | |
202 } | 223 } |
203 return ctx->fBaseGlyphCount; | |
204 } | 224 } |
205 #endif | 225 #endif |
206 | 226 |
207 /* This loops through all available fallback contexts (if needed) until it | 227 /* This loops through all available fallback contexts (if needed) until it |
208 finds some context that can handle the unichar. If all fail, returns 0 | 228 finds some context that can handle the unichar. If all fail, returns 0 |
209 */ | 229 */ |
210 uint16_t SkScalerContext::charToGlyphID(SkUnichar uni) { | 230 uint16_t SkScalerContext::charToGlyphID(SkUnichar uni) { |
211 SkScalerContext* ctx = this; | 231 |
212 unsigned glyphID; | 232 uint16_t tempID; |
213 for (;;) { | 233 SkScalerContext* ctx = this->getContextFromChar(uni, &tempID); |
214 glyphID = ctx->generateCharToGlyph(uni); | 234 if (NULL == ctx) { |
215 if (glyphID) { | 235 return 0; // no more contexts, return missing glyph |
216 break; // found it | |
217 } | |
218 ctx = ctx->getNextContext(); | |
219 if (NULL == ctx) { | |
220 return 0; // no more contexts, return missing glyph | |
221 } | |
222 } | 236 } |
223 // add the ctx's base, making glyphID unique for chain of contexts | 237 // add the ctx's base, making glyphID unique for chain of contexts |
224 glyphID += ctx->fBaseGlyphCount; | 238 unsigned glyphID = tempID + ctx->fBaseGlyphCount; |
225 // check for overflow of 16bits, since our glyphID cannot exceed that | 239 // check for overflow of 16bits, since our glyphID cannot exceed that |
226 if (glyphID > 0xFFFF) { | 240 if (glyphID > 0xFFFF) { |
227 glyphID = 0; | 241 glyphID = 0; |
228 } | 242 } |
229 return SkToU16(glyphID); | 243 return SkToU16(glyphID); |
230 } | 244 } |
231 | 245 |
232 SkUnichar SkScalerContext::glyphIDToChar(uint16_t glyphID) { | 246 SkUnichar SkScalerContext::glyphIDToChar(uint16_t glyphID) { |
233 SkScalerContext* ctx = this; | 247 SkScalerContext* ctx = this; |
234 unsigned rangeEnd = 0; | 248 unsigned rangeEnd = 0; |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) { | 773 SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) { |
760 SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); | 774 SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); |
761 if (NULL == c) { | 775 if (NULL == c) { |
762 c = SkFontHost::CreateScalerContext(desc); | 776 c = SkFontHost::CreateScalerContext(desc); |
763 } | 777 } |
764 if (NULL == c) { | 778 if (NULL == c) { |
765 c = SkNEW_ARGS(SkScalerContext_Empty, (desc)); | 779 c = SkNEW_ARGS(SkScalerContext_Empty, (desc)); |
766 } | 780 } |
767 return c; | 781 return c; |
768 } | 782 } |
OLD | NEW |