Revision: 9120
          http://sourceforge.net/p/skim-app/code/9120
Author:   hofman
Date:     2016-09-22 23:48:07 +0000 (Thu, 22 Sep 2016)
Log Message:
-----------
Use CGContext based drawing methods to draw PDF page, when available. We need 
to rewrite custom additions also to CGContext. Use interpolationQuality instead 
of ourselves setting the image interpolation, this should also be available on 
10.6 even if it was not documented there.

Modified Paths:
--------------
    trunk/NSGraphics_SKExtensions.h
    trunk/NSGraphics_SKExtensions.m
    trunk/PDFAnnotationLine_SKExtensions.m
    trunk/PDFAnnotationLink_SKExtensions.m
    trunk/PDFAnnotationMarkup_SKExtensions.m
    trunk/PDFAnnotation_SKExtensions.h
    trunk/PDFAnnotation_SKExtensions.m
    trunk/PDFPage_SKExtensions.m
    trunk/PDFView_SKExtensions.h
    trunk/PDFView_SKExtensions.m
    trunk/SKMainWindowController.m
    trunk/SKMainWindowController_Actions.m
    trunk/SKPDFView.m
    trunk/SKReadingBar.h
    trunk/SKReadingBar.m
    trunk/SKSecondaryPDFView.m
    trunk/SKSnapshotPDFView.m
    trunk/SKSnapshotWindowController.m
    trunk/SKSyncDot.h
    trunk/SKSyncDot.m

Modified: trunk/NSGraphics_SKExtensions.h
===================================================================
--- trunk/NSGraphics_SKExtensions.h     2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/NSGraphics_SKExtensions.h     2016-09-22 23:48:07 UTC (rev 9120)
@@ -39,8 +39,8 @@
 #import <Cocoa/Cocoa.h>
 
 
-extern void SKDrawResizeHandle(NSPoint point, CGFloat radius, BOOL active);
-extern void SKDrawResizeHandles(NSRect rect, CGFloat radius, BOOL active);
+extern void SKDrawResizeHandle(CGContextRef context, NSPoint point, CGFloat 
radius, BOOL active);
+extern void SKDrawResizeHandles(CGContextRef context, NSRect rect, CGFloat 
radius, BOOL active);
 
 #pragma mark -
 

Modified: trunk/NSGraphics_SKExtensions.m
===================================================================
--- trunk/NSGraphics_SKExtensions.m     2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/NSGraphics_SKExtensions.m     2016-09-22 23:48:07 UTC (rev 9120)
@@ -41,26 +41,28 @@
 #import "NSColor_SKExtensions.h"
 
 
-void SKDrawResizeHandle(NSPoint point, CGFloat radius, BOOL active)
+void SKDrawResizeHandle(CGContextRef context, NSPoint point, CGFloat radius, 
BOOL active)
 {
-    NSBezierPath *path = [NSBezierPath 
bezierPathWithOvalInRect:NSMakeRect(point.x - 0.875 * radius, point.y - 0.875 * 
radius, 1.75 * radius, 1.75 * radius)];
-    [path setLineWidth:0.25 * radius];
-    [[[(active ? [NSColor selectedControlColor] : [NSColor 
secondarySelectedControlColor]) 
colorUsingColorSpaceName:NSCalibratedRGBColorSpace] 
colorWithAlphaComponent:0.8] setFill];
-    [(active ? [NSColor alternateSelectedControlColor] : [NSColor 
disabledControlTextColor]) setStroke];
-    [path fill];
-    [path stroke];
+    CGRect rect = CGRectMake(point.x - 0.875 * radius, point.y - 0.875 * 
radius, 1.75 * radius, 1.75 * radius);
+    NSColor *color = [[(active ? [NSColor selectedControlColor] : [NSColor 
secondarySelectedControlColor]) 
colorUsingColorSpaceName:NSCalibratedRGBColorSpace] 
colorWithAlphaComponent:0.8];
+    CGContextSetFillColorWithColor(context, [color CGColor]);
+    color = (active ? [NSColor alternateSelectedControlColor] : [NSColor 
disabledControlTextColor]);
+    CGContextSetStrokeColorWithColor(context, [color CGColor]);
+    CGContextSetLineWidth(context, 0.25 * radius);
+    CGContextFillEllipseInRect(context, rect);
+    CGContextStrokeEllipseInRect(context, rect);
 }
 
