File: imsc_reader.md

package info (click to toggle)
ttconv 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,460 kB
  • sloc: python: 19,811; sh: 44; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 2,033 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# IMSC Reader

## Overview

The IMSC reader (`ttconv/imsc/reader.py`) converts [IMSC 1.1 Text
Profile](https://www.w3.org/TR/ttml-imsc1.1/#text-profile) documents into the [data model](./data-model.md). The objective is to
preserve rendering fidelity but not necessarily structure, e.g. referential styling is flattened.

## Usage

The IMSC reader accepts as input an XML document that conforms to the [ElementTree XML
API](https://docs.python.org/3.7/library/xml.etree.elementtree.html) and returns a `model.ContentDocument` object.

```python
import xml.etree.ElementTree as et
import ttconv.imsc.reader as imsc_reader
xml_doc = et.parse('src/test/resources/ttml/imsc-tests/imsc1/ttml/timing/BasicTiming007.ttml')
doc = imsc_reader.to_model(xml_doc)
# doc can then manipulated and written out using any of the writer modules
```

## Architecture

The input XML document is traversed using depth-first search (DFS). Each XML element encountered is processed using the `from_xml()`
method of the corresponding class in `ttconv/imsc/elements.py`. For example,
`ttconv.imsc.elements.PElement.from_xml()` is applied to each `<p>` element. Since the data model is a subset of the IMSC 1.1 model,
additional parsing state is preserved across calls to `from_xml()` by associating each parsed XML element in an instance of the
`ttconv.imsc.elements.TTMLElement.ParsingContext` structure and its subclasses.

To improve code manageability, processing of TTML style and other attributes is conducted in `ttconv/imsc/styles_properties.py` and
`ttconv/imsc/attributes.py`, respectively. Each style property in `ttconv/imsc/styles_properties.py` is mapped, as specified by the
`model_prop` member, to a style property of the data model in `ttconv/styles_properties.py`.

`ttconv/imsc/namespaces.py` and `ttconv/imsc/utils.py` contain common namespace declarations and utility functions, respectively.

## Tests

Unit tests include parsing into the data model all of the [IMSC test documents published by W3C](https://github.com/w3c/imsc-tests).