Skip to content

Commit

Permalink
Significantly improve spacing for thin characters
Browse files Browse the repository at this point in the history
  • Loading branch information
IdreesInc committed Jan 1, 2023
1 parent b890817 commit 4403411
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
Binary file modified images/glyphs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 38 additions & 20 deletions src/characters.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
"name": "single_quote",
"codepoint": 39,
"pixels": [
[0, 1, 0, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
Expand Down Expand Up @@ -997,7 +997,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0]
]
],
"leftMargin": -0.5
},
{
"character": "g",
Expand Down Expand Up @@ -1041,7 +1042,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "j",
Expand Down Expand Up @@ -1071,7 +1073,8 @@
[1, 1, 0, 0, 0],
[1, 0, 1, 0, 0],
[1, 0, 0, 1, 0]
]
],
"leftMargin": 0.5
},
{
"character": "l",
Expand All @@ -1085,7 +1088,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "m",
Expand Down Expand Up @@ -1201,7 +1205,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "u",
Expand Down Expand Up @@ -1947,7 +1952,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "í",
Expand All @@ -1962,7 +1968,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "î",
Expand All @@ -1977,7 +1984,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "ï",
Expand All @@ -1991,7 +1999,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "ð",
Expand Down Expand Up @@ -2164,7 +2173,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "ī",
Expand All @@ -2178,7 +2188,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "ĭ",
Expand All @@ -2193,7 +2204,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "ĵ",
Expand Down Expand Up @@ -2244,7 +2256,8 @@
[0, 0, 1, 0, 0],
[0, 1, 0, 0, 0]
],
"descent": 2
"descent": 2,
"leftMargin": 0.5
},
{
"character": "Ļ",
Expand Down Expand Up @@ -2278,7 +2291,8 @@
[0, 0, 0, 1, 0],
[0, 0, 1, 0, 0]
],
"descent": 2
"descent": 2,
"leftMargin": -0.5
},
{
"character": "Ł",
Expand Down Expand Up @@ -2306,7 +2320,8 @@
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "Ņ",
Expand Down Expand Up @@ -2417,7 +2432,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "Ů",
Expand All @@ -2440,7 +2456,8 @@
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
]
],
"leftMargin": -0.5
},
{
"character": "ĵ",
Expand Down Expand Up @@ -2525,7 +2542,8 @@
[0, 0, 1, 0, 0],
[0, 1, 0, 0, 0]
],
"descent": 2
"descent": 2,
"leftMargin": -0.5
},
{
"character": "Ѐ",
Expand Down
15 changes: 10 additions & 5 deletions src/monocraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def generateFont():
monocraft.fullname = "Monocraft"
monocraft.copyright = "Idrees Hassan, https://github.com/IdreesInc/Monocraft"
monocraft.encoding = "UnicodeFull"
monocraft.version = "2.2"
monocraft.weight = "Medium"
monocraft.version = "2.3"
monocraft.weight = "Regular"
monocraft.ascent = PIXEL_SIZE * 8
monocraft.descent = PIXEL_SIZE
monocraft.em = PIXEL_SIZE * 9
Expand All @@ -49,15 +49,17 @@ def generateFont():
monocraft.createChar(character["codepoint"], character["name"])
pen = monocraft[character["name"]].glyphPen()
top = 0
drawn = character
if "pixels" in character:
top = drawCharacter(character, pen)
elif "reference" in character:
top = drawCharacter(charactersByCodepoint[character["reference"]], pen)
drawn = charactersByCodepoint[character["reference"]]
top = drawCharacter(drawn, pen)
if "diacritic" in character:
diacritic = diacritics[character["diacritic"]]
if "diacriticSpace" in character:
top += PIXEL_SIZE * character["diacriticSpace"]
drawGlyph(diacritic["pixels"], pen, 0, top)
drawGlyph(diacritic["pixels"], pen, getLeftMargin(drawn), top)
monocraft[character["name"]].width = PIXEL_SIZE * 6
print(f"Generated {len(characters)} characters")

Expand All @@ -78,9 +80,12 @@ def generateFont():
monocraft.generate(outputDir + "Monocraft.ttf")
monocraft.generate(outputDir + "Monocraft.otf")

def getLeftMargin(character):
return PIXEL_SIZE * character["leftMargin"] if "leftMargin" in character else 0

def drawCharacter(character, pen):
if "reference" in character: return drawCharacter(charactersByCodepoint[character["reference"]],pen)
leftMargin = PIXEL_SIZE * character["leftMargin"] if "leftMargin" in character else 0
leftMargin = getLeftMargin(character)
floor = -PIXEL_SIZE * character["descent"] if "descent" in character else 0
return drawGlyph(character["pixels"], pen, leftMargin, floor)

Expand Down

0 comments on commit 4403411

Please sign in to comment.