feat: bind the html viewport config for java and python - #640
Conversation
`HtmlConfig::viewport_mode`, `spreadsheet_viewport_mode` and `viewport_content` shipped without bindings, so the mobile initial zoom was whatever `automatic` resolved to - not reachable from OpenDocument.droid, which is the consumer the option exists for. Java gets `HtmlViewportMode` (ordinals matching the C++ enum, `null` for the absent optional, as everywhere else in the marshalling) plus the three `HtmlConfig` fields; python gets the enum and three `def_readwrite`s. The C++ suite already covers the mode matrix, so the new tests only prove the config crosses the binding: a round trip through `HtmlService.config()`, and the meta tag an odt renders with. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qis7KBzd1YHZqPa9ZEd6WV
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Pull request overview
This PR exposes the existing C++ HTML viewport configuration (HtmlViewportMode and HtmlConfig’s viewport fields) through the Java (JNI) and Python bindings, enabling mobile clients (notably OpenDocument.droid) to control the generated <meta name="viewport"> behavior instead of being locked to the default automatic resolution.
Changes:
- Added
HtmlViewportModeenum bindings for both Python (pyodr.HtmlViewportMode) and Java (app.opendocument.core.HtmlViewportMode). - Bound
HtmlConfig.viewportMode,HtmlConfig.spreadsheetViewportMode(nullable), andHtmlConfig.viewportContentacross JNI and pybind11. - Added Java and Python tests to validate that viewport config round-trips through bindings and affects rendered HTML output.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/tests/test_html.py | Adds Python-level regression tests for viewport defaults and emitted viewport meta tag. |
| python/src/bind_html.cpp | Exposes HtmlViewportMode and HtmlConfig viewport fields via pybind11. |
| jni/tests/app/opendocument/core/HtmlTest.java | Adds JNI tests for viewport defaults, round-trip config, and emitted viewport meta tag. |
| jni/src/jni_style.cpp | Marshals viewport-related fields between odr::HtmlConfig and Java HtmlConfig. |
| jni/java/app/opendocument/core/HtmlViewportMode.java | Introduces Java enum mirroring odr::HtmlViewportMode ordinal mapping. |
| jni/java/app/opendocument/core/HtmlConfig.java | Adds Java-facing viewport configuration fields (mode, spreadsheet override, raw content). |
| jni/CMakeLists.txt | Includes the new HtmlViewportMode.java in the Java build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
🤖 Generated with Claude Code
HtmlConfig::viewport_mode,spreadsheet_viewport_modeandviewport_contenthad no bindings, so the mobile initial zoom was stuck on whateverautomaticresolved to — unreachable from OpenDocument.droid, which is the consumer the option exists for.Java
HtmlViewportMode(AUTOMATIC,FIT_WIDTH,ACTUAL_SIZE,NONE), constant order matching the C++ enumHtmlConfig.viewportMode/.spreadsheetViewportMode/.viewportContent, marshalled both ways injni_style.cpp. The two optionals follow the existing convention:null↔std::nullopt, via the-1enum ordinal for the mode andmake_string_opt/get_string_optfor the raw content.Python
pyodr.HtmlViewportModeplus the threedef_readwrites;pybind11/stl.his already included, so the optionals cross asNone.Tests
test/src/internal/html/common_test.cppalready covers the mode matrix, so the new tests only prove the config crosses the bindings: a round trip throughHtmlService.config()and the<meta name="viewport">an odt actually renders with, in both suites.Verified locally:
odr_jni_junit(7/7 inHtmlTest, none skipped) andpytest python/tests/test_html.py(8 passed).