classes.c13_library
1from const import GenericConst, TypefaceSlug, TYPEFACES 2from .c11_family import KFamily 3from .c33_basket import KBasket 4 5from lib import fonts 6 7 8class KLibrary: 9 """A library class for managing and accessing typeface families. 10 11 This class provides functionality to retrieve font families by slug, get random families, 12 and access fonts with specific criteria. It uses a basket system to manage typeface selection. 13 14 Attributes: 15 basket (KBasket): A basket containing all available typefaces for selection. 16 """ 17 18 def __init__(self): 19 self.basket = KBasket(list(TYPEFACES)) 20 """Internal basket to manage picking `const.TypefaceSlug`.""" 21 22 def getFamilyBySlug(self, slug: TypefaceSlug): 23 """Retrieves a font family by its typeface slug identifier. 24 25 Raises: 26 ValueError: If the provided slug is not found in TYPEFACES. 27 """ 28 if slug not in TYPEFACES: 29 raise ValueError(f"Unknown typeface slug: {slug}") 30 31 # Retrieve and return the font family associated with the slug 32 familyConst = GenericConst(slug) 33 return KFamily(familyConst.fontFolder) 34 35 def getNextFamily(self): 36 """Gets the next font family from the basket.""" 37 return self.getFamilyBySlug(self.basket.pickNext()) 38 39 def getRandomFamily(self): 40 """Get a random font family from the library.""" 41 return self.getFamilyBySlug(self.basket.pickRandom()) 42 43 def getRandomFont(self, criteria: fonts.FontType | list[fonts.FontType]): 44 """Gets a random font from a random family that matches the specified criteria. See `lib.fonts.FontType`.""" 45 family = self.getRandomFamily() 46 return family.getRandom(criteria)
class
KLibrary:
9class KLibrary: 10 """A library class for managing and accessing typeface families. 11 12 This class provides functionality to retrieve font families by slug, get random families, 13 and access fonts with specific criteria. It uses a basket system to manage typeface selection. 14 15 Attributes: 16 basket (KBasket): A basket containing all available typefaces for selection. 17 """ 18 19 def __init__(self): 20 self.basket = KBasket(list(TYPEFACES)) 21 """Internal basket to manage picking `const.TypefaceSlug`.""" 22 23 def getFamilyBySlug(self, slug: TypefaceSlug): 24 """Retrieves a font family by its typeface slug identifier. 25 26 Raises: 27 ValueError: If the provided slug is not found in TYPEFACES. 28 """ 29 if slug not in TYPEFACES: 30 raise ValueError(f"Unknown typeface slug: {slug}") 31 32 # Retrieve and return the font family associated with the slug 33 familyConst = GenericConst(slug) 34 return KFamily(familyConst.fontFolder) 35 36 def getNextFamily(self): 37 """Gets the next font family from the basket.""" 38 return self.getFamilyBySlug(self.basket.pickNext()) 39 40 def getRandomFamily(self): 41 """Get a random font family from the library.""" 42 return self.getFamilyBySlug(self.basket.pickRandom()) 43 44 def getRandomFont(self, criteria: fonts.FontType | list[fonts.FontType]): 45 """Gets a random font from a random family that matches the specified criteria. See `lib.fonts.FontType`.""" 46 family = self.getRandomFamily() 47 return family.getRandom(criteria)
A library class for managing and accessing typeface families.
This class provides functionality to retrieve font families by slug, get random families, and access fonts with specific criteria. It uses a basket system to manage typeface selection.
Attributes:
- basket (KBasket): A basket containing all available typefaces for selection.
def
getFamilyBySlug( self, slug: Literal['stabil-grotesk', 'labil-grotesk', 'attila-sans', 'uniforma', 'victor-serif', 'victor-narrow', 'alfresco', 'silikon', 'radial-grotesk']):
23 def getFamilyBySlug(self, slug: TypefaceSlug): 24 """Retrieves a font family by its typeface slug identifier. 25 26 Raises: 27 ValueError: If the provided slug is not found in TYPEFACES. 28 """ 29 if slug not in TYPEFACES: 30 raise ValueError(f"Unknown typeface slug: {slug}") 31 32 # Retrieve and return the font family associated with the slug 33 familyConst = GenericConst(slug) 34 return KFamily(familyConst.fontFolder)
Retrieves a font family by its typeface slug identifier.
Raises:
- ValueError: If the provided slug is not found in TYPEFACES.
def
getNextFamily(self):
36 def getNextFamily(self): 37 """Gets the next font family from the basket.""" 38 return self.getFamilyBySlug(self.basket.pickNext())
Gets the next font family from the basket.
def
getRandomFamily(self):
40 def getRandomFamily(self): 41 """Get a random font family from the library.""" 42 return self.getFamilyBySlug(self.basket.pickRandom())
Get a random font family from the library.
def
getRandomFont( self, criteria: Union[Literal['upright', 'italic', 'display', 'text', 'thin', 'thick', 'any'], list[Literal['upright', 'italic', 'display', 'text', 'thin', 'thick', 'any']]]):
44 def getRandomFont(self, criteria: fonts.FontType | list[fonts.FontType]): 45 """Gets a random font from a random family that matches the specified criteria. See `lib.fonts.FontType`.""" 46 family = self.getRandomFamily() 47 return family.getRandom(criteria)
Gets a random font from a random family that matches the specified criteria. See lib.fonts.FontType.