- removed support for Python 2.2 on MacOS 10.2
- worked around a bug in GetCreatorType() on intel Macs
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@526 4cde692c-a291-49d1-8350-778aa11640f8
diff --git a/Lib/fontTools/misc/macCreatorType.py b/Lib/fontTools/misc/macCreatorType.py
new file mode 100644
index 0000000..57d158c
--- /dev/null
+++ b/Lib/fontTools/misc/macCreatorType.py
@@ -0,0 +1,33 @@
+import sys
+try:
+ import MacOS
+except ImportError:
+ MacOS = None
+
+def _reverseString(s):
+ s = list(s)
+ s.reverse()
+ return "".join(s)
+
+
+def getMacCreatorAndType(path):
+ if MacOS is not None:
+ fileCreator, fileType = MacOS.GetCreatorAndType(path)
+ if sys.byteorder == "little":
+ # work around bug in MacOS.GetCreatorAndType() on intel:
+ # http://bugs.python.org/issue1594
+ fileCreator = _reverseString(fileCreator)
+ fileType = _reverseString(fileType)
+ return fileCreator, fileType
+ else:
+ return None, None
+
+
+def setMacCreatorAndType(path, fileCreator, fileType):
+ if MacOS is not None:
+ if sys.byteorder == "little":
+ # work around bug in MacOS.SetCreatorAndType() on intel:
+ # http://bugs.python.org/issue1594
+ fileCreator = _reverseString(fileCreator)
+ fileType = _reverseString(fileType)
+ MacOS.SetCreatorAndType(path, fileCreator, fileType)
diff --git a/Lib/fontTools/t1Lib.py b/Lib/fontTools/t1Lib.py
index 25dbc3d..6a14440 100644
--- a/Lib/fontTools/t1Lib.py
+++ b/Lib/fontTools/t1Lib.py
@@ -21,6 +21,7 @@
DEBUG = 0
from fontTools.misc import eexec
+from fontTools.misc.macCreatorType import getMacCreatorAndType
import string
import re
import os
@@ -102,10 +103,9 @@
def read(path, onlyHeader=0):
"""reads any Type 1 font file, returns raw data"""
normpath = string.lower(path)
- if haveMacSupport:
- creator, type = MacOS.GetCreatorAndType(path)
- if type == 'LWFN':
- return readLWFN(path, onlyHeader), 'LWFN'
+ creator, type = getMacCreatorAndType(path)
+ if type == 'LWFN':
+ return readLWFN(path, onlyHeader), 'LWFN'
if normpath[-4:] == '.pfb':
return readPFB(path, onlyHeader), 'PFB'
else:
@@ -252,8 +252,6 @@
f.write(chr(128) + chr(3))
finally:
f.close()
- if haveMacSupport:
- MacOS.SetCreatorAndType(path, 'mdos', 'BINA')
def writeOther(path, data, dohex = 0):
chunks = findEncryptedChunks(data)
@@ -274,8 +272,6 @@
f.write(chunk)
finally:
f.close()
- if haveMacSupport:
- MacOS.SetCreatorAndType(path, 'R*ch', 'TEXT') # BBEdit text file
# decryption tools
diff --git a/Lib/fontTools/ttx.py b/Lib/fontTools/ttx.py
index 1e2ab93..4116877 100644
--- a/Lib/fontTools/ttx.py
+++ b/Lib/fontTools/ttx.py
@@ -58,18 +58,13 @@
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables.otBase import OTLOffsetOverflowError
from fontTools.ttLib.tables.otTables import fixLookupOverFlows, fixSubTableOverFlows
+from fontTools.misc.macCreatorType import getMacCreatorAndType
from fontTools import version
def usage():
print __doc__ % version
sys.exit(2)
-
-if sys.platform == "darwin" and sys.version_info[:3] == (2, 2, 0):
- # the Mac support of Jaguar's Python 2.2 is broken
- have_broken_macsupport = 1
-else:
- have_broken_macsupport = 0
numberAddedRE = re.compile("(.*)#\d+$")
@@ -218,17 +213,11 @@
f = open(fileName, "rb")
except IOError:
return None
- if not have_broken_macsupport:
- try:
- import MacOS
- except ImportError:
- pass
- else:
- cr, tp = MacOS.GetCreatorAndType(fileName)
- if tp in ("sfnt", "FFIL"):
- return "TTF"
- if ext == ".dfont":
- return "TTF"
+ 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":