Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old ttProgram.py used to check and fix PUSHs mnemonics #248

Closed
sansplomb opened this issue Apr 21, 2015 · 3 comments
Closed

old ttProgram.py used to check and fix PUSHs mnemonics #248

sansplomb opened this issue Apr 21, 2015 · 3 comments

Comments

@sansplomb
Copy link
Contributor

The old version of fontTools used to check and fix PUSHs mnemonics so that it did not matter what kind of PUSHW, PUSHB, NPUSHW, or NPUSHB was called.

This current version of fontTools implies a generic 'PUSH' instruction must be used to have the automatic selection of Word-or-Byte One-or-Many while the original fontTools was making that automatic selection anyway.

For backward compatibility reasons I suggest to add the automatic correction of the PUSH instructions

@behdad
Copy link
Member

behdad commented Apr 23, 2015

What's your exact usecase?

@sansplomb
Copy link
Contributor Author

In RoboFont with the old fontTools I had a case where I did push 11 elements to the stack with a simple PUSHW[ ] and it did not raise any errors (I assume it was corrected to NPUSHW[ ]).

Now with the latest fontTools, I got AssertionError: 11

Traceback (most recent call last):
File "lib/fontObjects/doodleFontCompiler/ttfCompiler.pyc", line 510, in compile
File "ufo2fdk/makeotfParts.pyc", line 64, in compile
File "ufo2fdk/makeotfParts.pyc", line 79, in setupFile_outlineSource
File "lib/fontObjects/doodleFontCompiler/ttfCompiler.pyc", line 257, in compile
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/init.py", line 214, in save
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/init.py", line 626, in _writeTable
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/init.py", line 626, in _writeTable
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/init.py", line 629, in _writeTable
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/init.py", line 642, in getTableData
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/tables/_g_l_y_f.py", line 70, in compile
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/tables/_g_l_y_f.py", line 325, in compile
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/tables/_g_l_y_f.py", line 556, in compileCoordinates
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/tables/ttProgram.py", line 220, in getBytecode
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontTools/ttLib/tables/ttProgram.py", line 370, in _assemble
AssertionError: 11

But in fact this was more a problem with my code so I fixed it with a function that gives me the right PUSH for each case:
def autoPush(args):
nArgs = len(args)
# Check and Fix mnemonic
if max(args) > 255 or min(args) < 0:
mnemonic = "PUSHW[ ]"
else:
mnemonic = "PUSHB[ ]"
if 8 < nArgs < 256:
mnemonic = "N" + mnemonic
elif nArgs >= 256:
raise tt_instructions_error, "More than 255 push arguments (%s)" % nArgs

return (' '.join([mnemonic]+[str(a) for a in args]))

@behdad
Copy link
Member

behdad commented Mar 16, 2016

Ah, somehow I never saw your last comment :(. Anyway, there's more discussion on this here:
#92

@behdad behdad closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants