samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.7k stars 66 forks source link

I have a massive console logging of coordinates or something #89

Closed Apocritas99 closed 2 years ago

Apocritas99 commented 2 years ago

well what is happening is that i have a function to fit the text in a area lowering the font size this is the code

    textFith(ctx, text, font, px, x, y, maxWidth) {
        for (let index = 0; index < px; index++) {
            ctx.font = `${px - index}px ${font}`
            let txt = ctx.measureText(text)
            if (txt.width < maxWidth) {
                ctx.fillText(text, x, y);
                break;
            }
        }
    }

and in my console i have this and i'm sure that i don't have any console log in the code

ASSERT: 406.679688 != 428.242188
ASSERT: 406.679688 != 428.242188
ASSERT: 396.512695 != 417.536133
ASSERT: 396.512695 != 417.536133
ASSERT: 386.345703 != 406.830078
ASSERT: 386.345703 != 406.830078
ASSERT: 376.178711 != 396.124023
ASSERT: 376.178711 != 396.124023
ASSERT: 366.011719 != 385.417969
ASSERT: 366.011719 != 385.417969
ASSERT: 355.844727 != 374.711914
ASSERT: 355.844727 != 374.711914
ASSERT: 345.677734 != 364.005859
ASSERT: 345.677734 != 364.005859
ASSERT: 335.510742 != 353.299805
ASSERT: 335.510742 != 353.299805
ASSERT: 325.343750 != 342.593750
ASSERT: 325.343750 != 342.593750
ASSERT: 315.176758 != 331.887695
ASSERT: 315.176758 != 331.887695
ASSERT: 305.009766 != 321.181641
ASSERT: 305.009766 != 321.181641
ASSERT: 294.842773 != 310.475586
ASSERT: 294.842773 != 310.475586
ASSERT: 294.842773 != 310.475586
ASSERT: 406.679688 != 428.242188
ASSERT: 406.679688 != 428.242188
ASSERT: 396.512695 != 417.536133
ASSERT: 396.512695 != 417.536133
ASSERT: 386.345703 != 406.830078
ASSERT: 386.345703 != 406.830078
ASSERT: 376.178711 != 396.124023
ASSERT: 376.178711 != 396.124023
ASSERT: 366.011719 != 385.417969
ASSERT: 366.011719 != 385.417969
ASSERT: 355.844727 != 374.711914
ASSERT: 355.844727 != 374.711914
ASSERT: 345.677734 != 364.005859
ASSERT: 345.677734 != 364.005859
ASSERT: 335.510742 != 353.299805
ASSERT: 335.510742 != 353.299805
ASSERT: 325.343750 != 342.593750
ASSERT: 325.343750 != 342.593750
ASSERT: 315.176758 != 331.887695
ASSERT: 315.176758 != 331.887695
ASSERT: 305.009766 != 321.181641
ASSERT: 305.009766 != 321.181641
ASSERT: 294.842773 != 310.475586
ASSERT: 294.842773 != 310.475586
ASSERT: 294.842773 != 310.475586

i want to know if its an issue of the library or im doing something wrong

samizdatco commented 2 years ago

I can't reproduce this without knowing what values you were passing to the function. What did you supply for font, px, and maxWidth?

For me, the code below doesn't trigger any of those assertion messages:

function textFit(text, font, px, x, y, maxWidth) {
    for (let index = 0; index < px; index++) {
        ctx.font = `${px - index}px ${font}`
        let txt = ctx.measureText(text)
        if (txt.width < maxWidth) {
            ctx.fillText(text, x, y);
            return px-index
        }
    }
}

let size = textFit("Hello", "Arial", 20, 0, 0, 30)
console.log(size);
// prints: 13
Apocritas99 commented 2 years ago
textFith(ctx, 'Hello', 'Arista', 40, 196, 50, 315)
samizdatco commented 2 years ago

I tested against this version of Arista and still didn't get any unexpected output. What OS and node version are you running?

samizdatco commented 2 years ago

My guess is that the output you were seeing was coming from skia itself so hopefully the update to the newest milestone in 0.9.30 will have removed what looked to be unintentionally included debug code. Let me know if you keep seeing this issue with the current version of the library though...