コード例 #1
0
ファイル: test_scc_content.py プロジェクト: sandflow/ttconv
  def test_line_text_leading_and_trailing_spaces(self):
    line = SccCaptionLine(0, 0)
    line.add_text("123")
    self.assertEqual(0, line.get_leading_spaces())
    self.assertEqual(0, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text("   123")
    self.assertEqual(3, line.get_leading_spaces())
    self.assertEqual(0, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text("123   ")
    self.assertEqual(0, line.get_leading_spaces())
    self.assertEqual(3, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text(" 123  ")
    self.assertEqual(1, line.get_leading_spaces())
    self.assertEqual(2, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text("   ")
    line.add_text(SccCaptionText(" 123 "))
    line.add_text(SccCaptionText(" "))
    line.add_text(SccCaptionText("  "))
    self.assertEqual(4, line.get_leading_spaces())
    self.assertEqual(4, line.get_trailing_spaces())
コード例 #2
0
ファイル: paragraph.py プロジェクト: sandflow/ttconv
    def new_caption_text(self):
        """Appends a new caption text content, and keeps reference on it"""
        if self._current_line is None:
            LOGGER.warning("Add a new caption line to add new caption text")
            self.new_caption_line()

        self._current_line.add_text(SccCaptionText())
コード例 #3
0
ファイル: paragraph.py プロジェクト: sandflow/ttconv
    def copy_lines(self) -> Dict[int, SccCaptionLine]:
        """Copy paragraph lines (without time attributes)"""
        lines_copy = {}
        for row, orig_line in self._caption_lines.items():
            new_line = SccCaptionLine(orig_line.get_row(),
                                      orig_line.get_indent())

            for orig_text in orig_line.get_texts():
                new_text = SccCaptionText(orig_text.get_text())
                for style_type, style_value in orig_text.get_style_properties(
                ).items():
                    new_text.add_style_property(style_type, style_value)
                new_line.add_text(new_text)
            lines_copy[row] = new_line

        return lines_copy
コード例 #4
0
ファイル: test_scc_content.py プロジェクト: sandflow/ttconv
  def test_line(self):
    row = 6
    indent = 2
    caption_line = SccCaptionLine(row, indent)

    self.assertEqual(row, caption_line.get_row())
    self.assertEqual(indent, caption_line.get_indent())

    caption_line.set_row(7)
    caption_line.indent(2)

    self.assertEqual(7, caption_line.get_row())
    self.assertEqual(4, caption_line.get_indent())

    self.assertIsNone(caption_line.get_current_text())
    self.assertEqual(0, caption_line.get_cursor())
    self.assertEqual(0, caption_line.get_length())
    self.assertTrue(caption_line.is_empty())
    self.assertListEqual([], caption_line.get_texts())

    caption_line.set_cursor(10)
    self.assertEqual(0, caption_line.get_cursor())

    caption_line.add_text("Hello ")
    caption_text = caption_line.get_current_text()

    self.assertIsNotNone(caption_text)
    self.assertEqual("Hello ", caption_text.get_text())
    self.assertEqual(6, caption_text.get_cursor())
    self.assertEqual(6, caption_text.get_length())

    self.assertEqual(6, caption_line.get_cursor())
    self.assertEqual(6, caption_line.get_length())
    self.assertListEqual([caption_text], caption_line.get_texts())

    another_caption_text = SccCaptionText("World!")

    caption_line.add_text(another_caption_text)

    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual("World!", another_caption_text.get_text())
    self.assertEqual(6, another_caption_text.get_cursor())
    self.assertEqual(6, another_caption_text.get_length())

    self.assertEqual(12, caption_line.get_cursor())
    self.assertEqual(12, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.set_cursor(6)
    self.assertEqual(another_caption_text, caption_line.get_current_text())

    caption_line.add_text("hello")

    self.assertEqual("hello!", another_caption_text.get_text())
    self.assertEqual(5, another_caption_text.get_cursor())
    self.assertEqual(6, another_caption_text.get_length())

    self.assertEqual(11, caption_line.get_cursor())
    self.assertEqual(12, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.set_cursor(5)
    self.assertEqual(caption_text, caption_line.get_current_text())
    self.assertEqual(5, caption_text.get_cursor())

    caption_line.add_text(", abcd")

    self.assertEqual("Hello,", caption_text.get_text())
    self.assertEqual(6, caption_text.get_cursor())
    self.assertEqual(6, caption_text.get_length())

    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual(" abcd!", another_caption_text.get_text())
    self.assertEqual(5, another_caption_text.get_cursor())
    self.assertEqual(6, another_caption_text.get_length())

    self.assertEqual(11, caption_line.get_cursor())
    self.assertEqual(12, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.set_cursor(7)
    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual(1, another_caption_text.get_cursor())

    caption_line.add_text("123456789")

    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual(" 123456789", another_caption_text.get_text())
    self.assertEqual(10, another_caption_text.get_cursor())
    self.assertEqual(10, another_caption_text.get_length())

    self.assertEqual(16, caption_line.get_cursor())
    self.assertEqual(16, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.clear()
    self.assertEqual(0, caption_line.get_cursor())
    self.assertEqual(0, caption_line.get_length())
    self.assertListEqual([], caption_line.get_texts())
コード例 #5
0
ファイル: test_scc_content.py プロジェクト: sandflow/ttconv
  def test_style_properties(self):
    caption_text = SccCaptionText()

    caption_text.add_style_property(StyleProperties.Color, None)
    self.assertEqual(0, len(caption_text.get_style_properties()))

    caption_text.add_style_property(StyleProperties.Color, NamedColors.fuchsia.value)
    self.assertEqual(1, len(caption_text.get_style_properties()))
    self.assertEqual(NamedColors.fuchsia.value, caption_text.get_style_properties()[StyleProperties.Color])

    other_caption_text = SccCaptionText()
    self.assertFalse(caption_text.has_same_style_properties(other_caption_text))

    other_caption_text.add_style_property(StyleProperties.Color, NamedColors.fuchsia.value)
    self.assertTrue(caption_text.has_same_style_properties(other_caption_text))
コード例 #6
0
ファイル: test_scc_content.py プロジェクト: sandflow/ttconv
  def test_text_insertion(self):
    caption_text = SccCaptionText()
    self.assertEqual(0, caption_text.get_cursor())
    caption_text.append("Lorem ")
    self.assertEqual(6, caption_text.get_cursor())
    self.assertEqual("Lorem ", caption_text.get_text())

    caption_text.append("ipsum")
    self.assertEqual(11, caption_text.get_cursor())
    self.assertEqual("Lorem ipsum", caption_text.get_text())

    caption_text.set_cursor_at(0)
    self.assertEqual(0, caption_text.get_cursor())
    self.assertEqual("Lorem ipsum", caption_text.get_text())

    caption_text.append("Hello")
    self.assertEqual(5, caption_text.get_cursor())
    self.assertEqual("Hello ipsum", caption_text.get_text())

    caption_text.set_cursor_at(6)
    caption_text.append("World!")
    self.assertEqual(12, caption_text.get_cursor())
    self.assertEqual("Hello World!", caption_text.get_text())

    caption_text.set_cursor_at(5)
    caption_text.append("! Abc")
    self.assertEqual(10, caption_text.get_cursor())
    self.assertEqual("Hello! Abcd!", caption_text.get_text())
コード例 #7
0
ファイル: paragraph.py プロジェクト: RufaelDev/ttconv
 def new_caption_text(self):
   """Appends a new caption text content, and keeps reference on it"""
   self._caption_contents.append(SccCaptionText())
   self._current_text = self._caption_contents[-1]
コード例 #8
0
ファイル: test_scc_content.py プロジェクト: RufaelDev/ttconv
    def test_offsets_and_position(self):
        caption_text = SccCaptionText()

        caption_text.set_x_offset(None)
        caption_text.set_y_offset(None)

        expected = PositionType(LengthType(value=0, units=LengthType.Units.c),
                                LengthType(value=0, units=LengthType.Units.c))
        self.assertEqual(expected, caption_text.get_position())

        caption_text.set_x_offset(12)
        caption_text.set_y_offset(8)

        expected = PositionType(LengthType(value=12, units=LengthType.Units.c),
                                LengthType(value=8, units=LengthType.Units.c))
        self.assertEqual(expected, caption_text.get_position())

        other_caption_text = SccCaptionText()
        other_caption_text.set_x_offset(12)
        other_caption_text.set_y_offset(8)

        self.assertTrue(caption_text.has_same_origin(other_caption_text))
        self.assertFalse(caption_text.is_contiguous(other_caption_text))

        caption_text.set_y_offset(9)
        self.assertFalse(caption_text.has_same_origin(other_caption_text))
        self.assertTrue(caption_text.is_contiguous(other_caption_text))