Skip to content

Added read support for image blobs#11

Open
yannickulrich wants to merge 5 commits into
joagonca:mainfrom
yannickulrich:images
Open

Added read support for image blobs#11
yannickulrich wants to merge 5 commits into
joagonca:mainfrom
yannickulrich:images

Conversation

@yannickulrich
Copy link
Copy Markdown

This adds support for the native image insertions in notebooks on 3.27 or later. I've opened similar PRs with the python reader (ricklupton/rmscene#52 and ricklupton/rmc#50). The construction is based on remarkable-shapes which already has this ability in ruby.

On the top-level, images are defined in a ImageEntry (block type 0x0E) via a UUID. They can have a flag which currently always evaluates to [17, 0]. They are then references in the tree as a Image (block type 0x0F, item type 0x07). This uses the UUID defined earlier and includes image placement as a list of image vertices (x, y, u, v tuples)

[
  left, top, 0.0, 0.0,
  right, top, 1.0, 0.0,
  right, bottom, 1.0, 1.0,
  left, bottom, 0.0, 1.0
]

Exporting images is (in principle) pretty easy

func drawImage(image *parser.Image, w io.Writer, indent string) {
	fmt.Fprintf(w, "%s<g transform=\"translate(%.3f, %.3f)\">\n",
		indent, scale(float64(image.X)), scale(float64(image.Y)))
	fmt.Fprintf(w, "%s\t<image height=\"%.3f\" width=\"%.3f\" href=\"%s\"/>\n",
		indent, scale(float64(image.Height)), scale(float64(image.Width)), image.Filename.Value)
	fmt.Fprintf(w, "%s</g>\n", indent)
}

However, there is a question of how to load the image in the first place. An rmdoc file looks like

├── acf9e956-3646-4c6f-bf4a-c09ffdd17d77.content
├── acf9e956-3646-4c6f-bf4a-c09ffdd17d77.metadata
├── acf9e956-3646-4c6f-bf4a-c09ffdd17d77
│   ├── 34d0c003-1ff8-40a3-bba2-3b7807a3632c.png
│   └── f25ec2ea-bfb7-4777-ae8c-7c6711fa084c.png
└── acf9e956-3646-4c6f-bf4a-c09ffdd17d77.rm

Since the reader is just given a file handle for the .rm file, it won't be able to figure out how to load the .png files next to it. If you have a suggestion on how to best handle this, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant