Write per-page pdfTeX ProcSet from shipped resources
This commit is contained in:
1 parent
de481fd762
commit
1fe0ac9dd5
10 files changed
+162
-15
No files matched your search
@@ -326,6 +326,8 @@ enum Part {
|
||||
Jpeg {
|
||||
size: [u16; 2],
|
||||
precision: u8,
|
||||
#[serde(default)]
|
||||
components: u8,
|
||||
bytes: Vec<u8>,
|
||||
},
|
||||
Png(png::SampledImage),
|
||||
@@ -334,6 +336,12 @@ enum Part {
|
||||
MappedType1(Arc<ImportedType1Use>),
|
||||
}
|
||||
|
||||
pub(crate) enum RasterProcSet {
|
||||
Gray,
|
||||
Color,
|
||||
Indexed,
|
||||
}
|
||||
|
||||
pub(crate) fn real(value: f64) -> String {
|
||||
let body = format!("{value:.15}");
|
||||
body.trim_end_matches('0').trim_end_matches('.').to_owned()
|
||||
@@ -425,6 +433,7 @@ impl PdfImage {
|
||||
parts.push(Part::Jpeg {
|
||||
size: header.size,
|
||||
precision: header.precision,
|
||||
components: header.components,
|
||||
bytes: resource.data,
|
||||
});
|
||||
parts.push(Part::Bytes(b"\nendstream".to_vec()));
|
||||
@@ -516,6 +525,21 @@ impl PdfImage {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn raster_procset(&self) -> Option<RasterProcSet> {
|
||||
self.objects.first()?.iter().find_map(|part| match part {
|
||||
Part::Jpeg { components, bytes, .. } => {
|
||||
let components = if *components == 0 {
|
||||
jpeg::read(bytes).ok()?.components
|
||||
} else {
|
||||
*components
|
||||
};
|
||||
Some(if components == 1 { RasterProcSet::Gray } else { RasterProcSet::Color })
|
||||
}
|
||||
Part::Png(samples) => Some(samples.procset()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn sampled_image(&self) -> Option<&png::SampledImage> {
|
||||
match self.objects.first()?.as_slice() {
|
||||
[Part::Png(samples) | Part::Bmp(samples)] => Some(samples),
|
||||
|
||||
Reference in new issue
Block a user