Revert "migrate to passing paint/ctm for bounds"
This reverts commit d5ed3dafb2
.
Reason for revert: goofed up, passing default paint instead of real one
Original change's description:
> migrate to passing paint/ctm for bounds
>
> Some of this is left in for migrating callers (see docs)
>
> - want getWidths to just take widths (and no paint)
> - want getBounds to just take bounds AND paint
> - want getWidthsBounds to take it all
>
> Bug: skia:
> Change-Id: I498cd8295b90995c45237d3cf39fc097252f485e
> Reviewed-on: https://skia-review.googlesource.com/c/172868
> Reviewed-by: Ben Wagner <bungeman@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
TBR=bungeman@google.com,herb@google.com,reed@google.com
Change-Id: Ifa827d824f0f0ef63308e5cc1fe579b1b14df616
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/172975
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
ad5f069490
commit
914d319a02
@ -330,8 +330,7 @@ public:
|
||||
SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
|
||||
SkRect* bounds = nullptr) const;
|
||||
|
||||
/** DEPRECATED
|
||||
Retrieves the advance and bounds for each glyph in glyphs.
|
||||
/** Retrieves the advance and bounds for each glyph in glyphs.
|
||||
Both widths and bounds may be nullptr.
|
||||
If widths is not nullptr, widths must be an array of count entries.
|
||||
if bounds is not nullptr, bounds must be an array of count entries.
|
||||
@ -341,58 +340,8 @@ public:
|
||||
@param widths returns text advances for each glyph; may be nullptr
|
||||
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
|
||||
*/
|
||||
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
|
||||
this->getWidthsBounds(glyphs, count, widths, bounds, nullptr);
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[], std::nullptr_t) const {
|
||||
this->getWidths(glyphs, count, widths);
|
||||
}
|
||||
|
||||
/** Experimental
|
||||
Retrieves the advance and bounds for each glyph in glyphs.
|
||||
Both widths and bounds may be nullptr.
|
||||
If widths is not nullptr, widths must be an array of count entries.
|
||||
if bounds is not nullptr, bounds must be an array of count entries.
|
||||
|
||||
@param glyphs array of glyph indices to be measured
|
||||
@param count number of glyphs
|
||||
@param widths returns text advances for each glyph
|
||||
*/
|
||||
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[]) const {
|
||||
this->getWidthsBounds(glyphs, count, widths, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/** Experimental.
|
||||
Retrieves the advance and bounds for each glyph in glyphs.
|
||||
Both widths and bounds may be nullptr.
|
||||
If widths is not nullptr, widths must be an array of count entries.
|
||||
if bounds is not nullptr, bounds must be an array of count entries.
|
||||
|
||||
@param glyphs array of glyph indices to be measured
|
||||
@param count number of glyphs
|
||||
@param widths returns text advances for each glyph; may be nullptr
|
||||
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
|
||||
@param paint optional, specifies stroking, patheffect and maskfilter
|
||||
*/
|
||||
void getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
|
||||
const SkPaint* paint) const;
|
||||
|
||||
|
||||
/** Experimental.
|
||||
Retrieves the bounds for each glyph in glyphs.
|
||||
bounds must be an array of count entries.
|
||||
If paint is not nullptr, its stroking, patheffect and maskfilter fields will be respected.
|
||||
|
||||
@param glyphs array of glyph indices to be measured
|
||||
@param count number of glyphs
|
||||
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
|
||||
@param paint optional, specifies stroking, patheffect and maskfilter
|
||||
*/
|
||||
void getBounds(const uint16_t glyphs[], int count, SkRect bounds[], const SkPaint* paint) const {
|
||||
this->getWidthsBounds(glyphs, count, nullptr, bounds, paint);
|
||||
}
|
||||
void getWidths(const uint16_t glyphs[], int count, SkScalar widths[],
|
||||
SkRect bounds[] = nullptr) const;
|
||||
|
||||
/** Experimental
|
||||
Retrieves the positions for each glyph, beginning at the specified origin. The caller
|
||||
|
@ -302,8 +302,7 @@ static SkRect make_bounds(const SkGlyph& g, SkScalar scale) {
|
||||
}
|
||||
|
||||
template <typename HANDLER>
|
||||
void VisitGlyphs(const SkFont& origFont, const SkPaint* paint, const uint16_t glyphs[], int count,
|
||||
HANDLER handler) {
|
||||
void VisitGlyphs(const SkFont& origFont, const uint16_t glyphs[], int count, HANDLER handler) {
|
||||
if (count <= 0) {
|
||||
return;
|
||||
}
|
||||
@ -315,14 +314,12 @@ void VisitGlyphs(const SkFont& origFont, const SkPaint* paint, const uint16_t gl
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font,
|
||||
paint ? *paint : SkPaint());
|
||||
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font);
|
||||
handler(cache.get(), glyphs, count, scale);
|
||||
}
|
||||
|
||||
void SkFont::getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
|
||||
const SkPaint* paint) const {
|
||||
VisitGlyphs(*this, paint, glyphs, count, [widths, bounds]
|
||||
void SkFont::getWidths(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
|
||||
VisitGlyphs(*this, glyphs, count, [widths, bounds]
|
||||
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const SkGlyph* g;
|
||||
@ -340,7 +337,7 @@ void SkFont::getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths
|
||||
}
|
||||
|
||||
void SkFont::getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint origin) const {
|
||||
VisitGlyphs(*this, nullptr, glyphs, count, [pos, origin]
|
||||
VisitGlyphs(*this, glyphs, count, [pos, origin]
|
||||
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
|
||||
SkPoint loc = origin;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
@ -351,7 +348,7 @@ void SkFont::getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint o
|
||||
}
|
||||
|
||||
void SkFont::getXPos(const uint16_t glyphs[], int count, SkScalar xpos[], SkScalar origin) const {
|
||||
VisitGlyphs(*this, nullptr, glyphs, count, [xpos, origin]
|
||||
VisitGlyphs(*this, glyphs, count, [xpos, origin]
|
||||
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
|
||||
SkScalar x = origin;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
@ -405,11 +405,63 @@ SkScalar SkPaint::getFontMetrics(SkFontMetrics* metrics) const {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int SkPaint::getTextWidths(const void* text, size_t len, SkScalar widths[], SkRect bounds[]) const {
|
||||
const SkFont font = SkFont::LEGACY_ExtractFromPaint(*this);
|
||||
SkAutoToGlyphs gly(font, text, len, (SkTextEncoding)this->getTextEncoding());
|
||||
font.getWidthsBounds(gly.glyphs(), gly.count(), widths, bounds, this);
|
||||
return gly.count();
|
||||
static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) {
|
||||
bounds->set(g.fLeft * scale,
|
||||
g.fTop * scale,
|
||||
(g.fLeft + g.fWidth) * scale,
|
||||
(g.fTop + g.fHeight) * scale);
|
||||
}
|
||||
|
||||
int SkPaint::getTextWidths(const void* textData, size_t byteLength,
|
||||
SkScalar widths[], SkRect bounds[]) const {
|
||||
if (0 == byteLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SkASSERT(textData);
|
||||
|
||||
if (nullptr == widths && nullptr == bounds) {
|
||||
return this->countText(textData, byteLength);
|
||||
}
|
||||
|
||||
SkCanonicalizePaint canon(*this);
|
||||
const SkPaint& paint = canon.getPaint();
|
||||
SkScalar scale = canon.getScale();
|
||||
|
||||
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
|
||||
SkFontPriv::GlyphCacheProc glyphCacheProc = SkFontPriv::GetGlyphCacheProc(
|
||||
static_cast<SkTextEncoding>(paint.getTextEncoding()), nullptr != bounds);
|
||||
|
||||
const char* text = (const char*)textData;
|
||||
const char* stop = text + byteLength;
|
||||
int count = 0;
|
||||
|
||||
if (scale) {
|
||||
while (text < stop) {
|
||||
const SkGlyph& g = glyphCacheProc(cache.get(), &text, stop);
|
||||
if (widths) {
|
||||
*widths++ = advance(g) * scale;
|
||||
}
|
||||
if (bounds) {
|
||||
set_bounds(g, bounds++, scale);
|
||||
}
|
||||
++count;
|
||||
}
|
||||
} else {
|
||||
while (text < stop) {
|
||||
const SkGlyph& g = glyphCacheProc(cache.get(), &text, stop);
|
||||
if (widths) {
|
||||
*widths++ = advance(g);
|
||||
}
|
||||
if (bounds) {
|
||||
set_bounds(g, bounds++);
|
||||
}
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
SkASSERT(text == stop);
|
||||
return count;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -196,21 +196,18 @@ auto SkStrikeCache::findOrCreateStrike(
|
||||
}
|
||||
|
||||
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkPaint& paint) {
|
||||
return FindOrCreateStrikeWithNoDeviceExclusive(SkFont::LEGACY_ExtractFromPaint(paint),
|
||||
SkPaint());
|
||||
return FindOrCreateStrikeExclusive(
|
||||
paint, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
|
||||
kFakeGammaAndBoostContrast, SkMatrix::I());
|
||||
}
|
||||
|
||||
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font) {
|
||||
return FindOrCreateStrikeWithNoDeviceExclusive(font, SkPaint());
|
||||
}
|
||||
|
||||
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font,
|
||||
const SkPaint& paint) {
|
||||
SkAutoDescriptor ad;
|
||||
SkScalerContextEffects effects;
|
||||
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(font, paint,
|
||||
SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
|
||||
kFakeGammaAndBoostContrast, SkMatrix::I(), &ad, &effects);
|
||||
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(font,
|
||||
SkPaint(),
|
||||
SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
|
||||
kFakeGammaAndBoostContrast, SkMatrix::I(), &ad, &effects);
|
||||
auto typeface = SkFontPriv::GetTypefaceOrDefault(font);
|
||||
return SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface);
|
||||
}
|
||||
|
@ -136,9 +136,6 @@ public:
|
||||
|
||||
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont&);
|
||||
|
||||
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font,
|
||||
const SkPaint& paint);
|
||||
|
||||
static std::unique_ptr<SkScalerContext> CreateScalerContext(
|
||||
const SkDescriptor&, const SkScalerContextEffects&, const SkTypeface&);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user