Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
SkTextBlobPriv Class Reference

#include <SkTextBlobPriv.h>

Static Public Member Functions

static void Flatten (const SkTextBlob &, SkWriteBuffer &)
 
static sk_sp< SkTextBlobMakeFromBuffer (SkReadBuffer &)
 
static bool HasRSXForm (const SkTextBlob &blob)
 

Detailed Description

Definition at line 25 of file SkTextBlobPriv.h.

Member Function Documentation

◆ Flatten()

void SkTextBlobPriv::Flatten ( const SkTextBlob blob,
SkWriteBuffer buffer 
)
static

Serialize to a buffer.

Definition at line 663 of file SkTextBlob.cpp.

663 {
664 // seems like we could skip this, and just recompute bounds in unflatten, but
665 // some cc_unittests fail if we remove this...
666 buffer.writeRect(blob.bounds());
667
668 SkTextBlobRunIterator it(&blob);
669 while (!it.done()) {
670 SkASSERT(it.glyphCount() > 0);
671
672 buffer.write32(it.glyphCount());
673 PositioningAndExtended pe;
674 pe.intValue = 0;
675 pe.positioning = it.positioning();
676 SkASSERT((int32_t)it.positioning() == pe.intValue); // backwards compat.
677
678 uint32_t textSize = it.textSize();
679 pe.extended = textSize > 0;
680 buffer.write32(pe.intValue);
681 if (pe.extended) {
682 buffer.write32(textSize);
683 }
684 buffer.writePoint(it.offset());
685
686 SkFontPriv::Flatten(it.font(), buffer);
687
688 buffer.writeByteArray(it.glyphs(), it.glyphCount() * sizeof(uint16_t));
689 buffer.writeByteArray(it.pos(),
690 it.glyphCount() * sizeof(SkScalar) *
691 SkTextBlob::ScalarsPerGlyph(
692 SkTo<SkTextBlob::GlyphPositioning>(it.positioning())));
693 if (pe.extended) {
694 buffer.writeByteArray(it.clusters(), sizeof(uint32_t) * it.glyphCount());
695 buffer.writeByteArray(it.text(), it.textSize());
696 }
697
698 it.next();
699 }
700
701 // Marker for the last run (0 is not a valid glyph count).
702 buffer.write32(0);
703}
#define SkASSERT(cond)
Definition SkAssert.h:116
static void Flatten(const SkFont &, SkWriteBuffer &buffer)
const SkRect & bounds() const
Definition SkTextBlob.h:53
float SkScalar
Definition extension.cpp:12
static const uint8_t buffer[]

◆ HasRSXForm()

static bool SkTextBlobPriv::HasRSXForm ( const SkTextBlob blob)
static

◆ MakeFromBuffer()

sk_sp< SkTextBlob > SkTextBlobPriv::MakeFromBuffer ( SkReadBuffer reader)
static

Recreate an SkTextBlob that was serialized into a buffer.

Parameters
SkReadBufferSerialized blob data.
Returns
A new SkTextBlob representing the serialized data, or NULL if the buffer is invalid.

Definition at line 705 of file SkTextBlob.cpp.

