Skip to content

Commit

Permalink
Fix style refs
Browse files Browse the repository at this point in the history
  • Loading branch information
masaccio committed Jul 16, 2023
1 parent 8e8965d commit 6fc8145
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/numbers_parser/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def from_storage(cls, cell_storage: object, model: object):
strikethrough=model.cell_is_strikethrough(cell_storage),
underline=model.cell_is_underline(cell_storage),
name=model.cell_style_name(cell_storage),
_text_style_id=cell_storage.text_style_id,
_cell_style_id=cell_storage.cell_style_id,
_text_style_id=model.text_style_object_id(cell_storage),
_cell_style_id=model.cell_style_object_id(cell_storage),
)
return style

Expand Down
33 changes: 25 additions & 8 deletions src/numbers_parser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,22 @@ def add_cell_style(self, style: Style) -> int:
)
return cell_style_id

def text_style_object_id(self, cell_storage) -> int:
if cell_storage.text_style_id is None:
return None
entry = self._table_styles.lookup_value(
cell_storage.table_id, cell_storage.text_style_id
)
return entry.reference.identifier

def cell_style_object_id(self, cell_storage) -> int:
if cell_storage.cell_style_id is None:
return None
entry = self._table_styles.lookup_value(
cell_storage.table_id, cell_storage.cell_style_id
)
return entry.reference.identifier

def custom_style_name(self, current_styles: List[str]) -> Tuple[str, str]:
"""Find custom styles in the current document and return the next
highest numbered style"""
Expand Down Expand Up @@ -1388,14 +1404,15 @@ def pack_cell_storage( # noqa: C901
"""Create a storage buffer for a cell using v5 (modern) layout"""
cell = data[row_num][col_num]
if cell._style is not None:
cell._storage.text_style_id = self._table_styles.lookup_key(
cell._table_id,
TSPMessages.Reference(identifier=cell.style._text_style_id),
)
self.add_component_reference(
cell.style._text_style_id,
parent_id=self._table_styles.id(cell._table_id),
)
if cell.style._text_style_id is not None:
cell._storage.text_style_id = self._table_styles.lookup_key(
cell._table_id,
TSPMessages.Reference(identifier=cell.style._text_style_id),
)
self.add_component_reference(
cell.style._text_style_id,
parent_id=self._table_styles.id(cell._table_id),
)

if cell.style._cell_style_id is not None:
cell._storage.cell_style_id = self._table_styles.lookup_key(
Expand Down

0 comments on commit 6fc8145

Please sign in to comment.