PlutoBook Rendering Engine

repository·main·Indexed 43 days ago

https://github.com/plutoprint/plutobook

A high-performance, lightweight HTML/XML rendering engine written in C++ for paged media, such as PDF and Bitmap output. It features a memory-efficient independent engine that avoids reliance on Chromium, WebKit, or Gecko. PlutoBook supports CSS 3 and parts of CSS 4, HTML5, XHTML, and SVG, providing both C and C++ APIs for document layout, page-level rendering, and full-document image exports.

Tokens
7.9K
Snippets
9
Records
40
Agent score
54%

What's inside PlutoBook

  1. Overview of PlutoBook features and capabilities

    main

    PlutoBook is a high-performance document renderer for static layout and print-ready output.

    Core Capabilities:

    • Web Standards: Supports most of CSS 3 and parts of CSS 4, HTML5, XHTML, and SVG.
    • Image Formats: Supports JPG, PNG, WEBP, GIF, BMP, and TGA.
    • Output Formats: Supports PDF, image files, and any format supported by Cairo (e.g., SVG, PostScript).
    • Text & Fonts: Robust international text layout via ICU and HarfBuzz (Arabic, Hebrew, Hindi, etc.). Font handling via Fontconfig and FreeType allows access to system fonts. Supports emoji rendering.
    • Resource Loading: Supports file:, data:, and remote resources (http, https, ftp) via libcurl. Users can plug in custom fetchers for resource loading control.
  2. What is PlutoBook?

    main

    PlutoBook is a robust HTML/XML rendering library specifically designed for paged media. It allows you to take HTML or XML input, apply CSS stylesheets, and layout elements across multiple pages. The output can be rendered as Bitmap images or PDF documents.

    Key characteristics:

    • Independent Engine: It does not depend on Chromium, WebKit, or Gecko; it uses its own lightweight, memory-efficient C++ rendering engine.
    • Performance: Designed to be fast and low-memory, utilizing std::pmr::monotonic_buffer_resource to optimize allocations and minimize fragmentation.
  3. Understand libjpeg-turbo licensing models

    main

    libjpeg-turbo is covered by two compatible BSD-style licenses depending on which part of the library you are using:

    • IJG (Independent JPEG Group) License: Applies to the libjpeg API library and associated programs, including inherited code and modifications. Note that while SIMD source code uses the zlib License, its terms are subsumed by the IJG License in the context of the overall API library.
    • Modified (3-clause) BSD License: Applies to the TurboJPEG API library, associated programs, and the build system. Because the TurboJPEG API wraps the libjpeg API, both the IJG License and the Modified (3-clause) BSD License apply when using TurboJPEG.
  4. General restrictions and disclaimers for libjpeg-turbo

    main

    When using libjpeg-turbo, observe the following restrictions:

    • No Endorsement: You cannot use the name of the IJG, the libjpeg-turbo Project, or its contributors in advertising, publicity, or to endorse/promote products derived from this software without specific prior written permission.
    • No Warranty: The IJG and the libjpeg-turbo Project do not warrant the software to be free of defects and accept no liability for undesirable consequences resulting from its use.
  5. Use Paged Media for layout control

    main

    PlutoBook supports the CSS Paged Media Module Level 3, enabling precise control over content layout across multiple pages. You can use @page rules to define page margins and use margin boxes (e.g., @top-left, @bottom-center) to create running headers and footers.

    Current Limitations:

    • PlutoBook uses the page size and margin defined for the first page globally.
    • @page :first is the only pseudo-page selector that works reliably.
    • Named pages (@page name) are not yet fully implemented.
  6. Use Media Queries for Responsive Design

    main

    PlutoBook supports CSS Media Queries to adapt styles based on the output environment.

    Media Types:

    • all: Any device.
    • print: Paged output (e.g., PDFs).
    • screen: Typical on-screen displays.

    Media Features:

    • Dimensions: width, min-width, max-width, height, min-height, max-height.
    • Orientation: orientation (portrait vs. landscape).

    Logic & Restrictors:

    • Combine conditions using the and keyword.
    • Use only to ensure the query is fully understood by the engine.
    • Use not to reverse a condition.
  7. Create Multi-column Layouts

    main

    PlutoBook implements CSS Multi-column Layout Module Level 1 to allow content to flow into multiple columns (newspaper-style).

    Key Properties:

    • Column Sizing: Use column-count to specify the number of columns, or column-width to set a target width. The columns shorthand can be used to set both.
    • Spacing: Use column-gap to adjust the space between columns.
    • Dividers: Use column-rule-color, column-rule-style, and column-rule-width (or the column-rule shorthand) to add lines between columns.
    • Spanning: Use column-span on an element to make it break the column flow (e.g., for headings).
    • Content Distribution: Use column-fill with values balance (even distribution) or auto (sequential filling).
  8. Use Flexible Box (Flexbox) Layout

    main

    PlutoBook supports CSS Flexible Box Layout Module Level 1 for efficient space distribution among items in a container.

    Implementation Details:

    • Containers: Define a container using display: flex or display: inline-flex.
    • Direction & Wrapping: Control placement with flex-direction and wrapping with flex-wrap (or the flex-flow shorthand).
    • Alignment:
      • justify-content: Main-axis alignment.
      • align-items: Cross-axis alignment of items.
      • align-content: Alignment of multiple lines when wrapping.
      • align-self: Individual item override for cross-axis alignment.
    • Item Sizing: Use the flex shorthand or flex-grow, flex-shrink, and flex-basis.
    • Ordering: Use the order property to change the visual sequence of items.
    • Spacing: Use gap, row-gap, or column-gap to manage spacing between items.
  9. Use CSS Custom Properties (Variables)

    main

    PlutoBook supports CSS Custom Properties (CSS variables) for reusable design tokens.

    Usage:

    • Declaration: Define variables with a -- prefix (e.g., --main-color: red;).
    • Reference: Use the var() function to apply the value.
    • Fallbacks: You can provide a fallback value if the variable is undefined: var(--unknown, red).
    • Note: Advanced @property at-rule typed custom properties are not yet supported.
  10. Use Logical Properties for Flow-Relative Styling

    main

    PlutoBook supports CSS Logical Properties, allowing styles to adapt to different writing directions (block vs. inline axes).

    Supported Logical Properties:

    • Box Model: margin-block, margin-inline, padding-block, padding-inline (including -start and -end variants).
    • Sizing: inline-size, block-size, and their min/max forms.
    • Borders & Corners: Logical borders and logical corner radii.
    • Layout & Alignment: Logical values for float (inline-start, inline-end) and text-align (start, end).

    Limitation: writing-mode is partially supported to resolve mapping, but full vertical layout rendering is not guaranteed.

  11. Implement Table Layouts and Styling

    main

    PlutoBook supports CSS Tables Module Level 3, allowing for semantic HTML <table> markup or CSS-driven tabular layouts.

    Key Capabilities:

    • Display Values: Supports table, inline-table, table-row, table-row-group, table-header-group, table-footer-group, table-column, table-column-group, table-cell, and table-caption.
    • Border Control: Use border-collapse and border-spacing to manage cell borders.
    • Layout Modes: Supports table-layout: auto and table-layout: fixed.
    • Spanning: Cells can span rows or columns using row-span and column-span. Setting row-span: 0 allows a cell to automatically span all remaining rows in its row group.
  12. Embed and style Scalable Vector Graphics (SVG)

    main

    PlutoBook supports SVG (SVG 1.1, 1.2 Tiny, and select SVG 2.0 features). You can embed SVGs as standalone XML, inline HTML, or external image references. The svg element behaves as a replaced element (like <img>) and supports standard layout properties like display, float, margin, padding, border, and background.

    Supported Features:

    • Basic shapes, paths, and text.
    • Fills, strokes, gradients, and patterns.
    • Markers, masks, clip paths, and transformations.
    • Styling via both presentation attributes and CSS.

    Note: SVG animation is currently not supported.