Read mapped Type 1 fonts from PFA programs
This commit is contained in:
1 parent
868814288c
commit
60d67bbb7b
7 files changed
+211
-18
No files matched your search
@@ -257,7 +257,7 @@ fn verify_resource(
|
||||
}
|
||||
|
||||
const MAX_TYPE1_PROGRAMS: usize = 16;
|
||||
const MAX_CACHED_PFB_BYTES: usize = 256 * 1024;
|
||||
const MAX_CACHED_TYPE1_BYTES: usize = 256 * 1024;
|
||||
|
||||
/// Decoded Type 1 programs shared across revisions in one compiler.
|
||||
#[derive(Default)]
|
||||
@@ -274,13 +274,9 @@ struct DecodedType1 {
|
||||
}
|
||||
|
||||
impl DecodedType1 {
|
||||
fn from_pfb(resource: &LoadedResource, transform: Type1Transform) -> Result<Self, String> {
|
||||
let mut program = Type1Font::from_pfb(&resource.data).ok_or_else(|| {
|
||||
format!(
|
||||
"invalid Type1 PFB program: {}",
|
||||
resource.version.path.display()
|
||||
)
|
||||
})?;
|
||||
fn from_resource(resource: &LoadedResource, transform: Type1Transform) -> Result<Self, String> {
|
||||
let mut program = Type1Font::from_file(&resource.data)
|
||||
.map_err(|error| format!("{error}: {}", resource.version.path.display()))?;
|
||||
program.apply_map_transform(transform)?;
|
||||
let outlines = Type1Outlines::parse(&program)?;
|
||||
let (bbox, stem_v) = if transform.is_identity() {
|
||||
@@ -303,8 +299,8 @@ impl NativeFontCache {
|
||||
// The caller reads the actual resource and verifies its bytes on this
|
||||
// revision before asking for the decoded representation.
|
||||
fn type1(&self, resource: &LoadedResource, transform: Type1Transform) -> Result<Arc<DecodedType1>, String> {
|
||||
if resource.data.len() > MAX_CACHED_PFB_BYTES {
|
||||
return DecodedType1::from_pfb(resource, transform).map(Arc::new);
|
||||
if resource.data.len() > MAX_CACHED_TYPE1_BYTES {
|
||||
return DecodedType1::from_resource(resource, transform).map(Arc::new);
|
||||
}
|
||||
let mut entries = self.type1.lock().expect("native Type 1 cache poisoned");
|
||||
if let Some(index) = entries
|
||||
@@ -316,7 +312,7 @@ impl NativeFontCache {
|
||||
entries.push_back(entry);
|
||||
return Ok(decoded);
|
||||
}
|
||||
let decoded = Arc::new(DecodedType1::from_pfb(resource, transform)?);
|
||||
let decoded = Arc::new(DecodedType1::from_resource(resource, transform)?);
|
||||
if entries.len() == MAX_TYPE1_PROGRAMS {
|
||||
entries.pop_front();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user