108 // 2 bytes per source byte max 109 out = buf; outSize = bufSize; 110 /* linux iconv wants char** source and solaris wants const char**... 111 cast to void* */ 112 rc = iconv(cd, (void*)&in, &inSize, &out, &outSize); 113 iconv_close(cd); 114 115 if (rc == (size_t)-1) { 116 free(buf); 117 buf = NULL; 118 } else { 119 if (size) { 120 *size = (bufSize-outSize)/2; /* bytes to wchars */ 121 } 122 } 123 done: 124 setlocale(LC_ALL, old_locale); 125 return buf; 126 } 127 128 129 void 130 SplashInitPlatform(Splash * splash) { 131 pthread_mutex_init(&splash->lock, NULL); 132 133 splash->maskRequired = 0; 134 135 136 //TODO: the following is too much of a hack but should work in 90% cases. 137 // besides we don't use device-dependant drawing, so probably 138 // that's very fine indeed 139 splash->byteAlignment = 1; 140 initFormat(&splash->screenFormat, 0xff << 8, 141 0xff << 16, 0xff << 24, 0xff << 0); 142 splash->screenFormat.byteOrder = 1 ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST; 143 splash->screenFormat.depthBytes = 4; 144 145 // If this property is present we are running SWT and should not start a runLoop 146 // Can't check if running SWT in webstart, so splash screen in webstart SWT 147 // applications is not supported 208 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 209 // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ? 210 NSBitmapImageRep * rep = [[NSBitmapImageRep alloc] 211 initWithBitmapDataPlanes: (unsigned char**)&splash->screenData 212 pixelsWide: splash->width 213 pixelsHigh: splash->height 214 bitsPerSample: 8 215 samplesPerPixel: 4 216 hasAlpha: YES 217 isPlanar: NO 218 colorSpaceName: NSDeviceRGBColorSpace 219 bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat 220 bytesPerRow: splash->width * 4 221 bitsPerPixel: 32]; 222 223 NSImage * image = [[NSImage alloc] 224 initWithSize: NSMakeSize(splash->width, splash->height)]; 225 [image setBackgroundColor: [NSColor clearColor]]; 226 227 [image addRepresentation: rep]; 228 229 NSImageView * view = [[NSImageView alloc] init]; 230 231 [view setImage: image]; 232 [view setEditable: NO]; 233 //NOTE: we don't set a 'wait cursor' for the view because: 234 // 1. The Cocoa GUI guidelines suggest to avoid it, and use a progress 235 // bar instead. 236 // 2. There simply isn't an instance of NSCursor that represent 237 // the 'wait cursor'. So that is undoable. 238 239 //TODO: only the first image in an animated gif preserves transparency. 240 // Loos like the splash->screenData contains inappropriate data 241 // for all but the first frame. 242 243 [image release]; 244 [rep release]; 245 246 [splash->window setContentView: view]; 247 [splash->window orderFrontRegardless]; | 108 // 2 bytes per source byte max 109 out = buf; outSize = bufSize; 110 /* linux iconv wants char** source and solaris wants const char**... 111 cast to void* */ 112 rc = iconv(cd, (void*)&in, &inSize, &out, &outSize); 113 iconv_close(cd); 114 115 if (rc == (size_t)-1) { 116 free(buf); 117 buf = NULL; 118 } else { 119 if (size) { 120 *size = (bufSize-outSize)/2; /* bytes to wchars */ 121 } 122 } 123 done: 124 setlocale(LC_ALL, old_locale); 125 return buf; 126 } 127 128 char* SplashGetScaledImageName(const char* jar, const char* file, 129 float *scaleFactor) { 130 NSAutoreleasePool *pool = [NSAutoreleasePool new]; 131 *scaleFactor = 1; 132 char* scaledFile = nil; 133 float screenScaleFactor = [SplashNSScreen() backingScaleFactor]; 134 135 if (screenScaleFactor > 1) { 136 NSString *fileName = [NSString stringWithUTF8String: file]; 137 NSUInteger length = [fileName length]; 138 NSRange range = [fileName rangeOfString: @"." 139 options:NSBackwardsSearch]; 140 NSUInteger dotIndex = range.location; 141 NSString *fileName2x = nil; 142 143 if (dotIndex == NSNotFound) { 144 fileName2x = [fileName stringByAppendingString: @"@2x"]; 145 } else { 146 fileName2x = [fileName substringToIndex: dotIndex]; 147 fileName2x = [fileName2x stringByAppendingString: @"@2x"]; 148 fileName2x = [fileName2x stringByAppendingString: 149 [fileName substringFromIndex: dotIndex]]; 150 } 151 152 if ((fileName2x != nil) && (jar || [[NSFileManager defaultManager] 153 fileExistsAtPath: fileName2x])){ 154 *scaleFactor = 2; 155 scaledFile = strdup([fileName2x UTF8String]); 156 } 157 } 158 [pool drain]; 159 return scaledFile; 160 } 161 162 void 163 SplashInitPlatform(Splash * splash) { 164 pthread_mutex_init(&splash->lock, NULL); 165 166 splash->maskRequired = 0; 167 168 169 //TODO: the following is too much of a hack but should work in 90% cases. 170 // besides we don't use device-dependant drawing, so probably 171 // that's very fine indeed 172 splash->byteAlignment = 1; 173 initFormat(&splash->screenFormat, 0xff << 8, 174 0xff << 16, 0xff << 24, 0xff << 0); 175 splash->screenFormat.byteOrder = 1 ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST; 176 splash->screenFormat.depthBytes = 4; 177 178 // If this property is present we are running SWT and should not start a runLoop 179 // Can't check if running SWT in webstart, so splash screen in webstart SWT 180 // applications is not supported 241 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 242 // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ? 243 NSBitmapImageRep * rep = [[NSBitmapImageRep alloc] 244 initWithBitmapDataPlanes: (unsigned char**)&splash->screenData 245 pixelsWide: splash->width 246 pixelsHigh: splash->height 247 bitsPerSample: 8 248 samplesPerPixel: 4 249 hasAlpha: YES 250 isPlanar: NO 251 colorSpaceName: NSDeviceRGBColorSpace 252 bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat 253 bytesPerRow: splash->width * 4 254 bitsPerPixel: 32]; 255 256 NSImage * image = [[NSImage alloc] 257 initWithSize: NSMakeSize(splash->width, splash->height)]; 258 [image setBackgroundColor: [NSColor clearColor]]; 259 260 [image addRepresentation: rep]; 261 float scaleFactor = splash->scaleFactor; 262 if (0 < scaleFactor && scaleFactor != 1) { 263 [image setScalesWhenResized:YES]; 264 NSSize size = [image size]; 265 size.width /= scaleFactor; 266 size.height /= scaleFactor; 267 [image setSize: size]; 268 } 269 270 NSImageView * view = [[NSImageView alloc] init]; 271 272 [view setImage: image]; 273 [view setEditable: NO]; 274 //NOTE: we don't set a 'wait cursor' for the view because: 275 // 1. The Cocoa GUI guidelines suggest to avoid it, and use a progress 276 // bar instead. 277 // 2. There simply isn't an instance of NSCursor that represent 278 // the 'wait cursor'. So that is undoable. 279 280 //TODO: only the first image in an animated gif preserves transparency. 281 // Loos like the splash->screenData contains inappropriate data 282 // for all but the first frame. 283 284 [image release]; 285 [rep release]; 286 287 [splash->window setContentView: view]; 288 [splash->window orderFrontRegardless]; |