Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add paper_size in SceneInfo #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading