From d12f09201e167a1829b158f90bfb4c503214c13f Mon Sep 17 00:00:00 2001 From: David Whetstone Date: Thu, 24 Feb 2011 11:50:40 -0800 Subject: [PATCH] Envy Code R no longer required to build Use Monaco if Envy Code R is unavailable during the document icon generation phase. Call 'make getenvy' inside the icons/ folder to manually download Envy Code R. --- src/MacVim/icons/Makefile | 6 ++++-- src/MacVim/icons/make_icons.py | 33 +++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/MacVim/icons/Makefile b/src/MacVim/icons/Makefile index 2754670904..8b697c7bd1 100644 --- a/src/MacVim/icons/Makefile +++ b/src/MacVim/icons/Makefile @@ -1,14 +1,16 @@ -.PHONY: clean +.PHONY: clean getenvy OUTDIR ?= . -$(OUTDIR)/MacVim-generic.icns: make_icons.py vim-noshadow-512.png loadfont.so Envy\ Code\ R\ Bold.ttf +$(OUTDIR)/MacVim-generic.icns: make_icons.py vim-noshadow-512.png loadfont.so $(MAKE) -C makeicns /usr/bin/python make_icons.py $(OUTDIR) loadfont.so: loadfont.c /usr/bin/python setup.py install --install-lib . +getenvy: Envy\ Code\ R\ Bold.ttf + Envy\ Code\ R\ Bold.ttf: EnvyCodeR.zip unzip -jo EnvyCodeR.zip # unzip uses the file date from the zip file. Change the file date to diff --git a/src/MacVim/icons/make_icons.py b/src/MacVim/icons/make_icons.py index a83a4bef44..49d6f6340f 100644 --- a/src/MacVim/icons/make_icons.py +++ b/src/MacVim/icons/make_icons.py @@ -1,5 +1,11 @@ # Creates all of MacVim document icons. +import os +import sys + +fontname = '' +facename = None + # http://www.macresearch.org/cocoa-scientists-part-xx-python-scriptersmeet-cocoa try: # Make us independent of sysprefs->appearance->antialias fonts smaller than... @@ -9,12 +15,7 @@ try: prefs.setInteger_forKey_(4, 'AppleAntiAliasingThreshold') import docerator - - # Load Envy Code R from a file and register it under its postscript name - # Thanks to DamienG for this font (redistributed with permission): - # http://damieng.com/blog/2008/05/26/envy-code-r-preview-7-coding-font-released import loadfont - loadfont.loadfont('Envy Code R Bold.ttf') from Foundation import NSString from AppKit import * @@ -24,9 +25,6 @@ except Exception, e: print e dont_create = True # most likely because we're on tiger -import os -import sys - # icon types LARGE = 0 # 512, 128, 32, 16; about 96kB @@ -119,7 +117,6 @@ def createLinks(icons, target): os.remove(icnsName) os.symlink(target, icnsName) - if not dont_create: # define a few classes to render custom 16x16 icons @@ -135,9 +132,10 @@ if not dont_create: class SmallTextRenderer(docerator.TextRenderer): def _attribsAtSize(self, s): + global facename attribs = docerator.TextRenderer._attribsAtSize(self, s) - if s == 16: - font = NSFont.fontWithName_size_('EnvyCodeR-Bold', 7.0) + if s == 16 and facename is not None: + font = NSFont.fontWithName_size_(facename, 7.0) assert font attribs[NSFontAttributeName] = font attribs[NSForegroundColorAttributeName] = \ @@ -157,7 +155,6 @@ if not dont_create: attribs[NSKernAttributeName] = -1 # we need all the room we can get text.drawInRect_withAttributes_( ((1, 2), (15, 11)), attribs) - def main(): if dont_create: print "PyObjC not found, only using a stock icon for document icons." @@ -168,6 +165,18 @@ def main(): '%s.icns' % GENERIC_ICON_NAME) return + # choose an icon font + global fontname, facename + # Thanks to DamienG for Envy Code R (redistributed with permission): + # http://damieng.com/blog/2008/05/26/envy-code-r-preview-7-coding-font-released + fonts = [('Envy Code R Bold.ttf', 'EnvyCodeR-Bold'), + ('/System/Library/Fonts/Monaco.dfont', 'Monaco')] + for font in fonts: + if loadfont.loadfont(font[0]): + fontname, facename = font + break + print "Building icons with font '" + fontname + "'." + srcdir = os.getcwd() if len(sys.argv) > 1: os.chdir(sys.argv[1])