Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for unicode text, for setting clipboard image; ver 0.59 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vadrer
Copy link

@vadrer vadrer commented Oct 20, 2018

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

@Grinnz
Copy link

Grinnz commented Dec 1, 2020

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.

my $str = "\xA0";
utf8::downgrade $str;
Win32::Clipboard::USet($str);
print "not " unless Win32::Clipboard::UGet() eq "\xA0";
print "ok 13\n";
utf8::upgrade $str;
Win32::Clipboard::USet($str);
print "not " unless Win32::Clipboard::UGet() eq "\xA0";
print "ok 14\n";

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 eq test will fail.

EXTEND(SP,1);
if(myhandle = GetClipboardData(CF_UNICODETEXT)) {
/* here we decode UTF16-LE into UTF8, using perl API */
wchar_t *wcmyh = (wchar_t*)myhandle;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think you're correct...
thanks

Comment on lines +484 to +486
for (i=0; i<len; i++) {
e = uvuni_to_utf8(e, wcmyh[i]);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be SvPVbyte() to avoid the Unicode bug.

CloseClipboard();

if ( myhandle ) {
fprintf(stderr,"XS(SetBitmap) good\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +740 to +743
while (str < send) {
*szString++ = (wchar_t)utf8_to_uvchr(str, &ulen);
str += ulen;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also doesn't handle code points beyond the BMP (that need surrogates)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants