Update create font processing sketch (#2604)

* Modified Create_font procesing sketch to enable generation of a C header file.

* Commented out the second fontName definition in Create_font.pde.

---------

Co-authored-by: Pierre-Loup Martin <pierreloupm@gmail.com>
This commit is contained in:
Bodmer
2023-04-23 18:01:23 +01:00
committed by GitHub
parent 7250c62146
commit 8aa653ceac
3 changed files with 1639 additions and 4 deletions

View File

@@ -134,11 +134,17 @@ String fontType = ".ttf";
// Define the font size in points for the TFT_eSPI font file
int fontSize = 20;
int fontSize = 28;
// Font size to use in the Processing sketch display window that pops up (can be different to above)
int displayFontSize = 28;
// Create a C header (.h file) ready to be used or copied in your sketch folder
boolean createHeaderFile = true;
// Automaticely open the folder with created files when done
boolean openFolder = false;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Next we specify which unicode blocks from the the Basic Multilingual Plane (BMP) are included in the final font file. //
// Note: The ttf/otf font file MAY NOT contain all possible Unicode characters, refer to the fonts online documentation. //
@@ -392,7 +398,7 @@ void setup() {
// Set the fontName from the array number or the defined fontName
if (fontNumber >= 0)
{
fontName = fontList[fontNumber];
// fontName = fontList[fontNumber];
fontType = "";
}
@@ -499,11 +505,13 @@ void setup() {
println("Created font " + fontName + str(fontSize) + ".vlw");
String fontFileName = "FontFiles/" + fontName + str(fontSize) + ".vlw";
// creating file
try {
print("Saving to sketch FontFiles folder... ");
OutputStream output = createOutput("FontFiles/" + fontName + str(fontSize) + ".vlw");
OutputStream output = createOutput(fontFileName);
font.save(output);
output.close();
@@ -513,11 +521,50 @@ void setup() {
// Open up the FontFiles folder to access the saved file
String path = sketchPath();
Desktop.getDesktop().open(new File(path+"/FontFiles"));
if(openFolder){
Desktop.getDesktop().open(new File(path+"/FontFiles"));
}
System.err.println("All done! Note: Rectangles are displayed for non-existant characters.");
}
catch(IOException e) {
println("Doh! Failed to create the file");
}
if(!createHeaderFile) return;
// Now creating header file if the option was specified.
try{
print("saving header file to FontFile folder...");
InputStream input = createInputRaw(fontFileName);
PrintWriter output = createWriter("FontFiles/" + fontName + str(fontSize) + ".h");
output.println("#include <pgmspace.h>");
output.println();
output.println("const uint8_t " + fontName + str(fontSize) + "[] PROGMEM = {");
int i = 0;
int data = input.read();
while(data != -1){
output.print("0x");
output.print(hex(data, 2));
if(i++ < 15){
output.print(", ");
} else {
output.println(",");
i = 0;
}
data = input.read();
}
// font.save(output);
output.println("\n};");
output.close();
input.close();
println("C header file created.");
} catch(IOException e){
println("Failed to create C header file");
}
}

File diff suppressed because it is too large Load Diff