[t1Lib] use macRes.ResourceReader to read 'POST' resources from LWFN;
add comment about Res.FSpCreateResFile being deprecated since OS X 10.5 (a resource file writer would be nice, by low priority)
This commit is contained in:
parent
f41838edfe
commit
fb6efd0f23
@ -142,13 +142,11 @@ HEXLINELENGTH = 80
|
|||||||
|
|
||||||
def readLWFN(path, onlyHeader=False):
|
def readLWFN(path, onlyHeader=False):
|
||||||
"""reads an LWFN font file, returns raw data"""
|
"""reads an LWFN font file, returns raw data"""
|
||||||
resRef = Res.FSOpenResFile(path, 1) # read-only
|
from fontTools.misc.macRes import ResourceReader
|
||||||
|
reader = ResourceReader(path)
|
||||||
try:
|
try:
|
||||||
Res.UseResFile(resRef)
|
|
||||||
n = Res.Count1Resources('POST')
|
|
||||||
data = []
|
data = []
|
||||||
for i in range(501, 501 + n):
|
for res in reader.get('POST', []):
|
||||||
res = Res.Get1Resource('POST', i)
|
|
||||||
code = byteord(res.data[0])
|
code = byteord(res.data[0])
|
||||||
if byteord(res.data[1]) != 0:
|
if byteord(res.data[1]) != 0:
|
||||||
raise T1Error('corrupt LWFN file')
|
raise T1Error('corrupt LWFN file')
|
||||||
@ -167,7 +165,7 @@ def readLWFN(path, onlyHeader=False):
|
|||||||
else:
|
else:
|
||||||
raise T1Error('bad chunk code: ' + repr(code))
|
raise T1Error('bad chunk code: ' + repr(code))
|
||||||
finally:
|
finally:
|
||||||
Res.CloseResFile(resRef)
|
reader.close()
|
||||||
data = bytesjoin(data)
|
data = bytesjoin(data)
|
||||||
assertType1(data)
|
assertType1(data)
|
||||||
return data
|
return data
|
||||||
@ -215,6 +213,7 @@ def readOther(path):
|
|||||||
# file writing tools
|
# file writing tools
|
||||||
|
|
||||||
def writeLWFN(path, data):
|
def writeLWFN(path, data):
|
||||||
|
# Res.FSpCreateResFile was deprecated in OS X 10.5
|
||||||
Res.FSpCreateResFile(path, "just", "LWFN", 0)
|
Res.FSpCreateResFile(path, "just", "LWFN", 0)
|
||||||
resRef = Res.FSOpenResFile(path, 2) # write-only
|
resRef = Res.FSOpenResFile(path, 2) # write-only
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user