Skip to content

[p5.js 2.0 RFC Proposal]: Typography module revamp #7026

Closed
@limzykenneth

Description

@limzykenneth

Increasing access

Typography module enables text based work to be done in the canvas, creating more possibilities of interaction between free drawing in pixels and text. There are also opportunity for more creative manipulation of text and type once typography module has been stabilized and made up to date.

Which types of changes would be made?

  • Breaking change (Add-on libraries or sketches will work differently even if their code stays the same.)
  • Systemic change (Many features or contributor workflows will be affected.)
  • Overdue change (Modifications will be made that have been desirable for a long time.)
  • Unsure (The community can help to determine the type of change.)

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)

What's the problem?

Currently the typography module feels a bit brittle with many of the functions around text alignment, width/height measurement, text wrapping, etc, all undergoing fixes at one point or another. These fixes increases the technical debt the module has and also may have hidden edge case bugs (perhaps when using the module with non-English text for example) that we have not found yet.

In addition, for the textToPoints() function and drawing text onto a WebGL canvas, p5.js is currently relying on opentype.js which does not seem to be actively maintained. opentype.js also adds a very significant file size footprint in the overall p5.js bundle.

What's the solution?

There are two main interconnected parts to this:

  • Refactor/rewrite/redesign the typography modules to be more internally consistent and possibly changing external API if it made sense.
  • Remove, replace, or otherwise improve the use of opentype.js so that features such as textToPoint() and drawing text on WebGL canvas still continue to work with or without opentype.js. The priority will be to have either an up to date dependency or if at all possible not have any dependencies, reducing file size and future proofing the dependency list.

One possible way to start is to leverage browser text rendering API as much as possible, much of CSS and possibly the browser's own text rendering engine can potentially be leveraged to do much of the work (eg. loading fonts into CSS works as a way to load fonts in canvases). Some feature, especially those we rely heavily on opentype.js as mentioned above will likely not work out of the box with browsers so will need new solutions there.

The typography module should also be test to work across as many language scripts as possible without extra effort from the user.

Pros (updated based on community comments)

  • Reduce bundled library size
  • Reduce reliance on unmaintained projects
  • Easier to maintain internal code and easier to use external API

Cons (updated based on community comments)

  • Some features can prove to be very difficult to do

Proposal status

Under review

Metadata

Metadata

Type

No type

Projects

Status

Completed

Relationships

None yet

Development

No branches or pull requests

Issue actions