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

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

Issue 1190993002: Move Android SkFontMgr::Factory to its own file. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « include/ports/SkTypeface_android.h ('k') | src/ports/SkFontMgr_android_factory.cpp » ('j') | 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 * 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"
11 #include "SkFontMgr.h" 11 #include "SkFontMgr.h"
12 #include "SkFontMgr_android.h" 12 #include "SkFontMgr_android.h"
13 #include "SkFontStyle.h" 13 #include "SkFontStyle.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 #include "SkTDArray.h" 15 #include "SkTDArray.h"
16 #include "SkTSearch.h" 16 #include "SkTSearch.h"
17 #include "SkTypeface.h" 17 #include "SkTypeface.h"
18 #include "SkTypeface_android.h"
19 #include "SkTypefaceCache.h" 18 #include "SkTypefaceCache.h"
20 19
21 #include <limits> 20 #include <limits>
22 21
23 // For test only.
24 static const char* gTestFontsXml = NULL;
25 static const char* gTestFallbackFontsXml = NULL;
26 static const char* gTestBasePath = NULL;
27
28 class SkTypeface_Android : public SkTypeface_FreeType { 22 class SkTypeface_Android : public SkTypeface_FreeType {
29 public: 23 public:
30 SkTypeface_Android(const SkFontStyle& style, 24 SkTypeface_Android(const SkFontStyle& style,
31 bool isFixedPitch, 25 bool isFixedPitch,
32 const SkString& familyName) 26 const SkString& familyName)
33 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) 27 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
34 , fFamilyName(familyName) 28 , fFamilyName(familyName)
35 { } 29 { }
36 30
37 protected: 31 protected:
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 fDefaultFamily = fFontStyleSets[0]; 561 fDefaultFamily = fFontStyleSets[0];
568 fDefaultTypeface = fDefaultFamily->createTypeface(0); 562 fDefaultTypeface = fDefaultFamily->createTypeface(0);
569 } 563 }
570 SkASSERT(fDefaultFamily); 564 SkASSERT(fDefaultFamily);
571 SkASSERT(fDefaultTypeface); 565 SkASSERT(fDefaultTypeface);
572 } 566 }
573 567
574 typedef SkFontMgr INHERITED; 568 typedef SkFontMgr INHERITED;
575 }; 569 };
576 570
577 ///////////////////////////////////////////////////////////////////////////////
578 #ifdef SK_DEBUG 571 #ifdef SK_DEBUG
579 static char const * const gSystemFontUseStrings[] = { 572 static char const * const gSystemFontUseStrings[] = {
580 "OnlyCustom", "PreferCustom", "PreferSystem" 573 "OnlyCustom", "PreferCustom", "PreferSystem"
581 }; 574 };
582 #endif 575 #endif
583 SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { 576 SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) {
584 if (custom) { 577 if (custom) {
585 SkASSERT(0 <= custom->fSystemFontUse); 578 SkASSERT(0 <= custom->fSystemFontUse);
586 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings)) ; 579 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings)) ;
587 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n" , 580 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n" ,
588 gSystemFontUseStrings[custom->fSystemFontUse], 581 gSystemFontUseStrings[custom->fSystemFontUse],
589 custom->fBasePath, 582 custom->fBasePath,
590 custom->fFontsXml, 583 custom->fFontsXml,
591 custom->fFallbackFontsXml)); 584 custom->fFallbackFontsXml));
592 } 585 }
593 586
594 return SkNEW_ARGS(SkFontMgr_Android, (custom)); 587 return SkNEW_ARGS(SkFontMgr_Android, (custom));
595 } 588 }
596
597 SkFontMgr* SkFontMgr::Factory() {
598 // These globals exist so that Chromium can override the environment.
599 // TODO: these globals need to be removed, and Chromium use SkFontMgr_New_An droid instead.
600 if ((gTestFontsXml || gTestFallbackFontsXml) && gTestBasePath) {
601 SkFontMgr_Android_CustomFonts custom = {
602 SkFontMgr_Android_CustomFonts::kOnlyCustom,
603 gTestBasePath,
604 gTestFontsXml,
605 gTestFallbackFontsXml
606 };
607 return SkFontMgr_New_Android(&custom);
608 }
609
610 return SkFontMgr_New_Android(NULL);
611 }
612
613 void SkUseTestFontConfigFile(const char* fontsXml, const char* fallbackFontsXml,
614 const char* basePath)
615 {
616 gTestFontsXml = fontsXml;
617 gTestFallbackFontsXml = fallbackFontsXml;
618 gTestBasePath = basePath;
619 SkASSERT(gTestFontsXml);
620 SkASSERT(gTestFallbackFontsXml);
621 SkASSERT(gTestBasePath);
622 SkDEBUGF(("Test BasePath: %s Fonts: %s FallbackFonts: %s\n",
623 gTestBasePath, gTestFontsXml, gTestFallbackFontsXml));
624 }
OLDNEW
« no previous file with comments | « include/ports/SkTypeface_android.h ('k') | src/ports/SkFontMgr_android_factory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698