-void SKDrawResizeHandles(NSRect rect, CGFloat radius, BOOL active)
+void SKDrawResizeHandles(CGContextRef context, NSRect rect, CGFloat radius, 
BOOL active)
 {
-    SKDrawResizeHandle(NSMakePoint(NSMinX(rect), NSMidY(rect)), radius, 
active);
-    SKDrawResizeHandle(NSMakePoint(NSMidX(rect), NSMaxY(rect)), radius, 
active);
-    SKDrawResizeHandle(NSMakePoint(NSMidX(rect), NSMinY(rect)), radius, 
active);
-    SKDrawResizeHandle(NSMakePoint(NSMaxX(rect), NSMidY(rect)), radius, 
active);
-    SKDrawResizeHandle(NSMakePoint(NSMinX(rect), NSMaxY(rect)), radius, 
active);
-    SKDrawResizeHandle(NSMakePoint(NSMinX(rect), NSMinY(rect)), radius, 
active);
-    SKDrawResizeHandle(NSMakePoint(NSMaxX(rect), NSMaxY(rect)), radius, 
active);
-    SKDrawResizeHandle(NSMakePoint(NSMaxX(rect), NSMinY(rect)), radius, 
active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMinX(rect), NSMidY(rect)), 
radius, active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMidX(rect), NSMaxY(rect)), 
radius, active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMidX(rect), NSMinY(rect)), 
radius, active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMaxX(rect), NSMidY(rect)), 
radius, active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMinX(rect), NSMaxY(rect)), 
radius, active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMinX(rect), NSMinY(rect)), 
radius, active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMaxX(rect), NSMaxY(rect)), 
radius, active);
+    SKDrawResizeHandle(context, NSMakePoint(NSMaxX(rect), NSMinY(rect)), 
radius, active);
 }
 
 #pragma mark -

Modified: trunk/PDFAnnotationLine_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationLine_SKExtensions.m      2016-09-22 11:37:37 UTC (rev 
9119)
+++ trunk/PDFAnnotationLine_SKExtensions.m      2016-09-22 23:48:07 UTC (rev 
9120)
@@ -231,16 +231,16 @@
         return 0;
 }
 
-- (void)drawSelectionHighlightForView:(PDFView *)pdfView {
+- (void)drawSelectionHighlightForView:(PDFView *)pdfView 
inContext:(CGContextRef)context {
     if (NSIsEmptyRect([self bounds]))
         return;
     BOOL active = [[pdfView window] isKeyWindow] && [[[pdfView window] 
firstResponder] isDescendantOf:pdfView];
     NSPoint origin = [self bounds].origin;
     NSPoint point = SKAddPoints(origin, [self startPoint]);
     CGFloat delta = 4.0 / [pdfView scaleFactor];
-    SKDrawResizeHandle(point, delta, active);
+    SKDrawResizeHandle(context, point, delta, active);
     point = SKAddPoints(origin, [self endPoint]);
-    SKDrawResizeHandle(point, delta, active);
+    SKDrawResizeHandle(context, point, delta, active);
 }
 
 - (NSString *)colorDefaultKey { return SKLineNoteColorKey; }

Modified: trunk/PDFAnnotationLink_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationLink_SKExtensions.m      2016-09-22 11:37:37 UTC (rev 
9119)
+++ trunk/PDFAnnotationLink_SKExtensions.m      2016-09-22 23:48:07 UTC (rev 
9120)
@@ -55,7 +55,7 @@
     original_toolTip = (id (*)(id, 
SEL))SKReplaceInstanceMethodImplementationFromSelector(self, 
@selector(toolTip), @selector(replacement_toolTip));
 }
 
-- (void)drawSelectionHighlightForView:(PDFView *)pdfView {}
+- (void)drawSelectionHighlightForView:(PDFView *)pdfView 
inContext:(CGContextRef)context {}
 
 - (BOOL)isLink { return YES; }
 

Modified: trunk/PDFAnnotationMarkup_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationMarkup_SKExtensions.m    2016-09-22 11:37:37 UTC (rev 
9119)
+++ trunk/PDFAnnotationMarkup_SKExtensions.m    2016-09-22 23:48:07 UTC (rev 
9120)
@@ -276,7 +276,7 @@
     return bounds;
 }
 
-- (void)drawSelectionHighlightForView:(PDFView *)pdfView {
+- (void)drawSelectionHighlightForView:(PDFView *)pdfView 
inContext:(CGContextRef)context {
     if (NSIsEmptyRect([self bounds]))
         return;
     
@@ -285,12 +285,16 @@
     NSUInteger i, iMax = [lines count];
     CGFloat lineWidth = 1.0 / [pdfView scaleFactor];
     PDFPage *page = [self page];
+    CGColorRef color = [(active ? [NSColor alternateSelectedControlColor] : 
[NSColor disabledControlTextColor]) CGColor];
     
-    [NSGraphicsContext saveGraphicsState];
-    [(active ? [NSColor alternateSelectedControlColor] : [NSColor 
disabledControlTextColor]) setFill];
-    for (i = 0; i < iMax; i++)
-        NSFrameRectWithWidth([pdfView convertRect:NSIntegralRect([pdfView 
convertRect:[lines rectAtIndex:i] fromPage:page]) toPage:page], lineWidth);
-    [NSGraphicsContext restoreGraphicsState];
+    CGContextSaveGState(context);
+    CGContextSetStrokeColorWithColor(context, color);
+    CGContextSetLineWidth(context, lineWidth);
+    for (i = 0; i < iMax; i++) {
+        NSRect rect = [pdfView convertRect:NSIntegralRect([pdfView 
convertRect:[lines rectAtIndex:i] fromPage:page]) toPage:page];
+        CGContextStrokeRect(context, CGRectInset(NSRectToCGRect(rect), 0.5 * 
lineWidth, 0.5 * lineWidth));
+    }
+    CGContextRestoreGState(context);
 }
 
 - (BOOL)isMarkup { return YES; }

Modified: trunk/PDFAnnotation_SKExtensions.h
===================================================================
--- trunk/PDFAnnotation_SKExtensions.h  2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/PDFAnnotation_SKExtensions.h  2016-09-22 23:48:07 UTC (rev 9120)
@@ -96,7 +96,7 @@
 
 - (SKRectEdges)resizeHandleForPoint:(NSPoint)point 
scaleFactor:(CGFloat)scaleFactor;
 
-- (void)drawSelectionHighlightForView:(PDFView *)pdfView;
+- (void)drawSelectionHighlightForView:(PDFView *)pdfView 
inContext:(CGContextRef)context;
 
 - (void)registerUserName;
 

Modified: trunk/PDFAnnotation_SKExtensions.m
===================================================================
--- trunk/PDFAnnotation_SKExtensions.m  2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/PDFAnnotation_SKExtensions.m  2016-09-22 23:48:07 UTC (rev 9120)
@@ -293,18 +293,19 @@
     return [self isResizable] ? SKResizeHandleForPointFromRect(point, [self 
bounds], 4.0 / scaleFactor) : 0;
 }
 
