







Once the layout editor could take in external documents as editable pages, it was time to finish the opposite direction. An edited object has to stay recognizably the same object even when another tool changes it and sends it back, and a fixed page has to be convertible into very different semantic spaces, such as a responsive document or a physical printout. Exporting turned out to be less about generating files than about preserving meaning.
All of these outputs start from the same document, but each has to preserve different invariants. When going back to the original for editing, an object's identity and its editability matter most. In a responsive document, reading order and relationships matter more than fixed coordinates. In print, what matters is the exact page box, physical units, color and fonts. No single general-purpose conversion can optimize all of these invariants at once.
So I decided to build purpose-specific projections out of a common document model. Some projections throw away coordinates and keep the semantic structure; others do the opposite and pin down every bit of physical geometry. A good conversion states plainly what it keeps and what it gives up. Closing the loop that began with import, through the editable source, the responsive document and the printed page, was in the end a matter of defining several different equivalence relations.
The first distinction I drew for the editing round trip was between an object's identity and its current value. Even if an image's pixels or a vector path change, the role that object plays on the page can remain the same object. Conversely, two images that happen to have identical pixels are still two different objects. Equality of value and sameness of identity are separate relations.
Mathematically, a value is an element of some state space V, and an identity is closer to a label that ties a changing series of values into a single trajectory. If I write the visual state of object o at time t as `v_o(t)`, an edit is `v_o(t0) -> v_o(t1)`, yet o itself persists. With this distinction in place, I can replace only the content while leaving the surrounding layout and references untouched.
At the boundary where different editing regions meet, there is no need to share the entire internal state. What's needed is a minimal contract describing the identity of the target, the input revision and the meaning of the result. Mixing large assets and small control messages in the same channel couples copying cost to the unit of failure. Separating the control plane from the data plane is a general systems principle that applies not only to networks but to composite editors too.
When two results try to update the same object at the same time, revisions have to be compared. A result computed from stale input must not overwrite the latest state just because it finished later. I check that the revision read when the work started matches the revision at the moment of application, and if it doesn't, the result is merged or recomputed. A round-trip edit isn't a screen transition; it's an identity update with optimistic concurrency control.
Sending a result back to its place is safer when treated as an atomic replacement than as gradually patching a mutable object. If part of the old value is erased before the new one is fully ready, a mid-way failure becomes a loss the user can see. The old and new revisions should each exist as complete states, and the reference should switch to the new revision in a single step.
This resembles copy-on-write. Rather than overwriting an existing asset A, I create a new asset B, validate it, and only then switch object o's value from A to B. Before the switch every reader sees A, after it every reader sees B, and nobody ever sees a half-written asset. It is the same principle as an atomic rename in a filesystem or a commit in a database.
When the new value has a different aspect ratio, what to preserve also has to be decided as a constraint. Position, width, height, center point and area can't all be kept at once. If I fix the width w and apply a new ratio r, for example, the height is determined as `h = w/r`. Replacement becomes predictable once I separate the variables the user decided directly from those derived from the content.
Removing the old asset is a reachability problem over references. An asset can be judged garbage only when it can no longer be reached from a root, and if a past revision or another document references it, it has to stay alive. Reference counting is weak against cycles, and mark-and-sweep has to see the whole graph. The lifecycle of an editor's assets turned out to be the same problem as ordinary garbage collection theory.
Recovering reading order from a fixed page is harder than sorting geometry into string order. Which of two objects, A and B, should be read first can't be decided by a single comparison of x and y. Several cues, such as above-and-below relationships, the same row, columns, and the pairing of a caption with its image, combine into a partial order. The goal is to find a linear extension that doesn't violate that partial order.
I treat each object as a vertex and draw a directed edge whenever there is enough evidence that A comes before B. Separation along the y axis, shared alignment lines and containment can all justify an edge, but forcing in uncertain relationships creates cycles. A cycle doesn't mean the visual layout is contradictory; it means the heuristics are in conflict with each other. Weak edges have to be dropped, or semantic metadata given higher priority.
A page's column structure is a clustering problem in computational geometry. Taking each object's x interval and y interval, its alignment lines and the whitespace as features, I can estimate how likely objects are to belong to the same flow. Geometry alone can't fully determine meaning, though, because there's no way to know whether a shape in the same position is decoration or body text. Where explicit structure exists, it should take precedence over observed geometry.
A set of strongly overlapping objects may be a composition that can't be unrolled into a sequential document. Reading order, as a projection, can't preserve all visual information. So I have to distinguish the parts that can be moved into semantic structure from those that must stay as a single visual atom. Conversion from fixed layout to a responsive document is not a complete inverse function; it's an information projection fitted to its purpose.
Recovering responsive structure is the inverse problem of a renderer. A typical layout function L takes a structure S and a viewport v and produces geometry G. Here I have to estimate a possible S from one observed result G. Many different S satisfy `L(S, v) = G`, so the problem is ill-posed, and it needed an extra regularization criterion.
I can prefer the simplest structure, meaning the candidate that explains the geometry with the fewest containers and the fewest exception rules. This resembles the minimum description length principle. Giving every object an absolute coordinate reproduces the current G perfectly, but the description is long and doesn't generalize to other viewports. A structure described in terms of rows, columns and relative gaps is shorter, even with a little error, and more likely to be responsive.
The objective function can combine the reproduction error against the current screen with the structural complexity. In `E(S) = D(L(S,v), G) + λC(S)`, D is the difference in position and size, and C is the cost of the number of containers and exception rules. If λ is too small, the result drifts toward an absolute layout; if it is too large, it forces unrelated pieces into a single flow. Semantic metadata and reading order enter as additional constraints.
You can't fully discover responsive rules by looking at a single viewport. So the result of the conversion doesn't preserve every number in the original; it chooses the relationships that should hold across many screens. It gives priority to the meaning and order of text, the aspect ratio of images, and the relationships of the same row or column, and relaxes fine decorative positioning. I judged the correctness of responsive conversion by structural stability under new conditions rather than by pixel equality on one screen.
For the preview to match the final result, I can't count on two independent conversions happening to produce the same screen. The build has to produce a deterministic result from the same source, the same environment and the same tool versions. A reproducible build starts by spelling out the input set, the transformation function and the environment variables.
If I view the output as a function `B(source, assets, environment, version)`, it becomes easier to find which values are sneaking in implicitly. If the current time, file traversal in arbitrary order, fonts that aren't ready, or a device-specific locale change the result from outside the function, the same document produces different bytes. Only by removing such nondeterministic inputs, or including them in the build manifest, do preview and export come to mean the same thing.
Visual equivalence needed a definition as well. Bytes can differ because of compression order while the rendering is identical, and conversely the HTML string can be identical while a different font version changes the line breaks. Equivalence of document structure, of asset hashes and of final pixels each has to be checked in stages. It had to be clear which layer's sameness was being guaranteed.
So I treated the preview not as a separate mock-up but as a projection of the canonical build observed in one environment. The final deliverable must also come from the same source graph and the same transformation revision. By cutting down independent reinterpretation steps between the state the user approved and the state that gets published, the round trip between fixed pages and responsive documents settled into a reproducible production process.
Print rendering wasn't a matter of capturing the editing screen. The editing screen is mixed with state that isn't part of the document's meaning, such as selections, guides and temporary caches. Output has to start from the durable document graph and be materialized into physical page space. Removing view state wasn't a trick for deleting certain DOM elements; it was the result of separating the source model from its projection.
The renderer walks the scene graph in painter's order and accumulates each node's local transform to convert it into page coordinates. Transparency compositing depends on order, so a different z-order turns the same set of objects into a different image. Even the blending color space and whether alpha is premultiplied have to be fixed before the same scene gives similar results on every device.
What to keep as vector and what to rasterize can be judged by the closure of operations too. Affine transforms and simple fills are closed within a vector representation, but some filters and blend effects may not mean the same thing on the output device. In that case, sampling only those parts at a fixed resolution and color space while keeping the remaining geometry as vector strikes the balance between quality and compatibility.
The final page box must not contain screen zoom or device pixel ratio. The document's physical units and viewBox are the reference, and the output device converts them to its own sampling grid at the very end. By removing the editor's transient state and device-dependent variables, I made sure the same page graph lands in the same physical positions no matter when it is rendered.
A font subset isn't simply a matter of collecting the Unicode characters that appear in the document. Once shaping is applied, a character sequence can become a ligature glyph, and one glyph can reference other composite glyphs. OpenType substitution and positioning tables also select additional glyphs depending on script and language. The set that's needed isn't a simple image of the character set but the reachable closure of the shaping graph.
Starting from an initial glyph set G, I repeatedly follow composite references and substitution edges, expanding until no new glyphs appear, and that yields the least fixed point. With `G_(n+1) = G_n ∪ refs(G_n) ∪ subs(G_n)`, the point where `G_(n+1)=G_n` is the closure. Only the outlines and metrics outside this set may be removed if the typesetting relationships the document needs are to survive.
Metric tables and glyph index reassignment move together as well. If only the outlines remain while the character map, advance widths or kerning pairs still point to the old indices, the file opens but the letters come out wrong. Subsetting is the construction of an induced substructure of a graph, and every referencing table has to be carried over isomorphically into the new index space.
Font preparation is also a rendering barrier. Line breaks computed with a fallback font become invalid once the right font arrives. So the condition for “the page is ready” has to mean that the faces and metrics needed for shaping are settled, not merely that DOM creation has finished. Putting glyph closure and font readiness inside the same output contract made the typography on screen and in print match.
A screen document and a print document start from the same scene but live in different measurement spaces. The screen adapts to logical pixels and the viewport, while print is based on physical length, device resolution and the cutting process. Unless I attach a dimension to every quantity instead of mixing points, millimeters and pixels, zoom or DPI will change the size of the document.
A printed page isn't a single rectangle but a containment relationship among the media, trim, bleed and content boxes. `content ⊆ trim ⊆ bleed ⊆ media` must hold, and it must be clear which box each mark is defined against. If coordinates are derived from the box edges and offsets rather than written out page by page, the same geometric rules hold even when the trim size changes.
Raster resolution should be seen through the Nyquist lens too. Aliasing shrinks only when the sampling frequency is sufficiently higher than the spatial frequency of the finest lines and letter details. An indiscriminately high DPI only inflates memory and throughput, so it made more sense to separate elements preserved as vector from raster effects, and then calculate the resolution needed for the parts that are actually sampled.
Color space conversion is also a mapping from device-independent color to the output device's gamut. Where out-of-gamut colors get sent makes perceptual and relative colorimetric results differ. The RGB numbers on screen can't simply be copied into print channels; a profile and a rendering intent are required. Only by including physical geometry and color management did print output become a single, complete mathematical transformation.
Moving a project to another environment is closer to a graph isomorphism problem than to copying files. If the original document is a graph `G=(V,E)`, the graph `G'` in the new environment must have a correspondence function `φ:V->V'` that preserves edge relationships and node types, even if the vertices' actual names differ. What matters is not that the identifier strings are the same but that the structure is.
In a new namespace, the original identifiers may already be in use by other objects. So φ has to be injective, and every reference edge `(u,v)` has to be carried over together as `(φ(u),φ(v))`. If I create only new vertices and leave the old names inside the edges, the graph appears to exist but isn't closed. Namespace migration is a substitution applied to the entire structure.
Shared assets have to be preserved too. If two objects originally pointed at the same vertex, they must point to the same new vertex after restoration. Copying each reference independently splits what was one asset into several and changes the identity relationships. Only when φ is defined once as a global function and every edge uses the same mapping is the graph's sharing topology maintained.
Restoration is a transaction. Until the new graph is completely built and every vertex's type and the edge closure have been verified, it must not replace the existing healthy graph. A failed candidate graph is discarded and the previous revision stays. Even when every identifier is different on another computer, if the relationships among pages, styles and assets are the same, it can be stated mathematically that it is the same project.
By this stage, the role of the layout editor had been fully sorted out. The editing round trip became a revision replacement that separates identity from value, and asset changes could be explained by copy-on-write and a reachability-based lifecycle. Getting reading order from a fixed page became a linear extension of a partial order, and responsive structure became an inverse layout problem with minimum description length.
On the print path, the same document is pinned down by an entirely different equivalence relation. A reproducible build fixes the source and the environment, glyph closure closes the font graph needed for typesetting, and a deterministic renderer projects the scene graph into physical page space. Print geometry and color space were completed as transformations with a different dimension and gamut from the screen.
I repeatedly reviewed concurrent edit revisions, atomic asset replacement, complicated reading order, structural stability across viewports, font substitution, extreme page ratios and graph migration. I confirmed that the preview and the final result mean the same thing, that the box relationships of physical output hold, and that the project graph is restored isomorphically even in a new namespace. Opkle's production system, which runs from vector work through layout, EPUB and the web to real printed matter, was fully closed and stabilized at this stage.
