Revision: 4972
http://skim-app.svn.sourceforge.net/skim-app/?rev=4972&view=rev
Author: hofman
Date: 2008-11-19 14:16:12 +0000 (Wed, 19 Nov 2008)
Log Message:
-----------
Get the bundle for quicklook from the thumbnail/preview request
Modified Paths:
--------------
trunk/QuickLook-Skim/GeneratePreviewForURL.m
trunk/QuickLook-Skim/GenerateThumbnailForURL.m
trunk/QuickLook-Skim/SKQLConverter.h
trunk/QuickLook-Skim/SKQLConverter.m
Modified: trunk/QuickLook-Skim/GeneratePreviewForURL.m
===================================================================
--- trunk/QuickLook-Skim/GeneratePreviewForURL.m 2008-11-19 13:14:11 UTC
(rev 4971)
+++ trunk/QuickLook-Skim/GeneratePreviewForURL.m 2008-11-19 14:16:12 UTC
(rev 4972)
@@ -40,20 +40,23 @@
static const CGFloat _fontSize = 12.0;
-static NSDictionary *imageAttachments(NSSet *imageNames)
+static NSDictionary *imageAttachments(NSSet *imageNames, QLPreviewRequestRef
preview)
{
NSMutableDictionary *attachments = [NSMutableDictionary dictionary];
- NSBundle *bundle = SKQLGetMainBundle();
- NSString *imageName;
+ CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview);
NSMutableDictionary *imgProps;
- NSData *imgData;
- for (imageName in imageNames) {
- if (imgData = [NSData dataWithContentsOfFile:[bundle
pathForResource:imageName ofType:@"png"]]) {
- imgProps = [[NSMutableDictionary alloc] init];
- [imgProps setObject:imgData forKey:(NSString
*)kQLPreviewPropertyAttachmentDataKey];
- [attachments setObject:imgProps forKey:[imageName
stringByAppendingPathExtension:@"png"]];
- [imgProps release];
+ for (NSString *imageName in imageNames) {
+ NSURL *imgURL = (NSURL *)CFBundleCopyResourceURL(bundle,
(CFStringRef)imageName, CFSTR("png"), NULL);
+ if (imgURL) {
+ NSData *imgData = [NSData dataWithContentsOfURL:imgURL];
+ if (imgData) {
+ imgProps = [[NSMutableDictionary alloc] init];
+ [imgProps setObject:imgData forKey:(NSString
*)kQLPreviewPropertyAttachmentDataKey];
+ [attachments setObject:imgProps forKey:[imageName
stringByAppendingPathExtension:@"png"]];
+ [imgProps release];
+ }
+ [imgURL release];
}
}
return attachments;
@@ -93,7 +96,7 @@
NSDictionary *props = [NSDictionary
dictionaryWithObjectsAndKeys:
@"UTF-8", (NSString
*)kQLPreviewPropertyTextEncodingNameKey,
@"text/html", (NSString
*)kQLPreviewPropertyMIMETypeKey,
- imageAttachments(types), (NSString
*)kQLPreviewPropertyAttachmentsKey, nil];
+ imageAttachments(types, preview),
(NSString *)kQLPreviewPropertyAttachmentsKey, nil];
QLPreviewRequestSetDataRepresentation(preview,
(CFDataRef)data, kUTTypeHTML, (CFDictionaryRef)props);
err = noErr;
}
Modified: trunk/QuickLook-Skim/GenerateThumbnailForURL.m
===================================================================
--- trunk/QuickLook-Skim/GenerateThumbnailForURL.m 2008-11-19 13:14:11 UTC
(rev 4971)
+++ trunk/QuickLook-Skim/GenerateThumbnailForURL.m 2008-11-19 14:16:12 UTC
(rev 4972)
@@ -50,14 +50,15 @@
static const NSRect _iconRect = (NSRect) { { 50, 140 }, { 512, 512 } };
// wash the app icon over a white page background
-static void drawBackgroundAndApplicationIconInCurrentContext()
+static void
drawBackgroundAndApplicationIconInCurrentContext(QLThumbnailRequestRef
thumbnail)
{
[[NSColor whiteColor] setFill];
NSRect pageRect = { NSZeroPoint, _paperSize };
NSRectFillUsingOperation(pageRect, NSCompositeSourceOver);
- NSString *iconPath = [SKQLGetMainBundle() pathForResource:@"Skim"
ofType:@"icns"];
- NSImage *appIcon = [[NSImage alloc] initWithContentsOfFile:iconPath];
+ NSURL *iconURL = (NSURL
*)CFBundleCopyResourceURL(QLThumbnailRequestGetGeneratorBundle(thumbnail),
CFSTR("Skim"), CFSTR("icns"), NULL);
+ NSImage *appIcon = [[NSImage alloc] initWithContentsOfFile:[iconURL path]];
+ [iconURL release];
[appIcon drawInRect:_iconRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:0.3];
[appIcon release];
@@ -168,7 +169,7 @@
NSData *data = [[NSData alloc] initWithContentsOfURL:(NSURL *)url
options:NSUncachedRead error:NULL];
if (data) {
- NSAttributedString *attrString = [SKQLConverter
attributedStringWithNotes:[NSKeyedUnarchiver unarchiveObjectWithData:data]];
+ NSAttributedString *attrString = [SKQLConverter
attributedStringWithNotes:[NSKeyedUnarchiver unarchiveObjectWithData:data]
forThumbnail:thumbnail];
[data release];
if (attrString) {
@@ -177,7 +178,7 @@
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:nsContext];
- drawBackgroundAndApplicationIconInCurrentContext();
+ drawBackgroundAndApplicationIconInCurrentContext(thumbnail);
drawAttributedStringInCurrentContext(attrString);
QLThumbnailRequestFlushContext(thumbnail, ctxt);
Modified: trunk/QuickLook-Skim/SKQLConverter.h
===================================================================
--- trunk/QuickLook-Skim/SKQLConverter.h 2008-11-19 13:14:11 UTC (rev
4971)
+++ trunk/QuickLook-Skim/SKQLConverter.h 2008-11-19 14:16:12 UTC (rev
4972)
@@ -32,11 +32,11 @@
*/
#import <Cocoa/Cocoa.h>
+#include <QuickLook/QuickLook.h>
-extern NSBundle *SKQLGetMainBundle();
extern NSString *SKQLPDFPathForPDFBundleURL(NSURL *url);
@interface SKQLConverter : NSObject
-+ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes;
++ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes
forThumbnail:(QLThumbnailRequestRef)thumbnail;
+ (NSString *)htmlStringWithNotes:(NSArray *)notes;
@end
Modified: trunk/QuickLook-Skim/SKQLConverter.m
===================================================================
--- trunk/QuickLook-Skim/SKQLConverter.m 2008-11-19 13:14:11 UTC (rev
4971)
+++ trunk/QuickLook-Skim/SKQLConverter.m 2008-11-19 14:16:12 UTC (rev
4972)
@@ -39,8 +39,6 @@
static const CGFloat _fontSize = 20.0;
static const CGFloat _smallFontSize = 10.0;
-NSBundle *SKQLGetMainBundle() { return [NSBundle
bundleWithIdentifier:@"net.sourceforge.skim-app.quicklookgenerator"]; }
-
NSString *SKQLPDFPathForPDFBundleURL(NSURL *url)
{
NSString *filePath = [url path];
@@ -58,10 +56,10 @@
return pdfFile ? [filePath stringByAppendingPathComponent:pdfFile] : nil;
}
-static NSAttributedString *imageAttachmentForType(NSString *type)
+static NSAttributedString *imageAttachmentForPath(NSString *path)
{
- NSFileWrapper *wrapper = [[NSFileWrapper alloc]
initWithPath:[SKQLGetMainBundle() pathForResource:type ofType:@"png"]];
- [wrapper setPreferredFilename:[type
stringByAppendingPathExtension:@"png"]];
+ NSFileWrapper *wrapper = [[NSFileWrapper alloc] initWithPath:path];
+ [wrapper setPreferredFilename:[path lastPathComponent]];
NSTextAttachment *attachment = [[NSTextAttachment alloc]
initWithFileWrapper:wrapper];
[wrapper release];
@@ -142,7 +140,7 @@
@implementation SKQLConverter
-+ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes;
++ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes
forThumbnail:(QLThumbnailRequestRef)thumbnail;
{
NSMutableAttributedString *attrString = [[[NSMutableAttributedString
alloc] init] autorelease];
NSFont *font = [NSFont userFontOfSize:_fontSize];
@@ -157,6 +155,7 @@
[noteParStyle setHeadIndent:_noteIndent];
if (notes) {
+ CFBundleRef bundle = QLThumbnailRequestGetGeneratorBundle(thumbnail);
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc]
initWithKey:@"pageIndex" ascending:YES] autorelease];
NSEnumerator *noteEnum = [[notes sortedArrayUsingDescriptors:[NSArray
arrayWithObject:sortDescriptor]] objectEnumerator];
NSDictionary *note;
@@ -166,9 +165,10 @@
NSString *text = [[note objectForKey:@"text"] string];
NSColor *color = [note objectForKey:@"color"];
unsigned int pageIndex = [[note objectForKey:@"pageIndex"]
unsignedIntValue];
+ NSURL *imgURL = [(NSURL *)CFBundleCopyResourceURL(bundle,
(CFStringRef)type, CFSTR("png"), NULL) autorelease];
int start;
- [attrString appendAttributedString:imageAttachmentForType(type)];
+ [attrString appendAttributedString:imageAttachmentForPath([imgURL
path])];
[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];
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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit