Repository navigation
feat(ffi): add rofd_document_get_page_size_mm #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,43 @@ pub unsafe extern "C" fn rofd_document_get_page_count( | |
| } | ||
| } | ||
|
|
||
| /// Copies the physical page box of a zero-based index as millimetres. | ||
| /// | ||
| /// This metadata-only query reads the page area without parsing or caching page | ||
| /// content: it performs no content validation, collects no content warnings, and | ||
| /// also succeeds for a page whose content cannot be loaded. The value matches | ||
| /// [`rofd_page_get_size_mm`] for the same index. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// A non-null `document` must be a live document handle returned by this library. | ||
| /// Its storage must remain valid, must not be concurrently freed or modified, and | ||
| /// must not overlap the writable, aligned `page_size_mm` or `error` output slots. | ||
| /// Non-null output slots must also be mutually disjoint and valid for the call. | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn rofd_document_get_page_size_mm( | ||
| document: *const rofd_document_t, | ||
| page_index: usize, | ||
| page_size_mm: *mut rofd_rect_t, | ||
| error: *mut *mut rofd_error_t, | ||
| ) -> rofd_status_t { | ||
| // SAFETY: The shared boundary validates and transactionally writes the caller output slots. | ||
| unsafe { | ||
| boundary(error, ScalarOutput::required(page_size_mm), || { | ||
| let size = document_ref(document)? | ||
| .inner | ||
| .page_size(page_index) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Malformed page sizes disagree When a page's physical box has a nonpositive width or height, Make both page-size APIs apply the same validity rules, or document and test the malformed-page exception to the parity guarantee. Prompt for AI agentsIn `crates/rofd-ffi/src/document.rs` at line 160:
**Malformed page sizes disagree**
When a page's physical box has a nonpositive width or height, `Document::page_size` rejects nonpositive dimensions, while `Document::page` stores the parsed rectangle and `Page::size` returns it unchanged; this call therefore returns `ROFD_STATUS_INVALID_DOCUMENT` where `rofd_page_get_size_mm` returns a rectangle, breaking the documented parity.
Make both page-size APIs apply the same validity rules, or document and test the malformed-page exception to the parity guarantee. |
||
| .map_err(FfiError::from)?; | ||
| Ok(rofd_rect_t { | ||
| x_mm: size.x, | ||
| y_mm: size.y, | ||
| width_mm: size.width, | ||
| height_mm: size.height, | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /// Returns an independently owned page handle for a zero-based index. | ||
| /// | ||
| /// The returned page retains its document data and remains valid after the | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Page sizes fail on unreadable content
When the page has a readable physical box but its XML is malformed, malformed within its content subtree, or exceeds the configured XML depth limit,
Document::page_sizeparses or deserializes the page XML before extracting its area, so malformed content or a depth-limit violation returns an invalid-document error instead of the documented content-independent size result.Read the page's physical box without parsing or deserializing its XML.
Also at
crates/rofd-ffi/README.md:94-99,crates/rofd-ffi/include/rofd.h:343-349,crates/rofd-ffi/src/document.rs:137-140.Prompt for AI agents