processing / processing/p5.js

[p5.js 2.0 Bug Report]: textSize and textWeight order shouldn't matter

Open
#8,058 8 comments 1 reaction 1 assignee View on GitHub

@perminder-17 is already working on this.

Since Aug 27, 2025.

Area:Typography p5.js 2.0+
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

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)
p5.js version

2.0.4

Web browser and version

139.0.7258.139 (Official Build) (arm64)

Operating system

MaxOS 13.0 (22A380)

Steps to reproduce this
Steps:
  1. Use textSize and textWeight to apply a text style
  2. If textWeight comes after textSize, then the behavior is unexpected: the weight won't be applied to the next text correctly.
Snippet:

This has unexpected behavior, where the top word uses changing weight value, and not the bottom word:

async function setup() {
  createCanvas(400, 400);
  background(255);
  
  font = await loadFont("https://fonts.googleapis.com/css2?family=Google+Sans+Code:ital,wght@0,300..800;1,300..800&display=swap");
  textFont(font);
}

function draw(){
  background(255);
  
  textSize(10);
  textWeight(300);
  text("Hello", 10, 50); //this should be a constant weight
  
  textSize(30);
  textWeight(map(sin(frameCount/20), -1, 1, 300, 800));
  text("World", 10, 100); //this should be an animated weight
  
}

This shows the expected behavior:


async function setup() {
  createCanvas(400, 400);
  background(255);
  
  font = await loadFont("https://fonts.googleapis.com/css2?family=Google+Sans+Code:ital,wght@0,300..800;1,300..800&display=swap");
  textFont(font);
}

function draw(){
  background(255);
  
  textWeight(300);
  textSize(10);
  text("Hello", 10, 50);
  
  textWeight(map(sin(frameCount/20), -1, 1, 300, 800));
  textSize(30);
  text("World", 10, 100);
  
}

Intuitively, these snippets should act the same.
Thanks @pattvira for finding this behavior!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.