Beispiel #1
0
    def test_copy_to(self):
        src = model.ContentDocument()

        src.set_display_aspect_ratio(Fraction(16, 9))
        src.set_active_area(model.ActiveAreaType(0.1, 0.15, 0.8, 0.7))
        src.set_px_resolution(model.PixelResolutionType(height=480, width=640))
        src.set_lang("fr")
        src.set_cell_resolution(model.CellResolutionType(rows=10, columns=20))

        src.put_initial_value(styles.StyleProperties.Color,
                              styles.ColorType((12, 23, 43, 56)))

        dest = model.ContentDocument()

        src.copy_to(dest)

        self.assertEqual(dest.get_display_aspect_ratio(),
                         src.get_display_aspect_ratio())
        self.assertEqual(dest.get_active_area(), src.get_active_area())
        self.assertEqual(dest.get_px_resolution(), src.get_px_resolution())
        self.assertEqual(dest.get_lang(), src.get_lang())
        self.assertEqual(dest.get_cell_resolution(), src.get_cell_resolution())

        self.assertSequenceEqual(list(dest.iter_initial_values()),
                                 list(src.iter_initial_values()))
Beispiel #2
0
    def test_already_attached(self):
        doc = model.ContentDocument()
        doc2 = model.ContentDocument()

        e = model.ContentElement()

        e.set_doc(doc)

        with self.assertRaises(RuntimeError):
            e.set_doc(doc2)
Beispiel #3
0
    def test_add_detached_region(self):
        d = model.ContentDocument()

        r = model.Region("hello")

        with self.assertRaises(ValueError):
            d.put_region(r)
Beispiel #4
0
    def test_set_bad_body(self):
        d = model.ContentDocument()

        b = model.Body()

        with self.assertRaises(ValueError):
            d.set_body(b)
Beispiel #5
0
  def test_compute_padding(self):
    doc = model.ContentDocument()

    r1 = model.Region("r1", doc)
    r1.set_style(styles.StyleProperties.ShowBackground, styles.ShowBackgroundType.always)
    r1.set_style(
      styles.StyleProperties.Extent,
      styles.ExtentType(
        width=styles.LengthType(50, styles.LengthType.Units.pct),
        height=styles.LengthType(25, styles.LengthType.Units.pct)
      )
    )
    r1.set_style(
      styles.StyleProperties.Padding,
      styles.PaddingType(
        before=styles.LengthType(5, styles.LengthType.Units.pct),
        after=styles.LengthType(10, styles.LengthType.Units.pct),
        start=styles.LengthType(15, styles.LengthType.Units.pct),
        end=styles.LengthType(20, styles.LengthType.Units.pct)
      )
    )
    doc.put_region(r1)

    isd = ISD.from_model(doc, 0)

    region = list(isd.iter_regions())[0]

    padding: styles.PaddingType = region.get_style(styles.StyleProperties.Padding)

    self.assertAlmostEqual(padding.before.value, 25 * 0.05)
    self.assertAlmostEqual(padding.after.value, 25 * 0.10)
    self.assertAlmostEqual(padding.start.value, 50 * 0.15)
    self.assertAlmostEqual(padding.end.value, 50 * 0.2)
Beispiel #6
0
  def test_compute_extent_em(self):
    doc = model.ContentDocument()

    r1 = model.Region("r1", doc)
    r1.set_style(styles.StyleProperties.ShowBackground, styles.ShowBackgroundType.always)
    r1.set_style(
      styles.StyleProperties.Extent,
      styles.ExtentType(
        width=styles.LengthType(20, styles.LengthType.Units.em),
        height=styles.LengthType(3, styles.LengthType.Units.em)
      )
    )
    doc.put_region(r1)

    isd = ISD.from_model(doc, 0)

    region = list(isd.iter_regions())[0]

    extent: styles.ExtentType = region.get_style(styles.StyleProperties.Extent)

    self.assertAlmostEqual(extent.width.value, 100*20/doc.get_cell_resolution().rows)
    self.assertEqual(extent.width.units, styles.LengthType.Units.rh)

    self.assertAlmostEqual(extent.height.value, 100*3/doc.get_cell_resolution().rows)
    self.assertEqual(extent.height.units, styles.LengthType.Units.rh)
Beispiel #7
0
  def test_compute_style_property(self):
    doc = model.ContentDocument()

    r1 = model.Region("r1", doc)
    r1.set_style(styles.StyleProperties.FontSize, styles.LengthType(value=50, units=styles.LengthType.Units.pct))
    doc.put_region(r1)

    b = model.Body(doc)
    b.set_style(styles.StyleProperties.FontSize, styles.LengthType(value=50, units=styles.LengthType.Units.pct))
    b.set_region(r1)
    doc.set_body(b)

    div1 = model.Div(doc)
    b.push_child(div1)

    p1 = model.P(doc)
    div1.push_child(p1)

    span1 = model.Span(doc)
    p1.push_child(span1)

    t1 = model.Text(doc, "hello")
    span1.push_child(t1)

    isd = ISD.from_model(doc, 0)

    region = list(isd.iter_regions())[0]

    span = region[0][0][0][0]

    fs: styles.LengthType = span.get_style(styles.StyleProperties.FontSize)

    self.assertAlmostEqual(fs.value, 25 / doc.get_cell_resolution().rows)

    self.assertEqual(fs.units, styles.LengthType.Units.rh)
Beispiel #8
0
  def test_compute_extent_pct(self):
    doc = model.ContentDocument()

    r1 = model.Region("r1", doc)
    r1.set_style(styles.StyleProperties.ShowBackground, styles.ShowBackgroundType.always)
    r1.set_style(
      styles.StyleProperties.Extent,
      styles.ExtentType(
        width=styles.LengthType(50, styles.LengthType.Units.pct),
        height=styles.LengthType(25, styles.LengthType.Units.pct)
      )
    )
    doc.put_region(r1)

    isd = ISD.from_model(doc, 0)

    region = list(isd.iter_regions())[0]

    extent: styles.ExtentType = region.get_style(styles.StyleProperties.Extent)

    self.assertEqual(extent.height.value, 25)
    self.assertEqual(extent.height.units, styles.LengthType.Units.rh)

    self.assertEqual(extent.width.value, 50)
    self.assertEqual(extent.width.units, styles.LengthType.Units.rw)
Beispiel #9
0
  def test_default_region(self):

    doc = model.ContentDocument()

    b = model.Body(doc)
    doc.set_body(b)

    div1 = model.Div(doc)
    b.push_child(div1)

    p1 = model.P(doc)
    div1.push_child(p1)

    span1 = model.Span(doc)
    span1.push_child(model.Text(doc, "hello"))
    p1.push_child(span1)

    isd = ISD.from_model(doc, 0)

    self.assertEqual(len(isd), 1)

    regions = list(isd.iter_regions())

    self.assertEqual(regions[0].get_id(), ISD.DEFAULT_REGION_ID)

    p = regions[0][0][0][0]

    self.assertEqual(len(p), 1)

    self.assertEqual(p[0][0].get_text(), "hello")
Beispiel #10
0
        def __init__(self,
                     ttml_class: TTMLElement,
                     parent_ctx: typing.Optional[
                         TTMLElement.ParsingContext] = None):

            self.doc = parent_ctx.doc if parent_ctx is not None else model.ContentDocument(
            )

            self.style_elements: typing.Dict[str, StyleElement] = parent_ctx.style_elements if parent_ctx is not None else {}

            self.temporal_context = parent_ctx.temporal_context if parent_ctx is not None else imsc_attr.TemporalAttributeParsingContext(
            )

            self.ttml_class: TTMLElement = ttml_class

            self.lang: str = None

            self.space: typing.Optional[model.WhiteSpaceHandling] = None

            self.time_container: imsc_attr.TimeContainer = imsc_attr.TimeContainer.par

            self.explicit_begin: typing.Optional[Fraction] = None

            self.implicit_begin: typing.Optional[Fraction] = None

            self.desired_begin: typing.Optional[Fraction] = None

            self.explicit_end: typing.Optional[Fraction] = None

            self.implicit_end: typing.Optional[Fraction] = None

            self.desired_end: typing.Optional[Fraction] = None

            self.explicit_dur: typing.Optional[Fraction] = None
Beispiel #11
0
    def test_add_bad_initial_value(self):
        d = model.ContentDocument()

        c1 = styles.ColorType((12, 23, 43, 56))

        with self.assertRaises(ValueError):
            d.put_initial_value(styles.StyleProperties.Extent, c1)
