w3c / ttml2

Timed Text Markup Language 2 (TTML2)
https://w3c.github.io/ttml2/
Other
41 stars 16 forks source link

Clarify behaviour of tts:showBackground="whenActive" when xml:space="default" #1208

Closed paul-bivol closed 4 years ago

paul-bivol commented 4 years ago

Given a region having tts:showBackground="whenActive" and the content selected into it has xml:space="default", contains only whitespaces and is temporally active, is the region background visible in this case? In other words, is whitespace trimming and collapse performed before or after deciding if a region background is rendered or not?

Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<tt xmlns="http://www.w3.org/ns/ttml"
    xmlns:ttp="http://www.w3.org/ns/ttml#parameter"
    xmlns:ebuttm="urn:ebu:tt:metadata"
    xmlns:ebutts="urn:ebu:tt:style"
    xmlns:tts="http://www.w3.org/ns/ttml#styling"
    xml:lang="en"
    ttp:cellResolution="30 30"
    >
    <head>
        <styling>
        </styling>
        <layout>
            <region xml:id="reg1" tts:showBackground="whenActive" tts:origin="25% 5%" tts:extent="20% 40%" tts:backgroundColor="#f09020"/>
            <region xml:id="reg2" tts:showBackground="whenActive" tts:origin="46% 5%" tts:extent="20% 40%" tts:backgroundColor="#30a0f0"/>
            <region xml:id="reg3" tts:showBackground="whenActive" tts:origin="67% 5%" tts:extent="20% 40%" tts:backgroundColor="#10f010"/>
        </layout>
    </head>
    <body>
        <div xml:space="default">
            <p region="reg1" begin="00:00:00.000" end="00:00:10.000" tts:backgroundColor="#000000">
                p11
            </p>
            <p region="reg1" begin="00:00:20.000" end="00:00:30.000" tts:backgroundColor="#000000">
                p12
            </p>

            <p region="reg2" tts:backgroundColor="#000000">
                <span begin="00:00:00.000" end="00:01:00.000">
                </span>
                <span begin="00:00:00.000" end="00:00:10.000">p21</span>
            </p>
            <p region="reg2" tts:backgroundColor="#000000">
                <span begin="00:00:00.000" end="00:01:00.000">
                </span>
                <span begin="00:00:20.000" end="00:00:30.000">p22</span>
            </p>

            <p region="reg3" tts:backgroundColor="#000000" xml:space="preserve">
                <span begin="00:00:00.000" end="00:00:10.000">p31</span>
            </p>
            <p region="reg3" tts:backgroundColor="#000000" xml:space="preserve">
                <span begin="00:00:20.000" end="00:00:30.000">p32</span>
            </p>
        </div>
    </body>
</tt>

There is no ambiguity for reg1 as the whitespaces become temporally inactive when the rest of the text does. There is no ambiguity for reg3 as whitespaces are preserved and should be rendered. For reg2 there will be two whitespace only anonymous spans and a third whitespace only span surrounding a non-whitespace span that will become temporally inactive. If whitespace trimming happens before deciding if the region background is to be rendered then the background should dissapear. Otherwise it should continue to be rendered.

nigelmegitt commented 4 years ago

Thank you for raising this issue @paul-bivol . I do not believe that white space handling has any impact on whether content is active or not.

Tracing through the definitions from tts:showBackground:

if the value of this attribute is whenActive, then the region's background is rendered only when content is selected into the region, where that content is also temporally active;

and

[temporally active]

A syntactic or semantic feature, e.g., an element or the presentation of an element, is temporally active when the current time of the selected time base intersects with the active time interval of the feature.

So your question resolves down to whether content is selected into a region if that content is only whitespace. I think the answer is yes, because no exception is made to suggest that whitespace is not content.

Now there is an additional question: could the use of XML white space handling remove all content from a span? The TTML2 default white space handling rules are defined, and used in synchronic flow processing. By my reading, a span containing only a linefeed gets treated as a single space character. It is therefore not altogether empty. This is what I see in implementations too.

Translating that back to your example, there is no ambiguity for reg2 because the two p elements in reg2 are both active while their first whitespace-only span child is active. Those spans each contain a single space character.

One more point: you phrase your initial question as:

is whitespace trimming and collapse performed before or after deciding if a region background is rendered or not?

The TTML2 specification of white space handling states the set of white space handling attributes that should be considered to apply to the intermediate XSL-FO document generated by the synchronic flow processing algorithm. That synchronic flow processing algorithm itself is a subsequent step to temporal slicing, so the computation of whether a region is temporally active or not must happen before the generation of that XSL-FO document, and therefore the scenario you describe is again not ambiguous: reg2's background is rendered when content selected into it is active, even if that content may be modified by the application of XML white space handling attributes.

Standard caveat as per §11.3.1:

Any implementation is permitted provided that the externally observable results are consistent with the results produced by this model.

paul-bivol commented 4 years ago

Thank you very much @nigelmegitt for a very thorough and quick response.