2626ArduinoGraphics::ArduinoGraphics (int width, int height) :
2727 _width(width),
2828 _height(height),
29- _font(NULL )
29+ _font(NULL ),
30+ _textSizeX(1 ),
31+ _textSizeY(1 )
3032{
3133}
3234
@@ -241,7 +243,7 @@ void ArduinoGraphics::text(const char* str, int x, int y)
241243 uint8_t const c = (uint8_t )*str++;
242244
243245 if (c == ' \n ' ) {
244- y += _font->height ;
246+ y += _font->height * _textSizeY ;
245247 } else if (c == ' \r ' ) {
246248 x = 0 ;
247249 } else if (c == 0xc2 || c == 0xc3 ) {
@@ -254,10 +256,10 @@ void ArduinoGraphics::text(const char* str, int x, int y)
254256 }
255257
256258 if (b) {
257- bitmap (b, x, y, _font->width , _font->height );
259+ bitmap (b, x, y, _font->width , _font->height , _textSizeX, _textSizeY );
258260 }
259261
260- x += _font->width ;
262+ x += _font->width * _textSizeX ;
261263 }
262264 }
263265}
@@ -269,38 +271,51 @@ void ArduinoGraphics::textFont(const Font& which)
269271
270272int ArduinoGraphics::textFontWidth () const
271273{
272- return (_font ? _font->width : 0 );
274+ return (_font ? _font->width * _textSizeX : 0 );
273275}
274276
275277int ArduinoGraphics::textFontHeight () const
276278{
277- return (_font ? _font->height : 0 );
279+ return (_font ? _font->height * _textSizeY : 0 );
278280}
279281
280- void ArduinoGraphics::bitmap ( const uint8_t * data, int x, int y, int width, int height )
282+ void ArduinoGraphics::textSize ( uint8_t sx, uint8_t sy )
281283{
282- if (!_stroke) {
284+ _textSizeX = (sx > 0 )? sx : 1 ;
285+ _textSizeY = (sy > 0 )? sy : 1 ;
286+ }
287+
288+
289+ void ArduinoGraphics::bitmap (const uint8_t * data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y) {
290+ if (!_stroke || !scale_x || !scale_y) {
283291 return ;
284292 }
285293
286- if ((data == NULL ) || ((x + width ) < 0 ) || ((y + height ) < 0 ) || (x > _width) || (y > _height)) {
294+ if ((data == nullptr ) || ((x + (w * scale_x ) < 0 )) || ((y + (h * scale_y ) < 0 ) ) || (x > _width) || (y > _height)) {
287295 // offscreen
288296 return ;
289297 }
290298
291- for (int j = 0 ; j < height; j++) {
299+ int xStart = x;
300+ for (int j = 0 ; j < h; j++) {
292301 uint8_t b = data[j];
293-
294- for (int i = 0 ; i < width; i++) {
295- if (b & (1 << (7 - i))) {
296- set (x + i, y + j, _strokeR, _strokeG, _strokeB);
297- } else {
298- set (x + i, y + j, _backgroundR, _backgroundG, _backgroundB);
302+ for (uint8_t ys = 0 ; ys < scale_y; ys++) {
303+ if (ys >= _height) return ;
304+ x = xStart; // reset for each row
305+ for (int i = 0 ; i < w; i++) {
306+ if (b & (1 << (7 - i))) {
307+ for (uint8_t xs = 0 ; xs < scale_x; xs++) set (x++, y, _strokeR, _strokeG, _strokeB);
308+ } else {
309+ for (uint8_t xs = 0 ; xs < scale_x; xs++) set (x++, y, _backgroundR, _backgroundG, _backgroundB);
310+ }
311+ if (x >= _width) break ;
299312 }
313+ y++;
300314 }
301315 }
302316}
303317
318+
304319void ArduinoGraphics::imageRGB (const Image& img, int x, int y, int width, int height)
305320{
306321 const uint8_t * data = img.data ();
@@ -359,7 +374,7 @@ void ArduinoGraphics::image(const Image& img, int x, int y)
359374
360375void ArduinoGraphics::image (const Image& img, int x, int y, int width, int height)
361376{
362- if (!img || ((x + width) < 0 ) || ((y + height) < 0 ) || (x > _width) || (y > height )) {
377+ if (!img || ((x + width) < 0 ) || ((y + height) < 0 ) || (x > _width) || (y > _height )) {
363378 // offscreen
364379 return ;
365380 }
@@ -438,7 +453,7 @@ void ArduinoGraphics::endText(int scrollDirection)
438453 beginDraw ();
439454 int const text_x = _textX - i;
440455 text (_textBuffer, text_x, _textY);
441- bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height );
456+ bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height , _textSizeX, _textSizeY );
442457 endDraw ();
443458
444459 delay (_textScrollSpeed);
@@ -450,7 +465,7 @@ void ArduinoGraphics::endText(int scrollDirection)
450465 beginDraw ();
451466 int const text_x = _textX - (scrollLength - i - 1 );
452467 text (_textBuffer, text_x, _textY);
453- bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height );
468+ bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height , _textSizeX, _textSizeY );
454469 endDraw ();
455470
456471 delay (_textScrollSpeed);
@@ -462,7 +477,7 @@ void ArduinoGraphics::endText(int scrollDirection)
462477 beginDraw ();
463478 int const text_y = _textY - i;
464479 text (_textBuffer, _textX, text_y);
465- bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 );
480+ bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 , _textSizeX, _textSizeY );
466481 endDraw ();
467482
468483 delay (_textScrollSpeed);
@@ -474,7 +489,7 @@ void ArduinoGraphics::endText(int scrollDirection)
474489 beginDraw ();
475490 int const text_y = _textY - (scrollLength - i - 1 );
476491 text (_textBuffer, _textX, text_y);
477- bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 );
492+ bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 , _textSizeX, _textSizeY );
478493 endDraw ();
479494
480495 delay (_textScrollSpeed);
0 commit comments