Use Times metrics for table column widths
Halign measured every cell with the CMR default even in Times documents, so the sample table was wider than TeX and page 3 ink reached x=553. Give Halign an optional paragraph face and refresh column widths in that face; route-D now selects TimesRoman for ptm tabulars. Page 3 ink bbox moves to x=540, matching the reference.
This commit is contained in:
1 parent
43f8c979cf
commit
049365d595
3 files changed
+29
-3
No files matched your search
@@ -178,6 +178,9 @@ pub struct Halign {
|
|||||||
pub width: i64,
|
pub width: i64,
|
||||||
pub height: i64,
|
pub height: i64,
|
||||||
pub line_height: i64,
|
pub line_height: i64,
|
||||||
|
/// Metrics used for natural cell widths; keeps the CMR defaults.
|
||||||
|
#[serde(default)]
|
||||||
|
pub font: Option<crate::paragraph::ParagraphFont>,
|
||||||
/// Nested tables painted inside a cell: (row, cell, table).
|
/// Nested tables painted inside a cell: (row, cell, table).
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub nested: Vec<(usize, usize, Halign)>,
|
pub nested: Vec<(usize, usize, Halign)>,
|
||||||
@@ -346,6 +349,7 @@ impl Halign {
|
|||||||
width: self.width,
|
width: self.width,
|
||||||
height,
|
height,
|
||||||
line_height: self.line_height,
|
line_height: self.line_height,
|
||||||
|
font: self.font,
|
||||||
});
|
});
|
||||||
first_chunk = false;
|
first_chunk = false;
|
||||||
if last {
|
if last {
|
||||||
@@ -387,6 +391,7 @@ impl Halign {
|
|||||||
width: self.width,
|
width: self.width,
|
||||||
height,
|
height,
|
||||||
line_height: self.line_height,
|
line_height: self.line_height,
|
||||||
|
font: self.font,
|
||||||
});
|
});
|
||||||
start = index;
|
start = index;
|
||||||
height = 0;
|
height = 0;
|
||||||
@@ -414,6 +419,7 @@ impl Halign {
|
|||||||
width: self.width,
|
width: self.width,
|
||||||
height,
|
height,
|
||||||
line_height: self.line_height,
|
line_height: self.line_height,
|
||||||
|
font: self.font,
|
||||||
});
|
});
|
||||||
chunks
|
chunks
|
||||||
}
|
}
|
||||||
@@ -580,7 +586,10 @@ impl Halign {
|
|||||||
for cell in &row.cells {
|
for cell in &row.cells {
|
||||||
let span = cell.span.max(1).min(column_count.saturating_sub(column));
|
let span = cell.span.max(1).min(column_count.saturating_sub(column));
|
||||||
if span == 1 {
|
if span == 1 {
|
||||||
let width = crate::text_width(&cell.text);
|
let width = match self.font {
|
||||||
|
Some(font) => crate::text_width_with_font(&cell.text, font),
|
||||||
|
None => crate::text_width(&cell.text),
|
||||||
|
};
|
||||||
if let Some(slot) = widths.get_mut(column) {
|
if let Some(slot) = widths.get_mut(column) {
|
||||||
*slot = (*slot).max(width);
|
*slot = (*slot).max(width);
|
||||||
}
|
}
|
||||||
@@ -624,6 +633,12 @@ impl Halign {
|
|||||||
.sum();
|
.sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Select the text metrics used for table column widths.
|
||||||
|
pub fn set_font(&mut self, font: crate::paragraph::ParagraphFont) {
|
||||||
|
self.font = Some(font);
|
||||||
|
self.refresh_measurements();
|
||||||
|
}
|
||||||
|
|
||||||
/// Uniform intercolumn spacing derived from the table width.
|
/// Uniform intercolumn spacing derived from the table width.
|
||||||
fn uniform_intercolumn(&self) -> i64 {
|
fn uniform_intercolumn(&self) -> i64 {
|
||||||
if self.column_widths.len() > 1 {
|
if self.column_widths.len() > 1 {
|
||||||
@@ -685,7 +700,12 @@ impl Halign {
|
|||||||
|
|
||||||
/// Natural width of a run of text in the default 10pt Roman face.
|
/// Natural width of a run of text in the default 10pt Roman face.
|
||||||
pub(crate) fn text_width(text: &str) -> i64 {
|
pub(crate) fn text_width(text: &str) -> i64 {
|
||||||
let metrics = crate::cmr10::Cmr10Metrics::Roman;
|
text_width_with_font(text, crate::paragraph::ParagraphFont::Roman)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Natural width of a run of text in a selectable paragraph face.
|
||||||
|
pub(crate) fn text_width_with_font(text: &str, font: crate::paragraph::ParagraphFont) -> i64 {
|
||||||
|
let metrics = crate::cmr10::Cmr10Metrics::for_paragraph_font(font);
|
||||||
text.chars()
|
text.chars()
|
||||||
.map(|character| {
|
.map(|character| {
|
||||||
if character.is_whitespace() {
|
if character.is_whitespace() {
|
||||||
@@ -1291,6 +1311,7 @@ impl Unit {
|
|||||||
width,
|
width,
|
||||||
height: 0,
|
height: 0,
|
||||||
line_height,
|
line_height,
|
||||||
|
font: None,
|
||||||
};
|
};
|
||||||
halign.height = (0..halign.rows.len())
|
halign.height = (0..halign.rows.len())
|
||||||
.map(|index| halign.row_height(index) + halign.row_gap(index))
|
.map(|index| halign.row_height(index) + halign.row_gap(index))
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ reference_words 1243, candidate_words 1262
|
|||||||
word_sequence_ratio 0.8958
|
word_sequence_ratio 0.8958
|
||||||
page 1 ink bbox: TeX [72, 79, 540, 721] route-D [71, 79, 540, 724]
|
page 1 ink bbox: TeX [72, 79, 540, 721] route-D [71, 79, 540, 724]
|
||||||
page 2 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751]
|
page 2 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751]
|
||||||
page 3 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 553, 751]
|
page 3 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751]
|
||||||
page ink fraction: TeX 0.0416/0.0448/0.0432, route-D 0.0434/0.0492/0.0434
|
page ink fraction: TeX 0.0416/0.0448/0.0432, route-D 0.0434/0.0492/0.0434
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -4269,6 +4269,11 @@ fn tabular_unit(
|
|||||||
12,
|
12,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
);
|
);
|
||||||
|
if geometry.roman_family.as_deref() == Some("ptm")
|
||||||
|
&& let Some(VerticalItem::Halign(halign)) = unit.items.first_mut()
|
||||||
|
{
|
||||||
|
halign.set_font(texrra_tex_core::paragraph::ParagraphFont::TimesRoman);
|
||||||
|
}
|
||||||
let stretch = geometry.array_stretch.unwrap_or(1000);
|
let stretch = geometry.array_stretch.unwrap_or(1000);
|
||||||
if separator != 6 * SCALE || stretch != 1000 {
|
if separator != 6 * SCALE || stretch != 1000 {
|
||||||
if let Some(VerticalItem::Halign(halign)) = unit.items.first_mut() {
|
if let Some(VerticalItem::Halign(halign)) = unit.items.first_mut() {
|
||||||
|
|||||||
Reference in new issue
Block a user