feat(file): hand out the thumbnail the package already carries - #808
Merged
Conversation
andiwand
force-pushed
the
feat/document-thumbnail
branch
2 times, most recently
from
September 2, 2026 18:55
61a9cf3 to
913008d
Compare
`DocumentFile::thumbnail()` returns the preview the producing application stored: ODF's `Thumbnails/thumbnail.png`, and for OOXML the part the package relationship names — `.jpeg`, `.png`, `.emf` and `.wmf` all occur, so the relationship is read rather than a filename guessed. Nothing is rendered; a package that carries none says so, and an encrypted one carries none until it is decrypted. `parse_relationship_target` learned the package root, which is not a part and so has no parent to hang `_rels` off; `/_rels/.rels` is where its relationships live and its targets resolve against the root. Mirrored in the JNI, Apple and Python bindings, each with a test — the shared `mixed-layout.odt` fixture is real LibreOffice output and carries one. Closes #21. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018cMYRXLJdiCkH65Jm2W9B5
andiwand
force-pushed
the
feat/document-thumbnail
branch
from
September 2, 2026 18:56
913008d to
3188bdc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Generated with Claude Code
Closes #21 — which asked whether we would have to render documents ourselves, and the answer in the comment thread was "there is a thumbnail.png inside which would be easy to use". It is: the archive we already open has it.
Thumbnails/thumbnail.png..jpeg,.png,.emfand.wmfall occur — so the relationship is read rather than a filename guessed.Nothing is rendered to produce it, so it is as current as the last save by an application that writes one, and a great many files carry none — which is a
nullopt, not an error. An encrypted package carries none until it is decrypted.Along the way
parse_relationship_targetdid not handle the package root:/is not a part, soAbsPath("/").parent()throws "absolute path violation"./_rels/.relsis where the package's own relationships live and its targets resolve against the root, so the two helpers now say so.Bindings
Mirrored in JNI (
DocumentFile.thumbnail(),nullfor absent), Apple (DocumentFile.thumbnail, a nullableODRFile *following theODRImage.filepattern) and Python (DocumentFile.thumbnail(),Nonefor absent). Not in wasm, whose file surface is session-based and exposes noodr::Fileat all — a separate question.Verification
./odr_test --gtest_filter='-all_test_files/*'— 1117 tests, all pass, including three new ones. The OOXML one builds a package inline with the thumbnail at the deliberately unconventionaldocProps/preview.emf, so it proves the relationship is what is read.ctest --test-dir build/jni— 44 tests,thumbnail()among them.ctest --test-dir build/python—test_document_file_thumbnailpasses; it asserts both the absent case (the minimal odt the fixture builds) and the present one.ODR_XCFRAMEWORK=OdrCoreObjC.xcframework swift test— 22 tests,ThumbnailTestsamong them.The shared
mixed-layout.odtfixture is real LibreOffice output and carries a 428-byteThumbnails/thumbnail.png, so all three binding suites test against it without a new fixture.