Centre raster images inside floats
Add an x offset to VerticalItem::Image and use it when placing a decoded image in a float, so a 0.4\textwidth plot is centred while its caption remains centred across the float. Other image uses keep x=0. Test count stays 1074.
This commit is contained in:
1 parent
bbedf7676c
commit
aa2f3cb0af
4 files changed
+12
-4
No files matched your search
@@ -207,6 +207,9 @@ pub enum VerticalItem {
|
||||
},
|
||||
/// A raster image painted into the vertical list.
|
||||
Image {
|
||||
/// Horizontal offset inside the float/list.
|
||||
#[serde(default)]
|
||||
x: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
image: crate::render::RasterImage,
|
||||
@@ -7924,6 +7927,7 @@ mod tests {
|
||||
100,
|
||||
5,
|
||||
vec![VerticalItem::Image {
|
||||
x: 0,
|
||||
width: 100,
|
||||
height: 30,
|
||||
image,
|
||||
@@ -9679,6 +9683,7 @@ b & 2 \\
|
||||
vec![Unit::vertical(
|
||||
1,
|
||||
vec![VerticalItem::Image {
|
||||
x: 0,
|
||||
width: 50,
|
||||
height: 40,
|
||||
image,
|
||||
|
||||
@@ -617,6 +617,7 @@ impl Page {
|
||||
y += box_.height;
|
||||
}
|
||||
VerticalItem::Image {
|
||||
x: image_x,
|
||||
width,
|
||||
height,
|
||||
image,
|
||||
@@ -627,7 +628,7 @@ impl Page {
|
||||
rgb: image.rgb.clone(),
|
||||
});
|
||||
list.push(DisplayItem::Image {
|
||||
x: 0,
|
||||
x: *image_x,
|
||||
y,
|
||||
width: *width,
|
||||
height: *height,
|
||||
|
||||
@@ -48,9 +48,9 @@ execution is not a goal.
|
||||
parenthetical citations; inline `thebibliography` without labels remains
|
||||
numeric, and the full natbib option surface is not implemented;
|
||||
- display math is approximate;
|
||||
- PNG/JPEG/BMP floats now reserve their image height and embed the raster
|
||||
with its real pixel dimensions; the fbox frame and vector/PDF images are
|
||||
still missing, and float placement differs.
|
||||
- PNG/JPEG/BMP floats now reserve their image height, embed the raster with
|
||||
its real pixel dimensions, and centre the image within the float; the fbox
|
||||
frame and vector/PDF images are still missing, and float placement differs.
|
||||
- Incremental foundation exists:
|
||||
- `Engine::edit` + page hashes;
|
||||
- project-scoped sessions and changed-page reporting;
|
||||
|
||||
@@ -13744,6 +13744,7 @@ fn build_document_with_labels(
|
||||
image_height = (natural_height as f64 * scale).round() as i64;
|
||||
}
|
||||
content.push(VerticalItem::Image {
|
||||
x: ((width - image_width) / 2).max(0),
|
||||
width: image_width.max(1),
|
||||
height: image_height.max(1),
|
||||
image: image.clone(),
|
||||
@@ -15482,6 +15483,7 @@ mod source_tests {
|
||||
width,
|
||||
height,
|
||||
image,
|
||||
..
|
||||
} => Some((*width, *height, image.clone())),
|
||||
_ => None,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user