def loadGlyphsInfo():
	try:
		GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.GeorgSeifert.Glyphs2")
		if GlyphsPath is None:
			GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.GeorgSeifert.Glyphs")
		if GlyphsPath is None:
			GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.schriftgestaltung.Glyphs")
		if GlyphsPath is None:
			GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.schriftgestaltung.GlyphsMini")
		GlyphsPath = GlyphsPath.path()
	except:
		return
	
	if GlyphsPath is not None:
		GlyphsInfoPath = GlyphsPath+"/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/GlyphData.xml"
		WeightCodesPath = GlyphsPath+"/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/weights.plist"
	
	parseGlyphDataFile(GlyphsInfoPath)
	
	CustomGlyphsInfoPath = applicationSupportFolder()
	if CustomGlyphsInfoPath:
		CustomGlyphsInfoPath = CustomGlyphsInfoPath.stringByAppendingPathComponent_("/Info/GlyphData.xml")
		if os.path.isfile(CustomGlyphsInfoPath):
			parseGlyphDataFile(CustomGlyphsInfoPath)
	
	global weightCodes
	weightCodes = NSDictionary.alloc().initWithContentsOfFile_(WeightCodesPath)
def readGlyphsFile(filePath):
	print "Import Glyphs File"
	pool = NSAutoreleasePool.alloc().init()
	GlyphsDoc = NSDictionary.alloc().initWithContentsOfFile_(filePath)
	if GlyphsDoc is None:
		print "Could not load .glyphs file."
		pool.drain()
		return
	loadGlyphsInfo()
	from FL import fl, Font
	folder, base = os.path.split(filePath)
	base = base.replace(".glyphs", ".vfb")
	dest = os.path.join(folder, base)
	f = Font(  )
	fl.Add(f)
	global convertName
	try:
		convertName = GlyphsDoc["disablesNiceNames"] != None
	except:
		pass
	if not setFontInfo(f, GlyphsDoc):
		return False
	readGlyphs(f, GlyphsDoc)
	readKerning(f, GlyphsDoc)
	setLegacyNames(f)
	readFeatures(f, GlyphsDoc)
	
	fl.UpdateFont()
	f.modified = 0
	pool.drain()
示例#3
0
def loadGlyphsInfo():
    try:
        GlyphsPath = NSWorkspace.sharedWorkspace(
        ).URLForApplicationWithBundleIdentifier_("com.GeorgSeifert.Glyphs")
        if GlyphsPath is None:
            GlyphsPath = NSWorkspace.sharedWorkspace(
            ).URLForApplicationWithBundleIdentifier_(
                "com.schriftgestaltung.Glyphs")
        if GlyphsPath is None:
            GlyphsPath = NSWorkspace.sharedWorkspace(
            ).URLForApplicationWithBundleIdentifier_(
                "com.schriftgestaltung.GlyphsMini")
        GlyphsPath = GlyphsPath.path()
    except:
        return

    if GlyphsPath is not None:
        GlyphsInfoPath = GlyphsPath + "/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/GlyphData.xml"
        WeightCodesPath = GlyphsPath + "/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/weights.plist"

    parseGlyphDataFile(GlyphsInfoPath)

    CustomGlyphsInfoPath = applicationSupportFolder()
    if CustomGlyphsInfoPath:
        CustomGlyphsInfoPath = CustomGlyphsInfoPath.stringByAppendingPathComponent_(
            "/Info/GlyphData.xml")
        if os.path.isfile(CustomGlyphsInfoPath):
            parseGlyphDataFile(CustomGlyphsInfoPath)

    global weightCodes
    weightCodes = NSDictionary.alloc().initWithContentsOfFile_(WeightCodesPath)
示例#4
0
def readGlyphsFile(filePath):
    print "Import Glyphs File"
    pool = NSAutoreleasePool.alloc().init()
    GlyphsDoc = NSDictionary.alloc().initWithContentsOfFile_(filePath)

    loadGlyphsInfo()
    from FL import fl, Font
    folder, base = os.path.split(filePath)
    base = base.replace(".glyphs", ".vfb")
    dest = os.path.join(folder, base)
    f = Font()
    fl.Add(f)
    global convertName
    try:
        convertName = GlyphsDoc["disablesNiceNames"] != None
    except:
        pass
    if not setFontInfo(f, GlyphsDoc):
        return False
    readGlyphs(f, GlyphsDoc)
    readKerning(f, GlyphsDoc)
    setLegacyNames(f)
    readFeatures(f, GlyphsDoc)

    fl.UpdateFont()
    f.modified = 0
    pool.drain()
示例#5
0
def save_favservers(favs, path):
    # Prior to running code through NSKeyedArchiver, we want to strip out custom pyObjC subclass types
    temp_keys = favs.keys()
    fixed_values = [purify(favs[x]) for x in temp_keys]
    fixed_keys = [purify(x) for x in temp_keys]
    # Once everything is cleaned up, put it into a new NSDictionary
    formatted_favs = NSDictionary.alloc().initWithObjects_forKeys_(
        fixed_values, fixed_keys)
    return NSKeyedArchiver.archiveRootObject_toFile_(formatted_favs, path)
示例#6
0
    def __init__(self, plist_path=BOOKS_PLIST_PATH):
        if FMT_BINARY is None:
            if not NSDictionary is None:
                self.plist = NSDictionary.alloc().initWithContentsOfFile_(plist_path)
            else:
                self.plist = Ibex._ibex_plutil_read_xml(plist_path)
        else:
            self.plist = readPlist(plist_path)

        if self.plist is None:
            raise IbexError('%s: failed to read property list' % plist_path)
def readGlyphsFile(filePath):
    print "Import Glyphs File"
    pool = None
    try:
        from Foundation import NSAutoreleasePool, NSDictionary
    except ImportError:
        # on Windows, PyObjC is not available
        with open(filePath, "rb") as f:
            data = f.read()
        if data.startswith("<?xml"):
            # use the built-in plistlib module for XML plist
            from plistlib import readPlistFromString

            GlyphsDoc = readPlistFromString(data)
        else:
            # use glyphsLib's Parser for ASCII plist.
            # Download it from: https://github.com/googlei18n/glyphsLib
            from glyphsLib.parser import Parser

            GlyphsDoc = Parser(dict_type=dict).parse(data)
    else:
        # on OS X, use NSDictionary
        pool = NSAutoreleasePool.alloc().init()
        GlyphsDoc = NSDictionary.alloc().initWithContentsOfFile_(filePath)

    if not GlyphsDoc:
        print "Could not load .glyphs file."
        if pool:
            pool.drain()
        return

    from FL import fl, Font

    folder, base = os.path.split(filePath)
    base = base.replace(".glyphs", ".vfb")
    dest = os.path.join(folder, base)
    f = Font()
    fl.Add(f)
    global convertName
    try:
        convertName = GlyphsDoc["disablesNiceNames"] != None
    except:
        pass
    if not setFontInfo(f, GlyphsDoc):
        return False
    readGlyphs(f, GlyphsDoc)
    readKerning(f, GlyphsDoc)
    setLegacyNames(f)
    readFeatures(f, GlyphsDoc)

    fl.UpdateFont()
    f.modified = 0
    if pool:
        pool.drain()
示例#8
0
def create_favitem(url=None, name=None):
    if name is None:
        # Make the display name the same as the URL by default
        name = url
    props = {
        NSString.stringWithString_('com.apple.LSSharedFileList.OverrideIcon.OSType'):
        NSString.stringWithString_(u'srvr')
    }
    props = NSDictionary.alloc().initWithDictionary_(props)
    return SFLListItem.alloc().initWithName_URL_properties_(
        name,
        NSURL.alloc().initWithString_(url), props)
def readGlyphsFile(filePath):
	print "Import Glyphs File"
	pool = None
	try:
		from Foundation import NSAutoreleasePool, NSDictionary
	except ImportError:
		# on Windows, PyObjC is not available
		with open(filePath, 'rb') as f:
			data = f.read()
		if data.startswith("<?xml"):
			# use the built-in plistlib module for XML plist
			from plistlib import readPlistFromString
			GlyphsDoc = readPlistFromString(data)
		else:
			# use glyphsLib's Parser for ASCII plist.
			# Download it from: https://github.com/googlei18n/glyphsLib
			from glyphsLib.parser import Parser
			GlyphsDoc = Parser(dict_type=dict).parse(data)
	else:
		# on OS X, use NSDictionary
		pool = NSAutoreleasePool.alloc().init()
		GlyphsDoc = NSDictionary.alloc().initWithContentsOfFile_(filePath)

	if not GlyphsDoc:
		print "Could not load .glyphs file."
		if pool:
			pool.drain()
		return

	from FL import fl, Font
	folder, base = os.path.split(filePath)
	base = base.replace(".glyphs", ".vfb")
	dest = os.path.join(folder, base)
	f = Font(  )
	fl.Add(f)
	global convertName
	try:
		convertName = GlyphsDoc["disablesNiceNames"] != None
	except:
		pass
	if not setFontInfo(f, GlyphsDoc):
		return False
	readGlyphs(f, GlyphsDoc)
	readKerning(f, GlyphsDoc)
	setLegacyNames(f)
	readFeatures(f, GlyphsDoc)
	
	fl.UpdateFont()
	f.modified = 0
	if pool:
		pool.drain()
示例#10
0
def purify(obj):
    # This code ensures that certain data types are very definitely the ObjC versions
    d = dir(obj)
    if '__reversed__' in d:
        # list / NSArray
        return NSArray.alloc().initWithArray_(obj)
    elif 'items' in d:
        # dictionary / NSDictionary
        return NSDictionary.alloc().initWithDictionary_(obj)
    elif 'strip' in d:
        # string / NSString
        return NSString.alloc().initWithString_(obj)
    # Unhandled
    return obj
	def add(self, label, uri, index=-1):
		if label in self.labels:
			return
		if index == -1 or index > len(self.items):
			index = len(self.items)
		elif index < -1:
			index = 0
		new_item = NSDictionary.alloc().initWithDictionary_(
			dict(
				Name=NSString.alloc().initWithString_(label), 
				URL=NSString.alloc().initWithString_(uri)
			)
		)
		self.items.insert(index, new_item)
		self.labels.append(label)