Skip to content

Commit

Permalink
Add -o parameter support for gfx font converter.
Browse files Browse the repository at this point in the history
Improve documentation.
  • Loading branch information
gdex committed Nov 7, 2023
1 parent 5e59c54 commit a3d2cdf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ And there is nothing between.

Here, I started to fill this gap with the class library for the common embedded developers' tasks I faced in my own projects.
Also, it contains a common hardware interface (SPI, I2C, UART, RTC, etc) mapped to the framework-specific implementations.
Currently, ESP-IDF is supported, and the root CMake file is fully integrated into its native build system. The STM32-specific version is under development. And to make the transition fluent there is also an Arduino-based backend integrated with PlatformIO.
Currently, there are three ways to use library:
- ESP-IDF framework, can be imported as a component. The CMake file is fully integrated into its native build system.
- PlatformIO framework (Arduino backend). The library.json file is provided, so it can be imported as a library in the PlatformIO projects.
- A standalone CMake project. The CMakeLists.txt can be used as a standalone CMake project, the tests are provided in this way.

## The main concepts

Expand Down Expand Up @@ -79,22 +82,38 @@ EXPECT_EQ(*retrievedObject, testObject);
This library contains various graphics primitives, fonts and frame buffer.
See the [Readme](graphics/Readme.md) for details.
## GFX Font Converter
This is a console utility to convert the font from the TTF format to the GFX format used by the graphics library.
For the 7 bit (ASCII) charset it's compatible with the Adafruit GFX library.
For the 8 bit charset it's possible to specify the codepage to map one-byte character codes to the Unicode code points for rendering.
The non-printable codes between 0X7E and 0XA0 are omitted to save space.
Another difference is to create two binary files instead of C++ generated code. One for the font itself and another for the glyph metrics.
The utility is written in C++ and uses FreeType library to render the glyphs.
The suppported command line options are:
- -f, --font - the path to the TTF font file
- -s, --size - the output font size in points
- -d, --dpi - the output font resolution in DPI, default 141
- -e, --encoding - charset to use, default is ASCII (7-bit)
- -b - use binary format for the font data (default is generated C++ header)
- -o, --output - the output directory, default the executable's one.
## Hardware-independent interfaces
The library contains the hardware-independent interfaces for the common hardware:
- SpiDevice
- sendSync() - half-duplex send
- receiveSync() - half-duplex receive
- sendAndReceive() - full-duplex send and receive
- sendSync() - half-duplex blocking send
- receiveSync() - half-duplex blocking receive
- sendAndReceive() - full-duplex blocking send and receive
- I2CDevice
- sendSync() - send
- receiveSync() - receive
- sendSync() - blocking send with timeout
- receiveSync() - blocking receive with timeout
- PacketUart
- sendSync() - send
- receiveSync() - receive
- receiveUntil() - receive until the specified byte is received
- receiveBetween() - receive a packet betwiin specified start and stop bytes
- sendSync() - blocking send with timeout
- receiveSync() - blocking receive with timeout
- receiveUntil() - blocking receive until the specified byte is received or timeout happened
- receiveBetween() - blocking receive a packet between specified start and stop bytes, which are included in the result
## Hardware-specific implementations
Currencly Arduino and ESP-IDF frameworks are supported.
Currently, ESP32 and generic Arduino are supported. STM32 native implementation is under development.
2 changes: 1 addition & 1 deletion gfx-font-converter/FontConverterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FontConverterConfig::FontConverterConfig(int argc, char** argv)
fontFileName = optarg;
break;
case 'o':
outputFileName = optarg;
outputDirectory = optarg;
break;
case 'd':
DPI = std::stoi(optarg);
Expand Down
4 changes: 2 additions & 2 deletions gfx-font-converter/FontConverterConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FontConverterConfig
enum class Format { Header, Binary};
FontConverterConfig(int argc, char * argv[]);
const std::string& getFontFileName() const { return fontFileName; }
const std::string& getOutputFileName() const { return outputFileName; }
const std::string& getOutputDirectory() const { return outputDirectory; }
const std::string& getEncoding() const { return encoding; }
int getDPI() const { return DPI; }
int getFontSize() const { return fontSize; }
Expand All @@ -19,7 +19,7 @@ class FontConverterConfig
bool getPrintHelp() const { return printHelp; }
private:
std::string fontFileName;
std::string outputFileName;
std::string outputDirectory;
std::string encoding;
int DPI = 141;
int fontSize = 12;
Expand Down
5 changes: 3 additions & 2 deletions gfx-font-converter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ int main(int argc, char* argv[])
if (config.getPrintHelp() || fontFileName.empty())
{
std::cout << "Usage: " << std::filesystem::path(argv[0]).filename().string()
<< " -f fontfile [-o outputfile] [-d DPI] [-s size] [-l last char] [-e 8-bit codepage, default ISO-8859-1] [-h]"
<< " -f fontfile [-o outputfile] [-d DPI] [-s size] [-e 8-bit codepage, default ISO-8859-1] [-b] [-h]"
<< std::endl;
return 1;
}
Expand All @@ -271,7 +271,8 @@ int main(int argc, char* argv[])
fontName =
fontFilePath.filename().replace_extension("").string() + std::to_string(config.getFontSize()) + "pt" +
std::to_string(config.getLastChar() > 127 ? 8 : 7) + "b";
auto outputDir = std::filesystem::path(argv[0]).parent_path();
auto outputDir = std::filesystem::is_directory(config.getOutputDirectory()) ?
std::filesystem::path(config.getOutputDirectory()) : std::filesystem::path(argv[0]).parent_path();

const auto dpi = config.getDPI();
const FT_F26Dot6 fontSize = config.getFontSize() << 6;
Expand Down
22 changes: 3 additions & 19 deletions graphics/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,13 @@ It provides the following operations:

## EmbeddedFonts(.h/.cpp)

As an entry point for fonts used in application it declare and define a set of `EmbeddedFont` objects.
EmbeddedFonts.cpp contains a template for adding new fonts.
For the fonts converted to the C++ headers used in application it declares and define a set of `EmbeddedFont` objects.
EmbeddedFonts.cpp contains an example font definition and can be used as a template for adding new fonts.
It maps the GFX font definition files to `EmbeddedFont` objects.
The font definition files are located in `GFXFonts` directory. Initially it contains the following fonts:
* `FreeSans15pt7b`

The default font converter from Adafruit as well as online services available create a font file definition
with the C-style type casting of arrays. Instead, the adapter classes expect arrays for size deduction.
So you could modify the converter of just manually remove the castings like this:
```c++
// Original
const GFXfont FreeSans15pt7b PROGMEM = {
(uint8_t *)FreeSans15pt7bBitmaps,
(GFXglyph *)FreeSans15pt7bGlyphs,
0x20, 0x7E, 35 };

// Modified
const GFXfont FreeSans15pt7b PROGMEM = {
FreeSans15pt7bBitmaps,
FreeSans15pt7bGlyphs,
0x20, 0x7E, 35 };
```
## GFXFontsAdapter.h

Contains font and glyph adapters for GFX-compatible fonts.
It can be initialized from the embedded binary data or with the arrays from the generated C++ header
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "General Support Library",
"version": "1.0.0",
"description": "General C++ library for embedded development.",
"keywords": "C++17, esp32",
"keywords": "C++17, esp32, graphics, fonts",
"repository":
{
"type": "git",
Expand Down

0 comments on commit a3d2cdf

Please sign in to comment.