mirror of
https://github.com/typst/typst
synced 2025-06-08 13:16:24 +08:00
Fix missing rotation
This commit is contained in:
parent
399bcbb23d
commit
a51c38a6ce
@ -21,6 +21,7 @@ struct Repr {
|
|||||||
data: Bytes,
|
data: Bytes,
|
||||||
format: RasterFormat,
|
format: RasterFormat,
|
||||||
dynamic: Arc<image::DynamicImage>,
|
dynamic: Arc<image::DynamicImage>,
|
||||||
|
is_rotated: bool,
|
||||||
icc: Option<Vec<u8>>,
|
icc: Option<Vec<u8>>,
|
||||||
dpi: Option<f64>,
|
dpi: Option<f64>,
|
||||||
}
|
}
|
||||||
@ -51,15 +52,17 @@ impl RasterImage {
|
|||||||
.read_from_container(&mut std::io::Cursor::new(&data))
|
.read_from_container(&mut std::io::Cursor::new(&data))
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
|
let mut is_rotated = false;
|
||||||
// Apply rotation from EXIF metadata.
|
// Apply rotation from EXIF metadata.
|
||||||
if let Some(rotation) = exif.as_ref().and_then(exif_rotation) {
|
if let Some(rotation) = exif.as_ref().and_then(exif_rotation) {
|
||||||
apply_rotation(&mut dynamic, rotation);
|
apply_rotation(&mut dynamic, rotation);
|
||||||
|
is_rotated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract pixel density.
|
// Extract pixel density.
|
||||||
let dpi = determine_dpi(&data, exif.as_ref());
|
let dpi = determine_dpi(&data, exif.as_ref());
|
||||||
|
|
||||||
Ok(Self(Arc::new(Repr { data, format, dynamic: Arc::new(dynamic), icc, dpi })))
|
Ok(Self(Arc::new(Repr { data, format, is_rotated, dynamic: Arc::new(dynamic), icc, dpi })))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The raw image data.
|
/// The raw image data.
|
||||||
@ -77,6 +80,11 @@ impl RasterImage {
|
|||||||
self.dynamic().width()
|
self.dynamic().width()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the image has been rotated due to EXIF metadata.
|
||||||
|
pub fn is_rotated(&self) -> bool {
|
||||||
|
self.0.is_rotated
|
||||||
|
}
|
||||||
|
|
||||||
/// The image's pixel height.
|
/// The image's pixel height.
|
||||||
pub fn height(&self) -> u32 {
|
pub fn height(&self) -> u32 {
|
||||||
self.dynamic().height()
|
self.dynamic().height()
|
||||||
|
@ -109,7 +109,12 @@ impl CustomImage for PdfImage {
|
|||||||
pub(crate) fn raster(raster: RasterImage) -> Option<krilla::image::Image> {
|
pub(crate) fn raster(raster: RasterImage) -> Option<krilla::image::Image> {
|
||||||
match raster.format() {
|
match raster.format() {
|
||||||
RasterFormat::Jpg => {
|
RasterFormat::Jpg => {
|
||||||
krilla::image::Image::from_jpeg(Arc::new(raster.data().clone()))
|
if !raster.is_rotated() {
|
||||||
|
krilla::image::Image::from_jpeg(Arc::new(raster.data().clone()))
|
||||||
|
} else {
|
||||||
|
// Can't embed original JPEG data if it needed to be rotated.
|
||||||
|
krilla::image::Image::from_custom(PdfImage::new(raster))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => krilla::image::Image::from_custom(PdfImage::new(raster)),
|
_ => krilla::image::Image::from_custom(PdfImage::new(raster)),
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,6 @@ fn convert_gradient(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let angle = rotation;
|
let angle = rotation;
|
||||||
println!("angle: {:?}", angle);
|
|
||||||
|
|
||||||
let mut stops: Vec<krilla::paint::Stop<krilla::color::rgb::Color>> = vec![];
|
let mut stops: Vec<krilla::paint::Stop<krilla::color::rgb::Color>> = vec![];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user