Use CMR10 advances for route-D paragraphs and PDF text
This commit is contained in:
1 parent
8251e35de2
commit
67915402a6
7 files changed
+45
-19
No files matched your search
@@ -8,6 +8,7 @@ use std::sync::OnceLock;
|
||||
|
||||
use rusttype::Font;
|
||||
|
||||
use crate::cmr10::Cmr10Metrics;
|
||||
use crate::render::{DisplayItem, DisplayList, FontFace};
|
||||
|
||||
struct PdfFace {
|
||||
@@ -160,16 +161,24 @@ fn cid_widths(face: &'static PdfFace) -> String {
|
||||
let font = face_font(face);
|
||||
let units = font.units_per_em() as f32;
|
||||
let scale = 1000.0 / units;
|
||||
let metrics = Cmr10Metrics::new();
|
||||
let mut entries = Vec::new();
|
||||
for character in (0x20u8..=0x7e).map(char::from) {
|
||||
let glyph = font.glyph(character);
|
||||
let id = glyph.id().0;
|
||||
let width = (glyph
|
||||
.scaled(rusttype::Scale::uniform(units))
|
||||
.h_metrics()
|
||||
.advance_width
|
||||
* scale)
|
||||
.round() as i64;
|
||||
// The layout positions every glyph with CMR10 advances, independent of
|
||||
// the face used for painting. Reporting the CMR10 advance in `/W` keeps
|
||||
// PDF text extraction from inserting spaces between letters.
|
||||
let width = if character.is_ascii() {
|
||||
metrics.width(character) * 1000 / (10 * 65_536)
|
||||
} else {
|
||||
(glyph
|
||||
.scaled(rusttype::Scale::uniform(units))
|
||||
.h_metrics()
|
||||
.advance_width
|
||||
* scale)
|
||||
.round() as i64
|
||||
};
|
||||
entries.push((id, width));
|
||||
}
|
||||
entries.sort_unstable();
|
||||
|
||||
Reference in new issue
Block a user