From 2ec58b5f5c1b06e66f90316c041e2068b73ac7fa Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 13 Nov 2021 11:04:02 -0700 Subject: [PATCH 1/2] Backport my fixes/updates of ZoomPixmapWindow. --- src/zoomCocoa/ZoomPixmapWindow.m | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/zoomCocoa/ZoomPixmapWindow.m b/src/zoomCocoa/ZoomPixmapWindow.m index 0435fdc1..e03887f5 100644 --- a/src/zoomCocoa/ZoomPixmapWindow.m +++ b/src/zoomCocoa/ZoomPixmapWindow.m @@ -16,9 +16,9 @@ - (id) initWithZoomView: (ZoomView*) view { self = [super init]; if (self) { - pixmap = [[NSImage alloc] initWithSize: NSMakeSize(640, 480)]; - [pixmap setFlipped: YES]; + pixmap = [[NSImage alloc] initWithSize: NSMakeSize(640, 400)]; zView = view; + [zView.window setContentSize: NSMakeSize(640, 400)]; inputStyle = nil; } @@ -94,7 +94,7 @@ - (void) setSize: (NSSize) windowSize { - (void) plotRect: (NSRect) rect withStyle: (ZStyle*) style { - [pixmap lockFocus]; + [pixmap lockFocusFlipped:YES]; NSColor* foregroundColour = [zView foregroundColourForStyle: style]; [foregroundColour set]; @@ -107,7 +107,7 @@ - (void) plotRect: (NSRect) rect - (void) plotText: (NSString*) text atPoint: (NSPoint) point withStyle: (ZStyle*) style { - [pixmap lockFocus]; + [pixmap lockFocusFlipped:YES]; NSMutableDictionary* attr = [[zView attributesForStyle: style] mutableCopy]; @@ -129,7 +129,7 @@ - (void) plotText: (NSString*) text backgroundRect.size.width = ceilf(backgroundRect.size.width); backgroundRect.size.height = ceilf(backgroundRect.size.height) + 1.0; - [[attr objectForKey: NSBackgroundColorAttributeName] set]; + [(NSColor*)[attr objectForKey: NSBackgroundColorAttributeName] set]; NSRectFill(backgroundRect); // Draw the text @@ -145,18 +145,19 @@ - (void) plotText: (NSString*) text - (void) scrollRegion: (NSRect) region toPoint: (NSPoint) where { - [pixmap lockFocus]; + [pixmap lockFocusFlipped:YES]; // Used to use NSCopyBits but Apple randomly broke it sometime in Snow Leopard. The docs lied anyway. // This is much slower :-( NSBitmapImageRep* copiedBits = [[NSBitmapImageRep alloc] initWithFocusedViewRect: region]; NSImage* copiedImage = [[NSImage alloc] init]; [copiedImage addRepresentation: copiedBits]; - [copiedImage setFlipped: YES]; [copiedImage drawInRect: NSMakeRect(where.x, where.y, region.size.width, region.size.height) fromRect: NSMakeRect(0,0, region.size.width, region.size.height) operation: NSCompositeSourceOver - fraction: 1.0]; + fraction: 1.0 + respectFlipped: YES + hints: nil]; [copiedBits release]; @@ -203,7 +204,7 @@ - (NSSize) measureString: (in NSString*) string } - (NSColor*) colourAtPixel: (NSPoint) point { - [pixmap lockFocus]; + [pixmap lockFocusFlipped:YES]; if (point.x <= 0) point.x = 1; if (point.y <= 0) point.y = 1; @@ -222,8 +223,8 @@ - (void) setInputPosition: (NSPoint) point inputPos = point; if (inputStyle) { [inputStyle release]; - inputStyle = style; } + inputStyle = [style copy]; } - (NSPoint) inputPos { @@ -247,12 +248,13 @@ - (void) plotImageWithNumber: (int) number destRect.size = [[zView resources] sizeForImageWithNumber: number forPixmapSize: [pixmap size]]; - [pixmap lockFocus]; - [img setFlipped: [pixmap isFlipped]]; + [pixmap lockFocusFlipped:YES]; [img drawInRect: destRect fromRect: imgRect operation: NSCompositeSourceOver - fraction: 1.0]; + fraction: 1.0 + respectFlipped: YES + hints: nil]; [pixmap unlockFocus]; [zView setNeedsDisplay: YES]; From 6e27608c1141a79858492c64db2ccfdd929e89c6 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 13 Nov 2021 11:15:33 -0700 Subject: [PATCH 2/2] Add Obj-C properties to ZoomPixmapWindow. --- src/zoomCocoa/ZoomPixmapWindow.h | 8 +++--- src/zoomCocoa/ZoomPixmapWindow.m | 44 +++++++++++++------------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/zoomCocoa/ZoomPixmapWindow.h b/src/zoomCocoa/ZoomPixmapWindow.h index c14b65ee..ab42e78e 100644 --- a/src/zoomCocoa/ZoomPixmapWindow.h +++ b/src/zoomCocoa/ZoomPixmapWindow.h @@ -20,14 +20,14 @@ // Initialisation - (id) initWithZoomView: (ZoomView*) view; -- (void) setZoomView: (ZoomView*) view; +@property (assign) ZoomView* zoomView; // Getting the pixmap -- (NSSize) size; -- (NSImage*) pixmap; +@property (readonly) NSSize size; +@property (readonly, retain) NSImage *pixmap; // Input information -- (NSPoint) inputPos; +@property (readonly) NSPoint inputPos; - (ZStyle*) inputStyle; @end diff --git a/src/zoomCocoa/ZoomPixmapWindow.m b/src/zoomCocoa/ZoomPixmapWindow.m index e03887f5..3834250f 100644 --- a/src/zoomCocoa/ZoomPixmapWindow.m +++ b/src/zoomCocoa/ZoomPixmapWindow.m @@ -6,6 +6,7 @@ // Copyright (c) 2004 Andrew Hunter. All rights reserved. // +#include #import "ZoomPixmapWindow.h" @@ -39,9 +40,7 @@ - (NSSize) size { return [pixmap size]; } -- (NSImage*) pixmap { - return pixmap; -} +@synthesize pixmap; // = Standard window commands = @@ -63,10 +62,10 @@ - (NSSize) sizeOfFont: (NSFont*) font { NSLayoutManager* layoutManager = [[NSLayoutManager alloc] init]; // Width is one 'em' - float width = [@"M" sizeWithAttributes: [NSDictionary dictionaryWithObjectsAndKeys: NSFontAttributeName, font, nil]].width; + CGFloat width = [@"M" sizeWithAttributes: [NSDictionary dictionaryWithObjectsAndKeys: NSFontAttributeName, font, nil]].width; // Height is decided by the layout manager - float height = [layoutManager defaultLineHeightForFont: font]; + CGFloat height = [layoutManager defaultLineHeightForFont: font]; return NSMakeSize(width, height); } @@ -112,11 +111,11 @@ - (void) plotText: (NSString*) text NSMutableDictionary* attr = [[zView attributesForStyle: style] mutableCopy]; // Draw the background - float height = [self sizeOfFont: [attr objectForKey: NSFontAttributeName]].height; - float descender = [[attr objectForKey: NSFontAttributeName] descender]; + CGFloat height = [self sizeOfFont: [attr objectForKey: NSFontAttributeName]].height; + CGFloat descender = [[attr objectForKey: NSFontAttributeName] descender]; NSSize size = [text sizeWithAttributes: attr]; - point.y -= ceilf(height)+1.0; + point.y -= ceil(height)+1.0; size.height = height; NSRect backgroundRect; @@ -124,10 +123,10 @@ - (void) plotText: (NSString*) text backgroundRect.size = size; backgroundRect.origin.y -= descender; - backgroundRect.origin.x = floorf(backgroundRect.origin.x); - backgroundRect.origin.y = floorf(backgroundRect.origin.y); - backgroundRect.size.width = ceilf(backgroundRect.size.width); - backgroundRect.size.height = ceilf(backgroundRect.size.height) + 1.0; + backgroundRect.origin.x = floor(backgroundRect.origin.x); + backgroundRect.origin.y = floor(backgroundRect.origin.y); + backgroundRect.size.width = ceil(backgroundRect.size.width); + backgroundRect.size.height = ceil(backgroundRect.size.height) + 1.0; [(NSColor*)[attr objectForKey: NSBackgroundColorAttributeName] set]; NSRectFill(backgroundRect); @@ -152,14 +151,15 @@ - (void) scrollRegion: (NSRect) region NSBitmapImageRep* copiedBits = [[NSBitmapImageRep alloc] initWithFocusedViewRect: region]; NSImage* copiedImage = [[NSImage alloc] init]; [copiedImage addRepresentation: copiedBits]; + [copiedBits release]; [copiedImage drawInRect: NSMakeRect(where.x, where.y, region.size.width, region.size.height) fromRect: NSMakeRect(0,0, region.size.width, region.size.height) - operation: NSCompositeSourceOver + operation: NSCompositingOperationSourceOver fraction: 1.0 respectFlipped: YES hints: nil]; - [copiedBits release]; + [copiedImage release]; // Uh, docs say we should use NSNullObject here, but it's not defined. Making a guess at its value (sigh) // This would be less of a problem in a view, because we can get the view's own graphics state. But you @@ -227,9 +227,7 @@ - (void) setInputPosition: (NSPoint) point inputStyle = [style copy]; } -- (NSPoint) inputPos { - return inputPos; -} +@synthesize inputPos; - (ZStyle*) inputStyle { return inputStyle; @@ -239,10 +237,6 @@ - (void) plotImageWithNumber: (int) number atPoint: (NSPoint) point { NSImage* img = [[zView resources] imageWithNumber: number]; - NSRect imgRect; - imgRect.origin = NSMakePoint(0,0); - imgRect.size = [img size]; - NSRect destRect; destRect.origin = point; destRect.size = [[zView resources] sizeForImageWithNumber: number @@ -250,8 +244,8 @@ - (void) plotImageWithNumber: (int) number [pixmap lockFocusFlipped:YES]; [img drawInRect: destRect - fromRect: imgRect - operation: NSCompositeSourceOver + fromRect: NSZeroRect + operation: NSCompositingOperationSourceOver fraction: 1.0 respectFlipped: YES hints: nil]; @@ -280,9 +274,7 @@ - (id)initWithCoder:(NSCoder *)decoder { return self; } -- (void) setZoomView: (ZoomView*) view { - zView = view; -} +@synthesize zoomView=zView; // = Input styles =