Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit b3ded13

Browse files
committed
[[ Bug 17216 ]] Reinstate TIFF processing in Mac clipboard
Some applications on Mac only present TIFF as the image format on the clipboard (Preview included). As the engine (as a whole) does not understand TIFF data, this patch makes TIFF data on the clipboard masquerade as PNG data allowing it to be used in a loss-less way (relative to the original TIFF encoding). The TIFF data will still be listed in the rawClipboardData, but in the fullClipboardData it will come through as image and png.
1 parent cc5a1e4 commit b3ded13

File tree

6 files changed

+30
-3
lines changed

6 files changed

+30
-3
lines changed

docs/notes/bugfix-17216.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Allow pasting images from some applications on Mac

engine/src/clipboard.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,15 @@ bool MCClipboard::HasPNG() const
656656
MCAutoRefcounted<const MCRawClipboardItem> t_item = GetItem();
657657
if (t_item == NULL)
658658
return false;
659-
659+
660+
#ifdef __MAC__
661+
// Many Mac apps (like Preview) present things as TIFF on the clipboard. Since
662+
// the engine doesn't currently understand TIFF generally we make TIFF data
663+
// masquerade as PNG.
664+
if (t_item -> HasRepresentation(m_clipboard->GetKnownTypeString(kMCRawClipboardKnownTypeTIFF)))
665+
return true;
666+
#endif
667+
660668
return t_item->HasRepresentation(m_clipboard->GetKnownTypeString(kMCRawClipboardKnownTypePNG));
661669
}
662670

@@ -932,7 +940,22 @@ bool MCClipboard::CopyAsHTML(MCDataRef& r_html_data) const
932940

933941
bool MCClipboard::CopyAsPNG(MCDataRef& r_png) const
934942
{
935-
return CopyAsData(kMCRawClipboardKnownTypePNG, r_png);
943+
if (CopyAsData(kMCRawClipboardKnownTypePNG, r_png))
944+
return true;
945+
946+
#ifdef __MAC__
947+
MCAutoDataRef t_tiff_data;
948+
if (!CopyAsData(kMCRawClipboardKnownTypeTIFF, &t_tiff_data))
949+
return false;
950+
951+
extern bool MCMacPasteboardConvertTIFFToPNG(MCDataRef p_in_data, MCDataRef& r_out_data);
952+
if (!MCMacPasteboardConvertTIFFToPNG(*t_tiff_data, r_png))
953+
return false;
954+
955+
return true;
956+
#else
957+
return false;
958+
#endif
936959
}
937960

938961
bool MCClipboard::CopyAsGIF(MCDataRef& r_gif) const

engine/src/lnx-clipboard.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const char * const MCLinuxRawClipboard::s_formats[kMCRawClipboardKnownTypeLast+1
4747
"image/png", // PNG image
4848
"image/gif", // GIF image
4949
"image/jpeg", // JPEG image
50+
"image/tiff", // TIFF image
5051
NULL, // Windows metafile
5152
NULL, // Windows enhanced metafile
5253
NULL, // Windows bitmap

engine/src/mac-clipboard.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"public.png",
3737
"com.compuserve.gif",
3838
"public.jpeg",
39+
"public.tiff",
3940
NULL,
4041
NULL,
4142
NULL, // "com.microsoft.bmp" but the Mac engine doesn't support this format

engine/src/raw-clipboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum MCRawClipboardKnownType
4848
kMCRawClipboardKnownTypePNG, // PNG image
4949
kMCRawClipboardKnownTypeGIF, // GIF image
5050
kMCRawClipboardKnownTypeJPEG, // JPEG image
51+
kMCRawClipboardKnownTypeTIFF, // TIFF image
5152
kMCRawClipboardKnownTypeWinMF, // Windows Metafile image
5253
kMCRawClipboardKnownTypeWinEMF, // Windows Enhanced Metafile image
5354
kMCRawClipboardKnownTypeWinDIB, // Windows BMP image

engine/src/w32-clipboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ MCWin32RawClipboardCommon::format_mapping MCWin32RawClipboardCommon::s_formats[]
3636
{ 0, "PNG" }, // PNG image
3737
{ 0, "GIF" }, // GIF image
3838
{ 0, "JFIF" }, // JPEG image
39+
{ 6, "CF_TIFF" }, // TIFF image
3940
{ CF_METAFILEPICT, "CF_METAFILEPICT" }, // Windows Metafile image
4041
{ CF_ENHMETAFILE, "CF_ENHMETAFILE" }, // Windows Enhanced Metafile image
4142
{ CF_DIB, "CF_DIB" }, // Windows bitmap image
@@ -66,7 +67,6 @@ MCWin32RawClipboardCommon::format_mapping MCWin32RawClipboardCommon::s_formats[]
6667
{ 10, "CF_PENDATA" }, // Windows 3.1 (!) pen input data
6768
{ 11, "CF_RIFF" }, // RIFF-encoded audio
6869
{ 4, "CF_SYLK" }, // Microsoft Symbolic Link format
69-
{ 6, "CF_TIFF" }, // TIFF image
7070
{ 12, "CF_WAVE" }, // PCM audio
7171
};
7272

0 commit comments

Comments
 (0)