Bug 1765093 - patch 2 - Make ShrinkToLigatureBoundaries return whether any adjustment was made, so callers can skip redundant calls to partial-ligature code. r=gfx-reviewers,lsalzman

This allows a number of callers to skip calling partial-ligature functions
altogether if the ranges are known to be empty, which should be a minor win.

Depends on D145631

Differential Revision: https://phabricator.services.mozilla.com/D145632
This commit is contained in:
Jonathan Kew 2022-05-06 17:47:23 +00:00
Родитель a29c0bcdbe
Коммит 6e0eb71134
2 изменённых файлов: 48 добавлений и 32 удалений

Просмотреть файл

@ -409,21 +409,26 @@ bool gfxTextRun::GetAdjustedSpacingArray(
return true; return true;
} }
void gfxTextRun::ShrinkToLigatureBoundaries(Range* aRange) const { bool gfxTextRun::ShrinkToLigatureBoundaries(Range* aRange) const {
if (aRange->start >= aRange->end) return; if (aRange->start >= aRange->end) {
return false;
}
const CompressedGlyph* charGlyphs = mCharacterGlyphs; const CompressedGlyph* charGlyphs = mCharacterGlyphs;
bool adjusted = false;
while (aRange->start < aRange->end && while (aRange->start < aRange->end &&
!charGlyphs[aRange->start].IsLigatureGroupStart()) { !charGlyphs[aRange->start].IsLigatureGroupStart()) {
++aRange->start; ++aRange->start;
adjusted = true;
} }
if (aRange->end < GetLength()) { if (aRange->end < GetLength()) {
while (aRange->end > aRange->start && while (aRange->end > aRange->start &&
!charGlyphs[aRange->end].IsLigatureGroupStart()) { !charGlyphs[aRange->end].IsLigatureGroupStart()) {
--aRange->end; --aRange->end;
adjusted = true;
} }
} }
return adjusted;
} }
void gfxTextRun::DrawGlyphs(gfxFont* aFont, Range aRange, gfx::Point* aPt, void gfxTextRun::DrawGlyphs(gfxFont* aFont, Range aRange, gfx::Point* aPt,
@ -669,11 +674,12 @@ void gfxTextRun::Draw(const Range aRange, const gfx::Point aPt,
} }
Range ligatureRange(runRange); Range ligatureRange(runRange);
ShrinkToLigatureBoundaries(&ligatureRange); bool adjusted = ShrinkToLigatureBoundaries(&ligatureRange);
bool drawPartial = bool drawPartial =
(aParams.drawMode & (DrawMode::GLYPH_FILL | DrawMode::GLYPH_STROKE)) || adjusted &&
(aParams.drawMode == DrawMode::GLYPH_PATH && aParams.callbacks); ((aParams.drawMode & (DrawMode::GLYPH_FILL | DrawMode::GLYPH_STROKE)) ||
(aParams.drawMode == DrawMode::GLYPH_PATH && aParams.callbacks));
gfx::Point origPt = pt; gfx::Point origPt = pt;
if (drawPartial) { if (drawPartial) {
@ -731,11 +737,13 @@ void gfxTextRun::DrawEmphasisMarks(gfxContext* aContext, gfxTextRun* aMark,
uint32_t start = iter.GetStringStart(); uint32_t start = iter.GetStringStart();
uint32_t end = iter.GetStringEnd(); uint32_t end = iter.GetStringEnd();
Range ligatureRange(start, end); Range ligatureRange(start, end);
ShrinkToLigatureBoundaries(&ligatureRange); bool adjusted = ShrinkToLigatureBoundaries(&ligatureRange);
if (adjusted) {
inlineCoord += inlineCoord +=
direction * ComputePartialLigatureWidth( direction * ComputePartialLigatureWidth(
Range(start, ligatureRange.start), aProvider); Range(start, ligatureRange.start), aProvider);
}
AutoTArray<PropertyProvider::Spacing, 200> spacingBuffer; AutoTArray<PropertyProvider::Spacing, 200> spacingBuffer;
bool haveSpacing = GetAdjustedSpacingArray(ligatureRange, aProvider, bool haveSpacing = GetAdjustedSpacingArray(ligatureRange, aProvider,
@ -744,9 +752,11 @@ void gfxTextRun::DrawEmphasisMarks(gfxContext* aContext, gfxTextRun* aMark,
font->DrawEmphasisMarks(this, &aPt, ligatureRange.start, font->DrawEmphasisMarks(this, &aPt, ligatureRange.start,
ligatureRange.Length(), params); ligatureRange.Length(), params);
if (adjusted) {
inlineCoord += direction * ComputePartialLigatureWidth( inlineCoord += direction * ComputePartialLigatureWidth(
Range(ligatureRange.end, end), aProvider); Range(ligatureRange.end, end), aProvider);
} }
}
} }
void gfxTextRun::AccumulateMetricsForRun( void gfxTextRun::AccumulateMetricsForRun(
@ -810,12 +820,17 @@ gfxTextRun::Metrics gfxTextRun::MeasureText(
uint32_t start = iter.GetStringStart(); uint32_t start = iter.GetStringStart();
uint32_t end = iter.GetStringEnd(); uint32_t end = iter.GetStringEnd();
Range ligatureRange(start, end); Range ligatureRange(start, end);
ShrinkToLigatureBoundaries(&ligatureRange); bool adjusted = ShrinkToLigatureBoundaries(&ligatureRange);
if (adjusted) {
AccumulatePartialLigatureMetrics( AccumulatePartialLigatureMetrics(
font, Range(start, ligatureRange.start), aBoundingBoxType, font, Range(start, ligatureRange.start), aBoundingBoxType,
aRefDrawTarget, aProvider, iter.GetGlyphRun()->mOrientation, aRefDrawTarget, aProvider, iter.GetGlyphRun()->mOrientation,
&accumulatedMetrics); &accumulatedMetrics);
AccumulatePartialLigatureMetrics(
font, Range(ligatureRange.end, end), aBoundingBoxType, aRefDrawTarget,
aProvider, iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
}
// XXX This sucks. We have to get glyph extents just so we can detect // XXX This sucks. We have to get glyph extents just so we can detect
// glyphs outside the font box, even when aBoundingBoxType is LOOSE, // glyphs outside the font box, even when aBoundingBoxType is LOOSE,
@ -825,10 +840,6 @@ gfxTextRun::Metrics gfxTextRun::MeasureText(
AccumulateMetricsForRun( AccumulateMetricsForRun(
font, ligatureRange, aBoundingBoxType, aRefDrawTarget, aProvider, font, ligatureRange, aBoundingBoxType, aRefDrawTarget, aProvider,
ligatureRange, iter.GetGlyphRun()->mOrientation, &accumulatedMetrics); ligatureRange, iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
AccumulatePartialLigatureMetrics(
font, Range(ligatureRange.end, end), aBoundingBoxType, aRefDrawTarget,
aProvider, iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
} }
return accumulatedMetrics; return accumulatedMetrics;
@ -1207,12 +1218,14 @@ gfxFloat gfxTextRun::GetAdvanceWidth(
NS_ASSERTION(aRange.end <= GetLength(), "Substring out of range"); NS_ASSERTION(aRange.end <= GetLength(), "Substring out of range");
Range ligatureRange = aRange; Range ligatureRange = aRange;
ShrinkToLigatureBoundaries(&ligatureRange); bool adjusted = ShrinkToLigatureBoundaries(&ligatureRange);
gfxFloat result = ComputePartialLigatureWidth( gfxFloat result =
adjusted ? ComputePartialLigatureWidth(
Range(aRange.start, ligatureRange.start), aProvider) + Range(aRange.start, ligatureRange.start), aProvider) +
ComputePartialLigatureWidth( ComputePartialLigatureWidth(
Range(ligatureRange.end, aRange.end), aProvider); Range(ligatureRange.end, aRange.end), aProvider)
: 0.0;
if (aSpacing) { if (aSpacing) {
aSpacing->mBefore = aSpacing->mAfter = 0; aSpacing->mBefore = aSpacing->mAfter = 0;
@ -1244,13 +1257,15 @@ gfxFloat gfxTextRun::GetMinAdvanceWidth(Range aRange) {
MOZ_ASSERT(aRange.end <= GetLength(), "Substring out of range"); MOZ_ASSERT(aRange.end <= GetLength(), "Substring out of range");
Range ligatureRange = aRange; Range ligatureRange = aRange;
ShrinkToLigatureBoundaries(&ligatureRange); bool adjusted = ShrinkToLigatureBoundaries(&ligatureRange);
gfxFloat result = gfxFloat result =
std::max(ComputePartialLigatureWidth( adjusted
? std::max(ComputePartialLigatureWidth(
Range(aRange.start, ligatureRange.start), nullptr), Range(aRange.start, ligatureRange.start), nullptr),
ComputePartialLigatureWidth(Range(ligatureRange.end, aRange.end), ComputePartialLigatureWidth(
nullptr)); Range(ligatureRange.end, aRange.end), nullptr))
: 0.0;
// Compute min advance width by assuming each grapheme cluster takes its own // Compute min advance width by assuming each grapheme cluster takes its own
// line. // line.

Просмотреть файл

@ -830,7 +830,8 @@ class gfxTextRun : public gfxShapedText {
// Advance aRange.start to the start of the nearest ligature, back // Advance aRange.start to the start of the nearest ligature, back
// up aRange.end to the nearest ligature end; may result in // up aRange.end to the nearest ligature end; may result in
// aRange->start == aRange->end. // aRange->start == aRange->end.
void ShrinkToLigatureBoundaries(Range* aRange) const; // Returns whether any adjustment was made.
bool ShrinkToLigatureBoundaries(Range* aRange) const;
// result in appunits // result in appunits
gfxFloat GetPartialLigatureWidth(Range aRange, gfxFloat GetPartialLigatureWidth(Range aRange,
PropertyProvider* aProvider) const; PropertyProvider* aProvider) const;