-- (void)drawSelectionHighlightForView:(PDFView *)pdfView {
+- (void)drawSelectionHighlightForView:(PDFView *)pdfView 
inContext:(CGContextRef)context {
     if (NSIsEmptyRect([self bounds]))
         return;
-    [NSGraphicsContext saveGraphicsState];
     BOOL active = [[pdfView window] isKeyWindow] && [[[pdfView window] 
firstResponder] isDescendantOf:pdfView];
     NSRect rect = [pdfView convertRect:NSIntegralRect([pdfView 
convertRect:[self bounds] fromPage:[self page]]) toPage:[self page]];
     CGFloat lineWidth = 1.0 / [pdfView scaleFactor];
-    [(active ? [NSColor alternateSelectedControlColor] : [NSColor 
disabledControlTextColor]) setFill];
-    NSFrameRectWithWidth(rect, lineWidth);
+    CGContextSaveGState(context);
+    CGColorRef color = [(active ? [NSColor alternateSelectedControlColor] : 
[NSColor disabledControlTextColor]) CGColor];
+    CGContextSetStrokeColorWithColor(context, color);
+    CGContextStrokeRectWithWidth(context, CGRectInset(NSRectToCGRect(rect), 
0.5 * lineWidth, 0.5 * lineWidth), lineWidth);
     if ([self isResizable])
-        SKDrawResizeHandles(rect, 4.0 * lineWidth, active);
-    [NSGraphicsContext restoreGraphicsState];
+        SKDrawResizeHandles(context, rect, 4.0 * lineWidth, active);
+    CGContextRestoreGState(context);
 }
 
 - (void)registerUserName {

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/PDFPage_SKExtensions.m        2016-09-22 23:48:07 UTC (rev 9120)
@@ -203,7 +203,7 @@
         
         if (readingBar) {
             [self transformContextForBox:box];
-            [readingBar drawForPage:self withBox:box];
+            [readingBar drawForPage:self withBox:box 
inContext:[[NSGraphicsContext currentContext] graphicsPort]];
         }
         
         [[NSGraphicsContext currentContext] 
setImageInterpolation:NSImageInterpolationDefault];

Modified: trunk/PDFView_SKExtensions.h
===================================================================
--- trunk/PDFView_SKExtensions.h        2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/PDFView_SKExtensions.h        2016-09-22 23:48:07 UTC (rev 9120)
@@ -59,6 +59,8 @@
 
 - (void)applyDefaultPageBackgroundColor;
 
+- (void)applyDefaultInterpolationQuality;
+
 @end
 
 

Modified: trunk/PDFView_SKExtensions.m
===================================================================
--- trunk/PDFView_SKExtensions.m        2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/PDFView_SKExtensions.m        2016-09-22 23:48:07 UTC (rev 9120)
@@ -50,9 +50,24 @@
 
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_6
+
 @interface NSScreen (SKLionDeclarations)
 - (CGFloat)backingScaleFactor;
 @end
+
+typedef NSInteger PDFInterpolationQuality;
+enum
+{
+    kPDFInterpolationQualityNone = 0,
+    kPDFInterpolationQualityLow = 1,
+    kPDFInterpolationQualityHigh = 2
+};
+
+@interface PDFView (SKLionDeclarations)
+- (void)setInterpolationQuality:(PDFInterpolationQuality)quality;
+- (PDFInterpolationQuality)interpolationQuality;
+@end
+
 #endif
 
 @implementation PDFView (SKExtensions)
@@ -242,7 +257,9 @@
 }
 
 + (NSColor *)defaultPageBackgroundColor {
-    return [[NSUserDefaults standardUserDefaults] 
colorForKey:SKPageBackgroundColorKey] ?: [NSColor whiteColor];
+    if ([self respondsToSelector:@selector(setPageColor:)])
+        return [[NSUserDefaults standardUserDefaults] 
colorForKey:SKPageBackgroundColorKey] ?: [NSColor whiteColor];
+    return [NSColor whiteColor];
 }
 
 - (void)applyDefaultPageBackgroundColor {
@@ -250,4 +267,14 @@
         [self setPageColor:[[self class] defaultPageBackgroundColor]];
 }
 
+- (void)applyDefaultInterpolationQuality {
+    if ([self respondsToSelector:@selector(setInterpolationQuality:)]) {
+        NSImageInterpolation interpolation = [[NSUserDefaults 
standardUserDefaults] integerForKey:SKImageInterpolationKey];
+        // smooth graphics when anti-aliasing
+        if (interpolation == NSImageInterpolationDefault)
+            interpolation = [self shouldAntiAlias] ? NSImageInterpolationHigh 
: NSImageInterpolationNone;
+        [self setInterpolationQuality:interpolation == 
NSImageInterpolationHigh ? kPDFInterpolationQualityHigh : interpolation == 
NSImageInterpolationLow ? kPDFInterpolationQualityLow : 
kPDFInterpolationQualityNone];
+    }
+}
+
 @end

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKMainWindowController.m      2016-09-22 23:48:07 UTC (rev 9120)
@@ -366,6 +366,7 @@
     [pdfView setGreekingThreshold:[sud floatForKey:SKGreekingThresholdKey]];
     [pdfView setBackgroundColor:[sud colorForKey:SKBackgroundColorKey]];
     [pdfView applyDefaultPageBackgroundColor];
+    [pdfView applyDefaultInterpolationQuality];
     
     [self applyPDFSettings:hasWindowSetup ? savedNormalSetup : [sud 
dictionaryForKey:SKDefaultPDFDisplaySettingsKey]];
     
@@ -2320,7 +2321,9 @@
             [rightSideController.snapshotTableView 
noteHeightOfRowsWithIndexesChanged:[NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange(0, [self countOfSnapshots])]];
         } else if ([key isEqualToString:SKShouldAntiAliasKey]) {
             [pdfView setShouldAntiAlias:[[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldAntiAliasKey]];
+            [pdfView applyDefaultInterpolationQuality];
             [secondaryPdfView setShouldAntiAlias:[[NSUserDefaults 
standardUserDefaults] boolForKey:SKShouldAntiAliasKey]];
+            [secondaryPdfView applyDefaultInterpolationQuality];
         } else if ([key isEqualToString:SKGreekingThresholdKey]) {
             [pdfView setGreekingThreshold:[[NSUserDefaults 
standardUserDefaults] floatForKey:SKGreekingThresholdKey]];
             [secondaryPdfView setGreekingThreshold:[[NSUserDefaults 
standardUserDefaults] floatForKey:SKGreekingThresholdKey]];

Modified: trunk/SKMainWindowController_Actions.m
===================================================================
--- trunk/SKMainWindowController_Actions.m      2016-09-22 11:37:37 UTC (rev 
9119)
+++ trunk/SKMainWindowController_Actions.m      2016-09-22 23:48:07 UTC (rev 
9120)
@@ -1008,6 +1008,7 @@
             [secondaryPdfView applyDefaultPageBackgroundColor];
             [secondaryPdfView setDisplaysPageBreaks:NO];
             [secondaryPdfView setShouldAntiAlias:[[NSUserDefaults 
standardUserDefaults] boolForKey:SKShouldAntiAliasKey]];
+            [secondaryPdfView applyDefaultInterpolationQuality];
             [secondaryPdfView setGreekingThreshold:[[NSUserDefaults 
standardUserDefaults] floatForKey:SKGreekingThresholdKey]];
             [secondaryPdfView setSynchronizeZoom:YES];
             [secondaryPdfView setDocument:[pdfView document]];

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKPDFView.m   2016-09-22 23:48:07 UTC (rev 9120)
@@ -378,21 +378,20 @@
     CGContextAddRect(context, NSRectToCGRect(selectionRect));
     CGContextEOFillPath(context);
     if ([pdfPage pageIndex] != selectionPageIndex) {
-        CGColorRef color = CGColorCreateGenericGray(0.0, 0.3);
+        color = CGColorCreateGenericGray(0.0, 0.3);
         CGContextSetFillColorWithColor(context, color);
         CGColorRelease(color);
         CGContextFillRect(context, NSRectToCGRect(selectionRect));
     }
-    SKDrawResizeHandlesInContext(selectionRect, radius, active, context);
+    SKDrawResizeHandles(context, selectionRect, radius, active);
 }
 
 - (void)drawDragHighlightInContext:(CGContextRef)context {
     CGFloat width = 1.0 / [self scaleFactor];
     CGContextSaveGState(context);
     CGContextSetStrokeColorWithColor(context, 
CGColorGetConstantColor(kCGColorBlack));
-    CGContextSetLineWidth(context, width);
     NSRect rect = [self convertRect:NSIntegralRect([self 
convertRect:[highlightAnnotation bounds] fromPage:[highlightAnnotation page]]) 
toPage:[highlightAnnotation page]];
-    CGContextStrokeRect(context, CGRectInset(NSRectToCGRect(rect), 0.5 * 
width, 0.5 * width));
+    CGContextStrokeRectWithWidth(context, CGRectInset(NSRectToCGRect(rect), 
0.5 * width, 0.5 * width), width);
     CGContextRestoreGState(context);
 }
 
@@ -420,12 +419,6 @@
 }
 
 - (void)drawPage:(PDFPage *)pdfPage toContext:(CGContextRef)context {
-    CGInterpolationQuality interpolation = [[NSUserDefaults 
standardUserDefaults] integerForKey:SKImageInterpolationKey];
-    // smooth graphics when anti-aliasing
-    if (interpolation == kCGInterpolationDefault)
-        interpolation = [self shouldAntiAlias] ? kCGInterpolationHigh : 
kCGInterpolationNone;
-    CGContextSetInterpolationQuality(context, interpolation);
-    
     [PDFAnnotation setCurrentActiveAnnotation:activeAnnotation];
     
     // Let PDFView do most of the hard work.
@@ -433,8 +426,6 @@
     
     [PDFAnnotation setCurrentActiveAnnotation:nil];
     
-    CGContextSetInterpolationQuality(context, kCGInterpolationDefault);
-    
     [self drawPageHighlights:pdfPage toContext:context];
 }
 
