-- Leo's gemini proxy

-- Connecting to pgavlin.smol.pub:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

agrajag dev log 1


I've been preoccupied with pagination--a core issue for a device intended to be used for reading, but that does not support fluid scrolling.


Computing pagination isn't terribly difficult: lay out each paragraph, then emit its lines into the current page. If the page is full prior to emitting a line, break the page and emit into a new page. Once all paragraphs have been emitted, the set of page breaks is the pagination. Any change to the layout (e.g. changing the default text style) requires recomputing the pagination.


Accessing the pagination, however, can be more or less difficult depending on the source text. For example, if the source text includes contextual styling information that is not easily available at the beginning of a page, the reader must have some way to reestablish that styling information when jumping to a page.


Because I'm working with relatively tight power and memory constraints, I'd like to be able to load pages directly from non-volatile storage. It is acceptable for pagination to be a semi-offline process (read: it's okay if pagination takes a moment or two). With these characteristics in mind, I've opted to proceed with an approach that translates text from Markdown to a bespoke page description language. Documents will consist of a header that carries a vector of styles, followed by a sequence of commands for drawing each page, followed by an index of page offsets. The only state carried over from page to page is the style information in the header.


For now, a style will consist of a font face and the em size in pixels, and the page description commands will consist of the following:


* 0x20-0x7f: decode a UTF-8-encoded code point and push it into the current string to show.
             an implicit show command precedes all other commands.
* 0x00-0x08, 0x0d-0x1f: illegal
* 0x09 (ht): move the cursor tab_stop points in the current text direction
* 0x0a (nl): advance the cursor line_height points perpendicular to the current text
             direction
* 0x0b (vt): advance the cursor tab_stop points perpendicular to the current text direction
* 0x0c (ff): end the current page
* 0x80 show: displays the current string at the cursor, then advances the cursor by the
             width of the displayed string
* 0x81 advance(dx: u16): moves the cursor dx points in the current text direction
* 0x82 move_cursor(x: u16, y: u16): moves the cursor to a particular coordinate
* 0x83 set_style(i: u16): sets the current style to that identified by the given index
* 0x84 set_adjustment_ratio(r: f32): sets the current whitespace adjustment ratio to the given amount
* 0x85 set_line_height(h: u16): sets the current line height

I think that this should give me enough to render the basic Markdown constructs: block quotes, code blocks, headings, lists, and paragraphs with plain, bold, or italicized text.


For example, a page containing only the paragraph "Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-two million miles is an utterly insignificant little blue-green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea." might be represented as:


83 00 85 18
84 00 00 80 3f 46 61 72 20 6f 75 74 20 69 6e 20 74 68 65 20 75 6e 63 68 61 72 74 65 64 20 62 61 63 6b 77 61 74 65 72 73 20 6f 66 20 74 68 65 0a
84 cd cc cc be 75 6e 66 61 73 68 69 6f 6e 61 62 6c 65 20 65 6e 64 20 6f 66 20 74 68 65 20 77 65 73 74 65 72 6e 20 73 70 69 72 61 6c 20 61 72 6d 20 6f 66 20 74 68 65 20 47 61 6c 61 78 79 0a
...
84 00 00 00 00 64 69 67 69 74 61 6c 20 77 61 74 63 68 65 73 20 61 72 65 20 61 20 70 72 65 74 74 79 20 6e 65 61 74 20 69 64 65 61 2e 0c

We'll see how far this gets us.

-- Response ended

-- Page fetched on Sun May 12 09:46:52 2024