blob: bd9b0f410e46832a55d9445f5b031730d06125db [file] [log] [blame]
/*
* Copyright 2023 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkTypeface_Fontations_DEFINED
#define SkTypeface_Fontations_DEFINED
#include "include/core/SkStream.h"
#include "include/core/SkTypeface.h"
#include "src/core/SkAdvancedTypefaceMetrics.h"
#include "src/core/SkScalerContext.h"
#include "src/ports/fontations/gen/src/ffi.rs.h"
#include <memory>
class SkStreamAsset;
/** SkTypeface implementation based on Google Fonts Fontations Rust libraries. */
class SkTypeface_Fontations : public SkTypeface {
public:
SkTypeface_Fontations(std::unique_ptr<SkStreamAsset> font_data, uint32_t ttcIndex = 0);
const fontations_ffi::BridgeFontRef& getBridgeFontRef() { return *fBridgeFontRef; }
protected:
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
return sk_ref_sp(this);
}
std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec*) const override;
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
return nullptr;
}
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override {}
void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override;
int onCountGlyphs() const override;
void getPostScriptGlyphNames(SkString*) const override {}
void getGlyphToUnicodeMap(SkUnichar*) const override {}
int onGetUPEM() const override;
void onGetFamilyName(SkString* familyName) const override;
bool onGetPostScriptName(SkString*) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
bool onGlyphMaskNeedsCurrentColor() const override { return false; }
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const override {
return 0;
}
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) const override {
return 0;
}
int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { return 0; }
private:
sk_sp<SkData> fFontData;
// Incoming ttc index requested when this typeface was instantiated from data.
uint32_t fTtcIndex = 0;
// fBridgeFontRef accesses the data in fFontData. fFontData needs to be kept around for the
// lifetime of fBridgeFontRef to safely request parsed data.
rust::Box<::fontations_ffi::BridgeFontRef> fBridgeFontRef;
};
#endif // SkTypeface_Fontations_DEFINED