Add 10/11/12pt base font size options

This commit is contained in:
gloamxun committed 2026-10-19 13:52:24 +08:00
1 parent 269433abdb
commit 477e2124c8
8 files changed
+180 -69

No files matched your search

+9 -7
View File
@@ -304,12 +304,14 @@ rule reserves space without painting ink. `\fbox{...}` is an inline framed box:
the content is measured as a single unbreakable unit, wrapped in 3pt padding and the content is measured as a single unbreakable unit, wrapped in 3pt padding and
a 0.4pt frame, and painted in both the PDF and the SVG preview. a 0.4pt frame, and painted in both the PDF and the SVG preview.
Known gaps for full document classes: base font-size class options Base font-size class options `10pt`, `11pt`, and `12pt` now set the body
(`10pt`/`11pt`/`12pt`) are parsed but the engine still uses 11pt; size and propagate through headings, title material, lists, tables, block
custom `\maketitle` implementations are ignored (the engine title layout is boxes, footnotes, and the default paragraph indent.
used), `\parbox`/`\minipage` are block-level rather than inline, `\vbox` and Known gaps for full document classes: custom `\maketitle` implementations
`\vtop` map to a full-width block box rather than true nested VBox material, and are ignored (the engine title layout is used), `\parbox`/`\minipage` are
the abstract prints as body text without an "Abstract" heading. block-level rather than inline, `\vbox` and `\vtop` map to a full-width block
box rather than true nested VBox material, and the abstract prints as body text
without an "Abstract" heading.
`\footnote{...}` captures its content, emits a superscript marker, reserves `\footnote{...}` captures its content, emits a superscript marker, reserves
space on the page where the paragraph ends, and paints the notes with a space on the page where the paragraph ends, and paints the notes with a
@@ -480,7 +482,7 @@ advisory breaks, starred `\vspace`/`\hspace`, `center`, `\hrule`, `\fbox`,
| Paragraphs | Knuth-Plass breaking, TeX hyphenation, justification, centering, `\parindent` (17pt default), `\hfill`/`\hfil` | `\raggedright`/`\raggedleft` | | Paragraphs | Knuth-Plass breaking, TeX hyphenation, justification, centering, `\parindent` (17pt default), `\hfill`/`\hfil` | `\raggedright`/`\raggedleft` |
| Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure/table `[htbp]` placement (top/bottom/page/here approximations) | deferred float queue, `\textfraction` | | Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure/table `[htbp]` placement (top/bottom/page/here approximations) | deferred float queue, `\textfraction` |
| Pages | A4/Letter/... page sizes, margins/geometry, automatic pagination, `\newpage`, `\pagebreak`, plain/fancy page styles, `\thispagestyle`, fancyhdr L/C/R headers and footers | unified planner/renderer | | Pages | A4/Letter/... page sizes, margins/geometry, automatic pagination, `\newpage`, `\pagebreak`, plain/fancy page styles, `\thispagestyle`, fancyhdr L/C/R headers and footers | unified planner/renderer |
| Classes/packages | built-in + local classes, option protocol, local package options | base font-size options (10/11/12pt) | | Classes/packages | built-in + local classes, option protocol, local package options, base font sizes 10/11/12pt | class-specific section formatting |
| Live preview | incremental paragraph/page caches, page-hash diffing, SVG refresh | — | | Live preview | incremental paragraph/page caches, page-hash diffing, SVG refresh | — |
The compatibility layer also covers spacing macros, text symbols/letters, style The compatibility layer also covers spacing macros, text symbols/letters, style
+3
View File
@@ -68,6 +68,8 @@ pub struct DocumentModel {
pub date: String, pub date: String,
pub page: PageSize, pub page: PageSize,
pub parindent: common::Scaled, pub parindent: common::Scaled,
/// Base font size selected by the document class (10, 11, or 12pt).
pub base_font_size: u8,
pub margins: PageMargins, pub margins: PageMargins,
pub show_title: bool, pub show_title: bool,
pub blocks: Vec<Block>, pub blocks: Vec<Block>,
@@ -88,6 +90,7 @@ impl Default for DocumentModel {
page: PageSize::default(), page: PageSize::default(),
// article's default \parindent for 10/11pt text. // article's default \parindent for 10/11pt text.
parindent: common::Scaled(17 * 65_536), parindent: common::Scaled(17 * 65_536),
base_font_size: 11,
margins: PageMargins::default(), margins: PageMargins::default(),
show_title: false, show_title: false,
blocks: Vec::new(), blocks: Vec::new(),
+16
View File
@@ -853,6 +853,7 @@ impl Parser {
self.finish_metadata(*field); self.finish_metadata(*field);
} }
expanded::FrontendEventKind::Geometry(settings) => { expanded::FrontendEventKind::Geometry(settings) => {
apply_class_font_size(&mut self.document, settings);
apply_geometry(&mut self.document, settings); apply_geometry(&mut self.document, settings);
} }
expanded::FrontendEventKind::TextStyleStart(style) => self.begin_style(*style), expanded::FrontendEventKind::TextStyleStart(style) => self.begin_style(*style),
@@ -2074,6 +2075,21 @@ fn apply_geometry(document: &mut DocumentModel, settings: &str) {
apply_geometry_settings(&mut document.page, &mut document.margins, settings); apply_geometry_settings(&mut document.page, &mut document.margins, settings);
} }
/// Apply article-class base font size options (10pt, 11pt, 12pt).
fn apply_class_font_size(document: &mut DocumentModel, settings: &str) {
for setting in settings.split(',').map(str::trim) {
let size = match setting {
"10pt" => 10,
"11pt" => 11,
"12pt" => 12,
_ => continue,
};
document.base_font_size = size;
let indent = if size == 11 { 17 } else { 15 };
document.parindent = common::Scaled(indent * 65_536);
}
}
/// Apply comma-separated `geometry` settings to a page size and margins. /// Apply comma-separated `geometry` settings to a page size and margins.
/// ///
/// This is shared by the document parser and by the frontend's live length /// This is shared by the document parser and by the frontend's live length
+6 -3
View File
@@ -17,10 +17,13 @@ and geometry-aware `\textwidth`/`\textheight` named length registers.
ordered list of placed items, then use it for both page-break decisions and ordered list of placed items, then use it for both page-break decisions and
final painting. This is the prerequisite for a true deferred float queue. final painting. This is the prerequisite for a true deferred float queue.
## 2. Base font size ## 2. Base font size (implemented)
- Thread the `10pt`/`11pt`/`12pt` class option through the parser, line metrics, - `DocumentModel.base_font_size` is set by the class option (default 11)
headings, and the PDF so the base size changes consistently. and threaded through both the page planner and the positioned renderer:
body lines, headings (`article_heading_font_size`), title material, lists,
tables, block boxes, footnotes, and the default `\parindent` (15pt for
10/12pt, 17pt for 11pt).
## 3. Table of contents and lists ## 3. Table of contents and lists
+6 -4
View File
@@ -54,10 +54,12 @@ See `docs/ROADMAP.md` for concrete implementation plans.
- Notes: footnotes inside captions, floats, or arbitrary boxes are not - Notes: footnotes inside captions, floats, or arbitrary boxes are not
collected; the insertion area currently follows the page where the paragraph collected; the insertion area currently follows the page where the paragraph
ends rather than the exact reference line. ends rather than the exact reference line.
- Miscellaneous: `\tableofcontents`/list commands are no-ops; base font-size - Class sizes: 10pt/11pt/12pt set the body size and propagate through
class options (10/11/12pt) are parsed but unused; rules are painted with 1x1 headings, title material, lists, tables, block boxes, footnotes, and the
images in PDF; a document-level `\renewcommand{\maketitle}` is ignored in default paragraph indent (10/12pt use 15pt; 11pt uses 17pt).
favor of the engine title block. - Miscellaneous: \tableofcontents/list commands are no-ops; rules are
painted with 1x1 images in PDF; a document-level \renewcommand{\maketitle}
is ignored in favor of the engine title block.
## Verification ## Verification
+20 -16
View File
@@ -37,11 +37,13 @@ use self::layout::{
// The local font renderer takes integer point sizes, so `\Large` is rounded // The local font renderer takes integer point sizes, so `\Large` is rounded
// from the article class's 14.4pt setting to 14pt. // from the article class's 14.4pt setting to 14pt.
fn article_heading_font_size(level: u8) -> u8 { fn article_heading_font_size(level: u8, base: u8) -> u8 {
match level { match (base, level) {
1 => 14, (12, 1) => 17,
2 => 12, (_, 1) => 14,
_ => 11, (12, 2) => 14,
(_, 2) => 12,
_ => base,
} }
} }
@@ -111,6 +113,7 @@ struct PageLayoutConfig {
math_font_fingerprint: u64, math_font_fingerprint: u64,
math_layout_font_fingerprint: u64, math_layout_font_fingerprint: u64,
page_style_fingerprint: u64, page_style_fingerprint: u64,
base_font_size: u8,
} }
struct PageLayoutSnapshot { struct PageLayoutSnapshot {
@@ -2305,6 +2308,7 @@ pub(super) fn render_pdf(
} = resources; } = resources;
let page_break_plan = page_layout.plan; let page_break_plan = page_layout.plan;
let base_font_size = model.base_font_size;
if model.show_title { if model.show_title {
if !model.title.is_empty() { if !model.title.is_empty() {
let mut title = Run::plain(model.title.clone()); let mut title = Run::plain(model.title.clone());
@@ -2314,7 +2318,7 @@ pub(super) fn render_pdf(
&[title], &[title],
cjk_family, cjk_family,
mono_family, mono_family,
20, base_font_size + 9,
&math_metrics, &math_metrics,
&math_layout, &math_layout,
) )
@@ -2327,12 +2331,12 @@ pub(super) fn render_pdf(
&[Run::plain(model.author.clone())], &[Run::plain(model.author.clone())],
cjk_family, cjk_family,
mono_family, mono_family,
12, base_font_size + 1,
&math_metrics, &math_metrics,
&math_layout, &math_layout,
) )
.aligned(Alignment::Center), .aligned(Alignment::Center),
Style::new().with_font_size(12), Style::new().with_font_size(base_font_size + 1),
)); ));
} }
if !model.date.is_empty() { if !model.date.is_empty() {
@@ -2341,12 +2345,12 @@ pub(super) fn render_pdf(
&[Run::plain(model.date.clone())], &[Run::plain(model.date.clone())],
cjk_family, cjk_family,
mono_family, mono_family,
11, base_font_size,
&math_metrics, &math_metrics,
&math_layout, &math_layout,
) )
.aligned(Alignment::Center), .aligned(Alignment::Center),
Style::new().with_font_size(11), Style::new().with_font_size(base_font_size),
)); ));
} }
document.push(elements::Break::new(1.0)); document.push(elements::Break::new(1.0));
@@ -2376,18 +2380,18 @@ pub(super) fn render_pdf(
&runs, &runs,
cjk_family, cjk_family,
mono_family, mono_family,
11, base_font_size,
&math_metrics, &math_metrics,
&math_layout, &math_layout,
), ),
Style::new().with_font_size(11), Style::new().with_font_size(base_font_size),
)); ));
} else { } else {
let lines = cached_paragraph_lines( let lines = cached_paragraph_lines(
&runs, &runs,
content_width, content_width,
&box_metrics, &box_metrics,
11, base_font_size,
paragraph_layout_cache, paragraph_layout_cache,
); );
for (line_index, line) in lines.into_iter().enumerate() { for (line_index, line) in lines.into_iter().enumerate() {
@@ -2407,9 +2411,9 @@ pub(super) fn render_pdf(
cjk_family, cjk_family,
mono_family, mono_family,
sans_family, sans_family,
11, base_font_size,
), ),
Style::new().with_font_size(11), Style::new().with_font_size(base_font_size),
)); ));
} }
} }
@@ -2420,7 +2424,7 @@ pub(super) fn render_pdf(
} }
} }
Block::Heading { level, mut runs } => { Block::Heading { level, mut runs } => {
let size = article_heading_font_size(level); let size = article_heading_font_size(level, base_font_size);
for run in &mut runs { for run in &mut runs {
run.bold = true; run.bold = true;
} }
+91 -39
View File
@@ -466,6 +466,7 @@ fn append_list_layout_tokens(
math_metrics: &math_font::MathFontMetrics, math_metrics: &math_font::MathFontMetrics,
math_layout: &MathLayoutEnvironment, math_layout: &MathLayoutEnvironment,
cache: &mut ParagraphLayoutCache, cache: &mut ParagraphLayoutCache,
font_size: u8,
) -> Option<()> { ) -> Option<()> {
let topsep = latex_nested_list_topsep(depth); let topsep = latex_nested_list_topsep(depth);
tokens.push(ListLayoutToken::Gap { tokens.push(ListLayoutToken::Gap {
@@ -477,7 +478,8 @@ fn append_list_layout_tokens(
outer_topsep: is_outer, outer_topsep: is_outer,
outer_bottomsep: false, outer_bottomsep: false,
}); });
let (labels, local_indent_mm, label_x_mm) = list_layout_metrics(list, depth, font_cache, 11); let (labels, local_indent_mm, label_x_mm) =
list_layout_metrics(list, depth, font_cache, font_size);
let text_x_mm = parent_indent_mm + local_indent_mm; let text_x_mm = parent_indent_mm + local_indent_mm;
let item_width_mm = content_width_mm - text_x_mm; let item_width_mm = content_width_mm - text_x_mm;
if !list.items.is_empty() && item_width_mm <= 0.0 { if !list.items.is_empty() && item_width_mm <= 0.0 {
@@ -487,7 +489,7 @@ fn append_list_layout_tokens(
for (item_index, item) in list.items.iter().enumerate() { for (item_index, item) in list.items.iter().enumerate() {
let mut lines = measure_positioned_lines( let mut lines = measure_positioned_lines(
&item.runs, &item.runs,
11, font_size,
item_width_mm.max(1.0), item_width_mm.max(1.0),
metrics, metrics,
font_cache, font_cache,
@@ -499,8 +501,13 @@ fn append_list_layout_tokens(
cache, cache,
); );
if lines.is_empty() { if lines.is_empty() {
let height = let height = font_line_height_scaled(
font_line_height_scaled(font_cache, cjk_family, mono_family, sans_family, 11); font_cache,
cjk_family,
mono_family,
sans_family,
font_size,
);
lines.push(MeasuredLine { lines.push(MeasuredLine {
line_index: 0, line_index: 0,
content: PositionedLineContent::Text { content: PositionedLineContent::Text {
@@ -509,7 +516,7 @@ fn append_list_layout_tokens(
items: Vec::new(), items: Vec::new(),
pre_display_size: None, pre_display_size: None,
}, },
font_size: 11, font_size,
}, },
height, height,
ascent: height, ascent: height,
@@ -550,6 +557,7 @@ fn append_list_layout_tokens(
math_metrics, math_metrics,
math_layout, math_layout,
cache, cache,
font_size,
)?; )?;
} }
for glue in &item.vertical_glue_after { for glue in &item.vertical_glue_after {
@@ -602,6 +610,7 @@ fn layout_table(
math_metrics: &math_font::MathFontMetrics, math_metrics: &math_font::MathFontMetrics,
math_layout: &MathLayoutEnvironment, math_layout: &MathLayoutEnvironment,
cache: &mut ParagraphLayoutCache, cache: &mut ParagraphLayoutCache,
font_size: u8,
) -> Option<PositionedTable> { ) -> Option<PositionedTable> {
let column_count = rows.iter().map(Vec::len).max().unwrap_or(0); let column_count = rows.iter().map(Vec::len).max().unwrap_or(0);
if column_count == 0 { if column_count == 0 {
@@ -612,8 +621,14 @@ fn layout_table(
return None; return None;
} }
let empty_row_height = let cell_font_size = font_size.saturating_sub(1).max(1);
font_line_height_scaled(font_cache, cjk_family, mono_family, sans_family, 10); let empty_row_height = font_line_height_scaled(
font_cache,
cjk_family,
mono_family,
sans_family,
cell_font_size,
);
let mut positioned_rows = Vec::with_capacity(rows.len()); let mut positioned_rows = Vec::with_capacity(rows.len());
let mut total_height = 0_i64; let mut total_height = 0_i64;
for row in rows { for row in rows {
@@ -623,7 +638,7 @@ fn layout_table(
let runs = row.get(column).map(Vec::as_slice).unwrap_or_default(); let runs = row.get(column).map(Vec::as_slice).unwrap_or_default();
let lines = measure_positioned_lines( let lines = measure_positioned_lines(
runs, runs,
10, cell_font_size,
cell_width_mm, cell_width_mm,
metrics, metrics,
font_cache, font_cache,
@@ -802,6 +817,7 @@ fn measure_framed_box(
cache: &mut ParagraphLayoutCache, cache: &mut ParagraphLayoutCache,
frame: bool, frame: bool,
width: Option<common::Scaled>, width: Option<common::Scaled>,
font_size: u8,
) -> Option<MeasuredFramedBox> { ) -> Option<MeasuredFramedBox> {
let padding_mm = if frame { let padding_mm = if frame {
FRAMED_BOX_PADDING_PT * 25.4 / PDF_POINTS_PER_INCH FRAMED_BOX_PADDING_PT * 25.4 / PDF_POINTS_PER_INCH
@@ -819,7 +835,7 @@ fn measure_framed_box(
if let Some(width) = width { if let Some(width) = width {
let box_width_mm = scaled_units_to_mm(i64::from(width.0)); let box_width_mm = scaled_units_to_mm(i64::from(width.0));
let inner_mm = (box_width_mm - 2.0 * inset_mm).max(5.0); let inner_mm = (box_width_mm - 2.0 * inset_mm).max(5.0);
let lines = cached_paragraph_lines(runs, inner_mm, metrics, 11, cache); let lines = cached_paragraph_lines(runs, inner_mm, metrics, font_size, cache);
let mut content_height = 0_i64; let mut content_height = 0_i64;
for line in &lines { for line in &lines {
let (ascent, depth) = text_line_metrics_scaled( let (ascent, depth) = text_line_metrics_scaled(
@@ -828,11 +844,11 @@ fn measure_framed_box(
cjk_family, cjk_family,
mono_family, mono_family,
sans_family, sans_family,
11, font_size,
); );
content_height = content_height.saturating_add(ascent).saturating_add(depth); content_height = content_height.saturating_add(ascent).saturating_add(depth);
} }
let content_height = content_height.max(baseline_skip_scaled(11)); let content_height = content_height.max(baseline_skip_scaled(font_size));
return Some(MeasuredFramedBox { return Some(MeasuredFramedBox {
lines, lines,
width: millimeters_to_scaled(box_width_mm), width: millimeters_to_scaled(box_width_mm),
@@ -841,12 +857,18 @@ fn measure_framed_box(
frame, frame,
}); });
} }
let (line, ascent, descent) = let (line, ascent, descent) = layout_framed_runs(
layout_framed_runs(runs, font_cache, cjk_family, mono_family, sans_family, 11); runs,
font_cache,
cjk_family,
mono_family,
sans_family,
font_size,
);
let content_mm = f64::from(scaled_units_to_mm(i64::from(line.width.0))).min(max_content_mm); let content_mm = f64::from(scaled_units_to_mm(i64::from(line.width.0))).min(max_content_mm);
let content_height = let content_height =
i64::from(scaled_points(f64::from(ascent + descent) * PDF_POINTS_PER_INCH / 25.4).0) i64::from(scaled_points(f64::from(ascent + descent) * PDF_POINTS_PER_INCH / 25.4).0)
.max(baseline_skip_scaled(11)); .max(baseline_skip_scaled(font_size));
Some(MeasuredFramedBox { Some(MeasuredFramedBox {
lines: vec![line], lines: vec![line],
width: millimeters_to_scaled(content_mm + 2.0 * inset_mm), width: millimeters_to_scaled(content_mm + 2.0 * inset_mm),
@@ -979,16 +1001,23 @@ fn measure_centered(
mono_family: Option<FontFamily<fonts::Font>>, mono_family: Option<FontFamily<fonts::Font>>,
sans_family: Option<FontFamily<fonts::Font>>, sans_family: Option<FontFamily<fonts::Font>>,
cache: &mut ParagraphLayoutCache, cache: &mut ParagraphLayoutCache,
font_size: u8,
) -> MeasuredCentered { ) -> MeasuredCentered {
let lines = cached_paragraph_lines(runs, content_width_mm, metrics, 11, cache); let lines = cached_paragraph_lines(runs, content_width_mm, metrics, font_size, cache);
let mut height = 0_i64; let mut height = 0_i64;
for line in &lines { for line in &lines {
let (ascent, depth) = let (ascent, depth) = text_line_metrics_scaled(
text_line_metrics_scaled(font_cache, line, cjk_family, mono_family, sans_family, 11); font_cache,
line,
cjk_family,
mono_family,
sans_family,
font_size,
);
height = height.saturating_add(ascent).saturating_add(depth); height = height.saturating_add(ascent).saturating_add(depth);
} }
if height == 0 { if height == 0 {
height = baseline_skip_scaled(11); height = baseline_skip_scaled(font_size);
} }
MeasuredCentered { lines, height } MeasuredCentered { lines, height }
} }
@@ -1008,8 +1037,14 @@ pub(super) fn build_page_break_plan(
paragraph_cache: &mut ParagraphLayoutCache, paragraph_cache: &mut ParagraphLayoutCache,
page_layout_cache: &PageLayoutCache, page_layout_cache: &PageLayoutCache,
) -> Option<PageBreakPlan> { ) -> Option<PageBreakPlan> {
let normal_line_height = let base_font_size = model.base_font_size;
font_line_height_scaled(font_cache, cjk_family, mono_family, sans_family, 11); let normal_line_height = font_line_height_scaled(
font_cache,
cjk_family,
mono_family,
sans_family,
base_font_size,
);
let top_skip = i64::from(scaled_points(ARTICLE_11PT_TOPSKIP_PT).0); let top_skip = i64::from(scaled_points(ARTICLE_11PT_TOPSKIP_PT).0);
let max_depth = i64::from(scaled_points(ARTICLE_11PT_MAX_DEPTH_PT).0); let max_depth = i64::from(scaled_points(ARTICLE_11PT_MAX_DEPTH_PT).0);
let page_goal = scaled_points(content_height_mm * PDF_POINTS_PER_INCH / 25.4).0 as i64; let page_goal = scaled_points(content_height_mm * PDF_POINTS_PER_INCH / 25.4).0 as i64;
@@ -1017,9 +1052,9 @@ pub(super) fn build_page_break_plan(
let mut pre_display_size = None; let mut pre_display_size = None;
if model.show_title { if model.show_title {
for (text, size, bold) in [ for (text, size, bold) in [
(&model.title, 20, true), (&model.title, base_font_size + 9, true),
(&model.author, 12, false), (&model.author, base_font_size + 1, false),
(&model.date, 11, false), (&model.date, base_font_size, false),
] { ] {
if text.is_empty() { if text.is_empty() {
continue; continue;
@@ -1054,7 +1089,7 @@ pub(super) fn build_page_break_plan(
&mut nodes, &mut nodes,
runs, runs,
block_index, block_index,
11, base_font_size,
content_width_mm, content_width_mm,
font_cache, font_cache,
cjk_family, cjk_family,
@@ -1068,7 +1103,7 @@ pub(super) fn build_page_break_plan(
&mut nodes, &mut nodes,
runs, runs,
Some(block_index), Some(block_index),
11, base_font_size,
content_width_mm, content_width_mm,
metrics, metrics,
font_cache, font_cache,
@@ -1111,6 +1146,7 @@ pub(super) fn build_page_break_plan(
paragraph_cache, paragraph_cache,
*frame, *frame,
*width, *width,
base_font_size,
) else { ) else {
continue; continue;
}; };
@@ -1140,6 +1176,7 @@ pub(super) fn build_page_break_plan(
mono_family, mono_family,
sans_family, sans_family,
paragraph_cache, paragraph_cache,
base_font_size,
); );
nodes.push(VerticalNode::fixed_glue( nodes.push(VerticalNode::fixed_glue(
(normal_line_height as f64 * 0.35).round() as i64, (normal_line_height as f64 * 0.35).round() as i64,
@@ -1181,7 +1218,7 @@ pub(super) fn build_page_break_plan(
for run in &mut runs { for run in &mut runs {
run.bold = true; run.bold = true;
} }
let size = super::article_heading_font_size(*level); let size = super::article_heading_font_size(*level, base_font_size);
pre_display_size = if runs.iter().any(|run| run.math.is_some()) { pre_display_size = if runs.iter().any(|run| run.math.is_some()) {
append_vertical_inline_math( append_vertical_inline_math(
&mut nodes, &mut nodes,
@@ -1264,6 +1301,7 @@ pub(super) fn build_page_break_plan(
math_metrics, math_metrics,
math_layout, math_layout,
paragraph_cache, paragraph_cache,
base_font_size,
)?; )?;
let mut list_pre_display_size = None; let mut list_pre_display_size = None;
for token in tokens { for token in tokens {
@@ -1387,6 +1425,7 @@ pub(super) fn build_page_break_plan(
math_metrics, math_metrics,
math_layout, math_layout,
paragraph_cache, paragraph_cache,
base_font_size,
) { ) {
for row in table.rows { for row in table.rows {
if row.height > page_goal { if row.height > page_goal {
@@ -1545,6 +1584,7 @@ pub(super) fn build_page_break_plan(
text_font_fingerprint: metrics.fingerprint, text_font_fingerprint: metrics.fingerprint,
math_font_fingerprint: math_metrics.fingerprint, math_font_fingerprint: math_metrics.fingerprint,
math_layout_font_fingerprint: math_layout.font_fingerprint, math_layout_font_fingerprint: math_layout.font_fingerprint,
base_font_size: model.base_font_size,
page_style_fingerprint: { page_style_fingerprint: {
let mut hasher = DefaultHasher::new(); let mut hasher = DefaultHasher::new();
model.page_style.hash(&mut hasher); model.page_style.hash(&mut hasher);
@@ -1627,6 +1667,7 @@ fn footnote_reserve(
if numbers.is_empty() { if numbers.is_empty() {
return 0; return 0;
} }
let footnote_font_size = ((f32::from(model.base_font_size) * 0.82).round() as u8).max(1);
let width_mm = (content_width_mm - 8.0).max(20.0); let width_mm = (content_width_mm - 8.0).max(20.0);
let mut height = 0_i64; let mut height = 0_i64;
for number in numbers { for number in numbers {
@@ -1635,7 +1676,7 @@ fn footnote_reserve(
}; };
for line in measure_positioned_lines( for line in measure_positioned_lines(
&runs, &runs,
9, footnote_font_size,
width_mm, width_mm,
metrics, metrics,
font_cache, font_cache,
@@ -1810,6 +1851,7 @@ fn append_page_footnotes(
math_layout: &MathLayoutEnvironment, math_layout: &MathLayoutEnvironment,
cache: &mut ParagraphLayoutCache, cache: &mut ParagraphLayoutCache,
) { ) {
let footnote_font_size = ((f32::from(model.base_font_size) * 0.82).round() as u8).max(1);
let mut referenced = Vec::new(); let mut referenced = Vec::new();
for block in block_end_pages.keys() { for block in block_end_pages.keys() {
for number in footnote_numbers_for_block(model, *block) { for number in footnote_numbers_for_block(model, *block) {
@@ -1858,7 +1900,7 @@ fn append_page_footnotes(
}; };
note_lines.extend(measure_positioned_lines( note_lines.extend(measure_positioned_lines(
&runs, &runs,
9, footnote_font_size,
width_mm, width_mm,
metrics, metrics,
font_cache, font_cache,
@@ -1897,7 +1939,7 @@ fn append_page_footnotes(
}, },
content: PositionedLineContent::Text { content: PositionedLineContent::Text {
line: rule_line, line: rule_line,
font_size: 9, font_size: footnote_font_size,
}, },
y, y,
x: 0, x: 0,
@@ -1936,8 +1978,14 @@ pub(super) fn build_positioned_pages(
math_layout: &MathLayoutEnvironment, math_layout: &MathLayoutEnvironment,
cache: &mut ParagraphLayoutCache, cache: &mut ParagraphLayoutCache,
) -> Option<Vec<PositionedPage>> { ) -> Option<Vec<PositionedPage>> {
let normal_line_height = let base_font_size = model.base_font_size;
font_line_height_scaled(font_cache, cjk_family, mono_family, sans_family, 11); let normal_line_height = font_line_height_scaled(
font_cache,
cjk_family,
mono_family,
sans_family,
base_font_size,
);
let top_skip = i64::from(scaled_points(ARTICLE_11PT_TOPSKIP_PT).0); let top_skip = i64::from(scaled_points(ARTICLE_11PT_TOPSKIP_PT).0);
let max_depth = i64::from(scaled_points(ARTICLE_11PT_MAX_DEPTH_PT).0); let max_depth = i64::from(scaled_points(ARTICLE_11PT_MAX_DEPTH_PT).0);
let paragraph_gap = (normal_line_height as f64 * 0.35).round() as i64; let paragraph_gap = (normal_line_height as f64 * 0.35).round() as i64;
@@ -1953,9 +2001,9 @@ pub(super) fn build_positioned_pages(
if model.show_title { if model.show_title {
for (text, font_size, bold) in [ for (text, font_size, bold) in [
(&model.title, 20, true), (&model.title, base_font_size + 9, true),
(&model.author, 12, false), (&model.author, base_font_size + 1, false),
(&model.date, 11, false), (&model.date, base_font_size, false),
] { ] {
if text.is_empty() { if text.is_empty() {
continue; continue;
@@ -2016,9 +2064,9 @@ pub(super) fn build_positioned_pages(
match block { match block {
Block::Paragraph(runs) | Block::Heading { runs, .. } => { Block::Paragraph(runs) | Block::Heading { runs, .. } => {
let (font_size, is_heading) = match block { let (font_size, is_heading) = match block {
Block::Paragraph(_) => (11, false), Block::Paragraph(_) => (base_font_size, false),
Block::Heading { level, .. } => { Block::Heading { level, .. } => {
let size = super::article_heading_font_size(*level); let size = super::article_heading_font_size(*level, base_font_size);
(size, true) (size, true)
} }
_ => unreachable!("the outer match selected a text block"), _ => unreachable!("the outer match selected a text block"),
@@ -2119,6 +2167,7 @@ pub(super) fn build_positioned_pages(
cache, cache,
*frame, *frame,
*width, *width,
base_font_size,
) else { ) else {
continue; continue;
}; };
@@ -2168,6 +2217,7 @@ pub(super) fn build_positioned_pages(
mono_family, mono_family,
sans_family, sans_family,
cache, cache,
base_font_size,
); );
let anchor = PageAnchor { let anchor = PageAnchor {
block: block_index, block: block_index,
@@ -2240,7 +2290,7 @@ pub(super) fn build_positioned_pages(
anchor, anchor,
content: PositionedLineContent::Text { content: PositionedLineContent::Text {
line, line,
font_size: 11, font_size: base_font_size,
}, },
y: cursor, y: cursor,
x: 0, x: 0,
@@ -2339,6 +2389,7 @@ pub(super) fn build_positioned_pages(
math_metrics, math_metrics,
math_layout, math_layout,
cache, cache,
base_font_size,
)?; )?;
let mut list_pre_display_size = None; let mut list_pre_display_size = None;
for token in tokens { for token in tokens {
@@ -2390,7 +2441,7 @@ pub(super) fn build_positioned_pages(
&label_runs, &label_runs,
content_width_mm, content_width_mm,
metrics, metrics,
11, base_font_size,
cache, cache,
) )
.into_iter() .into_iter()
@@ -2404,7 +2455,7 @@ pub(super) fn build_positioned_pages(
anchor, anchor,
content: PositionedLineContent::Text { content: PositionedLineContent::Text {
line: label_line, line: label_line,
font_size: 11, font_size: base_font_size,
}, },
y: cursor, y: cursor,
x: millimeters_to_scaled(label_x_mm), x: millimeters_to_scaled(label_x_mm),
@@ -2505,6 +2556,7 @@ pub(super) fn build_positioned_pages(
math_metrics, math_metrics,
math_layout, math_layout,
cache, cache,
base_font_size,
) { ) {
let PositionedTable { let PositionedTable {
rows: table_rows, rows: table_rows,
+29
View File
@@ -759,3 +759,32 @@ fn letter_paper_updates_text_width_length() {
"letter textwidth is wrong: {width}" "letter textwidth is wrong: {width}"
); );
} }
#[test]
fn document_class_font_size_scales_body_and_headings() {
for (option, body_size, heading_size) in [
("10pt", "3.5278", "4.9389"),
("11pt", "3.8806", "4.9389"),
("12pt", "4.2333", "5.9972"),
] {
let source = format!(
r"\documentclass[{option}]{{article}}
\begin{{document}}
\section{{Heading}}
Body text.
\end{{document}}
"
);
let value = fresh_preview(&source, "fontsize.tex");
assert_eq!(value["status"], "ok", "{option}: {}", value["message"]);
let svg = page_svg(&value, 0);
assert!(
svg.contains(&format!("font-size=\"{body_size}\" font-weight=\"400\"")),
"{option}: body size {body_size} missing"
);
assert!(
svg.contains(&format!("font-size=\"{heading_size}\" font-weight=\"700\"")),
"{option}: heading size {heading_size} missing"
);
}
}