Add basic ico support (#40822)
Closes https://github.com/zed-industries/zed/discussions/40763 <img width="867" height="1088" alt="Screenshot 2025-10-21 at 23 14 47" src="https://github.com/user-attachments/assets/d691fb2a-afc6-4445-a335-054ef164e0d3" /> Also improves error handling on image open failure: <img width="864" height="1083" alt="Screenshot 2025-10-21 at 23 14 30" src="https://github.com/user-attachments/assets/d5388b61-995f-441b-b375-ad5136d1533b" /> Release Notes: - Added basic ico support, improved unsupported image handling
This commit is contained in:
@@ -1644,6 +1644,8 @@ pub enum ImageFormat {
|
||||
Bmp,
|
||||
/// .tif or .tiff
|
||||
Tiff,
|
||||
/// .ico
|
||||
Ico,
|
||||
}
|
||||
|
||||
impl ImageFormat {
|
||||
@@ -1657,6 +1659,7 @@ impl ImageFormat {
|
||||
ImageFormat::Svg => "image/svg+xml",
|
||||
ImageFormat::Bmp => "image/bmp",
|
||||
ImageFormat::Tiff => "image/tiff",
|
||||
ImageFormat::Ico => "image/ico",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1670,6 +1673,7 @@ impl ImageFormat {
|
||||
"image/svg+xml" => Some(Self::Svg),
|
||||
"image/bmp" => Some(Self::Bmp),
|
||||
"image/tiff" | "image/tif" => Some(Self::Tiff),
|
||||
"image/ico" => Some(Self::Ico),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -1776,6 +1780,7 @@ impl Image {
|
||||
ImageFormat::Webp => frames_for_image(&self.bytes, image::ImageFormat::WebP)?,
|
||||
ImageFormat::Bmp => frames_for_image(&self.bytes, image::ImageFormat::Bmp)?,
|
||||
ImageFormat::Tiff => frames_for_image(&self.bytes, image::ImageFormat::Tiff)?,
|
||||
ImageFormat::Ico => frames_for_image(&self.bytes, image::ImageFormat::Ico)?,
|
||||
ImageFormat::Svg => {
|
||||
let pixmap = svg_renderer.render_pixmap(&self.bytes, SvgSize::ScaleFactor(1.0))?;
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ x11rb::atom_manager! {
|
||||
SVG__MIME: ImageFormat::mime_type(ImageFormat::Svg ).as_bytes(),
|
||||
BMP__MIME: ImageFormat::mime_type(ImageFormat::Bmp ).as_bytes(),
|
||||
TIFF_MIME: ImageFormat::mime_type(ImageFormat::Tiff).as_bytes(),
|
||||
ICO__MIME: ImageFormat::mime_type(ImageFormat::Ico ).as_bytes(),
|
||||
|
||||
// This is just some random name for the property on our window, into which
|
||||
// the clipboard owner writes the data we requested.
|
||||
@@ -1003,6 +1004,7 @@ impl Clipboard {
|
||||
ImageFormat::Svg => self.inner.atoms.SVG__MIME,
|
||||
ImageFormat::Bmp => self.inner.atoms.BMP__MIME,
|
||||
ImageFormat::Tiff => self.inner.atoms.TIFF_MIME,
|
||||
ImageFormat::Ico => self.inner.atoms.ICO__MIME,
|
||||
};
|
||||
let data = vec![ClipboardData {
|
||||
bytes: image.bytes,
|
||||
|
||||
@@ -1607,6 +1607,7 @@ impl From<ImageFormat> for UTType {
|
||||
ImageFormat::Gif => Self::gif(),
|
||||
ImageFormat::Bmp => Self::bmp(),
|
||||
ImageFormat::Svg => Self::svg(),
|
||||
ImageFormat::Ico => Self::ico(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1645,6 +1646,11 @@ impl UTType {
|
||||
Self(unsafe { ns_string("public.svg-image") })
|
||||
}
|
||||
|
||||
pub fn ico() -> Self {
|
||||
// https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/ico
|
||||
Self(unsafe { ns_string("com.microsoft.ico") })
|
||||
}
|
||||
|
||||
pub fn tiff() -> Self {
|
||||
// https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/tiff
|
||||
Self(unsafe { NSPasteboardTypeTIFF }) // This is a rare case where there's a built-in NSPasteboardType
|
||||
|
||||
Reference in New Issue
Block a user