[p5.js 2.0+ Bug Report]: textAlign() with an invalid horizontal value draws nothing in 2D but falls back to LEFT in WEBGL
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript
- Lĩnh vực
- computer-graphics
Hướng nghiên cứu
Đọc switch căn chỉnh ngang trong src/core/p5.Renderer2D.js (các dòng 942-956) và thêm default: adjustedX = x; để khớp với fallback của Renderer3D. Thêm một bài kiểm thử đơn vị cho textAlign với một giá trị ngang không hợp lệ trong bộ kiểm thử typography. Hoàn thành khi canvas 2D vẽ văn bản tại LEFT và bài kiểm thử mới qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- WebGPU
- p5.strands
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.3.4 (Web Editor). Source checked on main at 51eefe3d0, and the relevant code is the same.
Web browser and version
156.0.8078.48 (Official Build) (arm64)
Operating system
MacOS GoldenGate
Steps to reproduce this
Steps to reproduce this
textAlign() saves any string as the horizontal alignment. When the value isn't LEFT, CENTER or RIGHT, the 2D and WEBGL renderers handle it differently. An easy way to hit this is textAlign(TOP), which passes a vertical constant into the horizontal slot.
| 2D | WEBGL | |
|---|---|---|
textAlign(LEFT) (control) |
text drawn at left | text drawn at left |
textAlign(TOP) |
nothing drawn | text drawn at left |
Controls (textAlign(LEFT)), 2D then WEBGL:
textAlign(TOP), 2D then WEBGL:
With FES on, both renderers show the same warning:
🌸 p5.js says: Expected constant (please refer to documentation for allowed values) at the first parameter, but received top in textAlign().
So the user is warned, but what happens next depends on the renderer.
With p5.disableFriendlyErrors = true, the 2D sketch draws nothing and the p5 console is empty. The only message is the browser's CanvasTextAlign warning in DevTools, which doesn't point to textAlign():
Sketch:
// p5.disableFriendlyErrors = true; // uncomment for the FES-off run
let font;
async function setup() {
createCanvas(200, 100); // or createCanvas(200, 100, WEBGL)
font = await loadFont('Arial.ttf');
// translate(-width / 2, -height / 2); // WEBGL only
background(220);
textFont(font);
textSize(20);
textAlign(TOP); // LEFT for the control
text('hello', 20, 50);
}
Why they differ (from reading the source). Both renderers work out the x position with a switch (textAlign):
src/core/p5.Renderer3D.js:1891–1909hasdefault: adjustedX = x, so an unknown value falls back to LEFT.src/core/p5.Renderer2D.js:942–956has nodefault:. That leavesadjustedXasundefined, and it gets passed tofillText()as the x coordinate, so nothing is drawn.- The shared helper
_xAlignOffset(src/type/textCore.js:2103) also hasdefault: return 0, so the 2D renderer is the only one without a fallback.
Possible fix: add default: adjustedX = x; to the 2D switch so both renderers fall back to LEFT, plus a unit test.
I'd like to fix this myself if approved.
- Ngôn ngữ chính
- JavaScript
- Star
- 24.3k
- Fork
- 3.9k
- Merge trung bình
- 3 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 48
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của processing/p5.js
-
[p5.js 2.0+ Bug Report]: Incorrect isDone assignment in MediaElement.onended() exampleCó thể đã có người làm @BhumitSahani đã nhận 4 ngày trước. Đang mởArea:DOM p5.js 2.0+
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
processing/p5.js#9339 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[p5.js 2.0+ Bug Report]: Mismatched map() Reference ExampleCó thể đã có người làm @j-xsen đã nhận 4 ngày trước. Đang mởArea:Math Documentation p5.js 2.0+
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 87/100
processing/p5.js#9329 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Area:Core p5.js 2.0+
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
processing/p5.js#9319 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Area:WebGL p5.js 2.0+ p5.strands
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
processing/p5.js#9317 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[p5.js 2.0+ Bug Report]: createRadio().disable(false) does not re-enable radio inputsCó thể đã có người làm @aryanb1906 đã nhận 5 ngày trước. Đang mởArea:DOM Good First Issue p5.js 2.0+
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
processing/p5.js#9316 · 5 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của processing/p5.js
Issue tương tự
-
JS/TS: JSX props compile errors should link to a doc page explaining the static-list requirementĐang mởarea: js-runtime enhancement exists-upstream interop priority: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
shayanhabibi/fickl#307 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
editor good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
webarkit/webarkit-studio#16 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
superdesigndev/treg#1324 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
entur/iteru-3dbus#48 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
pigeon189/zcode-fox-widget#17 · 1 bình luận ·