예제 #1
0
파일: utils.py 프로젝트: RufaelDev/ttconv
def parse_color(attr_value: str) -> styles.ColorType:
    '''Parses the TTML \\<color\\> value contained in `attr_value`
  '''

    lower_attr_value = str.lower(attr_value)

    if lower_attr_value in styles.NamedColors.__members__:

        return styles.NamedColors[lower_attr_value].value

    m = _HEX_COLOR_RE.match(attr_value)

    if m:

        return styles.ColorType(
            (int(m.group(1), 16), int(m.group(2), 16), int(m.group(3), 16),
             int(m.group(4), 16) if m.group(4) else 255))

    m = _DEC_COLOR_RE.match(attr_value)

    if m:

        return styles.ColorType(
            (int(m.group(1)), int(m.group(2)), int(m.group(3)), 255))

    m = _DEC_COLORA_RE.match(attr_value)

    if m:

        return styles.ColorType((int(m.group(1)), int(m.group(2)),
                                 int(m.group(3)), int(m.group(4))))

    raise ValueError("Bad Syntax")
예제 #2
0
    def add_dup_initial_value(self):
        d = model.Document()

        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)
예제 #3
0
    def iter_initial_values(self):
        d = model.Document()

        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())
예제 #4
0
    def add_bad_initial_value(self):
        d = model.Document()

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

        with self.assertRaises(ValueError):
            d.put_initial_value(styles.StyleProperties.Extent, c1)
예제 #5
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()))
예제 #6
0
    def add_initial_value(self):
        d = model.Document()

        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)
예제 #7
0
    def add_null_initial_value(self):
        d = model.Document()

        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)

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

        self.assertFalse(d.has_initial_value(styles.StyleProperties.Color))

        self.assertIsNone(d.get_initial_value(styles.StyleProperties.Color))
예제 #8
0
    def test_remove_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)

        d.remove_initial_value(styles.StyleProperties.Color)

        self.assertFalse(d.has_initial_value(styles.StyleProperties.Color))

        self.assertIsNone(d.get_initial_value(styles.StyleProperties.Color))