pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/robotools/fontMath/pull/245/files

"https://github.githubassets.com/assets/primer-primitives-6da842159062d25e.css" /> Test groups for equality before doing fontMath kerning math by benkiel · Pull Request #245 · robotools/fontMath · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Lib/fontMath/mathKerning.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class kerning dictionary.

class MathKerning(object):

def __init__(self, kerning=None, groups=None):
def __init__(self, kerning=None, groups=None, strictGroups=False):
if kerning is None:
kerning = {}
if groups is None:
groups = {}
self.update(kerning)
self.updateGroups(groups)
self.strictGroups = strictGroups

# -------
# Loading
Expand Down Expand Up @@ -168,15 +169,18 @@ def __sub__(self, other):
return k

def _processMathOne(self, other, funct):
g1 = self.groups()
g2 = other.groups()
if self.strictGroups or other.strictGroups:
if g1 != g2:
raise ValueError("Kerning groups must be exactly the same.")
comboPairs = set(self._kerning.keys()) | set(other._kerning.keys())
kerning = dict.fromkeys(comboPairs, None)
for k in comboPairs:
v1 = self.get(k)
v2 = other.get(k)
v = funct(v1, v2)
kerning[k] = v
g1 = self.groups()
g2 = other.groups()
if g1 == g2 or not g1 or not g2:
groups = g1 or g2
else:
Expand Down
98 changes: 96 additions & 2 deletions Lib/fontMath/test/test_mathKerning.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,37 @@ def test_copy(self):
obj2 = obj1.copy()
self.assertEqual(sorted(obj1.items()), sorted(obj2.items()))

def test_add(self):
def test_add_different_groups_strict(self):
kerning1 = {
("A", "A"): 1,
("B", "B"): 1,
("NotIn2", "NotIn2"): 1,
("public.kern1.NotIn2", "C"): 1,
("public.kern1.D", "public.kern2.D"): 1,
}
groups1 = {
"public.kern1.NotIn1": ["C"],
"public.kern1.D": ["D", "H"],
"public.kern2.D": ["D", "H"],
}
kerning2 = {
("A", "A"): -1,
("B", "B"): 1,
("NotIn1", "NotIn1"): 1,
("public.kern1.NotIn1", "C"): 1,
("public.kern1.D", "public.kern2.D"): 1,
}
groups2 = {
"public.kern1.NotIn2": ["C"],
"public.kern1.D": ["D", "H"],
"public.kern2.D": ["D", "H"],
}
with self.assertRaises(ValueError):
obj = MathKerning(kerning1, groups1, strictGroups=True) + MathKerning(kerning2, groups2)
with self.assertRaises(ValueError):
obj = MathKerning(kerning1, groups1) + MathKerning(kerning2, groups2, strictGroups=True)

def test_add_different_groups(self):
kerning1 = {
("A", "A"): 1,
("B", "B"): 1,
Expand Down Expand Up @@ -195,7 +225,37 @@ def test_add_same_groups(self):
obj.groups()["public.kern2.D"],
['D', 'H'])

def test_sub(self):
def test_sub_different_groups_strict(self):
kerning1 = {
("A", "A"): 1,
("B", "B"): 1,
("NotIn2", "NotIn2"): 1,
("public.kern1.NotIn2", "C"): 1,
("public.kern1.D", "public.kern2.D"): 1,
}
groups1 = {
"public.kern1.NotIn1": ["C"],
"public.kern1.D": ["D", "H"],
"public.kern2.D": ["D", "H"],
}
kerning2 = {
("A", "A"): -1,
("B", "B"): 1,
("NotIn1", "NotIn1"): 1,
("public.kern1.NotIn1", "C"): 1,
("public.kern1.D", "public.kern2.D"): 1,
}
groups2 = {
"public.kern1.NotIn2": ["C"],
"public.kern1.D": ["D"],
"public.kern2.D": ["D", "H"],
}
with self.assertRaises(ValueError):
obj = MathKerning(kerning1, groups1, strictGroups=True) - MathKerning(kerning2, groups2)
with self.assertRaises(ValueError):
obj = MathKerning(kerning1, groups1) - MathKerning(kerning2, groups2, strictGroups=True)

def test_sub_different_groups(self):
kerning1 = {
("A", "A"): 1,
("B", "B"): 1,
Expand Down Expand Up @@ -235,6 +295,40 @@ def test_sub(self):
obj.groups()["public.kern2.D"],
['D', 'H'])

def test_sub_same_groups(self):
kerning1 = {
("A", "A"): 1,
("B", "B"): 1,
("NotIn2", "NotIn2"): 1,
("public.kern1.D", "public.kern2.D"): 1,
}
groups1 = {
"public.kern1.D": ["D", "H"],
"public.kern2.D": ["D", "H"],
}
kerning2 = {
("A", "A"): -1,
("B", "B"): 1,
("NotIn1", "NotIn1"): 1,
("public.kern1.D", "public.kern2.D"): 1,
}
groups2 = {
"public.kern1.D": ["D"],
"public.kern2.D": ["D", "H"],
}
obj = MathKerning(kerning1, groups1) - MathKerning(kerning2, groups2)
self.assertEqual(
sorted(obj.items()),
[(('A', 'A'), 2),
(('NotIn1', 'NotIn1'), -1),
(('NotIn2', 'NotIn2'), 1)])
self.assertEqual(
obj.groups()["public.kern1.D"],
['D', 'H'])
self.assertEqual(
obj.groups()["public.kern2.D"],
['D', 'H'])

def test_mul(self):
kerning = {
("A", "A"): 0,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy