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

Side by Side Diff: src/ports/SkFontConfigInterface_android.cpp

Issue 23621052: FYI, Language parameter on Android (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 /* 2 /*
3 * Copyright 2013 The Android Open Source Project 3 * Copyright 2013 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 #include "SkFontConfigInterface.h" 9 #include "SkFontConfigInterface.h"
10 #include "SkTypeface_android.h" 10 #include "SkTypeface_android.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 struct FamilyRec { 62 struct FamilyRec {
63 FamilyRec() { 63 FamilyRec() {
64 memset(fFontRecID, INVALID_FONT_REC_ID, sizeof(fFontRecID)); 64 memset(fFontRecID, INVALID_FONT_REC_ID, sizeof(fFontRecID));
65 } 65 }
66 66
67 static const int FONT_STYLE_COUNT = 4; 67 static const int FONT_STYLE_COUNT = 4;
68 FontRecID fFontRecID[FONT_STYLE_COUNT]; 68 FontRecID fFontRecID[FONT_STYLE_COUNT];
69 bool fIsFallbackFont; 69 bool fIsFallbackFont;
70 SkPaintOptionsAndroid fPaintOptions; 70 SkPaintOptionsAndroid fPaintOptions;
71 // To allow fallback fonts to be identified by family names.
72 SkString fPseudoFamilyName;
71 }; 73 };
72 74
73 75
74 typedef SkTDArray<FamilyRecID> FallbackFontList; 76 typedef SkTDArray<FamilyRecID> FallbackFontList;
75 77
76 class SkFontConfigInterfaceAndroid : public SkFontConfigInterface { 78 class SkFontConfigInterfaceAndroid : public SkFontConfigInterface {
77 public: 79 public:
78 SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies); 80 SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies);
79 virtual ~SkFontConfigInterfaceAndroid(); 81 virtual ~SkFontConfigInterfaceAndroid();
80 82
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 "multiple families. skipping subsequent occurrences", tolc.lc() ); 190 "multiple families. skipping subsequent occurrences", tolc.lc() );
189 } else { 191 } else {
190 familyNameDict.set(tolc.lc(), familyRecID); 192 familyNameDict.set(tolc.lc(), familyRecID);
191 } 193 }
192 } 194 }
193 195
194 // Defined in SkFontHost_FreeType.cpp 196 // Defined in SkFontHost_FreeType.cpp
195 bool find_name_and_attributes(SkStream* stream, SkString* name, 197 bool find_name_and_attributes(SkStream* stream, SkString* name,
196 SkTypeface::Style* style, bool* isFixedWidth); 198 SkTypeface::Style* style, bool* isFixedWidth);
197 199
200 static void setPseudoFamilyName(FamilyRecID familyRecID, FamilyRec* familyRec) {
201 SkString pseudoFamilyName("##");
202 pseudoFamilyName.appendHex(static_cast<uint32_t>(familyRecID) ^ reinterpret_ cast<uint32_t>(familyRec));
203 familyRec->fPseudoFamilyName = pseudoFamilyName;
204 }
205
198 /////////////////////////////////////////////////////////////////////////////// 206 ///////////////////////////////////////////////////////////////////////////////
199 207
200 SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily* >& fontFamilies) : 208 SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily* >& fontFamilies) :
201 fFonts(fontFamilies.count()), 209 fFonts(fontFamilies.count()),
202 fFontFamilies(fontFamilies.count() / FamilyRec::FONT_STYLE_COUNT), 210 fFontFamilies(fontFamilies.count() / FamilyRec::FONT_STYLE_COUNT),
203 fFamilyNameDict(1024), 211 fFamilyNameDict(1024),
204 fDefaultFamilyRecID(INVALID_FAMILY_REC_ID), 212 fDefaultFamilyRecID(INVALID_FAMILY_REC_ID),
205 fFallbackFontDict(128), 213 fFallbackFontDict(128),
206 fFallbackFontAliasDict(128), 214 fFallbackFontAliasDict(128),
207 fLocaleFallbackFontList(NULL) { 215 fLocaleFallbackFontList(NULL) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 familyRec = &fFontFamilies.push_back(); 267 familyRec = &fFontFamilies.push_back();
260 familyRecID = fFontFamilies.count() - 1; 268 familyRecID = fFontFamilies.count() - 1;
261 fontRec.fFamilyRecID = familyRecID; 269 fontRec.fFamilyRecID = familyRecID;
262 270
263 familyRec->fIsFallbackFont = family->fIsFallbackFont; 271 familyRec->fIsFallbackFont = family->fIsFallbackFont;
264 familyRec->fPaintOptions = family->fFontFiles[j]->fPaintOptions; 272 familyRec->fPaintOptions = family->fFontFiles[j]->fPaintOptions;
265 273
266 // if this is a fallback font then add it to the appropriate fal lback chains 274 // if this is a fallback font then add it to the appropriate fal lback chains
267 if (familyRec->fIsFallbackFont) { 275 if (familyRec->fIsFallbackFont) {
268 addFallbackFamily(familyRecID); 276 addFallbackFamily(familyRecID);
277 // create a unique pseudo family name for the fallback famil y and
278 // add the fallback font into the name dictionary. This is needed
279 // by getFallbackFamilyNameForChar() so that fallback famili es can be
280 // requested by the pseudo family names of the fonts they co ntain.
281 setPseudoFamilyName(familyRecID, familyRec);
282 insert_into_name_dict(fFamilyNameDict, familyRec->fPseudoFam ilyName.c_str(), familyRecID);
269 } 283 }
270 } else if (familyRec->fPaintOptions != family->fFontFiles[j]->fPaint Options) { 284 } else if (familyRec->fPaintOptions != family->fFontFiles[j]->fPaint Options) {
271 SkDebugf("Every font file within a family must have identical" 285 SkDebugf("Every font file within a family must have identical"
272 "language and variant attributes"); 286 "language and variant attributes");
273 sk_throw(); 287 sk_throw();
274 } 288 }
275 289
276 // add this font to the current familyRec 290 // add this font to the current familyRec
277 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) { 291 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) {
278 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d) ", 292 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d) ",
279 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle ], 293 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle ],
280 fontRecID)); 294 fontRecID));
281 } 295 }
282 familyRec->fFontRecID[fontRec.fStyle] = fontRecID; 296 familyRec->fFontRecID[fontRec.fStyle] = fontRecID;
283
284 // add the fallback file name to the name dictionary. This is neede d
285 // by getFallbackFamilyNameForChar() so that fallback families can b e
286 // requested by the filenames of the fonts they contain.
287 if (familyRec && familyRec->fIsFallbackFont) {
288 insert_into_name_dict(fFamilyNameDict, fontRec.fFileName.c_str() , familyRecID);
289 }
290 } 297 }
291 298
292 // add the names that map to this family to the dictionary for easy look up 299 // add the names that map to this family to the dictionary for easy look up
293 if (familyRec && !familyRec->fIsFallbackFont) { 300 if (familyRec && !familyRec->fIsFallbackFont) {
294 SkTDArray<const char*> names = family->fNames; 301 SkTDArray<const char*> names = family->fNames;
295 if (names.isEmpty()) { 302 if (names.isEmpty()) {
296 SkDEBUGFAIL("ERROR: non-fallback font with no name"); 303 SkDEBUGFAIL("ERROR: non-fallback font with no name");
297 continue; 304 continue;
298 } 305 }
299 306
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 // if it is not one of the accepted variants then move to the next famil y 522 // if it is not one of the accepted variants then move to the next famil y
516 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | 523 int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant |
517 SkPaintOptionsAndroid::kElegant_Variant; 524 SkPaintOptionsAndroid::kElegant_Variant;
518 if (!(fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & accept edVariants)) { 525 if (!(fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & accept edVariants)) {
519 continue; 526 continue;
520 } 527 }
521 528
522 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType face::kNormal); 529 FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkType face::kNormal);
523 SkTypeface* face = this->getTypefaceForFontRec(fontRecID); 530 SkTypeface* face = this->getTypefaceForFontRec(fontRecID);
524 531
532 FontRecID fontRecID = find_best_style(familyRec, SkTypeface::kNormal);
533 SkTypeface* face = getTypefaceForFontRec(fontRecID);
534
525 SkPaint paint; 535 SkPaint paint;
526 paint.setTypeface(face); 536 paint.setTypeface(face);
527 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); 537 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
528 538
529 uint16_t glyphID; 539 uint16_t glyphID;
530 paint.textToGlyphs(&uni, sizeof(uni), &glyphID); 540 paint.textToGlyphs(&uni, sizeof(uni), &glyphID);
531 if (glyphID != 0) { 541 if (glyphID != 0) {
532 name->set(fFonts[fontRecID].fFileName); 542 name->set(familyRec.fPseudoFamilyName);
533 return true; 543 return true;
534 } 544 }
535 } 545 }
536 return false; 546 return false;
537 } 547 }
538 548
539 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni, 549 SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForChar(SkUnichar uni,
540 SkTypeface::Style s tyle, 550 SkTypeface::Style s tyle,
541 SkPaintOptionsAndro id::FontVariant fontVariant) { 551 SkPaintOptionsAndro id::FontVariant fontVariant) {
542 FontRecID fontRecID = find_best_style(fFontFamilies[fDefaultFamilyRecID], st yle); 552 FontRecID fontRecID = find_best_style(fFontFamilies[fDefaultFamilyRecID], st yle);
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant); 861 return SkCreateTypefaceForScriptNG(getHBScriptFromHBScriptOld(script), style , fontVariant);
852 } 862 }
853 863
854 #endif 864 #endif
855 865
856 /////////////////////////////////////////////////////////////////////////////// 866 ///////////////////////////////////////////////////////////////////////////////
857 867
858 SkFontMgr* SkFontMgr::Factory() { 868 SkFontMgr* SkFontMgr::Factory() {
859 return NULL; 869 return NULL;
860 } 870 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698