示例#1
0
    def from_model(model_doc: model.ContentDocument) -> et.Element:

        tt_element = et.Element(TTElement.qn)

        imsc_attr.XMLLangAttribute.set(tt_element, model_doc.get_lang())

        if model_doc.get_cell_resolution() != model.CellResolutionType(
                rows=15, columns=32):
            imsc_attr.CellResolutionAttribute.set(
                tt_element, model_doc.get_cell_resolution())

        has_px = False

        all_elements = list(model_doc.iter_regions())

        if model_doc.get_body() is not None:
            all_elements.extend(model_doc.get_body().dfs_iterator())

        for element in all_elements:
            for model_style_prop in element.iter_styles():
                if StyleProperties.BY_MODEL_PROP[model_style_prop].has_px(
                        element.get_style(model_style_prop)):
                    has_px = True
                    break
            if has_px:
                break

        if model_doc.get_px_resolution() is not None and has_px:
            imsc_attr.ExtentAttribute.set(tt_element,
                                          model_doc.get_px_resolution())

        if model_doc.get_active_area() is not None:
            imsc_attr.ActiveAreaAttribute.set(tt_element,
                                              model_doc.get_active_area())

        # Write the <head> section first
        head_element = HeadElement.from_model(model_doc)

        if head_element is not None:
            tt_element.append(head_element)

        model_body = model_doc.get_body()

        if model_body is not None:

            body_element = BodyElement.from_model(model_body)

            if body_element is not None:
                tt_element.append(body_element)

        return tt_element
示例#2
0
    def _has_document_paragraphs(self, doc: ContentDocument) -> bool:
        body = doc.get_body()

        if body is None:
            return False

        paragraphs = False

        for child in body:
            if self._has_child_paragraphs(child):
                return True

        return paragraphs
示例#3
0
  def from_model(
    model_doc: model.ContentDocument,
    frame_rate: typing.Optional[Fraction],
    time_expression_syntax: imsc_attr.TimeExpressionSyntaxEnum,
    progress_callback: typing.Callable[[numbers.Real], typing.NoReturn]
  ) -> et.Element:
    '''Converts the data model to an IMSC document contained in an ElementTree Element'''

    ctx = TTMLElement.WritingContext(frame_rate, time_expression_syntax)

    tt_element = et.Element(TTElement.qn)

    imsc_attr.XMLLangAttribute.set(tt_element, model_doc.get_lang())
    
    if model_doc.get_cell_resolution() != model.CellResolutionType(rows=15, columns=32):
      imsc_attr.CellResolutionAttribute.set(tt_element, model_doc.get_cell_resolution())

    has_px = False

    all_elements = list(model_doc.iter_regions())

    if model_doc.get_body() is not None:
      all_elements.extend(model_doc.get_body().dfs_iterator())

    for element in all_elements:
      for model_style_prop in element.iter_styles():
        if StyleProperties.BY_MODEL_PROP[model_style_prop].has_px(element.get_style(model_style_prop)):
          has_px = True
          break
      for animation_step in element.iter_animation_steps():
        if StyleProperties.BY_MODEL_PROP[animation_step.style_property].has_px(animation_step.value):
          has_px = True
          break      
      if has_px:
        break

    if model_doc.get_px_resolution() is not None and has_px:
      imsc_attr.ExtentAttribute.set(tt_element, model_doc.get_px_resolution())

    if model_doc.get_active_area() is not None:
      imsc_attr.ActiveAreaAttribute.set(tt_element, model_doc.get_active_area())

    if model_doc.get_display_aspect_ratio() is not None:
      imsc_attr.DisplayAspectRatioAttribute.set(tt_element, model_doc.get_display_aspect_ratio())

    if frame_rate is not None:
      imsc_attr.FrameRateAttribute.set(tt_element, frame_rate)

    # Write the <head> section first
    head_element = HeadElement.from_model(ctx, model_doc)

    progress_callback(0.5)

    if head_element is not None:
      tt_element.append(head_element)

    model_body = model_doc.get_body()

    if model_body is not None:

      body_element = BodyElement.from_model(ctx, model_body)

      if body_element is not None:
        tt_element.append(body_element)

    progress_callback(1.0)

    return tt_element