Skip to content

Discussion: Friendlier API for variable font settings #8810

@SableRaf

Description

@SableRaf

Increasing access

The proposed change would make variable fonts in p5.js easier to learn and teach by making the feature more idiomatic, and reducing the prerequisite knowledge (see Context section below)

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

Feature request details

Context

Controlling font variations currently requires manually constructing a fontVariationSettings string through textProperty().

Example today:

textProperty(
  "fontVariationSettings",
  `"wdth" ${wdth}, "slnt" ${slnt}, ` +
  `"YOPQ" ${yopq}, "YTLC" ${ytlc}`
);

This works, but it gets verbose, and requires prior knowledge of template literals and string concatenation.

Proposal

Would it make sense to expand textProperty() so it can also set individual variable font properties directly?

For example:

textProperty("slnt", slnt);
textProperty("wdth", wdth);
textProperty("YOPQ", yopq);

Or to avoid overloading textProperty(), introduce a dedicated method:

textVariation("slnt", slnt);
textVariation("wdth", wdth);
textVariation("YOPQ", yopq);

The later might make it easier to handle non-existent axes and offer feedback like "The selected font fontName doesn't have a slant axis".

If technically feasible, it could also be useful to expose available variation settings (axes and ranges) via textProperties().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions