2012-02-10 31 views
6

Làm cách nào để xóa biểu tượng cuộn tròn mà hình thu nhỏ tạo trong plugin xem nhanh?Xóa góc cuộn tròn khỏi hình thu nhỏ qlgenerator

Ảnh chụp màn hình của biểu tượng hiện tại: enter image description here

Ảnh chụp màn hình của những gì tôi muốn: enter image description here

GeneratePreviewForURL.m:

#include <CoreFoundation/CoreFoundation.h> 
#include <CoreServices/CoreServices.h> 
#include <QuickLook/QuickLook.h> 

#import "GenerateIcon.h" 

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options); 
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview); 

/* ----------------------------------------------------------------------------- 
    Generate a preview for file 

    This function's job is to create preview for designated file 
    ----------------------------------------------------------------------------- */ 

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) 
{ 
    // To complete your generator please implement the function GeneratePreviewForURL in GeneratePreviewForURL.c 

    [GenerateIcon generatePreviewWithRef:preview URL:url]; 

    return noErr; 
} 

void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) 
{ 
    // Implement only if supported 
} 

GenerateIcon.m:

// 
// GenerateIcon.m 
// Windows Binary Icon 
// 
// Created by Asger Hautop Drewsen on 2/5/12. 
// Copyright (c) 2012 Asger Drewsen. All rights reserved. 
// 

#import "GenerateIcon.h" 

@implementation GenerateIcon 

+(void) generateThumbnailWithRef:(QLThumbnailRequestRef)requestRef URL:(CFURLRef)url 
{ 
    [GenerateIcon generateMultiWithThumbnailRef:requestRef PreviewRef:nil URL:url]; 
} 
+(void) generatePreviewWithRef:(QLPreviewRequestRef)requestRef URL:(CFURLRef)url 
{ 
    [GenerateIcon generateMultiWithThumbnailRef:nil PreviewRef:requestRef URL:url]; 
} 

    +(void) generateMultiWithThumbnailRef:(QLThumbnailRequestRef)thumbnail PreviewRef:(QLPreviewRequestRef)preview URL:(CFURLRef)url 
{ 
    @autoreleasepool { 

     NSString * tempDir = NSTemporaryDirectory(); 
     if (tempDir == nil) 
      tempDir = @"/tmp"; 

     NSFileManager *fileManager = [[NSFileManager alloc] init]; 

     NSString *directory = [tempDir stringByAppendingFormat: [NSString stringWithFormat:@"%@-%.0f", @"exe-icons", [NSDate timeIntervalSinceReferenceDate] * 1000.0]]; 

     //NSString *directory = [tempDir stringByAppendingPathComponent:@"com.tyilo.exe-icons"]; 

     /*for (NSString *file in [fileManager contentsOfDirectoryAtPath:directory error:nil]) 
     { 
     [fileManager removeItemAtPath:file error:nil]; 
     }*/ 

     [fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:nil]; 

     [[NSTask launchedTaskWithLaunchPath:@"/usr/local/bin/wrestool" arguments:[NSArray arrayWithObjects: 
                        @"-t", 
                        @"group_icon", 
                        @"-o", 
                        directory, 
                        @"-x", 
                        [(__bridge NSURL *)url path], 
                        nil]] waitUntilExit]; 

     NSArray *icons = [fileManager contentsOfDirectoryAtPath:directory error:nil]; 

     if (icons.count > 0) 
     { 
      NSImage *image = [[NSImage alloc] initWithContentsOfFile:[directory stringByAppendingPathComponent: [icons objectAtIndex:0]]]; 
      NSData *thumbnailData = [image TIFFRepresentation]; 
      CGSize size = image.size; 
      NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys: 
             [NSNumber numberWithInt:size.width],kQLPreviewPropertyWidthKey, 
             [NSNumber numberWithInt:size.height],kQLPreviewPropertyHeightKey, 
             nil]; 
      CGContextRef CGContext; 
      if (thumbnail) 
      { 
       CGContext = QLThumbnailRequestCreateContext(thumbnail, size, TRUE, (__bridge CFDictionaryRef)properties); 
      } 
      else 
      { 
       CGContext = QLPreviewRequestCreateContext(preview, size, TRUE, (__bridge CFDictionaryRef)properties); 
      } 
      if(CGContext) { 
       NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:(void *)CGContext flipped:size.width > size.height]; 
       if(context) { 
        //These two lines of code are just good safe programming… 
        [NSGraphicsContext saveGraphicsState]; 
        [NSGraphicsContext setCurrentContext:context]; 

        NSBitmapImageRep *thumbnailBitmap = [NSBitmapImageRep imageRepWithData:thumbnailData]; 
        [thumbnailBitmap draw]; 

        //This line sets the context back to what it was when we're done 
        [NSGraphicsContext restoreGraphicsState]; 
       } 

       // When we are done with our drawing code QLThumbnailRequestFlushContext() is called to flush the context 
       if (thumbnail) 
       { 
        QLThumbnailRequestFlushContext(thumbnail, CGContext); 
       } 
       else 
       { 
        QLPreviewRequestFlushContext(preview, CGContext); 
       } 

       // Release the CGContext 
       CFRelease(CGContext); 
      } 
      /*NSLog(@"%@", [directory stringByAppendingPathComponent: [icons objectAtIndex:0]]); 
      CGImageRef image = (__bridge CGImageRef) [[NSImage alloc] initByReferencingFile:[directory stringByAppendingPathComponent: [icons objectAtIndex:0]]]; 
      QLThumbnailRequestSetImage(thumbnail, image, properties);*/ 
     } 
     else 
     { 
      NSLog(@"Failed to generate thumbnail!"); 
     } 
    } 
} 

