Bind pdfTeX image color spaces to written PDF objects

This commit is contained in:
gloamxun committed 2026-11-26 18:16:31 +08:00
1 parent e10e0cce53
commit 520e8eede2
8 files changed
+147 -32

No files matched your search

+8 -4
View File
@@ -106,6 +106,7 @@ pub(super) fn decode(bytes: &[u8]) -> Result<(SampledImage, Option<PixelDimensio
pub(super) fn read(
resource: LoadedResource,
fallback_resolution: i32,
color_space: Option<i32>,
) -> Result<(PdfImage, Option<&'static str>), String> {
let (image, physical) = decode(&resource.data).map_err(|error| {
format!(
@@ -140,6 +141,7 @@ pub(super) fn read(
natural,
extent: [1.0_f64.to_bits(); 2],
objects: vec![vec![Part::Png(image)]],
color_space,
imported_fonts: Vec::new(),
},
warning,
@@ -180,13 +182,15 @@ impl SampledImage {
attributes: &[u8],
compression: u8,
pdf_version: (i32, i32),
color_space: Option<i64>,
) -> usize {
let id = pdf.len() + 1;
let [width, height] = self.size;
let mut color = match &self.color {
ColorSpace::Gray => "/DeviceGray".to_owned(),
ColorSpace::Rgb => "/DeviceRGB".to_owned(),
ColorSpace::Indexed(table) => {
let mut color = match (color_space, &self.color) {
(Some(id), _) => format!("{id} 0 R"),
(None, ColorSpace::Gray) => "/DeviceGray".to_owned(),
(None, ColorSpace::Rgb) => "/DeviceRGB".to_owned(),
(None, ColorSpace::Indexed(table)) => {
let mut color = format!("[/Indexed /DeviceRGB {} <", table.len() / 3 - 1);
for byte in table {
write!(color, "{byte:02X}").expect("writing to a string");