From 9bf42a25442ec316c9ee0df6b33d55ae57182b33 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:50:59 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Speed=20up=20method=20`Fon?= =?UTF-8?q?t.=5Fregistered=5Ffont=5Fkey`=20by=2020%=20###=20Explanation=20?= =?UTF-8?q?of=20Optimizations.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/toga/fonts.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/core/src/toga/fonts.py b/core/src/toga/fonts.py index f2a7016d49..fd9f96af6d 100644 --- a/core/src/toga/fonts.py +++ b/core/src/toga/fonts.py @@ -5,7 +5,7 @@ # Use the Travertino font definitions as-is from travertino import constants from travertino.constants import ( - BOLD, + FONT_STYLES, FONT_VARIANTS, FONT_WEIGHTS, BOLD, CURSIVE, FANTASY, ITALIC, @@ -99,11 +99,9 @@ def _registered_font_key( style: str, variant: str, ) -> tuple[str, str, str, str]: - if weight not in constants.FONT_WEIGHTS: - weight = NORMAL - if style not in constants.FONT_STYLES: - style = NORMAL - if variant not in constants.FONT_VARIANTS: - variant = NORMAL - - return family, weight, style, variant + return ( + family, + weight if weight in FONT_WEIGHTS else NORMAL, + style if style in FONT_STYLES else NORMAL, + variant if variant in FONT_VARIANTS else NORMAL, + )