Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mathml] Fix offset of vertical glyph assembly
When ShapeResult::CreateForStretchyMathOperator shapes vertical glyph assemblies, the offset of each part is adjusted by the advance specified in the corresponding MathGlyphVariantRecord table [1]. Note that this may be slightly different from the calculated ink height of the glyph, but is faster to get. In any case the baselines of glyphs are used as a reference when setting an offset in ShapeResults, so this CL changes the adjustment to use the glyph ink ascent instead of the glyph ink height. This CL fixes rendering issues for vertical stretchy MathML Operators for fonts like Cambria Math that use non-zero ink descent for parts in a glyph assembly. StretchyOperatorShaperTest.GlyphVariants is tweaked to use an equivalent stretchy.woff font (glyphs have zero ink descent) and a new test StretchyOperatorShaperTest.GlyphVariantsCenteredOnBaseline is introduced for a similar stretchy-centered-on-baseline.woff (glyphs have non-zero and equal ink ascent/descent). Finally, a WPT test is added to check that the painting of a vertical glyph assembly with the two fonts above matches the location of their bounding boxes. [1] https://learn.microsoft.com/en-us/typography/opentype/spec/math Bug: 1409380 Change-Id: I173c1cf461cebe3523e1a10aaf8d7b479bca03ad Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4197134 Commit-Queue: Frédéric Wang <fwang@igalia.com> Reviewed-by: Dominik Röttsches <drott@chromium.org> Cr-Commit-Position: refs/heads/main@{#1098136}
- Loading branch information
Showing
10 changed files
with
251 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.47 KB
third_party/blink/web_tests/external/wpt/fonts/math/stretchy-centered-on-baseline.woff
Binary file not shown.
Binary file modified
BIN
+28 Bytes
(100%)
third_party/blink/web_tests/external/wpt/fonts/math/stretchy.woff
Binary file not shown.
22 changes: 22 additions & 0 deletions
22
...external/wpt/mathml/presentation-markup/operators/painting-stretchy-operator-001-ref.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Painting of vertical assembly (reference)</title> | ||
<style> | ||
.container { | ||
font-size: 50px; | ||
position: absolute; | ||
left: 1em; | ||
top: 1em; | ||
padding: 5px; | ||
background: green; | ||
width: 4em; | ||
height: 8em; | ||
} | ||
</style> | ||
<body> | ||
<p>This test passes if you see a green rectangle and no red.</p> | ||
<div class="container"> | ||
</div> | ||
</body> |
73 changes: 73 additions & 0 deletions
73
...sts/external/wpt/mathml/presentation-markup/operators/painting-stretchy-operator-001.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!DOCTYPE html> | ||
<html class="reftest-wait"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Painting of vertical assembly</title> | ||
<link rel="match" href="painting-stretchy-operator-001-ref.html"> | ||
<link rel="help" href="https://w3c.github.io/mathml-core/#operator-fence-separator-or-accent-mo"> | ||
<link rel="help" href="https://crbug.com/1409380"> | ||
<meta name="assert" content="Verify that vertical glyph assemblies are painted at the position of their bounding box."> | ||
<script src="/mathml/support/fonts.js"></script> | ||
<style> | ||
.container { | ||
font-size: 50px; | ||
position: absolute; | ||
left: 1em; | ||
top: 1em; | ||
padding: 5px; | ||
background: green; | ||
width: 4em; | ||
height: 8em; | ||
} | ||
mo { | ||
color: green; | ||
background: red; | ||
} | ||
.frame { | ||
position: absolute; | ||
box-sizing: border-box; | ||
border: 2px solid green; | ||
} | ||
@font-face { | ||
font-family: stretchy; | ||
src: url("/fonts/math/stretchy.woff"); | ||
} | ||
@font-face { | ||
font-family: stretchy-centered-on-baseline; | ||
src: url("/fonts/math/stretchy-centered-on-baseline.woff"); | ||
} | ||
</style> | ||
<script> | ||
function runTests() { | ||
// Add a green frame around mo to avoid antialisasing/rounding issues. | ||
Array.from(document.getElementsByTagName('mo')).forEach(mo => { | ||
let box = mo.getBoundingClientRect(); | ||
let div = document.createElement("div"); | ||
div.className = 'frame'; | ||
div.style.left = `${box.left-1}px`; | ||
div.style.top = `${box.top-1}px`; | ||
div.style.width = `${box.width+1}px`; | ||
div.style.height = `${box.height+1}px`; | ||
document.body.appendChild(div); | ||
}); | ||
document.documentElement.classList.remove("reftest-wait"); | ||
} | ||
window.addEventListener("load", () => { loadAllFonts().then(runTests); }); | ||
</script> | ||
<body> | ||
<p>This test passes if you see a green rectangle and no red.</p> | ||
<div class="container"> | ||
<!-- This font uses assembly glyphs with zero ink descent, which is what | ||
Latin Modern Math does for U+007C VERTICAL LINE. --> | ||
<math style="font-family: stretchy"> | ||
<mspace height="4em"/> | ||
<mo stretchy="true" symmetric="true">⥜</mo> | ||
</math> | ||
<!-- This font uses assembly glyphs with non-zero ink descent, which is what | ||
Cambria Math does for U+007C VERTICAL LINE. --> | ||
<math style="font-family: stretchy-centered-on-baseline"> | ||
<mspace height="4em"/> | ||
<mo stretchy="true" symmetric="true">⥜</mo> | ||
</math> | ||
</div> | ||
</body> |
43 changes: 43 additions & 0 deletions
43
third_party/blink/web_tests/external/wpt/mathml/tools/stretchy-centered-on-baseline.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from utils import mathfont | ||
import fontforge | ||
|
||
# Create a WOFF font with glyphs for all the operator strings. | ||
font = mathfont.create("stretchy-centered-on-baseline", "Copyright (c) 2023 Igalia S.L.") | ||
|
||
# Set parameters for stretchy tests. | ||
font.math.MinConnectorOverlap = mathfont.em // 2 | ||
|
||
# Make sure that underover parameters don't add extra spacing. | ||
font.math.LowerLimitBaselineDropMin = 0 | ||
font.math.LowerLimitGapMin = 0 | ||
font.math.StretchStackBottomShiftDown = 0 | ||
font.math.StretchStackGapAboveMin = 0 | ||
font.math.UnderbarVerticalGap = 0 | ||
font.math.UnderbarExtraDescender = 0 | ||
font.math.UpperLimitBaselineRiseMin = 0 | ||
font.math.UpperLimitGapMin = 0 | ||
font.math.StretchStackTopShiftUp = 0 | ||
font.math.StretchStackGapBelowMin = 0 | ||
font.math.OverbarVerticalGap = 0 | ||
font.math.AccentBaseHeight = 0 | ||
font.math.OverbarExtraAscender = 0 | ||
|
||
# These two characters will be stretchable in both directions. | ||
horizontalArrow = 0x295A # LEFTWARDS HARPOON WITH BARB UP FROM BAR | ||
verticalArrow = 0x295C # UPWARDS HARPOON WITH BARB RIGHT FROM BAR | ||
|
||
mathfont.createSizeVariants(font, aUsePUA = True, aCenterOnBaseline = True) | ||
|
||
# Add stretchy vertical and horizontal constructions for the horizontal arrow. | ||
mathfont.createSquareGlyph(font, horizontalArrow) | ||
mathfont.createStretchy(font, horizontalArrow, True) | ||
mathfont.createStretchy(font, horizontalArrow, False) | ||
|
||
# Add stretchy vertical and horizontal constructions for the vertical arrow. | ||
mathfont.createSquareGlyph(font, verticalArrow) | ||
mathfont.createStretchy(font, verticalArrow, True) | ||
mathfont.createStretchy(font, verticalArrow, False) | ||
|
||
mathfont.save(font) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters