Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the fixed fonts to be scaled up. #45

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

KurtE
Copy link
Contributor

@KurtE KurtE commented Aug 12, 2024

This hopefully addresses issue #3

On larger displays, the two built in fonts are almost invisible. One possible solution is to supply some larger fonts.

Another approach is to do, like several TFT display drivers do and allow you to scale the system fixed fonts up to a larger size. Decided this was the easiest approach, and did a quick implementation of it. Like the Adafruit displays, I allowed you to set different scale factors for X and Y.

I added a scaledBitmap function which is a modified version of the current bitmap function. I also changed all of the text functions to use it. I left the unscalled version of the API, although I have it simply call the scaled version with scales 1 and 1, as since these methods are virtual, potentially some other subclasses might use and/or implement their own version.

Updated the textFontWidth and textFontHeight to multiply the height * the scale as the one example sketch here needs it.

I also updated the sketch to scale the canvas to take the font size into account. This appears to work with the changes and

I have not used or tested the scroll code. Its sizing should be updated teh same way the test sketch was with the changes with the textFontWidth and textFontHeight changes

Copy link

Memory usage change @ 6d1e09e

Board flash % RAM for global variables %
arduino:samd:arduino_zero_edbg 🔺 +364 - +364 +0.14 - +0.14 🔺 +3728 - +3728 +11.38 - +11.38
arduino:samd:mkrzero 🔺 +364 - +364 +0.14 - +0.14 🔺 +3728 - +3728 +11.38 - +11.38
arduino:samd:nano_33_iot 🔺 +364 - +364 +0.14 - +0.14 🔺 +3728 - +3728 +11.38 - +11.38
Click for full report table
Board examples/ASCIIDraw
flash
% examples/ASCIIDraw
RAM for global variables
%
arduino:samd:arduino_zero_edbg 364 0.14 3728 11.38
arduino:samd:mkrzero 364 0.14 3728 11.38
arduino:samd:nano_33_iot 364 0.14 3728 11.38
Click for full report CSV
Board,examples/ASCIIDraw<br>flash,%,examples/ASCIIDraw<br>RAM for global variables,%
arduino:samd:arduino_zero_edbg,364,0.14,3728,11.38
arduino:samd:mkrzero,364,0.14,3728,11.38
arduino:samd:nano_33_iot,364,0.14,3728,11.38

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Aug 12, 2024
@KurtE
Copy link
Contributor Author

KurtE commented Aug 12, 2024

As I mentioned in the forum thread:
https://forum.arduino.cc/t/arduino-h7-video-h-and-arduinographics-library-fonts/1289636/3?u=kurte

I have run what tests I know of for this library. I believe there are integration issues between this library and
the Arduino_H7_Video library, but that is caused by these changes. So I will go ahead and mark it ready for review

Copy link
Contributor

@leonardocavagnis leonardocavagnis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good!

Some adjustments for consistency:

  • _textsize_x, _textsize_y -> _textSizeX, _textSizeY
  • setTextSize() -> textSize()
  • remove scaledBitmap function, and overload bitmap with default values

@@ -114,6 +118,8 @@ class ArduinoGraphics : public Print {
uint8_t _textR, _textG, _textB;
int _textX;
int _textY;
uint8_t _textsize_x;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint8_t _textsize_x;
uint8_t _textSizeX;

@@ -114,6 +118,8 @@ class ArduinoGraphics : public Print {
uint8_t _textR, _textG, _textB;
int _textX;
int _textY;
uint8_t _textsize_x;
uint8_t _textsize_y;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint8_t _textsize_y;
uint8_t _textSizeY;

@@ -92,6 +94,8 @@ class ArduinoGraphics : public Print {

protected:
virtual void bitmap(const uint8_t* data, int x, int y, int width, int height);
virtual void scaledBitmap(const uint8_t* data, int x, int y, int width, int height,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
virtual void scaledBitmap(const uint8_t* data, int x, int y, int width, int height,

@@ -92,6 +94,8 @@ class ArduinoGraphics : public Print {

protected:
virtual void bitmap(const uint8_t* data, int x, int y, int width, int height);
virtual void scaledBitmap(const uint8_t* data, int x, int y, int width, int height,
uint8_t scale_x, uint8_t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint8_t scale_x, uint8_t);

@@ -92,6 +94,8 @@ class ArduinoGraphics : public Print {

protected:
virtual void bitmap(const uint8_t* data, int x, int y, int width, int height);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
virtual void bitmap(const uint8_t* data, int x, int y, int width, int height);
virtual void bitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x = 1, uint8_t scale_y = 1);

@@ -26,7 +26,9 @@
ArduinoGraphics::ArduinoGraphics(int width, int height) :
_width(width),
_height(height),
_font(NULL)
_font(NULL),
_textsize_x(1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_textsize_x(1),
_textSizeX(1),

_font(NULL)
_font(NULL),
_textsize_x(1),
_textsize_y(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_textsize_y(1)
_textSizeY(1)

@@ -85,6 +86,7 @@ void setup() {
ASCIIDraw.stroke('@', 0, 0);
const char text[] = "ARDUINO";
ASCIIDraw.textFont(Font_5x7);
ASCIIDraw.setTextSize(fontSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ASCIIDraw.setTextSize(fontSize);
ASCIIDraw.textSize(fontSize);

Comment on lines 291 to 295
// forward to scaled version
scaledBitmap(data, x, y, width, height, 1, 1);
}

void ArduinoGraphics::scaledBitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// forward to scaled version
scaledBitmap(data, x, y, width, height, 1, 1);
}
void ArduinoGraphics::scaledBitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y) {

_textsize_y = (sy > 0)? sy : 1;
}


void ArduinoGraphics::bitmap(const uint8_t* data, int x, int y, int width, int height)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void ArduinoGraphics::bitmap(const uint8_t* data, int x, int y, int width, int height)
void ArduinoGraphics::bitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I pushed up the changes that were requested.
First attempt forgot to update the example sketch.

Let me know if I missed anything.

@leonardocavagnis leonardocavagnis linked an issue Sep 2, 2024 that may be closed by this pull request
@leonardocavagnis
Copy link
Contributor

Thank you for the changes!
Could you please rebase and merge the modifications into a single commit? Also, could you update the API documentation to include the textSize function?

Copy link

github-actions bot commented Sep 2, 2024

Memory usage change @ 7169c43

Board flash % RAM for global variables %
arduino:samd:arduino_zero_edbg 🔺 +316 - +316 +0.12 - +0.12 🔺 +3728 - +3728 +11.38 - +11.38
arduino:samd:mkrzero 🔺 +316 - +316 +0.12 - +0.12 🔺 +3728 - +3728 +11.38 - +11.38
arduino:samd:nano_33_iot 🔺 +316 - +316 +0.12 - +0.12 🔺 +3728 - +3728 +11.38 - +11.38
Click for full report table
Board examples/ASCIIDraw
flash
% examples/ASCIIDraw
RAM for global variables
%
arduino:samd:arduino_zero_edbg 316 0.12 3728 11.38
arduino:samd:mkrzero 316 0.12 3728 11.38
arduino:samd:nano_33_iot 316 0.12 3728 11.38
Click for full report CSV
Board,examples/ASCIIDraw<br>flash,%,examples/ASCIIDraw<br>RAM for global variables,%
arduino:samd:arduino_zero_edbg,316,0.12,3728,11.38
arduino:samd:mkrzero,316,0.12,3728,11.38
arduino:samd:nano_33_iot,316,0.12,3728,11.38

On larger displays, the two built in fonts are almost invisible.
One possible solution is to supply some larger fonts.

Another approach is to do, like several TFT display drivers do and allow you to scale the system fixed fonts up to a larger size.  Decided this was the easiest approach, and did a quick implementation of it.  Like the Adafruit displays, I allowed you to set different scale factors for X and Y.

I added a scaledBitmap function which is a modified version of the current bitmap function.  I also changed all of the text functions to use it.  I left the unscalled version of the API, although I have it simply call the scaled version with scales 1 and 1, as since these methods are virtual, potentially some other subclasses might use and/or implement their own version.

Updated the textFontWidth and textFontHeight to multiply  the height * the scale as
the one example sketch here needs it.

I also updated the sketch to scale the canvas to take the font size into account.
This appears to work with the changes and

I have not used or tested the scroll code.  Its sizing should be updated teh same way
the test sketch was with the changes with the textFontWidth and textFontHeight changes

Update api.md

Forgot to update the AsciiDraw example sketch

Code Review requested changes

_textsize_x -> _textSizeX  (ditto for y)
setTextSize() -> textSize()

scaledBitmap -> bitmap with the extra parameters with defaults
@KurtE
Copy link
Contributor Author

KurtE commented Sep 2, 2024

Pushed up changes and squashed all down to 1...

Copy link

github-actions bot commented Sep 2, 2024

Memory usage change @ 0ea3666

Board flash % RAM for global variables %
arduino:samd:arduino_zero_edbg 🔺 +316 - +316 +0.12 - +0.12 🔺 +3728 - +3728 +11.38 - +11.38
arduino:samd:mkrzero 🔺 +316 - +316 +0.12 - +0.12 🔺 +3728 - +3728 +11.38 - +11.38
arduino:samd:nano_33_iot 🔺 +316 - +316 +0.12 - +0.12 🔺 +3728 - +3728 +11.38 - +11.38
Click for full report table
Board examples/ASCIIDraw
flash
% examples/ASCIIDraw
RAM for global variables
%
arduino:samd:arduino_zero_edbg 316 0.12 3728 11.38
arduino:samd:mkrzero 316 0.12 3728 11.38
arduino:samd:nano_33_iot 316 0.12 3728 11.38
Click for full report CSV
Board,examples/ASCIIDraw<br>flash,%,examples/ASCIIDraw<br>RAM for global variables,%
arduino:samd:arduino_zero_edbg,316,0.12,3728,11.38
arduino:samd:mkrzero,316,0.12,3728,11.38
arduino:samd:nano_33_iot,316,0.12,3728,11.38

@leonardocavagnis leonardocavagnis merged commit 4241408 into arduino-libraries:master Sep 2, 2024
6 checks passed
@KurtE KurtE deleted the text_size branch September 2, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
3 participants