rmscene

package module
v0.0.0-...-0396c09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 7 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-rmscene is a high-performance, zero-dependency Go library for parsing reMarkable tablet v6 binary scene files (.rm lines format) and rendering them to layered, publication-quality vector SVG documents.

What It Does

  • Binary stroke decoding: Parses reMarkable v6 binary .rm files into structured block hierarchies and typed stroke models.
  • Paper Pro color decoding: Decodes 24-bit RGB colors from Paper Pro highlighter and shader strokes encoded in little-endian BGRA buffers.
  • Physics-based stylus dynamics: Reproduces pressure curves, tilt dampening, velocity variations, and opacity gradients across 11 writing tools.
  • Layer-ordered SVG rendering: Groups highlighter and shader washes underneath pen ink in painter's order to maintain sharp, legible handwriting.
  • Bi-directional binary tooling: Includes DataWriter encoder and DataStream reader for inspecting and generating valid v6 binary streams.

How It Works

  • Validates the 43-byte magic file header (reMarkable .lines file, version=6).
  • Iterates through variable-length binary blocks, decoding tagged CRDT identifiers and telemetry points.
  • Builds an in-memory scene tree separating vector strokes, text items, migration info, and layer metadata.
  • Generates layered vector SVGs using stylus physics models and Paper Pro color palettes.

How it Really Works

  • The parser operates directly on byte slices or seekable streams using pure Go standard library primitives, allocating zero external buffers or C bindings.
  • In painter's order SVG output, highlighters are placed into <g id="highlighters"> with semi-transparency and square linecaps before <g id="pen_strokes">, ensuring highlighter washes never obscure black handwriting.
  • Tool 23 (SHADER) is dynamically classified as a variable-opacity wash rather than an opaque yellow stroke, mapping raw alpha bytes (e.g. 77 -> 30%, 115 -> 45%) to CSS stroke opacity.
  • Subblocks are protected against buffer underflows and overflows; any stream exceeding its declared length fails immediately with ErrBlockOverflow.

Prerequisites

  • Go 1.26 or newer.

Installation

go get github.com/alexgorbatchev/go-rmscene

Quick Start

package main

import (
	"fmt"
	"os"

	"github.com/alexgorbatchev/go-rmscene"
)

func main() {
	rmBytes, err := os.ReadFile("page.rm")
	if err != nil {
		panic(err)
	}

	// Parse binary strokes into Scene structure
	scene, err := rmscene.Parse(rmBytes)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Parsed %d blocks, %d lines\n", len(scene.Blocks), len(scene.Lines()))

	// Render directly to SVG string
	svg, err := rmscene.RenderRMToSVG(rmBytes, rmscene.WithDimensions(447.87, 608.20))
	if err != nil {
		panic(err)
	}

	_ = os.WriteFile("page.svg", []byte(svg), 0644)
}

API

Export Signature Description
Parse (data []byte) (*Scene, error) Parses v6 binary scene file from a byte slice
ParseReader (r io.Reader) (*Scene, error) Parses v6 binary scene stream from an io.Reader
RenderRMToSVG (rmBytes []byte, opts ...SVGOption) (string, error) Parses and converts .rm bytes directly to SVG
RenderToSVG (blocks []Block, opts ...SVGOption) string Renders parsed blocks into a layered SVG string
ValidateHeader (r io.Reader) error Validates the 43-byte magic header in a stream
NewDataWriter (w io.Writer) *DataWriter Creates a binary serializer for v6 .rm streams
NewDataStream (r io.ReadSeeker) *DataStream Creates a low-level binary tag stream decoder

Configuration

Option Type Default Description
WithDimensions (widthPt, heightPt float64) 447.87, 608.20 Output SVG canvas width and height in points
WithViewBox (viewBox string) centered Custom SVG viewBox string
WithHighlighterOpacity (opacity float64) 0.45 Default opacity for standard highlighter strokes
WithHighlighterWidth (width float64) 10.0 Default stroke width for highlighters

License

MIT License (c) 2026 Alex Gorbatchev

Documentation

Index

Constants

View Source
const (
	BlockTypeMigrationInfo  = 0x00
	BlockTypeSceneTree      = 0x01
	BlockTypeTreeNode       = 0x02
	BlockTypeSceneGlyph     = 0x03
	BlockTypeSceneGroup     = 0x04
	BlockTypeSceneLine      = 0x05
	BlockTypeSceneText      = 0x06
	BlockTypeRootText       = 0x07
	BlockTypeSceneTombstone = 0x08
	BlockTypeAuthorIds      = 0x09
	BlockTypePageInfo       = 0x0A
	BlockTypeSceneInfo      = 0x0D
)
View Source
const (
	// DefaultWidthPt is the standard reMarkable A5 portrait width in points.
	DefaultWidthPt = 447.874
	// DefaultHeightPt is the standard reMarkable A5 portrait height in points.
	DefaultHeightPt = 595.275
	// DefaultHighlighterOpacity is the standard stroke opacity for highlighter ink.
	DefaultHighlighterOpacity = 0.45
	// DefaultHighlighterWidth is the standard stroke width for highlighters.
	DefaultHighlighterWidth = 10.0
	// ScreenDPI is the hardware screen DPI of the reMarkable tablet (226 DPI).
	ScreenDPI = 226.0
	// ScaleFactor converts tablet screen units to standard 72 DPI points (72 / 226).
	ScaleFactor = 72.0 / ScreenDPI
)
View Source
const HeaderLength = len(HeaderV6)

HeaderLength is the required length of the header in bytes (43 bytes).

View Source
const HeaderV6 = "reMarkable .lines file, version=6          "

HeaderV6 is the expected 43-byte magic header for reMarkable version 6 .rm files.

Variables

View Source
var (
	// ErrInvalidHeader is returned when the file header does not match HeaderV6.
	ErrInvalidHeader = errors.New("invalid reMarkable v6 header")
	// ErrUnexpectedEOF is returned when the stream ends unexpectedly.
	ErrUnexpectedEOF = errors.New("unexpected EOF")
)
View Source
var (
	// ErrBlockOverflow is returned when reading exceeds the declared block size.
	ErrBlockOverflow = errors.New("block overflow: read past declared block size")
	// ErrUnexpectedTag is returned when a tag does not match the expected index or type.
	ErrUnexpectedTag = errors.New("unexpected tag in block stream")
)
View Source
var DefaultHighlighterColor = Color{R: 255, G: 235, B: 59}

DefaultHighlighterColor is standard highlighter yellow (255, 235, 59).

View Source
var DefaultPalette = map[PenColor]Color{
	PenColorBlack:       {R: 0, G: 0, B: 0},
	PenColorGray:        {R: 144, G: 144, B: 144},
	PenColorWhite:       {R: 255, G: 255, B: 255},
	PenColorYellow:      {R: 251, G: 247, B: 25},
	PenColorGreen:       {R: 0, G: 255, B: 0},
	PenColorPink:        {R: 255, G: 192, B: 203},
	PenColorBlue:        {R: 78, G: 105, B: 201},
	PenColorRed:         {R: 179, G: 62, B: 57},
	PenColorGrayOverlap: {R: 125, G: 125, B: 125},
	PenColorHighlight:   {R: 251, G: 247, B: 25},
	PenColorGreen2:      {R: 161, G: 216, B: 125},
	PenColorCyan:        {R: 139, G: 208, B: 229},
	PenColorMagenta:     {R: 242, G: 158, B: 255},
	PenColorYellow2:     {R: 247, G: 232, B: 81},
}

DefaultPalette maps PenColor enum values to their standard display RGB colors. Values incorporate Paper Pro color palette definitions.

Functions

func RenderRMToSVG

func RenderRMToSVG(rmBytes []byte, opts ...SVGOption) (string, error)

RenderRMToSVG parses raw .rm file bytes and exports an SVG string directly.

func RenderToSVG

func RenderToSVG(blocks []Block, opts ...SVGOption) string

RenderToSVG parses the provided blocks and exports a layered SVG string.

Highlighters are rendered in painter's order underneath pen strokes with true Paper Pro RGB colors, stroke-opacity="0.45", and square linecaps. Pen strokes are rendered on top with their individual segment dynamic widths and colors.

func Scale

func Scale(unit float64) float64

Scale converts a raw coordinate or dimension from screen units to SVG points.

func ValidateHeader

func ValidateHeader(r io.Reader) error

ValidateHeader reads HeaderLength bytes from r and returns nil if it matches HeaderV6.

func ValidateHeaderBytes

func ValidateHeaderBytes(data []byte) error

ValidateHeaderBytes verifies that the provided byte slice starts with HeaderV6.

Types

type AuthorIdsBlock

type AuthorIdsBlock struct {
	Authors map[uint16][]byte `json:"authors"`
	// contains filtered or unexported fields
}

AuthorIdsBlock maps author UUIDs to numerical IDs (BlockType 0x09).

func (*AuthorIdsBlock) BlockType

func (b *AuthorIdsBlock) BlockType() uint8

func (*AuthorIdsBlock) ExtraData

func (b *AuthorIdsBlock) ExtraData() []byte

type Ballpoint

type Ballpoint struct {
	// contains filtered or unexported fields
}

Ballpoint pen implementation with dynamic width and ink pressure variation.

func NewBallpoint

func NewBallpoint(width float64, color Color) *Ballpoint

func (*Ballpoint) BaseColor

func (p *Ballpoint) BaseColor() Color

func (*Ballpoint) BaseWidth

func (p *Ballpoint) BaseWidth() float64

func (*Ballpoint) Name

func (p *Ballpoint) Name() string

func (*Ballpoint) SegmentColor

func (p *Ballpoint) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Ballpoint) SegmentLength

func (p *Ballpoint) SegmentLength() int

func (*Ballpoint) SegmentOpacity

func (p *Ballpoint) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Ballpoint) SegmentWidth

func (p *Ballpoint) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Ballpoint) StrokeLinecap

func (p *Ballpoint) StrokeLinecap() string

type Block

type Block interface {
	BlockType() uint8
	ExtraData() []byte
}

Block is the common interface for top-level tagged blocks in a v6 .rm file.

func ReadBlock

func ReadBlock(s *DataStream) (Block, error)

ReadBlock parses the next top-level block from stream. Returns io.EOF when no more blocks remain.

type Brush

type Brush struct {
	// contains filtered or unexported fields
}

Brush (Paintbrush) implementation with pressure-sensitive color and width.

func NewBrush

func NewBrush(width float64, color Color) *Brush

func (*Brush) BaseColor

func (p *Brush) BaseColor() Color

func (*Brush) BaseWidth

func (p *Brush) BaseWidth() float64

func (*Brush) Name

func (p *Brush) Name() string

func (*Brush) SegmentColor

func (p *Brush) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Brush) SegmentLength

func (p *Brush) SegmentLength() int

func (*Brush) SegmentOpacity

func (p *Brush) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Brush) SegmentWidth

func (p *Brush) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Brush) StrokeLinecap

func (p *Brush) StrokeLinecap() string

type Calligraphy

type Calligraphy struct {
	// contains filtered or unexported fields
}

Calligraphy pen implementation.

func NewCalligraphy

func NewCalligraphy(width float64, color Color) *Calligraphy

func (*Calligraphy) BaseColor

func (p *Calligraphy) BaseColor() Color

func (*Calligraphy) BaseWidth

func (p *Calligraphy) BaseWidth() float64

func (*Calligraphy) Name

func (p *Calligraphy) Name() string

func (*Calligraphy) SegmentColor

func (p *Calligraphy) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Calligraphy) SegmentLength

func (p *Calligraphy) SegmentLength() int

func (*Calligraphy) SegmentOpacity

func (p *Calligraphy) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Calligraphy) SegmentWidth

func (p *Calligraphy) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Calligraphy) StrokeLinecap

func (p *Calligraphy) StrokeLinecap() string

type Color

type Color struct {
	R     uint8   `json:"r"`
	G     uint8   `json:"g"`
	B     uint8   `json:"b"`
	Alpha float64 `json:"alpha,omitempty"`
}

Color represents an RGB color with optional alpha transparency.

func ExtractHighlighterColor

func ExtractHighlighterColor(extraBytes []byte) Color

ExtractHighlighterColor extracts a 24-bit RGB color from Paper Pro extra_value_data.

Paper Pro stores color in little-endian BGRA format following tag 0x84 0x01 (tag index 8, type Byte4). Defaults to standard highlighter yellow (255, 235, 59) if tag 0x84 0x01 is absent or malformed.

func ExtractHighlighterColorWithFallback

func ExtractHighlighterColorWithFallback(extraBytes []byte, fallback Color) Color

ExtractHighlighterColorWithFallback extracts a 24-bit RGB color from Paper Pro extra_value_data, returning fallback if tag 0x84 0x01 is absent or malformed.

func GetColor

func GetColor(c PenColor) Color

GetColor returns the RGB color for a given PenColor, falling back to black if unknown.

func (Color) Hex

func (c Color) Hex() string

Hex returns the #RRGGBB hexadecimal representation of the color.

func (Color) String

func (c Color) String() string

type CrdtId

type CrdtId struct {
	Part1 uint8  `json:"part1"`
	Part2 uint64 `json:"part2"`
}

CrdtId is a unique identifier or timestamp in reMarkable CRDT structures.

func (CrdtId) IsZero

func (id CrdtId) IsZero() bool

func (CrdtId) String

func (id CrdtId) String() string

type DataStream

type DataStream struct {
	// contains filtered or unexported fields
}

DataStream wraps an io.ReadSeeker to provide primitives for reading reMarkable v6 binary data.

func NewDataStream

func NewDataStream(r io.ReadSeeker) *DataStream

NewDataStream creates a new DataStream from an io.ReadSeeker.

func (*DataStream) CheckTag

func (s *DataStream) CheckTag(expectedIndex int, expectedType TagType) bool

CheckTag checks whether the next tag matches expectedIndex and expectedType without advancing the stream.

func (*DataStream) ReadBool

func (s *DataStream) ReadBool() (bool, error)

ReadBool reads a single boolean byte.

func (*DataStream) ReadBytes

func (s *DataStream) ReadBytes(n int) ([]byte, error)

ReadBytes reads exactly n bytes from the stream.

func (*DataStream) ReadCrdtId

func (s *DataStream) ReadCrdtId() (CrdtId, error)

ReadCrdtId reads a CRDT identifier (uint8 part1 followed by varuint part2).

func (*DataStream) ReadFloat32

func (s *DataStream) ReadFloat32() (float32, error)

ReadFloat32 reads a 32-bit little-endian IEEE-754 float.

func (*DataStream) ReadFloat64

func (s *DataStream) ReadFloat64() (float64, error)

ReadFloat64 reads a 64-bit little-endian IEEE-754 double.

func (*DataStream) ReadId

func (s *DataStream) ReadId(index int) (CrdtId, error)

ReadId reads a tagged CRDT ID with TagType ID.

func (*DataStream) ReadLwwBool

func (s *DataStream) ReadLwwBool(index int) (LwwValue[bool], error)

ReadLwwBool reads a LWW bool subblock at the given index.

func (*DataStream) ReadLwwByte

func (s *DataStream) ReadLwwByte(index int) (LwwValue[uint8], error)

ReadLwwByte reads a LWW byte subblock at the given index.

func (*DataStream) ReadLwwFloat

func (s *DataStream) ReadLwwFloat(index int) (LwwValue[float32], error)

ReadLwwFloat reads a LWW float subblock at the given index.

func (*DataStream) ReadLwwId

func (s *DataStream) ReadLwwId(index int) (LwwValue[CrdtId], error)

ReadLwwId reads a LWW CRDT ID subblock at the given index.

func (*DataStream) ReadLwwString

func (s *DataStream) ReadLwwString(index int) (LwwValue[string], error)

ReadLwwString reads a LWW string subblock at the given index.

func (*DataStream) ReadString

func (s *DataStream) ReadString(index int) (string, error)

ReadString reads a string subblock at the given tag index.

func (*DataStream) ReadTag

func (s *DataStream) ReadTag(expectedIndex int, expectedType TagType) (int, TagType, error)

ReadTag reads and validates that the next tag matches expectedIndex and expectedType. If it does not match, the stream is rewound to the position before the tag.

func (*DataStream) ReadTagValues

func (s *DataStream) ReadTagValues() (int, TagType, error)

ReadTagValues decodes the next varuint tag into (index, tagType).

func (*DataStream) ReadTaggedBool

func (s *DataStream) ReadTaggedBool(index int) (bool, error)

ReadTaggedBool reads a tagged bool with TagType Byte1.

func (*DataStream) ReadTaggedByte

func (s *DataStream) ReadTaggedByte(index int) (uint8, error)

ReadTaggedByte reads a tagged byte with TagType Byte1.

func (*DataStream) ReadTaggedDouble

func (s *DataStream) ReadTaggedDouble(index int) (float64, error)

ReadTaggedDouble reads a tagged 8-byte double with TagType Byte8.

func (*DataStream) ReadTaggedFloat

func (s *DataStream) ReadTaggedFloat(index int) (float32, error)

ReadTaggedFloat reads a tagged 4-byte float with TagType Byte4.

func (*DataStream) ReadTaggedInt

func (s *DataStream) ReadTaggedInt(index int) (uint32, error)

ReadTaggedInt reads a tagged 4-byte unsigned integer with TagType Byte4.

func (*DataStream) ReadUint8

func (s *DataStream) ReadUint8() (uint8, error)

ReadUint8 reads a single 8-bit unsigned integer.

func (*DataStream) ReadUint16

func (s *DataStream) ReadUint16() (uint16, error)

ReadUint16 reads a 16-bit little-endian unsigned integer.

func (*DataStream) ReadUint32

func (s *DataStream) ReadUint32() (uint32, error)

ReadUint32 reads a 32-bit little-endian unsigned integer.

func (*DataStream) ReadVarUint

func (s *DataStream) ReadVarUint() (uint64, error)

ReadVarUint reads an unsigned LEB128 variable-length integer.

func (*DataStream) Seek

func (s *DataStream) Seek(offset int64, whence int) (int64, error)

Seek seeks to offset relative to whence.

func (*DataStream) Tell

func (s *DataStream) Tell() int64

Tell returns the current byte position in the stream.

type DataWriter

type DataWriter struct {
	// contains filtered or unexported fields
}

DataWriter wraps an io.Writer to serialize reMarkable v6 binary structures.

func NewDataWriter

func NewDataWriter(w io.Writer) *DataWriter

NewDataWriter creates a new DataWriter.

func (*DataWriter) WriteBlock

func (w *DataWriter) WriteBlock(blockType, minVersion, currentVersion uint8, writeFn func(bw *DataWriter) error) error

WriteBlock writes a top-level block with 8-byte header and payload.

func (*DataWriter) WriteBool

func (w *DataWriter) WriteBool(v bool) error

WriteBool writes a single boolean byte.

func (*DataWriter) WriteBytes

func (w *DataWriter) WriteBytes(b []byte) error

WriteBytes writes raw bytes to the stream.

func (*DataWriter) WriteCrdtId

func (w *DataWriter) WriteCrdtId(id CrdtId) error

WriteCrdtId writes a CrdtId (part1 uint8 + part2 varuint).

func (*DataWriter) WriteFloat32

func (w *DataWriter) WriteFloat32(v float32) error

WriteFloat32 writes a 32-bit little-endian float.

func (*DataWriter) WriteFloat64

func (w *DataWriter) WriteFloat64(v float64) error

WriteFloat64 writes a 64-bit little-endian double.

func (*DataWriter) WriteHeader

func (w *DataWriter) WriteHeader() error

WriteHeader writes the 43-byte magic header.

func (*DataWriter) WriteId

func (w *DataWriter) WriteId(index int, id CrdtId) error

WriteId writes a tagged CrdtId.

func (*DataWriter) WriteLine

func (w *DataWriter) WriteLine(line *Line, version uint8) error

WriteLine writes a Line structure inside a subblock.

func (*DataWriter) WriteLwwBool

func (w *DataWriter) WriteLwwBool(index int, ts CrdtId, val bool) error

WriteLwwBool writes a tagged LwwValue[bool].

func (*DataWriter) WriteLwwByte

func (w *DataWriter) WriteLwwByte(index int, ts CrdtId, val uint8) error

WriteLwwByte writes a tagged LwwValue[uint8].

func (*DataWriter) WriteLwwFloat

func (w *DataWriter) WriteLwwFloat(index int, ts CrdtId, val float32) error

WriteLwwFloat writes a tagged LwwValue[float32].

func (*DataWriter) WriteLwwId

func (w *DataWriter) WriteLwwId(index int, ts CrdtId, val CrdtId) error

WriteLwwId writes a tagged LwwValue[CrdtId].

func (*DataWriter) WriteLwwString

func (w *DataWriter) WriteLwwString(index int, ts CrdtId, val string) error

WriteLwwString writes a tagged LwwValue[string].

func (*DataWriter) WritePoint

func (w *DataWriter) WritePoint(p Point, version uint8) error

WritePoint writes a Point in version 2 format (14 bytes) or version 1 format (24 bytes).

func (*DataWriter) WriteSceneLineItemBlock

func (w *DataWriter) WriteSceneLineItemBlock(block *SceneLineItemBlock, version uint8) error

WriteSceneLineItemBlock writes a complete SceneLineItemBlock.

func (*DataWriter) WriteString

func (w *DataWriter) WriteString(index int, s string) error

WriteString writes a tagged string subblock.

func (*DataWriter) WriteSubblock

func (w *DataWriter) WriteSubblock(index int, writeFn func(sw *DataWriter) error) error

WriteSubblock writes a subblock prefixed with tag index and length.

func (*DataWriter) WriteTag

func (w *DataWriter) WriteTag(index int, tagType TagType) error

WriteTag writes a tag with the given index and TagType.

func (*DataWriter) WriteTaggedBool

func (w *DataWriter) WriteTaggedBool(index int, v bool) error

WriteTaggedBool writes a tagged bool (TagByte1).

func (*DataWriter) WriteTaggedByte

func (w *DataWriter) WriteTaggedByte(index int, v uint8) error

WriteTaggedByte writes a tagged uint8 (TagByte1).

func (*DataWriter) WriteTaggedDouble

func (w *DataWriter) WriteTaggedDouble(index int, v float64) error

WriteTaggedDouble writes a tagged float64 (TagByte8).

func (*DataWriter) WriteTaggedFloat

func (w *DataWriter) WriteTaggedFloat(index int, v float32) error

WriteTaggedFloat writes a tagged float32 (TagByte4).

func (*DataWriter) WriteTaggedInt

func (w *DataWriter) WriteTaggedInt(index int, v uint32) error

WriteTaggedInt writes a tagged uint32 (TagByte4).

func (*DataWriter) WriteUint8

func (w *DataWriter) WriteUint8(v uint8) error

WriteUint8 writes a single uint8.

func (*DataWriter) WriteUint16

func (w *DataWriter) WriteUint16(v uint16) error

WriteUint16 writes a 16-bit little-endian integer.

func (*DataWriter) WriteUint32

func (w *DataWriter) WriteUint32(v uint32) error

WriteUint32 writes a 32-bit little-endian integer.

func (*DataWriter) WriteVarUint

func (w *DataWriter) WriteVarUint(v uint64) error

WriteVarUint writes an unsigned LEB128 variable-length integer.

type EraseArea

type EraseArea struct {
	// contains filtered or unexported fields
}

EraseArea implementation.

func NewEraseArea

func NewEraseArea(width float64, color Color) *EraseArea

func (*EraseArea) BaseColor

func (p *EraseArea) BaseColor() Color

func (*EraseArea) BaseWidth

func (p *EraseArea) BaseWidth() float64

func (*EraseArea) Name

func (p *EraseArea) Name() string

func (*EraseArea) SegmentColor

func (p *EraseArea) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*EraseArea) SegmentLength

func (p *EraseArea) SegmentLength() int

func (*EraseArea) SegmentOpacity

func (p *EraseArea) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*EraseArea) SegmentWidth

func (p *EraseArea) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*EraseArea) StrokeLinecap

func (p *EraseArea) StrokeLinecap() string

type Eraser

type Eraser struct {
	// contains filtered or unexported fields
}

Eraser implementation.

func NewEraser

func NewEraser(width float64, color Color) *Eraser

func (*Eraser) BaseColor

func (p *Eraser) BaseColor() Color

func (*Eraser) BaseWidth

func (p *Eraser) BaseWidth() float64

func (*Eraser) Name

func (p *Eraser) Name() string

func (*Eraser) SegmentColor

func (p *Eraser) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Eraser) SegmentLength

func (p *Eraser) SegmentLength() int

func (*Eraser) SegmentOpacity

func (p *Eraser) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Eraser) SegmentWidth

func (p *Eraser) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Eraser) StrokeLinecap

func (p *Eraser) StrokeLinecap() string

type Fineliner

type Fineliner struct {
	// contains filtered or unexported fields
}

Fineliner pen implementation.

func NewFineliner

func NewFineliner(width float64, color Color) *Fineliner

func (*Fineliner) BaseColor

func (p *Fineliner) BaseColor() Color

func (*Fineliner) BaseWidth

func (p *Fineliner) BaseWidth() float64

func (*Fineliner) Name

func (p *Fineliner) Name() string

func (*Fineliner) SegmentColor

func (p *Fineliner) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Fineliner) SegmentLength

func (p *Fineliner) SegmentLength() int

func (*Fineliner) SegmentOpacity

func (p *Fineliner) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Fineliner) SegmentWidth

func (p *Fineliner) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Fineliner) StrokeLinecap

func (p *Fineliner) StrokeLinecap() string

type Group

