Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 54bf684

Browse files
reed-at-googleSkia Commit-Bot
authored andcommitted
Revert "Revert "migrate to passing paint/ctm for bounds""
Fix: pass real paint to FindOrCreateStrikeWithNoDeviceExclusive This reverts commit 914d319. Bug: skia: Change-Id: I2d618a868ae57e34cba5964aadd4a365481cb4cd Reviewed-on: https://skia-review.googlesource.com/c/172976 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Reed <reed@google.com>
1 parent 09523b4 commit 54bf684

File tree

5 files changed

+80
-73
lines changed

5 files changed

+80
-73
lines changed

include/core/SkFont.h

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ class SK_API SkFont {
330330
SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
331331
SkRect* bounds = nullptr) const;
332332

333-
/** Retrieves the advance and bounds for each glyph in glyphs.
333+
/** DEPRECATED
334+
Retrieves the advance and bounds for each glyph in glyphs.
334335
Both widths and bounds may be nullptr.
335336
If widths is not nullptr, widths must be an array of count entries.
336337
if bounds is not nullptr, bounds must be an array of count entries.
@@ -340,8 +341,58 @@ class SK_API SkFont {
340341
@param widths returns text advances for each glyph; may be nullptr
341342
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
342343
*/
343-
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[],
344-
SkRect bounds[] = nullptr) const;
344+
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
345+
this->getWidthsBounds(glyphs, count, widths, bounds, nullptr);
346+
}
347+
348+
// DEPRECATED
349+
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[], std::nullptr_t) const {
350+
this->getWidths(glyphs, count, widths);
351+
}
352+
353+
/** Experimental
354+
Retrieves the advance and bounds for each glyph in glyphs.
355+
Both widths and bounds may be nullptr.
356+
If widths is not nullptr, widths must be an array of count entries.
357+
if bounds is not nullptr, bounds must be an array of count entries.
358+
359+
@param glyphs array of glyph indices to be measured
360+
@param count number of glyphs
361+
@param widths returns text advances for each glyph
362+
*/
363+
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[]) const {
364+
this->getWidthsBounds(glyphs, count, widths, nullptr, nullptr);
365+
}
366+
367+
/** Experimental.
368+
Retrieves the advance and bounds for each glyph in glyphs.
369+
Both widths and bounds may be nullptr.
370+
If widths is not nullptr, widths must be an array of count entries.
371+
if bounds is not nullptr, bounds must be an array of count entries.
372+
373+
@param glyphs array of glyph indices to be measured
374+
@param count number of glyphs
375+
@param widths returns text advances for each glyph; may be nullptr
376+
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
377+
@param paint optional, specifies stroking, patheffect and maskfilter
378+
*/
379+
void getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
380+
const SkPaint* paint) const;
381+
382+
383+
/** Experimental.
384+
Retrieves the bounds for each glyph in glyphs.
385+
bounds must be an array of count entries.
386+
If paint is not nullptr, its stroking, patheffect and maskfilter fields will be respected.
387+
388+
@param glyphs array of glyph indices to be measured
389+
@param count number of glyphs
390+
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
391+
@param paint optional, specifies stroking, patheffect and maskfilter
392+
*/
393+
void getBounds(const uint16_t glyphs[], int count, SkRect bounds[], const SkPaint* paint) const {
394+
this->getWidthsBounds(glyphs, count, nullptr, bounds, paint);
395+
}
345396

