re-added progress support, to be tested
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@183 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
1288f8ad41
commit
9b7b8e0f5b
@ -5,6 +5,8 @@ from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
|||||||
|
|
||||||
class TTXParseError(Exception): pass
|
class TTXParseError(Exception): pass
|
||||||
|
|
||||||
|
BUFSIZE = 0x4000
|
||||||
|
|
||||||
|
|
||||||
class ExpatParser:
|
class ExpatParser:
|
||||||
|
|
||||||
@ -13,7 +15,6 @@ class ExpatParser:
|
|||||||
self.progress = progress
|
self.progress = progress
|
||||||
self.root = None
|
self.root = None
|
||||||
self.contentStack = []
|
self.contentStack = []
|
||||||
self.lastpos = 0
|
|
||||||
self.stackSize = 0
|
self.stackSize = 0
|
||||||
|
|
||||||
def parseFile(self, file):
|
def parseFile(self, file):
|
||||||
@ -24,15 +25,18 @@ class ExpatParser:
|
|||||||
parser.EndElementHandler = self.endElementHandler
|
parser.EndElementHandler = self.endElementHandler
|
||||||
parser.CharacterDataHandler = self.characterDataHandler
|
parser.CharacterDataHandler = self.characterDataHandler
|
||||||
|
|
||||||
parser.ParseFile(file)
|
pos = 0
|
||||||
|
while 1:
|
||||||
|
chunk = file.read(BUFSIZE)
|
||||||
|
if not chunk:
|
||||||
|
parser.Parse(chunk, 1)
|
||||||
|
break
|
||||||
|
pos = pos + len(chunk)
|
||||||
|
if self.progress:
|
||||||
|
self.progress.set(pos / 100)
|
||||||
|
parser.Parse(chunk, 0)
|
||||||
|
|
||||||
def startElementHandler(self, name, attrs):
|
def startElementHandler(self, name, attrs):
|
||||||
if 0 and self.progress:
|
|
||||||
# XXX
|
|
||||||
pos = self.locator.pos + self.locator.block_offset
|
|
||||||
if (pos - self.lastpos) > 4000:
|
|
||||||
self.progress.set(pos / 100)
|
|
||||||
self.lastpos = pos
|
|
||||||
stackSize = self.stackSize
|
stackSize = self.stackSize
|
||||||
self.stackSize = self.stackSize + 1
|
self.stackSize = self.stackSize + 1
|
||||||
if not stackSize:
|
if not stackSize:
|
||||||
@ -105,6 +109,9 @@ def importXML(ttFont, fileName, progress=None):
|
|||||||
"""Import a TTX file (an XML-based text format), so as to recreate
|
"""Import a TTX file (an XML-based text format), so as to recreate
|
||||||
a font object.
|
a font object.
|
||||||
"""
|
"""
|
||||||
|
if progress:
|
||||||
|
import stat
|
||||||
|
progress.set(0, os.stat(fileName)[stat.ST_SIZE] / 100 or 1)
|
||||||
p = ExpatParser(ttFont, progress)
|
p = ExpatParser(ttFont, progress)
|
||||||
file = open(fileName)
|
file = open(fileName)
|
||||||
p.parseFile(file)
|
p.parseFile(file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user