@@ -443,12 +434,6 @@
         // on 10.12 this should call drawPage:toContext:
         [super drawPage:pdfPage];
     } else {
-        NSImageInterpolation interpolation = [[NSUserDefaults 
standardUserDefaults] integerForKey:SKImageInterpolationKey];
-        // smooth graphics when anti-aliasing
-        if (interpolation == NSImageInterpolationDefault)
-            interpolation = [self shouldAntiAlias] ? NSImageInterpolationHigh 
: NSImageInterpolationNone;
-        [[NSGraphicsContext currentContext] 
setImageInterpolation:interpolation];
-        
         [PDFAnnotation setCurrentActiveAnnotation:activeAnnotation];
         
         // Let PDFView do most of the hard work.
@@ -456,8 +441,6 @@
         
         [PDFAnnotation setCurrentActiveAnnotation:nil];
         
-        [[NSGraphicsContext currentContext] 
setImageInterpolation:NSImageInterpolationDefault];
-        
         [self drawPageHighlights:pdfPage toContext:[[NSGraphicsContext 
currentContext] graphicsPort]];
     }
 }
@@ -3914,7 +3897,12 @@
             NSImage *image;
             NSRange pageRange;
             NSAffineTransform *transform = [NSAffineTransform transform];
+            NSImageInterpolation interpolation = [[NSUserDefaults 
standardUserDefaults] integerForKey:SKImageInterpolationKey];
             
+            // smooth graphics when anti-aliasing
+            if (interpolation == NSImageInterpolationDefault)
+                interpolation = [self shouldAntiAlias] ? 
NSImageInterpolationHigh : NSImageInterpolationNone;
+            
             [transform translateXBy:mouseLocSelf.x yBy:mouseLocSelf.y];
             [transform scaleBy:1.0 / magnification];
             [transform translateXBy:-mouseLocSelf.x yBy:-mouseLocSelf.y];
@@ -3961,7 +3949,12 @@
                     [pageTransform concat];
                     [pageTransform release];
                     [[NSGraphicsContext currentContext] 
setShouldAntialias:[self shouldAntiAlias]];
-                    [self drawPage:page];
+                    [[NSGraphicsContext currentContext] 
setImageInterpolation:interpolation];
+                    if ([PDFView 
instancesRespondToSelector:@selector(drawPage:toContext:)])
+                        [self drawPage:page toContext:[[NSGraphicsContext 
currentContext] graphicsPort]];
+                    else
+                        [self drawPage:page];
+                    [[NSGraphicsContext currentContext] 
setImageInterpolation:NSImageInterpolationDefault];
                     [NSGraphicsContext restoreGraphicsState];
                 }
                 

Modified: trunk/SKReadingBar.h
===================================================================
--- trunk/SKReadingBar.h        2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKReadingBar.h        2016-09-22 23:48:07 UTC (rev 9120)
@@ -63,6 +63,6 @@
 - (BOOL)goToPreviousPage;
 - (BOOL)goToLineForPoint:(NSPoint)point;
 
-- (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box;
+- (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
inContext:(CGContextRef)context;
 
 @end

Modified: trunk/SKReadingBar.m
===================================================================
--- trunk/SKReadingBar.m        2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKReadingBar.m        2016-09-22 23:48:07 UTC (rev 9120)
@@ -197,30 +197,30 @@
     return YES;
 }
 
-- (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box {
+- (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
inContext:(CGContextRef)context {
     NSRect rect = [self currentBoundsForBox:box];
     
-    [NSGraphicsContext saveGraphicsState];
+    CGContextSaveGState(context);
     
-    [[[NSUserDefaults standardUserDefaults] colorForKey:SKReadingBarColorKey] 
setFill];
+    CGContextSetFillColorWithColor(context, [[[NSUserDefaults 
standardUserDefaults] colorForKey:SKReadingBarColorKey] CGColor]);
     
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKReadingBarInvertKey]) {
         NSRect bounds = [pdfPage boundsForBox:box];
         if (NSEqualRects(rect, NSZeroRect) || [page isEqual:pdfPage] == NO) {
-            [NSBezierPath fillRect:bounds];
+            CGContextFillRect(context, NSRectToCGRect(bounds));
         } else if (([pdfPage intrinsicRotation] % 180)) {
-            [NSBezierPath fillRect:SKSliceRect(bounds, NSMaxX(bounds) - 
NSMaxX(rect), NSMaxXEdge)];
-            [NSBezierPath fillRect:SKSliceRect(bounds, NSMinX(rect) - 
NSMinX(bounds), NSMinXEdge)];
+            CGContextFillRect(context, NSRectToCGRect(SKSliceRect(bounds, 
NSMaxX(bounds) - NSMaxX(rect), NSMaxXEdge)));
+            CGContextFillRect(context, NSRectToCGRect(SKSliceRect(bounds, 
NSMinX(rect) - NSMinX(bounds), NSMinXEdge)));
         } else {
-            [NSBezierPath fillRect:SKSliceRect(bounds, NSMaxY(bounds) - 
NSMaxY(rect), NSMaxYEdge)];
-            [NSBezierPath fillRect:SKSliceRect(bounds, NSMinY(rect) - 
NSMinY(bounds), NSMinYEdge)];
+            CGContextFillRect(context, NSRectToCGRect(SKSliceRect(bounds, 
NSMaxY(bounds) - NSMaxY(rect), NSMaxYEdge)));
+            CGContextFillRect(context, NSRectToCGRect(SKSliceRect(bounds, 
NSMinY(rect) - NSMinY(bounds), NSMinYEdge)));
         }
     } else if ([page isEqual:pdfPage]) {
-        CGContextSetBlendMode([[NSGraphicsContext currentContext] 
graphicsPort], kCGBlendModeMultiply);        
-        [NSBezierPath fillRect:rect];
+        CGContextSetBlendMode(context, kCGBlendModeMultiply);
+        CGContextFillRect(context, NSRectToCGRect(rect));
     }
     
-    [NSGraphicsContext restoreGraphicsState];
+    CGContextRestoreGState(context);
 }
 
 @end

Modified: trunk/SKSecondaryPDFView.m
===================================================================
--- trunk/SKSecondaryPDFView.m  2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKSecondaryPDFView.m  2016-09-22 23:48:07 UTC (rev 9120)
@@ -130,16 +130,6 @@
                                                      
name:PDFDocumentDidUnlockNotification object:document];
 }
 
