Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
SkShaperJSONWriter Class Referencefinal

#include <SkShaperJSONWriter.h>

Inheritance diagram for SkShaperJSONWriter:
SkShaper::RunHandler

Public Types

using BreakupClustersCallback = std::function< void(size_t, size_t, uint32_t, uint32_t)>
 
using VisualizeClustersCallback = std::function< void(size_t, SkSpan< const char >, SkSpan< const SkGlyphID >)>
 

Public Member Functions

 SkShaperJSONWriter (SkJSONWriter *JSONWriter, const char *utf8, size_t size)
 
void beginLine () override
 
void runInfo (const RunInfo &info) override
 
void commitRunInfo () override
 
Buffer runBuffer (const RunInfo &info) override
 
void commitRunBuffer (const RunInfo &info) override
 
void commitLine () override
 
- Public Member Functions inherited from SkShaper::RunHandler
virtual ~RunHandler ()=default
 

Static Public Member Functions

static void BreakupClusters (size_t utf8Begin, size_t utf8End, SkSpan< const uint32_t > clusters, const BreakupClustersCallback &processMToN)
 
static void VisualizeClusters (const char utf8[], size_t utf8Begin, size_t utf8End, SkSpan< const SkGlyphID > glyphIDs, SkSpan< const uint32_t > clusters, const VisualizeClustersCallback &processMToN)
 

Detailed Description

Definition at line 23 of file SkShaperJSONWriter.h.

Member Typedef Documentation

◆ BreakupClustersCallback

using SkShaperJSONWriter::BreakupClustersCallback = std::function<void(size_t, size_t, uint32_t, uint32_t)>

Definition at line 37 of file SkShaperJSONWriter.h.

◆ VisualizeClustersCallback

using SkShaperJSONWriter::VisualizeClustersCallback = std::function<void(size_t, SkSpan<const char>, SkSpan<const SkGlyphID>)>

Definition at line 46 of file SkShaperJSONWriter.h.

Constructor & Destructor Documentation

◆ SkShaperJSONWriter()

SkShaperJSONWriter::SkShaperJSONWriter ( SkJSONWriter JSONWriter,
const char *  utf8,
size_t  size 
)

Definition at line 24 of file SkShaperJSONWriter.cpp.

25 : fJSONWriter{JSONWriter}
26 , fUTF8{utf8, size} {}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

Member Function Documentation

◆ beginLine()

void SkShaperJSONWriter::beginLine ( )
overridevirtual

Called when beginning a line.

Implements SkShaper::RunHandler.

Definition at line 28 of file SkShaperJSONWriter.cpp.

28{ }

◆ BreakupClusters()

void SkShaperJSONWriter::BreakupClusters ( size_t  utf8Begin,
size_t  utf8End,
SkSpan< const uint32_t >  clusters,
const BreakupClustersCallback processMToN 
)
static

Definition at line 137 of file SkShaperJSONWriter.cpp.

139 {
140
141 if (clusters.front() <= clusters.back()) {
142 // Handle left-to-right text direction
143 size_t glyphStartIndex = 0;
144 for (size_t glyphEndIndex = 0; glyphEndIndex < clusters.size(); glyphEndIndex++) {
145
146 if (clusters[glyphStartIndex] == clusters[glyphEndIndex]) { continue; }
147
148 processMToN(glyphStartIndex, glyphEndIndex,
149 clusters[glyphStartIndex], clusters[glyphEndIndex]);
150
151 glyphStartIndex = glyphEndIndex;
152 }
153
154 processMToN(glyphStartIndex, clusters.size(), clusters[glyphStartIndex], utf8End);
155
156 } else {
157 // Handle right-to-left text direction.
158 SkASSERT(clusters.size() >= 2);
159 size_t glyphStartIndex = 0;
160 uint32_t utf8EndIndex = utf8End;
161 for (size_t glyphEndIndex = 0; glyphEndIndex < clusters.size(); glyphEndIndex++) {
162
163 if (clusters[glyphStartIndex] == clusters[glyphEndIndex]) { continue; }
164
165 processMToN(glyphStartIndex, glyphEndIndex,
166 clusters[glyphStartIndex], utf8EndIndex);
167
168 utf8EndIndex = clusters[glyphStartIndex];
169 glyphStartIndex = glyphEndIndex;
170 }
171 processMToN(glyphStartIndex, clusters.size(), utf8Begin, clusters[glyphStartIndex-1]);
172 }
173}
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr T & front() const
Definition SkSpan_impl.h:88
constexpr T & back() const
Definition SkSpan_impl.h:89
constexpr size_t size() const
Definition SkSpan_impl.h:95

