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

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

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Slightly more palatable. Created 5 years, 8 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 10 matching lines...) Expand all
21 #include <limits> 21 #include <limits>
22 22
23 // For test only. 23 // For test only.
24 static const char* gTestFontsXml = NULL; 24 static const char* gTestFontsXml = NULL;
25 static const char* gTestFallbackFontsXml = NULL; 25 static const char* gTestFallbackFontsXml = NULL;
26 static const char* gTestBasePath = NULL; 26 static const char* gTestBasePath = NULL;
27 27
28 class SkTypeface_Android : public SkTypeface_FreeType { 28 class SkTypeface_Android : public SkTypeface_FreeType {
29 public: 29 public:
30 SkTypeface_Android(int index, 30 SkTypeface_Android(int index,
31 const SkTArray<SkFixed, true>& axes,
31 const SkFontStyle& style, 32 const SkFontStyle& style,
32 bool isFixedPitch, 33 bool isFixedPitch,
33 const SkString& familyName) 34 const SkString& familyName)
34 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) 35 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
35 , fIndex(index) 36 , fIndex(index)
36 , fFamilyName(familyName) { } 37 , fFamilyName(familyName) { }
37 38
38 protected: 39 protected:
39 void onGetFamilyName(SkString* familyName) const override { 40 void onGetFamilyName(SkString* familyName) const override {
40 *familyName = fFamilyName; 41 *familyName = fFamilyName;
41 } 42 }
42 43
43 int fIndex; 44 int fIndex;
44 SkString fFamilyName; 45 SkString fFamilyName;
46 const SkTArray<SkFixed, true> fAxes;
45 47
46 private: 48 private:
47 typedef SkTypeface_FreeType INHERITED; 49 typedef SkTypeface_FreeType INHERITED;
48 }; 50 };
49 51
50 class SkTypeface_AndroidSystem : public SkTypeface_Android { 52 class SkTypeface_AndroidSystem : public SkTypeface_Android {
51 public: 53 public:
52 SkTypeface_AndroidSystem(const SkString& pathName, 54 SkTypeface_AndroidSystem(const SkString& pathName,
53 int index, 55 int index,
56 const SkTArray<SkFixed, true>& axes,
54 const SkFontStyle& style, 57 const SkFontStyle& style,
55 bool isFixedPitch, 58 bool isFixedPitch,
56 const SkString& familyName, 59 const SkString& familyName,
57 const SkLanguage& lang, 60 const SkLanguage& lang,
58 FontVariant variantStyle) 61 FontVariant variantStyle)
59 : INHERITED(index, style, isFixedPitch, familyName) 62 : INHERITED(index, axes, style, isFixedPitch, familyName)
60 , fPathName(pathName) 63 , fPathName(pathName)
61 , fLang(lang) 64 , fLang(lang)
62 , fVariantStyle(variantStyle) { } 65 , fVariantStyle(variantStyle) { }
63 66
64 virtual void onGetFontDescriptor(SkFontDescriptor* desc, 67 virtual void onGetFontDescriptor(SkFontDescriptor* desc,
65 bool* serialize) const override { 68 bool* serialize) const override {
66 SkASSERT(desc); 69 SkASSERT(desc);
67 SkASSERT(serialize); 70 SkASSERT(serialize);
68 desc->setFamilyName(fFamilyName.c_str()); 71 desc->setFamilyName(fFamilyName.c_str());
69 desc->setFontFileName(fPathName.c_str());
70 desc->setFontIndex(fIndex);
71 *serialize = false; 72 *serialize = false;
72 } 73 }
73 SkStreamAsset* onOpenStream(int* ttcIndex) const override { 74 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
74 *ttcIndex = fIndex; 75 *ttcIndex = fIndex;
75 return SkStream::NewFromFile(fPathName.c_str()); 76 return SkStream::NewFromFile(fPathName.c_str());
76 } 77 }
78 SkFontData* onCreateFontData() const SK_OVERRIDE {
79 return new SkFontData(SkStream::NewFromFile(fPathName.c_str()), fIndex,
80 fAxes.count(), fAxes.begin());
81 }
77 82
78 const SkString fPathName; 83 const SkString fPathName;
79 const SkLanguage fLang; 84 const SkLanguage fLang;
80 const FontVariant fVariantStyle; 85 const FontVariant fVariantStyle;
81 86
82 typedef SkTypeface_Android INHERITED; 87 typedef SkTypeface_Android INHERITED;
83 }; 88 };
84 89
85 class SkTypeface_AndroidStream : public SkTypeface_Android { 90 class SkTypeface_AndroidStream : public SkTypeface_Android {
86 public: 91 public:
87 SkTypeface_AndroidStream(SkStreamAsset* stream, 92 SkTypeface_AndroidStream(SkStreamAsset* stream,
88 int index, 93 int index,
94 const SkTArray<SkFixed, true>& axes,
89 const SkFontStyle& style, 95 const SkFontStyle& style,
90 bool isFixedPitch, 96 bool isFixedPitch,
91 const SkString& familyName) 97 const SkString& familyName)
92 : INHERITED(index, style, isFixedPitch, familyName) 98 : INHERITED(index, axes, style, isFixedPitch, familyName)
93 , fStream(stream) { } 99 , fStream(stream) { }
94 100
95 virtual void onGetFontDescriptor(SkFontDescriptor* desc, 101 virtual void onGetFontDescriptor(SkFontDescriptor* desc,
96 bool* serialize) const override { 102 bool* serialize) const override {
97 SkASSERT(desc); 103 SkASSERT(desc);
98 SkASSERT(serialize); 104 SkASSERT(serialize);
99 desc->setFamilyName(fFamilyName.c_str()); 105 desc->setFamilyName(fFamilyName.c_str());
100 desc->setFontFileName(NULL);
101 *serialize = true; 106 *serialize = true;
102 } 107 }
103 108
104 SkStreamAsset* onOpenStream(int* ttcIndex) const override { 109 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
105 *ttcIndex = fIndex; 110 *ttcIndex = fIndex;
106 return fStream->duplicate(); 111 return fStream->duplicate();
107 } 112 }
108 113
114 SkFontData* onCreateFontData() const SK_OVERRIDE {
115 return new SkFontData(fStream->duplicate(), fIndex, fAxes.count(), fAxes .begin());
116 }
117
109 private: 118 private:
110 SkAutoTDelete<SkStreamAsset> fStream; 119 SkAutoTDelete<SkStreamAsset> fStream;
111 120
112 typedef SkTypeface_Android INHERITED; 121 typedef SkTypeface_Android INHERITED;
113 }; 122 };
114 123
115 class SkFontStyleSet_Android : public SkFontStyleSet { 124 class SkFontStyleSet_Android : public SkFontStyleSet {
116 public: 125 public:
117 explicit SkFontStyleSet_Android(const FontFamily& family, 126 explicit SkFontStyleSet_Android(const FontFamily& family,
118 const SkTypeface_FreeType::Scanner& scanner) 127 const SkTypeface_FreeType::Scanner& scanner)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 165 }
157 166
158 // The first specified family name overrides the family name found i n the font. 167 // The first specified family name overrides the family name found i n the font.
159 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should return 168 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should return
160 // all of the specified family names in addition to the names found in the font. 169 // all of the specified family names in addition to the names found in the font.
161 if (cannonicalFamilyName != NULL) { 170 if (cannonicalFamilyName != NULL) {
162 familyName = *cannonicalFamilyName; 171 familyName = *cannonicalFamilyName;
163 } 172 }
164 173
165 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, 174 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem,
166 (pathName, ttcIndex, 175 (pathName, ttcIndex, fontFile.f Axes,
167 style, isFixedWidth, familyNam e, 176 style, isFixedWidth, familyNam e,
168 lang, variant))); 177 lang, variant)));
169 } 178 }
170 } 179 }
171 180
172 int count() override { 181 int count() override {
173 return fStyles.count(); 182 return fStyles.count();
174 } 183 }
175 void getStyle(int index, SkFontStyle* style, SkString* name) override { 184 void getStyle(int index, SkFontStyle* style, SkString* name) override {
176 if (index < 0 || fStyles.count() <= index) { 185 if (index < 0 || fStyles.count() <= index) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 412 }
404 413
405 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override { 414 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override {
406 SkAutoTDelete<SkStreamAsset> stream(bareStream); 415 SkAutoTDelete<SkStreamAsset> stream(bareStream);
407 bool isFixedPitch; 416 bool isFixedPitch;
408 SkFontStyle style; 417 SkFontStyle style;
409 SkString name; 418 SkString name;
410 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) { 419 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
411 return NULL; 420 return NULL;
412 } 421 }
413 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), ttcIndex, 422 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), ttcIndex, SkTArray<SkFixed, true>(),
414 style, isFixedPitch, name)) ; 423 style, isFixedPitch, name)) ;
415 } 424 }
416 425
426 SkTypeface* onCreateFromFontData(SkFontData* data) const SK_OVERRIDE {
427 SkAutoTDelete<SkStreamAsset> stream(data->transferStream());
428 bool isFixedPitch;
429 SkFontStyle style;
430 SkString name;
431 if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixed Pitch)) {
432 return NULL;
433 }
434 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), data->getI ndex(),
435 SkTArray<SkFixed, true>(dat a->getAxis(), data->getAxisCount()),
436 style, isFixedPitch, name)) ;
437 }
438
417 439
418 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 440 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
419 unsigned styleBits) const overrid e { 441 unsigned styleBits) const overrid e {
420 SkFontStyle style = SkFontStyle(styleBits); 442 SkFontStyle style = SkFontStyle(styleBits);
421 443
422 if (familyName) { 444 if (familyName) {
423 // On Android, we must return NULL when we can't find the requested 445 // On Android, we must return NULL when we can't find the requested
424 // named typeface so that the system/app can provide their own recov ery 446 // named typeface so that the system/app can provide their own recov ery
425 // mechanism. On other platforms we'd provide a typeface from the 447 // mechanism. On other platforms we'd provide a typeface from the
426 // default family instead. 448 // default family instead.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 { 562 {
541 gTestFontsXml = fontsXml; 563 gTestFontsXml = fontsXml;
542 gTestFallbackFontsXml = fallbackFontsXml; 564 gTestFallbackFontsXml = fallbackFontsXml;
543 gTestBasePath = basePath; 565 gTestBasePath = basePath;
544 SkASSERT(gTestFontsXml); 566 SkASSERT(gTestFontsXml);
545 SkASSERT(gTestFallbackFontsXml); 567 SkASSERT(gTestFallbackFontsXml);
546 SkASSERT(gTestBasePath); 568 SkASSERT(gTestBasePath);
547 SkDEBUGF(("Test BasePath: %s Fonts: %s FallbackFonts: %s\n", 569 SkDEBUGF(("Test BasePath: %s Fonts: %s FallbackFonts: %s\n",
548 gTestBasePath, gTestFontsXml, gTestFallbackFontsXml)); 570 gTestBasePath, gTestFontsXml, gTestFallbackFontsXml));
549 } 571 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698