51static inline const constexpr bool kSkShowTextBlitCoverage =
false;
57 #define SCALE_X(field) dst.field *= sx
58 #define SCALE_Y(field) dst.field *= sy
89 std::vector<SkCustomTypefaceBuilder::GlyphRec>&& recs)
91 , fGlyphRecs(
std::move(recs))
95 const std::vector<SkCustomTypefaceBuilder::GlyphRec> fGlyphRecs;
101 void getGlyphToUnicodeMap(
SkUnichar* glyphToUnicode)
const override;
102 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics()
const override;
108 void onGetFamilyName(
SkString* familyName)
const override;
109 bool onGetPostScriptName(
SkString*)
const override;
112 std::unique_ptr<SkStreamAsset> onOpenStream(
int*)
const override;
116 std::unique_ptr<SkStreamAsset> onOpenExistingStream(
int*)
const override {
return nullptr; }
121 int onCountGlyphs()
const override {
return this->glyphCount(); }
122 int onGetUPEM()
const override {
return 2048; }
130 void getPostScriptGlyphNames(
SkString*)
const override {}
131 bool onGlyphMaskNeedsCurrentColor()
const override {
return false; }
133 int)
const override {
return 0; }
135 int)
const override {
return 0; }
136 int onGetTableTags(
SkFontTableTag tags[])
const override {
return 0; }
137 size_t onGetTableData(
SkFontTableTag,
size_t,
size_t,
void*)
const override {
return 0; }
139 int glyphCount()
const {
140 return SkToInt(fGlyphRecs.size());
145 sk_bzero(&fMetrics,
sizeof(fMetrics));
156SkCustomTypefaceBuilder::GlyphRec& SkCustomTypefaceBuilder::ensureStorage(
SkGlyphID index) {
157 if (index >= fGlyphRecs.size()) {
161 return fGlyphRecs[index];
165 auto& rec = this->ensureStorage(index);
166 rec.fAdvance = advance;
168 rec.fDrawable =
nullptr;
173 auto& rec = this->ensureStorage(index);
174 rec.fAdvance = advance;
175 rec.fDrawable = std::move(drawable);
181 if (fGlyphRecs.empty())
return nullptr;
186 for (
const auto& rec : fGlyphRecs) {
187 bounds.join(rec.isDrawable()
189 : rec.fPath.getBounds());
206void SkUserTypeface::getGlyphToUnicodeMap(
SkUnichar* glyphToUnicode)
const {
207 for (
int gid = 0; gid < this->glyphCount(); ++gid) {
208 glyphToUnicode[gid] = SkTo<SkUnichar>(gid);
212std::unique_ptr<SkAdvancedTypefaceMetrics> SkUserTypeface::onGetAdvancedMetrics()
const {
223 glyphs[
i] = chars[
i] < this->glyphCount() ? SkTo<SkGlyphID>(chars[
i]) : 0;
227void SkUserTypeface::onGetFamilyName(
SkString* familyName)
const {
231bool SkUserTypeface::onGetPostScriptName(
SkString*)
const {
262 const auto& rec = tf->fGlyphRecs[glyph.
getGlyphID()];
263 if (rec.isDrawable()) {
279 SkASSERTF(rec.isDrawable(),
"Only drawable-backed glyphs should reach generateImage.");
284 if constexpr (kSkShowTextBlitCoverage) {
285 canvas->clear(0x33FF0000);
290 canvas->translate(-glyph.
left(), -glyph.
top());
293 canvas->drawDrawable(rec.fDrawable.get(), &fMatrix);
301 rec.fPath.transform(fMatrix,
path);
307 class DrawableMatrixWrapper final :
public SkDrawable {
310 : fDrawable(std::move(drawable))
314 SkRect onGetBounds()
override {
315 return fMatrix.
mapRect(fDrawable->getBounds());
318 size_t onApproximateBytesUsed()
override {
319 return fDrawable->approximateBytesUsed() +
sizeof(DrawableMatrixWrapper);
322 void onDraw(
SkCanvas* canvas)
override {
323 if constexpr (kSkShowTextBlitCoverage) {
325 paint.setColor(0x3300FF00);
339 ? sk_make_sp<DrawableMatrixWrapper>(rec.fDrawable, fMatrix)
344 auto [sx, sy] = fMatrix.
mapXY(1, 1);
352std::unique_ptr<SkScalerContext> SkUserTypeface::onCreateScalerContext(
355 return std::make_unique<SkUserScalerContext>(
368std::unique_ptr<SkStreamAsset> SkUserTypeface::onOpenStream(
int* ttcIndex)
const {
373 wstream.
write(&fMetrics,
sizeof(fMetrics));
376 wstream.
write(&style,
sizeof(style));
378 wstream.
write32(this->glyphCount());
380 for (
const auto& rec : fGlyphRecs) {
385 wstream.
write(&rec.fBounds,
sizeof(rec.fBounds));
387 auto data = rec.isDrawable()
388 ? rec.fDrawable->serialize()
389 : rec.fPath.serialize();
391 const size_t sz =
data->size();
393 wstream.
write(&sz,
sizeof(sz));
406 fPosition =
stream->getPosition();
411 fStream->
seek(fPosition);
430 if (
stream->read(&metrics,
sizeof(metrics)) !=
sizeof(metrics)) {
435 if (
stream->read(&style,
sizeof(style)) !=
sizeof(style)) {
449 for (
int i = 0;
i < glyphCount; ++
i) {
451 if (!
stream->readU32(>ype) ||
457 if (!
stream->readScalar(&advance)) {
468 if (
stream->read(&sz,
sizeof(sz)) !=
sizeof(sz)) {
479 if (
stream->read(
data->writable_data(), sz) != sz) {
510 return Deserialize(
stream.get());
SkStrokeRec::Style fStyle
sk_bzero(glyphs, sizeof(glyphs))
static constexpr bool SkIsAlign4(T x)
#define SkASSERTF(cond, fmt,...)
constexpr SkColor SK_ColorTRANSPARENT
static const char gHeaderString[]
static constexpr int kMaxGlyphCount
static SkFontMetrics scale_fontmetrics(const SkFontMetrics &src, float sx, float sy)
static constexpr size_t kHeaderSize
#define SkFixedToScalar(x)
@ kNone
glyph outlines unchanged
sk_sp< T > sk_ref_sp(T *obj)
bool StreamRemainingLengthIsBelow(SkStream *stream, size_t len)
constexpr size_t SkToSizeT(S x)
constexpr int SkToInt(S x)
AutoRestorePosition(SkStream *stream)
static std::unique_ptr< SkCanvas > MakeRasterDirectN32(int width, int height, SkPMColor *pixels, size_t rowBytes)
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawDrawable(SkDrawable *drawable, const SkMatrix *matrix=nullptr)
sk_sp< SkTypeface > detach()
static sk_sp< SkTypeface > MakeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
void setGlyph(SkGlyphID, float advance, const SkPath &)
friend class SkUserTypeface
void setMetrics(const SkFontMetrics &fm, float scale=1)
SkCustomTypefaceBuilder()
void setFontStyle(SkFontStyle)
static constexpr SkTypeface::FactoryId FactoryId
static sk_sp< SkData > MakeUninitialized(size_t length)
static sk_sp< SkDrawable > Deserialize(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
std::unique_ptr< SkStreamAsset > detachAsStream()
bool write(const void *buffer, size_t size) override
SkGlyphID getGlyphID() const
SkMask::Format maskFormat() const
SkFixed getSubYFixed() const
SkFixed getSubXFixed() const
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
@ kFill_Style
set to fill geometry
void forceGenerateImageFromPath()
SkTypeface * getTypeface() const
virtual bool seek(size_t)
SkFontStyle fontStyle() const
void generateFontMetrics(SkFontMetrics *metrics) override
SkUserScalerContext(sk_sp< SkUserTypeface > face, const SkScalerContextEffects &effects, const SkDescriptor *desc)
const SkUserTypeface * userTF() const
bool generatePath(const SkGlyph &glyph, SkPath *path) override
sk_sp< SkDrawable > generateDrawable(const SkGlyph &glyph) override
GlyphMetrics generateMetrics(const SkGlyph &glyph, SkArenaAlloc *) override
void generateImage(const SkGlyph &glyph, void *imageBuffer) override
bool writeScalar(SkScalar)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Optional< SkRect > bounds
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
static const char header[]
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...
@ kARGB32_Format
SkPMColor.
void getSingleMatrix(SkMatrix *) const
void setHinting(SkFontHinting)
SkMask::Format maskFormat
std::shared_ptr< const fml::Mapping > data