/usr/lib/python3/dist-packages/fontMath/mathGuideline.py is in python3-fontmath 0.4.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | from fontMath.mathFunctions import factorAngle, _roundNumber
__all__ = [
"_expandGuideline",
"_compressGuideline",
"_pairGuidelines",
"_processMathOneGuidelines",
"_processMathTwoGuidelines",
"_roundGuidelines"
]
def _expandGuideline(guideline):
guideline = dict(guideline)
x = guideline.get("x")
y = guideline.get("y")
# horizontal
if x is None:
guideline["x"] = 0
guideline["angle"] = 0
# vertical
elif y is None:
guideline["y"] = 0
guideline["angle"] = 90
return guideline
def _compressGuideline(guideline):
guideline = dict(guideline)
x = guideline["x"]
y = guideline["y"]
angle = guideline["angle"]
# horizontal
if x == 0 and angle in (0, 180):
guideline["x"] = None
guideline["angle"] = None
# vertical
elif y == 0 and angle in (90, 270):
guideline["y"] = None
guideline["angle"] = None
return guideline
def _pairGuidelines(guidelines1, guidelines2):
guidelines1 = list(guidelines1)
guidelines2 = list(guidelines2)
pairs = []
# name + identifier + (x, y, angle)
_findPair(guidelines1, guidelines2, pairs, ("name", "identifier", "x", "y", "angle"))
# name + identifier matches
_findPair(guidelines1, guidelines2, pairs, ("name", "identifier"))
# name + (x, y, angle)
_findPair(guidelines1, guidelines2, pairs, ("name", "x", "y", "angle"))
# identifier + (x, y, angle)
_findPair(guidelines1, guidelines2, pairs, ("identifier", "x", "y", "angle"))
# name matches
if guidelines1 and guidelines2:
_findPair(guidelines1, guidelines2, pairs, ("name",))
# identifier matches
if guidelines1 and guidelines2:
_findPair(guidelines1, guidelines2, pairs, ("identifier",))
# done
return pairs
def _findPair(guidelines1, guidelines2, pairs, attrs):
removeFromGuidelines1 = []
for guideline1 in guidelines1:
match = None
for guideline2 in guidelines2:
attrMatch = False not in [guideline1.get(attr) == guideline2.get(attr) for attr in attrs]
if attrMatch:
match = guideline2
break
if match is not None:
guideline2 = match
removeFromGuidelines1.append(guideline1)
guidelines2.remove(guideline2)
pairs.append((guideline1, guideline2))
for removeGuide in removeFromGuidelines1:
guidelines1.remove(removeGuide)
def _processMathOneGuidelines(guidelinePairs, ptFunc, func):
result = []
for guideline1, guideline2 in guidelinePairs:
guideline = dict(guideline1)
pt1 = (guideline1["x"], guideline1["y"])
pt2 = (guideline2["x"], guideline2["y"])
guideline["x"], guideline["y"] = ptFunc(pt1, pt2)
angle1 = guideline1["angle"]
angle2 = guideline2["angle"]
guideline["angle"] = func(angle1, angle2) % 360
result.append(guideline)
return result
def _processMathTwoGuidelines(guidelines, factor, func):
result = []
for guideline in guidelines:
guideline = dict(guideline)
guideline["x"] = func(guideline["x"], factor[0])
guideline["y"] = func(guideline["y"], factor[1])
angle = guideline["angle"]
guideline["angle"] = factorAngle(angle, factor, func) % 360
result.append(guideline)
return result
def _roundGuidelines(guidelines, digits=None):
results = []
for guideline in guidelines:
guideline = dict(guideline)
guideline['x'] = _roundNumber(guideline['x'], digits)
guideline['y'] = _roundNumber(guideline['y'], digits)
results.append(guideline)
return results
if __name__ == "__main__":
import sys
import doctest
sys.exit(doctest.testmod().failed)
|