Skip to content

Commit

Permalink
Remove duplicated pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
IdreesInc committed Feb 9, 2024
1 parent f46b41a commit e371f7c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 174 deletions.
9 changes: 5 additions & 4 deletions src/miracode.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

characters = generateDiacritics(characters, diacritics)
charactersByCodepoint = {}
for character in characters:
charactersByCodepoint[character["codepoint"]] = character

def generateFont():
miracode = fontforge.font()
Expand All @@ -50,7 +52,6 @@ def generateFont():
miracode.addLookupSubtable("ligatures", "ligatures-subtable")

for character in characters:
charactersByCodepoint[character["codepoint"]] = character
miracode.createChar(character["codepoint"], character["name"])
pen = miracode[character["name"]].glyphPen()
top = 0
Expand Down Expand Up @@ -110,7 +111,7 @@ def test():
passedTests = 0
failedTests = 0
for test in tests:
input = test["input"]
input = charactersByCodepoint[test["codepoint"]]["pixels"]
output = test["output"]
edgesPerPoint = getEdgesPerPoint(generateEdges(input))
failed = []
Expand All @@ -120,12 +121,12 @@ def test():
if output[row][col] != numOfEdges:
failed.append(((row, col), output[row][col], numOfEdges))
if len(failed) > 0:
print(f"💥 Test failed: {test['name']}")
print(f"💥 Test failed: {test['character']}")
for fail in failed:
print(f" Expected {fail[1]} edge(s) at {fail[0]}, got {fail[2]}")
failedTests += 1
else:
# print (f"✅ Test passed: {test['name']}")
# print (f"✅ Test passed: {test['character']}")
passedTests += 1
if failedTests == 0:
print("All tests passed! 🎉")
Expand Down
204 changes: 34 additions & 170 deletions src/tests.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
{
"tests": [
{
"name": "H",
"input": [
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1]
],
"character": "H",
"codepoint": 72,
"output": [
[1, 0, 0, 0, 1],
[2, 0, 0, 0, 2],
Expand All @@ -22,16 +14,8 @@
]
},
{
"name": "f",
"input": [
[0, 0, 0, 1, 1],
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 1],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0]
],
"character": "f",
"codepoint": 102,
"output": [
[0, 0, 0, 2, 1],
[0, 0, 2, 0, 0],
Expand All @@ -43,16 +27,8 @@
]
},
{
"name": "W",
"input": [
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 1, 0, 1],
[1, 1, 0, 1, 1],
[1, 0, 0, 0, 1]
],
"character": "W",
"codepoint": 87,
"output": [
[1, 0, 0, 0, 1],
[2, 0, 0, 0, 2],
Expand All @@ -64,16 +40,8 @@
]
},
{
"name": "w",
"input": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 1, 0, 1],
[1, 0, 1, 0, 1],
[0, 1, 1, 1, 1]
],
"character": "w",
"codepoint": 119,
"output": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
Expand All @@ -85,16 +53,8 @@
]
},
{
"name": "k",
"input": [
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 1, 0],
[1, 0, 1, 0, 0],
[1, 1, 0, 0, 0],
[1, 0, 1, 0, 0],
[1, 0, 0, 1, 0]
],
"character": "k",
"codepoint": 107,
"output": [
[1, 0, 0, 0, 0],
[2, 0, 0, 0, 0],
Expand All @@ -106,16 +66,8 @@
]
},
{
"name": "z",
"input": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[1, 1, 1, 1, 1],
[0, 0, 0, 1, 0],
[0, 0, 1, 0, 0],
[0, 1, 0, 0, 0],
[1, 1, 1, 1, 1]
],
"character": "z",
"codepoint": 122,
"output": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
Expand All @@ -127,16 +79,8 @@
]
},
{
"name": "M",
"input": [
[1, 0, 0, 0, 1],
[1, 1, 0, 1, 1],
[1, 0, 1, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1]
],
"character": "M",
"codepoint": 77,
"output": [
[2, 0, 0, 0, 2],
[2, 2, 0, 2, 2],
Expand All @@ -148,16 +92,8 @@
]
},
{
"name": "l",
"input": [
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
],
"character": "l",
"codepoint": 108,
"output": [
[0, 1, 2, 0, 0],
[0, 0, 2, 0, 0],
Expand All @@ -169,16 +105,8 @@
]
},
{
"name": "0",
"input": [
[0, 1, 1, 1, 0],
[1, 0, 0, 0, 1],
[1, 0, 0, 1, 1],
[1, 0, 1, 0, 1],
[1, 1, 0, 0, 1],
[1, 0, 0, 0, 1],
[0, 1, 1, 1, 0]
],
"character": "0",
"codepoint": 48,
"output": [
[0, 2, 2, 2, 0],
[2, 0, 0, 0, 3],
Expand All @@ -190,16 +118,8 @@
]
},
{
"name": "h",
"input": [
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 1, 1, 0],
[1, 1, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1]
],
"character": "h",
"codepoint": 104,
"output": [
[1, 0, 0, 0, 0],
[2, 0, 0, 0, 0],
Expand All @@ -211,16 +131,8 @@
]
},
{
"name": "u",
"input": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[0, 1, 1, 1, 1]
],
"character": "u",
"codepoint": 117,
"output": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
Expand All @@ -232,16 +144,8 @@
]
},
{
"name": "F",
"input": [
[1, 1, 1, 1, 1],
[1, 0, 0, 0, 0],
[1, 1, 1, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0]
],
"character": "F",
"codepoint": 70,
"output": [
[2, 2, 2, 2, 1],
[2, 0, 0, 0, 0],
Expand All @@ -253,16 +157,8 @@
]
},
{
"name": "5",
"input": [
[1, 1, 1, 1, 1],
[1, 0, 0, 0, 0],
[1, 1, 1, 1, 0],
[0, 0, 0, 0, 1],
[0, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[0, 1, 1, 1, 0]
],
"character": "5",
"codepoint": 53,
"output": [
[2, 2, 2, 2, 1],
[2, 0, 0, 0, 0],
Expand All @@ -274,16 +170,8 @@
]
},
{
"name": "1",
"input": [
[0, 0, 1, 0, 0],
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[1, 1, 1, 1, 1]
],
"character": "1",
"codepoint": 49,
"output": [
[0, 0, 2, 0, 0],
[0, 1, 2, 0, 0],
Expand All @@ -295,16 +183,8 @@
]
},
{
"name": "m",
"input": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[1, 1, 0, 1, 0],
[1, 0, 1, 0, 1],
[1, 0, 1, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1]
],
"character": "m",
"codepoint": 109,
"output": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
Expand All @@ -316,16 +196,8 @@
]
},
{
"name": "7",
"input": [
[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[0, 0, 0, 0, 1],
[0, 0, 0, 1, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0]
],
"character": "7",
"codepoint": 55,
"output": [
[2, 2, 2, 2, 2],
[1, 0, 0, 0, 2],
Expand All @@ -337,16 +209,8 @@
]
},
{
"name": "Z",
"input": [
[1, 1, 1, 1, 1],
[0, 0, 0, 0, 1],
[0, 0, 0, 1, 0],
[0, 0, 1, 0, 0],
[0, 1, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 1, 1, 1, 1]
],
"character": "Z",
"codepoint": 90,
"output": [
[1, 2, 2, 2, 2],
[0, 0, 0, 0, 2],
Expand Down

0 comments on commit e371f7c

Please sign in to comment.