diff --git a/src/route_d.rs b/src/route_d.rs index 0956f49..e2f69f1 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -7913,6 +7913,8 @@ struct FloatSpec { caption_starred: bool, /// `\includegraphics` path for a figure. image: Option, + /// 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, } @@ -8360,7 +8362,8 @@ fn float_block(raw: &str) -> Option { } 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 { 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 { list_caption: None, caption_starred: false, image, + rule_body: false, table: None, }), }) @@ -9343,6 +9382,7 @@ fn rule_block(raw: &str) -> Option { 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 { 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);