Revision: 13505
          http://sourceforge.net/p/skim-app/code/13505
Author:   hofman
Date:     2023-06-23 23:01:37 +0000 (Fri, 23 Jun 2023)
Log Message:
-----------
Pass bundle rather than thumbnail, so we don't need import in header. Get 
attachment from type rather than path.

Modified Paths:
--------------
    trunk/QuickLook-Skim/GenerateThumbnailForURL.m
    trunk/QuickLook-Skim/SKQLConverter.h
    trunk/QuickLook-Skim/SKQLConverter.m

Modified: trunk/QuickLook-Skim/GenerateThumbnailForURL.m
===================================================================
--- trunk/QuickLook-Skim/GenerateThumbnailForURL.m      2023-06-23 22:46:12 UTC 
(rev 13504)
+++ trunk/QuickLook-Skim/GenerateThumbnailForURL.m      2023-06-23 23:01:37 UTC 
(rev 13505)
@@ -210,7 +210,7 @@
         
         if (data) {
             NSArray *notes = [SKQLConverter notesWithData:data];
-            NSAttributedString *attrString = [SKQLConverter 
attributedStringWithNotes:notes forThumbnail:thumbnail];
+            NSAttributedString *attrString = [SKQLConverter 
attributedStringWithNotes:notes 
bundle:QLThumbnailRequestGetGeneratorBundle(thumbnail)];
             [data release];
             
             if (attrString) {

Modified: trunk/QuickLook-Skim/SKQLConverter.h
===================================================================
--- trunk/QuickLook-Skim/SKQLConverter.h        2023-06-23 22:46:12 UTC (rev 
13504)
+++ trunk/QuickLook-Skim/SKQLConverter.h        2023-06-23 23:01:37 UTC (rev 
13505)
@@ -32,12 +32,11 @@
  */
 
 #import <Cocoa/Cocoa.h>
-#include <QuickLook/QuickLook.h>
 
 extern NSString *SKQLPDFPathForPDFBundleURL(NSURL *url);
 
 @interface SKQLConverter : NSObject
 + (NSArray *)notesWithData:(NSData *)data;
-+ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes 
forThumbnail:(QLThumbnailRequestRef)thumbnail;
++ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes 
bundle:(CFBundleRef)bundle;
 + (NSString *)htmlStringWithNotes:(NSArray *)notes;
 @end

Modified: trunk/QuickLook-Skim/SKQLConverter.m
===================================================================
--- trunk/QuickLook-Skim/SKQLConverter.m        2023-06-23 22:46:12 UTC (rev 
13504)
+++ trunk/QuickLook-Skim/SKQLConverter.m        2023-06-23 23:01:37 UTC (rev 
13505)
@@ -57,18 +57,20 @@
     return pdfFile ? [filePath stringByAppendingPathComponent:pdfFile] : nil;
 }
 
-static NSAttributedString *imageAttachmentForPath(NSString *path)
-{        
+static NSAttributedString *imageAttachmentForType(NSString *type, CFBundleRef 
bundle)
+{
     static NSMutableDictionary *imageWrappers = nil;
-    NSFileWrapper *wrapper = [imageWrappers objectForKey:path];
+    NSFileWrapper *wrapper = [imageWrappers objectForKey:type];
     
     if (wrapper == nil) {
+        CFURLRef imgURL = CFBundleCopyResourceURL(bundle, (CFStringRef)type, 
CFSTR("png"), NULL);
         if (imageWrappers == nil)
             imageWrappers = [[NSMutableDictionary alloc] init];
-        wrapper = [[NSFileWrapper alloc] initWithURL:[NSURL 
fileURLWithPath:path] options:0 error:NULL];
-        [wrapper setPreferredFilename:[path lastPathComponent]];
-        [imageWrappers setObject:wrapper forKey:path];
+        wrapper = [[NSFileWrapper alloc] initWithURL:(NSURL *)imgURL options:0 
error:NULL];
+        [wrapper setPreferredFilename:[type 
stringByAppendingPathExtension:@"png"]];
+        [imageWrappers setObject:wrapper forKey:type];
         [wrapper release];
+        if (imgURL) CFRelease(imgURL);
     }
     
     NSTextAttachment *attachment = [[NSTextAttachment alloc] 
initWithFileWrapper:wrapper];
@@ -179,7 +181,7 @@
     return [notes isKindOfClass:[NSArray class]] ? notes : nil;
 }
 
-+ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes 
forThumbnail:(QLThumbnailRequestRef)thumbnail;
++ (NSAttributedString *)attributedStringWithNotes:(NSArray *)notes 
bundle:(CFBundleRef)bundle;
 {
     NSMutableAttributedString *attrString = [[[NSMutableAttributedString 
alloc] init] autorelease];
     NSFont *font = [NSFont userFontOfSize:_fontSize];
@@ -194,7 +196,6 @@
     [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;
@@ -204,7 +205,6 @@
             NSAttributedString *text = [note objectForKey:@"text"];
             NSColor *color = [note objectForKey:@"color"];
             NSUInteger pageIndex = [[note objectForKey:@"pageIndex"] 
unsignedIntegerValue];
-            NSURL *imgURL = [(NSURL *)CFBundleCopyResourceURL(bundle, 
(CFStringRef)type, CFSTR("png"), NULL) autorelease];
             NSInteger start;
             
             if ([text isKindOfClass:[NSData class]])
@@ -212,7 +212,7 @@
             if ([color isKindOfClass:[NSArray class]])
                 color = colorFromArray((NSArray *)color);
             
-            [attrString appendAttributedString:imageAttachmentForPath([imgURL 
path])];
+            [attrString appendAttributedString:imageAttachmentForType(type, 
bundle)];
             [attrString addAttribute:NSBackgroundColorAttributeName 
value:color range:NSMakeRange([attrString length] - 1, 1)];
             [attrString appendAttributedString:[[[NSAttributedString alloc] 
initWithString:[NSString stringWithFormat:@"%@ (page %ld)\n", type, 
(long)(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.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to