Skip to content

Commit

Permalink
Initial IMSC Writer implementation (#52)
Browse files Browse the repository at this point in the history
* Cleanup. Basic, dummy implementation for the imsc writer. CI passes

* Adding from_model to TTElement (#22)

* More plumbing of from_model (#22)

* Adding writing of head/layout/region information (#22)

* Adding writing of body information (#22)

* Adding writing of information for div, p, span (#22)

* Cleanup. Using get_id. Putting head before body (#22)

* fixing issue with _id vs get_id, serializing RegionAttribute

* Adding setter APIs to imsc StyleProperties (#22)

* Adding setter APIs to imsc StyleProperties (#22)

* Implementing various setters in StyleProperties. Fixing other writing issues (#22)

* Implementing various setters in StyleProperties. Cleanup (#22)

* Implementing various setters in StyleProperties. Cleanup (#22)

* Merging master to branch (#22)

* Merge cleanup (#22)

* Reapplying changes (#22)

* Setting namespaces (#22)

* Fixing writing fontSize value. Adding origin. (#22)

* Adding P begin/end (#22)

* Color write formating (#22)

* More unit tests (#22)

* Covering more sytles and properties (#22)

* Marking attributes as pass (#22)

* Made progress on IMSC style property serialization

* Implemented Br (#22)

* Basic implemention of Styling/Style/Initial (#22)

* Basic implemention of Set (#22)

* Rd/issue 22 pal suggestions (#67)

* Set elements now processed (#61)

Added coverage scripts and pre-requisites

* Suggested refactoring

* Further refactoring

* Handle set elements

* Further refinements

* Fixed set issue

* Pretty TTML output

Co-authored-by: Pierre-Anthony Lemieux <[email protected]>
Co-authored-by: Pierre-Anthony Lemieux <[email protected]>

* Do not return opacity of ff for xml value (#22)

* Do not truncate percentages. Use full percision (#22)

* Only write style if not none (#22)

* Only write style if not none (#22)

* Fixing swap of imsc and model in from_model_style_properties (#22_

* Fixing unit tests (#22)

Co-authored-by: Pierre-Anthony Lemieux <[email protected]>
Co-authored-by: Pierre-Anthony Lemieux <[email protected]>
  • Loading branch information
3 people authored Oct 26, 2020
1 parent 692e581 commit 19ab99b
Show file tree
Hide file tree
Showing 7 changed files with 945 additions and 53 deletions.
41 changes: 37 additions & 4 deletions src/main/python/ttconv/imsc/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import ttconv.model as model
import ttconv.imsc.utils as utils
import ttconv.imsc.namespaces as ns
#import xml.etree.ElementTree as et

LOGGER = logging.getLogger(__name__)

Expand All @@ -47,7 +48,9 @@ class XMLIDAttribute:
def extract(ttml_element):
return ttml_element.attrib.get(XMLIDAttribute.qn)


@staticmethod
def set(xml_element, model_value):
xml_element.set(XMLIDAttribute.qn, model_value)

class XMLLangAttribute:
'''xml:lang attribute
Expand All @@ -59,7 +62,9 @@ class XMLLangAttribute:
def extract(ttml_element):
return ttml_element.attrib.get(XMLLangAttribute.qn)


@staticmethod
def set(ttml_element, lang):
ttml_element.set(XMLLangAttribute.qn, lang)

class XMLSpaceAttribute:
'''xml:space attribute
Expand Down Expand Up @@ -94,13 +99,16 @@ class RegionAttribute:
def extract(ttml_element):
return ttml_element.attrib.get(RegionAttribute.qn)

@staticmethod
def set(ttml_element, res):
ttml_element.set(RegionAttribute.qn, res)


class CellResolutionAttribute:
'''ttp:cellResolution attribute
'''

qn = f"{ns.TTP}cellResolution"
qn = f"{{{ns.TTP}}}cellResolution"

_CELL_RESOLUTION_RE = re.compile(r"(\d+) (\d+)")

Expand All @@ -123,6 +131,9 @@ def extract(ttml_element) -> model.CellResolutionType:

return model.CellResolutionType(rows=15, columns=32)

@staticmethod
def set(ttml_element, res):
ttml_element.set(CellResolutionAttribute.qn, f"{res.rows}px {res.columns}px")

class ExtentAttribute:
'''ttp:extent attribute on \\<tt\\>
Expand Down Expand Up @@ -151,6 +162,9 @@ def extract(ttml_element) -> model.PixelResolutionType:

return None

@staticmethod
def set(ttml_element, res):
ttml_element.set(ExtentAttribute.qn, f"{res.width}px {res.height}px")

class ActiveAreaAttribute:
'''ittp:activeArea attribute on \\<tt\\>
Expand Down Expand Up @@ -192,6 +206,10 @@ def extract(ttml_element) -> model.ActiveAreaType:

return None

@staticmethod
def set(ttml_element, activeArea):
ttml_element.set(ActiveAreaAttribute.qn,
f"{(activeArea.left_offset * 100)}% {(activeArea.top_offset * 100)}% {(activeArea.width * 100)}% {activeArea.height * 100}%")

class TickRateAttribute:
'''ttp:tickRate attribute
Expand Down Expand Up @@ -297,6 +315,11 @@ def extract(context: TemporalAttributeParsingContext, xml_element) -> typing.Opt

return None

@staticmethod
def set(ttml_element, begin):
value = begin.numerator / begin.denominator
ttml_element.set(BeginAttribute.qn, f"{value}s")


class EndAttribute:
'''end attributes
Expand All @@ -320,6 +343,11 @@ def extract(context: TemporalAttributeParsingContext, xml_element) -> typing.Opt

return None

@staticmethod
def set(ttml_element, end):
value = end.numerator / end.denominator
ttml_element.set(EndAttribute.qn, f"{value}s")

class DurAttribute:
'''dur attributes
'''
Expand All @@ -340,6 +368,11 @@ def extract(context: TemporalAttributeParsingContext, xml_element) -> typing.Opt

return None

@staticmethod
def set(ttml_element, dur):
ttml_element.set(DurAttribute.qn, dur)


class TimeContainer(Enum):
par = "par"
seq = "seq"
Expand Down Expand Up @@ -382,4 +415,4 @@ def extract(xml_element) -> typing.List[str]:

raw_value = xml_element.attrib.get(StyleAttribute.qn)

return raw_value.split(" ") if raw_value is not None else []
return raw_value.split(" ") if raw_value is not None else []
Loading

0 comments on commit 19ab99b

Please sign in to comment.