def get_origin(self) -> PositionType: """Computes and returns the current paragraph origin, based on its content""" if len(self._caption_contents) > 0: x_offsets = [text.get_x_offset() for text in self._caption_contents if isinstance(text, SccCaptionText)] y_offsets = [text.get_y_offset() for text in self._caption_contents if isinstance(text, SccCaptionText)] return get_position_from_offsets(min(x_offsets), min(y_offsets)) return get_position_from_offsets(self._safe_area_x_offset, self._safe_area_y_offset)
def get_origin(self) -> CoordinateType: """Computes and returns the current paragraph origin, based on its content""" if len(self._caption_lines) > 0: x_offsets = [ text.get_indent() for text in self._caption_lines.values() ] y_offsets = [ text.get_row() - 1 for text in self._caption_lines.values() ] return get_position_from_offsets( min(x_offsets) + self._safe_area_x_offset, min(y_offsets) + self._safe_area_y_offset) return get_position_from_offsets(self._safe_area_x_offset, self._safe_area_y_offset)
def _create_matching_region(self) -> Region: """Creates a new region based on paragraph needs""" doc_regions = list(self._doc.iter_regions()) paragraph_origin = self._paragraph.get_origin() region = Region(self._get_region_prefix() + str(len(doc_regions) + 1), self._doc) # Convert origin cells to percentages if self._paragraph.get_caption_style() is SccCaptionStyle.RollUp: # The region origin x offset region_origin = get_position_from_offsets(paragraph_origin.x.value, self._top) region_origin_pct = convert_cells_to_percentages( region_origin, self._doc.get_cell_resolution()) else: # The region origin matches with paragraph origin region_origin_pct = convert_cells_to_percentages( paragraph_origin, self._doc.get_cell_resolution()) region.set_style(StyleProperties.Origin, region_origin_pct) # The region width is initialized with he paragraph width (up to the right of the safe area) paragraph_extent = self._paragraph.get_extent() available_width = self._right - int(paragraph_origin.x.value) region_width = min(paragraph_extent.width.value, available_width) if self._paragraph.get_caption_style() is SccCaptionStyle.RollUp: # The region height extends from the top row to the bottom row of the safe area region_height = self._bottom - (self._top + 1) region.set_style(StyleProperties.DisplayAlign, DisplayAlignType.after) else: # The region height extends from its origin to the bottom of the safe area region_height = self._bottom - int(paragraph_origin.y.value) - 1 region.set_style(StyleProperties.DisplayAlign, DisplayAlignType.before) region_extent = get_extent_from_dimensions(region_width, region_height) # Convert extent cells to percentages region_extent_pct = convert_cells_to_percentages( region_extent, self._doc.get_cell_resolution()) region.set_style(StyleProperties.Extent, region_extent_pct) # Set default region style properties region.set_style(StyleProperties.ShowBackground, ShowBackgroundType.whenActive) self._doc.put_region(region) return region
def get_position(self) -> PositionType: """Returns current row and column offsets as a cell-based PositionType""" return get_position_from_offsets(self._x_offset, self._y_offset)