>> Nico, have you used icns browser to examine those icon files. You'll
>> find that they contain more than just a 512^2 icon or smaller.
>
> Yes, I'm aware of that. Preview also displays the several sizes. I'm
> currently cooking up a program to create document icons.

The script is attached. I tested it with Preview's app icon and  
compared it to the document icons bundled with Preview.app. It's close.

To use this, drop the script into the directory containing  
vim_gloss.icns and execute it in Terminal. It will create a file  
called out.png. It's probably best to use a vim icon that doesn't have  
any shadow for this script (Bjorn, do you have a version of the icon  
without shadow?). I'm open for all kinds of comments. If there are  
none, I'll use this to create icons for all filetypes supported by vim  
tomorrow.

Nico


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

# Creates a document icon from an app icon and an optional text.

# The font is not quite right, use this script to create a document icon
# for 'PDF' and compare the D with the D in Preview's pdf.icns

# http://www.macresearch.org/cocoa-scientists-part-xx-python-scriptersmeet-cocoa
from Foundation import *
from AppKit import *


# Resources
BACKGROUND = '/System/Library/CoreServices/CoreTypes.bundle/' + \
    'Contents/Resources/GenericDocumentIcon.icns'  # might require leopard?

APPICON = 'vim_gloss.icns'

text = NSString.stringWithString_('C')


# Make us not crash
# http://www.cocoabuilder.com/archive/message/cocoa/2008/8/6/214964
NSApplicationLoad()


# Prepare input images
bg = NSImage.alloc().initWithContentsOfFile_(BACKGROUND)
icon = NSImage.alloc().initWithContentsOfFile_(APPICON)


# Prepare text format
style = NSMutableParagraphStyle.new()
style.setParagraphStyle_(NSParagraphStyle.defaultParagraphStyle())
style.setAlignment_(NSCenterTextAlignment)
# http://developer.apple.com/documentation/Cocoa/Conceptual/AttributedStrings/Articles/standardAttributes.html#//apple_ref/doc/uid/TP40004903
attribs = {
    NSParagraphStyleAttributeName: style,
    NSFontAttributeName: NSFont.fontWithName_size_('LucidaSans-Demi', 72.0),
    NSForegroundColorAttributeName: NSColor.colorWithDeviceWhite_alpha_(0.34, 1)
}


# Draw!
bg.lockFocus()
w, h = 289, 289
icon.drawInRect_fromRect_operation_fraction_(
    (((512-w)/2 + 1 + .5, 405 - h), (w, h)),
    ((.5, .5), (512, 512)), NSCompositeSourceOver, 1.0)
text.drawInRect_withAttributes_( ((0.5, 53.5), (511, 90)), attribs)
bg.unlockFocus()


# Save
# http://www.cocoadev.com/index.pl?NSImageToJPEG (this is retarded)
tmp = NSBitmapImageRep.imageRepWithData_(bg.TIFFRepresentation())
png = tmp.representationUsingType_properties_(NSPNGFileType, None)
png.writeToFile_atomically_('out.png', True)

#print NSFontManager.sharedFontManager().availableFonts()


Reply via email to