Use public api to serialize typefaces.

SkFontData can be phased out now that there is the public
SkFontParameters and SkFontArguments and supporting methods implemented
on all SkTypefaces. After this change onMakeFontData can be moved to the
FreeType backed typeface as an implementation detail.

Change-Id: I26c41ecbbe9d3c6a5bd401e908fef67d325e1770
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299442
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2020-06-27 10:36:04 -04:00 committed by Skia Commit-Bot
parent 342273cbaa
commit 81e4bf2870
2 changed files with 31 additions and 2 deletions

View File

@ -17,13 +17,22 @@
class SkFontData {
public:
/** Makes a copy of the data in 'axis'. */
SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, const SkFixed axis[],int axisCount)
SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, const SkFixed* axis, int axisCount)
: fStream(std::move(stream)), fIndex(index), fAxisCount(axisCount), fAxis(axisCount)
{
for (int i = 0; i < axisCount; ++i) {
fAxis[i] = axis[i];
}
}
SkFontData(std::unique_ptr<SkStreamAsset> stream, SkFontArguments args)
: fStream(std::move(stream)), fIndex(args.getCollectionIndex())
, fAxisCount(args.getVariationDesignPosition().coordinateCount)
, fAxis(args.getVariationDesignPosition().coordinateCount)
{
for (int i = 0; i < fAxisCount; ++i) {
fAxis[i] = SkFloatToFixed(args.getVariationDesignPosition().coordinates[i].value);
}
}
SkFontData(const SkFontData& that)
: fStream(that.fStream->duplicate())
, fIndex(that.fIndex)

View File

@ -187,7 +187,27 @@ void SkTypeface::serialize(SkWStream* wstream, SerializeBehavior behavior) const
// has said they don't want the fontdata? Does this actually happen (getDescriptor returns
// fontdata as well?)
if (shouldSerializeData && !desc.hasFontData()) {
desc.setFontData(this->onMakeFontData());
SkFontArguments args;
int index;
std::unique_ptr<SkStreamAsset> stream = this->openStream(&index);
args.setCollectionIndex(index);
SkAutoSTMalloc<4, SkFontArguments::VariationPosition::Coordinate> variation;
int numAxes = this->getVariationDesignPosition(nullptr, 0);
if (0 < numAxes) {
variation.reset(numAxes);
numAxes = this->getVariationDesignPosition(variation.get(), numAxes);
if (0 < numAxes) {
SkFontArguments::VariationPosition pos{variation.get(), numAxes};
args.setVariationDesignPosition(pos);
}
}
if (stream) {
std::unique_ptr<SkFontData> fontData(new SkFontData(std::move(stream), args));
desc.setFontData(std::move(fontData));
}
}
desc.serialize(wstream);
}