From 23d3ede6fce74f4e07f71b82836990f1e7b2bf10 Mon Sep 17 00:00:00 2001 From: Jeremy Chen Date: Tue, 4 Oct 2016 22:22:52 +0800 Subject: [PATCH] Bug 1307402 - use a more precise bounding box for initial letter texts. r=jfkthame MozReview-Commit-ID: 5OIXp0uQisn --HG-- extra : rebase_source : 00f6a72742c763bb3ec572a08d3cdaf12402d7f6 --- layout/generic/nsFirstLetterFrame.cpp | 8 +++++++- layout/generic/nsTextFrame.cpp | 15 ++++++++++++--- layout/generic/nsTextFrame.h | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/layout/generic/nsFirstLetterFrame.cpp b/layout/generic/nsFirstLetterFrame.cpp index 5ea704a51aef..623e67fcc238 100644 --- a/layout/generic/nsFirstLetterFrame.cpp +++ b/layout/generic/nsFirstLetterFrame.cpp @@ -256,7 +256,13 @@ nsFirstLetterFrame::Reflow(nsPresContext* aPresContext, aMetrics.ISize(lineWM) = ll->EndSpan(this) + bp.IStartEnd(wm); ll->SetInFirstLetter(false); - nsLayoutUtils::SetBSizeFromFontMetrics(this, aMetrics, bp, lineWM, wm); + if (mStyleContext->StyleTextReset()->mInitialLetterSize != 0.0f) { + aMetrics.SetBlockStartAscent(kidMetrics.BlockStartAscent() + + bp.BStart(wm)); + aMetrics.BSize(lineWM) = kidMetrics.BSize(lineWM) + bp.BStartEnd(wm); + } else { + nsLayoutUtils::SetBSizeFromFontMetrics(this, aMetrics, bp, lineWM, wm); + } } if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) { diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index a4175e9193fa..09b284238930 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -8772,6 +8772,14 @@ nsTextFrame::IsFloatingFirstLetterChild() const frame->GetType() == nsGkAtoms::letterFrame; } +bool +nsTextFrame::IsInitialLetterChild() const +{ + nsIFrame* frame = GetParent(); + return frame && frame->StyleTextReset()->mInitialLetterSize != 0.0f && + frame->GetType() == nsGkAtoms::letterFrame; +} + struct NewlineProperty { int32_t mStartOffset; // The offset of the first \n after mStartOffset, or -1 if there is none @@ -9050,9 +9058,10 @@ nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth, // The metrics for the text go in here gfxTextRun::Metrics textMetrics; - gfxFont::BoundingBoxType boundingBoxType = IsFloatingFirstLetterChild() ? - gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS : - gfxFont::LOOSE_INK_EXTENTS; + gfxFont::BoundingBoxType boundingBoxType = + IsFloatingFirstLetterChild() || IsInitialLetterChild() + ? gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS + : gfxFont::LOOSE_INK_EXTENTS; NS_ASSERTION(!(NS_REFLOW_CALC_BOUNDING_METRICS & aMetrics.mFlags), "We shouldn't be passed NS_REFLOW_CALC_BOUNDING_METRICS anymore"); diff --git a/layout/generic/nsTextFrame.h b/layout/generic/nsTextFrame.h index 0df69552e5eb..0f2744b1f1c3 100644 --- a/layout/generic/nsTextFrame.h +++ b/layout/generic/nsTextFrame.h @@ -587,6 +587,8 @@ public: bool IsFloatingFirstLetterChild() const; + bool IsInitialLetterChild() const; + virtual bool ComputeCustomOverflow(nsOverflowAreas& aOverflowAreas) override; void AssignJustificationGaps(const mozilla::JustificationAssignment& aAssign);