(ctx, text, x, y, w, h, textSize, color)
| 3608 | } |
| 3609 | |
| 3610 | function drawOledThresholdedText(ctx, text, x, y, w, h, textSize, color) { |
| 3611 | const ts = Number(textSize || 1); |
| 3612 | // For size 1, use a real bitmap font so it looks correct (no browser anti-alias artifacts). |
| 3613 | if (ts <= 1.05) { |
| 3614 | drawOledBitmapText5x7(ctx, text, x, y, w, h, color, 1); |
| 3615 | return; |
| 3616 | } |
| 3617 | const W = Math.max(1, Math.min(dispWidth, Math.floor(w))); |
| 3618 | const H = Math.max(1, Math.min(dispHeight, Math.floor(h))); |
| 3619 | if (!_oledTextCtx) return; |
| 3620 | |
| 3621 | _oledTextCanvas.width = W; |
| 3622 | _oledTextCanvas.height = H; |
| 3623 | _oledTextCtx.clearRect(0, 0, W, H); |
| 3624 | _oledTextCtx.imageSmoothingEnabled = false; |
| 3625 | _oledTextCtx.fillStyle = "#ffffff"; |
| 3626 | _oledTextCtx.textBaseline = "top"; |
| 3627 | _oledTextCtx.textAlign = "left"; |
| 3628 | const px = Math.max(6, Math.floor(8 * (Number(textSize || 1)))); |
| 3629 | _oledTextCtx.font = `${px}px ui-monospace, Menlo, Consolas, monospace`; |
| 3630 | |
| 3631 | const lines = String(text || "").split(/\r?\n/); |
| 3632 | const lh = Math.max(1, Math.floor(px + 1)); |
| 3633 | lines.forEach((line, idx) => _oledTextCtx.fillText(line, 0, idx * lh)); |
| 3634 | |
| 3635 | const data = _oledTextCtx.getImageData(0, 0, W, H).data; |
| 3636 | ctx.fillStyle = color; |
| 3637 | for (let j = 0; j < H; j++) { |
| 3638 | for (let i = 0; i < W; i++) { |
| 3639 | const a = data[(j * W + i) * 4 + 3]; |
| 3640 | if (a > 90) ctx.fillRect(x + i, y + j, 1, 1); |
| 3641 | } |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | function drawOledThresholdedImage(ctx, src, x, y, w, h, color) { |
| 3646 | const img = getCachedOledImage(src); |
no test coverage detected