cff: Use new exceptions
Aliases for the old errors will stay because the AFDKO and maybe others use them.
This commit is contained in:
parent
5a53d1d4ad
commit
5b5c964b0f
@ -1,5 +1,4 @@
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import os
|
|
||||||
from fontTools.cffLib import (
|
from fontTools.cffLib import (
|
||||||
maxStackLimit,
|
maxStackLimit,
|
||||||
TopDictIndex,
|
TopDictIndex,
|
||||||
@ -21,6 +20,13 @@ from fontTools.varLib.models import allEqual
|
|||||||
from fontTools.misc.psCharStrings import T2CharString, T2OutlineExtractor
|
from fontTools.misc.psCharStrings import T2CharString, T2OutlineExtractor
|
||||||
from fontTools.pens.t2CharStringPen import T2CharStringPen, t2c_round
|
from fontTools.pens.t2CharStringPen import T2CharStringPen, t2c_round
|
||||||
|
|
||||||
|
from .errors import VarLibCFFDictMergeError, VarLibCFFPointTypeMergeError, VarLibMergeError
|
||||||
|
|
||||||
|
|
||||||
|
# Backwards compatibility
|
||||||
|
MergeDictError = VarLibCFFDictMergeError
|
||||||
|
MergeTypeError = VarLibCFFPointTypeMergeError
|
||||||
|
|
||||||
|
|
||||||
def addCFFVarStore(varFont, varModel, varDataList, masterSupports):
|
def addCFFVarStore(varFont, varModel, varDataList, masterSupports):
|
||||||
fvarTable = varFont['fvar']
|
fvarTable = varFont['fvar']
|
||||||
@ -126,16 +132,6 @@ def convertCFFtoCFF2(varFont):
|
|||||||
del varFont['CFF ']
|
del varFont['CFF ']
|
||||||
|
|
||||||
|
|
||||||
class MergeDictError(TypeError):
|
|
||||||
def __init__(self, key, value, values):
|
|
||||||
error_msg = ["For the Private Dict key '{}', ".format(key),
|
|
||||||
"the default font value list:",
|
|
||||||
"\t{}".format(value),
|
|
||||||
"had a different number of values than a region font:"]
|
|
||||||
error_msg += ["\t{}".format(region_value) for region_value in values]
|
|
||||||
error_msg = os.linesep.join(error_msg)
|
|
||||||
|
|
||||||
|
|
||||||
def conv_to_int(num):
|
def conv_to_int(num):
|
||||||
if isinstance(num, float) and num.is_integer():
|
if isinstance(num, float) and num.is_integer():
|
||||||
return int(num)
|
return int(num)
|
||||||
@ -219,7 +215,7 @@ def merge_PrivateDicts(top_dicts, vsindex_dict, var_model, fd_map):
|
|||||||
try:
|
try:
|
||||||
values = zip(*values)
|
values = zip(*values)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise MergeDictError(key, value, values)
|
raise VarLibCFFDictMergeError(key, value, values)
|
||||||
"""
|
"""
|
||||||
Row 0 contains the first value from each master.
|
Row 0 contains the first value from each master.
|
||||||
Convert each row from absolute values to relative
|
Convert each row from absolute values to relative
|
||||||
@ -426,21 +422,6 @@ def merge_charstrings(glyphOrder, num_masters, top_dicts, masterModel):
|
|||||||
return cvData
|
return cvData
|
||||||
|
|
||||||
|
|
||||||
class MergeTypeError(TypeError):
|
|
||||||
def __init__(self, point_type, pt_index, m_index, default_type, glyphName):
|
|
||||||
self.error_msg = [
|
|
||||||
"In glyph '{gname}' "
|
|
||||||
"'{point_type}' at point index {pt_index} in master "
|
|
||||||
"index {m_index} differs from the default font point "
|
|
||||||
"type '{default_type}'"
|
|
||||||
"".format(
|
|
||||||
gname=glyphName,
|
|
||||||
point_type=point_type, pt_index=pt_index,
|
|
||||||
m_index=m_index, default_type=default_type)
|
|
||||||
][0]
|
|
||||||
super(MergeTypeError, self).__init__(self.error_msg)
|
|
||||||
|
|
||||||
|
|
||||||
def makeRoundNumberFunc(tolerance):
|
def makeRoundNumberFunc(tolerance):
|
||||||
if tolerance < 0:
|
if tolerance < 0:
|
||||||
raise ValueError("Rounding tolerance must be positive")
|
raise ValueError("Rounding tolerance must be positive")
|
||||||
@ -547,7 +528,7 @@ class CFF2CharStringMergePen(T2CharStringPen):
|
|||||||
else:
|
else:
|
||||||
cmd = self._commands[self.pt_index]
|
cmd = self._commands[self.pt_index]
|
||||||
if cmd[0] != point_type:
|
if cmd[0] != point_type:
|
||||||
raise MergeTypeError(
|
raise VarLibCFFPointTypeMergeError(
|
||||||
point_type,
|
point_type,
|
||||||
self.pt_index, len(cmd[1]),
|
self.pt_index, len(cmd[1]),
|
||||||
cmd[0], self.glyphName)
|
cmd[0], self.glyphName)
|
||||||
@ -560,7 +541,7 @@ class CFF2CharStringMergePen(T2CharStringPen):
|
|||||||
else:
|
else:
|
||||||
cmd = self._commands[self.pt_index]
|
cmd = self._commands[self.pt_index]
|
||||||
if cmd[0] != hint_type:
|
if cmd[0] != hint_type:
|
||||||
raise MergeTypeError(hint_type, self.pt_index, len(cmd[1]),
|
raise VarLibCFFPointTypeMergeError(hint_type, self.pt_index, len(cmd[1]),
|
||||||
cmd[0], self.glyphName)
|
cmd[0], self.glyphName)
|
||||||
cmd[1].append(args)
|
cmd[1].append(args)
|
||||||
self.pt_index += 1
|
self.pt_index += 1
|
||||||
@ -576,7 +557,7 @@ class CFF2CharStringMergePen(T2CharStringPen):
|
|||||||
else:
|
else:
|
||||||
cmd = self._commands[self.pt_index]
|
cmd = self._commands[self.pt_index]
|
||||||
if cmd[0] != hint_type:
|
if cmd[0] != hint_type:
|
||||||
raise MergeTypeError(hint_type, self.pt_index, len(cmd[1]),
|
raise VarLibCFFPointTypeMergeError(hint_type, self.pt_index, len(cmd[1]),
|
||||||
cmd[0], self.glyphName)
|
cmd[0], self.glyphName)
|
||||||
self.pt_index += 1
|
self.pt_index += 1
|
||||||
cmd = self._commands[self.pt_index]
|
cmd = self._commands[self.pt_index]
|
||||||
@ -646,8 +627,8 @@ class CFF2CharStringMergePen(T2CharStringPen):
|
|||||||
# second has only args.
|
# second has only args.
|
||||||
if lastOp in ['hintmask', 'cntrmask']:
|
if lastOp in ['hintmask', 'cntrmask']:
|
||||||
coord = list(cmd[1])
|
coord = list(cmd[1])
|
||||||
assert allEqual(coord), (
|
if not allEqual(coord):
|
||||||
"hintmask values cannot differ between source fonts.")
|
raise VarLibMergeError("Hintmask values cannot differ between source fonts.")
|
||||||
cmd[1] = [coord[0][0]]
|
cmd[1] = [coord[0][0]]
|
||||||
else:
|
else:
|
||||||
coords = cmd[1]
|
coords = cmd[1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user