type Group struct {
	NodeID          CrdtId   `json:"node_id"`
	Label           string   `json:"label"`
	Visible         bool     `json:"visible"`
	AnchorID        *CrdtId  `json:"anchor_id,omitempty"`
	AnchorType      *uint8   `json:"anchor_type,omitempty"`
	AnchorThreshold *float32 `json:"anchor_threshold,omitempty"`
	AnchorOriginX   *float32 `json:"anchor_origin_x,omitempty"`
}

Group represents a scene tree group node (e.g. layer).

type Highlighter

type Highlighter struct {
	// contains filtered or unexported fields
}

Highlighter implementation.

func NewHighlighter

func NewHighlighter(width float64, color Color) *Highlighter

func (*Highlighter) BaseColor

func (p *Highlighter) BaseColor() Color

func (*Highlighter) BaseWidth

func (p *Highlighter) BaseWidth() float64

func (*Highlighter) Name

func (p *Highlighter) Name() string

func (*Highlighter) SegmentColor

func (p *Highlighter) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Highlighter) SegmentLength

func (p *Highlighter) SegmentLength() int

func (*Highlighter) SegmentOpacity

func (p *Highlighter) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Highlighter) SegmentWidth

func (p *Highlighter) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Highlighter) StrokeLinecap

func (p *Highlighter) StrokeLinecap() string

type Item

type Item[T any] struct {
	ItemID        CrdtId `json:"item_id"`
	LeftID        CrdtId `json:"left_id"`
	RightID       CrdtId `json:"right_id"`
	DeletedLength uint32 `json:"deleted_length"`
	Value         T      `json:"value"`
}

Item represents a CRDT sequence item wrapping a value.

type Line

type Line struct {
	Color          PenColor `json:"color"`
	Tool           PenTool  `json:"tool"`
	Points         []Point  `json:"points"`
	ThicknessScale float64  `json:"thickness_scale"`
	StartingLength float32  `json:"starting_length"`
	MoveID         *CrdtId  `json:"move_id,omitempty"`
}

Line represents a single stroke on the tablet.

type LwwValue

type LwwValue[T any] struct {
	Timestamp CrdtId `json:"timestamp"`
	Value     T      `json:"value"`
}

LwwValue holds a value managed with Last-Write-Wins semantics by timestamp.

type MainBlockInfo

type MainBlockInfo struct {
	Offset         int64
	Size           uint32
	Unknown        uint8
	MinVersion     uint8
	CurrentVersion uint8
	BlockType      uint8
	ExtraData      []byte
}

MainBlockInfo holds metadata about a top-level block.

type Marker

type Marker struct {
	// contains filtered or unexported fields
}

Marker pen implementation with tilt-sensitive width.

func NewMarker

func NewMarker(width float64, color Color) *Marker

func (*Marker) BaseColor

func (p *Marker) BaseColor() Color

func (*Marker) BaseWidth

func (p *Marker) BaseWidth() float64

func (*Marker) Name

func (p *Marker) Name() string

func (*Marker) SegmentColor

func (p *Marker) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Marker) SegmentLength

func (p *Marker) SegmentLength() int

func (*Marker) SegmentOpacity

func (p *Marker) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Marker) SegmentWidth

func (p *Marker) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Marker) StrokeLinecap

func (p *Marker) StrokeLinecap() string

type MechanicalPencil

type MechanicalPencil struct {
	// contains filtered or unexported fields
}

MechanicalPencil implementation.

func NewMechanicalPencil

func NewMechanicalPencil(width float64, color Color) *MechanicalPencil

func (*MechanicalPencil) BaseColor

func (p *MechanicalPencil) BaseColor() Color

func (*MechanicalPencil) BaseWidth

func (p *MechanicalPencil) BaseWidth() float64

func (*MechanicalPencil) Name

func (p *MechanicalPencil) Name() string

func (*MechanicalPencil) SegmentColor

func (p *MechanicalPencil) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*MechanicalPencil) SegmentLength

func (p *MechanicalPencil) SegmentLength() int

func (*MechanicalPencil) SegmentOpacity

func (p *MechanicalPencil) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*MechanicalPencil) SegmentWidth

func (p *MechanicalPencil) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*MechanicalPencil) StrokeLinecap

func (p *MechanicalPencil) StrokeLinecap() string

type MigrationInfoBlock

type MigrationInfoBlock struct {
	MigrationID CrdtId `json:"migration_id"`
	IsDevice    bool   `json:"is_device"`
	Unknown     bool   `json:"unknown,omitempty"`
	// contains filtered or unexported fields
}

MigrationInfoBlock represents migration metadata (BlockType 0x00).

func (*MigrationInfoBlock) BlockType

func (b *MigrationInfoBlock) BlockType() uint8

func (*MigrationInfoBlock) ExtraData

func (b *MigrationInfoBlock) ExtraData() []byte

type PageInfoBlock

type PageInfoBlock struct {
	LoadsCount        uint32 `json:"loads_count"`
	MergesCount       uint32 `json:"merges_count"`
	TextCharsCount    uint32 `json:"text_chars_count"`
	TextLinesCount    uint32 `json:"text_lines_count"`
	TypeFolioUseCount uint32 `json:"type_folio_use_count,omitempty"`
	// contains filtered or unexported fields
}

PageInfoBlock holds document page statistics (BlockType 0x0A).

func (*PageInfoBlock) BlockType

func (b *PageInfoBlock) BlockType() uint8

func (*PageInfoBlock) ExtraData

func (b *PageInfoBlock) ExtraData() []byte

type Pen

type Pen interface {
	Name() string
	SegmentLength() int
	StrokeLinecap() string
	BaseWidth() float64
	BaseColor() Color
	SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64
	SegmentColor(speed, direction, width, pressure, lastWidth float64) string
	SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64
}

Pen is the interface implemented by all writing and drawing tools.

func CreatePen

func CreatePen(tool PenTool, colorID PenColor, thicknessScale float64) Pen

CreatePen instantiates the appropriate Pen model given tool enum, color enum, and thickness scale.

func CreatePenWithColor

func CreatePenWithColor(tool PenTool, color Color, thicknessScale float64) Pen

CreatePenWithColor instantiates the appropriate Pen model given tool enum, resolved Color, and thickness scale.

type PenColor

type PenColor int

PenColor represents the palette color index stored in the stroke line.

const (
	PenColorBlack       PenColor = 0
	PenColorGray        PenColor = 1
	PenColorWhite       PenColor = 2
	PenColorYellow      PenColor = 3
	PenColorGreen       PenColor = 4
	PenColorPink        PenColor = 5
	PenColorBlue        PenColor = 6
	PenColorRed         PenColor = 7
	PenColorGrayOverlap PenColor = 8
	PenColorHighlight   PenColor = 9
	PenColorGreen2      PenColor = 10
	PenColorCyan        PenColor = 11
	PenColorMagenta     PenColor = 12
	PenColorYellow2     PenColor = 13
)

func (PenColor) String

func (c PenColor) String() string

type PenTool

type PenTool int

PenTool represents the writing or drawing instrument used for a stroke.

const (
	PenToolPaintbrush1       PenTool = 0
	PenToolPencil1           PenTool = 1
	PenToolBallpoint1        PenTool = 2
	PenToolMarker1           PenTool = 3
	PenToolFineliner1        PenTool = 4
	PenToolHighlighter1      PenTool = 5
	PenToolEraser            PenTool = 6
	PenToolMechanicalPencil1 PenTool = 7
	PenToolEraserArea        PenTool = 8
	PenToolPaintbrush2       PenTool = 12
	PenToolMechanicalPencil2 PenTool = 13
	PenToolPencil2           PenTool = 14
	PenToolBallpoint2        PenTool = 15
	PenToolMarker2           PenTool = 16
	PenToolFineliner2        PenTool = 17
	PenToolHighlighter2      PenTool = 18
	PenToolCalligraphy       PenTool = 21
	PenToolShader            PenTool = 23
)

func (PenTool) IsHighlighter

func (t PenTool) IsHighlighter() bool

IsHighlighter returns true if the tool is any variation of the highlighter or shader wash.

func (PenTool) String

func (t PenTool) String() string

type Pencil

type Pencil struct {
	// contains filtered or unexported fields
}

Pencil implementation with pressure, tilt and speed curves.

func NewPencil

func NewPencil(width float64, color Color) *Pencil

func (*Pencil) BaseColor

func (p *Pencil) BaseColor() Color

func (*Pencil) BaseWidth

func (p *Pencil) BaseWidth() float64

func (*Pencil) Name

func (p *Pencil) Name() string

func (*Pencil) SegmentColor

func (p *Pencil) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Pencil) SegmentLength

func (p *Pencil) SegmentLength() int

func (*Pencil) SegmentOpacity

func (p *Pencil) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Pencil) SegmentWidth

func (p *Pencil) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Pencil) StrokeLinecap

func (p *Pencil) StrokeLinecap() string

type Point

type Point struct {
	X         float32 `json:"x"`
	Y         float32 `json:"y"`
	Speed     uint16  `json:"speed"`
	Direction uint8   `json:"direction"`
	Width     uint16  `json:"width"`
	Pressure  uint8   `json:"pressure"`
}

Point represents a single point in a stroke with location and stylus telemetry.

type SVGOption

type SVGOption func(*SVGOptions)

SVGOption is a functional option for configuring SVG output.

func WithDimensions

func WithDimensions(widthPt, heightPt float64) SVGOption

WithDimensions sets explicit SVG width and height in points.

func WithHighlighterOpacity

func WithHighlighterOpacity(opacity float64) SVGOption

WithHighlighterOpacity configures the opacity used for highlighter strokes.

func WithHighlighterWidth

func WithHighlighterWidth(width float64) SVGOption

WithHighlighterWidth configures the stroke width used for highlighters.

func WithViewBox

func WithViewBox(viewBox string) SVGOption

WithViewBox sets an explicit viewBox attribute on the root SVG element.

type SVGOptions

type SVGOptions struct {
	WidthPt            float64
	HeightPt           float64
	ViewBox            string
	HighlighterOpacity float64
	HighlighterWidth   float64
}

SVGOptions configures the SVG exporter output.

type Scene

type Scene struct {
	Blocks []Block
}

Scene represents a parsed reMarkable .rm v6 scene file.

func Parse

func Parse(data []byte) (*Scene, error)

Parse parses a reMarkable v6 .rm binary file from bytes.

func ParseReader

func ParseReader(r io.Reader) (*Scene, error)

ParseReader parses a reMarkable v6 .rm binary stream from an io.Reader.

func (*Scene) Highlighters

func (s *Scene) Highlighters() []*Line

Highlighters returns all highlighter strokes in the scene.

func (*Scene) Lines

func (s *Scene) Lines() []*Line

Lines returns all pen strokes in the scene (excluding highlighters).

func (*Scene) ToSVG

func (s *Scene) ToSVG(opts ...SVGOption) string

ToSVG exports the scene to an SVG string.

type SceneGroupItemBlock

type SceneGroupItemBlock struct {
	ParentID CrdtId       `json:"parent_id"`
	Item     Item[CrdtId] `json:"item"`
	// contains filtered or unexported fields
}

SceneGroupItemBlock represents a scene group item block (BlockType 0x04).

func (*SceneGroupItemBlock) BlockType

func (b *SceneGroupItemBlock) BlockType() uint8

func (*SceneGroupItemBlock) ExtraData

func (b *SceneGroupItemBlock) ExtraData() []byte

type SceneInfoBlock

type SceneInfoBlock struct {
	CurrentLayer        LwwValue[CrdtId] `json:"current_layer"`
	BackgroundVisible   LwwValue[bool]   `json:"background_visible"`
	RootDocumentVisible LwwValue[bool]   `json:"root_document_visible"`
	// contains filtered or unexported fields
}

SceneInfoBlock holds root scene visibility and active layer info (BlockType 0x0D).

func (*SceneInfoBlock) BlockType

func (b *SceneInfoBlock) BlockType() uint8

func (*SceneInfoBlock) ExtraData

func (b *SceneInfoBlock) ExtraData() []byte

type SceneLineItemBlock

type SceneLineItemBlock struct {
	ParentID       CrdtId      `json:"parent_id"`
	Item           Item[*Line] `json:"item"`
	ExtraValueData []byte      `json:"extra_value_data,omitempty"`
	// contains filtered or unexported fields
}

SceneLineItemBlock represents a stroke line item block (BlockType 0x05).

func (*SceneLineItemBlock) BlockType

func (b *SceneLineItemBlock) BlockType() uint8

func (*SceneLineItemBlock) ExtraData

func (b *SceneLineItemBlock) ExtraData() []byte

type SceneTreeBlock

type SceneTreeBlock struct {
	TreeID   CrdtId `json:"tree_id"`
	NodeID   CrdtId `json:"node_id"`
	IsUpdate bool   `json:"is_update"`
	ParentID CrdtId `json:"parent_id"`
	// contains filtered or unexported fields
}

SceneTreeBlock represents a hierarchy link in the scene tree (BlockType 0x01).

func (*SceneTreeBlock) BlockType

func (b *SceneTreeBlock) BlockType() uint8

func (*SceneTreeBlock) ExtraData

func (b *SceneTreeBlock) ExtraData() []byte

type Shader

type Shader struct {
	// contains filtered or unexported fields
}

Shader implementation.

func NewShader

func NewShader(width float64, color Color) *Shader

func (*Shader) BaseColor

func (p *Shader) BaseColor() Color

func (*Shader) BaseWidth

func (p *Shader) BaseWidth() float64

func (*Shader) Name

func (p *Shader) Name() string

func (*Shader) SegmentColor

func (p *Shader) SegmentColor(speed, direction, width, pressure, lastWidth float64) string

func (*Shader) SegmentLength

func (p *Shader) SegmentLength() int

func (*Shader) SegmentOpacity

func (p *Shader) SegmentOpacity(speed, direction, width, pressure, lastWidth float64) float64

func (*Shader) SegmentWidth

func (p *Shader) SegmentWidth(speed, direction, width, pressure, lastWidth float64) float64

func (*Shader) StrokeLinecap

func (p *Shader) StrokeLinecap() string

type SubBlockInfo

type SubBlockInfo struct {
	Offset    int64
	Size      uint32
	ExtraData []byte
}

SubBlockInfo holds metadata about a subblock.

type TagType

type TagType uint8

TagType represents the data type following a tag in the binary format.

const (
	TagByte1   TagType = 0x1 // 1 byte (bool or uint8)
	TagByte4   TagType = 0x4 // 4 bytes (uint32 or float32)
	TagByte8   TagType = 0x8 // 8 bytes (float64 / double)
	TagLength4 TagType = 0xC // 4-byte length prefix for subblock
	TagID      TagType = 0xF // CrdtId (1 byte part1 + varuint part2)
)

func (TagType) String

func (t TagType) String() string

type TreeNodeBlock

type TreeNodeBlock struct {
	Group Group `json:"group"`
	// contains filtered or unexported fields
}

TreeNodeBlock represents a layer or tree node block (BlockType 0x02).

func (*TreeNodeBlock) BlockType

func (b *TreeNodeBlock) BlockType() uint8

func (*TreeNodeBlock) ExtraData

func (b *TreeNodeBlock) ExtraData() []byte

type UnknownBlock

type UnknownBlock struct {
	Type uint8         `json:"block_type"`
	Info MainBlockInfo `json:"info"`
	Data []byte        `json:"data"`
	// contains filtered or unexported fields
}

UnknownBlock captures unhandled or forward-compatible block types safely.

func (*UnknownBlock) BlockType

func (b *UnknownBlock) BlockType() uint8

func (*UnknownBlock) ExtraData

func (b *UnknownBlock) ExtraData() []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址