Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
sktext Namespace Reference

Namespaces

namespace  gpu
 

Classes

class  GlyphRun
 
class  GlyphRunBuilder
 
class  GlyphRunList
 
union  IDOrDrawable
 
union  IDOrPath
 
class  SkStrikePromise
 
class  StrikeForGPU
 
class  StrikeForGPUCacheInterface
 
class  StrikeMutationMonitor
 

Functions

static SkRect glyphrun_source_bounds (const SkFont &font, const SkPaint &paint, SkZip< const SkGlyphID, const SkPoint > source, SkSpan< const SkVector > scaledRotations)
 
static SkSpan< const SkPointdraw_text_positions (const SkFont &font, SkSpan< const SkGlyphID > glyphIDs, SkPoint origin, SkPoint *buffer)
 

Function Documentation

◆ draw_text_positions()

static SkSpan< const SkPoint > sktext::draw_text_positions ( const SkFont font,
SkSpan< const SkGlyphID glyphIDs,
SkPoint  origin,
SkPoint buffer 
)
static

Definition at line 196 of file GlyphRun.cpp.

197 {
199 SkBulkGlyphMetrics storage{strikeSpec};
200 auto glyphs = storage.glyphs(glyphIDs);
201
202 SkPoint* positionCursor = buffer;
203 SkPoint endOfLastGlyph = origin;
204 for (auto glyph : glyphs) {
205 *positionCursor++ = endOfLastGlyph;
206 endOfLastGlyph += glyph->advanceVector();
207 }
208 return SkSpan(buffer, glyphIDs.size());
209}
uint16_t glyphs[5]
constexpr size_t size() const
Definition SkSpan_impl.h:95
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
static const uint8_t buffer[]

◆ glyphrun_source_bounds()

static SkRect sktext::glyphrun_source_bounds ( const SkFont font,
const SkPaint paint,
SkZip< const SkGlyphID, const SkPoint source,
SkSpan< const SkVector scaledRotations 
)
static

Definition at line 119 of file GlyphRun.cpp.

123 {
125 const SkRect fontBounds = SkFontPriv::GetFontBounds(font);
126
127 SkSpan<const SkGlyphID> glyphIDs = source.get<0>();
128 SkSpan<const SkPoint> positions = source.get<1>();
129
130 if (fontBounds.isEmpty()) {
131 // Empty font bounds are likely a font bug. TightBounds has a better chance of
132 // producing useful results in this case.
133 auto [strikeSpec, strikeToSourceScale] = SkStrikeSpec::MakeCanonicalized(font, &paint);
134 SkBulkGlyphMetrics metrics{strikeSpec};
135 SkSpan<const SkGlyph*> glyphs = metrics.glyphs(glyphIDs);
136 if (scaledRotations.empty()) {
137 // No RSXForm data - glyphs x/y aligned.
138 auto scaleAndTranslateRect =
139 [scale = strikeToSourceScale](const SkRect& in, const SkPoint& pos) {
140 return SkRect::MakeLTRB(in.left() * scale + pos.x(),
141 in.top() * scale + pos.y(),
142 in.right() * scale + pos.x(),
143 in.bottom() * scale + pos.y());
144 };
145
147 for (auto [pos, glyph] : SkMakeZip(positions, glyphs)) {
148 if (SkRect r = glyph->rect(); !r.isEmpty()) {
149 bounds.join(scaleAndTranslateRect(r, pos));
150 }
151 }
152 return bounds;
153 } else {
154 // RSXForm - glyphs can be any scale or rotation.
156 for (auto [pos, scaleRotate, glyph] : SkMakeZip(positions, scaledRotations, glyphs)) {
157 if (!glyph->rect().isEmpty()) {
158 SkMatrix xform = SkMatrix().setRSXform(
159 SkRSXform{pos.x(), pos.y(), scaleRotate.x(), scaleRotate.y()});
160 xform.preScale(strikeToSourceScale, strikeToSourceScale);
161 bounds.join(xform.mapRect(glyph->rect()));
162 }
163 }
164 return bounds;
165 }
166 }
167
168 // Use conservative bounds. All glyph have a box of fontBounds size.
169 if (scaledRotations.empty()) {
171 bounds.setBounds(positions.data(), SkCount(positions));
172 bounds.fLeft += fontBounds.left();
173 bounds.fTop += fontBounds.top();
174 bounds.fRight += fontBounds.right();
175 bounds.fBottom += fontBounds.bottom();
176 return bounds;
177 } else {
178 // RSXForm case glyphs can be any scale or rotation.
180 bounds.setEmpty();
181 for (auto [pos, scaleRotate] : SkMakeZip(positions, scaledRotations)) {
182 const SkRSXform xform{pos.x(), pos.y(), scaleRotate.x(), scaleRotate.y()};
183 bounds.join(SkMatrix().setRSXform(xform).mapRect(fontBounds));
184 }
185 return bounds;
186 }
187}
SkPoint pos
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr int SkCount(const Container &c)
Definition SkTLogic.h:54
constexpr auto SkMakeZip(Ts &&... ts)
Definition SkZip.h:212
bool empty() const
Definition SkBitmap.h:210
static SkRect GetFontBounds(const SkFont &)
Definition SkFont.cpp:354
SkMatrix & setRSXform(const SkRSXform &rsxForm)
Definition SkMatrix.cpp:420
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:315
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
constexpr T * data() const
Definition SkSpan_impl.h:94
constexpr bool empty() const
Definition SkSpan_impl.h:96
static std::tuple< SkStrikeSpec, SkScalar > MakeCanonicalized(const SkFont &font, const SkPaint *paint=nullptr)
const Paint & paint
SkBitmap source
Definition examples.cpp:28
Optional< SkRect > bounds
Definition SkRecords.h:189
const Scalar scale
constexpr float y() const
constexpr float x() const
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595
constexpr float left() const
Definition SkRect.h:734
constexpr float top() const
Definition SkRect.h:741
constexpr float right() const
Definition SkRect.h:748
bool isEmpty() const
Definition SkRect.h:693
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646
constexpr float bottom() const
Definition SkRect.h:755