예제 #1
0
    def make_anonymous_span(doc, text):

        s = model.Span(doc)
        t = model.Text(doc, text)
        s.push_child(t)

        return s
예제 #2
0
파일: test_isd.py 프로젝트: sandflow/ttconv
    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")
예제 #3
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')
예제 #4
0
  def handle_data(self, data):
    lines = data.split("\n")

    for i, line in enumerate(lines):
      if i > 0:
        self.parent.push_child(model.Br(self.parent.get_doc()))
      span = model.Span(self.parent.get_doc())
      span.push_child(model.Text(self.parent.get_doc(), line))
      self.parent.push_child(span)
예제 #5
0
파일: tf.py 프로젝트: sandflow/ttconv
  def end_span(self):
    if len(self.text_buffer) > 0 and self.span is not None:
      text_element = model.Text(self.parent.get_doc())
      text_element.set_text(self.decode_func(self.text_buffer, errors="note")[0])

      self.span.push_child(text_element)
      self.parent.push_child(self.span)
      self.span = None
      self.text_buffer.clear()
예제 #6
0
    def test_push_child(self):

        d1 = model.Div()

        d1.push_child(model.P())

        d1.push_child(model.Div())

        with self.assertRaises(TypeError):
            d1.push_child(model.Text())
예제 #7
0
    def test_push_child(self):

        s = model.Span()

        s.push_child(model.Br())

        s.push_child(model.Span())

        s.push_child(model.Text())

        with self.assertRaises(TypeError):
            s.push_child(model.P())
예제 #8
0
    def test_push_child(self):

        p = model.P()

        p.push_child(model.Br())

        p.push_child(model.Span())

        p.push_child(model.Ruby())

        with self.assertRaises(TypeError):
            p.push_child(model.Text())
예제 #9
0
    def test_set_text(self):

        t = model.Text()

        self.assertEqual(t.get_text(), "")

        sample_text = "hello"

        t.set_text(sample_text)

        self.assertEqual(t.get_text(), sample_text)

        with self.assertRaises(TypeError):
            t.set_text(None)
예제 #10
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
      )
    )
예제 #11
0
    def test_body_only(self):

        doc = model.ContentDocument()
        body = model.Body(doc)
        div = model.Div(doc)
        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)

        # write the document out to a file
        imsc_writer.from_model(doc).write('build/BodyElement.out.ttml',
                                          encoding='utf-8',
                                          xml_declaration=True)
예제 #12
0
파일: test_isd.py 프로젝트: sandflow/ttconv
    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)
예제 #13
0
    def test_tts_writing_no_extent_when_body_has_no_extents(self):

        doc = model.ContentDocument()
        body = model.Body(doc)
        div = model.Div(doc)
        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)

        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, None)
예제 #14
0
    def test_push_child(self):

        t = model.Text()

        with self.assertRaises(RuntimeError):
            t.push_child(model.Span())
예제 #15
0
  def setUp(self):
    self.doc = model.ContentDocument()

    a1 = model.DiscreteAnimationStep(
      style_property=styles.StyleProperties.Color,
      begin=None,
      end=None,
      value=styles.NamedColors.red.value
    )

    a2 = model.DiscreteAnimationStep(
      style_property=styles.StyleProperties.Color,
      begin=Fraction(1),
      end=None,
      value=styles.NamedColors.green.value
    )

    a3 = model.DiscreteAnimationStep(
      style_property=styles.StyleProperties.Color,
      begin=Fraction(2),
      end=None,
      value=styles.NamedColors.blue.value
    )

    r1 = model.Region("r1", self.doc)
    self.doc.put_region(r1)

    # r2: sig times = {2, 9}

    r2 = model.Region("r2", self.doc)
    r2.set_begin(Fraction(2))
    r2.set_end(Fraction(9))
    r2.add_animation_step(a1)
    self.doc.put_region(r2)

    # b: sig times = {1, 10}

    b = model.Body(self.doc)
    b.set_begin(Fraction(1))
    b.set_end(Fraction(10))
    self.doc.set_body(b)

    # div1: offset = 1, sig times = {2, 4}

    div1 = model.Div(self.doc)
    div1.add_animation_step(a2)
    div1.set_begin(Fraction(3))
    div1.set_region(r1)
    b.push_child(div1)

    # div2: offset = 1, sig times = {10}

    div2 = model.Div(self.doc)
    div2.set_end(Fraction(12))
    div2.set_region(r2)
    b.push_child(div2)

    # p1: offset = 1, sig times = {}

    p1 = model.P(self.doc)
    div2.push_child(p1)

    # span1: offset = 1, sig times = {3}
    span1 = model.Span(self.doc)
    span1.add_animation_step(a3)
    p1.push_child(span1)

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