Beispiel #12
0
    def test_tts_writing_extent_when_body_has_extents(self):

        doc = model.ContentDocument()
        body = model.Body(doc)
        div = model.Div(doc)

        div.set_style(
            styles.StyleProperties.Extent,
            get_extent_from_dimensions(123, 456, styles.LengthType.Units.px))

        p = model.P(doc)
        span = model.Span(doc)
        text = model.Text(doc)
        text.set_text("asdf")

        span.push_child(text)
        p.push_child(span)
        div.push_child(p)
        body.push_child(div)
        doc.set_body(body)

        r = model.Region("hello", doc)
        r.set_style(
            styles.StyleProperties.Extent,
            get_extent_from_dimensions(123, 456, styles.LengthType.Units.px))

        doc.put_region(r)

        tree_from_model = imsc_writer.from_model(doc)

        extent = tree_from_model.getroot().attrib.get(
            f"{{{imsc_styles.StyleProperties.Extent.ns}}}{imsc_styles.StyleProperties.Extent.local_name}"
        )

        self.assertEqual(extent, '1920px 1080px')
Beispiel #13
0
  def setUp(self):
    self.doc = model.ContentDocument()

    r1 = model.Region("r1", self.doc)
    r1.set_style(styles.StyleProperties.ShowBackground, styles.ShowBackgroundType.whenActive)
    self.doc.put_region(r1)

    b = model.Body(self.doc)
    b.set_region(r1)
    self.doc.set_body(b)

    div1 = model.Div(self.doc)
    b.push_child(div1)

    p1 = model.P(self.doc)
    p1.set_begin(1)
    p1.set_end(3)
    div1.push_child(p1)

    span1 = model.Span(self.doc)
    span1.push_child(model.Text(self.doc, "hello"))
    p1.push_child(span1)

    span2 = model.Span(self.doc)
    span2.set_begin(1)
    span2.push_child(model.Text(self.doc, "bye"))
    p1.push_child(span2)
Beispiel #14
0
    def test_add_region(self):
        d = model.ContentDocument()

        r = model.Region("hello", d)

        d.put_region(r)

        self.assertIs(d.get_region(r.get_id()), r)
Beispiel #15
0
    def test_attach(self):
        doc = model.ContentDocument()

        e = model.ContentElement()

        e.set_doc(doc)

        self.assertTrue(e.get_doc() is doc)
        self.assertTrue(e.is_attached())
Beispiel #16
0
    def test_add_initial_value(self):
        d = model.ContentDocument()

        c = styles.ColorType((12, 23, 43, 56))

        d.put_initial_value(styles.StyleProperties.Color, c)

        c2 = d.get_initial_value(styles.StyleProperties.Color)

        self.assertEqual(c, c2)
Beispiel #17
0
    def test_detach(self):
        doc = model.ContentDocument()

        e = model.ContentElement()

        e.set_doc(doc)

        e.set_doc(None)

        self.assertIsNone(e.get_doc())
        self.assertFalse(e.is_attached())
Beispiel #18
0
    def test_tts_writing_no_extent_when_no_body(self):

        d = model.ContentDocument()

        tree_from_model = imsc_writer.from_model(d)

        extent = tree_from_model.getroot().attrib.get(
            f"{{{imsc_styles.StyleProperties.Extent.ns}}}{imsc_styles.StyleProperties.Extent.local_name}"
        )

        self.assertEqual(extent, None)
Beispiel #19
0
    def test_failed_child_detach(self):
        doc = model.ContentDocument()

        e = model.ContentElement(doc)

        c = model.ContentElement(doc)

        e.push_child(c)

        with self.assertRaises(RuntimeError):
            c.set_doc(None)
Beispiel #20
0
    def test_iter_region(self):
        d = model.ContentDocument()

        r1 = model.Region("hello1", d)

        r2 = model.Region("hello2", d)

        d.put_region(r1)

        d.put_region(r2)

        self.assertCountEqual(d.iter_regions(), [r1, r2])
Beispiel #21
0
  def test_init(self):
    d = model.ContentDocument()

    self.assertIsNone(d.get_body())
    
    self.assertEqual(d.get_px_resolution(), model.PixelResolutionType(width=1920, height=1080))

    self.assertEqual(len(d.iter_initial_values()), 0)

    self.assertEqual(len(d.iter_regions()), 0)

    self.assertEqual(d.get_cell_resolution(), model.CellResolutionType(rows=15, columns=32))
