Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,8 +9,8 @@ import zipfile
|
|
| 9 |
import tempfile
|
| 10 |
import os
|
| 11 |
from fontTools.ttLib import TTFont
|
| 12 |
-
from fontTools.
|
| 13 |
-
from fontTools.ttLib.tables import
|
| 14 |
|
| 15 |
def load_model():
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained("ChevalierJoseph/typtop")
|
|
@@ -60,45 +60,59 @@ def generate_svg_files(glyphs, width=100, height=100):
|
|
| 60 |
|
| 61 |
def create_otf_font(glyphs, output_path="font.otf"):
|
| 62 |
font = TTFont()
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
font['
|
| 75 |
-
font['hhea']
|
| 76 |
-
font['maxp']
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
for lettre, path in glyphs:
|
| 89 |
unicode_val = ord(lettre)
|
| 90 |
glyph_name = f"glyph{unicode_val}"
|
| 91 |
|
|
|
|
| 92 |
glyph = glyf_table.glyphClass()
|
| 93 |
glyph.name = glyph_name
|
| 94 |
-
glyph.numberOfContours = 0 # Placeholder logic here for drawing the glyph
|
| 95 |
|
| 96 |
-
glyf_table
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
|
|
|
| 101 |
|
|
|
|
| 102 |
font.save(output_path)
|
| 103 |
return output_path
|
| 104 |
|
|
|
|
| 9 |
import tempfile
|
| 10 |
import os
|
| 11 |
from fontTools.ttLib import TTFont
|
| 12 |
+
from fontTools.ttLib.tables import _h_e_a_d, _h_h_e_a, _m_a_x_p, _n_a_m_e, _O_S_2, _p_o_s_t
|
| 13 |
+
from fontTools.ttLib.tables._c_m_a_p import CmapSubtable
|
| 14 |
|
| 15 |
def load_model():
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained("ChevalierJoseph/typtop")
|
|
|
|
| 60 |
|
| 61 |
def create_otf_font(glyphs, output_path="font.otf"):
|
| 62 |
font = TTFont()
|
| 63 |
+
|
| 64 |
+
# Create and add mandatory tables
|
| 65 |
+
head = _h_e_a_d.table__h_e_a_d()
|
| 66 |
+
hhea = _h_h_e_a.table__h_h_e_a()
|
| 67 |
+
maxp = _m_a_x_p.table__m_a_x_p()
|
| 68 |
+
name = _n_a_m_e.table__n_a_m_e()
|
| 69 |
+
os2 = _O_S_2.table__O_S_2()
|
| 70 |
+
post = _p_o_s_t.table__p_o_s_t()
|
| 71 |
+
hmtx = TTFont.newTable('hmtx')
|
| 72 |
+
cmap = TTFont.newTable('cmap')
|
| 73 |
+
|
| 74 |
+
font['head'] = head
|
| 75 |
+
font['hhea'] = hhea
|
| 76 |
+
font['maxp'] = maxp
|
| 77 |
+
font['name'] = name
|
| 78 |
+
font['OS/2'] = os2
|
| 79 |
+
font['post'] = post
|
| 80 |
+
font['hmtx'] = hmtx
|
| 81 |
+
font['cmap'] = cmap
|
| 82 |
+
|
| 83 |
+
# Set required fields
|
| 84 |
+
head.fontRevision = 1.0
|
| 85 |
+
hhea.ascent = 800
|
| 86 |
+
hhea.descent = -200
|
| 87 |
+
hhea.lineGap = 0
|
| 88 |
+
maxp.numGlyphs = len(glyphs)
|
| 89 |
+
|
| 90 |
+
# Create a cmap table
|
| 91 |
+
cmap_table = CmapSubtable.newSubtable(3, 1, 0) # Windows platform, Unicode BMP encoding
|
| 92 |
+
|
| 93 |
+
# Add glyphs to the font
|
| 94 |
+
glyf_table = TTFont.newTable('glyf')
|
| 95 |
|
| 96 |
for lettre, path in glyphs:
|
| 97 |
unicode_val = ord(lettre)
|
| 98 |
glyph_name = f"glyph{unicode_val}"
|
| 99 |
|
| 100 |
+
# Create a simple glyph (this is a placeholder)
|
| 101 |
glyph = glyf_table.glyphClass()
|
| 102 |
glyph.name = glyph_name
|
|
|
|
| 103 |
|
| 104 |
+
glyf_table[glyph_name] = glyph
|
| 105 |
+
|
| 106 |
+
# Map unicode to glyph name
|
| 107 |
+
cmap_table.cmap[unicode_val] = glyph_name
|
| 108 |
+
# Set metrics for each glyph
|
| 109 |
+
hmtx[glyph_name] = (1000, 0) # (advanceWidth, leftSideBearing)
|
| 110 |
|
| 111 |
+
# Assign the cmap and glyf tables to the font
|
| 112 |
+
cmap.tables = [cmap_table]
|
| 113 |
+
font['glyf'] = glyf_table
|
| 114 |
|
| 115 |
+
# Save the font
|
| 116 |
font.save(output_path)
|
| 117 |
return output_path
|
| 118 |
|