Render PDFs with odrcore, and hide the buttons a document cannot use - #159
Merged
Conversation
PDFs were the one format pushed off odrcore on purpose: `translate` refused them and `documentLoadingError` handed the file to WKWebView, which drew it with the system viewer. Nothing in the app reached inside that - no search, no fit to the screen, and the tool bar sat above a page it knew nothing about. odrcore has rendered PDFs itself since 6.2, so the guard is gone and a pdf goes down the same path as a document: `isPdfFile` joins the guard, and the branch that has no `Document` behind it - the one a csv already took - translates the decoded file. `.unknown` keeps the combined view, which for a pdf is every page. Images, media and fonts stay with the system. odrcore translates them too, but only into an `<img>` or a `<video>` the web view decodes anyway, and its own table says the page it writes for a psd or a wmf paints nothing. Search is not on yet: odrcore writes the `odr` object into what it renders as a document or as text, and `pdf_file.cpp` does not call `write_document_script`. So the button is now driven by the page rather than by the format - `didFinish` asks whether `odr.search` is there. A pdf picks the button up on its own the day odrcore writes the script for it, with no change here. `testPdfPageCarriesItsText` holds the other half of that: the text is in the page, so there will be something to walk. The button goes rather than greys out, like the pencil beside it. Both are filtered out of the bar together with the 10pt gap behind them, or what stays drifts off the trailing edge - hence the two new spacer outlets. `canEdit` and `canSearch` replace `showEditButton`, and `EXTENSION_WHITELIST` is now `systemRenderedExtensions`, which is what it always was: the other side of odrcore's format table, not something derived from it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNugiHVRHVc1CGHgVGW7Dz
odrcore reads the standard security handler, so an encrypted pdf takes the prompt the ODF formats already had - `isPasswordEncrypted` is true, and a missing or wrong password comes back as `wrongPassword`, which is what `Document.parse` turns into the alert rather than the error page. Verified against AES-256 (`V 5`, `R 6`), what a pdf written today is locked with. The fixture is qpdf's, because AES is not in the standard library and R6 derives its key with it. `make-fixtures.py` calls out to it and says so if it is missing; everything else it writes is still by hand. `copyFixture` takes a name now, since the fixtures are no longer all `test`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNugiHVRHVc1CGHgVGW7Dz
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNugiHVRHVc1CGHgVGW7Dz
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.
PDFs were the one format pushed off odrcore on purpose:
CoreWrapper.translaterefused them anddocumentLoadingErrorhanded the file to WKWebView, which drew it with the system viewer. Nothing in the app reached inside that — no search, no fit to the screen, and the tool bar sat above a page it knew nothing about. odrcore renders PDFs itself now, so the guard is gone and a pdf takes the same path as a document:isPdfFilejoins the guard, and the branch with noDocumentbehind it — the one a csv already took — translates the decoded file..unknownkeeps the combined view, which for a pdf is every page.Images, media and fonts stay with the system. odrcore translates those too, but only into an
<img>or a<video>the web view decodes anyway, and its own table says the page it writes for a psd or a wmf paints nothing.Search
Not on yet, and not this repository's to switch on. odrcore writes the
odrobject into what it renders as a document or as text;pdf_file.cppnever callswrite_document_script, so a pdf page has noodr.searchto call. The button is therefore driven by the page rather than by the format —didFinishasks whetherodr.searchis there. A pdf picks the button up on its own the day odrcore writes the script for it, with no change here.testPdfPageCarriesItsTextholds the other half: the text is already in the page, so there will be something to walk.The buttons
The search button now leaves the bar rather than greying out, like the pencil beside it. Both are filtered out together with the 10pt gap behind them, or what stays drifts off the trailing edge — hence the two new spacer outlets.
canEditandcanSearchreplaceshowEditButton, andEXTENSION_WHITELISTbecomessystemRenderedExtensions, which is what it always was: the other side of odrcore's format table rather than something derived from it.Tests
test.pdfis a two page fixture the generator writes by hand, a few hundred bytes like the ODF ones. Three tests on it — that odrcore translates it into the one combined page, that it is not editable, and that its text reaches the page — plus one asserting a png is still refused, so the line between odrcore and the system is written down.36 tests pass; both schemes build.
🤖 Generated with Claude Code