(ctx, text, x, y, w, h, color, scale = 1)
| 3561 | ]; |
| 3562 | |
| 3563 | function drawOledBitmapText5x7(ctx, text, x, y, w, h, color, scale = 1) { |
| 3564 | const sx = Math.max(1, Math.floor(scale)); |
| 3565 | const sy = sx; |
| 3566 | const maxW = Math.max(0, Math.floor(w)); |
| 3567 | const maxH = Math.max(0, Math.floor(h)); |
| 3568 | const startX = Math.floor(x); |
| 3569 | const startY = Math.floor(y); |
| 3570 | let cx = 0; |
| 3571 | let cy = 0; |
| 3572 | const charW = 6 * sx; // 5 + 1 spacing |
| 3573 | const charH = 8 * sy; // 7 + 1 spacing |
| 3574 | |
| 3575 | ctx.fillStyle = color; |
| 3576 | const lines = String(text || "").split(/\r?\n/); |
| 3577 | for (let li = 0; li < lines.length; li++) { |
| 3578 | const line = lines[li]; |
| 3579 | cx = 0; |
| 3580 | for (let k = 0; k < line.length; k++) { |
| 3581 | const ch = line.charCodeAt(k) & 0xff; |
| 3582 | if (ch < 32 || ch > 127) { |
| 3583 | cx += charW; |
| 3584 | continue; |
| 3585 | } |
| 3586 | if (cx + charW > maxW) break; |
| 3587 | if (cy + charH > maxH) return; |
| 3588 | |
| 3589 | const base = (ch - 32) * 5; |
| 3590 | for (let col = 0; col < 5; col++) { |
| 3591 | const bits = OLED_FONT_5X7[base + col] || 0; |
| 3592 | for (let row = 0; row < 7; row++) { |
| 3593 | if ((bits >> row) & 0x01) { |
| 3594 | const px = startX + cx + col * sx; |
| 3595 | const py = startY + cy + row * sy; |
| 3596 | // clip |
| 3597 | if (px < startX || py < startY) continue; |
| 3598 | if (px >= startX + maxW || py >= startY + maxH) continue; |
| 3599 | ctx.fillRect(px, py, sx, sy); |
| 3600 | } |
| 3601 | } |
| 3602 | } |
| 3603 | cx += charW; |
| 3604 | } |
| 3605 | cy += charH; |
| 3606 | if (cy + charH > maxH) return; |
| 3607 | } |
| 3608 | } |
| 3609 | |
| 3610 | function drawOledThresholdedText(ctx, text, x, y, w, h, textSize, color) { |
| 3611 | const ts = Number(textSize || 1); |
no outgoing calls
no test coverage detected