From 6ad28910942886749e259f58505ee23fea04f267 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 12 Sep 2009 19:32:04 -0400 Subject: devdraw: update OS X snarf for 32-bit Rune http://codereview.appspot.com/117057 --- src/cmd/devdraw/osx-screen.c | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/cmd/devdraw/osx-screen.c b/src/cmd/devdraw/osx-screen.c index abf276aa..7c686ed9 100644 --- a/src/cmd/devdraw/osx-screen.c +++ b/src/cmd/devdraw/osx-screen.c @@ -732,7 +732,7 @@ struct { char* getsnarf(void) { - char *s, *t; + char *s; CFArrayRef flavors; CFDataRef data; CFIndex nflavor, ndata, j; @@ -741,6 +741,9 @@ getsnarf(void) PasteboardItemID id; PasteboardSyncFlags flags; UInt32 i; + u16int *u; + Fmt fmt; + Rune r; /* fprint(2, "applegetsnarf\n"); */ qlock(&clip.lk); @@ -775,15 +778,26 @@ getsnarf(void) continue; if(PasteboardCopyItemFlavorData(clip.apple, id, type, &data) != noErr) continue; - ndata = CFDataGetLength(data); qunlock(&clip.lk); - s = smprint("%.*S", ndata/2, (Rune*)CFDataGetBytePtr(data)); + ndata = CFDataGetLength(data)/2; + u = (u16int*)CFDataGetBytePtr(data); + fmtstrinit(&fmt); + // decode utf-16. what was apple thinking? + for(i=0; i= 0x10000) { + r -= 0x10000; + *p++ = 0xd800 + (r>>10); + *p++ = 0xdc00 + (r & ((1<<10)-1)); + } else + *p++ = r; + } cfdata = CFDataCreate(kCFAllocatorDefault, - (uchar*)clip.rbuf, runestrlen(clip.rbuf)*2); + (uchar*)u, (p-u)*2); + free(u); if(cfdata == nil){ fprint(2, "apple pasteboard cfdatacreate failed\n"); qunlock(&clip.lk); -- cgit v1.2.3