-- (void)drawPage:(PDFPage *)pdfPage {
-    NSImageInterpolation interpolation = [[NSUserDefaults 
standardUserDefaults] integerForKey:SKImageInterpolationKey];
-    // smooth graphics when anti-aliasing
-    if (interpolation == NSImageInterpolationDefault)
-        interpolation = [self shouldAntiAlias] ? NSImageInterpolationHigh : 
NSImageInterpolationNone;
-    [[NSGraphicsContext currentContext] setImageInterpolation:interpolation];
-    [super drawPage:pdfPage];
-    [[NSGraphicsContext currentContext] 
setImageInterpolation:NSImageInterpolationDefault];
-}
-
 #pragma mark Popup buttons
 
 static void sizePopUpToItemAtIndex(NSPopUpButton *popUpButton, NSUInteger 
anIndex) {

Modified: trunk/SKSnapshotPDFView.m
===================================================================
--- trunk/SKSnapshotPDFView.m   2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKSnapshotPDFView.m   2016-09-22 23:48:07 UTC (rev 9120)
@@ -80,16 +80,6 @@
 #define CONTROL_HEIGHT 15.0
 #define CONTROL_WIDTH_OFFSET 20.0
 
-- (void)drawPage:(PDFPage *)pdfPage {
-    NSImageInterpolation interpolation = [[NSUserDefaults 
standardUserDefaults] integerForKey:SKImageInterpolationKey];
-    // smooth graphics when anti-aliasing
-    if (interpolation == NSImageInterpolationDefault)
-        interpolation = [self shouldAntiAlias] ? NSImageInterpolationHigh : 
NSImageInterpolationNone;
-    [[NSGraphicsContext currentContext] setImageInterpolation:interpolation];
-    [super drawPage:pdfPage];
-    [[NSGraphicsContext currentContext] 
setImageInterpolation:NSImageInterpolationDefault];
-}
-
 #pragma mark Popup button
 
 - (void)commonInitialization {

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKSnapshotWindowController.m  2016-09-22 23:48:07 UTC (rev 9120)
@@ -280,6 +280,7 @@
     [pdfView setGreekingThreshold:[[NSUserDefaults standardUserDefaults] 
floatForKey:SKGreekingThresholdKey]];
     [pdfView setBackgroundColor:[[NSUserDefaults standardUserDefaults] 
colorForKey:SKBackgroundColorKey]];
     [pdfView applyDefaultPageBackgroundColor];
+    [pdfView applyDefaultInterpolationQuality];
     [pdfView setDocument:pdfDocument];
     
     [self 
setWindowFrameAutosaveNameOrCascade:SKSnapshotWindowFrameAutosaveName];
@@ -637,6 +638,7 @@
                 [self updateWindowLevel];
         } else if ([key isEqualToString:SKShouldAntiAliasKey]) {
             [pdfView setShouldAntiAlias:[[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldAntiAliasKey]];
+            [pdfView applyDefaultInterpolationQuality];
         } else if ([key isEqualToString:SKGreekingThresholdKey]) {
             [pdfView setGreekingThreshold:[[NSUserDefaults 
standardUserDefaults] floatForKey:SKGreekingThresholdKey]];
         } else if ([key isEqualToString:SKBackgroundColorKey]) {

Modified: trunk/SKSyncDot.h
===================================================================
--- trunk/SKSyncDot.h   2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKSyncDot.h   2016-09-22 23:48:07 UTC (rev 9120)
@@ -58,6 +58,6 @@
 
 - (void)invalidate;
 
-- (void)draw;
+- (void)drawInContext:(CGContextRef)context;
 
 @end

Modified: trunk/SKSyncDot.m
===================================================================
--- trunk/SKSyncDot.m   2016-09-22 11:37:37 UTC (rev 9119)
+++ trunk/SKSyncDot.m   2016-09-22 23:48:07 UTC (rev 9120)
@@ -98,26 +98,29 @@
     return SKRectFromCenterAndSquareSize(point, 22.0);
 }
 
-- (void)draw {
-    [NSGraphicsContext saveGraphicsState];
+- (void)drawInContext:(CGContextRef)context {
+    CGContextSaveGState(context);
     
+    CGColorRef color;
     CGFloat s = 6.0;
     if (phase < 1.0) {
         s += 8.0 * sin(phase * M_PI);
-        [NSShadow setShadowWithColor:[NSColor colorWithCalibratedWhite:0.0 
alpha:0.33333] blurRadius:2.0 yOffset:-2.0];
-        [[NSColor redColor] setFill];
-        [[NSBezierPath 
bezierPathWithOvalInRect:SKRectFromCenterAndSquareSize(point, s)] fill];
-        [NSGraphicsContext restoreGraphicsState];
-        [NSGraphicsContext saveGraphicsState];
-        NSGradient *gradient = [[[NSGradient alloc] 
initWithStartingColor:[NSColor colorWithCalibratedRed:1.0 green:0.3 blue:0.3 
alpha:1.0] endingColor:[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 
alpha:1.0]] autorelease];
-        [gradient drawInBezierPath:[NSBezierPath 
bezierPathWithOvalInRect:SKRectFromCenterAndSquareSize(point, s)] 
relativeCenterPosition:NSMakePoint(0, 0.7)];
+        CGFloat components[8] = {1.0, 0.3, 0.3, 1.0, 1.0, 0.0, 0.0, 1.0};
+        CGFloat locations[2] = {0.0, 1.0};
+        CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
+        CGGradientRef gradient = 
CGGradientCreateWithColorComponents(colorspace, components, locations, 2);
+        CGColorSpaceRelease(colorspace);
+        CGContextDrawRadialGradient(context, gradient, CGPointMake(point.x, 
point.y + 0.35 * s), 0.0, CGPointMake(point.x, point.y), 0.5 * s, 0);
+        CGGradientRelease(gradient);
     } else {
-        CGContextSetBlendMode([[NSGraphicsContext currentContext] 
graphicsPort], kCGBlendModeMultiply);        
-        [[NSColor redColor] setFill];
-        [[NSBezierPath 
bezierPathWithOvalInRect:SKRectFromCenterAndSquareSize(point, s)] fill];
+        CGContextSetBlendMode(context, kCGBlendModeMultiply);
+        color = CGColorCreateGenericRGB(1.0, 0.0, 0.0, 1.0);
+        CGContextSetFillColorWithColor(context, color);
+        CGColorRelease(color);
+        CGContextFillEllipseInRect(context, CGRectMake(point.x - 0.5 * s, 
point.y - 0.5 * s, s, s));
     }
     
-    [NSGraphicsContext restoreGraphicsState];
+    CGContextRestoreGState(context);
 }
 
 @end

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to