Makes the features.fea and features.family files. Combines the various feature files into one for features_roman.fea and features_italic.fea. *root* the root folder where the features files should be saved to *features* the master features.fea file that points to the various ot
(root, features, version)
| 289 | |
| 290 | |
| 291 | def buildFamilyFeatures(root, features, version): |
| 292 | """ |
| 293 | Makes the features.fea and features.family files. |
| 294 | Combines the various feature files into one for features_roman.fea and |
| 295 | features_italic.fea. |
| 296 | |
| 297 | *root* the root folder where the features files should be saved to |
| 298 | *features* the master features.fea file that points to the various other |
| 299 | features. |
| 300 | *version* a `string` of the version to set the font to |
| 301 | """ |
| 302 | |
| 303 | fea_root = os.path.split(features)[0] |
| 304 | regex = re.compile(r'/.+/(.+\.fea)') |
| 305 | feature_roman = [] |
| 306 | feature_mono_italic = [] # includes ss07 |
| 307 | feature_sans_italic = [] # includes ss07, liga |
| 308 | with open(features, 'r') as f: |
| 309 | for l in f: |
| 310 | if l.startswith("languagesystem"): |
| 311 | feature_roman.append(l) |
| 312 | feature_sans_italic.append(l) |
| 313 | feature_mono_italic.append(l) |
| 314 | elif "#" in l: |
| 315 | pass |
| 316 | elif l.startswith("include"): |
| 317 | match = regex.search(l) |
| 318 | path = os.path.join(fea_root, "features", match.group(1)) |
| 319 | with open(path, 'r') as fea: |
| 320 | for line in fea: |
| 321 | line = line.replace("\t", " ") |
| 322 | if match.group(1) == "liga.fea": |
| 323 | line = line.replace("i.italic", "i") |
| 324 | line = line.replace("l.italic", "l") |
| 325 | feature_sans_italic.append(line) |
| 326 | else: |
| 327 | feature_roman.append(line) |
| 328 | feature_mono_italic.append(line) |
| 329 | feature_sans_italic.append(line) |
| 330 | feature_roman.append("\n\n") |
| 331 | feature_mono_italic.append("\n\n") |
| 332 | feature_sans_italic.append("\n\n") |
| 333 | else: |
| 334 | feature_roman.append(l) |
| 335 | feature_mono_italic.append(l) |
| 336 | feature_sans_italic.append(l) |
| 337 | |
| 338 | # swap italic diagonals in ss07 |
| 339 | for i, line in enumerate(feature_sans_italic): |
| 340 | if "sub @curvyDiagonals by @romanDiagonals;" in line: |
| 341 | feature_sans_italic[i] = " sub @romanDiagonals by @curvyDiagonals;" |
| 342 | |
| 343 | # swap italic diagonals in ss07 |
| 344 | for i, line in enumerate(feature_mono_italic): |
| 345 | if "sub @curvyDiagonals by @romanDiagonals;" in line: |
| 346 | feature_mono_italic[i] = " sub @romanDiagonals by @curvyDiagonals;" |
| 347 | |
| 348 | path_roman = os.path.join(root, "features_roman.fea") |