Support XeTeX OpenType vertical shaping and PDF writing mode
This commit is contained in:
1 parent
23ec506fa3
commit
e2af618e65
9 files changed
+481
-44
No files matched your search
@@ -296,6 +296,7 @@ impl SourceMap {
|
||||
}
|
||||
}
|
||||
let mut mapped_pages = Vec::with_capacity(pages.len());
|
||||
let mut vertical_faces = std::collections::BTreeMap::new();
|
||||
for (page_index, page) in pages.iter().enumerate() {
|
||||
if page.sources.keys().any(|i| *i >= page.items.len()) {
|
||||
return Err("source map paint index outside page".into());
|
||||
@@ -417,11 +418,42 @@ impl SourceMap {
|
||||
let left = top_offset.min(bottom_offset).floor() as i64;
|
||||
let right = top_offset.max(bottom_offset).ceil() as i64;
|
||||
let stroke = (font.paint_embolden() / (2. * page.units.bp(1))).ceil() as i64;
|
||||
Some((PaintKind::OpenTypeGlyph { font: font.id.index(), glyph: *glyph }, Bounds {
|
||||
let mut bounds = Bounds {
|
||||
x: x + advance.min(&0) + left - stroke, y: y - ascent - stroke,
|
||||
width: advance.abs() + right - left + 2 * stroke,
|
||||
height: ascent + descent + 2 * stroke,
|
||||
}))
|
||||
};
|
||||
if font.is_vertical() {
|
||||
let face = match vertical_faces.entry(font.id) {
|
||||
std::collections::btree_map::Entry::Vacant(entry) => entry.insert(font.face()?),
|
||||
std::collections::btree_map::Entry::Occupied(entry) => entry.into_mut(),
|
||||
};
|
||||
if let Some(rect) = face.glyph_bounding_box(rustybuzz::ttf_parser::GlyphId(*glyph)) {
|
||||
let [a, b, c, d, e, f] = font.vertical_paint_matrix(face, *glyph, *size as f64);
|
||||
let mut left = f64::INFINITY;
|
||||
let mut right = f64::NEG_INFINITY;
|
||||
let mut top = f64::INFINITY;
|
||||
let mut bottom = f64::NEG_INFINITY;
|
||||
for gx in [rect.x_min, rect.x_max].map(f64::from) {
|
||||
for gy in [rect.y_min, rect.y_max].map(f64::from) {
|
||||
let px = a * gx + c * gy + e;
|
||||
let py = b * gx + d * gy + f;
|
||||
left = left.min(px);
|
||||
right = right.max(px);
|
||||
top = top.min(py);
|
||||
bottom = bottom.max(py);
|
||||
}
|
||||
}
|
||||
let (left, top) = (left.floor() as i64, top.floor() as i64);
|
||||
bounds = Bounds {
|
||||
x: x + left - stroke,
|
||||
y: y + top - stroke,
|
||||
width: right.ceil() as i64 - left + 2 * stroke,
|
||||
height: bottom.ceil() as i64 - top + 2 * stroke,
|
||||
};
|
||||
}
|
||||
}
|
||||
Some((PaintKind::OpenTypeGlyph { font: font.id.index(), glyph: *glyph }, bounds))
|
||||
}
|
||||
DisplayItem::Rule {
|
||||
x,
|
||||
|
||||
Reference in new issue
Block a user