Skip to content

Commit

Permalink
[sample] Get sample text from the font if not provided by caller
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledhosny committed Nov 25, 2024
1 parent 558aa9f commit 391cb8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Lib/alifTools/sample/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def set_location(
self._location = location
self.hbFont.set_variations(location)

@cached_property
def sample_text(self):
return self.hbFont.face.get_name(hb.OTNameIdPredefined.SAMPLE_TEXT)

def _shape(
self,
buf: hb.Buffer,
Expand Down Expand Up @@ -362,7 +366,7 @@ def set_dark_colors(

def draw(
font_path: str,
text: str,
text: None | str,
features: str,
foreground: None | str,
background: None | str,
Expand All @@ -377,6 +381,12 @@ def draw(
y = margin
font = Font(font_path)

if text is None:
text = font.sample_text

if text is None:
raise ValueError("No text provided and no sample text in the font")

locations = font.locations
for location in reversed(locations):
font.set_location(location)
Expand Down Expand Up @@ -470,7 +480,7 @@ def parseColor(color):
def main(argv=None):
parser = argparse.ArgumentParser(description="Create SVG sample.")
parser.add_argument("font", help="input font")
parser.add_argument("-t", "--text", help="input text", required=True)
parser.add_argument("-t", "--text", help="input text")
parser.add_argument("-f", "--features", help="input features")
parser.add_argument(
"-o",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies = []
[project.optional-dependencies]
test = ["pytest", "black", "isort", "flake8", "ufolib2"]
shaping = ["pyyaml", "uharfbuzz>=0.40.0"]
sample = ["blackrenderer", "uharfbuzz>=0.40.0"]
sample = ["blackrenderer", "uharfbuzz>=0.43.0"]
filters = ["ufo2ft"]

[project.urls]
Expand Down

0 comments on commit 391cb8c

Please sign in to comment.