346397
/** Experimental
347398
Retrieves the positions for each glyph, beginning at the specified origin. The caller

src/core/SkFont.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ static SkRect make_bounds(const SkGlyph& g, SkScalar scale) {
302302
}
303303

304304
template <typename HANDLER>
305-
void VisitGlyphs(const SkFont& origFont, const uint16_t glyphs[], int count, HANDLER handler) {
305+
void VisitGlyphs(const SkFont& origFont, const SkPaint* paint, const uint16_t glyphs[], int count,
306+
HANDLER handler) {
306307
if (count <= 0) {
307308
return;
308309
}
@@ -314,12 +315,14 @@ void VisitGlyphs(const SkFont& origFont, const uint16_t glyphs[], int count, HAN
314315
scale = 1;
315316
}
316317

317-
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font);
318+
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font,
319+
paint ? *paint : SkPaint());
318320
handler(cache.get(), glyphs, count, scale);
319321
}
320322

321-
void SkFont::getWidths(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
322-
VisitGlyphs(*this, glyphs, count, [widths, bounds]
323+
void SkFont::getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
324+
const SkPaint* paint) const {
325+
VisitGlyphs(*this, paint, glyphs, count, [widths, bounds]
323326
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
324327
for (int i = 0; i < count; ++i) {
325328
const SkGlyph* g;
@@ -337,7 +340,7 @@ void SkFont::getWidths(const uint16_t glyphs[], int count, SkScalar widths[], Sk
337340
}
338341

339342
void SkFont::getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint origin) const {
340-
VisitGlyphs(*this, glyphs, count, [pos, origin]
343+
VisitGlyphs(*this, nullptr, glyphs, count, [pos, origin]
341344
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
342345
SkPoint loc = origin;
343346
for (int i = 0; i < count; ++i) {
@@ -348,7 +351,7 @@ void SkFont::getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint o
348351
}
349352

350353
void SkFont::getXPos(const uint16_t glyphs[], int count, SkScalar xpos[], SkScalar origin) const {
351-
VisitGlyphs(*this, glyphs, count, [xpos, origin]
354+
VisitGlyphs(*this, nullptr, glyphs, count, [xpos, origin]
352355
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
353356
SkScalar x = origin;
354357
for (int i = 0; i < count; ++i) {

src/core/SkPaint_text.cpp

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -405,63 +405,11 @@ SkScalar SkPaint::getFontMetrics(SkFontMetrics* metrics) const {
405405

406406
///////////////////////////////////////////////////////////////////////////////
407407

408-
static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) {
409-
bounds->set(g.fLeft * scale,
410-
g.fTop * scale,
411-
(g.fLeft + g.fWidth) * scale,
412-
(g.fTop + g.fHeight) * scale);
413-
}
414-
415-
int SkPaint::getTextWidths(const void* textData, size_t byteLength,
416-
SkScalar widths[], SkRect bounds[]) const {
417-
if (0 == byteLength) {
418-
return 0;
419-
}
420-
421-
SkASSERT(textData);
422-
423-
if (nullptr == widths && nullptr == bounds) {
424-
return this->countText(textData, byteLength);
425-
}
426-
427-
SkCanonicalizePaint canon(*this);
428-
const SkPaint& paint = canon.getPaint();
429-
SkScalar scale = canon.getScale();
430-
431-
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
432-
SkFontPriv::GlyphCacheProc glyphCacheProc = SkFontPriv::GetGlyphCacheProc(
433-
static_cast<SkTextEncoding>(paint.getTextEncoding()), nullptr != bounds);
434-
435-
const char* text = (const char*)textData;
436-
const char* stop = text + byteLength;
437-
int count = 0;
438-
439-
if (scale) {
440-
while (text < stop) {
441-
const SkGlyph& g = glyphCacheProc(cache.get(), &text, stop);
442-
if (widths) {
443-
*widths++ = advance(g) * scale;
444-
}
445-
if (bounds) {
446-
set_bounds(g, bounds++, scale);
447-
}
448-
++count;
449-
}
450-
} else {
451-
while (text < stop) {
452-
const SkGlyph& g = glyphCacheProc(cache.get(), &text, stop);
453-
if (widths) {
454-
*widths++ = advance(g);
455-
}
456-
if (bounds) {
457-
set_bounds(g, bounds++);
458-
}
459-
++count;
460-
}
461-
}
462-
463-
SkASSERT(text == stop);
464-
return count;
408+
int SkPaint::getTextWidths(const void* text, size_t len, SkScalar widths[], SkRect bounds[]) const {
409+
const SkFont font = SkFont::LEGACY_ExtractFromPaint(*this);
410+
SkAutoToGlyphs gly(font, text, len, (SkTextEncoding)this->getTextEncoding());
411+
font.getWidthsBounds(gly.glyphs(), gly.count(), widths, bounds, this);
412+
return gly.count();
465413
}
466414

467415
///////////////////////////////////////////////////////////////////////////////

src/core/SkStrikeCache.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,20 @@ auto SkStrikeCache::findOrCreateStrike(
196196
}
197197

198198
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkPaint& paint) {
199-
return FindOrCreateStrikeExclusive(
200-
paint, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
201-
kFakeGammaAndBoostContrast, SkMatrix::I());
199+
return FindOrCreateStrikeWithNoDeviceExclusive(SkFont::LEGACY_ExtractFromPaint(paint), paint);
202200
}
203201

204202
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font) {
203+
return FindOrCreateStrikeWithNoDeviceExclusive(font, SkPaint());
204+
}
205+
206+
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font,
207+
const SkPaint& paint) {
205208
SkAutoDescriptor ad;
206209
SkScalerContextEffects effects;
207-
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(font,
208-
SkPaint(),
209-
SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
210-
kFakeGammaAndBoostContrast, SkMatrix::I(), &ad, &effects);
210+
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(font, paint,
211+
SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
212+
kFakeGammaAndBoostContrast, SkMatrix::I(), &ad, &effects);
211213
auto typeface = SkFontPriv::GetTypefaceOrDefault(font);
212214
return SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface);
213215
}

src/core/SkStrikeCache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class SkStrikeCache {
136136

137137
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont&);
138138

139+
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font,
140+
const SkPaint& paint);
141+
139142
static std::unique_ptr<SkScalerContext> CreateScalerContext(
140143
const SkDescriptor&, const SkScalerContextEffects&, const SkTypeface&);
141144

0 commit comments

Comments
 (0)