Revision: 3254
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3254&view=rev
Author:   amaxwell
Date:     2007-11-24 12:36:26 -0800 (Sat, 24 Nov 2007)

Log Message:
-----------
Various compilation and other fixes.  Tested on 10.5.1, seems to work okay.
Didn't fully audit for leaks.  Specific changes listed below.
  
- Fix variable names
- Replace categories with static functions, since we're in the plugin namespace
  and categories get dangerous in that case
- Avoid caching local statics to decrease memory overhead in the daemon
- My suggestion of using the QL function for a PDF thumbnail didn't work, so we
  have to draw that manually and lose some cosmetic benefits
- Simplified image property code
- Add missing format specifier in hex color
- Remove BibDesk QL plugin function from main.c
- Increased .skim thumbnail font size; default size is hard to see in 
  the CoverFlow view in Finder
- Removed hotKeyEventHandler() declaration, whatever that was for

Modified Paths:
--------------
    trunk/QuickLook-Skim/GeneratePreviewForURL.m
    trunk/QuickLook-Skim/GenerateThumbnailForURL.m
    trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj
    trunk/QuickLook-Skim/main.c

Modified: trunk/QuickLook-Skim/GeneratePreviewForURL.m
===================================================================
--- trunk/QuickLook-Skim/GeneratePreviewForURL.m        2007-11-24 20:10:44 UTC 
(rev 3253)
+++ trunk/QuickLook-Skim/GeneratePreviewForURL.m        2007-11-24 20:36:26 UTC 
(rev 3254)
@@ -37,22 +37,16 @@
 #include <QuickLook/QuickLook.h>
 #import <Cocoa/Cocoa.h>
 
