Bug 1142982 - implement dominant-baseline=middle properly. r=heycam

This commit is contained in:
Robert Longson 2015-04-08 16:18:33 +01:00
Родитель 0c2e1ab7dd
Коммит 7407a9449d
3 изменённых файлов: 21 добавлений и 4 удалений

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

@ -0,0 +1,10 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -10 20 20" preserveAspectRatio="none"
font-family="sans-serif">
<rect y="-10" width="20" height="20" fill="lime"/>
<text dominant-baseline="middle" fill="red">x</text>
<text y="0.5ex" fill="lime" stroke-width="1" stroke="lime">x</text>
</svg>

После

Ширина:  |  Высота:  |  Размер: 423 B

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

@ -26,6 +26,7 @@ include moz-only/reftest.list
include svg-integration/reftest.list
== altGlyph-01.svg altGlyph-01-ref.svg
== baseline-middle-01.svg pass.svg
== border-radius-01.html pass.svg
== cssComment-in-attribute-01.svg cssComment-in-attribute-01-ref.svg
== clip-01.svg pass.svg

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

@ -337,7 +337,8 @@ IsGlyphPositioningAttribute(nsIAtom* aAttribute)
static nscoord
GetBaselinePosition(nsTextFrame* aFrame,
gfxTextRun* aTextRun,
uint8_t aDominantBaseline)
uint8_t aDominantBaseline,
float aFontSizeScaleFactor)
{
// use a dummy WritingMode, because nsTextFrame::GetLogicalBaseLine
// doesn't use it anyway
@ -356,6 +357,10 @@ GetBaselinePosition(nsTextFrame* aFrame,
case NS_STYLE_DOMINANT_BASELINE_AUTO:
case NS_STYLE_DOMINANT_BASELINE_ALPHABETIC:
return aFrame->GetLogicalBaseline(writingMode);
case NS_STYLE_DOMINANT_BASELINE_MIDDLE:
return aFrame->GetLogicalBaseline(writingMode) -
SVGContentUtils::GetFontXHeight(aFrame) / 2.0 *
aFrame->PresContext()->AppUnitsPerCSSPixel() * aFontSizeScaleFactor;
}
gfxTextRun::Metrics metrics =
@ -367,7 +372,6 @@ GetBaselinePosition(nsTextFrame* aFrame,
case NS_STYLE_DOMINANT_BASELINE_IDEOGRAPHIC:
return metrics.mAscent + metrics.mDescent;
case NS_STYLE_DOMINANT_BASELINE_CENTRAL:
case NS_STYLE_DOMINANT_BASELINE_MIDDLE:
case NS_STYLE_DOMINANT_BASELINE_MATHEMATICAL:
return (metrics.mAscent + metrics.mDescent) / 2.0;
}
@ -1993,7 +1997,8 @@ TextRenderedRunIterator::Next()
frame->EnsureTextRun(nsTextFrame::eInflated);
baseline = GetBaselinePosition(frame,
frame->GetTextRun(nsTextFrame::eInflated),
mFrameIterator.DominantBaseline());
mFrameIterator.DominantBaseline(),
mFontSizeScaleFactor);
// Trim the offset/length to remove any leading/trailing white space.
uint32_t untrimmedOffset = offset;
@ -4607,7 +4612,8 @@ SVGTextFrame::DetermineCharPositions(nsTArray<nsPoint>& aPositions)
if (textRun->IsRightToLeft()) {
position.x += frame->GetRect().width;
}
position.y += GetBaselinePosition(frame, textRun, frit.DominantBaseline());
position.y += GetBaselinePosition(frame, textRun, frit.DominantBaseline(),
mFontSizeScaleFactor);
// Any characters not in a frame, e.g. when display:none.
for (uint32_t i = 0; i < frit.UndisplayedCharacters(); i++) {