Implement native automatic font expansion for paragraphs
This commit is contained in:
1 parent
1dd745afcb
commit
ebbc9e2c17
24 files changed
+632
-34
No files matched your search
@@ -54,9 +54,17 @@ impl NativeFontProgram {
|
||||
pub struct NativeFont {
|
||||
pub id: FontId,
|
||||
pub name: String,
|
||||
pub metrics: TfmMetrics,
|
||||
pub metrics: Arc<TfmMetrics>,
|
||||
pub resource: FontResource,
|
||||
/// Horizontal font adjustment in thousandths. The backing TFM and
|
||||
/// outline program are the original font at the original point size.
|
||||
#[serde(default, skip_serializing_if = "unexpanded")]
|
||||
pub expansion: i32,
|
||||
}
|
||||
pub(crate) fn unexpanded(amount: &i32) -> bool {
|
||||
*amount == 0
|
||||
}
|
||||
|
||||
impl NativeFont {
|
||||
pub fn metrics(&self) -> &TfmMetrics {
|
||||
&self.metrics
|
||||
@@ -64,6 +72,22 @@ impl NativeFont {
|
||||
pub fn size_sp(&self) -> i64 {
|
||||
self.metrics.size_sp()
|
||||
}
|
||||
pub fn advance(&self, slot: u8) -> i64 {
|
||||
let width = self.metrics.width(char::from(slot));
|
||||
if self.expansion == 0 {
|
||||
return width;
|
||||
}
|
||||
crate::pdf_device::magnify(width, 1000 + self.expansion)
|
||||
}
|
||||
pub(crate) fn same_base(&self, other: &Self) -> bool {
|
||||
std::ptr::eq(self, other)
|
||||
|| (self.id == other.id
|
||||
&& self.name == other.name
|
||||
&& (Arc::ptr_eq(&self.metrics, &other.metrics) || self.metrics == other.metrics)
|
||||
&& self.resource.version == other.resource.version
|
||||
&& (Arc::ptr_eq(&self.resource.data, &other.resource.data)
|
||||
|| self.resource.data == other.resource.data))
|
||||
}
|
||||
pub fn has_slot(&self, slot: u8) -> bool {
|
||||
self.metrics.has_slot(slot)
|
||||
}
|
||||
@@ -294,7 +318,7 @@ fn resolve_physical_fonts(
|
||||
let entry = used
|
||||
.entry(font.id)
|
||||
.or_insert_with(|| (font.clone(), BTreeSet::new()));
|
||||
if entry.0.as_ref() != font.as_ref() {
|
||||
if !Arc::ptr_eq(&entry.0, font) && !entry.0.same_base(font) {
|
||||
return Err("native font ids from different jobs cannot share output".into());
|
||||
}
|
||||
entry.1.insert(*slot);
|
||||
|
||||
Reference in new issue
Block a user