Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: set stroke and fill properly in PFont.getShape #910

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

Junology
Copy link
Contributor

@Junology Junology commented Jan 11, 2025

This PR is re-opening #899 which I mistakenly close.
I also rebased the branch to the up to date main.

Original Post:
Currently, PFont.getShape returns an instance of PShape which renders nothing.
This is because fill and storke are not properly set in the construction of the shape.
The commit fixes the issue by calling PShape.noStroke() and PShape.fill(0) at the begining of the construction.

Test code:

import java.awt.Font;
import java.util.stream.IntStream;

PFont symbols;
PShape[] symbolShapes;

void setup() {
  size(512, 512);
  
  symbols = createFont("winjs-symbols.ttf", 32);
  Font font = (Font) symbols.getNative();
  final int[] codes = IntStream.range(0, 0x10000).filter(font::canDisplay).toArray();
  symbolShapes = new PShape[codes.length];
  for(int i = 0; i < codes.length; ++i) {
    symbolShapes[i] = symbols.getShape((char) codes[i]);
    symbolShapes[i].width=32;
    symbolShapes[i].height=32;
  }
}

void draw() {
  background(#AABBCC);
  for(int i = 0; i < symbolShapes.length; ++i) {
    int x = i % 16;
    int y = i / 16;
    symbolShapes[i].setFill(#0000FF);
    shape(symbolShapes[i], 32 * x + 4, 32 * y + 36, 24, 24);
  }
}

winjs-symbols.ttf can be downladed here.

@Stefterv Stefterv self-assigned this Jan 14, 2025
@Stefterv Stefterv merged commit 7b2a490 into processing:main Jan 14, 2025
6 checks passed
@Junology Junology deleted the pfontshape branch January 15, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants