Skip to content

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

@ksen0

Description

@ksen0

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!

Metadata

Metadata

Assignees

Type

Projects

Status

Open for Discussion

Relationships

None yet

Development

No branches or pull requests

Issue actions