From ded390fbf000a7dbfa075da3f6389381fcc530da Mon Sep 17 00:00:00 2001 From: Renaud de Villemeur Date: Wed, 27 Nov 2024 14:52:24 -0500 Subject: [PATCH] Add explanation on loading font, from Martin explanation in Discord --- Chapters/bloc/text.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Chapters/bloc/text.md b/Chapters/bloc/text.md index 51fdbf9..ff30ff9 100644 --- a/Chapters/bloc/text.md +++ b/Chapters/bloc/text.md @@ -254,4 +254,33 @@ element text: 'hello world' asRopedText. label. ``` +## upload a font to bloc +you can load a directory with fonts (e.g. .ttf and .otf files) this way: +`AeFontManager globalInstance scanDirectory: '../../fonts' asFileReference` + +There is also +`AeFontManager globalInstance scanDefaultDirectories` +which takes a second to find font files in the typical font directories in current platform (OS) + +For example, say you have a font called "Minecraft" in a relative directory. +This font has only "Medium" type (this is important, too): + +```smalltalk +AeFontManager globalInstance scanDirectory: '../../fonts' asFileReference. + +BlTextElement new + text: ('Hola, Bonjour, Hello!' asRopedText + fontName: 'Minecraft' "<--- family name"; + medium; "<--- weight" + fontSize: 50; + yourself); + openInNewSpace. +``` + +This can be tricky: You must set carefully not only the "family name", but also +3 font properties: "slant" (e.g. normal/italic), "weight" (e.g. regular, bold, +light) and "stretch". In my example, when I set the Minecraft family name but +don't set the medium weight, then by default it will lookup for a Minecraft +regular weight font, it won't find it (the TTF only comes with a Medium weight +face), and then will use the default font.