diff --git a/README.md b/README.md index 92fbb19..57de571 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/rmscene/scene_stream.py b/src/rmscene/scene_stream.py index 16e15b2..7491614 100644 --- a/src/rmscene/scene_stream.py +++ b/src/rmscene/scene_stream.py @@ -143,21 +143,25 @@ 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) + writer.write_int_pair(5, self.paper_size) @dataclass diff --git a/src/rmscene/tagged_block_reader.py b/src/rmscene/tagged_block_reader.py index c7931af..a26dbf4 100644 --- a/src/rmscene/tagged_block_reader.py +++ b/src/rmscene/tagged_block_reader.py @@ -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 diff --git a/src/rmscene/tagged_block_writer.py b/src/rmscene/tagged_block_writer.py index d110788..c078e90 100644 --- a/src/rmscene/tagged_block_writer.py +++ b/src/rmscene/tagged_block_writer.py @@ -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])