Revision: 25634 http://sourceforge.net/p/bibdesk/svn/25634 Author: hofman Date: 2021-03-20 19:38:29 +0000 (Sat, 20 Mar 2021) Log Message: ----------- Smaller thumbnail for search and cache files
Modified Paths: -------------- trunk/QuickLook-BibDesk/GenerateThumbnailForURL.m Modified: trunk/QuickLook-BibDesk/GenerateThumbnailForURL.m =================================================================== --- trunk/QuickLook-BibDesk/GenerateThumbnailForURL.m 2021-03-20 19:11:56 UTC (rev 25633) +++ trunk/QuickLook-BibDesk/GenerateThumbnailForURL.m 2021-03-20 19:38:29 UTC (rev 25634) @@ -47,11 +47,11 @@ // Same size as [[NSPrintInfo sharedPrintInfo] paperSize] on my system // NSPrintInfo must not be used in a non-main thread (and it's hellishly slow in some circumstances) static const NSSize _paperSize = (NSSize) { 612, 792 }; +static const NSSize _listSize = (NSSize) { 512, 512 }; // page margins 20 pt on all edges static const CGFloat _horizontalMargin = 20; static const CGFloat _verticalMargin = 20; -static const NSSize _containerSize = (NSSize) { 572, 762 }; // readable in Cover Flow view, and distinguishable as text in icon view static const CGFloat _fontSize = 20; @@ -176,22 +176,22 @@ } // wash the app icon over a white page background -static void drawBackgroundAndApplicationIconInCurrentContext(QLThumbnailRequestRef thumbnail) +static void drawBackgroundAndApplicationIconInCurrentContext(QLThumbnailRequestRef thumbnail, NSSize size) { [[NSColor whiteColor] setFill]; - NSRect pageRect = NSMakeRect(0, 0, _paperSize.width, _paperSize.height); + NSRect pageRect = NSMakeRect(0, 0, size.width, size.height); NSRectFillUsingOperation(pageRect, NSCompositeSourceOver); NSURL *iconURL = (NSURL *)CFBundleCopyResourceURL(QLThumbnailRequestGetGeneratorBundle(thumbnail), CFSTR("FolderPenIcon"), CFSTR("icns"), NULL); - NSImage *appIcon = [[NSImage alloc] initWithContentsOfFile:[iconURL path]]; + NSImage *appIcon = [[NSImage alloc] initWithContentsOfURL:iconURL]; [iconURL release]; NSRect iconRect = NSZeroRect; // draw the icon smaller than the text container - NSSize iconSize = NSMakeSize(_containerSize.width * 0.9, _containerSize.width * 0.9); + NSSize iconSize = NSMakeSize((size.width - 2 * _horizontalMargin) * 0.9, (size.width - 2 * _verticalMargin) * 0.9); iconRect.size = iconSize; - iconRect.origin.x = (_containerSize.width - iconSize.width) / 2; - iconRect.origin.y = (_containerSize.height - iconSize.height) / 2; + iconRect.origin.x = (size.width - iconSize.width) / 2; + iconRect.origin.y = (size.height - iconSize.height) / 2; [appIcon drawInRect:iconRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.3]; [appIcon release]; @@ -198,12 +198,12 @@ } // creates a new NSTextStorage/NSLayoutManager/NSTextContainer system suitable for drawing in a thread -static NSTextStorage *createTextStorage() +static NSTextStorage *createTextStorage(NSSize size) { NSTextStorage *textStorage = [[NSTextStorage alloc] init]; NSLayoutManager *lm = [[NSLayoutManager alloc] init]; NSTextContainer *tc = [[NSTextContainer alloc] init]; - [tc setContainerSize:_containerSize]; + [tc setContainerSize:NSMakeSize(size.width - 2 * _horizontalMargin, size.height - 2 * _verticalMargin)]; [lm addTextContainer:tc]; // don't let the layout manager use its threaded layout (see header) [lm setBackgroundLayoutEnabled:NO]; @@ -219,21 +219,21 @@ } // assumes that the current NSGraphicsContext is the destination -static void drawAttributedStringInCurrentContext(NSAttributedString *attrString) +static void drawAttributedStringInCurrentContext(NSAttributedString *attrString, NSSize size) { CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicsPort]; - NSTextStorage *textStorage = createTextStorage(); + NSTextStorage *textStorage = createTextStorage(size); [textStorage beginEditing]; [textStorage setAttributedString:attrString]; [textStorage endEditing]; NSRect stringRect = NSZeroRect; - stringRect.size = _paperSize; + stringRect.size = size; CGContextSaveGState(ctxt); - CGAffineTransform t1 = CGAffineTransformMakeTranslation(_horizontalMargin, _paperSize.height - _verticalMargin); + CGAffineTransform t1 = CGAffineTransformMakeTranslation(_horizontalMargin, size.height - _verticalMargin); CGAffineTransform t2 = CGAffineTransformMakeScale(1, -1); CGAffineTransform pageTransform = CGAffineTransformConcat(t2, t1); CGContextConcatCTM(ctxt, pageTransform); @@ -266,15 +266,15 @@ 4) flushes the context and disposes of it */ -static void drawIconForThumbnailWithAttributedString(QLThumbnailRequestRef thumbnail, NSAttributedString *attrString) +static void drawIconForThumbnailWithAttributedString(QLThumbnailRequestRef thumbnail, NSAttributedString *attrString, NSSize size) { - CGContextRef ctxt = QLThumbnailRequestCreateContext(thumbnail, *(CGSize *)&_paperSize, FALSE, NULL); + CGContextRef ctxt = QLThumbnailRequestCreateContext(thumbnail, *(CGSize *)&size, FALSE, NULL); NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:ctxt flipped:YES]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:nsContext]; - drawBackgroundAndApplicationIconInCurrentContext(thumbnail); - drawAttributedStringInCurrentContext(attrString); + drawBackgroundAndApplicationIconInCurrentContext(thumbnail, size); + drawAttributedStringInCurrentContext(attrString, size); QLThumbnailRequestFlushContext(thumbnail, ctxt); CGContextRelease(ctxt); @@ -291,7 +291,7 @@ NSAttributedString *attrString = createAttributedStringWithContentsOfURLByGuessingEncoding((NSURL *)url, isBibTeX); if (attrString) { - drawIconForThumbnailWithAttributedString(thumbnail, attrString); + drawIconForThumbnailWithAttributedString(thumbnail, attrString, _paperSize); [attrString release]; didGenerate = true; } @@ -300,23 +300,6 @@ return didGenerate; } -static bool generateThumbnailForItems(QLThumbnailRequestRef thumbnail, NSArray *items) -{ - bool didGenerate = false; - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - - NSAttributedString *attrString = createAttributedStringWithItems(items); - - if (attrString) { - drawIconForThumbnailWithAttributedString(thumbnail, attrString); - [attrString release]; - didGenerate = true; - } - [pool release]; - - return didGenerate; -} - // draws index card thumbnail for a metadata cache file static bool generateThumbnailForCacheFile(QLThumbnailRequestRef thumbnail, CFURLRef url, CGSize maxSize) { @@ -329,7 +312,7 @@ [values release]; if (attrString) { - drawIconForThumbnailWithAttributedString(thumbnail, attrString); + drawIconForThumbnailWithAttributedString(thumbnail, attrString, _listSize); [attrString release]; didGenerate = true; } @@ -350,7 +333,7 @@ [values release]; if (attrString) { - drawIconForThumbnailWithAttributedString(thumbnail, attrString); + drawIconForThumbnailWithAttributedString(thumbnail, attrString, _listSize); [attrString release]; didGenerate = true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit