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

Unified Diff: src/ports/SkFontMgr_custom.cpp

Issue 2053903003: Implement all onCreateFromStream overloads. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontMgr_custom.cpp
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index ed5e58dd332b2cf814aa98e69808989225c604e0..200173d987a4cf5030fcab2c188d1e640834eb70 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -21,6 +21,7 @@
#include "SkTypes.h"
#include <limits>
+#include <memory>
class SkData;
@@ -72,20 +73,25 @@ private:
/** The stream SkTypeface implementation for the custom font manager. */
class SkTypeface_Stream : public SkTypeface_Custom {
public:
- SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
- const SkString familyName, SkStreamAsset* stream, int index)
- : INHERITED(style, isFixedPitch, sysFont, familyName, index)
- , fStream(stream)
+ SkTypeface_Stream(std::unique_ptr<SkFontData> fontData,
+ const SkFontStyle& style, bool isFixedPitch, bool sysFont,
+ const SkString familyName)
+ : INHERITED(style, isFixedPitch, sysFont, familyName, fontData->getIndex())
+ , fData(std::move(fontData))
{ }
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
- *ttcIndex = this->getIndex();
- return fStream->duplicate();
+ *ttcIndex = fData->getIndex();
+ return fData->duplicateStream();
+ }
+
+ SkFontData* onCreateFontData() const override {
+ return new SkFontData(*fData.get());
}
private:
- const SkAutoTDelete<const SkStreamAsset> fStream;
+ std::unique_ptr<const SkFontData> fData;
typedef SkTypeface_Custom INHERITED;
};
@@ -123,8 +129,8 @@ public:
explicit SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(familyName) { }
/** Should only be called during the inital build phase. */
- void appendTypeface(SkTypeface_Custom* typeface) {
- fStyles.push_back().reset(typeface);
+ void appendTypeface(sk_sp<SkTypeface_Custom> typeface) {
+ fStyles.emplace_back(std::move(typeface));
}
int count() override {
@@ -153,7 +159,7 @@ public:
SkString getFamilyName() { return fFamilyName; }
private:
- SkTArray<SkAutoTUnref<SkTypeface_Custom>, true> fStyles;
+ SkTArray<sk_sp<SkTypeface_Custom>> fStyles;
SkString fFamilyName;
friend class SkFontMgr_Custom;
@@ -168,7 +174,7 @@ private:
*/
class SkFontMgr_Custom : public SkFontMgr {
public:
- typedef SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> Families;
+ typedef SkTArray<sk_sp<SkFontStyleSet_Custom>> Families;
class SystemFontLoader {
public:
virtual ~SystemFontLoader() { }
@@ -182,23 +188,23 @@ public:
"Arial", "Verdana", "Times New Roman", "Droid Sans", nullptr
};
for (size_t i = 0; i < SK_ARRAY_COUNT(defaultNames); ++i) {
- SkFontStyleSet_Custom* set = this->onMatchFamily(defaultNames[i]);
+ sk_sp<SkFontStyleSet_Custom> set(this->onMatchFamily(defaultNames[i]));
if (nullptr == set) {
continue;
}
- SkTypeface* tf = set->matchStyle(SkFontStyle(SkFontStyle::kNormal_Weight,
- SkFontStyle::kNormal_Width,
- SkFontStyle::kUpright_Slant));
+ sk_sp<SkTypeface> tf(set->matchStyle(SkFontStyle(SkFontStyle::kNormal_Weight,
+ SkFontStyle::kNormal_Width,
+ SkFontStyle::kUpright_Slant)));
if (nullptr == tf) {
continue;
}
- fDefaultFamily = set;
+ fDefaultFamily = set.get();
break;
}
if (nullptr == fDefaultFamily) {
- fDefaultFamily = fFamilies[0];
+ fDefaultFamily = fFamilies[0].get();
}
}
@@ -245,7 +251,7 @@ protected:
{
for (int i = 0; i < fFamilies.count(); ++i) {
for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) {
- if (fFamilies[i]->fStyles[j] == familyMember) {
+ if (fFamilies[i]->fStyles[j].get() == familyMember) {
return fFamilies[i]->matchStyle(fontStyle);
}
}
@@ -258,20 +264,31 @@ protected:
}
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- SkAutoTDelete<SkStreamAsset> stream(bareStream);
- if (nullptr == stream || stream->getLength() <= 0) {
- return nullptr;
- }
+ return this->createFromStream(bareStream, FontParameters().setCollectionIndex(ttcIndex));
+ }
+ SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
+ using Scanner = SkTypeface_FreeType::Scanner;
+ SkAutoTDelete<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
- if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, nullptr)) {
- return new SkTypeface_Stream(style, isFixedPitch, false, name, stream.release(),
- ttcIndex);
- } else {
+ Scanner::AxisDefinitions axisDefinitions;
+ if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &style, &isFixedPitch,
+ &axisDefinitions))
+ {
return nullptr;
}
+
+ int paramAxisCount;
+ const FontParameters::Axis* paramAxes = params.getAxes(&paramAxisCount);
+ SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
+ Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name);
+
+ std::unique_ptr<SkFontData> data(new SkFontData(stream.release(),
+ params.getCollectionIndex(),
+ axisValues.get(), axisDefinitions.count()));
+ return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
@@ -290,7 +307,7 @@ protected:
tf = fDefaultFamily->matchStyle(style);
}
- return SkSafeRef(tf);
+ return tf;
bungeman-skia 2016/06/10 00:18:48 Like in the SkFontMgr_Custom constructor, this lea
}
private:
@@ -316,7 +333,7 @@ public:
if (families->empty()) {
SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString());
families->push_back().reset(family);
- family->appendTypeface(new SkTypeface_Empty);
+ family->appendTypeface(sk_make_sp<SkTypeface_Empty>());
}
}
@@ -363,16 +380,14 @@ private:
continue;
}
- SkTypeface_Custom* tf = new SkTypeface_File(style, isFixedPitch,
- true, // system-font (cannot delete)
- realname, filename.c_str(), faceIndex);
-
SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str());
if (nullptr == addTo) {
addTo = new SkFontStyleSet_Custom(realname);
families->push_back().reset(addTo);
}
- addTo->appendTypeface(tf);
+ addTo->appendTypeface(sk_make_sp<SkTypeface_File>(style, isFixedPitch, true,
+ realname, filename.c_str(),
+ faceIndex));
}
}
@@ -413,7 +428,7 @@ public:
if (families->empty()) {
SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString());
families->push_back().reset(family);
- family->appendTypeface(new SkTypeface_Empty);
+ family->appendTypeface(sk_make_sp<SkTypeface_Empty>());
}
}
@@ -450,16 +465,16 @@ private:
return;
}
- SkTypeface_Custom* tf =
- new SkTypeface_Stream(style, isFixedPitch, true, // system-font (cannot delete)
- realname, stream.release(), faceIndex);
-
SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str());
if (nullptr == addTo) {
addTo = new SkFontStyleSet_Custom(realname);
families->push_back().reset(addTo);
}
- addTo->appendTypeface(tf);
+ std::unique_ptr<SkFontData> data(
+ new SkFontData(stream.release(), faceIndex, nullptr, 0));
+ addTo->appendTypeface(sk_make_sp<SkTypeface_Stream>(std::move(data),
+ style, isFixedPitch,
+ true, realname));
}
}
@@ -481,7 +496,7 @@ public:
{
SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString());
families->push_back().reset(family);
- family->appendTypeface(new SkTypeface_Empty);
+ family->appendTypeface(sk_make_sp<SkTypeface_Empty>());
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698