diff options
author | 2016-01-21 14:17:47 -0800 | |
---|---|---|
committer | 2016-01-21 14:17:47 -0800 | |
commit | f6c7107d0385cc2b556802354b93b7dcff61570d (patch) | |
tree | 6acc6e0ae4621e2bbc6deb43c3198a73c5d56433 /src/ports/SkFontMgr_android.cpp | |
parent | 27a6e86fb17fce7ce962b9080eae36926e87d568 (diff) |
Expose API for gx font variation axes.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1590223003
Review URL: https://codereview.chromium.org/1590223003
Diffstat (limited to 'src/ports/SkFontMgr_android.cpp')
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 11244c55ee..afa7873454 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -6,7 +6,6 @@ */ #include "SkTypes.h" -#if defined(SK_BUILD_FOR_ANDROID) #include "SkFixed.h" #include "SkFontDescriptor.h" @@ -208,26 +207,27 @@ public: } SkDEBUGCODE( - // Check for axis specified, but not matched in font. - for (int i = 0; i < fontFile.fAxes.count(); ++i) { - SkFourByteTag skTag = fontFile.fAxes[i].fTag; - bool found = false; - for (int j = 0; j < axisDefinitions.count(); ++j) { - if (skTag == axisDefinitions[j].fTag) { - found = true; - break; - } + // Check for axis specified, but not matched in font. + for (int i = 0; i < fontFile.fAxes.count(); ++i) { + SkFourByteTag skTag = fontFile.fAxes[i].fTag; + bool found = false; + for (int j = 0; j < axisDefinitions.count(); ++j) { + if (skTag == axisDefinitions[j].fTag) { + found = true; + break; } - if (!found) { - SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", - familyName.c_str(), (skTag >> 24) & 0xFF, - (skTag >> 16) & 0xFF, (skTag >> 8) & 0xFF, (skTag)&0xFF)); - } - }) + } + if (!found) { + SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", + familyName.c_str(), (skTag >> 24) & 0xFF, + (skTag >> 16) & 0xFF, (skTag >> 8) & 0xFF, (skTag)&0xFF)); + } + } + ) - fStyles.push_back().reset(new SkTypeface_AndroidSystem( - pathName, ttcIndex, axisValues.get(), axisDefinitions.count(), style, - isFixedWidth, familyName, lang, variant)); + fStyles.push_back().reset(new SkTypeface_AndroidSystem( + pathName, ttcIndex, axisValues.get(), axisDefinitions.count(), style, + isFixedWidth, familyName, lang, variant)); } } @@ -476,6 +476,29 @@ protected: return new SkTypeface_AndroidStream(data, style, isFixedPitch, name); } + SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override { + using Scanner = SkTypeface_FreeType::Scanner; + SkAutoTDelete<SkStreamAsset> stream(s); + bool isFixedPitch; + SkFontStyle style; + SkString name; + Scanner::AxisDefinitions axisDefinitions; + if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &style, &isFixedPitch, + &axisDefinitions)) + { + return nullptr; + } + + int paramAxisCount; + const FontParameters::Axis* paramAxes = params.getAxes(¶mAxisCount); + SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count()); + Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name); + + SkFontData* data(new SkFontData(stream.detach(), params.getCollectionIndex(), + axisValues.get(), axisDefinitions.count())); + return new SkTypeface_AndroidStream(data, style, isFixedPitch, name); + } + SkTypeface* onCreateFromFontData(SkFontData* data) const override { SkStreamAsset* stream(data->getStream()); bool isFixedPitch; @@ -589,5 +612,3 @@ SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { return new SkFontMgr_Android(custom); } - -#endif//defined(SK_BUILD_FOR_ANDROID) |