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

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

Issue 1590223003: Expose API for gx font variation axes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix FontConfig and Android. Created 4 years, 11 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 | « src/ports/SkFontHost_mac.cpp ('k') | src/ports/SkFontMgr_fontconfig.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 "SkTypes.h" 8 #include "SkTypes.h"
9 #if defined(SK_BUILD_FOR_ANDROID)
10 9
11 #include "SkFixed.h" 10 #include "SkFixed.h"
12 #include "SkFontDescriptor.h" 11 #include "SkFontDescriptor.h"
13 #include "SkFontHost_FreeType_common.h" 12 #include "SkFontHost_FreeType_common.h"
14 #include "SkFontMgr.h" 13 #include "SkFontMgr.h"
15 #include "SkFontMgr_android.h" 14 #include "SkFontMgr_android.h"
16 #include "SkFontMgr_android_parser.h" 15 #include "SkFontMgr_android_parser.h"
17 #include "SkFontStyle.h" 16 #include "SkFontStyle.h"
18 #include "SkPaint.h" 17 #include "SkPaint.h"
19 #include "SkRefCnt.h" 18 #include "SkRefCnt.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 SkFixedToDouble(axisSpecified.fValue), 200 SkFixedToDouble(axisSpecified.fValue),
202 SkFixedToDouble(axisValues[i]))); 201 SkFixedToDouble(axisValues[i])));
203 } 202 }
204 break; 203 break;
205 } 204 }
206 } 205 }
207 // TODO: warn on defaulted axis? 206 // TODO: warn on defaulted axis?
208 } 207 }
209 208
210 SkDEBUGCODE( 209 SkDEBUGCODE(
211 // Check for axis specified, but not matched in font. 210 // Check for axis specified, but not matched in font.
212 for (int i = 0; i < fontFile.fAxes.count(); ++i) { 211 for (int i = 0; i < fontFile.fAxes.count(); ++i) {
213 SkFourByteTag skTag = fontFile.fAxes[i].fTag; 212 SkFourByteTag skTag = fontFile.fAxes[i].fTag;
214 bool found = false; 213 bool found = false;
215 for (int j = 0; j < axisDefinitions.count(); ++j) { 214 for (int j = 0; j < axisDefinitions.count(); ++j) {
216 if (skTag == axisDefinitions[j].fTag) { 215 if (skTag == axisDefinitions[j].fTag) {
217 found = true; 216 found = true;
218 break; 217 break;
219 }
220 } 218 }
221 if (!found) { 219 }
222 SkDEBUGF(("Requested font axis not found: %s '%c%c%c %c'\n", 220 if (!found) {
223 familyName.c_str(), (skTag >> 24) & 0xFF, 221 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\ n",
224 (skTag >> 16) & 0xFF, (skTag >> 8) & 0xFF, (skTag)&0xFF)); 222 familyName.c_str(), (skTag >> 24) & 0xFF,
225 } 223 (skTag >> 16) & 0xFF, (skTag >> 8) & 0xFF, ( skTag)&0xFF));
226 }) 224 }
225 }
226 )
227 227
228 fStyles.push_back().reset(new SkTypeface_AndroidSystem( 228 fStyles.push_back().reset(new SkTypeface_AndroidSystem(
229 pathName, ttcIndex, axisValues.get(), axisDefinition s.count(), style, 229 pathName, ttcIndex, axisValues.get(), axisDefinitions.count( ), style,
230 isFixedWidth, familyName, lang, variant)); 230 isFixedWidth, familyName, lang, variant));
231 } 231 }
232 } 232 }
233 233
234 int count() override { 234 int count() override {
235 return fStyles.count(); 235 return fStyles.count();
236 } 236 }
237 void getStyle(int index, SkFontStyle* style, SkString* name) override { 237 void getStyle(int index, SkFontStyle* style, SkString* name) override {
238 if (index < 0 || fStyles.count() <= index) { 238 if (index < 0 || fStyles.count() <= index) {
239 return; 239 return;
240 } 240 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 bool isFixedPitch; 469 bool isFixedPitch;
470 SkFontStyle style; 470 SkFontStyle style;
471 SkString name; 471 SkString name;
472 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, n ullptr)) { 472 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, n ullptr)) {
473 return nullptr; 473 return nullptr;
474 } 474 }
475 SkFontData* data(new SkFontData(stream.detach(), ttcIndex, nullptr, 0)); 475 SkFontData* data(new SkFontData(stream.detach(), ttcIndex, nullptr, 0));
476 return new SkTypeface_AndroidStream(data, style, isFixedPitch, name); 476 return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
477 } 477 }
478 478
479 SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param s) const override {
480 using Scanner = SkTypeface_FreeType::Scanner;
481 SkAutoTDelete<SkStreamAsset> stream(s);
482 bool isFixedPitch;
483 SkFontStyle style;
484 SkString name;
485 Scanner::AxisDefinitions axisDefinitions;
486 if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &styl e, &isFixedPitch,
487 &axisDefinitions))
488 {
489 return nullptr;
490 }
491
492 int paramAxisCount;
493 const FontParameters::Axis* paramAxes = params.getAxes(&paramAxisCount);
494 SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
495 Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, a xisValues, name);
496
497 SkFontData* data(new SkFontData(stream.detach(), params.getCollectionInd ex(),
498 axisValues.get(), axisDefinitions.count( )));
499 return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
500 }
501
479 SkTypeface* onCreateFromFontData(SkFontData* data) const override { 502 SkTypeface* onCreateFromFontData(SkFontData* data) const override {
480 SkStreamAsset* stream(data->getStream()); 503 SkStreamAsset* stream(data->getStream());
481 bool isFixedPitch; 504 bool isFixedPitch;
482 SkFontStyle style; 505 SkFontStyle style;
483 SkString name; 506 SkString name;
484 if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixed Pitch, nullptr)) { 507 if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixed Pitch, nullptr)) {
485 return nullptr; 508 return nullptr;
486 } 509 }
487 return new SkTypeface_AndroidStream(data, style, isFixedPitch, name); 510 return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
488 } 511 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings)) ; 605 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings)) ;
583 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n" , 606 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n" ,
584 gSystemFontUseStrings[custom->fSystemFontUse], 607 gSystemFontUseStrings[custom->fSystemFontUse],
585 custom->fBasePath, 608 custom->fBasePath,
586 custom->fFontsXml, 609 custom->fFontsXml,
587 custom->fFallbackFontsXml)); 610 custom->fFallbackFontsXml));
588 } 611 }
589 612
590 return new SkFontMgr_Android(custom); 613 return new SkFontMgr_Android(custom);
591 } 614 }
592
593 #endif//defined(SK_BUILD_FOR_ANDROID)
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_mac.cpp ('k') | src/ports/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698