20#include <winpr/config.h>
24#include <winpr/user.h>
25#include <winpr/image.h>
27#include "../utils/image.h"
31#define TAG WINPR_TAG("clipboard.synthetic")
33static const char mime_html[] =
"text/html";
34static const char mime_ms_html[] =
"HTML Format";
35static const char* mime_bitmap[] = {
"image/bmp",
"image/x-bmp",
"image/x-MS-bmp",
36 "image/x-win-bitmap" };
38static const char mime_webp[] =
"image/webp";
39static const char mime_png[] =
"image/png";
40static const char mime_jpeg[] =
"image/jpeg";
41static const char mime_tiff[] =
"image/tiff";
43static const BYTE enc_base64url[] =
44 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
46WINPR_ATTR_NODISCARD
static inline char* b64_encode(
const BYTE* WINPR_RESTRICT data,
size_t length,
50 const BYTE* WINPR_RESTRICT alphabet = enc_base64url;
53 size_t outLen = (length + 3) * 4 / 3;
57 const size_t alen = outLen + extra + 1ull;
58 BYTE* p = malloc(alen);
77 blocks = length - (length % 3);
78 for (
size_t i = 0; i < blocks; i += 3, q += 3)
80 c = (q[0] << 16) + (q[1] << 8) + q[2];
82 *p++ = alphabet[(c & 0x00FC0000) >> 18];
83 *p++ = alphabet[(c & 0x0003F000) >> 12];
84 *p++ = alphabet[(c & 0x00000FC0) >> 6];
85 *p++ = alphabet[c & 0x0000003F];
95 *p++ = alphabet[(c & 0x00FC0000) >> 18];
96 *p++ = alphabet[(c & 0x0003F000) >> 12];
99 c = (q[0] << 16) + (q[1] << 8);
100 *p++ = alphabet[(c & 0x00FC0000) >> 18];
101 *p++ = alphabet[(c & 0x0003F000) >> 12];
102 *p++ = alphabet[(c & 0x00000FC0) >> 6];
109 *plen = WINPR_ASSERTING_INT_CAST(
size_t, p - ret);
125static void* clipboard_synthesize_cf_text(wClipboard* clipboard, UINT32 formatId,
const void* data,
129 char* pDstData =
nullptr;
131 if (formatId == CF_UNICODETEXT)
133 char* str = ConvertWCharNToUtf8Alloc(data, *pSize /
sizeof(WCHAR), &size);
135 if (!str || (size > UINT32_MAX))
141 pDstData = ConvertLineEndingToCRLF(str, &size);
143 *pSize = (UINT32)size;
146 else if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
147 (formatId == ClipboardGetFormatId(clipboard, mime_text_plain)))
150 pDstData = ConvertLineEndingToCRLF(data, &size);
152 if (!pDstData || (size > *pSize))
158 *pSize = (UINT32)size;
171static void* clipboard_synthesize_cf_oemtext(wClipboard* clipboard, UINT32 formatId,
172 const void* data, UINT32* pSize)
174 return clipboard_synthesize_cf_text(clipboard, formatId, data, pSize);
183static void* clipboard_synthesize_cf_locale(WINPR_ATTR_UNUSED wClipboard* clipboard,
184 WINPR_ATTR_UNUSED UINT32 formatId,
185 WINPR_ATTR_UNUSED
const void* data,
186 WINPR_ATTR_UNUSED UINT32* pSize)
188 UINT32* pDstData =
nullptr;
189 pDstData = (UINT32*)malloc(
sizeof(UINT32));
195 return (
void*)pDstData;
204static void* clipboard_synthesize_cf_unicodetext(wClipboard* clipboard, UINT32 formatId,
205 const void* data, UINT32* pSize)
208 char* crlfStr =
nullptr;
209 WCHAR* pDstData =
nullptr;
211 if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
212 (formatId == ClipboardGetFormatId(clipboard, mime_text_plain)))
215 if (!pSize || (*pSize > INT32_MAX))
219 crlfStr = ConvertLineEndingToCRLF((
const char*)data, &size);
224 pDstData = ConvertUtf8NToWCharAlloc(crlfStr, size, &len);
227 if ((len < 1) || ((len + 1) > UINT32_MAX /
sizeof(WCHAR)))
233 const size_t slen = (len + 1) *
sizeof(WCHAR);
234 *pSize = (UINT32)slen;
237 return (
void*)pDstData;
246static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 formatId,
247 const void* data, UINT32* pSize)
249 if (formatId == CF_UNICODETEXT)
252 char* pDstData = ConvertWCharNToUtf8Alloc(data, *pSize /
sizeof(WCHAR), &size);
257 const size_t rc = ConvertLineEndingToLF(pDstData, size);
258 WINPR_ASSERT(rc <= UINT32_MAX);
262 else if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
263 (formatId == ClipboardGetFormatId(clipboard, mime_text_plain)))
265 const size_t size = *pSize;
266 char* pDstData = calloc(size + 1,
sizeof(
char));
271 CopyMemory(pDstData, data, size);
272 const size_t rc = ConvertLineEndingToLF(pDstData, size);
273 WINPR_ASSERT(rc <= UINT32_MAX);
281static BOOL is_format_bitmap(wClipboard* clipboard, UINT32 formatId)
283 for (
size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++)
285 const char* mime = mime_bitmap[x];
286 const UINT32 altFormatId = ClipboardGetFormatId(clipboard, mime);
287 if (altFormatId == formatId)
300static void* clipboard_synthesize_cf_dib(wClipboard* clipboard, UINT32 formatId,
const void* data,
305 BYTE* pDstData =
nullptr;
308#if defined(WINPR_UTILS_IMAGE_DIBv5)
309 if (formatId == CF_DIBV5)
311 WLog_WARN(TAG,
"[DIB] Unsupported destination format %s",
312 ClipboardGetFormatName(clipboard, formatId));
316 if (is_format_bitmap(clipboard, formatId))
319 wStream sbuffer = WINPR_C_ARRAY_INIT;
320 wStream* s = Stream_StaticConstInit(&sbuffer, data, SrcSize);
321 if (!readBitmapFileHeader(s, &pFileHeader))
325 pDstData = (BYTE*)malloc(DstSize);
331 CopyMemory(pDstData, data, DstSize);
337 WLog_WARN(TAG,
"[DIB] Unsupported destination format %s",
338 ClipboardGetFormatName(clipboard, formatId));
349#if defined(WINPR_UTILS_IMAGE_DIBv5)
350static void* clipboard_synthesize_cf_dibv5(wClipboard* clipboard, UINT32 formatId,
351 WINPR_ATTR_UNUSED
const void* data,
352 WINPR_ATTR_UNUSED UINT32* pSize)
354 if (formatId == CF_DIB)
356 WLog_WARN(TAG,
"[DIBv5] Unsupported destination format %s",
357 ClipboardGetFormatName(clipboard, formatId));
359 else if (is_format_bitmap(clipboard, formatId))
361 WLog_WARN(TAG,
"[DIBv5] Unsupported destination format %s",
362 ClipboardGetFormatName(clipboard, formatId));
366 BOOL handled = FALSE;
367#if defined(WINPR_UTILS_IMAGE_PNG)
369 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_png);
370 if (formatId == altFormatId)
375#if defined(WINPR_UTILS_IMAGE_JPEG)
377 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_jpeg);
378 if (formatId == altFormatId)
385 WLog_WARN(TAG,
"[DIBv5] Unsupported destination format %s",
386 ClipboardGetFormatName(clipboard, formatId));
395 const void* data,
size_t size, UINT32* pSize)
397 WINPR_ASSERT(pInfoHeader);
401 if ((pInfoHeader->biBitCount < 1) || (pInfoHeader->biBitCount > 32))
405 if (DstSize > UINT32_MAX)
408 wStream* s = Stream_New(
nullptr, DstSize);
413 fileHeader.bfType[0] =
'B';
414 fileHeader.bfType[1] =
'M';
415 fileHeader.bfSize = (UINT32)DstSize;
417 if (!writeBitmapFileHeader(s, &fileHeader))
420 if (!Stream_EnsureRemainingCapacity(s, size))
422 Stream_Write(s, data, size);
425 const size_t len = Stream_GetPosition(s);
430 *pSize = (UINT32)DstSize;
433 BYTE* dst = Stream_Buffer(s);
434 Stream_Free(s, FALSE);
439 Stream_Free(s, TRUE);
449static void* clipboard_synthesize_image_bmp(WINPR_ATTR_UNUSED wClipboard* clipboard,
450 UINT32 formatId,
const void* data, UINT32* pSize)
452 UINT32 SrcSize = *pSize;
454 if (formatId == CF_DIB)
459 wStream sbuffer = WINPR_C_ARRAY_INIT;
462 wStream* s = Stream_StaticConstInit(&sbuffer, data, SrcSize);
463 if (!readBitmapInfoHeader(s, &header, &offset))
466 return clipboard_prepend_bmp_header(&header, data, SrcSize, pSize);
468#if defined(WINPR_UTILS_IMAGE_DIBv5)
469 else if (formatId == CF_DIBV5)
471 WLog_WARN(TAG,
"[BMP] Unsupported destination format %s",
472 ClipboardGetFormatName(clipboard, formatId));
477 WLog_WARN(TAG,
"[BMP] Unsupported destination format %s",
478 ClipboardGetFormatName(clipboard, formatId));
484#if defined(WINPR_UTILS_IMAGE_PNG) || defined(WINPR_UTILS_IMAGE_WEBP) || \
485 defined(WINPR_UTILS_IMAGE_JPEG)
486static void* clipboard_synthesize_image_bmp_to_format(wClipboard* clipboard, UINT32 formatId,
487 UINT32 bmpFormat,
const void* data,
490 WINPR_ASSERT(clipboard);
495 void* result =
nullptr;
497 wImage* img = winpr_image_new();
498 void* bmp = clipboard_synthesize_image_bmp(clipboard, formatId, data, pSize);
499 const UINT32 SrcSize = *pSize;
505 if (winpr_image_read_buffer(img, bmp, SrcSize) <= 0)
508 result = winpr_image_write_buffer(img, bmpFormat, &dsize);
511 if (dsize <= UINT32_MAX)
512 *pSize = (UINT32)dsize;
522 winpr_image_free(img, TRUE);
527#if defined(WINPR_UTILS_IMAGE_PNG)
528static void* clipboard_synthesize_image_bmp_to_png(wClipboard* clipboard, UINT32 formatId,
529 const void* data, UINT32* pSize)
531 return clipboard_synthesize_image_bmp_to_format(clipboard, formatId, WINPR_IMAGE_PNG, data,
536#if defined(WINPR_UTILS_IMAGE_PNG) || defined(WINPR_UTILS_IMAGE_WEBP) || \
537 defined(WINPR_UTILS_IMAGE_JPEG)
538static void* clipboard_synthesize_image_format_to_bmp(WINPR_ATTR_UNUSED wClipboard* clipboard,
539 WINPR_ATTR_UNUSED UINT32 srcFormatId,
540 const void* data, UINT32* pSize)
542 WINPR_ASSERT(clipboard);
547 const UINT32 SrcSize = *pSize;
549 wImage* image = winpr_image_new();
553 const int res = winpr_image_read_buffer(image, data, SrcSize);
557 dst = winpr_image_write_buffer(image, WINPR_IMAGE_BITMAP, &size);
564 *pSize = (UINT32)size;
567 winpr_image_free(image, TRUE);
576#if defined(WINPR_UTILS_IMAGE_PNG)
577static void* clipboard_synthesize_image_png_to_bmp(wClipboard* clipboard, UINT32 formatId,
578 const void* data, UINT32* pSize)
580 return clipboard_synthesize_image_format_to_bmp(clipboard, formatId, data, pSize);
584#if defined(WINPR_UTILS_IMAGE_WEBP)
585static void* clipboard_synthesize_image_bmp_to_webp(wClipboard* clipboard, UINT32 formatId,
586 const void* data, UINT32* pSize)
588 return clipboard_synthesize_image_bmp_to_format(clipboard, formatId, WINPR_IMAGE_WEBP, data,
592static void* clipboard_synthesize_image_webp_to_bmp(wClipboard* clipboard, UINT32 formatId,
593 const void* data, UINT32* pSize)
595 return clipboard_synthesize_image_format_to_bmp(clipboard, formatId, data, pSize);
599#if defined(WINPR_UTILS_IMAGE_JPEG)
600static void* clipboard_synthesize_image_bmp_to_jpeg(wClipboard* clipboard, UINT32 formatId,
601 const void* data, UINT32* pSize)
603 return clipboard_synthesize_image_bmp_to_format(clipboard, formatId, WINPR_IMAGE_JPEG, data,
607static void* clipboard_synthesize_image_jpeg_to_bmp(wClipboard* clipboard, UINT32 formatId,
608 const void* data, UINT32* pSize)
610 return clipboard_synthesize_image_format_to_bmp(clipboard, formatId, data, pSize);
620static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 formatId,
621 const void* pData, UINT32* pSize)
630 char* pDstData =
nullptr;
632 pSrcData.cpv =
nullptr;
634 WINPR_ASSERT(clipboard);
637 if (formatId == ClipboardGetFormatId(clipboard, mime_html))
639 const size_t SrcSize = (size_t)*pSize;
640 const size_t DstSize = SrcSize + 200;
641 char* body =
nullptr;
642 char num[20] = WINPR_C_ARRAY_INIT;
645 pSrcData.pv = calloc(1, SrcSize + 1);
648 memcpy(pSrcData.pv, pData, SrcSize);
652 if (SrcSize > INT_MAX)
656 if ((pSrcData.cpb[0] == 0xFE) && (pSrcData.cpb[1] == 0xFF))
658 if (!ByteSwapUnicode(pSrcData.pv, (SrcSize / 2)))
663 if ((pSrcData.cpb[0] == 0xFF) && (pSrcData.cpb[1] == 0xFE))
666 ConvertWCharNToUtf8Alloc(&pSrcData.pv[1], SrcSize /
sizeof(WCHAR),
nullptr);
668 pSrcData.cpc = utfString;
674 pDstData = (
char*)calloc(1, DstSize);
679 (void)sprintf_s(pDstData, DstSize,
681 "StartHTML:0000000000\r\n"
682 "EndHTML:0000000000\r\n"
683 "StartFragment:0000000000\r\n"
684 "EndFragment:0000000000\r\n");
685 body = strstr(pSrcData.cpc,
"<body");
688 body = strstr(pSrcData.cpc,
"<BODY");
691 (void)sprintf_s(num,
sizeof(num),
"%010" PRIuz
"", strnlen(pDstData, DstSize));
692 CopyMemory(&pDstData[23], num, 10);
696 if (!winpr_str_append(
"<HTML><BODY>", pDstData, DstSize,
nullptr))
700 if (!winpr_str_append(
"<!--StartFragment-->", pDstData, DstSize,
nullptr))
704 (void)sprintf_s(num,
sizeof(num),
"%010" PRIuz
"", strnlen(pDstData, SrcSize + 200));
705 CopyMemory(&pDstData[69], num, 10);
707 if (!winpr_str_append(pSrcData.cpc, pDstData, DstSize,
nullptr))
711 (void)sprintf_s(num,
sizeof(num),
"%010" PRIuz
"", strnlen(pDstData, SrcSize + 200));
712 CopyMemory(&pDstData[93], num, 10);
714 if (!winpr_str_append(
"<!--EndFragment-->", pDstData, DstSize,
nullptr))
719 if (!winpr_str_append(
"</BODY></HTML>", pDstData, DstSize,
nullptr))
724 (void)sprintf_s(num,
sizeof(num),
"%010" PRIuz
"", strnlen(pDstData, DstSize));
725 CopyMemory(&pDstData[43], num, 10);
726 *pSize = (UINT32)strnlen(pDstData, DstSize) + 1;
733static char* html_pre_write(
wStream* s,
const char* what)
735 const size_t len = strlen(what);
736 Stream_Write(s, what, len);
737 char* startHTML = Stream_PointerAs(s,
char);
738 for (
size_t x = 0; x < 10; x++)
739 Stream_Write_INT8(s,
'0');
740 Stream_Write(s,
"\r\n", 2);
744static void html_fill_number(
char* pos,
size_t val)
746 char str[11] = WINPR_C_ARRAY_INIT;
747 (void)_snprintf(str,
sizeof(str),
"%010" PRIuz, val);
748 memcpy(pos, str, 10);
751static void* clipboard_wrap_html(
const char* mime,
const char* idata,
size_t ilength,
760 char* b64 = b64_encode((
const BYTE*)idata, ilength, &b64len);
764 const size_t mimelen = strlen(mime);
765 wStream* s = Stream_New(
nullptr, b64len + 225 + mimelen);
772 char* startHTML = html_pre_write(s,
"Version:0.9\r\nStartHTML:");
773 char* endHTML = html_pre_write(s,
"EndHTML:");
774 char* startFragment = html_pre_write(s,
"StartFragment:");
775 char* endFragment = html_pre_write(s,
"EndFragment:");
777 html_fill_number(startHTML, Stream_GetPosition(s));
778 const char html[] =
"<html><!--StartFragment-->";
779 Stream_Write(s, html, strnlen(html,
sizeof(html)));
781 html_fill_number(startFragment, Stream_GetPosition(s));
783 const char body[] =
"<body><img alt=\"FreeRDP clipboard image\" src=\"data:";
784 Stream_Write(s, body, strnlen(body,
sizeof(body)));
786 Stream_Write(s, mime, mimelen);
788 const char base64[] =
";base64,";
789 Stream_Write(s, base64, strnlen(base64,
sizeof(base64)));
790 Stream_Write(s, b64, b64len);
792 const char end[] =
"\"/></body>";
793 Stream_Write(s, end, strnlen(end,
sizeof(end)));
795 html_fill_number(endFragment, Stream_GetPosition(s));
797 const char fragend[] =
"<!--EndFragment--></html>";
798 Stream_Write(s, fragend, strnlen(fragend,
sizeof(fragend)));
799 html_fill_number(endHTML, Stream_GetPosition(s));
801 void* res = Stream_Buffer(s);
802 const size_t pos = Stream_GetPosition(s);
803 *plen = WINPR_ASSERTING_INT_CAST(uint32_t, pos);
804 Stream_Free(s, FALSE);
809static void* clipboard_wrap_format_to_html(uint32_t bmpFormat,
const char* idata,
size_t ilength,
813 wImage* img = winpr_image_new();
817 if (winpr_image_read_buffer(img, (
const BYTE*)idata, ilength) <= 0)
822 void* bmp = winpr_image_write_buffer(img, bmpFormat, &bmpsize);
826 res = clipboard_wrap_html(winpr_image_format_mime(bmpFormat), bmp, bmpsize, plen);
830 winpr_image_free(img, TRUE);
834static void* clipboard_wrap_bmp_to_html(
const char* idata,
size_t ilength, uint32_t* plen)
836 const uint32_t formats[] = { WINPR_IMAGE_WEBP, WINPR_IMAGE_PNG, WINPR_IMAGE_JPEG };
838 for (
size_t x = 0; x < ARRAYSIZE(formats); x++)
840 const uint32_t format = formats[x];
841 if (winpr_image_format_is_supported(format))
843 return clipboard_wrap_format_to_html(format, idata, ilength, plen);
846 const uint32_t bmpFormat = WINPR_IMAGE_BITMAP;
847 return clipboard_wrap_html(winpr_image_format_mime(bmpFormat), idata, ilength, plen);
850static void* clipboard_synthesize_image_html(WINPR_ATTR_UNUSED wClipboard* clipboard,
851 UINT32 formatId,
const void* data, UINT32* pSize)
855 const size_t datalen = *pSize;
860 return clipboard_wrap_html(mime_tiff, data, datalen, pSize);
864 uint32_t bmplen = *pSize;
865 void* bmp = clipboard_synthesize_image_bmp(clipboard, formatId, data, &bmplen);
868 WLog_WARN(TAG,
"failed to convert formatId 0x%08" PRIx32
" [%s]", formatId,
869 ClipboardGetFormatName(clipboard, formatId));
874 void* res = clipboard_wrap_bmp_to_html(bmp, bmplen, pSize);
880 const uint32_t idWebp = ClipboardRegisterFormat(clipboard, mime_webp);
881 const uint32_t idPng = ClipboardRegisterFormat(clipboard, mime_png);
882 const uint32_t idJpeg = ClipboardRegisterFormat(clipboard, mime_jpeg);
883 const uint32_t idTiff = ClipboardRegisterFormat(clipboard, mime_tiff);
884 if (formatId == idWebp)
886 return clipboard_wrap_html(mime_webp, data, datalen, pSize);
888 else if (formatId == idPng)
890 return clipboard_wrap_html(mime_png, data, datalen, pSize);
892 else if (formatId == idJpeg)
894 return clipboard_wrap_html(mime_jpeg, data, datalen, pSize);
896 else if (formatId == idTiff)
898 return clipboard_wrap_html(mime_tiff, data, datalen, pSize);
902 for (
size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++)
904 const char* mime = mime_bitmap[x];
905 const uint32_t
id = ClipboardRegisterFormat(clipboard, mime);
908 return clipboard_wrap_bmp_to_html(data, datalen, pSize);
912 WLog_WARN(TAG,
"Unsupported image format id 0x%08" PRIx32
" [%s]", formatId,
913 ClipboardGetFormatName(clipboard, formatId));
926static void* clipboard_synthesize_text_html(wClipboard* clipboard, UINT32 formatId,
927 const void* data, UINT32* pSize)
929 char* pDstData =
nullptr;
931 if (formatId == ClipboardGetFormatId(clipboard, mime_ms_html))
933 const char* str = (
const char*)data;
934 const size_t SrcSize = *pSize;
935 const char* begStr = strstr(str,
"StartHTML:");
936 const char* endStr = strstr(str,
"EndHTML:");
938 if (!begStr || !endStr)
942 const long beg = strtol(&begStr[10],
nullptr, 10);
947 const long end = strtol(&endStr[8],
nullptr, 10);
949 if ((beg < 0) || (end < 0) || ((
size_t)beg > SrcSize) || ((
size_t)end > SrcSize) ||
950 (beg >= end) || (errno != 0))
953 const size_t DstSize = (size_t)(end - beg);
954 pDstData = calloc(DstSize + 1,
sizeof(
char));
959 CopyMemory(pDstData, &str[beg], DstSize);
960 const size_t rc = ConvertLineEndingToLF(pDstData, DstSize);
961 WINPR_ASSERT(rc <= UINT32_MAX);
968BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
974 if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_OEMTEXT,
975 clipboard_synthesize_cf_oemtext))
977 if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_UNICODETEXT,
978 clipboard_synthesize_cf_unicodetext))
980 if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_LOCALE,
981 clipboard_synthesize_cf_locale))
984 UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
985 if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, altFormatId,
986 clipboard_synthesize_utf8_string))
993 if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_TEXT,
994 clipboard_synthesize_cf_text))
996 if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_UNICODETEXT,
997 clipboard_synthesize_cf_unicodetext))
999 if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_LOCALE,
1000 clipboard_synthesize_cf_locale))
1002 UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
1003 if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, altFormatId,
1004 clipboard_synthesize_utf8_string))
1011 if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_TEXT,
1012 clipboard_synthesize_cf_text))
1014 if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_OEMTEXT,
1015 clipboard_synthesize_cf_oemtext))
1017 if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_LOCALE,
1018 clipboard_synthesize_cf_locale))
1020 UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
1021 if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, altFormatId,
1022 clipboard_synthesize_utf8_string))
1029 UINT32 formatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
1033 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
1034 clipboard_synthesize_cf_text))
1036 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
1037 clipboard_synthesize_cf_oemtext))
1039 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
1040 clipboard_synthesize_cf_unicodetext))
1042 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
1043 clipboard_synthesize_cf_locale))
1051 UINT32 formatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
1055 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
1056 clipboard_synthesize_cf_text))
1058 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
1059 clipboard_synthesize_cf_oemtext))
1061 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
1062 clipboard_synthesize_cf_unicodetext))
1064 if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
1065 clipboard_synthesize_cf_locale))
1070 const uint32_t htmlFormat = ClipboardRegisterFormat(clipboard, mime_ms_html);
1071 const uint32_t tiffFormat = ClipboardRegisterFormat(clipboard, mime_tiff);
1076 if (!ClipboardRegisterSynthesizer(clipboard, CF_TIFF, htmlFormat,
1077 clipboard_synthesize_image_html))
1079 if (!ClipboardRegisterSynthesizer(clipboard, tiffFormat, htmlFormat,
1080 clipboard_synthesize_image_html))
1087#if defined(WINPR_UTILS_IMAGE_DIBv5)
1088 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, CF_DIBV5,
1089 clipboard_synthesize_cf_dibv5))
1092 for (
size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++)
1094 const char* mime = mime_bitmap[x];
1095 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime);
1096 if (altFormatId == 0)
1098 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
1099 clipboard_synthesize_image_bmp))
1102 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, htmlFormat,
1103 clipboard_synthesize_image_html))
1110#if defined(WINPR_UTILS_IMAGE_DIBv5)
1112 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, CF_DIB, clipboard_synthesize_cf_dib))
1115 for (
size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++)
1117 const char* mime = mime_bitmap[x];
1118 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime);
1119 if (altFormatId == 0)
1121 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
1122 clipboard_synthesize_image_bmp))
1125 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, htmlFormat,
1126 clipboard_synthesize_image_html))
1134 for (
size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++)
1136 const char* mime = mime_bitmap[x];
1137 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime);
1138 if (altFormatId == 0)
1140 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB,
1141 clipboard_synthesize_cf_dib))
1143#if defined(WINPR_UTILS_IMAGE_DIBv5)
1144 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
1145 clipboard_synthesize_cf_dibv5))
1148 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
1149 clipboard_synthesize_image_html))
1156#if defined(WINPR_UTILS_IMAGE_PNG)
1158 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_png);
1159 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
1160 clipboard_synthesize_image_bmp_to_png))
1162 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB,
1163 clipboard_synthesize_image_png_to_bmp))
1165 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
1166 clipboard_synthesize_image_html))
1168#if defined(WINPR_UTILS_IMAGE_DIBv5)
1169 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
1170 clipboard_synthesize_image_bmp_to_png))
1172 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
1173 clipboard_synthesize_image_png_to_bmp))
1182#if defined(WINPR_UTILS_IMAGE_WEBP)
1184 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_webp);
1185 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
1186 clipboard_synthesize_image_bmp_to_webp))
1188 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB,
1189 clipboard_synthesize_image_webp_to_bmp))
1191 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
1192 clipboard_synthesize_image_html))
1194#if defined(WINPR_UTILS_IMAGE_DIBv5)
1195 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
1196 clipboard_synthesize_image_bmp_to_webp))
1198 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
1199 clipboard_synthesize_image_webp_to_bmp))
1208#if defined(WINPR_UTILS_IMAGE_JPEG)
1210 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_jpeg);
1211 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
1212 clipboard_synthesize_image_bmp_to_jpeg))
1214 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB,
1215 clipboard_synthesize_image_jpeg_to_bmp))
1217 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
1218 clipboard_synthesize_image_html))
1220#if defined(WINPR_UTILS_IMAGE_DIBv5)
1221 if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
1222 clipboard_synthesize_image_jpeg_to_bmp))
1224 if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
1225 clipboard_synthesize_image_bmp_to_jpeg))
1235 UINT32 formatId = ClipboardRegisterFormat(clipboard, mime_ms_html);
1239 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_html);
1240 if (!ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
1241 clipboard_synthesize_text_html))
1250 UINT32 formatId = ClipboardRegisterFormat(clipboard, mime_html);
1254 const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_ms_html);
1255 if (!ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
1256 clipboard_synthesize_html_format))