705 {
707 reader.readRect(&bounds);
708
709 SkTextBlobBuilder blobBuilder;
710 SkSafeMath safe;
711 for (;;) {
712 int glyphCount = reader.read32();
713 if (glyphCount == 0) {
714 // End-of-runs marker.
715 break;
716 }
717
718 PositioningAndExtended pe;
719 pe.intValue = reader.read32();
720 const auto pos = SkTo<SkTextBlob::GlyphPositioning>(pe.positioning);
721 if (glyphCount <= 0 || pos > SkTextBlob::kRSXform_Positioning) {
722 return nullptr;
723 }
724 int textSize = pe.extended ? reader.read32() : 0;
725 if (textSize < 0) {
726 return nullptr;
727 }
728
730 reader.readPoint(&offset);
731 SkFont font;
732 SkFontPriv::Unflatten(&font, reader);
733
734 // Compute the expected size of the buffer and ensure we have enough to deserialize
735 // a run before allocating it.
736 const size_t glyphSize = safe.mul(glyphCount, sizeof(uint16_t)),
737 posSize =
738 safe.mul(glyphCount, safe.mul(sizeof(SkScalar),
739 SkTextBlob::ScalarsPerGlyph(pos))),
740 clusterSize = pe.extended ? safe.mul(glyphCount, sizeof(uint32_t)) : 0;
741 const size_t totalSize =
742 safe.add(safe.add(glyphSize, posSize), safe.add(clusterSize, textSize));
743
744 if (!reader.isValid() || !safe || totalSize > reader.available()) {
745 return nullptr;
746 }
747
748 const SkTextBlobBuilder::RunBuffer* buf = nullptr;
749 switch (pos) {
750 case SkTextBlob::kDefault_Positioning:
751 buf = &blobBuilder.allocRunText(font, glyphCount, offset.x(), offset.y(),
752 textSize, &bounds);
753 break;
754 case SkTextBlob::kHorizontal_Positioning:
755 buf = &blobBuilder.allocRunTextPosH(font, glyphCount, offset.y(),
756 textSize, &bounds);
757 break;
758 case SkTextBlob::kFull_Positioning:
759 buf = &blobBuilder.allocRunTextPos(font, glyphCount, textSize, &bounds);
760 break;
761 case SkTextBlob::kRSXform_Positioning:
762 buf = &blobBuilder.allocRunTextRSXform(font, glyphCount, textSize, &bounds);
763 break;
764 }
765
766 if (!buf->glyphs ||
767 !buf->pos ||
768 (pe.extended && (!buf->clusters || !buf->utf8text))) {
769 return nullptr;
770 }
771
772 if (!reader.readByteArray(buf->glyphs, glyphSize) ||
773 !reader.readByteArray(buf->pos, posSize)) {
774 return nullptr;
775 }
776
777 if (pe.extended) {
778 if (!reader.readByteArray(buf->clusters, clusterSize) ||
779 !reader.readByteArray(buf->utf8text, textSize)) {
780 return nullptr;
781 }
782 }
783 }
784
785 return blobBuilder.make();
786}
SkPoint pos
static bool Unflatten(SkFont *, SkReadBuffer &buffer)
void readRect(SkRect *rect)
void readPoint(SkPoint *point)
bool readByteArray(void *value, size_t size)
bool isValid() const
int32_t read32()
size_t available() const
size_t add(size_t x, size_t y)
Definition SkSafeMath.h:33
size_t mul(size_t x, size_t y)
Definition SkSafeMath.h:29
const RunBuffer & allocRunTextPosH(const SkFont &font, int count, SkScalar y, int textByteCount, const SkRect *bounds=nullptr)
const RunBuffer & allocRunText(const SkFont &font, int count, SkScalar x, SkScalar y, int textByteCount, const SkRect *bounds=nullptr)
const RunBuffer & allocRunTextRSXform(const SkFont &font, int count, int textByteCount, const SkRect *bounds=nullptr)
sk_sp< SkTextBlob > make()
const RunBuffer & allocRunTextPos(const SkFont &font, int count, int textByteCount, const SkRect *bounds=nullptr)
Optional< SkRect > bounds
Definition SkRecords.h:189
font
Font Metadata and Metrics.
Point offset
SkScalar * pos
storage for glyph positions in run
Definition SkTextBlob.h:330
char * utf8text
storage for text UTF-8 code units in run
Definition SkTextBlob.h:331
SkGlyphID * glyphs
storage for glyph indexes in run
Definition SkTextBlob.h:329
uint32_t * clusters
storage for glyph clusters (index of UTF-8 code unit)
Definition SkTextBlob.h:332

The documentation for this class was generated from the following files: