Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Lib/feaPyFoFum/feaPyFoFum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,3 +1057,55 @@ def _stylisticSetNames(self, names):
self._indentText(text)
self._identifierStack.append("stylisticSetNames")
return text

# character variant

def formatCharacterVariantNames(self, *names):
lines = ["cvParameters {"]
orderedNames = dict(
FeatUILabelNameID=[],
FeatUITooltipTextNameID=[],
SampleTextNameID=[],
ParamUILabelNameID=[],
)
for name in names:
if (nameType := name["type"]) in orderedNames:
orderedNames[nameType].append(name)
# XXX silently fail here?
for nameType, nameDicts in orderedNames.items():
if len(nameDicts) == 0:
continue
block = [f"{self._whitespace}{nameType} {{"]
for name in nameDicts:
text = name["text"]
platform = name.get("platform")
script = name.get("script")
language = name.get("language")
line = ["name"]
if platform is not None:
line.append(str(platform))
if script is not None:
line.append(str(script))
line.append(str(language))
line.append(u'\"%s\"' % text)
line = (self._whitespace * 2) + " ".join(line) + ";"
block.append(line)
block.append((self._whitespace + "};"))
lines.extend(block)
lines.append("};")
text = "\n".join(lines)
return text

def characterVariantNames(self, *names):
d = dict(
identifier="characterVariantNames",
names=names
)
self._content.append(d)

def _characterVariantNames(self, names):
text = self._handleBreakBefore("characterVariantNames")
text.extend(self.formatCharacterVariantNames(*names).splitlines())
self._indentText(text)
self._identifierStack.append("characterVariantNames")
return text
19 changes: 18 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ If `choice` is `True` the rule will be written as a `from` rule (GSUB LookupType

The same contextual marking defined in the `substitution` method will be run for `ignoreSubstitution`.

##### writer.stylisticSetFeatureNames(name1, name2, name3, ...)
##### writer.stylisticSetNames(name1, name2, name3, ...)

This will write the given names as `featureNames` in the current feature. Names must be dicts of this form:

Expand All @@ -116,6 +116,21 @@ name = {
}
```

##### writer.characterVariantNames(name1, name2, name3, ...)

This will write the given names as `cvParameters` in the current feature. Names must be dicts of this form:

```python
name = {
"type": "type for this name",
# 'type' must be one of [FeatUILabelNameID, FeatUITooltipTextNameID, SampleTextNameID, ParamUILabelNameID]
"text" : "name for string",
"platform" : int, # optional
"script" : int, # optional
"language" : int, # optional
}
```

##### writer.write()

Return a string containing everything stored in the writer properly formatted for .fea.
Expand Down Expand Up @@ -149,6 +164,8 @@ This will only assume that the substitution rule should contain contextual marki

##### writer.formatStylisticSetNames(name1, name2, name3, ...)

##### writer.formatCharacterVariantNames(name1, name2, name3, ...)


# FeaPyFoFum

Expand Down