Skip to content

Commit

Permalink
Merge pull request #1009 from googlefonts/fontra-u-plus
Browse files Browse the repository at this point in the history
[fontra format] Prepend U+ to code points in .csv, but still allow 'bare' hex values when reading
  • Loading branch information
justvanrossum authored Dec 2, 2023
2 parents 007220a + b7db9ec commit a38a01d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 48 deletions.
17 changes: 15 additions & 2 deletions src/fontra/backends/fontra.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _readGlyphInfo(self):
for row in reader:
glyphName, *rest = row
if rest:
codePoints = [int(cp, 16) for cp in rest[0].split(",") if cp]
codePoints = _parseCodePoints(rest[0])
else:
codePoints = []
self.glyphMap[glyphName] = codePoints
Expand All @@ -120,7 +120,7 @@ def _writeGlyphInfo(self):
writer = csv.writer(file, delimiter=";")
writer.writerow(["glyph name", "code points"])
for glyphName, codePoints in sorted(self.glyphMap.items()):
codePoints = ",".join(f"{cp:04X}" for cp in codePoints)
codePoints = ",".join(f"U+{cp:04X}" for cp in codePoints)
writer.writerow([glyphName, codePoints])

def _readFontData(self):
Expand All @@ -144,6 +144,19 @@ def getGlyphFilePath(self, glyphName):
return self.glyphsDir / (stringToFileName(glyphName) + ".json")


def _parseCodePoints(cell):
codePoints = []
cell = cell.strip()
if cell:
for s in cell.split(","):
s = s.strip()
# U+ should become mandatory, but for now let's be lenient
if s.startswith("U+"):
s = s[2:]
codePoints.append(int(s, 16))
return codePoints


def serializeGlyph(glyph, glyphName=None):
glyph = glyph.convertToPaths()
jsonGlyph = unstructure(glyph)
Expand Down
92 changes: 46 additions & 46 deletions test-common/fonts/MutatorSans.fontra/glyph-info.csv
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
glyph name;code points
A;0041,0061
Aacute;00C1,00E1
Adieresis;00C4,00E4
B;0042,0062
C;0043,0063
D;0044,0064
E;0045,0065
F;0046,0066
G;0047,0067
H;0048,0068
I;0049,0069
A;U+0041,U+0061
Aacute;U+00C1,U+00E1
Adieresis;U+00C4,U+00E4
B;U+0042,U+0062
C;U+0043,U+0063
D;U+0044,U+0064
E;U+0045,U+0065
F;U+0046,U+0066
G;U+0047,U+0067
H;U+0048,U+0068
I;U+0049,U+0069
I.narrow;
IJ;
J;004A,006A
J;U+004A,U+006A
J.narrow;
K;004B,006B
L;004C,006C
M;004D,006D
N;004E,006E
O;004F,006F
P;0050,0070
Q;0051,0071
R;0052,0072
K;U+004B,U+006B
L;U+004C,U+006C
M;U+004D,U+006D
N;U+004E,U+006E
O;U+004F,U+006F
P;U+0050,U+0070
Q;U+0051,U+0071
R;U+0052,U+0072
R.alt;
S;0053,0073
S;U+0053,U+0073
S.closed;
T;0054,0074
U;0055,0075
V;0056,0076
W;0057,0077
X;0058,0078
Y;0059,0079
Z;005A,007A
acute;00B4
arrowdown;2193
arrowleft;2190
arrowright;2192
arrowup;2191
colon;003A
comma;002C
dieresis;00A8
dot;27D1
T;U+0054,U+0074
U;U+0055,U+0075
V;U+0056,U+0076
W;U+0057,U+0077
X;U+0058,U+0078
Y;U+0059,U+0079
Z;U+005A,U+007A
acute;U+00B4
arrowdown;U+2193
arrowleft;U+2190
arrowright;U+2192
arrowup;U+2191
colon;U+003A
comma;U+002C
dieresis;U+00A8
dot;U+27D1
em;
nestedcomponents;
nlitest;
period;002E
quotedblbase;201E
quotedblleft;201C
quotedblright;201D
quotesinglbase;201A
semicolon;003B
space;0020
varcotest1;E000
varcotest2;E001
period;U+002E
quotedblbase;U+201E
quotedblleft;U+201C
quotedblright;U+201D
quotesinglbase;U+201A
semicolon;U+003B
space;U+0020
varcotest1;U+E000
varcotest2;U+E001

0 comments on commit a38a01d

Please sign in to comment.