Embed table-cell images at their grid rectangles
This commit is contained in:
1 parent
d50b4bf560
commit
87a81f16cd
7 files changed
+57
-7
No files matched your search
@@ -433,6 +433,7 @@ pub struct RuleBox {
|
|||||||
pub height: common::Scaled,
|
pub height: common::Scaled,
|
||||||
/// Optional fill colour; means the regular black rule.
|
/// Optional fill colour; means the regular black rule.
|
||||||
pub color: Option<[u8; 3]>,
|
pub color: Option<[u8; 3]>,
|
||||||
|
pub image: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paragraph-level alignment requested by `\raggedright` or `\raggedleft`.
|
/// Paragraph-level alignment requested by `\raggedright` or `\raggedleft`.
|
||||||
|
|||||||
@@ -1719,6 +1719,7 @@ impl Parser {
|
|||||||
raise,
|
raise,
|
||||||
height,
|
height,
|
||||||
color: None,
|
color: None,
|
||||||
|
image: None,
|
||||||
}),
|
}),
|
||||||
box_run: None,
|
box_run: None,
|
||||||
unresolved_reference: None,
|
unresolved_reference: None,
|
||||||
@@ -2312,8 +2313,8 @@ impl Parser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(table) = &mut self.table {
|
if let Some(table) = &mut self.table {
|
||||||
// Table-cell images are represented as grey boxes until the cell
|
// Table-cell images reuse the rule box so table layout can keep the
|
||||||
// image renderer lands. This still preserves the reference grid.
|
// reference grid; the PDF renderer embeds the source image at this rect.
|
||||||
let width = (0.138_f64 * 160.0 * 72.27 / 25.4 * 65536.0).round() as i32;
|
let width = (0.138_f64 * 160.0 * 72.27 / 25.4 * 65536.0).round() as i32;
|
||||||
let height = (width as f64 * 1.35).round() as i32;
|
let height = (width as f64 * 1.35).round() as i32;
|
||||||
let mut run = Run::plain(String::new());
|
let mut run = Run::plain(String::new());
|
||||||
@@ -2322,6 +2323,7 @@ impl Parser {
|
|||||||
raise: common::Scaled(0),
|
raise: common::Scaled(0),
|
||||||
height: common::Scaled(height),
|
height: common::Scaled(height),
|
||||||
color: Some([170, 170, 170]),
|
color: Some([170, 170, 170]),
|
||||||
|
image: Some(path.clone()),
|
||||||
});
|
});
|
||||||
table.cell.push(run);
|
table.cell.push(run);
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-1
@@ -150,7 +150,7 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
|||||||
since printpdf 0.3.4 has no annotation API.
|
since printpdf 0.3.4 has no annotation API.
|
||||||
|
|
||||||
- Fonts: bundled reserved-glyph subsets in `assets/fonts-subset/` are used when the document charset is covered; arXiv PDF is about 0.29 MB.
|
- Fonts: bundled reserved-glyph subsets in `assets/fonts-subset/` are used when the document charset is covered; arXiv PDF is about 0.29 MB.
|
||||||
- New-template compatibility: the SIVP class file loads fully and `sn-article.tex` previews and exports a 14-page PDF; PDF figures render as placeholders and table-cell images are emitted as placeholder blocks that preserve the reference grid geometry instead of becoming page-sized strips. Its journal title block captures title, author/affiliation, corresponding-author stars, both e-mails, abstract, and keywords; class declaration option leakage is consumed. The Huawei E fragment compiles to 16 A4 pages. Generic support added for TeX `\if`/`\ifx`, `\newcount`, `\newdimen`, `\char`, `tabular*`/`tabularx`, math accents/operators/arrows, a 64-bit dimension scanner, and `geometry` `text={width,height}` blocks. Both fixtures are regression tests (`sivp_project_previews_and_exports_a_pdf`, `e_fixture_compiles`).
|
- New-template compatibility: the SIVP class file loads fully and `sn-article.tex` previews and exports a 14-page PDF; PDF figures render as placeholders and table-cell images are embedded at fixed grid rectangles instead of becoming page-sized strips. Its journal title block captures title, author/affiliation, corresponding-author stars, both e-mails, abstract, and keywords; class declaration option leakage is consumed. The Huawei E fragment compiles to 16 A4 pages. Generic support added for TeX `\if`/`\ifx`, `\newcount`, `\newdimen`, `\char`, `tabular*`/`tabularx`, math accents/operators/arrows, a 64-bit dimension scanner, and `geometry` `text={width,height}` blocks. Both fixtures are regression tests (`sivp_project_previews_and_exports_a_pdf`, `e_fixture_compiles`).
|
||||||
|
|
||||||
- Lines whose justification ratio exceeds 3 fall back to natural spacing instead of stretching inter-word gaps across the measure.
|
- Lines whose justification ratio exceeds 3 fall back to natural spacing instead of stretching inter-word gaps across the measure.
|
||||||
|
|
||||||
|
|||||||
@@ -1785,6 +1785,7 @@ fn boxworks_line_break(
|
|||||||
raise: rule.raise,
|
raise: rule.raise,
|
||||||
height: rule.height,
|
height: rule.height,
|
||||||
y_offset,
|
y_offset,
|
||||||
|
image: rule.image.clone(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let (bold, italic, monospace, sans, glyph_size) = style_by_font
|
let (bold, italic, monospace, sans, glyph_size) = style_by_font
|
||||||
|
|||||||
@@ -533,6 +533,7 @@ fn append_list_layout_tokens(
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn layout_table(
|
fn layout_table(
|
||||||
|
source_dir: &Path,
|
||||||
rows: &[Vec<Vec<Run>>],
|
rows: &[Vec<Vec<Run>>],
|
||||||
alignments: &[ColumnAlignment],
|
alignments: &[ColumnAlignment],
|
||||||
rules: &[TableRule],
|
rules: &[TableRule],
|
||||||
@@ -548,6 +549,18 @@ fn layout_table(
|
|||||||
cache: &mut ParagraphLayoutCache,
|
cache: &mut ParagraphLayoutCache,
|
||||||
font_size: u8,
|
font_size: u8,
|
||||||
) -> Option<PositionedTable> {
|
) -> Option<PositionedTable> {
|
||||||
|
let mut rows = rows.to_vec();
|
||||||
|
for row in &mut rows {
|
||||||
|
for cell in row {
|
||||||
|
for run in cell {
|
||||||
|
if let Some(rule) = run.rule.as_mut()
|
||||||
|
&& let Some(image) = rule.image.as_mut()
|
||||||
|
{
|
||||||
|
*image = source_dir.join(&*image).to_string_lossy().into_owned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
let row_column_count = |row: &Vec<Vec<Run>>, styles: Option<&Vec<TableCellStyle>>| {
|
let row_column_count = |row: &Vec<Vec<Run>>, styles: Option<&Vec<TableCellStyle>>| {
|
||||||
let mut columns = 0;
|
let mut columns = 0;
|
||||||
for index in 0..row.len() {
|
for index in 0..row.len() {
|
||||||
@@ -1007,6 +1020,7 @@ fn layout_framed_runs(
|
|||||||
raise: rule.raise,
|
raise: rule.raise,
|
||||||
height: rule.height,
|
height: rule.height,
|
||||||
y_offset: run.y_offset.unwrap_or_default(),
|
y_offset: run.y_offset.unwrap_or_default(),
|
||||||
|
image: rule.image.clone(),
|
||||||
});
|
});
|
||||||
width += Mm::from(scaled_units_to_mm(i64::from(rule.width.0)));
|
width += Mm::from(scaled_units_to_mm(i64::from(rule.width.0)));
|
||||||
let above = i64::from(rule.raise.0) + i64::from(rule.height.0);
|
let above = i64::from(rule.raise.0) + i64::from(rule.height.0);
|
||||||
@@ -1515,6 +1529,7 @@ fn append_page_footnotes(
|
|||||||
raise: common::Scaled::ZERO,
|
raise: common::Scaled::ZERO,
|
||||||
height: common::Scaled(separator as i32),
|
height: common::Scaled(separator as i32),
|
||||||
y_offset: common::Scaled::ZERO,
|
y_offset: common::Scaled::ZERO,
|
||||||
|
image: None,
|
||||||
}],
|
}],
|
||||||
pre_display_size: None,
|
pre_display_size: None,
|
||||||
};
|
};
|
||||||
@@ -1679,6 +1694,7 @@ fn push_title_rule(
|
|||||||
raise: common::Scaled::ZERO,
|
raise: common::Scaled::ZERO,
|
||||||
height: common::Scaled(height as i32),
|
height: common::Scaled(height as i32),
|
||||||
y_offset: common::Scaled::ZERO,
|
y_offset: common::Scaled::ZERO,
|
||||||
|
image: None,
|
||||||
}],
|
}],
|
||||||
pre_display_size: None,
|
pre_display_size: None,
|
||||||
};
|
};
|
||||||
@@ -2659,6 +2675,7 @@ pub(super) fn build_positioned_pages(
|
|||||||
raise: common::Scaled::ZERO,
|
raise: common::Scaled::ZERO,
|
||||||
height: *height,
|
height: *height,
|
||||||
y_offset: common::Scaled::ZERO,
|
y_offset: common::Scaled::ZERO,
|
||||||
|
image: None,
|
||||||
}],
|
}],
|
||||||
pre_display_size: None,
|
pre_display_size: None,
|
||||||
};
|
};
|
||||||
@@ -2891,6 +2908,7 @@ pub(super) fn build_positioned_pages(
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
let table = layout_table(
|
let table = layout_table(
|
||||||
|
source_dir,
|
||||||
rows,
|
rows,
|
||||||
alignments,
|
alignments,
|
||||||
rules,
|
rules,
|
||||||
@@ -3731,6 +3749,7 @@ fn append_header_rule(page: &mut PositionedPage, page_number: usize, y: i64, wid
|
|||||||
raise: common::Scaled::ZERO,
|
raise: common::Scaled::ZERO,
|
||||||
height: common::Scaled(rule_height as i32),
|
height: common::Scaled(rule_height as i32),
|
||||||
y_offset: common::Scaled::ZERO,
|
y_offset: common::Scaled::ZERO,
|
||||||
|
image: None,
|
||||||
}],
|
}],
|
||||||
pre_display_size: None,
|
pre_display_size: None,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ pub(super) enum LineItem {
|
|||||||
raise: Scaled,
|
raise: Scaled,
|
||||||
height: Scaled,
|
height: Scaled,
|
||||||
y_offset: Scaled,
|
y_offset: Scaled,
|
||||||
|
image: Option<String>,
|
||||||
},
|
},
|
||||||
Frame {
|
Frame {
|
||||||
width: Scaled,
|
width: Scaled,
|
||||||
@@ -99,6 +100,7 @@ enum TextLineItem {
|
|||||||
raise: Mm,
|
raise: Mm,
|
||||||
height: Mm,
|
height: Mm,
|
||||||
y_offset: Mm,
|
y_offset: Mm,
|
||||||
|
image: Option<String>,
|
||||||
},
|
},
|
||||||
Frame {
|
Frame {
|
||||||
width: Mm,
|
width: Mm,
|
||||||
@@ -118,6 +120,7 @@ pub(super) struct PositionedRule {
|
|||||||
pub(super) raise: Mm,
|
pub(super) raise: Mm,
|
||||||
pub(super) height: Mm,
|
pub(super) height: Mm,
|
||||||
pub(super) y_offset: Mm,
|
pub(super) y_offset: Mm,
|
||||||
|
pub(super) image: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextLine {
|
impl TextLine {
|
||||||
@@ -233,6 +236,7 @@ impl TextLine {
|
|||||||
raise,
|
raise,
|
||||||
height,
|
height,
|
||||||
y_offset,
|
y_offset,
|
||||||
|
image,
|
||||||
} => {
|
} => {
|
||||||
flush_text(
|
flush_text(
|
||||||
&mut items,
|
&mut items,
|
||||||
@@ -248,6 +252,7 @@ impl TextLine {
|
|||||||
raise: scaled_to_mm(*raise),
|
raise: scaled_to_mm(*raise),
|
||||||
height: scaled_to_mm(*height),
|
height: scaled_to_mm(*height),
|
||||||
y_offset: scaled_to_mm(*y_offset),
|
y_offset: scaled_to_mm(*y_offset),
|
||||||
|
image: image.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
LineItem::Glue(width) => {
|
LineItem::Glue(width) => {
|
||||||
@@ -388,6 +393,7 @@ impl TextLine {
|
|||||||
raise,
|
raise,
|
||||||
height,
|
height,
|
||||||
y_offset,
|
y_offset,
|
||||||
|
image,
|
||||||
} => {
|
} => {
|
||||||
if *height > Mm::from(0.0) {
|
if *height > Mm::from(0.0) {
|
||||||
ascent = ascent.max(*raise + *height + *y_offset);
|
ascent = ascent.max(*raise + *height + *y_offset);
|
||||||
@@ -398,6 +404,7 @@ impl TextLine {
|
|||||||
raise: *raise,
|
raise: *raise,
|
||||||
height: *height,
|
height: *height,
|
||||||
y_offset: *y_offset,
|
y_offset: *y_offset,
|
||||||
|
image: image.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -493,13 +500,19 @@ impl TextLine {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
for rule in &layout.rules {
|
for rule in &layout.rules {
|
||||||
|
let fill = if rule.image.is_some() {
|
||||||
|
"#aaaaaa"
|
||||||
|
} else {
|
||||||
|
"#000000"
|
||||||
|
};
|
||||||
let _ = write!(
|
let _ = write!(
|
||||||
output,
|
output,
|
||||||
"<rect x=\"{:.4}\" y=\"{:.4}\" width=\"{:.4}\" height=\"{:.4}\" fill=\"#000000\"/>",
|
"<rect x=\"{:.4}\" y=\"{:.4}\" width=\"{:.4}\" height=\"{:.4}\" fill=\"{}\"/>",
|
||||||
f64::from(x + horizontal_offset + rule.x),
|
f64::from(x + horizontal_offset + rule.x),
|
||||||
f64::from(baseline - rule.y_offset - rule.raise - rule.height),
|
f64::from(baseline - rule.y_offset - rule.raise - rule.height),
|
||||||
f64::from(rule.width),
|
f64::from(rule.width),
|
||||||
f64::from(rule.height),
|
f64::from(rule.height),
|
||||||
|
fill,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for span in &layout.spans {
|
for span in &layout.spans {
|
||||||
@@ -639,15 +652,25 @@ impl Element for TextLine {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
for rule in &layout.rules {
|
for rule in &layout.rules {
|
||||||
area.fill_rect(
|
let position = Position::new(
|
||||||
Position::new(
|
|
||||||
rule.x + horizontal_offset,
|
rule.x + horizontal_offset,
|
||||||
layout.ascent - rule.y_offset - rule.raise - rule.height,
|
layout.ascent - rule.y_offset - rule.raise - rule.height,
|
||||||
),
|
);
|
||||||
|
if let Some(path) = &rule.image {
|
||||||
|
let mut image = genpdf::elements::Image::from_path(path)?;
|
||||||
|
let mut image_area = area.clone();
|
||||||
|
image_area.add_offset(position);
|
||||||
|
image_area.set_width(rule.width);
|
||||||
|
image_area.set_height(rule.height);
|
||||||
|
image.render(context, image_area, inherited_style)?;
|
||||||
|
} else {
|
||||||
|
area.fill_rect(
|
||||||
|
position,
|
||||||
Size::new(rule.width, rule.height),
|
Size::new(rule.width, rule.height),
|
||||||
Style::new().with_color(genpdf::style::Color::Rgb(0, 0, 0)),
|
Style::new().with_color(genpdf::style::Color::Rgb(0, 0, 0)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut placements = Vec::with_capacity(layout.spans.len());
|
let mut placements = Vec::with_capacity(layout.spans.len());
|
||||||
for span in &layout.spans {
|
for span in &layout.spans {
|
||||||
|
|||||||
@@ -1941,6 +1941,10 @@ fn sivp_project_previews_and_exports_a_pdf() {
|
|||||||
"missing table image label {needle}"
|
"missing table image label {needle}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
assert!(
|
||||||
|
all_svg.contains("fill=\"#aaaaaa\""),
|
||||||
|
"table image cells should stay image-backed"
|
||||||
|
);
|
||||||
let pdf = CompilerSession::default()
|
let pdf = CompilerSession::default()
|
||||||
.compile(&source, "projects/_sivp__/sn-article.tex")
|
.compile(&source, "projects/_sivp__/sn-article.tex")
|
||||||
.expect("SIVP PDF");
|
.expect("SIVP PDF");
|
||||||
|
|||||||
Reference in new issue
Block a user