fop-layout
Layout engine for the Apache FOP Rust implementation. Transforms the FO tree (from fop-core) into an area tree that can be rendered to PDF or other formats.
Version: 0.1.1 | Release Date: 2026-04-20
Pipeline
FO Tree (fop-core)
|
v
LayoutEngine -- coordinates the process
|
+-- BlockLayout -- stacks blocks vertically
+-- InlineLayout -- positions text horizontally, breaks lines
+-- TableLayout -- computes column widths, positions cells
+-- ListLayout -- positions labels and bodies side-by-side
+-- PageBreaker -- splits content across pages
|
v
Area Tree -- positioned rectangles ready for rendering
Installation
Add fop-layout to your Cargo.toml:
[]
= "0.1"
Or with cargo add:
Usage
use FoTreeBuilder;
use LayoutEngine;
use Cursor;
Architecture
area/ — Area Tree Data Structures
| File | Lines | Description |
|---|---|---|
types.rs |
205 | Area, AreaType (8 types), TraitSet, FontStyle |
area_tree.rs |
241 | AreaTree, AreaNode, AreaId (arena-allocated) |
Area Types: Page, Region, Block, Inline, Line, Table, ListItem, Image
Each area has a Rect (position + size) and an optional TraitSet for styling (font, color, borders).
layout/ — Layout Algorithms
| File | Lines | Description |
|---|---|---|
engine.rs |
533 | LayoutEngine — main coordinator, wires all algorithms |
block.rs |
100 | BlockLayoutContext — vertical block stacking |
inline.rs |
238 | InlineArea, InlineLayoutContext, LineBreaker |
knuth_plass.rs |
336 | KnuthPlassBreaker — optimal line breaking algorithm |
table.rs |
421 | TableLayout, ColumnWidth — table column computation |
list.rs |
362 | ListLayout, ListMarkerStyle — list positioning |
page_break.rs |
283 | PageBreaker — multi-page content splitting |
properties.rs |
210 | Property extraction (FO properties → area traits) |
Total: 2,994 lines across 11 files
Key Algorithms
Knuth-Plass Line Breaking
Optimal line breaking using the Knuth-Plass algorithm (same as TeX). Minimizes total "badness" across all lines rather than greedily filling each line.
use KnuthPlassBreaker;
use Length;
Table Layout
Computes column widths using fixed, proportional, or automatic sizing.
use ;
use Length;
List Layout
Positions list labels (markers) and bodies side-by-side with 9 marker styles.
use ;
use Length;
Marker Styles: Disc, Circle, Square, Decimal, LowerAlpha, UpperAlpha, LowerRoman, UpperRoman, None
Page Breaking
Splits content across multiple pages when it overflows.
use PageBreaker;
use Length;
Tests
52 unit tests covering:
- Block layout vertical stacking
- Inline layout horizontal positioning
- Knuth-Plass line breaking (various paragraph widths)
- Table layout (fixed, proportional, auto, mixed columns)
- List layout (all 9 marker styles, positioning)
- Page breaking (overflow detection, multi-page, area splitting)
- Area tree construction and traversal
- Property extraction from FO nodes
Dependencies
| Crate | Version | Kind |
|---|---|---|
| fop-types | workspace | Internal |
| fop-core | workspace | Internal |
| thiserror | 2.0 | Error handling |
| log | 0.4 | Logging |
Related Crates
| Crate | Description |
|---|---|
| fop-types | Core XSL-FO types (lengths, colors, properties) |
| fop-core | FO tree parser and builder |
| fop-render | Rendering traits and SVG/PostScript output |
| fop-pdf-renderer | PDF output renderer |
| fop-cli | Command-line interface |
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Author
Copyright 2024–2026 COOLJAPAN OU (Team Kitasan)