mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Fix CFF font bug
This commit is contained in:
parent
15ef72cca4
commit
49b8574b8d
@ -127,13 +127,11 @@ impl<'a> PdfExporter<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Write the CID font referencing the font descriptor.
|
// Write the CID font referencing the font descriptor.
|
||||||
self.writer
|
let mut cid = self.writer.cid_font(cid_ref);
|
||||||
.cid_font(cid_ref)
|
cid.subtype(subtype)
|
||||||
.subtype(subtype)
|
|
||||||
.base_font(base_font)
|
.base_font(base_font)
|
||||||
.system_info(system_info)
|
.system_info(system_info)
|
||||||
.font_descriptor(descriptor_ref)
|
.font_descriptor(descriptor_ref)
|
||||||
.cid_to_gid_map_predefined(Name(b"Identity"))
|
|
||||||
.widths()
|
.widths()
|
||||||
.consecutive(0, {
|
.consecutive(0, {
|
||||||
let num_glyphs = ttf.number_of_glyphs();
|
let num_glyphs = ttf.number_of_glyphs();
|
||||||
@ -143,6 +141,12 @@ impl<'a> PdfExporter<'a> {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if subtype == CidFontType::Type2 {
|
||||||
|
cid.cid_to_gid_map_predefined(Name(b"Identity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
cid.finish();
|
||||||
|
|
||||||
let mut flags = FontFlags::empty();
|
let mut flags = FontFlags::empty();
|
||||||
flags.set(FontFlags::SERIF, postscript_name.contains("Serif"));
|
flags.set(FontFlags::SERIF, postscript_name.contains("Serif"));
|
||||||
flags.set(FontFlags::FIXED_PITCH, ttf.is_monospaced());
|
flags.set(FontFlags::FIXED_PITCH, ttf.is_monospaced());
|
||||||
@ -165,8 +169,8 @@ impl<'a> PdfExporter<'a> {
|
|||||||
let stem_v = 10.0 + 0.244 * (f32::from(ttf.weight().to_number()) - 50.0);
|
let stem_v = 10.0 + 0.244 * (f32::from(ttf.weight().to_number()) - 50.0);
|
||||||
|
|
||||||
// Write the font descriptor (contains metrics about the font).
|
// Write the font descriptor (contains metrics about the font).
|
||||||
self.writer
|
let mut font_descriptor = self.writer.font_descriptor(descriptor_ref);
|
||||||
.font_descriptor(descriptor_ref)
|
font_descriptor
|
||||||
.name(base_font)
|
.name(base_font)
|
||||||
.flags(flags)
|
.flags(flags)
|
||||||
.bbox(bbox)
|
.bbox(bbox)
|
||||||
@ -174,8 +178,14 @@ impl<'a> PdfExporter<'a> {
|
|||||||
.ascent(ascender)
|
.ascent(ascender)
|
||||||
.descent(descender)
|
.descent(descender)
|
||||||
.cap_height(cap_height)
|
.cap_height(cap_height)
|
||||||
.stem_v(stem_v)
|
.stem_v(stem_v);
|
||||||
.font_file2(data_ref);
|
|
||||||
|
match subtype {
|
||||||
|
CidFontType::Type0 => font_descriptor.font_file3(data_ref),
|
||||||
|
CidFontType::Type2 => font_descriptor.font_file2(data_ref),
|
||||||
|
};
|
||||||
|
|
||||||
|
font_descriptor.finish();
|
||||||
|
|
||||||
// Compute a reverse mapping from glyphs to unicode.
|
// Compute a reverse mapping from glyphs to unicode.
|
||||||
let cmap = {
|
let cmap = {
|
||||||
@ -210,10 +220,14 @@ impl<'a> PdfExporter<'a> {
|
|||||||
// Subset and write the face's bytes.
|
// Subset and write the face's bytes.
|
||||||
let buffer = face.buffer();
|
let buffer = face.buffer();
|
||||||
let subsetted = subset(buffer, face.index(), glyphs);
|
let subsetted = subset(buffer, face.index(), glyphs);
|
||||||
let data = subsetted.as_deref().unwrap_or(buffer);
|
let data = deflate(subsetted.as_deref().unwrap_or(buffer));
|
||||||
self.writer
|
let mut font_stream = self.writer.stream(data_ref, &data);
|
||||||
.stream(data_ref, &deflate(data))
|
|
||||||
.filter(Filter::FlateDecode);
|
if subtype == CidFontType::Type0 {
|
||||||
|
font_stream.pair(Name(b"Subtype"), Name(b"CIDFontType0C"));
|
||||||
|
}
|
||||||
|
|
||||||
|
font_stream.filter(Filter::FlateDecode).finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user