diff options
| author | Andrés Cuervo <andrescuervor@gmail.com> | 2023-05-18 19:11:58 +0000 |
|---|---|---|
| committer | Andrés Cuervo <andrescuervor@gmail.com> | 2023-05-18 19:11:58 +0000 |
| commit | 2a15e4fc9b148f4c8bee30cda8d8f66ea556612f (patch) | |
| tree | dcbe497283572a59464a1a2fbb278c48b0b983b9 | |
| parent | Different style of fillQuad and quads in april tags (diff) | |
| download | folk-2a15e4fc9b148f4c8bee30cda8d8f66ea556612f.tar.gz folk-2a15e4fc9b148f4c8bee30cda8d8f66ea556612f.zip | |
Add font scaling
| -rw-r--r-- | pi/Display.tcl | 56 | ||||
| -rw-r--r-- | virtual-programs/label.folk | 4 |
2 files changed, 18 insertions, 42 deletions
diff --git a/pi/Display.tcl b/pi/Display.tcl index a6c168c4..a8bde6e7 100644 --- a/pi/Display.tcl +++ b/pi/Display.tcl @@ -137,47 +137,23 @@ dc proc drawCircle {int x0 int y0 int radius int color} void { } } -dc proc drawText {int x0 int y0 int upsidedown char* text} void { +dc proc drawText {int x0 int y0 int upsidedown int scale char* text} void { // Draws 1 line of text (no linebreak handling). - - /* size_t width = text.len * font.char_width; */ - /* size_t height = font.char_height; */ - /* if (x0 < 0 || y0 < 0 || */ - /* x0 + width >= fbwidth || y0 + height >= fbheight) return; */ - - /* printf("%d x %d\n", font.char_width, font.char_height); */ - /* printf("[%c] (%d)\n", c, c); */ - int len = strlen(text); - if (upsidedown) { - for (unsigned i = 0; i < len; i++) { - for (unsigned y = 0; y < font.char_height; y++) { - for (unsigned x = 0; x < font.char_width; x++) { - int idx = (text[i] * font.char_height * 2) + (y * 2) + (x >= 8 ? 1 : 0); - int bit = (font.font_bitmap[idx] >> (7 - (x & 7))) & 0x01; - - int sx = ((len-i)*font.char_width + x0-x); - int sy = y0 - y; - if (sx >= 0 && sx < fbwidth && sy >= 0 && sy < fbheight) { - if (bit) { - staging[(sy*fbwidth) + sx] = 0xFFFF; - } - } - } - } - } - } else { - for (unsigned i = 0; i < len; i++) { - for (unsigned y = 0; y < font.char_height; y++) { - for (unsigned x = 0; x < font.char_width; x++) { - int idx = (text[i] * font.char_height * 2) + (y * 2) + (x >= 8 ? 1 : 0); - int bit = (font.font_bitmap[idx] >> (7 - (x & 7))) & 0x01; - - int sx = (i*font.char_width + x0+x); - int sy = y0 + y; - if (sx >= 0 && sx < fbwidth && sy >= 0 && sy < fbheight) { - if (bit) { - staging[(sy*fbwidth) + sx] = 0xFFFF; + for (unsigned i = 0; i < len; i++) { + for (unsigned y = 0; y < font.char_height; y++) { + for (unsigned x = 0; x < font.char_width; x++) { + int idx = (text[i] * font.char_height * 2) + (y * 2) + (x >= 8 ? 1 : 0); + int bit = (font.font_bitmap[idx] >> (7 - (x & 7))) & 0x01; + + if(bit) { + for (int dy = 0; dy < scale; dy++) { + for (int dx = 0; dx < scale; dx++) { + int sx = x0 + (((upsidedown ? len-i : i) * font.char_width + (upsidedown ? -x : x))) * scale + dx; + int sy = y0 + (y * (upsidedown ? -1 : 1)) * scale + dy; + if (sx >= 0 && sx < fbwidth && sy >= 0 && sy < fbheight) { + staging[(sy*fbwidth) + sx] = 0xFFFF; + } } } } @@ -290,7 +266,7 @@ namespace eval Display { } proc text {fb x y fontSize text radians} { - drawText [expr {int($x)}] [expr {int($y)}] [expr {abs($radians) < 1.57}] $text + drawText [expr {int($x)}] [expr {int($y)}] [expr {abs($radians) < 1.57}] $fontSize $text } proc circle {x y radius thickness color} { for {set i 0} {$i < $thickness} {incr i} { diff --git a/virtual-programs/label.folk b/virtual-programs/label.folk index 03f92daf..eef544a8 100644 --- a/virtual-programs/label.folk +++ b/virtual-programs/label.folk @@ -14,11 +14,11 @@ When /thing/ has region /region/ { if {$text eq ""} { return } set lines [split $text "\n"] - set fontSize 12 + set fontSize 1 for {set lineNum 0} {$lineNum < [llength $lines]} {incr lineNum} { set shouldFlip [expr {abs($radians) < 1.57}] if {$::isLaptop} { set shouldFlip false} - set ly [expr {$shouldFlip ? $y+$lineNum*18 : $y+$lineNum*18}] + set ly [expr {$shouldFlip ? $y+$lineNum*$fontSize*18 : $y+$lineNum*$fontSize*18}] Display::text device $x $ly $fontSize [lindex [expr {$shouldFlip ? [lreverse $lines] : $lines }] $lineNum] $radians } } |
