Update oled-guide.mdx (#1467)

* Update oled-guide.mdx

* better formatting for the entire page

---------

Co-authored-by: rcarteraz <robert.l.carter2@gmail.com>
This commit is contained in:
panaceya 2024-11-20 02:18:20 +02:00 committed by GitHub
parent ff3e52e39f
commit 63d314fcce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,14 +5,27 @@ sidebar_label: OLED Localization
sidebar_position: 3 sidebar_position: 3
--- ---
1. Create an extended ASCII custom font. Use a glyph editor to create a new font file. The easiest way is to use the online [glyph editor](https://rawgit.com/ThingPulse/esp8266-oled-ssd1306/master/resources/glyphEditor.html) from the OLED library. ([glyph editor source code](https://github.com/ThingPulse/esp8266-oled-ssd1306/tree/master/resources)) ## Overview of Localization Steps
This guide provides instructions for localizing an OLED display by creating custom fonts, updating relevant code files, and defining language settings. The localization process involves the following steps:
### 1. Create an Extended ASCII Custom Font
Use a glyph editor to create a new font file. The easiest way is to use the online [glyph editor](https://rawgit.com/ThingPulse/esp8266-oled-ssd1306/master/resources/glyphEditor.html) from the OLED library ([glyph editor source code](https://github.com/ThingPulse/esp8266-oled-ssd1306/tree/master/resources)).
1. Copy and paste the existing font. 1. Copy and paste the existing font.
2. Modify it according desired codepage and save the new font file in `graphics/font` folder. 2. Modify it according to the desired codepage and save the new font file in the `graphics/font` folder.
Please note that the used font file format differs from common Adafruit GFX.
2. Update the `customFontTableLookup` function in `Screen.h` _Note: The font file format differs from the common Adafruit GFX format._
1. To map the double-byte UTF-8 code to the corresponding extended ASCII character of the desired codepage update the `customFontTableLookup` function in the `Screen.h` file.
2. Modify the `switch (last)` statement: use left byte from UTF-8 code in the `case` label to map character's right byte to its extended ASCII code by specifying an offset. ### 2. Update the `customFontTableLookup` Function in `Screen.h`
3. Define language and font in `Screen.cpp`
1. Map the double-byte UTF-8 code to the corresponding extended ASCII character of the desired codepage by updating the `customFontTableLookup` function in the `Screen.h` file.
2. Modify the `switch (last)` statement: Use the left byte from the UTF-8 code in the `case` label to map the character's right byte to its extended ASCII code by specifying an offset.
### 3. Define Language and Font in `Screen.cpp`
Add language-specific font definitions using conditional compilation:
```c ```c
#ifdef OLED_{LANG_NAME} #ifdef OLED_{LANG_NAME}
@ -28,7 +41,11 @@ sidebar_position: 3
#endif #endif
``` ```
4. Define language in `variant/*/platformio.ini` ### 4. Configure Language Settings
#### Primary Method: Define in `variant/*/platformio.ini`
Language settings can be defined in the `platformio.ini` file under the appropriate variant directory:
```text ```text
build_flags = build_flags =
@ -37,3 +54,13 @@ sidebar_position: 3
-D OLED_{LANG_NAME} -D OLED_{LANG_NAME}
-I variants/xxxxx -I variants/xxxxx
``` ```
#### Alternative: Define in `userPrefs.h`
As an alternative to modifying `platformio.ini`, the language can be defined in `userPrefs.h`.
```c
#define OLED_{LANG_NAME}
```
Both methods achieve the same result, and the choice depends on the specific project setup.