@end 

Chỉnh sửa: Đã thêm ảnh chụp màn hình.

+0

Bạn có tìm thấy giải pháp cho việc này không? – Mark

+0

@Mark Không, tôi chưa bao giờ làm. – Tyilo

Trả lời

0

Khía cạnh của các biểu tượng của bạn được chọn tự động bằng Quick Look và không có cách nào công khai để tùy chỉnh điều đó. Cây phù hợp loại của bạn là gì?

Để biết thêm thông tin về UTI, hãy xem Uniform Type Identifiers Overview. Lưu ý rằng cây phù hợp loại của bạn sẽ không nhất thiết phải dịch sang những gì bạn muốn từ Quick Look nhưng ít nhất bạn sẽ có một điểm khởi đầu lành mạnh.

+1

Tôi chỉ muốn loại bỏ các góc cong và tôi không có ý tưởng những gì bạn vừa viết – Tyilo

+0

Khía cạnh của các biểu tượng được tạo ra bởi Quick Look được suy ra từ việc khai báo kiểu của bạn (ví dụ: bao gồm cả thời gian để đặt một góc cong). Khi bạn khai báo UTI của bạn, bạn cần phải xác định sự phù hợp kiểu của bạn (UTTypeConformsTo). Câu hỏi của tôi là: loại của riêng bạn phù hợp với những gì? – Julien

+0

Hiện tại, nó tuân theo 'public.item', tuy nhiên nó chỉ hoạt động với các tệp exe. Tôi có nên đổi nó thành cái gì khác không? – Tyilo

5

Tôi sắp đến trễ một chút với câu hỏi này!

Bạn cần thêm khóa "IconFlavor" chưa được lấy giấy phép vào từ điển thuộc tính mà bạn cung cấp cho QLThumbnailRequestCreateContext() hoặc QLThumbnailRequestSetXXX() và đặt giá trị 1 cho trang trí tối thiểu.

Xem here để biết ví dụ. Ở đầu tệp đó là một số giá trị khác mà tôi đã phát hiện cho "IconFlavour".

+0

Hoàn hảo! Bạn, thưa bạn, xứng đáng là một huy chương. Làm thế nào bạn phát hiện ra điều đó? Nhân tiện, kQLThumbnailIconPlainFlavor có kết quả tốt hơn cho các biểu tượng exe hơn kQLThumbnailIconShadowFlavor. – vitormm