LivelyKernel / lively.next

lively.next is a personal programming kit. It emphasizes liveness, directness, and interactivity.
https://lively-next.org
MIT License
69 stars 16 forks source link

Support Generic Font Names #1459

Closed rickmcgeer closed 7 months ago

rickmcgeer commented 7 months ago

Describe the Feature This is related to https://github.com/LivelyKernel/lively.next/issues/1458. 'Sans Serif' is not a valid font family. But it's quite common for people to select classes of font as the font name, generally as the last choice (e.g., "Barlow, Arial, 'Sans Serif'") in order to ensure that they don't spend mornings like I did, chasing down bad font names.

Graphics We've all seen this, but here's a sample from GMail: image

Implementation Details A simple solution is to have default fonts for each class ( Sans Serif, Serif, and Fixed Width -- perhaps others) , and in sanitizeFont (see

$world.execCommand("open browser", {moduleName: "helpers.js", packageName: "lively.morphic", codeEntity: "sanitizeFont"});

Have code that looks something like this:

   genericFonts = {
      'Sans Serif': 'Open Sans',
      'Serif': 'Times New Roman',
      'Fixed Width': 'Courier New'
   }
   if (font in genericFonts) {
     return genericFonts[font]
  }

Obviously that's too simplistic, and you'll want genericFonts to be pulled from a config, but that's the idea.

linusha commented 7 months ago

Nice idea, @rickmcgeer! I implemented this in the linked PR. This is basically just an alias that will internally set a font name. So checking for fontName === 'Mono' for example will not work in other places. Also, we currently support specifying exactly one fontFamily, so using for example, "Mono" as a fallback, as is often done, will not work in lively. The reason for this is that usually, this is done to handle the font availability on specific systems, which we do not need as we explicitly ship and bundle a selected set of fonts.