Skip to content
Open
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
24 changes: 13 additions & 11 deletions gradio/themes/utils/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def default(self, obj):
return {
"__gradio_font__": True,
"name": obj.name,
"class": "google"
if isinstance(obj, GoogleFont)
else "local"
if isinstance(obj, LocalFont)
else "font",
"weights": obj.weights
if isinstance(obj, (GoogleFont, LocalFont))
else None,
"class": (
"google"
if isinstance(obj, GoogleFont)
else "local" if isinstance(obj, LocalFont) else "font"
),
"weights": (
obj.weights if isinstance(obj, (GoogleFont, LocalFont)) else None
),
}
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(self, name: str, weights: Iterable[int] = (400, 600)):
self.weights = weights

def stylesheet(self) -> dict:
url = f"https://fonts.googleapis.com/css2?family={self.name.replace(' ', '+')}:wght@{';'.join(str(weight) for weight in self.weights)}&display=swap"
url = f"https://fonts.googleapis.com/css2?family={self.name.replace(' ', '+')}:wght@{';'.join(map(str, self.weights))}&display=swap"
return {"url": url, "css": None}


Expand All @@ -83,14 +83,16 @@ def __init__(self, name: str, weights: Iterable[int] = (400, 700)):
self.weights = weights

def stylesheet(self) -> dict:
css_template = textwrap.dedent("""
css_template = textwrap.dedent(
"""
@font-face {{
font-family: '{name}';
src: url('static/fonts/{file_name}/{file_name}-{weight}.woff2') format('woff2');
font-weight: {weight};
font-style: normal;
}}
""")
"""
)
css_rules = []
for weight in self.weights:
weight_name = (
Expand Down