skynav / ttt

Timed Text Toolkit
BSD 2-Clause "Simplified" License
74 stars 15 forks source link

Fix percent inherited (fixes issue #166) #313

Closed MaxEliaserAWS closed 2 years ago

MaxEliaserAWS commented 2 years ago

This PR fixes issue #166 (font size percentages getting re-multiplied each time they are inherited) and one unticketed TODO comment (tts:textEmphasis not working on nested <span>s.)

Both of these fixes were authored by myself.

Test Changes

ttml2-prstn-text-emphasis-imsc11-2

The original for this test case is here: https://github.com/w3c/imsc-tests/blob/main/imsc1_1/ttml/textEmphasis/textEmphasis002.ttml And the reference rendering is here: https://github.com/w3c/imsc-tests/blob/main/imsc1_1/png/textEmphasis002/0.000000.png

The input file for this test contains a <span> with a tts:textEmphasis and an additional <span> nested within it. The TTML2 spec says that tts:textEmphasis is a heritable property, so it should be applying to the nested <span>.

In the upstream "expected" result (bottom,) not only are the decorations missing on the nested <span>'s text, but the text itself is missing too. In the "new" rendition (top,) the text and its decorations are present. This is a better representation of the source file and more closely resembles the reference rendering from w3c as well. ttml2-prstn-text-emphasis-imsc11-2_comparison

ttml2-prstn-ruby-align-imsc11-4

The input file for this test has most of the document at a font size of 48px, but the English text has a font size of 75% in a child element. This ought to be 75% of 48 pixels, or 36 pixels.

In the intermediate golden file (bottom,) we can see that the font size on the English text is too small. In the new rendering (top,) the font size is correct. I have also verified this by diffing the SVG files:

--- "pred to upstream/ttps000001.svg"   2021-10-01 15:25:12.000000000 -0800
+++ new/ttps000001.svg  2021-10-07 20:45:50.000000000 -0800
@@ -53,35 +53,35 @@
 <g class="line p" fill="#FFFFFF" font-family="Noto Sans JP" font-size="36">
 <rect fill="none" height="45" stroke="#FFFF00" width="1024"/>
 <text fill="#FFFF00" font-family="sans-serif" font-size="6" x="2" y="8">P2L1</text>
-<g class="glyphs p" font-size="27" transform="translate(327.941,27)">
+<g class="glyphs p" transform="translate(266.588,36)">

As you can see, the erroneous font size of 27 is removed, and the correct size of 36 is retained.

This issue happened because the percentage of 75% was re-applied every time the font size was inherited by a child element, which is the TTT issue 166 that I am fixing here. 75% of 36 is 27. ttml2-prstn-ruby-align-imsc11-4_comparison_font_size