Bug 1081867 - Convert textrun metrics to physical coordinates before merging with visual-overflow region. r=smontagu

This commit is contained in:
Jonathan Kew 2014-10-16 09:40:19 +01:00
parent 9d676614ce
commit 0e773b6fc0
11 changed files with 54 additions and 21 deletions

View File

@ -552,11 +552,13 @@ gfxDWriteFont::Measure(gfxTextRun *aTextRun,
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aRefContext,
Spacing *aSpacing)
Spacing *aSpacing,
uint16_t aOrientation)
{
gfxFont::RunMetrics metrics =
gfxFont::Measure(aTextRun, aStart, aEnd,
aBoundingBoxType, aRefContext, aSpacing);
aBoundingBoxType, aRefContext, aSpacing,
aOrientation);
// if aBoundingBoxType is LOOSE_INK_EXTENTS
// and the underlying cairo font may be antialiased,

View File

@ -49,7 +49,8 @@ public:
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aContextForTightBoundingBox,
Spacing *aSpacing);
Spacing *aSpacing,
uint16_t aOrientation);
virtual bool ProvidesGlyphWidths() const;

View File

@ -2103,7 +2103,8 @@ gfxFont::Measure(gfxTextRun *aTextRun,
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aRefContext,
Spacing *aSpacing)
Spacing *aSpacing,
uint16_t aOrientation)
{
// If aBoundingBoxType is TIGHT_HINTED_OUTLINE_EXTENTS
// and the underlying cairo font may be antialiased,
@ -2119,14 +2120,15 @@ gfxFont::Measure(gfxTextRun *aTextRun,
if (mNonAAFont) {
return mNonAAFont->Measure(aTextRun, aStart, aEnd,
TIGHT_HINTED_OUTLINE_EXTENTS,
aRefContext, aSpacing);
aRefContext, aSpacing, aOrientation);
}
}
const int32_t appUnitsPerDevUnit = aTextRun->GetAppUnitsPerDevUnit();
// Current position in appunits
gfxFont::Orientation orientation =
aTextRun->IsVertical() ? gfxFont::eVertical : gfxFont::eHorizontal;
aOrientation == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT
? gfxFont::eVertical : gfxFont::eHorizontal;
const gfxFont::Metrics& fontMetrics = GetMetrics(orientation);
RunMetrics metrics;

View File

@ -1556,7 +1556,7 @@ public:
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aContextForTightBoundingBox,
Spacing *aSpacing);
Spacing *aSpacing, uint16_t aOrientation);
/**
* Line breaks have been changed at the beginning and/or end of a substring
* of the text. Reshaping may be required; glyph updating is permitted.

View File

@ -145,11 +145,13 @@ gfxGDIFont::Measure(gfxTextRun *aTextRun,
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aRefContext,
Spacing *aSpacing)
Spacing *aSpacing,
uint16_t aOrientation)
{
gfxFont::RunMetrics metrics =
gfxFont::Measure(aTextRun, aStart, aEnd,
aBoundingBoxType, aRefContext, aSpacing);
aBoundingBoxType, aRefContext, aSpacing,
aOrientation);
// if aBoundingBoxType is LOOSE_INK_EXTENTS
// and the underlying cairo font may be antialiased,

View File

@ -43,7 +43,8 @@ public:
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aContextForTightBoundingBox,
Spacing *aSpacing);
Spacing *aSpacing,
uint16_t aOrientation);
/* required for MathML to suppress effects of ClearType "padding" */
virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption);

View File

@ -167,11 +167,13 @@ gfxMacFont::Measure(gfxTextRun *aTextRun,
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aRefContext,
Spacing *aSpacing)
Spacing *aSpacing,
uint16_t aOrientation)
{
gfxFont::RunMetrics metrics =
gfxFont::Measure(aTextRun, aStart, aEnd,
aBoundingBoxType, aRefContext, aSpacing);
aBoundingBoxType, aRefContext, aSpacing,
aOrientation);
// if aBoundingBoxType is not TIGHT_HINTED_OUTLINE_EXTENTS then we need to add
// a pixel column each side of the bounding box in case of antialiasing "bleed"

View File

@ -35,7 +35,7 @@ public:
uint32_t aStart, uint32_t aEnd,
BoundingBoxType aBoundingBoxType,
gfxContext *aContextForTightBoundingBox,
Spacing *aSpacing);
Spacing *aSpacing, uint16_t aOrientation);
virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont> GetScaledFont(mozilla::gfx::DrawTarget *aTarget);

View File

@ -690,13 +690,15 @@ gfxTextRun::AccumulateMetricsForRun(gfxFont *aFont,
gfxContext *aRefContext,
PropertyProvider *aProvider,
uint32_t aSpacingStart, uint32_t aSpacingEnd,
uint16_t aOrientation,
Metrics *aMetrics)
{
nsAutoTArray<PropertyProvider::Spacing,200> spacingBuffer;
bool haveSpacing = GetAdjustedSpacingArray(aStart, aEnd, aProvider,
aSpacingStart, aSpacingEnd, &spacingBuffer);
Metrics metrics = aFont->Measure(this, aStart, aEnd, aBoundingBoxType, aRefContext,
haveSpacing ? spacingBuffer.Elements() : nullptr);
haveSpacing ? spacingBuffer.Elements() : nullptr,
aOrientation);
aMetrics->CombineWith(metrics, IsRightToLeft());
}
@ -704,7 +706,7 @@ void
gfxTextRun::AccumulatePartialLigatureMetrics(gfxFont *aFont,
uint32_t aStart, uint32_t aEnd,
gfxFont::BoundingBoxType aBoundingBoxType, gfxContext *aRefContext,
PropertyProvider *aProvider, Metrics *aMetrics)
PropertyProvider *aProvider, uint16_t aOrientation, Metrics *aMetrics)
{
if (aStart >= aEnd)
return;
@ -717,7 +719,7 @@ gfxTextRun::AccumulatePartialLigatureMetrics(gfxFont *aFont,
Metrics metrics;
AccumulateMetricsForRun(aFont, data.mLigatureStart, data.mLigatureEnd,
aBoundingBoxType, aRefContext,
aProvider, aStart, aEnd, &metrics);
aProvider, aStart, aEnd, aOrientation, &metrics);
// Clip the bounding box to the ligature part
gfxFloat bboxLeft = metrics.mBoundingBox.X();
@ -757,7 +759,8 @@ gfxTextRun::MeasureText(uint32_t aStart, uint32_t aLength,
ShrinkToLigatureBoundaries(&ligatureRunStart, &ligatureRunEnd);
AccumulatePartialLigatureMetrics(font, start, ligatureRunStart,
aBoundingBoxType, aRefContext, aProvider, &accumulatedMetrics);
aBoundingBoxType, aRefContext, aProvider,
iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
// XXX This sucks. We have to get glyph extents just so we can detect
// glyphs outside the font box, even when aBoundingBoxType is LOOSE,
@ -767,10 +770,11 @@ gfxTextRun::MeasureText(uint32_t aStart, uint32_t aLength,
AccumulateMetricsForRun(font,
ligatureRunStart, ligatureRunEnd, aBoundingBoxType,
aRefContext, aProvider, ligatureRunStart, ligatureRunEnd,
&accumulatedMetrics);
iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
AccumulatePartialLigatureMetrics(font, ligatureRunEnd, end,
aBoundingBoxType, aRefContext, aProvider, &accumulatedMetrics);
aBoundingBoxType, aRefContext, aProvider,
iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
}
return accumulatedMetrics;

View File

@ -684,6 +684,7 @@ private:
gfxFont::BoundingBoxType aBoundingBoxType,
gfxContext *aRefContext,
PropertyProvider *aProvider,
uint16_t aOrientation,
Metrics *aMetrics);
// **** measurement helper ****
@ -692,6 +693,7 @@ private:
gfxContext *aRefContext,
PropertyProvider *aProvider,
uint32_t aSpacingStart, uint32_t aSpacingEnd,
uint16_t aOrientation,
Metrics *aMetrics);
// **** drawing helper ****

View File

@ -7578,7 +7578,13 @@ nsTextFrame::ComputeTightBounds(gfxContext* aContext) const
aContext, &provider);
// mAscent should be the same as metrics.mAscent, but it's what we use to
// paint so that's the one we'll use.
return RoundOut(metrics.mBoundingBox) + nsPoint(0, mAscent);
nsRect boundingBox = RoundOut(metrics.mBoundingBox) + nsPoint(0, mAscent);
if (mTextRun->IsVertical()) {
// Swap line-relative textMetrics dimensions to physical coordinates.
Swap(boundingBox.x, boundingBox.y);
Swap(boundingBox.width, boundingBox.height);
}
return boundingBox;
}
/* virtual */ nsresult
@ -8284,6 +8290,11 @@ nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
// Handle text that runs outside its normal bounds.
nsRect boundingBox = RoundOut(textMetrics.mBoundingBox) + nsPoint(0, mAscent);
aMetrics.SetOverflowAreasToDesiredBounds();
if (mTextRun->IsVertical()) {
// Swap line-relative textMetrics dimensions to physical coordinates.
Swap(boundingBox.x, boundingBox.y);
Swap(boundingBox.width, boundingBox.height);
}
aMetrics.VisualOverflow().UnionRect(aMetrics.VisualOverflow(), boundingBox);
// When we have text decorations, we don't need to compute their overflow now
@ -8530,7 +8541,13 @@ nsTextFrame::RecomputeOverflow(const nsHTMLReflowState& aBlockReflowState)
gfxFont::LOOSE_INK_EXTENTS, nullptr,
&provider);
nsRect &vis = result.VisualOverflow();
vis.UnionRect(vis, RoundOut(textMetrics.mBoundingBox) + nsPoint(0, mAscent));
nsRect boundingBox = RoundOut(textMetrics.mBoundingBox) + nsPoint(0, mAscent);
if (mTextRun->IsVertical()) {
// Swap line-relative textMetrics dimensions to physical coordinates.
Swap(boundingBox.x, boundingBox.y);
Swap(boundingBox.width, boundingBox.height);
}
vis.UnionRect(vis, boundingBox);
UnionAdditionalOverflow(PresContext(), aBlockReflowState.frame, provider,
&vis, true);
return result;