q5 2.9.22 → 2.9.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +26 -0
- package/bun.lockb +0 -0
- package/p5-tests/js/chai_helpers.js +20 -0
- package/p5-tests/js/mocha_setup.js +2 -0
- package/p5-tests/js/modernizr.js +5 -0
- package/p5-tests/js/p5_helpers.js +135 -0
- package/p5-tests/js/sinon.js +5949 -0
- package/p5-tests/mocha.css +289 -0
- package/p5-tests/test.html +71 -0
- package/p5-tests/unit/color/color_conversion.js +68 -0
- package/p5-tests/unit/color/creating_reading.js +217 -0
- package/p5-tests/unit/color/p5.Color.js +1000 -0
- package/p5-tests/unit/color/setting.js +289 -0
- package/p5-tests/unit/core/2d_primitives.js +490 -0
- package/p5-tests/unit/core/attributes.js +115 -0
- package/p5-tests/unit/core/curves.js +139 -0
- package/p5-tests/unit/core/environment.js +248 -0
- package/p5-tests/unit/core/error_helpers.js +1158 -0
- package/p5-tests/unit/core/main.js +340 -0
- package/p5-tests/unit/core/p5.Element.js +773 -0
- package/p5-tests/unit/core/p5.Graphics.js +179 -0
- package/p5-tests/unit/core/preload.js +285 -0
- package/p5-tests/unit/core/rendering.js +116 -0
- package/p5-tests/unit/core/structure.js +293 -0
- package/p5-tests/unit/core/transform.js +144 -0
- package/p5-tests/unit/core/version.js +28 -0
- package/p5-tests/unit/core/vertex.js +137 -0
- package/p5-tests/unit/dom/dom.js +2146 -0
- package/p5-tests/unit/events/acceleration.js +213 -0
- package/p5-tests/unit/events/keyboard.js +179 -0
- package/p5-tests/unit/events/mouse.js +487 -0
- package/p5-tests/unit/events/touch.js +180 -0
- package/p5-tests/unit/image/downloading.js +379 -0
- package/p5-tests/unit/image/filters.js +92 -0
- package/p5-tests/unit/image/loading.js +413 -0
- package/p5-tests/unit/image/p5.Image.js +201 -0
- package/p5-tests/unit/image/pixels.js +234 -0
- package/p5-tests/unit/io/files.js +378 -0
- package/p5-tests/unit/io/loadBytes.js +149 -0
- package/p5-tests/unit/io/loadImage.js +123 -0
- package/p5-tests/unit/io/loadJSON.js +185 -0
- package/p5-tests/unit/io/loadModel.js +215 -0
- package/p5-tests/unit/io/loadShader.js +176 -0
- package/p5-tests/unit/io/loadStrings.js +140 -0
- package/p5-tests/unit/io/loadTable.js +183 -0
- package/p5-tests/unit/io/loadXML.js +127 -0
- package/p5-tests/unit/io/saveModel.js +113 -0
- package/p5-tests/unit/io/saveTable.js +142 -0
- package/p5-tests/unit/math/calculation.js +452 -0
- package/p5-tests/unit/math/noise.js +66 -0
- package/p5-tests/unit/math/p5.Vector.js +1886 -0
- package/p5-tests/unit/math/random.js +177 -0
- package/p5-tests/unit/math/trigonometry.js +144 -0
- package/p5-tests/unit/spec.js +50 -0
- package/p5-tests/unit/typography/attributes.js +120 -0
- package/p5-tests/unit/typography/loadFont.js +162 -0
- package/p5-tests/unit/typography/p5.Font.js +63 -0
- package/p5-tests/unit/utilities/conversion.js +329 -0
- package/p5-tests/unit/utilities/time_date.js +133 -0
- package/package.json +1 -1
- package/q5.js +48 -37
- package/q5.min.js +1 -1
- package/src/q5-2d-image.js +3 -1
- package/src/q5-core.js +3 -1
- package/src/q5-math.js +1 -0
- package/src/q5-webgpu-canvas.js +8 -7
- package/src/q5-webgpu-drawing.js +15 -12
- package/src/q5-webgpu-image.js +1 -1
- package/src/q5-webgpu-text.js +17 -15
package/src/q5-webgpu-text.js
CHANGED
|
@@ -168,8 +168,9 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
|
|
|
168
168
|
getChar(charCode) {
|
|
169
169
|
return this.chars[charCode] ?? this.defaultChar;
|
|
170
170
|
}
|
|
171
|
-
// Gets the distance in pixels a line should advance for a given
|
|
172
|
-
// character code
|
|
171
|
+
// Gets the distance in pixels a line should advance for a given
|
|
172
|
+
// character code. If the upcoming character code is given any
|
|
173
|
+
// kerning between the two characters will be taken into account.
|
|
173
174
|
getXAdvance(charCode, nextCharCode = -1) {
|
|
174
175
|
let char = this.getChar(charCode);
|
|
175
176
|
if (nextCharCode >= 0) {
|
|
@@ -211,8 +212,8 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
|
|
|
211
212
|
});
|
|
212
213
|
Q5.device.queue.copyExternalImageToTexture({ source: img }, { texture }, imgSize);
|
|
213
214
|
|
|
214
|
-
//
|
|
215
|
-
//
|
|
215
|
+
// chars and kernings can be stored as csv strings, making the file
|
|
216
|
+
// size smaller, but they need to be parsed into arrays of objects
|
|
216
217
|
if (typeof atlas.chars == 'string') {
|
|
217
218
|
atlas.chars = $.CSV.parse(atlas.chars, ' ');
|
|
218
219
|
atlas.kernings = $.CSV.parse(atlas.kernings, ' ');
|
|
@@ -338,7 +339,7 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
|
|
|
338
339
|
let charCode = nextCharCode;
|
|
339
340
|
nextCharCode = i < text.length - 1 ? text.charCodeAt(i + 1) : -1;
|
|
340
341
|
switch (charCode) {
|
|
341
|
-
case 10: //
|
|
342
|
+
case 10: // newline
|
|
342
343
|
lineWidths.push(offsetX);
|
|
343
344
|
line++;
|
|
344
345
|
maxWidth = Math.max(maxWidth, offsetX);
|
|
@@ -347,11 +348,11 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
|
|
|
347
348
|
break;
|
|
348
349
|
case 13: // CR
|
|
349
350
|
break;
|
|
350
|
-
case 32: //
|
|
351
|
+
case 32: // space
|
|
351
352
|
// advance the offset without actually adding a character
|
|
352
353
|
offsetX += font.getXAdvance(charCode);
|
|
353
354
|
break;
|
|
354
|
-
case 9: //
|
|
355
|
+
case 9: // tab
|
|
355
356
|
offsetX += font.getXAdvance(charCode) * 2;
|
|
356
357
|
break;
|
|
357
358
|
default:
|
|
@@ -376,7 +377,8 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
|
|
|
376
377
|
|
|
377
378
|
$.text = (str, x, y, w, h) => {
|
|
378
379
|
if (!$._font) {
|
|
379
|
-
// check if online and loading the default font
|
|
380
|
+
// check if online and loading the default font
|
|
381
|
+
// hasn't been attempted yet
|
|
380
382
|
if (navigator.onLine && !initLoadDefaultFont) {
|
|
381
383
|
initLoadDefaultFont = true;
|
|
382
384
|
$.loadFont('https://q5js.org/fonts/YaHei-msdf.json');
|
|
@@ -535,27 +537,27 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
|
|
|
535
537
|
$._hooks.preRender.push(() => {
|
|
536
538
|
if (!$._charStack.length) return;
|
|
537
539
|
|
|
538
|
-
//
|
|
540
|
+
// calculate total buffer size for text data
|
|
539
541
|
let totalTextSize = 0;
|
|
540
542
|
for (let charsData of $._charStack) {
|
|
541
543
|
totalTextSize += charsData.length * 4;
|
|
542
544
|
}
|
|
543
545
|
|
|
544
|
-
//
|
|
546
|
+
// create a single buffer for all the char data
|
|
545
547
|
let charBuffer = Q5.device.createBuffer({
|
|
546
548
|
size: totalTextSize,
|
|
547
549
|
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
|
|
548
550
|
mappedAtCreation: true
|
|
549
551
|
});
|
|
550
552
|
|
|
551
|
-
//
|
|
553
|
+
// copy all the text data into the buffer
|
|
552
554
|
new Float32Array(charBuffer.getMappedRange()).set($._charStack.flat());
|
|
553
555
|
charBuffer.unmap();
|
|
554
556
|
|
|
555
|
-
//
|
|
557
|
+
// calculate total buffer size for metadata
|
|
556
558
|
let totalMetadataSize = $._textStack.length * 6 * 4;
|
|
557
559
|
|
|
558
|
-
//
|
|
560
|
+
// create a single buffer for all metadata
|
|
559
561
|
let textBuffer = Q5.device.createBuffer({
|
|
560
562
|
label: 'textBuffer',
|
|
561
563
|
size: totalMetadataSize,
|
|
@@ -563,11 +565,11 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
|
|
|
563
565
|
mappedAtCreation: true
|
|
564
566
|
});
|
|
565
567
|
|
|
566
|
-
//
|
|
568
|
+
// copy all metadata into the buffer
|
|
567
569
|
new Float32Array(textBuffer.getMappedRange()).set($._textStack.flat());
|
|
568
570
|
textBuffer.unmap();
|
|
569
571
|
|
|
570
|
-
//
|
|
572
|
+
// create a single bind group for the text buffer and metadata buffer
|
|
571
573
|
$._textBindGroup = Q5.device.createBindGroup({
|
|
572
574
|
label: 'msdf text bind group',
|
|
573
575
|
layout: textBindGroupLayout,
|