Skip to content

PDF generation on client and backend, and a pure-Java viewer - #6253

Open
shai-almog wants to merge 15 commits into
masterfrom
pdf-support
Open

shai-almog wants to merge 15 commits into
masterfrom
pdf-support

Conversation

@shai-almog

Copy link
Copy Markdown
Collaborator

Codename One can now write PDF files in an app or on a Codename One backend, and show them in an app, in pure Java on every port.

What's in it

  • com.codename1.pdf (shared with the backend, no UI dependency)
    • PdfDocument, PdfPage, PdfCanvas: paths, transforms, colors with alpha, dashes, clipping, text, JPEG/PNG/ARGB images, links, bookmarks, metadata.
    • Fonts: the standard 14, or TrueType/OpenType subsets with ToUnicode maps so text stays searchable.
    • Right-to-left text (Unicode bidi), Arabic joining and lam-alef from the font's GSUB.
    • PdfLayout: paragraphs with styled runs, tables that split across pages and repeat headers, images, rules, page decorators ("Page 3 of 7").
    • PdfReader: page count, sizes, metadata and text. Handles xref streams, object streams, incremental updates, broken xrefs, and RC4/AES-128/AES-256 encryption.
  • com.codename1.pdf.ui.PdfViewer: scrolling, pinch and double-tap zoom, renderPage for thumbnails. The renderer covers vector graphics, every blend mode, transparency groups, soft masks, all shading types, tiling patterns, TrueType/CFF/Type 1/Type 3 fonts, and JPEG, JPEG 2000, JBIG2 and CCITT images.
  • A developer guide chapter, PDF.asciidoc, and a PdfViewer screenshot test in hellocodenameone. Its baseline will come from this PR's CI run.

Untrusted input

A viewer opens files it did not make, so the parser and renderer went through four adversarial review rounds. Recursion, fan-out, decoded sizes and allocations are all bounded. Casts on parsed objects are instanceof-guarded. A bad page renders blank instead of crashing or hanging.

Testing

  • PdfDocumentTest and PdfInternalsTest in core-unittests (round trips, codec vectors, hostile-input regressions).
  • The backend SelfTest generates and reads back a PDF on the JavaSE and ParparVM runtimes.
  • Renders were compared against poppler output.

🤖 Generated with Claude Code

shai-almog and others added 5 commits November 16, 2026 11:53
com.codename1.pdf writes and reads PDF documents headlessly (shared with
the backend); com.codename1.pdf.ui.PdfViewer renders them with a
pure-Java renderer on every port.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd 1)

Bounded lexer nesting, seac recursion, decode sizes, xref and object
stream counts, ToUnicode ranges and calculator operands; a nesting guard
for patterns and soft masks; viewer memory caps; valid names and URIs;
cluster-safe word breaks; free xref entries; overlay state for page
decorators.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tile counts computed without int overflow; budgets for composite glyph
components, stitching-function trees, JPEG 2000 code-blocks and JBIG2
halftone work; caps on RunLength, concatenated contents, PNG and CCITT
sizes; JPEG frame size checked before the platform decoder; Indexed
hival and sampled-function parameters validated; a two-slot cache for
large decoded streams; balanced q/Q for left-open saves; header repeat
judged by the header rows' own height; shaped-width check on long-word
breaks; one retry after out of memory in the viewer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Structures past the nesting limit are skipped whole, stepping over
strings and comments, for dictionaries as well as arrays; sampled
function tables must fit their data; JBIG2 grid sizes bounded before
multiplying; DNL JPEGs accepted, with the decoded size checked. GSUB
features and lookups deduplicated and budgeted; fonts without glyphs
rejected; negative cmap glyphs ignored; the subset walk no longer drops
components; R2-R4 passwords as Latin-1 and R5/R6 UTF-8 with surrogate
pairs; lossless and arithmetic JPEG refused for embedding; pixel-array
size checked in long.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…round 4)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Developer Guide build artifacts are available for download from this workflow run:

Developer Guide quality checks:

  • AsciiDoc linter: No issues found (report)
  • Vale: No alerts found (report)
  • Paragraph capitalization: No paragraph capitalization issues (report)
  • LanguageTool: No grammar matches (report)
  • Image references: No unused images detected (report)

Every PDF example in the guide and the API reference now declares its
own inputs, so it compiles in the Playground as it stands. The viewer
screenshot test is registered under a PDF viewer feature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Cloudflare Preview

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ✅ ByteCodeTranslator: 0 findings (no issues)
    • ✅ android: 0 findings (no issues)
    • ✅ android-compat: 0 findings (no issues)
    • ✅ android-res-compiler: 0 findings (no issues)
    • ✅ backend: 0 findings (no issues)
    • ✅ backend-test: 0 findings (no issues)
    • ✅ build-engine: 0 findings (no issues)
    • ✅ build-hint-catalog: 0 findings (no issues)
    • ✅ build-hint-tools: 0 findings (no issues)
    • ✅ codenameone-gradle-plugin: 0 findings (no issues)
    • ✅ codenameone-maven-plugin: 0 findings (no issues)
    • ✅ compose-compat: 0 findings (no issues)
    • ✅ core-unittests: 0 findings (no issues)
    • ✅ desktop-compat-runtime: 0 findings (no issues)
    • ✅ fxml-compiler: 0 findings (no issues)
    • ✅ ios: 0 findings (no issues)
    • ✅ javac: 0 findings (no issues)
    • ✅ javafx-compat: 0 findings (no issues)
    • ✅ project-model: 0 findings (no issues)
    • ✅ python-runtime: 0 findings (no issues)
    • ✅ python-transpiler: 0 findings (no issues)
    • ✅ swing-compat: 0 findings (no issues)
  • ✅ PMD: 0 findings (no issues) [Report archive]
  • ✅ Checkstyle: 0 findings (no issues) [Report archive]

Generated automatically by the PR CI workflow.

shai-almog and others added 9 commits November 16, 2026 18:43
Claiming to scroll with nothing to scroll painted a scroll thumb across
the whole track, a dark strip down the right edge of a light page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/developer-guide/languagetool-accept.txt
A resource in the core jar ships in every application, whether or not
it reads a PDF. As a class it is stripped with the rest of the PDF code
where nothing references it, and reaches the backend build, which
copies shared classes and never resources. Packed 7 bits per char so
the constants stay one byte per char in the class file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- com.codename1.util.Bidi replaces the editor's BidiUtil and the PDF's
  PdfBidi: one UBA implementation for the editor, the PDF writer and the
  text extractor, shared with the backend.
- com.codename1.security.Aes (CBC, whole blocks) runs through a new
  CryptoEngine.aesCbc hook: the port's native cipher on the client, the
  server's on the backend, portable Java elsewhere (the JavaScript port).
- com.codename1.util.Jpeg2000 exposes the JPX decoder as a public API;
  the PDF renderer supplies its colour spaces through Jpeg2000.Colors.
- Tests: NIST CBC vectors on both paths, an R6 (AES-256) encrypted file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Bidi: surrogates, supplemental punctuation and the remaining fullwidth
  punctuation are neutral (CS for comma, full stop, colon), so emoji and
  CJK punctuation no longer split right-to-left runs.
- PdfSecurity: strip PKCS#5 padding only from a whole-block payload whose
  pad bytes all agree; one UTF-8 encoder for the package.
- Aes: a native result of the wrong length falls back to Java.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A PR adding a screenshot test failed check-workflows as well as golden-plan
until its capture landed; golden-plan alone reports gaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same bytes as ISO 32000-2's zero-IV unwrap; CodeQL flagged the constant
reaching the ports' shared cipher entry point.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant