def to_model(scc_content: str): """Converts a SCC document to the data model""" context = _SccContext() document = ContentDocument() # Safe area must be a 32x15 grid, that represents 80% of the root area root_cell_resolution = CellResolutionType(rows=19, columns=40) document.set_cell_resolution(root_cell_resolution) context.set_safe_area(int((root_cell_resolution.columns - 32) / 2), int((root_cell_resolution.rows - 15) / 2)) body = Body() body.set_doc(document) document.set_body(body) context.div = Div() context.div.set_doc(document) body.push_child(context.div) time_code = None for line in scc_content.splitlines(): LOGGER.debug(line) scc_line = SccLine.from_str(line) if scc_line is None: continue time_code = scc_line.to_model(context) context.flush(time_code) return document
def to_model(scc_content: str): """Converts a SCC document to the data model""" context = _SccContext() document = Document() body = Body() body.set_doc(document) document.set_body(body) context.div = Div() context.div.set_doc(document) body.push_child(context.div) for line in scc_content.splitlines(): _read_line(context, line) return document
def to_model(scc_content: str, config: Optional[SccReaderConfiguration] = None, progress_callback=lambda _: None): """Converts a SCC document to the data model""" context = _SccContext(config) document = ContentDocument() # Safe area must be a 32x15 grid, that represents 80% of the root area root_cell_resolution = CellResolutionType( rows=SCC_ROOT_CELL_RESOLUTION_ROWS, columns=SCC_ROOT_CELL_RESOLUTION_COLUMNS) document.set_cell_resolution(root_cell_resolution) context.set_safe_area( int((root_cell_resolution.columns - SCC_SAFE_AREA_CELL_RESOLUTION_COLUMNS) / 2), int((root_cell_resolution.rows - SCC_SAFE_AREA_CELL_RESOLUTION_ROWS) / 2)) # The active area is equivalent to the safe area active_area = ActiveAreaType( left_offset=context.safe_area_x_offset / root_cell_resolution.columns, top_offset=context.safe_area_y_offset / root_cell_resolution.rows, width=(root_cell_resolution.columns - (context.safe_area_x_offset * 2)) / root_cell_resolution.columns, height=(root_cell_resolution.rows - (context.safe_area_y_offset * 2)) / root_cell_resolution.rows, ) document.set_active_area(active_area) body = Body() body.set_doc(document) document.set_body(body) # the default value of LineHeight ("normal") typically translates to 125% of the font size, which causes regions to overflow. body.set_style(StyleProperties.LineHeight, LengthType(value=100, units=LengthType.Units.pct)) # use a more readable font than the default Courier body.set_style(StyleProperties.FontFamily, ("Consolas", "Monaco", GenericFontFamilyType.monospace)) # add line padding body.set_style(StyleProperties.LinePadding, LengthType(value=0.25, units=LengthType.Units.c)) context.div = Div() context.div.set_doc(document) body.push_child(context.div) lines = scc_content.splitlines() nb_lines = len(lines) for (index, line) in enumerate(lines): LOGGER.debug(line) scc_line = SccLine.from_str(line) progress_callback((index + 1) / nb_lines) if scc_line is None: continue context.process_line(scc_line) context.flush() return document