Exemple #1
0
    def extract(ttml_element) -> model.ActiveAreaType:

        aa = ttml_element.attrib.get(ActiveAreaAttribute.qn)

        if aa is not None:

            s = aa.split(" ")

            if len(s) != 4:
                LOGGER.error("Syntax error in ittp:activeArea on <tt>")
                return None

            (left_offset, left_offset_units) = utils.parse_length(s[0])

            (top_offset, top_offset_units) = utils.parse_length(s[1])

            (w, w_units) = utils.parse_length(s[2])

            (h, h_units) = utils.parse_length(s[3])

            if w_units != "%" or h_units != "%" or left_offset_units != "%" or top_offset_units != "%":
                LOGGER.error("ittp:activeArea on <tt> must use % units")
                return None

            return model.ActiveAreaType(left_offset / 100, top_offset / 100,
                                        w / 100, h / 100)

        return None
Exemple #2
0
        def extract(cls, context: StyleParsingContext, xml_attrib: str):

            (value, units) = utils.parse_length(xml_attrib)

            if units != "%":
                raise ValueError(r"tts:shear must be expressed in % units")

            return value if abs(value) <= 100 else math.copysign(100, value)
Exemple #3
0
    def extract(ttml_element) -> model.PixelResolutionType:

        extent = ttml_element.attrib.get(ExtentAttribute.qn)

        if extent is not None:

            s = extent.split(" ")

            (w, w_units) = utils.parse_length(s[0])

            (h, h_units) = utils.parse_length(s[1])

            if w_units != "px" or h_units != "px":
                LOGGER.error("ttp:extent on <tt> does not use px units")
                return None

            return model.PixelResolutionType(w, h)

        return None
Exemple #4
0
  def extract(ttml_element) -> typing.Optional[model.PixelResolutionType]:

    extent = ttml_element.attrib.get(ExtentAttribute.qn)

    if extent is not None:

      s = extent.split(" ")

      (w, w_units) = utils.parse_length(s[0])

      (h, h_units) = utils.parse_length(s[1])

      if w_units != "px" or h_units != "px":
        LOGGER.error("ttp:extent on <tt> does not use px units")
        return None

      if not w.is_integer() or not h.is_integer():
        LOGGER.error("Pixel resolution dimensions must be integer values")

      return model.PixelResolutionType(int(w), int(h))

    return None
Exemple #5
0
    def ttml_length_to_model(cls, _context: StyleParsingContext,
                             xml_attrib: str):
        (value, units) = utils.parse_length(xml_attrib)

        return styles.LengthType(value, styles.LengthType.Units(units))