[EMAIL PROTECTED] NSColor (SKQLExtensions)
-- (NSString *)hexString;
[EMAIL PROTECTED]
-
[EMAIL PROTECTED] NSColor (SKQLExtensions)
-- (NSString *)hexString {
+static NSString *hexStringWithColor(NSColor *color)
+{
     static char hexChars[16] = "0123456789abcdef";
-    NSColor *color = self;
-    if ([self alphaComponent] < 1.0)
-        color = [[NSColor controlBackgroundColor] 
blendedColorWithFraction:[self alphaComponent] ofColor:[self 
colorWithAlphaComponent:1.0]];
+    if ([color alphaComponent] < 1.0)
+        color = [[NSColor controlBackgroundColor] 
blendedColorWithFraction:[color alphaComponent] ofColor:[color 
colorWithAlphaComponent:1.0]];
     int red = (int)roundf(255 * [color redComponent]);
     int green = (int)roundf(255 * [color greenComponent]);
     int blue = (int)roundf(255 * [color blueComponent]);
     return [NSString stringWithFormat:@"%C%C%C%C%C%C", hexChars[red / 16], 
hexChars[red % 16], hexChars[green / 16], hexChars[green % 16], hexChars[blue / 
16], hexChars[blue % 16]];
 }
[EMAIL PROTECTED]
 
 /* 
-----------------------------------------------------------------------------
    Generate a preview for file
@@ -70,20 +64,20 @@
         
         NSString *filePath = [(NSURL *)url path];
         NSArray *files = [[NSFileManager defaultManager] 
subpathsAtPath:filePath];
-        NSString *fileName = [[[path stringByDeletingLastPathComponent] 
stringByDeletingPathExtension] stringByAppendingPathExtension:@"pdf"];
+        NSString *fileName = [[[filePath lastPathComponent] 
stringByDeletingPathExtension] stringByAppendingPathExtension:@"pdf"];
         NSString *pdfFile = nil;
         
-        if ([subfiles containsObject:fileName]) {
+        if ([files containsObject:fileName]) {
             pdfFile = fileName;
         } else {
-            unsigned int index = [[subfiles 
valueForKeyPath:@"pathExtension.lowercaseString"] indexOfObject:@"pdf"];
+            unsigned int index = [[files 
valueForKeyPath:@"pathExtension.lowercaseString"] indexOfObject:@"pdf"];
             if (index != NSNotFound)
-                pdfFile = [subfiles objectAtIndex:index];
+                pdfFile = [files objectAtIndex:index];
         }
         pdfFile = pdfFile ? [filePath stringByAppendingPathComponent:pdfFile] 
: nil;
         NSData *data = pdfFile ? [NSData dataWithContentsOfFile:pdfFile] : nil;
         if (data) {
-            QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)data, 
kUTTypePDF, (CFDictionaryRef)properties);
+            QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)data, 
kUTTypePDF, NULL);
         } else {
             err = 2;
         }
@@ -112,7 +106,7 @@
                     NSString *text = [[note objectForKey:@"text"] string];
                     NSColor *color = [note objectForKey:@"color"];
                     unsigned int pageIndex = [[note objectForKey:@"pageIndex"] 
unsignedIntValue];
-                    [htmlString appendFormat:@"<dt><img src=\"cid:%@.png\" 
style=\"background-color:#\" />%@ (page %i)</dt>", type, [color hexString], 
type, pageIndex+1];
+                    [htmlString appendFormat:@"<dt><img src=\"cid:%@.png\" 
style=\"background-color:[EMAIL PROTECTED]" />%@ (page %i)</dt>", type, 
hexStringWithColor(color), type, pageIndex+1];
                     [htmlString appendFormat:@"<dd>%@", contents];
                     if (text)
                         [htmlString appendFormat:@"<div 
class=\"note-text\">%@</div>", text];
@@ -128,63 +122,21 @@
             NSBundle *bundle = [NSBundle 
bundleWithIdentifier:@"net.sourceforge.skim-app.quicklookgenerator"];
             NSImage *image;
             
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"FreeText" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"FreeText.png"];
-            [imgProps release];
+            NSArray *allImageNames = [NSArray arrayWithObjects:@"FreeText", 
@"Note", @"Circle", @"Square", @"Highlight", @"Underline", @"StrikeOut", 
@"Line", nil];
+            NSString *imageName;
+            for (imageName in allImageNames) {
+                imgProps = [[NSMutableDictionary alloc] init];
+                image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:imageName ofType:@"png"]];
+                if (image) {
+                    [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
+                    [attachmentProps setObject:imgProps forKey:[imageName 
stringByAppendingPathExtension:@"png"]];
+                }
+                [imgProps release];
+            }
             
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"Note" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"Note.png"];
-            [imgProps release];
-            
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"Circle" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"Circle.png"];
-            [imgProps release];
-            
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"Square" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"Square.png"];
-            [imgProps release];
-            
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"Highlight" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"Highlight.png"];
-            [imgProps release];
-            
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"Underline" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"Underline.png"];
-            [imgProps release];
-            
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"StrikeOut" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"StrikeOut.png"];
-            [imgProps release];
-            
-            imgProps = [[NSMutableDictionary alloc] init];
-            image = [NSData dataWithContentsOfFile:[bundle 
pathForResource:@"Line" ofType:@"png"]];
-            [imgProps setObject:@"image/png" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];
-            [imgProps setObject:image forKey:(NSString 
*)kQLPreviewPropertyAttachmentDataKey];
-            [attachmentProps setObject:imgProps forKey:@"Line.png"];
-            [imgProps release];
-            
             [props setObject:attachmentProps forKey:(NSString 
*)kQLPreviewPropertyAttachmentsKey];
+            [attachmentProps release];
+            
             [props setObject:@"UTF-8" forKey:(NSString 
*)kQLPreviewPropertyTextEncodingNameKey];
             [props setObject:@"text/html" forKey:(NSString 
*)kQLPreviewPropertyMIMETypeKey];            
             
@@ -197,9 +149,7 @@
             err = 2;
         }
         
-static OSStatus hotKeyEventHandler(EventHandlerCallRef inHandlerRef, EventRef 
inEvent, void* refCon );
-    }
-    
+    }    
     [pool release];
     
     return err;

Modified: trunk/QuickLook-Skim/GenerateThumbnailForURL.m
===================================================================
--- trunk/QuickLook-Skim/GenerateThumbnailForURL.m      2007-11-24 20:10:44 UTC 
(rev 3253)
+++ trunk/QuickLook-Skim/GenerateThumbnailForURL.m      2007-11-24 20:36:26 UTC 
(rev 3254)
@@ -37,36 +37,22 @@
 #include <QuickLook/QuickLook.h>
 #import <Foundation/Foundation.h>
 
[EMAIL PROTECTED] NSAttributedString (SKQLExtensions)
-+ (NSAttributedString *)imageAttachmentForType:(NSString *)type;
[EMAIL PROTECTED]
-
[EMAIL PROTECTED] NSAttributedString (SKQLExtensions)
-+ (NSAttributedString *)imageAttachmentForType:(NSString *)type {
-    static NSMutableDictionary *imageAttachments = nil;
+static NSAttributedString *imageAttachmentForType(NSString *type)
+{        
+    NSBundle *bundle = [NSBundle 
bundleWithIdentifier:@"net.sourceforge.skim-app.quicklookgenerator"];
+    NSImage *image = [[NSImage alloc] initWithContentsOfFile:[bundle 
pathForResource:@"Note" ofType:@"png"]];
+    NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:[image TIFFRepresentation]];
+    [image release];
+    [wrapper setPreferredFilename:[NSString stringWithFormat:@"[EMAIL 
PROTECTED]", type]];
     
-    NSAttributedString *attrString = nil;
-    if (attrString == nil) {
-        if (imageAttachments == nil)
-            imageAttachments = [[NSMutableDictionary alloc] init];
-        NSBundle *bundle = [NSBundle 
bundleWithIdentifier:@"net.sourceforge.skim-app.quicklookgenerator"];
-        NSImage *image = [[NSImage alloc] initWithContentsOfFile:[bundle 
pathForResource:@"Note" ofType:@"png"]];
-        NSFileWrapper *wrapper = [[NSFileWrapper alloc] 
initRegularFileWithContents:[image TIFFRepresentation]];
-        [wrapper setPreferredFilename:[NSString stringWithFormat:@"[EMAIL 
PROTECTED]", type]];
-        [image release];
-        
-        NSTextAttachment *attachment = [[NSTextAttachment alloc] 
initWithFileWrapper:wrapper];
-        [wrapper release];
-        attrString = [NSAttributedString 
attributedStringWithAttachment:attachment];
-        [imageAttachments setObject:attrString forKey:type];
-        [attachment release];
-    }
+    NSTextAttachment *attachment = [[NSTextAttachment alloc] 
initWithFileWrapper:wrapper];
+    [wrapper release];
+    NSAttributedString *attrString = [NSAttributedString 
attributedStringWithAttachment:attachment];
+    [attachment release];
     
     return attrString;
 }
[EMAIL PROTECTED]
 
-
 /* 
-----------------------------------------------------------------------------
     Generate a thumbnail for file
 
@@ -85,25 +71,39 @@
             
             NSString *filePath = [(NSURL *)url path];
             NSArray *files = [[NSFileManager defaultManager] 
subpathsAtPath:filePath];
-            NSString *fileName = [[[path stringByDeletingLastPathComponent] 
stringByDeletingPathExtension] stringByAppendingPathExtension:@"pdf"];
+            NSString *fileName = [[[filePath 
stringByDeletingLastPathComponent] stringByDeletingPathExtension] 
stringByAppendingPathExtension:@"pdf"];
             NSString *pdfFile = nil;
             
-            if ([subfiles containsObject:fileName]) {
+            if ([files containsObject:fileName]) {
                 pdfFile = fileName;
             } else {
-                unsigned int index = [[subfiles 
valueForKeyPath:@"pathExtension.lowercaseString"] indexOfObject:@"pdf"];
+                unsigned int index = [[files 
valueForKeyPath:@"pathExtension.lowercaseString"] indexOfObject:@"pdf"];
                 if (index != NSNotFound)
-                    pdfFile = [subfiles objectAtIndex:index];
+                    pdfFile = [files objectAtIndex:index];
             }
             if (pdfFile) {
+                // sadly, we can't use the system's QL generator from inside 
quicklookd, so we don't get the fancy binder on the left edge
                 pdfFile = [filePath stringByAppendingPathComponent:pdfFile];
-                CGImageRef image = QLThumbnailImageCreate(kCFAllocatorDefault, 
(CFURLRef)[NSURL fileURLWithPath:pdfFile], maxSize, options);
-                if (image != NULL) {
-                    CFDictionaryRef properties = CFDictionaryCreate(NULL, 
NULL, NULL, 0, NULL, NULL);
-                    QLThumbnailRequestSetImage(thumbnail, image, properties);
-                    CGImageRelease(image);
-                    CFRelease(properties);
-
+                CGPDFDocumentRef pdfDoc = 
CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:pdfFile]);
+                CGPDFPageRef pdfPage = NULL;
+                if (pdfDoc && CGPDFDocumentGetNumberOfPages(pdfDoc) > 0)
+                    pdfPage = CGPDFDocumentGetPage(pdfDoc, 1);
+                
+                BOOL failed = NO;
+                if (pdfPage) {
+                    CGRect pageRect = CGPDFPageGetBoxRect(pdfPage, 
kCGPDFCropBox);
+                    CGContextRef ctxt = 
QLThumbnailRequestCreateContext(thumbnail, pageRect.size, FALSE, NULL);
+                    CGAffineTransform t = 
CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, pageRect, 0, true);
+                    CGContextConcatCTM(ctxt, t);
+                    CGContextClipToRect(ctxt, pageRect);
+                    CGContextDrawPDFPage(ctxt, pdfPage);
+                    QLThumbnailRequestFlushContext(thumbnail, ctxt);
+                }
+                else {
+                    failed = YES;
+                }
+                CGPDFDocumentRelease(pdfDoc);
+                if (NO == failed) {
                     // !!! early return
                     [pool release];
                     return noErr;
@@ -118,7 +118,8 @@
                 [data release];
                 
                 NSMutableAttributedString *attrString = 
[[NSMutableAttributedString alloc] init];
-                NSFont *font = [NSFont userFontOfSize:0.0];
+                // large font size for thumbnails
+                NSFont *font = [NSFont userFontOfSize:20.0];
                 NSFont *noteFont = [NSFont 
fontWithName:@"LucidaHandwriting-Italic" size:[font pointSize]];
                 NSFont *noteTextFont = [NSFont 
fontWithName:@"LucidaHandwriting-Italic" size:[font pointSize] - 2.0];
                 NSDictionary *attrs = [NSDictionary 
dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil];
@@ -140,7 +141,7 @@
                         unsigned int pageIndex = [[note 
objectForKey:@"pageIndex"] unsignedIntValue];
                         int start;
                         
-                        [attrString appendAttributedString:[NSAttributedString 
imageAttachmentForType:type]];
+                        [attrString 
appendAttributedString:imageAttachmentForType(type)];
                         [attrString 
addAttribute:NSBackgroundColorAttributeName value:color 
range:NSMakeRange([attrString length] - 1, 1)];
                         [attrString 
appendAttributedString:[[[NSAttributedString alloc] initWithString:[NSString 
stringWithFormat:@"%@ (page %i)\n", type, pageIndex+1] attributes:attrs] 
autorelease]];
                         start = [attrString length];

Modified: trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj       
2007-11-24 20:10:44 UTC (rev 3253)
+++ trunk/QuickLook-Skim/QuickLook-Skim.xcodeproj/project.pbxproj       
2007-11-24 20:36:26 UTC (rev 3254)
@@ -3,7 +3,7 @@
        archiveVersion = 1;
        classes = {
        };
-       objectVersion = 42;
+       objectVersion = 44;
        objects = {
 
 /* Begin PBXBuildFile section */

Modified: trunk/QuickLook-Skim/main.c
===================================================================
--- trunk/QuickLook-Skim/main.c 2007-11-24 20:10:44 UTC (rev 3253)
+++ trunk/QuickLook-Skim/main.c 2007-11-24 20:36:26 UTC (rev 3254)
@@ -121,9 +121,6 @@
 {
     CFUUIDRef theFactoryID;
     
-    extern void BDSKSpotlightIconControllerFreeStatics();
-    BDSKSpotlightIconControllerFreeStatics();
-    
     theFactoryID = thisInstance->factoryID;
         /* Free the conduitInterface table up */
     free(thisInstance->conduitInterface);


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to