support for unicode text, for setting clipboard image; ver 0.59#5
support for unicode text, for setting clipboard image; ver 0.59#5vadrer wants to merge 1 commit intojandubois:masterfrom
Conversation
|
I suspect this may suffer from the Unicode bug in its implementation. See https://perldoc.perl.org/perlguts#Unicode-Support for more information - unfortunately I do not have the expertise to advise on fixes if this is the case. The following tests can be added to ensure a non-buggy implementation. The same test can be applied to SetBitmap. In the USet case this string should be interpreted as U+00A0 regardless if it is upgraded, and in the SetBitmap case it should be interpreted as the byte 0xA0 in either case. Also, the is_utf8 test is unnecessary; the UTF8 flag of the returned string is not relevant as long as it correctly indicates the internal storage that was used to return the string - if it doesn't, the |
| EXTEND(SP,1); | ||
| if(myhandle = GetClipboardData(CF_UNICODETEXT)) { | ||
| /* here we decode UTF16-LE into UTF8, using perl API */ | ||
| wchar_t *wcmyh = (wchar_t*)myhandle; |
There was a problem hiding this comment.
Shouldn't this be a GlobalLock(), like in the example at https://docs.microsoft.com/en-us/windows/win32/dataxchg/using-the-clipboard#pasting-information-from-the-clipboard ?
There was a problem hiding this comment.
yes, I think you're correct...
thanks
| for (i=0; i<len; i++) { | ||
| e = uvuni_to_utf8(e, wcmyh[i]); | ||
| } |
There was a problem hiding this comment.
This doesn't handle surrogate pairs at all and should be using WideCharToMultiByte() with CodePage set to CP_UTF8 to translate it. Unfortunately perl's builtin functions to do this conversion are not API.
| HANDLE myhandle; | ||
| HGLOBAL hGlobal; | ||
| STRLEN leng; | ||
| U8 *str = (U8*) SvPV(dib, leng); |
There was a problem hiding this comment.
This should be SvPVbyte() to avoid the Unicode bug.
| CloseClipboard(); | ||
|
|
||
| if ( myhandle ) { | ||
| fprintf(stderr,"XS(SetBitmap) good\n"); |
There was a problem hiding this comment.
left from debugging? another a few lines further down
| wchar_t *szString = (wchar_t *) GlobalLock(hGlobal); | ||
| U8 * const send = str + leng; | ||
| /* we have raw data */ | ||
| while (str < send) { |
There was a problem hiding this comment.
This expansion from bytes to wchar_t looks wrong, Standard Clipboard Formats claims it's a
A memory object containing a BITMAPINFO structure followed by the bitmap bits.
and doesn't mention converting it like this.
| while (str < send) { | ||
| *szString++ = (wchar_t)utf8_to_uvchr(str, &ulen); | ||
| str += ulen; | ||
| } |
There was a problem hiding this comment.
This also doesn't handle code points beyond the BMP (that need surrogates)
some new functionality; also there are plans to make more tests; and then to work on FAIL on http://matrix.cpantesters.org/?dist=Win32-Clipboard+0.58