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

Unified Diff: src/ports/SkFontMgr_fontconfig.cpp

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Android and tests. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/ports/SkFontMgr_fontconfig.cpp
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index f03e5acaf1382d50fc6ababd4d682f7cabacd632..a242d20021671eaf1ff9bf668ddb7ef7ffa914be 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -376,10 +376,12 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) {
class SkTypeface_stream : public SkTypeface_FreeType {
public:
/** @param stream does not take ownership of the reference, does take ownership of the stream.*/
- SkTypeface_stream(const SkFontStyle& style, bool fixedWidth, int index, SkStreamAsset* stream)
+ SkTypeface_stream(SkStreamAsset* stream, int index, const SkFixed* axes, int axesCount,
+ const SkFontStyle& style, bool fixedWidth)
: INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
, fStream(stream)
, fIndex(index)
+ , fAxes(axes, axesCount)
{ };
void onGetFamilyName(SkString* familyName) const override {
@@ -387,7 +389,6 @@ public:
}
void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override {
- desc->setFontIndex(fIndex);
*serialize = true;
}
@@ -396,9 +397,14 @@ public:
return fStream->duplicate();
}
+ SkFontData* onCreateFontData() const override {
+ return new SkFontData(fStream->duplicate(), fIndex, fAxes.count(), fAxes.begin());
+ }
+
private:
- SkAutoTDelete<SkStreamAsset> fStream;
- int fIndex;
+ const SkAutoTDelete<const SkStreamAsset> fStream;
+ const int fIndex;
+ const SkSTArray<4, SkFixed, true> fAxes;
typedef SkTypeface_FreeType INHERITED;
};
@@ -420,7 +426,6 @@ public:
desc->setFamilyName(get_string(fPattern, FC_FAMILY));
desc->setFullName(get_string(fPattern, FC_FULLNAME));
desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME));
- desc->setFontIndex(get_int(fPattern, FC_INDEX, 0));
*serialize = false;
}
@@ -822,12 +827,12 @@ protected:
SkFontStyle style;
bool isFixedWidth = false;
- if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth)) {
+ if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NULL)) {
return NULL;
}
- return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex,
- static_cast<SkStreamAsset*>(stream.detach())));
+ return SkNEW_ARGS(SkTypeface_stream, (stream.detach(), ttcIndex, NULL, 0,
+ style, isFixedWidth));
}
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
@@ -838,6 +843,25 @@ protected:
return this->createFromStream(SkStream::NewFromFile(path), ttcIndex);
}
+ SkTypeface* onCreateFromFontData(SkFontData* fontData) const override {
+ SkAutoTDelete<SkStreamAsset> stream(fontData->detachStream());
+ const size_t length = stream->getLength();
+ if (length <= 0 || (1u << 30) < length) {
+ return NULL;
+ }
+
+ const int ttcIndex = fontData->getIndex();
+ SkFontStyle style;
+ bool isFixedWidth = false;
+ if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NULL)) {
+ return NULL;
+ }
+
+ return SkNEW_ARGS(SkTypeface_stream, (stream.detach(), ttcIndex,
+ fontData->getAxis(), fontData->getAxisCount(),
+ style, isFixedWidth));
+ }
+
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
unsigned styleBits) const override {
bool bold = styleBits & SkTypeface::kBold;

Powered by Google App Engine
This is Rietveld 408576698