Add per-face PDF font resources

This commit is contained in:
gloamxun committed 2026-10-20 18:27:14 +08:00
1 parent 03025de783
commit d40595c7e5
5 files changed
+91 -9

No files matched your search

+23 -1
View File
@@ -10,6 +10,15 @@ use crate::math::{self, MathAtom};
use crate::{FloatPlacement, Halign, HorizontalItem, Page, VerticalItem};
/// One absolute drawing primitive in scaled points.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum FontFace {
Roman,
Bold,
Italic,
BoldItalic,
Mono,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DisplayItem {
Text {
@@ -17,6 +26,7 @@ pub enum DisplayItem {
y: i64,
size: i64,
text: String,
font: FontFace,
},
Rule {
x: i64,
@@ -112,7 +122,9 @@ impl DisplayList {
);
for item in &self.items {
match item {
DisplayItem::Text { x, y, size, text } => {
DisplayItem::Text {
x, y, size, text, ..
} => {
let x = *x as f64 / 65_536.0;
let y = *y as f64 / 65_536.0;
let size = *size as f64 / 65_536.0;
@@ -213,6 +225,7 @@ impl Halign {
for (index, cell) in row.cells.iter().enumerate() {
if let Some((x, _)) = self.cell_box(row_index, index) {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline,
size: self.line_height * 5 / 6,
@@ -323,6 +336,7 @@ impl Page {
HorizontalItem::Box(box_) => {
if let Some(character) = box_.character {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline,
size,
@@ -435,6 +449,7 @@ impl Page {
MathAtom::Symbol(character) => {
if !character.is_whitespace() {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline,
size,
@@ -446,6 +461,7 @@ impl Page {
let mut cursor = x;
for character in text.chars() {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x: cursor,
y: baseline,
size,
@@ -520,6 +536,7 @@ impl Page {
MathAtom::Sqrt { radicand, .. } => {
let box_ = math::layout_math(radicand, font);
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline,
size,
@@ -537,6 +554,7 @@ impl Page {
let body_box = math::layout_math(body, font);
if *left != '.' {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline,
size,
@@ -546,6 +564,7 @@ impl Page {
Self::paint_math(body, font, x + font.width(*left), baseline, size, list);
if *right != '.' {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x: x + font.width(*left) + body_box.width,
y: baseline,
size,
@@ -557,6 +576,7 @@ impl Page {
let base_box = math::layout_math(base, font);
Self::paint_math(base, font, x, baseline, size, list);
list.push(DisplayItem::Text {
font: FontFace::Roman,
x: x + base_box.width / 2,
y: baseline - base_box.height - 65_536,
size,
@@ -654,6 +674,7 @@ impl Page {
MathAtom::BigOperator { name } => {
for (index, character) in name.chars().enumerate() {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x: x + index as i64 * font.width(character),
y: baseline,
size,
@@ -663,6 +684,7 @@ impl Page {
}
MathAtom::SizedDelimiter { delimiter, .. } => {
list.push(DisplayItem::Text {
font: FontFace::Roman,
x,
y: baseline,
size,