Skip to content

2.0.0

Latest

Choose a tag to compare

@odrobnik odrobnik released this 01 Jul 13:20
f8e6642

Headline: a new pure-Swift, cross-platform HTML/CSS → PDF render engine — no platform graphics dependencies — plus RTL/Arabic support and new Numbers & Keynote readers.

SwiftTextRender — HTML/CSS → PDF (new engine)

  • End-to-end HTML/CSS → PDF: DOM adapter, styled tree, box tree, block + inline layout, and paint — entirely in Swift, on every platform.
  • Paginates to fixed-size pages; honors @page size and margins from CSS.
  • Tables: block layout, colspan/rowspan, and per-cell vertical-align (top/middle/bottom).
  • Lists: item markers, list-style-type (decimal, alpha, roman, disc/circle/square, none), and correct absolute marker baselines.
  • Inline: text-decoration underline/line-through, letter-spacing/word-spacing, text-indent, white-space:pre (preserved space runs + forced breaks), and <br>.
  • Images: <img> for JPEG and PNG with no decoding dependencies.
  • Fonts: embed arbitrary OpenType fonts (CIDFontType2), WinAnsi (CP1252) encoding, Helvetica-Bold metrics for bold, serif → Times.
  • Navigation: clickable links via PDF Link annotations and a PDF outline (bookmarks) generated from headings.
  • Collapses adjacent vertical margins; honors <style> stylesheets and text-align.
  • CLI: pdf --engine swift selects the cross-platform render path.

RTL & Arabic

  • Unicode Bidirectional Algorithm (UAX #9) implemented in pure Swift.
  • RTL inline layout: bidi reordering + direction-aware alignment, with automatic base-direction detection for RTL Markdown.
  • CSS direction property and the dir attribute.
  • Arabic shaping: presentation-forms shaper and RTL lists.
  • Font fallback: per-run glyph substitution for missing glyphs.

New pure-Swift foundation modules

  • SwiftTextOpenType — pure-Swift OpenType/TrueType reader.
  • SwiftTextCSS — CSS Syntax Level 3 tokenizer/parser (tinycss2 port), selector parsing + specificity + matching, the cascade with typed computed values, and CSS Color Level 3.
  • SwiftTextPDFWriter — cross-platform PDF generator (pydyf port).
  • SwiftTextAttributedString — all-platform Markdown → Foundation AttributedString.
  • DOM: HTMLDocument.styleSheets / DOMElement.styleSheets() and resolution of <link rel="stylesheet">.

iWork: Numbers & Keynote (new readers)

  • Numbers (.numbers): extract tables as Markdown, HTML, TSV, or JSON (numbers --json). Reads frozen cell values — numbers, dates, and formula results — as static text.
  • Keynote (.key): extract slide text as Markdown (one heading per slide, body as bullets), JSON (title/body/notes per slide), or plain text.
  • Shared SwiftTextIWA module (Snappy, protobuf, TSTTableReader); PagesParser converged onto the same table reader.
  • Legacy iWork '09: Numbers via index.xml, and the shared '09 table extractor so Pages '09 reads tables too.

CLI

  • New numbers and keynote subcommands.
  • pdf --engine swift for the cross-platform render engine.
  • render --page-break-before to start chapters on new pages.

Tooling, CI & robustness

  • SwiftLint linting (CI + pre-commit), mirroring SwiftAgents.
  • Portable unit tests now run on Windows and Android; SwiftTextAttributedString is genuinely all-platform (AttributedString excluded on Windows for the swift-foundation BigString link gap — see swiftlang/swift#88132).

Cross-platform command-line tool

  • The swifttext CLI now builds and runs on macOS, Linux, and Windows (it was macOS-only before).
  • Cross-platform subcommands: docx, pages, numbers, keynote (iWork/DOCX readers), html (text/Markdown), and pdf / render (Markdown/HTML → PDF/DOCX/Pages).
  • Off macOS, pdf/render default to the pure-Swift SwiftTextRender engine (no WebKit); on macOS WebKit stays the default and --engine swift opts in. ocr/overlay (Vision) and the WebKit engine remain macOS-only.
  • Recognizes native absolute paths on every platform (POSIX /… and Windows C:\… / UNC).
  • On Linux/Windows the HTML/render paths need libxml2 (libxml2-dev on Linux, vcpkg on Windows).

Full changelog: 1.2.0...2.0.0