◆ commitLine()

void SkShaperJSONWriter::commitLine ( )
inlineoverridevirtual

Called when ending a line.

Implements SkShaper::RunHandler.

Definition at line 35 of file SkShaperJSONWriter.h.

35{}

◆ commitRunBuffer()

void SkShaperJSONWriter::commitRunBuffer ( const RunInfo info)
overridevirtual

Called after each runBuffer is filled out.

Implements SkShaper::RunHandler.

Definition at line 75 of file SkShaperJSONWriter.cpp.

75 {
76 fJSONWriter->beginObject("run", true);
77
78 // Font name
79 SkString fontName;
80 info.fFont.getTypeface()->getFamilyName(&fontName);
81 fJSONWriter->appendString("font name", fontName);
82
83 // Font size
84 fJSONWriter->appendFloat("font size", info.fFont.getSize());
85
86 if (info.fBidiLevel > 0) {
87 std::string bidiType = info.fBidiLevel % 2 == 0 ? "left-to-right" : "right-to-left";
88 std::string bidiOutput = bidiType + " lvl " + std::to_string(info.fBidiLevel);
89 fJSONWriter->appendString("BiDi", bidiOutput);
90 }
91
92 if (is_one_to_one(fUTF8.c_str(), info.utf8Range.begin(), info.utf8Range.end(), fClusters)) {
93 std::string utf8{&fUTF8[info.utf8Range.begin()], info.utf8Range.size()};
94 fJSONWriter->appendString("UTF8", utf8);
95
96 fJSONWriter->beginArray("glyphs", false);
97 for (auto glyphID : fGlyphs) {
98 fJSONWriter->appendU32(glyphID);
99 }
100 fJSONWriter->endArray();
101
102 fJSONWriter->beginArray("clusters", false);
103 for (auto cluster : fClusters) {
104 fJSONWriter->appendU32(cluster);
105 }
106 fJSONWriter->endArray();
107 } else {
108 VisualizeClusters(fUTF8.c_str(),
109 info.utf8Range.begin(), info.utf8Range.end(),
110 SkSpan(fGlyphs),
111 SkSpan(fClusters),
112 [this](size_t codePointCount, SkSpan<const char> utf1to1,
113 SkSpan<const SkGlyphID> glyph1to1) {
114 this->displayMToN(codePointCount, utf1to1, glyph1to1);
115 });
116 }
117
118 if (info.glyphCount > 1) {
119 fJSONWriter->beginArray("horizontal positions", false);
120 for (auto position : fPositions) {
121 fJSONWriter->appendFloat(position.x());
122 }
123 fJSONWriter->endArray();
124 }
125
126 fJSONWriter->beginArray("advances", false);
127 for (size_t i = 1; i < info.glyphCount; i++) {
128 fJSONWriter->appendFloat(fPositions[i].fX - fPositions[i-1].fX);
129 }
130 SkPoint lastAdvance = info.fAdvance - (fPositions.back() - fPositions.front());
131 fJSONWriter->appendFloat(lastAdvance.fX);
132 fJSONWriter->endArray();
133
134 fJSONWriter->endObject();
135}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static bool is_one_to_one(const char utf8[], size_t utf8Begin, size_t utf8End, std::vector< uint32_t > &clusters)
void beginArray(const char *name=nullptr, bool multiline=true)
void appendU32(uint32_t value)
void beginObject(const char *name=nullptr, bool multiline=true)
void appendFloat(float value)
void appendString(const char *value, size_t size)
static void VisualizeClusters(const char utf8[], size_t utf8Begin, size_t utf8End, SkSpan< const SkGlyphID > glyphIDs, SkSpan< const uint32_t > clusters, const VisualizeClustersCallback &processMToN)
float fX
x-axis value

◆ commitRunInfo()

void SkShaperJSONWriter::commitRunInfo ( )
overridevirtual

Called after all runInfo calls for a line.

