mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-28 17:30:24 +01:00
#816: pdf: a later image budget never raises a lower one
set_image_budget says it lowers the budget, but a second call with more bytes raised it again (4 then 8 gave the next page 8 bytes). It now keeps the smaller of the two. Found by CodeRabbit.
This commit is contained in:
1 parent
9e1abd22a2
commit
5f9b38946b
2 files changed
+7
-2
No files matched your search
@@ -1099,9 +1099,10 @@ impl PdfDoc {
|
||||
}
|
||||
|
||||
/// Lowers the bytes of image data the whole document keeps (never above
|
||||
/// [`MAX_DOC_IMAGE_BYTES`]); images drawn past it are left out.
|
||||
/// [`MAX_DOC_IMAGE_BYTES`], nor above a budget set before); images drawn past it are left out.
|
||||
pub fn set_image_budget(&mut self, bytes: u64) {
|
||||
self.image_budget = Some(bytes.min(MAX_DOC_IMAGE_BYTES));
|
||||
let cap = self.image_budget.unwrap_or(MAX_DOC_IMAGE_BYTES);
|
||||
self.image_budget = Some(bytes.min(cap));
|
||||
}
|
||||
|
||||
/// Image bytes the document may still keep: its budget minus what every closed page holds
|
||||
|
||||
@@ -934,6 +934,10 @@ fn image_bytes_are_bounded_across_pages() -> Result<(), Box<dyn Error>> {
|
||||
assert_eq!(d.add_page(100.0, 100.0).image_room(), MAX_DOC_IMAGE_BYTES);
|
||||
d.set_image_budget(u64::MAX);
|
||||
assert_eq!(d.add_page(100.0, 100.0).image_room(), MAX_DOC_IMAGE_BYTES, "the budget is never raised");
|
||||
let mut d = PdfDoc::new();
|
||||
d.set_image_budget(4);
|
||||
d.set_image_budget(8);
|
||||
assert_eq!(d.add_page(100.0, 100.0).image_room(), 4, "a later, higher budget doesn't raise a lower one");
|
||||
|
||||
let mut d = PdfDoc::new();
|
||||
d.set_image_budget(10_000);
|
||||
|
||||
Reference in new issue
Block a user