Exemplo n.º 1
0
def guessFileType(fileName):
	base, ext = os.path.splitext(fileName)
	try:
		f = open(fileName, "rb")
	except IOError:
		return None
	cr, tp = getMacCreatorAndType(fileName)
	if tp in ("sfnt", "FFIL"):
		return "TTF"
	if ext == ".dfont":
		return "TTF"
	header = f.read(256)
	head = Tag(header[:4])
	if head == "OTTO":
		return "OTF"
	elif head == "ttcf":
		return "TTC"
	elif head in ("\0\1\0\0", "true"):
		return "TTF"
	elif head == "wOFF":
		return "WOFF"
	elif head == "wOF2":
		return "WOFF2"
	elif head.lower() == "<?xm":
		# Use 'latin1' because that can't fail.
		header = tostr(header, 'latin1')
		if opentypeheaderRE.search(header):
			return "OTX"
		else:
			return "TTX"
	return None
Exemplo n.º 2
0
def guessFileType(fileName):
    base, ext = os.path.splitext(fileName)
    try:
        f = open(fileName, "rb")
    except IOError:
        return None
    cr, tp = getMacCreatorAndType(fileName)
    if tp in ("sfnt", "FFIL"):
        return "TTF"
    if ext == ".dfont":
        return "TTF"
    header = f.read(256)
    head = Tag(header[:4])
    if head == "OTTO":
        return "OTF"
    elif head == "ttcf":
        return "TTC"
    elif head in ("\0\1\0\0", "true"):
        return "TTF"
    elif head == "wOFF":
        return "WOFF"
    elif head.lower() == "<?xm":
        # Use 'latin1' because that can't fail.
        header = tostr(header, 'latin1')
        if opentypeheaderRE.search(header):
            return "OTX"
        else:
            return "TTX"
    return None
Exemplo n.º 3
0
def guessFileType(fileName):
    base, ext = os.path.splitext(fileName)
    try:
        with open(fileName, "rb") as f:
            header = f.read(256)
    except IOError:
        return None

    if header.startswith(b'\xef\xbb\xbf<?xml'):
        header = header.lstrip(b'\xef\xbb\xbf')
    cr, tp = getMacCreatorAndType(fileName)
    if tp in ("sfnt", "FFIL"):
        return "TTF"
    if ext == ".dfont":
        return "TTF"
    head = Tag(header[:4])
    if head == "OTTO":
        return "OTF"
    elif head == "ttcf":
        return "TTC"
    elif head in ("\0\1\0\0", "true"):
        return "TTF"
    elif head == "wOFF":
        return "WOFF"
    elif head == "wOF2":
        return "WOFF2"
    elif head == "<?xm":
        # Use 'latin1' because that can't fail.
        header = tostr(header, 'latin1')
        if opentypeheaderRE.search(header):
            return "OTX"
        else:
            return "TTX"
    return None
Exemplo n.º 4
0
def guessFileType(fileName):
    base, ext = os.path.splitext(fileName)
    try:
        f = open(fileName, "rb")
    except IOError:
        return None
    cr, tp = getMacCreatorAndType(fileName)
    if tp in ("sfnt", "FFIL"):
        return "TTF"
    if ext == ".dfont":
        return "TTF"
    header = f.read(256)
    head = header[:4]
    if head == "OTTO":
        return "OTF"
    elif head == "ttcf":
        return "TTC"
    elif head in ("\0\1\0\0", "true"):
        return "TTF"
    elif head.lower() == "<?xm":
        if header.find('sfntVersion="OTTO"') > 0:
            return "OTX"
        else:
            return "TTX"
    return None
Exemplo n.º 5
0
def guessFileType(fileName):
	base, ext = os.path.splitext(fileName)
	try:
		f = open(fileName, "rb")
	except IOError:
		return None
	cr, tp = getMacCreatorAndType(fileName)
	if tp in ("sfnt", "FFIL"):
		return "TTF"
	if ext == ".dfont":
		return "TTF"
	header = f.read(256)
	head = header[:4]
	if head == "OTTO":
		return "OTF"
	elif head == "ttcf":
		return "TTC"
	elif head in ("\0\1\0\0", "true"):
		return "TTF"
	elif head.lower() == "<?xm":
		if opentypeheaderRE.search(header):
			return "OTX"
		else:
			return "TTX"
	return None
Exemplo n.º 6
0
def read(path, onlyHeader=False):
	"""reads any Type 1 font file, returns raw data"""
	normpath = path.lower()
	creator, typ = getMacCreatorAndType(path)
	if typ == 'LWFN':
		return readLWFN(path, onlyHeader), 'LWFN'
	if normpath[-4:] == '.pfb':
		return readPFB(path, onlyHeader), 'PFB'
	else:
		return readOther(path), 'OTHER'
Exemplo n.º 7
0
Arquivo: t1Lib.py Projeto: wondie/stdm
def read(path, onlyHeader=0):
    """reads any Type 1 font file, returns raw data"""
    normpath = string.lower(path)
    creator, type = getMacCreatorAndType(path)
    if type == 'LWFN':
        return readLWFN(path, onlyHeader), 'LWFN'
    if normpath[-4:] == '.pfb':
        return readPFB(path, onlyHeader), 'PFB'
    else:
        return readOther(path), 'OTHER'
Exemplo n.º 8
0
def read(path, onlyHeader=0):
    """reads any Type 1 font file, returns raw data"""
    normpath = string.lower(path)
    creator, type = getMacCreatorAndType(path)
    if type == "LWFN":
        return readLWFN(path, onlyHeader), "LWFN"
    if normpath[-4:] == ".pfb":
        return readPFB(path, onlyHeader), "PFB"
    else:
        return readOther(path), "OTHER"
Exemplo n.º 9
0
def read(path, onlyHeader=False):
    """reads any Type 1 font file, returns raw data"""
    _, ext = os.path.splitext(path)
    ext = ext.lower()
    creator, typ = getMacCreatorAndType(path)
    if typ == 'LWFN':
        return readLWFN(path, onlyHeader), 'LWFN'
    if ext == '.pfb':
        return readPFB(path, onlyHeader), 'PFB'
    else:
        return readOther(path), 'OTHER'
Exemplo n.º 10
0
def read(path, onlyHeader=False):
	"""reads any Type 1 font file, returns raw data"""
	_, ext = os.path.splitext(path)
	ext = ext.lower()
	creator, typ = getMacCreatorAndType(path)
	if typ == 'LWFN':
		return readLWFN(path, onlyHeader), 'LWFN'
	if ext == '.pfb':
		return readPFB(path, onlyHeader), 'PFB'
	else:
		return readOther(path), 'OTHER'
Exemplo n.º 11
0
def getFontType(fileName):
    base, ext = os.path.splitext(fileName)
    try:
        _file = open(fileName, "rb")
    except IOError:
        return None
    header = _file.read(256)
    _file.close()
    cr, tp = getMacCreatorAndType(fileName)
    if tp in ("sfnt", "FFIL"):
        return "TTF"
    head = Tag(header[:4])
    if head == "OTTO":
        return "OTF"
    elif head in ("\0\1\0\0", "true"):
        return "TTF"
    return None
Exemplo n.º 12
0
def getFeatureTagsForFontName(fontName):
    featureTags = []
    font = AppKit.NSFont.fontWithName_size_(fontName, 12)
    if font is None:
        return featureTags
    fontDescriptor = font.fontDescriptor()
    url = CoreText.CTFontDescriptorCopyAttribute(fontDescriptor, CoreText.kCTFontURLAttribute)
    psFontName = CoreText.CTFontDescriptorCopyAttribute(fontDescriptor, CoreText.kCTFontNameAttribute)
    if url is None or psFontName is None:
        return featureTags
    path = url.path()
    ext = os.path.splitext(path)[1].lower()
    macType = getMacCreatorAndType(path)[1]
    if ext in (".ttc", ".otc"):
        ft = _getTTFontFromTTC(path, psFontName)
    elif ext in (".ttf", ".otf"):
        ft = TTFont(path, lazy=True)
    elif ext == ".dfont" or macType == "FFIL":
        ft = _getTTFontFromSuitcase(path, psFontName)
        if ft is None:
            return featureTags
    else:
        return featureTags
    featureTags = set()
    if "GPOS" in ft and ft["GPOS"].table.FeatureList is not None:
        for record in ft["GPOS"].table.FeatureList.FeatureRecord:
            featureTags.add(record.FeatureTag)
    if "GSUB" in ft and ft["GSUB"].table.FeatureList is not None:
        for record in ft["GSUB"].table.FeatureList.FeatureRecord:
            featureTags.add(record.FeatureTag)
    if "feat" in ft:
        for featureName in ft["feat"].table.FeatureNames.FeatureName:
            for featureSetting in featureName.Settings.Setting:
                featureTag = SFNTLayoutTypes.reversedFeatureMap.get((featureName.FeatureType, featureSetting.SettingValue))
                if featureTag:
                    featureTag = featureTag.replace("_off", "")
                    featureTags.add(featureTag)
    ft.close()
    return list(sorted(featureTags))