Skip to content

Commit

Permalink
feat: add paper_size in SceneInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-sti1 committed Dec 5, 2024
1 parent 9df89e2 commit 5f3995a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ To convert rm files to other formats, you can use [rmc](https://github.com/rickl

### Unreleased

New feature:

- Add support for `paper_size` field on some SceneInfo

### v0.6.1

Fixes:
Expand Down
7 changes: 6 additions & 1 deletion src/rmscene/scene_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,26 @@ def version_info(self, _) -> tuple[int, int]:
current_layer: LwwValue[CrdtId]
background_visible: LwwValue[bool]
root_document_visible: LwwValue[bool]
paper_size: tp.Optional[tuple[int, int]]

@classmethod
def from_stream(cls, stream: TaggedBlockReader) -> SceneInfo:
current_layer = stream.read_lww_id(1)
background_visible = stream.read_lww_bool(2)
root_document_visible = stream.read_lww_bool(3)
paper_size = stream.read_int_pair(5) if stream.bytes_remaining_in_block() > 0 else None

return SceneInfo(current_layer=current_layer,
background_visible=background_visible,
root_document_visible=root_document_visible)
root_document_visible=root_document_visible,
paper_size=paper_size)

def to_stream(self, writer: TaggedBlockWriter):
writer.write_lww_id(1, self.current_layer)
writer.write_lww_bool(2, self.background_visible)
writer.write_lww_bool(3, self.root_document_visible)
if self.paper_size:
writer.write_int_pair(5, self.paper_size)


@dataclass
Expand Down
7 changes: 7 additions & 0 deletions src/rmscene/tagged_block_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,10 @@ def read_string_with_format(self, index: int) -> tuple[str, tp.Optional[int]]:
fmt = None

return string, fmt

def read_int_pair(self, index: int) -> tp.Optional[tuple[int, int]]:
"""Read a sub block containing two uint32"""
with self.read_subblock(index):
first = self.data.read_uint32()
second = self.data.read_uint32()
return first, second
6 changes: 6 additions & 0 deletions src/rmscene/tagged_block_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,9 @@ def write_string_with_format(self, index: int, text: str, fmt: int):
self.data.write_bool(is_ascii)
self.data.write_bytes(b)
self.write_int(2, fmt)

def write_int_pair(self, index: int, value: tuple[int, int]):
"""Read a sub block containing two uint32"""
with self.write_subblock(index):
self.data.write_uint32(value[0])
self.data.write_uint32(value[1])
6 changes: 4 additions & 2 deletions tests/test_scene_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,20 @@ def test_write_blocks():


def test_blocks_keep_unknown_data_in_main_block():
# The "E1 FF" is represents new, unknown data -- note that this might need
# The "E1 FF" represents new, unknown data -- note that this might need
# to be changed in future if the next id starts to actually be used in a
# future update!
data_hex = """
21000000 0000010D
2E000000 0000010D
1C 06000000
1F 0000
2F 0000
2C 05000000
1F 0000 21 01
3C 05000000
1F 0000 21 01
5C 08000000
7C050000 50070000
E1 FF
"""
buf = BytesIO(HEADER_V6 + bytes.fromhex(data_hex))
Expand Down

0 comments on commit 5f3995a

Please sign in to comment.