Draw a framed rule body for fbox figures
A figure whose body is \rule now gets a small raster fbox approximation: black frame, white gap and filled body, centred in the float. Image height is already part of the float height, so the caption follows instead of overlapping. The arXiv figure is now a centred framed square; it is still on page 2 while TeX puts it on page 3. Test count stays 1074.
This commit is contained in:
1 parent
192788ec4b
commit
13d0dd2fb7
1 file changed
+60
-1
+60
-1
@@ -7913,6 +7913,8 @@ struct FloatSpec {
|
||||
caption_starred: bool,
|
||||
/// `\includegraphics` path for a figure.
|
||||
image: Option<String>,
|
||||
/// The body is a `\rule`, drawn as a framed filled box.
|
||||
rule_body: bool,
|
||||
/// Index into `PageGeometry::tabular` for a captured table body.
|
||||
table: Option<usize>,
|
||||
}
|
||||
@@ -8360,7 +8362,8 @@ fn float_block(raw: &str) -> Option<SourceParagraph> {
|
||||
}
|
||||
let (mut width, mut height, image, scale, keep_aspectratio) =
|
||||
figure_graphic(inner).unwrap_or((None, None, None, None, false));
|
||||
if let Some((rule_width, rule_height)) = figure_rule(inner) {
|
||||
let rule_body = figure_rule(inner);
|
||||
if let Some((rule_width, rule_height)) = rule_body {
|
||||
width = width.or(Some(rule_width));
|
||||
height = height.or(Some(rule_height));
|
||||
}
|
||||
@@ -8405,6 +8408,7 @@ fn float_block(raw: &str) -> Option<SourceParagraph> {
|
||||
list_caption: None,
|
||||
caption_starred,
|
||||
image,
|
||||
rule_body: rule_body.is_some(),
|
||||
table,
|
||||
}),
|
||||
})
|
||||
@@ -8516,6 +8520,40 @@ fn figure_graphic(
|
||||
))
|
||||
}
|
||||
|
||||
/// A small raster `\fbox{\rule...}` body: black frame, white gap, filled box.
|
||||
fn fbox_rule_image(rule_width: i64, rule_height: i64) -> RasterImage {
|
||||
let width = (rule_width / SCALE).max(1) as usize + 12;
|
||||
let height = (rule_height / SCALE).max(1) as usize + 12;
|
||||
let mut rgb = vec![255u8; width * height * 3];
|
||||
let inset = 6usize;
|
||||
let border = 2usize;
|
||||
let box_width = width.saturating_sub(inset * 2);
|
||||
let box_height = height.saturating_sub(inset * 2);
|
||||
for y in inset..(inset + box_height).min(height) {
|
||||
for x in inset..(inset + box_width).min(width) {
|
||||
let edge = x < inset + border
|
||||
|| x >= inset + box_width - border
|
||||
|| y < inset + border
|
||||
|| y >= inset + box_height - border;
|
||||
let gap = x < inset + border + 2
|
||||
|| x >= inset + box_width - border - 2
|
||||
|| y < inset + border + 2
|
||||
|| y >= inset + box_height - border - 2;
|
||||
if edge || !gap {
|
||||
let index = (y * width + x) * 3;
|
||||
rgb[index] = 0;
|
||||
rgb[index + 1] = 0;
|
||||
rgb[index + 2] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
RasterImage {
|
||||
width: width as u32,
|
||||
height: height as u32,
|
||||
rgb,
|
||||
}
|
||||
}
|
||||
|
||||
/// A figure whose body is a `\rule` rather than an image (the arXiv sample
|
||||
/// uses `\fbox{\rule...}`). Return the first non-zero rule dimensions.
|
||||
fn figure_rule(inner: &str) -> Option<(ImageLength, ImageLength)> {
|
||||
@@ -9301,6 +9339,7 @@ fn standalone_graphic(raw: &str) -> Option<SourceParagraph> {
|
||||
list_caption: None,
|
||||
caption_starred: false,
|
||||
image,
|
||||
rule_body: false,
|
||||
table: None,
|
||||
}),
|
||||
})
|
||||
@@ -9343,6 +9382,7 @@ fn rule_block(raw: &str) -> Option<SourceParagraph> {
|
||||
list_caption: None,
|
||||
caption_starred: false,
|
||||
image: None,
|
||||
rule_body: false,
|
||||
table: None,
|
||||
});
|
||||
block.space_before = 6 * SCALE;
|
||||
@@ -9377,6 +9417,7 @@ fn rule_block(raw: &str) -> Option<SourceParagraph> {
|
||||
list_caption: None,
|
||||
caption_starred: false,
|
||||
image: None,
|
||||
rule_body: false,
|
||||
table: None,
|
||||
});
|
||||
block.space_before = 6 * SCALE;
|
||||
@@ -13752,6 +13793,24 @@ fn build_document_with_labels(
|
||||
placed_image = true;
|
||||
}
|
||||
}
|
||||
if !placed_image
|
||||
&& spec.rule_body
|
||||
&& let (Some(rule_width), Some(rule_height)) = (
|
||||
spec.width.as_ref().map(resolve),
|
||||
spec.height.as_ref().map(resolve),
|
||||
)
|
||||
{
|
||||
let image = fbox_rule_image(rule_width, rule_height);
|
||||
let image_width = image.width as i64 * SCALE;
|
||||
let image_height = image.height as i64 * SCALE;
|
||||
content.push(VerticalItem::Image {
|
||||
x: ((width - image_width) / 2).max(0),
|
||||
width: image_width,
|
||||
height: image_height,
|
||||
image,
|
||||
});
|
||||
placed_image = true;
|
||||
}
|
||||
if !placed_image && (spec.height.is_some() || spec.width.is_some()) {
|
||||
let rule_width = spec.width.as_ref().map(resolve).unwrap_or(width);
|
||||
let rule_height = spec.height.as_ref().map(resolve).unwrap_or(rule_width / 2);
|
||||
|
||||
Reference in new issue
Block a user