| Index: src/ports/SkFontMgr_android.cpp
|
| diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
|
| index ae1b663e261dd30a976fbed417e09d033c92bee7..9edea62066b0e07cb684daa4eb4eb365098e0d28 100644
|
| --- a/src/ports/SkFontMgr_android.cpp
|
| +++ b/src/ports/SkFontMgr_android.cpp
|
| @@ -28,12 +28,15 @@ static const char* gTestBasePath = NULL;
|
| class SkTypeface_Android : public SkTypeface_FreeType {
|
| public:
|
| SkTypeface_Android(int index,
|
| + const SkFixed* axes, int axesCount,
|
| const SkFontStyle& style,
|
| bool isFixedPitch,
|
| const SkString& familyName)
|
| : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
|
| , fIndex(index)
|
| - , fFamilyName(familyName) { }
|
| + , fFamilyName(familyName)
|
| + , fAxes(axes, axesCount)
|
| + { }
|
|
|
| protected:
|
| void onGetFamilyName(SkString* familyName) const override {
|
| @@ -42,6 +45,7 @@ protected:
|
|
|
| int fIndex;
|
| SkString fFamilyName;
|
| + const SkSTArray<4, SkFixed, true> fAxes;
|
|
|
| private:
|
| typedef SkTypeface_FreeType INHERITED;
|
| @@ -51,12 +55,13 @@ class SkTypeface_AndroidSystem : public SkTypeface_Android {
|
| public:
|
| SkTypeface_AndroidSystem(const SkString& pathName,
|
| int index,
|
| + const SkFixed* axes, int axesCount,
|
| const SkFontStyle& style,
|
| bool isFixedPitch,
|
| const SkString& familyName,
|
| const SkLanguage& lang,
|
| FontVariant variantStyle)
|
| - : INHERITED(index, style, isFixedPitch, familyName)
|
| + : INHERITED(index, axes, axesCount, style, isFixedPitch, familyName)
|
| , fPathName(pathName)
|
| , fLang(lang)
|
| , fVariantStyle(variantStyle) { }
|
| @@ -66,13 +71,16 @@ public:
|
| SkASSERT(desc);
|
| SkASSERT(serialize);
|
| desc->setFamilyName(fFamilyName.c_str());
|
| - desc->setFontIndex(fIndex);
|
| *serialize = false;
|
| }
|
| SkStreamAsset* onOpenStream(int* ttcIndex) const override {
|
| *ttcIndex = fIndex;
|
| return SkStream::NewFromFile(fPathName.c_str());
|
| }
|
| + SkFontData* onCreateFontData() const override {
|
| + return new SkFontData(SkStream::NewFromFile(fPathName.c_str()), fIndex,
|
| + fAxes.count(), fAxes.begin());
|
| + }
|
|
|
| const SkString fPathName;
|
| const SkLanguage fLang;
|
| @@ -85,10 +93,11 @@ class SkTypeface_AndroidStream : public SkTypeface_Android {
|
| public:
|
| SkTypeface_AndroidStream(SkStreamAsset* stream,
|
| int index,
|
| + const SkFixed* axes, int axesCount,
|
| const SkFontStyle& style,
|
| bool isFixedPitch,
|
| const SkString& familyName)
|
| - : INHERITED(index, style, isFixedPitch, familyName)
|
| + : INHERITED(index, axes, axesCount, style, isFixedPitch, familyName)
|
| , fStream(stream) { }
|
|
|
| virtual void onGetFontDescriptor(SkFontDescriptor* desc,
|
| @@ -104,6 +113,10 @@ public:
|
| return fStream->duplicate();
|
| }
|
|
|
| + SkFontData* onCreateFontData() const override {
|
| + return new SkFontData(fStream->duplicate(), fIndex, fAxes.count(), fAxes.begin());
|
| + }
|
| +
|
| private:
|
| SkAutoTDelete<SkStreamAsset> fStream;
|
|
|
| @@ -111,10 +124,10 @@ private:
|
| };
|
|
|
| class SkFontStyleSet_Android : public SkFontStyleSet {
|
| + typedef SkTypeface_FreeType::Scanner Scanner;
|
| +
|
| public:
|
| - explicit SkFontStyleSet_Android(const FontFamily& family,
|
| - const SkTypeface_FreeType::Scanner& scanner)
|
| - {
|
| + explicit SkFontStyleSet_Android(const FontFamily& family, const Scanner& scanner) {
|
| const SkString* cannonicalFamilyName = NULL;
|
| if (family.fNames.count() > 0) {
|
| cannonicalFamilyName = &family.fNames[0];
|
| @@ -137,7 +150,10 @@ public:
|
| SkString familyName;
|
| SkFontStyle style;
|
| bool isFixedWidth;
|
| - if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, &isFixedWidth)) {
|
| + Scanner::AxisDefinitions axisDefinitions;
|
| + if (!scanner.scanFont(stream.get(), ttcIndex,
|
| + &familyName, &style, &isFixedWidth, &axisDefinitions))
|
| + {
|
| SkDEBUGF(("Requested font file %s exists, but is not a valid font.\n",
|
| pathName.c_str()));
|
| continue;
|
| @@ -166,8 +182,57 @@ public:
|
| familyName = *cannonicalFamilyName;
|
| }
|
|
|
| + SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
|
| + for (int i = 0; i < axisDefinitions.count(); ++i) {
|
| + const Scanner::AxisDefinition& axisDefinition = axisDefinitions[i];
|
| + axisValues[i] = axisDefinition.fDefault;
|
| + for (int j = 0; j < fontFile.fAxes.count(); ++j) {
|
| + const FontFileInfo::Axis& axisSpecified = fontFile.fAxes[j];
|
| + if (axisDefinition.fTag == axisSpecified.fTag) {
|
| + axisValues[i] = SkTPin(axisSpecified.fValue, axisDefinition.fMinimum,
|
| + axisDefinition.fMaximum);
|
| + if (axisValues[i] != axisSpecified.fValue) {
|
| + SkDEBUGF(("Requested font axis value out of range: "
|
| + "%s '%c%c%c%c' %f; pinned to %f.\n",
|
| + familyName.c_str(),
|
| + (axisDefinition.fTag >> 24) & 0xFF,
|
| + (axisDefinition.fTag >> 16) & 0xFF,
|
| + (axisDefinition.fTag >> 8) & 0xFF,
|
| + (axisDefinition.fTag ) & 0xFF,
|
| + SkFixedToDouble(axisSpecified.fValue),
|
| + SkFixedToDouble(axisValues[i])));
|
| + }
|
| + break;
|
| + }
|
| + }
|
| + // TODO: warn on defaulted axis?
|
| + }
|
| +
|
| + 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;
|
| + }
|
| + }
|
| + 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(SkNEW_ARGS(SkTypeface_AndroidSystem,
|
| (pathName, ttcIndex,
|
| + axisValues.get(), axisDefinitions.count(),
|
| style, isFixedWidth, familyName,
|
| lang, variant)));
|
| }
|
| @@ -411,10 +476,23 @@ protected:
|
| bool isFixedPitch;
|
| SkFontStyle style;
|
| SkString name;
|
| - if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
|
| + if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, NULL)) {
|
| + return NULL;
|
| + }
|
| + return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), ttcIndex, NULL, 0,
|
| + style, isFixedPitch, name));
|
| + }
|
| +
|
| + SkTypeface* onCreateFromFontData(SkFontData* data) const override {
|
| + SkAutoTDelete<SkStreamAsset> stream(data->detachStream());
|
| + bool isFixedPitch;
|
| + SkFontStyle style;
|
| + SkString name;
|
| + if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, NULL)) {
|
| return NULL;
|
| }
|
| - return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), ttcIndex,
|
| + return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), data->getIndex(),
|
| + data->getAxis(), data->getAxisCount(),
|
| style, isFixedPitch, name));
|
| }
|
|
|
|
|