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;
112 std::unique_ptr<SkStreamAsset>
onOpenStream(
int*)
const override;
133 int)
const override {
return 0; }
135 int)
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);
176 rec.fBounds = bounds;
181 if (fGlyphRecs.empty())
return nullptr;
186 for (
const auto& rec : fGlyphRecs) {
187 bounds.join(rec.isDrawable()
189 : rec.fPath.getBounds());
192 fMetrics.
fTop = bounds.top();
193 fMetrics.
fBottom = bounds.bottom();
194 fMetrics.
fXMin = bounds.left();
195 fMetrics.
fXMax = bounds.right();
207 for (
int gid = 0; gid < this->glyphCount(); ++gid) {
208 glyphToUnicode[gid] = SkTo<SkUnichar>(gid);
222 for (
int i = 0; i <
count; ++i) {
223 glyphs[i] = chars[i] < this->glyphCount() ? SkTo<SkGlyphID>(chars[i]) : 0;
262 const auto& rec = tf->fGlyphRecs[glyph.
getGlyphID()];
263 if (rec.isDrawable()) {
269 bounds.roundOut(&mx.
bounds);
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);
355 return std::make_unique<SkUserScalerContext>(
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));
394 wstream.
write(data->data(), 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)) {
462 if (
stream->read(&bounds,
sizeof(bounds)) !=
sizeof(bounds) || !
bounds.isFinite()) {
468 if (
stream->read(&sz,
sizeof(sz)) !=
sizeof(sz)) {
479 if (
stream->read(
data->writable_data(), sz) != sz) {
489 builder.setGlyph(i, advance, std::move(drawable), bounds);
497 builder.setGlyph(i, advance, path);
510 return Deserialize(stream.get());
SkStrokeRec::Style fStyle
constexpr int kMaxGlyphCount
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
static void sk_bzero(void *buffer, size_t size)
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
void onFilterRec(SkScalerContextRec *rec) const override
void onCharsToGlyphs(const SkUnichar *chars, int count, SkGlyphID glyphs[]) const override
size_t onGetTableData(SkFontTableTag, size_t, size_t, void *) const override
bool onGetPostScriptName(SkString *) const override
SkTypeface::LocalizedStrings * onCreateFamilyNameIterator() const override
void getGlyphToUnicodeMap(SkUnichar *glyphToUnicode) const override
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis[], int) const override
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate[], int) const override
int onGetUPEM() const override
int onGetTableTags(SkFontTableTag tags[]) const override
void onGetFontDescriptor(SkFontDescriptor *desc, bool *isLocal) const override
bool onComputeBounds(SkRect *bounds) const override
std::unique_ptr< SkStreamAsset > onOpenStream(int *) const override
std::unique_ptr< SkAdvancedTypefaceMetrics > onGetAdvancedMetrics() const override
bool onGlyphMaskNeedsCurrentColor() const override
void onGetFamilyName(SkString *familyName) const override
sk_sp< SkTypeface > onMakeClone(const SkFontArguments &args) const override
void getPostScriptGlyphNames(SkString *) const override
std::unique_ptr< SkStreamAsset > onOpenExistingStream(int *) const override
std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *desc) const override
int onCountGlyphs() const 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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
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