// w->cgc = [[[view window] graphicsContext] graphicsPort];
w->cgc = 0;
w->window.view = view;
+ CFRetain (w->window.view); // needed for garbage collection?
w->window.background = BlackPixel(0,0);
d->main_window = w;
if (d->type == PIXMAP) {
depth = d->pixmap.depth;
+ alpha_first_p = 1; // we created it with kCGImageAlphaNoneSkipFirst.
ibpp = CGBitmapContextGetBitsPerPixel (d->cgc);
ibpl = CGBitmapContextGetBytesPerRow (d->cgc);
data = CGBitmapContextGetData (d->cgc);
void
-jwxyz_draw_NSImage (Display *dpy, Drawable d, void *nsimg_arg,
- XRectangle *geom_ret, int exif_rotation)
+jwxyz_draw_NSImage_or_CGImage (Display *dpy, Drawable d,
+ Bool nsimg_p, void *img_arg,
+ XRectangle *geom_ret, int exif_rotation)
{
- NSImage *nsimg = (NSImage *) nsimg_arg;
+ CGImageRef cgi;
+ CGImageSourceRef cgsrc;
+ NSSize imgr;
+
+ if (nsimg_p) {
+
+ NSImage *nsimg = (NSImage *) img_arg;
+ imgr = [nsimg size];
+
+ // convert the NSImage to a CGImage via the toll-free-bridging
+ // of NSData and CFData...
+ //
+ NSData *nsdata = [NSBitmapImageRep
+ TIFFRepresentationOfImageRepsInArray:
+ [nsimg representations]];
+ CFDataRef cfdata = (CFDataRef) nsdata;
+ cgsrc = CGImageSourceCreateWithData (cfdata, NULL);
+ cgi = CGImageSourceCreateImageAtIndex (cgsrc, 0, NULL);
+
+ } else {
+ cgi = (CGImageRef) img_arg;
+ imgr.width = CGImageGetWidth (cgi);
+ imgr.height = CGImageGetHeight (cgi);
+ }
- // convert the NSImage to a CGImage via the toll-free-bridging
- // of NSData and CFData...
- //
- NSData *nsdata = [NSBitmapImageRep
- TIFFRepresentationOfImageRepsInArray:
- [nsimg representations]];
- CFDataRef cfdata = (CFDataRef) nsdata;
- CGImageSourceRef cgsrc = CGImageSourceCreateWithData (cfdata, NULL);
- CGImageRef cgi = CGImageSourceCreateImageAtIndex (cgsrc, 0, NULL);
-
- NSSize imgr = [nsimg size];
Bool rot_p = (exif_rotation >= 5);
if (rot_p)
CGContextDrawImage (d->cgc, dst2, cgi);
CGContextRestoreGState (d->cgc);
- CFRelease (cgsrc);
- CGImageRelease (cgi);
+ if (nsimg_p) {
+ CFRelease (cgsrc);
+ CGImageRelease (cgi);
+ }
if (geom_ret) {
geom_ret->x = dst.origin.x;
NSTextStorage *ts = [[NSTextStorage alloc] initWithString:nsstr];
[ts setFont:fid->nsfont];
NSLayoutManager *lm = [[NSLayoutManager alloc] init];
+
+ /* Without this, the layout manager ends up on a queue somewhere and is
+ referenced again after we return to the command loop. Since we don't
+ use this layout manager again, by that time it may have been garbage
+ collected, and we crash. Setting this seems to cause `lm' to no
+ longer be referenced once we exit this block. */
+ [lm setBackgroundLayoutEnabled:NO];
+
NSTextContainer *tc = [[NSTextContainer alloc] init];
[lm addTextContainer:tc];
[tc release]; // lm retains tc
NSLog(@"no NSFont for \"%s\"", name);
abort();
}
+ CFRetain (fid->nsfont); // needed for garbage collection?
//NSLog(@"parsed \"%s\" to %s %.1f", name, fid->ps_name, fid->size);
// They're probably not very big...
//
// [fid->nsfont release];
+ // CFRelease (fid->nsfont);
free (fid);
return 0;
XUnloadFont (dpy, gc->gcv.font);
gc->gcv.font = copy_font (fid);
[gc->gcv.font->nsfont retain];
+ CFRetain (gc->gcv.font->nsfont); // needed for garbage collection?
return 0;
}
font = XLoadFont (0, 0);
gc->gcv.font = font;
[gc->gcv.font->nsfont retain];
+ CFRetain (gc->gcv.font->nsfont); // needed for garbage collection?
}
CGContextSelectFont (cgc, font->ps_name, font->size, kCGEncodingMacRoman);
CGContextSetTextMatrix (cgc, CGAffineTransformIdentity);