diff options
Diffstat (limited to 'Lib/fontTools/varLib/varStore.py')
-rw-r--r-- | Lib/fontTools/varLib/varStore.py | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/Lib/fontTools/varLib/varStore.py b/Lib/fontTools/varLib/varStore.py index 8a382df0..bcf81b39 100644 --- a/Lib/fontTools/varLib/varStore.py +++ b/Lib/fontTools/varLib/varStore.py @@ -5,7 +5,6 @@ from fontTools.varLib.builder import (buildVarRegionList, buildVarStore, buildVarRegion, buildVarData) from functools import partial from collections import defaultdict -from array import array def _getLocationKey(loc): @@ -375,12 +374,11 @@ class _Encoding(object): as a VarData.""" c = 6 while chars: - if chars & 3: + if chars & 0b1111: c += 2 - chars >>= 2 + chars >>= 4 return c - def _find_yourself_best_new_encoding(self, done_by_width): self.best_new_encoding = None for new_width in range(self.width+1, self.width+self.room+1): @@ -405,14 +403,31 @@ class _EncodingDict(dict): @staticmethod def _row_characteristics(row): """Returns encoding characteristics for a row.""" + longWords = False + chars = 0 i = 1 for v in row: if v: chars += i if not (-128 <= v <= 127): - chars += i * 2 - i <<= 2 + chars += i * 0b0010 + if not (-32768 <= v <= 32767): + longWords = True + break + i <<= 4 + + if longWords: + # Redo; only allow 2byte/4byte encoding + chars = 0 + i = 1 + for v in row: + if v: + chars += i * 0b0011 + if not (-32768 <= v <= 32767): + chars += i * 0b1100 + i <<= 4 + return chars @@ -423,7 +438,7 @@ def VarStore_optimize(self): # Check that no two VarRegions are the same; if they are, fold them. n = len(self.VarRegionList.Region) # Number of columns - zeroes = array('h', [0]*n) + zeroes = [0] * n front_mapping = {} # Map from old VarIdxes to full row tuples @@ -435,7 +450,7 @@ def VarStore_optimize(self): for minor,item in enumerate(data.Item): - row = array('h', zeroes) + row = list(zeroes) for regionIdx,v in zip(regionIndices, item): row[regionIdx] += v row = tuple(row) |