From 459bf739dd0a1ec6fdafb8b626ce8d323dcb55f0 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Wed, 7 Aug 2024 11:48:40 +0200 Subject: [PATCH] improvement expose alternate reuse variables --- common/Font.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/common/Font.py b/common/Font.py index 667c22f..679443e 100644 --- a/common/Font.py +++ b/common/Font.py @@ -34,7 +34,6 @@ name_to_glyph_d = { "space": " ", } - class FontFace: """FontFace is a class holding glyphs @@ -84,7 +83,7 @@ def add_glyph(font_name, face_name, glyph_id, glyph_object): fonts[font_name].faces[face_name].glyphs.get(glyph_id).append(glyph_object) -def get_glyph(font_name, face_name, glyph_id): +def get_glyph(font_name, face_name, glyph_id, alternate=0): """ add_glyph adds a glyph to a FontFace it creates the :class:`Font` and :class:`FontFace` if it does not exist yet @@ -104,16 +103,18 @@ def get_glyph(font_name, face_name, glyph_id): print(fonts.keys()) return None - if fonts[font_name].faces.get(face_name) == None: - print(f"FONT3D::get_glyph: font face({face_name}) not found") + face = fonts[font_name].faces.get(face_name) + if face == None: + print(f"FONT3D::get_glyph: font({font_name}) face({face_name}) not found") print(fonts[font_name].faces.keys()) return None - if fonts[font_name].faces[face_name].glyphs.get(glyph_id) == None: - print(f"FONT3D::get_glyph: glyph id({glyph_id}) not found") + glyphs_for_id = face.glyphs.get(glyph_id) + if glyphs_for_id == None or len(glyphs_for_id) <= alternate: + print(f"FONT3D::get_glyph: font({font_name}) face({face_name}) glyph({glyph_id})[{alternate}] not found") return None - - return fonts[font_name].faces[face_name].glyphs.get(glyph_id)[0] + + return fonts[font_name].faces[face_name].glyphs.get(glyph_id)[alternate] def get_loaded_fonts(): return fonts.keys()