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

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

Issue 673443003: Update fontMgr to take list of bcp47 language tags. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontHost_FreeType_common.h" 10 #include "SkFontHost_FreeType_common.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 if (fFontStyleSets[i]->fStyles[j] == typeface) { 339 if (fFontStyleSets[i]->fStyles[j] == typeface) {
340 return fFontStyleSets[i]->matchStyle(style); 340 return fFontStyleSets[i]->matchStyle(style);
341 } 341 }
342 } 342 }
343 } 343 }
344 return NULL; 344 return NULL;
345 } 345 }
346 346
347 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], 347 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
348 const SkFontStyle& style, 348 const SkFontStyle& style,
349 const char bpc47[], 349 const char** bcp47,
350 uint32_t character) const SK _OVERRIDE 350 size_t bcpLength,
351 SkUnichar character) const S K_OVERRIDE
351 { 352 {
352 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen t/descent'. 353 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen t/descent'.
353 // The variant 'default' means 'compact and elegant'. 354 // The variant 'default' means 'compact and elegant'.
354 // As a result, it is not possible to know the variant context from the font alone. 355 // As a result, it is not possible to know the variant context from the font alone.
355 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. 356 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request.
356 357
357 // For compatibility, try 'elegant' fonts first in fallback. 358 // For compatibility, try 'elegant' fonts first in fallback.
358 uint32_t variantMask = kElegant_FontVariant; 359 uint32_t variantMask = kElegant_FontVariant;
359 360
360 // The first time match anything in the mask, second time anything not i n the mask. 361 // The first time match anything in the mask, second time anything not i n the mask.
361 for (bool maskMatches = true; maskMatches != false; maskMatches = false) { 362 for (bool maskMatches = true; maskMatches != false; maskMatches = false) {
362 SkLanguage lang(bpc47); 363 size_t bcpNext = 1;
364 SkLanguage lang((bcpLength > 0) ? bcp47[0] : NULL);
363 // Match against the language, removing a segment each time. 365 // Match against the language, removing a segment each time.
364 // The last time through the loop, the language will be empty. 366 // The last time through the loop, the language will be empty.
365 // The empty language is special, and matches all languages. 367 // The empty language is special, and matches all languages.
366 do { 368 do {
367 const SkString& langTag = lang.getTag(); 369 const SkString& langTag = lang.getTag();
368 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) { 370 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) {
369 SkFontStyleSet_Android* family = fFallbackNameToFamilyMap[i] .styleSet; 371 SkFontStyleSet_Android* family = fFallbackNameToFamilyMap[i] .styleSet;
370 SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchSty le(style)); 372 SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchSty le(style));
371 373
372 if (!langTag.isEmpty() && langTag != face->fLang.getTag()) { 374 if (!langTag.isEmpty() && langTag != face->fLang.getTag()) {
373 continue; 375 continue;
374 } 376 }
375 377
376 if (SkToBool(face->fVariantStyle & variantMask) != maskMatch es) { 378 if (SkToBool(face->fVariantStyle & variantMask) != maskMatch es) {
377 continue; 379 continue;
378 } 380 }
379 381
380 SkPaint paint; 382 SkPaint paint;
381 paint.setTypeface(face); 383 paint.setTypeface(face);
382 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); 384 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
383 385
384 uint16_t glyphID; 386 uint16_t glyphID;
385 paint.textToGlyphs(&character, sizeof(character), &glyphID); 387 paint.textToGlyphs(&character, sizeof(character), &glyphID);
386 if (glyphID != 0) { 388 if (glyphID != 0) {
387 return face.detach(); 389 return face.detach();
388 } 390 }
389 } 391 }
392
393 // move onto the next language tag until we exhaust them and
394 // only then fall through to the default case (i.e. empty lang).
395 if (lang.getTag().isEmpty() && bcpNext < bcpLength) {
396 lang.set(bcp47[bcpNext++]);
397 }
398
390 } while (!lang.getTag().isEmpty() && (lang = lang.getParent(), true) ); 399 } while (!lang.getTag().isEmpty() && (lang = lang.getParent(), true) );
391 } 400 }
392 return NULL; 401 return NULL;
393 } 402 }
394 403
395 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE { 404 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE {
396 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data)); 405 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data));
397 return this->createFromStream(stream, ttcIndex); 406 return this->createFromStream(stream, ttcIndex);
398 } 407 }
399 408
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", 539 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s",
531 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) ); 540 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) );
532 } 541 }
533 542
534 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf , 543 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf ,
535 const char** fontsdir) { 544 const char** fontsdir) {
536 *mainconf = gTestMainConfigFile; 545 *mainconf = gTestMainConfigFile;
537 *fallbackconf = gTestFallbackConfigFile; 546 *fallbackconf = gTestFallbackConfigFile;
538 *fontsdir = gTestFontFilePrefix; 547 *fontsdir = gTestFontFilePrefix;
539 } 548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698