def process_page_columns(self, page): columns = [] for layout in page: c_column = ColumnLayout.get_layout_column(layout, columns) if c_column is None: c_column = ColumnLayout() columns.append(c_column) c_column.add_layout(layout) columns = self._merge_columns(columns) columns = layout_utils.order_horizontally(columns) return columns
def _merge_columns(self, columns): merged_columns = list(columns) has_merged_column = True while has_merged_column: has_merged_column = False for i in range(0, len(merged_columns)): c1 = merged_columns[i] for j in range(i + 1, len(merged_columns)): c2 = merged_columns[j] if ColumnLayout.is_mergeable(c1, c2): new_column = ColumnLayout.merge(c1, c2) merged_columns.remove(c1) merged_columns.remove(c2) merged_columns.append(new_column) has_merged_column = True break if has_merged_column: break return merged_columns