Beispiel #22
0
    def test_add_dup_region(self):
        d = model.ContentDocument()

        r1 = model.Region("hello", d)

        r2 = model.Region("hello", d)

        d.put_region(r1)

        d.put_region(r2)

        self.assertIs(d.get_region(r2.get_id()), r2)
Beispiel #23
0
    def test_compute_extent_em(self):
        doc = model.ContentDocument()

        r1 = model.Region("r1", doc)
        r1.set_style(styles.StyleProperties.ShowBackground,
                     styles.ShowBackgroundType.always)
        with self.assertRaises(ValueError) as _context:
            r1.set_style(
                styles.StyleProperties.Extent,
                styles.ExtentType(
                    width=styles.LengthType(20, styles.LengthType.Units.em),
                    height=styles.LengthType(3, styles.LengthType.Units.em)))
Beispiel #24
0
    def test_set_body(self):
        d = model.ContentDocument()

        b = model.Body(d)

        d.set_body(b)

        self.assertEqual(d.get_body(), b)

        d.set_body(None)

        self.assertIsNone(d.get_body())
Beispiel #25
0
    def test_document_active_area(self):

        d = model.ContentDocument()

        aa = model.ActiveAreaType(0.1, 0.15, 0.8, 0.7)

        d.set_active_area(aa)

        self.assertEqual(d.get_active_area(), aa)

        d.set_active_area(None)

        self.assertIsNone(d.get_active_area())
Beispiel #26
0
  def test_text_decoration_inheritance(self):
    doc = model.ContentDocument()

    r1 = model.Region("r1", doc)
    r1.set_style(
      styles.StyleProperties.TextDecoration,
      styles.TextDecorationType(
        line_through=False,
        underline=True,
        overline=True
      )
    )
    doc.put_region(r1)

    b = model.Body(doc)
    b.set_style(
      styles.StyleProperties.TextDecoration,
      styles.TextDecorationType(
        overline=False
      )
    )
    b.set_region(r1)
    doc.set_body(b)

    div1 = model.Div(doc)
    b.push_child(div1)

    p1 = model.P(doc)
    div1.push_child(p1)

    span1 = model.Span(doc)
    p1.push_child(span1)

    t1 = model.Text(doc, "hello")
    span1.push_child(t1)

    isd = ISD.from_model(doc, 0)

    region = list(isd.iter_regions())[0]

    span = region[0][0][0][0]

    self.assertEqual(
      span.get_style(styles.StyleProperties.TextDecoration),
      styles.TextDecorationType(
        line_through=False,
        underline=True,
        overline=False
      )
    )
Beispiel #27
0
    def test_remove_region(self):
        d = model.ContentDocument()

        r = model.Region("hello", d)

        d.put_region(r)

        self.assertIs(d.get_region(r.get_id()), r)

        d.remove_region(r.get_id())

        self.assertFalse(d.has_region(r.get_id()))

        self.assertIsNone(d.get_region(r.get_id()))
Beispiel #28
0
    def test_add_dup_initial_value(self):
        d = model.ContentDocument()

        c1 = styles.ColorType((12, 23, 43, 56))

        c2 = styles.ColorType((12, 96, 43, 56))

        d.put_initial_value(styles.StyleProperties.Color, c1)

        d.put_initial_value(styles.StyleProperties.Color, c2)

        self.assertIsNot(d.get_initial_value(styles.StyleProperties.Color), c1)

        self.assertIs(d.get_initial_value(styles.StyleProperties.Color), c2)
Beispiel #29
0
    def test_iter_initial_values(self):
        d = model.ContentDocument()

        c1 = styles.ColorType((12, 23, 43, 56))

        c2 = styles.ColorType((12, 96, 43, 56))

        d.put_initial_value(styles.StyleProperties.Color, c1)

        d.put_initial_value(styles.StyleProperties.BackgroundColor, c2)

        self.assertCountEqual([(styles.StyleProperties.Color, c1),
                               (styles.StyleProperties.BackgroundColor, c2)],
                              d.iter_initial_values())
Beispiel #30
0
    def test_language(self):

        d = model.ContentDocument()

        self.assertEqual(d.get_lang(), "")

        lang = "fr-CA"

        d.set_lang(lang)

        self.assertEqual(d.get_lang(), lang)

        with self.assertRaises(TypeError):
            d.set_lang(1)