aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkFontMgr_fontconfig.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2015-05-20 09:21:04 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-20 09:21:04 -0700
commit41868fe5625fc3bd70daa3f461c881b5db6a9265 (patch)
tree6f6d670bbf415a70c152b0a6332a0428fb0d77b4 /src/ports/SkFontMgr_fontconfig.cpp
parentd223eb36a0be2bb5a278a483d6289a16b28eaf1a (diff)
Font variations.
Multiple Master and TrueType fonts support variation axes. This implements back-end support for axes on platforms which support it. Committed: https://skia.googlesource.com/skia/+/05773ed30920c0214d1433c07cf6360a05476c97 Committed: https://skia.googlesource.com/skia/+/3489ee0f4fa34f124f9de090d12bdc2107d52aa9 Review URL: https://codereview.chromium.org/1027373002
Diffstat (limited to 'src/ports/SkFontMgr_fontconfig.cpp')
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index f03e5acaf1..3baec41cb5 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -375,11 +375,10 @@ 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)
+ /** @param data takes ownership of the font data.*/
+ SkTypeface_stream(SkFontData* data, const SkFontStyle& style, bool fixedWidth)
: INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
- , fStream(stream)
- , fIndex(index)
+ , fData(data)
{ };
void onGetFamilyName(SkString* familyName) const override {
@@ -387,18 +386,20 @@ public:
}
void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override {
- desc->setFontIndex(fIndex);
*serialize = true;
}
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
- *ttcIndex = fIndex;
- return fStream->duplicate();
+ *ttcIndex = fData->getIndex();
+ return fData->duplicateStream();
+ }
+
+ SkFontData* onCreateFontData() const override {
+ return new SkFontData(*fData.get());
}
private:
- SkAutoTDelete<SkStreamAsset> fStream;
- int fIndex;
+ const SkAutoTDelete<const SkFontData> fData;
typedef SkTypeface_FreeType INHERITED;
};
@@ -420,7 +421,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 +822,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, (new SkFontData(stream.detach(), ttcIndex, NULL, 0),
+ style, isFixedWidth));
}
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
@@ -838,6 +838,23 @@ protected:
return this->createFromStream(SkStream::NewFromFile(path), ttcIndex);
}
+ SkTypeface* onCreateFromFontData(SkFontData* fontData) const override {
+ SkStreamAsset* stream(fontData->getStream());
+ 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, (fontData, style, isFixedWidth));
+ }
+
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
unsigned styleBits) const override {
bool bold = styleBits & SkTypeface::kBold;