This commit is contained in:
Chris van Marle 2024-10-02 01:20:16 +05:30 committed by GitHub
commit 68f9b097ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
62 changed files with 459 additions and 0 deletions

2
render/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
render

25
render/Arduino.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef __ARDUINO_H__
#define __ARDUINO_H__
// Minimal Arduino.h implementation
// to support compilation of Adafruit_GFX
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h> // for strlen
#define PROGMEM
typedef const char *__FlashStringHelper;
// Empty String class
// Doesn't really work, but isn't used either
// Only defined to make Adafruit_GFX compile
class String {
public:
inline unsigned int length(void) const { return 0; }
const char *c_str() const { return ""; }
};
#endif

BIN
render/DefaultFont.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

BIN
render/FreeMono12pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 990 B

BIN
render/FreeMono18pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
render/FreeMono24pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
render/FreeMono9pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1020 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

BIN
render/FreeSans12pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
render/FreeSans18pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
render/FreeSans24pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
render/FreeSans9pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 B

BIN
render/FreeSerif12pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

BIN
render/FreeSerif18pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
render/FreeSerif24pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
render/FreeSerif9pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

20
render/Makefile Normal file
View File

@ -0,0 +1,20 @@
CPP=g++
CPPFLAGS=-Wall -g -I. -DARDUINO=100
OBJS=Adafruit_GFX.o RenderGFX.o render.o
LIBS=-lgd -lpng
TARGET=render
GFX_PATH=../
all: $(TARGET)
render: $(OBJS)
$(CPP) -o $@ $^ $(LIBS)
%.o: %.c
$(CPP) -c -o $@ $< $(CPPFLAGS)
Adafruit_GFX.o: $(GFX_PATH)/Adafruit_GFX.cpp
$(CPP) -c -o $@ $< $(CPPFLAGS)
clean:
rm -rf $(OBJS) $(TARGET)

BIN
render/Org_01.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

BIN
render/Picopixel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

28
render/Print.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef __PRINT_H__
#define __PRINT_H__
#include <cstdio>
class Print {
public:
virtual size_t write(uint8_t) = 0;
virtual size_t write(const uint8_t *buffer, size_t size) {
size_t n = 0;
while (size--) {
if (write(*buffer++))
n++;
else
break;
}
return n;
}
size_t print(const char *str) { return write(str, strlen(str)); }
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}
};
#endif

176
render/README.md Normal file
View File

@ -0,0 +1,176 @@
# Adafruit GFX Examples Rendering
A little tool to render examples of all the fonts included in the Adafruit GFX library.
**Compile**:
`$ make`
**Run**:
`$ ./render`
**Update Readme**:
`$ ./update_readme.sh`
## Fonts
### DefaultFont
![DefaultFont](DefaultFont.png)
### FreeMono12pt7b
![FreeMono12pt7b](FreeMono12pt7b.png)
### FreeMono18pt7b
![FreeMono18pt7b](FreeMono18pt7b.png)
### FreeMono24pt7b
![FreeMono24pt7b](FreeMono24pt7b.png)
### FreeMono9pt7b
![FreeMono9pt7b](FreeMono9pt7b.png)
### FreeMonoBold12pt7b
![FreeMonoBold12pt7b](FreeMonoBold12pt7b.png)
### FreeMonoBold18pt7b
![FreeMonoBold18pt7b](FreeMonoBold18pt7b.png)
### FreeMonoBold24pt7b
![FreeMonoBold24pt7b](FreeMonoBold24pt7b.png)
### FreeMonoBold9pt7b
![FreeMonoBold9pt7b](FreeMonoBold9pt7b.png)
### FreeMonoBoldOblique12pt7b
![FreeMonoBoldOblique12pt7b](FreeMonoBoldOblique12pt7b.png)
### FreeMonoBoldOblique18pt7b
![FreeMonoBoldOblique18pt7b](FreeMonoBoldOblique18pt7b.png)
### FreeMonoBoldOblique24pt7b
![FreeMonoBoldOblique24pt7b](FreeMonoBoldOblique24pt7b.png)
### FreeMonoBoldOblique9pt7b
![FreeMonoBoldOblique9pt7b](FreeMonoBoldOblique9pt7b.png)
### FreeMonoOblique12pt7b
![FreeMonoOblique12pt7b](FreeMonoOblique12pt7b.png)
### FreeMonoOblique18pt7b
![FreeMonoOblique18pt7b](FreeMonoOblique18pt7b.png)
### FreeMonoOblique24pt7b
![FreeMonoOblique24pt7b](FreeMonoOblique24pt7b.png)
### FreeMonoOblique9pt7b
![FreeMonoOblique9pt7b](FreeMonoOblique9pt7b.png)
### FreeSans12pt7b
![FreeSans12pt7b](FreeSans12pt7b.png)
### FreeSans18pt7b
![FreeSans18pt7b](FreeSans18pt7b.png)
### FreeSans24pt7b
![FreeSans24pt7b](FreeSans24pt7b.png)
### FreeSans9pt7b
![FreeSans9pt7b](FreeSans9pt7b.png)
### FreeSansBold12pt7b
![FreeSansBold12pt7b](FreeSansBold12pt7b.png)
### FreeSansBold18pt7b
![FreeSansBold18pt7b](FreeSansBold18pt7b.png)
### FreeSansBold24pt7b
![FreeSansBold24pt7b](FreeSansBold24pt7b.png)
### FreeSansBold9pt7b
![FreeSansBold9pt7b](FreeSansBold9pt7b.png)
### FreeSansBoldOblique12pt7b
![FreeSansBoldOblique12pt7b](FreeSansBoldOblique12pt7b.png)
### FreeSansBoldOblique18pt7b
![FreeSansBoldOblique18pt7b](FreeSansBoldOblique18pt7b.png)
### FreeSansBoldOblique24pt7b
![FreeSansBoldOblique24pt7b](FreeSansBoldOblique24pt7b.png)
### FreeSansBoldOblique9pt7b
![FreeSansBoldOblique9pt7b](FreeSansBoldOblique9pt7b.png)
### FreeSansOblique12pt7b
![FreeSansOblique12pt7b](FreeSansOblique12pt7b.png)
### FreeSansOblique18pt7b
![FreeSansOblique18pt7b](FreeSansOblique18pt7b.png)
### FreeSansOblique24pt7b
![FreeSansOblique24pt7b](FreeSansOblique24pt7b.png)
### FreeSansOblique9pt7b
![FreeSansOblique9pt7b](FreeSansOblique9pt7b.png)
### FreeSerif12pt7b
![FreeSerif12pt7b](FreeSerif12pt7b.png)
### FreeSerif18pt7b
![FreeSerif18pt7b](FreeSerif18pt7b.png)
### FreeSerif24pt7b
![FreeSerif24pt7b](FreeSerif24pt7b.png)
### FreeSerif9pt7b
![FreeSerif9pt7b](FreeSerif9pt7b.png)
### FreeSerifBold12pt7b
![FreeSerifBold12pt7b](FreeSerifBold12pt7b.png)
### FreeSerifBold18pt7b
![FreeSerifBold18pt7b](FreeSerifBold18pt7b.png)
### FreeSerifBold24pt7b
![FreeSerifBold24pt7b](FreeSerifBold24pt7b.png)
### FreeSerifBold9pt7b
![FreeSerifBold9pt7b](FreeSerifBold9pt7b.png)
### FreeSerifBoldItalic12pt7b
![FreeSerifBoldItalic12pt7b](FreeSerifBoldItalic12pt7b.png)
### FreeSerifBoldItalic18pt7b
![FreeSerifBoldItalic18pt7b](FreeSerifBoldItalic18pt7b.png)
### FreeSerifBoldItalic24pt7b
![FreeSerifBoldItalic24pt7b](FreeSerifBoldItalic24pt7b.png)
### FreeSerifBoldItalic9pt7b
![FreeSerifBoldItalic9pt7b](FreeSerifBoldItalic9pt7b.png)
### FreeSerifItalic12pt7b
![FreeSerifItalic12pt7b](FreeSerifItalic12pt7b.png)
### FreeSerifItalic18pt7b
![FreeSerifItalic18pt7b](FreeSerifItalic18pt7b.png)
### FreeSerifItalic24pt7b
![FreeSerifItalic24pt7b](FreeSerifItalic24pt7b.png)
### FreeSerifItalic9pt7b
![FreeSerifItalic9pt7b](FreeSerifItalic9pt7b.png)
### Org_01
![Org_01](Org_01.png)
### Picopixel
![Picopixel](Picopixel.png)
### Tiny3x3a2pt7b
![Tiny3x3a2pt7b](Tiny3x3a2pt7b.png)
### TomThumb
![TomThumb](TomThumb.png)

22
render/RenderGFX.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "RenderGFX.h"
#include <cstdio>
RenderGFX::RenderGFX(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
im = gdImageCreate(w, h);
}
void RenderGFX::drawPixel(int16_t x, int16_t y, uint16_t color) {
gdImageSetPixel(im, x, y, color);
}
uint16_t RenderGFX::color(uint8_t r, uint8_t g, uint8_t b) {
return gdImageColorAllocate(im, r, g, b);
}
void RenderGFX::save(const char *name) {
FILE *pngout = fopen(name, "wb");
gdImagePng(im, pngout);
fclose(pngout);
}

22
render/RenderGFX.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __RENDERGFX_H
#define __RENDERGFX_H
#include "../Adafruit_GFX.h"
#include "Arduino.h"
#include <gd.h>
class RenderGFX : public Adafruit_GFX {
public:
RenderGFX(uint16_t w, uint16_t h);
virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
virtual uint16_t color(uint8_t r, uint8_t g, uint8_t b);
virtual void save(const char *name);
protected:
gdImagePtr im;
};
#endif

BIN
render/Tiny3x3a2pt7b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

BIN
render/TomThumb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

159
render/render.cpp Normal file
View File

@ -0,0 +1,159 @@
#include "Arduino.h"
#include "RenderGFX.h"
#include <cstdio>
#include <stdint.h>
// Update includes:
// for FILE in ../Fonts/*.h; do printf '#include "%s"\n' "$FILE"; done
#include "../Fonts/FreeMono12pt7b.h"
#include "../Fonts/FreeMono18pt7b.h"
#include "../Fonts/FreeMono24pt7b.h"
#include "../Fonts/FreeMono9pt7b.h"
#include "../Fonts/FreeMonoBold12pt7b.h"
#include "../Fonts/FreeMonoBold18pt7b.h"
#include "../Fonts/FreeMonoBold24pt7b.h"
#include "../Fonts/FreeMonoBold9pt7b.h"
#include "../Fonts/FreeMonoBoldOblique12pt7b.h"
#include "../Fonts/FreeMonoBoldOblique18pt7b.h"
#include "../Fonts/FreeMonoBoldOblique24pt7b.h"
#include "../Fonts/FreeMonoBoldOblique9pt7b.h"
#include "../Fonts/FreeMonoOblique12pt7b.h"
#include "../Fonts/FreeMonoOblique18pt7b.h"
#include "../Fonts/FreeMonoOblique24pt7b.h"
#include "../Fonts/FreeMonoOblique9pt7b.h"
#include "../Fonts/FreeSans12pt7b.h"
#include "../Fonts/FreeSans18pt7b.h"
#include "../Fonts/FreeSans24pt7b.h"
#include "../Fonts/FreeSans9pt7b.h"
#include "../Fonts/FreeSansBold12pt7b.h"
#include "../Fonts/FreeSansBold18pt7b.h"
#include "../Fonts/FreeSansBold24pt7b.h"
#include "../Fonts/FreeSansBold9pt7b.h"
#include "../Fonts/FreeSansBoldOblique12pt7b.h"
#include "../Fonts/FreeSansBoldOblique18pt7b.h"
#include "../Fonts/FreeSansBoldOblique24pt7b.h"
#include "../Fonts/FreeSansBoldOblique9pt7b.h"
#include "../Fonts/FreeSansOblique12pt7b.h"
#include "../Fonts/FreeSansOblique18pt7b.h"
#include "../Fonts/FreeSansOblique24pt7b.h"
#include "../Fonts/FreeSansOblique9pt7b.h"
#include "../Fonts/FreeSerif12pt7b.h"
#include "../Fonts/FreeSerif18pt7b.h"
#include "../Fonts/FreeSerif24pt7b.h"
#include "../Fonts/FreeSerif9pt7b.h"
#include "../Fonts/FreeSerifBold12pt7b.h"
#include "../Fonts/FreeSerifBold18pt7b.h"
#include "../Fonts/FreeSerifBold24pt7b.h"
#include "../Fonts/FreeSerifBold9pt7b.h"
#include "../Fonts/FreeSerifBoldItalic12pt7b.h"
#include "../Fonts/FreeSerifBoldItalic18pt7b.h"
#include "../Fonts/FreeSerifBoldItalic24pt7b.h"
#include "../Fonts/FreeSerifBoldItalic9pt7b.h"
#include "../Fonts/FreeSerifItalic12pt7b.h"
#include "../Fonts/FreeSerifItalic18pt7b.h"
#include "../Fonts/FreeSerifItalic24pt7b.h"
#include "../Fonts/FreeSerifItalic9pt7b.h"
#include "../Fonts/Org_01.h"
#include "../Fonts/Picopixel.h"
#include "../Fonts/Tiny3x3a2pt7b.h"
#include "../Fonts/TomThumb.h"
#include "../gfxfont.h"
#define SCALE 2
#define BORDER_SIZE 5 * SCALE
void render(const char *filename, GFXfont *font, bool correctBox = true) {
printf("%s\n", filename);
const char *text = "The Quick Brown Fox Jumps Over The Lazy Dog";
int16_t sizex, sizey;
uint16_t sizew, sizeh;
RenderGFX render(1000, 1000);
render.setTextWrap(false);
render.setTextSize(SCALE);
render.setFont(font);
render.getTextBounds(text, 0, 0, &sizex, &sizey, &sizew, &sizeh);
printf("Size: %d, %d, %d, %d\n", sizex, sizey, sizew, sizeh);
render = RenderGFX(sizew + 2 * BORDER_SIZE, sizeh + 2 * BORDER_SIZE);
int black = render.color(0, 0, 0);
int white = render.color(255, 255, 255);
int lgrey = render.color(200, 200, 200);
int yoff = BORDER_SIZE - (correctBox ? sizey : 0);
render.fillScreen(white);
render.setFont(font);
render.setCursor(BORDER_SIZE, yoff);
render.setTextSize(SCALE);
render.setTextColor(black);
render.print(text);
render.drawRect(BORDER_SIZE, BORDER_SIZE, sizew, sizeh, lgrey);
render.save(filename);
}
void render(const char *filename, GFXfont font, bool correctBox = true) {
render(filename, &font, correctBox);
}
int main(int argc, char **argv) {
// Update render calls:
// for FILE in ../Fonts/*.h; do
// NAME=$(basename "$FILE" .h);
// printf ' render("%s.png", %s);\n' "$NAME" "$NAME";
// done
render("FreeMono12pt7b.png", FreeMono12pt7b);
render("FreeMono18pt7b.png", FreeMono18pt7b);
render("FreeMono24pt7b.png", FreeMono24pt7b);
render("FreeMono9pt7b.png", FreeMono9pt7b);
render("FreeMonoBold12pt7b.png", FreeMonoBold12pt7b);
render("FreeMonoBold18pt7b.png", FreeMonoBold18pt7b);
render("FreeMonoBold24pt7b.png", FreeMonoBold24pt7b);
render("FreeMonoBold9pt7b.png", FreeMonoBold9pt7b);
render("FreeMonoBoldOblique12pt7b.png", FreeMonoBoldOblique12pt7b);
render("FreeMonoBoldOblique18pt7b.png", FreeMonoBoldOblique18pt7b);
render("FreeMonoBoldOblique24pt7b.png", FreeMonoBoldOblique24pt7b);
render("FreeMonoBoldOblique9pt7b.png", FreeMonoBoldOblique9pt7b);
render("FreeMonoOblique12pt7b.png", FreeMonoOblique12pt7b);
render("FreeMonoOblique18pt7b.png", FreeMonoOblique18pt7b);
render("FreeMonoOblique24pt7b.png", FreeMonoOblique24pt7b);
render("FreeMonoOblique9pt7b.png", FreeMonoOblique9pt7b);
render("FreeSans12pt7b.png", FreeSans12pt7b);
render("FreeSans18pt7b.png", FreeSans18pt7b);
render("FreeSans24pt7b.png", FreeSans24pt7b);
render("FreeSans9pt7b.png", FreeSans9pt7b);
render("FreeSansBold12pt7b.png", FreeSansBold12pt7b);
render("FreeSansBold18pt7b.png", FreeSansBold18pt7b);
render("FreeSansBold24pt7b.png", FreeSansBold24pt7b);
render("FreeSansBold9pt7b.png", FreeSansBold9pt7b);
render("FreeSansBoldOblique12pt7b.png", FreeSansBoldOblique12pt7b);
render("FreeSansBoldOblique18pt7b.png", FreeSansBoldOblique18pt7b);
render("FreeSansBoldOblique24pt7b.png", FreeSansBoldOblique24pt7b);
render("FreeSansBoldOblique9pt7b.png", FreeSansBoldOblique9pt7b);
render("FreeSansOblique12pt7b.png", FreeSansOblique12pt7b);
render("FreeSansOblique18pt7b.png", FreeSansOblique18pt7b);
render("FreeSansOblique24pt7b.png", FreeSansOblique24pt7b);
render("FreeSansOblique9pt7b.png", FreeSansOblique9pt7b);
render("FreeSerif12pt7b.png", FreeSerif12pt7b);
render("FreeSerif18pt7b.png", FreeSerif18pt7b);
render("FreeSerif24pt7b.png", FreeSerif24pt7b);
render("FreeSerif9pt7b.png", FreeSerif9pt7b);
render("FreeSerifBold12pt7b.png", FreeSerifBold12pt7b);
render("FreeSerifBold18pt7b.png", FreeSerifBold18pt7b);
render("FreeSerifBold24pt7b.png", FreeSerifBold24pt7b);
render("FreeSerifBold9pt7b.png", FreeSerifBold9pt7b);
render("FreeSerifBoldItalic12pt7b.png", FreeSerifBoldItalic12pt7b);
render("FreeSerifBoldItalic18pt7b.png", FreeSerifBoldItalic18pt7b);
render("FreeSerifBoldItalic24pt7b.png", FreeSerifBoldItalic24pt7b);
render("FreeSerifBoldItalic9pt7b.png", FreeSerifBoldItalic9pt7b);
render("FreeSerifItalic12pt7b.png", FreeSerifItalic12pt7b);
render("FreeSerifItalic18pt7b.png", FreeSerifItalic18pt7b);
render("FreeSerifItalic24pt7b.png", FreeSerifItalic24pt7b);
render("FreeSerifItalic9pt7b.png", FreeSerifItalic9pt7b);
render("Org_01.png", Org_01);
render("Picopixel.png", Picopixel);
render("Tiny3x3a2pt7b.png", Tiny3x3a2pt7b);
render("TomThumb.png", TomThumb);
render("DefaultFont.png", NULL);
return 0;
}

5
render/update_readme.sh Executable file
View File

@ -0,0 +1,5 @@
sed -i -n '0,/## Fonts/p' README.md
for FILE in *.png; do
NAME=${FILE%.*};
echo -e "### $NAME\n![$NAME]($FILE)\n";
done >> README.md