Bug 1603629 - fix dominant-baseline hanging and mathematical r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D88877
This commit is contained in:
longsonr 2020-09-04 11:00:40 +00:00
Родитель 77af5a272b
Коммит 1d904c3e45
3 изменённых файлов: 55 добавлений и 1 удалений

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

@ -485,6 +485,7 @@ random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-layout-05.svg text-
fuzzy-if(cocoaWidget&&layersGPUAccelerated,0-1,0-3) random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-layout-06.svg text-layout-06-ref.svg # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-layout-07.svg text-layout-07-ref.svg # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-layout-08.svg text-layout-08-ref.svg # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-layout-09.svg pass.svg # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-scale-01.svg text-scale-01-ref.svg # Bug 1392106
fuzzy-if(skiaContent,0-2,0-1000) random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-scale-02.svg text-scale-02-ref.svg # Bug 1392106
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == text-scale-03.svg text-scale-03-ref.svg # Bug 1392106

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

@ -0,0 +1,51 @@
<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" class="reftest-wait">
<foreignObject><canvas xmlns="http://www.w3.org/1999/xhtml" id="canvas"/></foreignObject>
<rect width="100%" height="100%" fill="lime"/>
<g fill="red">
<text dominant-baseline="hanging" x="70" y="70">hanging</text>
<text dominant-baseline="mathematical" x="70" y="140">mathematical</text>
</g>
<g fill="lime">
<text id="hanging" x="70" y="70" dy="0">hanging</text>
<text id="mathematical" x="70" y="140" dy="0">mathematical</text>
</g>
<style><![CDATA[
text {
font: bold 30px Verdana, Helvetica, Arial, sans-serif;
}
]]></style>
<script>
function cover(element) {
let rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
let bbox = element.getBBox();
rect.x.baseVal.value = bbox.x;
rect.y.baseVal.value = bbox.y;
rect.width.baseVal.value = bbox.width;
rect.height.baseVal.value = bbox.height;
element.parentElement.appendChild(rect);
}
onload = function() {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.font = 'bold 30px Verdana, Helvetica, Arial, sans-serif';
let text = 'h';
let textMetrics = ctx.measureText(text);
let hanging = document.getElementById("hanging");
hanging.dy.baseVal[0].value = textMetrics.actualBoundingBoxAscent * 1.1;
cover(hanging);
let mathematical = document.getElementById("mathematical");
mathematical.dy.baseVal[0].value = textMetrics.actualBoundingBoxAscent / 2 * 1.4;
cover(mathematical);
document.documentElement.removeAttribute('class');
}
</script>
</svg>

После

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

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

@ -286,6 +286,7 @@ static nscoord GetBaselinePosition(nsTextFrame* aFrame, gfxTextRun* aTextRun,
switch (aDominantBaseline) {
case StyleDominantBaseline::Hanging:
return metrics.mAscent * 0.2;
case StyleDominantBaseline::TextBeforeEdge:
return writingMode.IsVerticalRL() ? metrics.mAscent + metrics.mDescent
: 0;
@ -308,8 +309,9 @@ static nscoord GetBaselinePosition(nsTextFrame* aFrame, gfxTextRun* aTextRun,
: metrics.mAscent + metrics.mDescent;
case StyleDominantBaseline::Central:
case StyleDominantBaseline::Mathematical:
return (metrics.mAscent + metrics.mDescent) / 2.0;
case StyleDominantBaseline::Mathematical:
return metrics.mAscent / 2.0;
}
MOZ_ASSERT_UNREACHABLE("unexpected dominant-baseline value");