summaryrefslogtreecommitdiff
path: root/src/export/pdf
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-19 11:31:37 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-19 11:36:59 +0200
commit30be75c6687f1e03cf867d258b3ddba353cc7aa2 (patch)
tree51afd42ae8875811ae51974e66681a17990de7f2 /src/export/pdf
parent4ec3bcee487c1567bc6551f81d4f69eee4379076 (diff)
Renaming
`Face` -> `Font` `FaceId` -> `FontId` `SourceFile` -> `Source`
Diffstat (limited to 'src/export/pdf')
-rw-r--r--src/export/pdf/font.rs32
-rw-r--r--src/export/pdf/mod.rs12
-rw-r--r--src/export/pdf/page.rs24
3 files changed, 34 insertions, 34 deletions
diff --git a/src/export/pdf/font.rs b/src/export/pdf/font.rs
index 804a2cb1..99268f9c 100644
--- a/src/export/pdf/font.rs
+++ b/src/export/pdf/font.rs
@@ -9,20 +9,20 @@ use crate::util::SliceExt;
/// Embed all used fonts into the PDF.
pub fn write_fonts(ctx: &mut PdfContext) {
- for face_id in ctx.face_map.layout_indices() {
+ for font_id in ctx.font_map.layout_indices() {
let type0_ref = ctx.alloc.bump();
let cid_ref = ctx.alloc.bump();
let descriptor_ref = ctx.alloc.bump();
let cmap_ref = ctx.alloc.bump();
let data_ref = ctx.alloc.bump();
- ctx.face_refs.push(type0_ref);
+ ctx.font_refs.push(type0_ref);
- let glyphs = &ctx.glyph_sets[&face_id];
- let face = ctx.fonts.get(face_id);
- let metrics = face.metrics();
- let ttf = face.ttf();
+ let glyphs = &ctx.glyph_sets[&font_id];
+ let font = ctx.fonts.get(font_id);
+ let metrics = font.metrics();
+ let ttf = font.ttf();
- let postscript_name = face
+ let postscript_name = font
.find_name(name_id::POST_SCRIPT_NAME)
.unwrap_or_else(|| "unknown".to_string());
@@ -70,7 +70,7 @@ pub fn write_fonts(ctx: &mut PdfContext) {
let mut widths = vec![0.0; num_glyphs as usize];
for &g in glyphs {
let x = ttf.glyph_hor_advance(GlyphId(g)).unwrap_or(0);
- widths[g as usize] = face.to_em(x).to_font_units();
+ widths[g as usize] = font.to_em(x).to_font_units();
}
// Write all non-zero glyph widths.
@@ -97,10 +97,10 @@ pub fn write_fonts(ctx: &mut PdfContext) {
let global_bbox = ttf.global_bounding_box();
let bbox = Rect::new(
- face.to_em(global_bbox.x_min).to_font_units(),
- face.to_em(global_bbox.y_min).to_font_units(),
- face.to_em(global_bbox.x_max).to_font_units(),
- face.to_em(global_bbox.y_max).to_font_units(),
+ font.to_em(global_bbox.x_min).to_font_units(),
+ font.to_em(global_bbox.y_min).to_font_units(),
+ font.to_em(global_bbox.x_max).to_font_units(),
+ font.to_em(global_bbox.y_max).to_font_units(),
);
let italic_angle = ttf.italic_angle().unwrap_or(0.0);
@@ -160,15 +160,15 @@ pub fn write_fonts(ctx: &mut PdfContext) {
.cmap(cmap_ref, &deflate(&cmap.finish()))
.filter(Filter::FlateDecode);
- // Subset and write the face's bytes.
- let data = face.buffer();
+ // Subset and write the font's bytes.
+ let data = font.buffer();
let subsetted = {
let glyphs: Vec<_> = glyphs.iter().copied().collect();
let profile = subsetter::Profile::pdf(&glyphs);
- subsetter::subset(data, face.index(), profile)
+ subsetter::subset(data, font.index(), profile)
};
- // Compress and write the face's byte.
+ // Compress and write the font's byte.
let data = subsetted.as_deref().unwrap_or(data);
let data = deflate(data);
let mut stream = ctx.writer.stream(data_ref, &data);
diff --git a/src/export/pdf/mod.rs b/src/export/pdf/mod.rs
index 4afe749f..9ab3df24 100644
--- a/src/export/pdf/mod.rs
+++ b/src/export/pdf/mod.rs
@@ -14,7 +14,7 @@ use pdf_writer::{Finish, Name, PdfWriter, Ref, TextStr};
use self::outline::{Heading, HeadingNode};
use self::page::Page;
-use crate::font::{FaceId, FontStore};
+use crate::font::{FontId, FontStore};
use crate::frame::Frame;
use crate::geom::{Dir, Em, Length};
use crate::image::{ImageId, ImageStore};
@@ -51,12 +51,12 @@ pub struct PdfContext<'a> {
page_heights: Vec<f32>,
alloc: Ref,
page_tree_ref: Ref,
- face_refs: Vec<Ref>,
+ font_refs: Vec<Ref>,
image_refs: Vec<Ref>,
page_refs: Vec<Ref>,
- face_map: Remapper<FaceId>,
+ font_map: Remapper<FontId>,
image_map: Remapper<ImageId>,
- glyph_sets: HashMap<FaceId, HashSet<u16>>,
+ glyph_sets: HashMap<FontId, HashSet<u16>>,
languages: HashMap<Lang, usize>,
heading_tree: Vec<HeadingNode>,
}
@@ -74,9 +74,9 @@ impl<'a> PdfContext<'a> {
alloc,
page_tree_ref,
page_refs: vec![],
- face_refs: vec![],
+ font_refs: vec![],
image_refs: vec![],
- face_map: Remapper::new(),
+ font_map: Remapper::new(),
image_map: Remapper::new(),
glyph_sets: HashMap::new(),
languages: HashMap::new(),
diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs
index 7cd0f58f..e5739a82 100644
--- a/src/export/pdf/page.rs
+++ b/src/export/pdf/page.rs
@@ -5,7 +5,7 @@ use pdf_writer::{Content, Filter, Finish, Name, Rect, Ref, Str};
use super::{
deflate, EmExt, Heading, HeadingNode, LengthExt, PdfContext, RefExt, D65_GRAY, SRGB,
};
-use crate::font::FaceId;
+use crate::font::FontId;
use crate::frame::{Destination, Element, Frame, Group, Role, Text};
use crate::geom::{
self, Color, Em, Geometry, Length, Numeric, Paint, Point, Ratio, Shape, Size, Stroke,
@@ -80,7 +80,7 @@ pub fn write_page_tree(ctx: &mut PdfContext) {
spaces.finish();
let mut fonts = resources.fonts();
- for (font_ref, f) in ctx.face_map.pdf_indices(&ctx.face_refs) {
+ for (font_ref, f) in ctx.font_map.pdf_indices(&ctx.font_refs) {
let name = format_eco!("F{}", f);
fonts.pair(Name(name.as_bytes()), font_ref);
}
@@ -169,7 +169,7 @@ struct PageContext<'a, 'b> {
#[derive(Debug, Default, Clone)]
struct State {
transform: Transform,
- font: Option<(FaceId, Length)>,
+ font: Option<(FontId, Length)>,
fill: Option<Paint>,
fill_space: Option<Name<'static>>,
stroke: Option<Stroke>,
@@ -200,12 +200,12 @@ impl<'a, 'b> PageContext<'a, 'b> {
]);
}
- fn set_font(&mut self, face_id: FaceId, size: Length) {
- if self.state.font != Some((face_id, size)) {
- self.parent.face_map.insert(face_id);
- let name = format_eco!("F{}", self.parent.face_map.map(face_id));
+ fn set_font(&mut self, font_id: FontId, size: Length) {
+ if self.state.font != Some((font_id, size)) {
+ self.parent.font_map.insert(font_id);
+ let name = format_eco!("F{}", self.parent.font_map.map(font_id));
self.content.set_font(Name(name.as_bytes()), size.to_f32());
- self.state.font = Some((face_id, size));
+ self.state.font = Some((font_id, size));
}
}
@@ -329,14 +329,14 @@ fn write_text(ctx: &mut PageContext, x: f32, y: f32, text: &Text) {
*ctx.parent.languages.entry(text.lang).or_insert(0) += text.glyphs.len();
ctx.parent
.glyph_sets
- .entry(text.face_id)
+ .entry(text.font_id)
.or_default()
.extend(text.glyphs.iter().map(|g| g.id));
- let face = ctx.parent.fonts.get(text.face_id);
+ let font = ctx.parent.fonts.get(text.font_id);
ctx.set_fill(text.fill);
- ctx.set_font(text.face_id, text.size);
+ ctx.set_font(text.font_id, text.size);
ctx.content.begin_text();
// Position the text.
@@ -364,7 +364,7 @@ fn write_text(ctx: &mut PageContext, x: f32, y: f32, text: &Text) {
encoded.push((glyph.id >> 8) as u8);
encoded.push((glyph.id & 0xff) as u8);
- if let Some(advance) = face.advance(glyph.id) {
+ if let Some(advance) = font.advance(glyph.id) {
adjustment += glyph.x_advance - advance;
}