Implements SkShaper::RunHandler.

Definition at line 32 of file SkShaperJSONWriter.cpp.

32{ }

◆ runBuffer()

SkShaper::RunHandler::Buffer SkShaperJSONWriter::runBuffer ( const RunInfo info)
overridevirtual

Called for each run in a line after commitRunInfo. The buffer will be filled out.

Implements SkShaper::RunHandler.

Definition at line 35 of file SkShaperJSONWriter.cpp.

35 {
36 fGlyphs.resize(info.glyphCount);
37 fPositions.resize(info.glyphCount);
38 fClusters.resize(info.glyphCount);
39 return {fGlyphs.data(), fPositions.data(), nullptr, fClusters.data(), {0, 0}};
40}

◆ runInfo()

void SkShaperJSONWriter::runInfo ( const RunInfo info)
overridevirtual

Called once for each run in a line. Can compute baselines and offsets.

Implements SkShaper::RunHandler.

Definition at line 30 of file SkShaperJSONWriter.cpp.

30{ }

◆ VisualizeClusters()

void SkShaperJSONWriter::VisualizeClusters ( const char  utf8[],
size_t  utf8Begin,
size_t  utf8End,
SkSpan< const SkGlyphID glyphIDs,
SkSpan< const uint32_t >  clusters,
const VisualizeClustersCallback processMToN 
)
static

Definition at line 175 of file SkShaperJSONWriter.cpp.

178 {
179
180 size_t glyphRangeStart, glyphRangeEnd;
181 uint32_t utf8RangeStart, utf8RangeEnd;
182
183 auto resetRanges = [&]() {
184 glyphRangeStart = std::numeric_limits<size_t>::max();
185 glyphRangeEnd = 0;
186 utf8RangeStart = std::numeric_limits<uint32_t>::max();
187 utf8RangeEnd = 0;
188 };
189
190 auto checkRangesAndProcess = [&]() {
191 if (glyphRangeStart < glyphRangeEnd) {
192 size_t glyphRangeCount = glyphRangeEnd - glyphRangeStart;
193 SkSpan<const char> utf8Span{&utf8[utf8RangeStart], utf8RangeEnd - utf8RangeStart};
194 SkSpan<const SkGlyphID> glyphSpan{&glyphIDs[glyphRangeStart], glyphRangeCount};
195
196 // Glyph count is the same as codepoint count for 1:1.
197 processMToN(glyphRangeCount, utf8Span, glyphSpan);
198 }
199 resetRanges();
200 };
201
202 auto gatherRuns = [&](size_t glyphStartIndex, size_t glyphEndIndex,
203 uint32_t utf8StartIndex, uint32_t utf8EndIndex) {
204 int possibleCount = SkUTF::CountUTF8(&utf8[utf8StartIndex], utf8EndIndex - utf8StartIndex);
205 if (possibleCount == -1) { return; }
206 size_t codePointCount = SkTo<size_t>(possibleCount);
207 if (codePointCount == 1 && glyphEndIndex - glyphStartIndex == 1) {
208 glyphRangeStart = std::min(glyphRangeStart, glyphStartIndex);
209 glyphRangeEnd = std::max(glyphRangeEnd, glyphEndIndex );
210 utf8RangeStart = std::min(utf8RangeStart, utf8StartIndex );
211 utf8RangeEnd = std::max(utf8RangeEnd, utf8EndIndex );
212 } else {
213 checkRangesAndProcess();
214
215 SkSpan<const char> utf8Span{&utf8[utf8StartIndex], utf8EndIndex - utf8StartIndex};
216 SkSpan<const SkGlyphID> glyphSpan{&glyphIDs[glyphStartIndex],
217 glyphEndIndex - glyphStartIndex};
218
219 processMToN(codePointCount, utf8Span, glyphSpan);
220 }
221 };
222
223 resetRanges();
224 BreakupClusters(utf8Begin, utf8End, clusters, gatherRuns);
225 checkRangesAndProcess();
226}
static void BreakupClusters(size_t utf8Begin, size_t utf8End, SkSpan< const uint32_t > clusters, const BreakupClustersCallback &processMToN)
SK_SPI int CountUTF8(const char *utf8, size_t byteLength)
Definition SkUTF.cpp:47

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