経緯
e-Paperプログラムに付属していた等幅フォント(モノスペースフォント)ですが、見栄えがあまり良くなかったため、プロポーショナルフォント風に改良してみました。

手順
1.構造体 sFONTに文字幅を指定するための lengthOffset を定義しました。8行目
diff --git a/fonts.h b/fonts.h
index 3015167..164f8ca 100644
--- a/fonts.h
+++ b/fonts.h
@@ -48,6 +48,7 @@
#include <stdint.h>
struct sFONT {
+ const uint8_t *lengthOffset;
const uint8_t *table;
uint16_t Width;
uint16_t Height
2.等幅フォントでは、次の文字の書き出し位置 refcolumn にフォント幅 font->Width を加算します。15行目
3.幅の狭い文字(例:i、l、I など)の場合は、送りを調整するため、refcolumn から定数 lengthOffsetの値を差し引きます。16行目
4.17〜19行目 幅の狭い文字(例:i、l、I など)が連続する場合は、送りをさらに戻して調整します。17〜19行目
diff --git a/epdpaint.cpp b/epdpaint.cpp
index 859b964..64e51a5 100644
--- a/epdpaint.cpp
+++ b/epdpaint.cpp
@@ -169,13 +169,13 @@ void Paint::DrawStringAt(int x, int y, const char* text, sFONT* font, int colore
const char* p_text = text;
unsigned int counter = 0;
int refcolumn = x;
-
while (*p_text != 0) {
DrawCharAt(refcolumn, y, *p_text, font, colored);
refcolumn += font->Width;
+ refcolumn -= font->lengthOffset[ *p_text - ' ' ];
+ if(*p_text == 'l' && *(p_text+1) == 'l') refcolumn -= 3;
+ if(*p_text == 'i' && *(p_text+1) == 'i') refcolumn -= 3;
+ if(*p_text == 'I' && *(p_text+1) == 'I') refcolumn -= 2;
p_text++;
counter++;
5.文字幅指定用の lengthOffset は、ASCIIコード 0x20〜0x7F の範囲で定義しています。11〜17行目
6.sFONT 構造体の Font20 に、文字幅テーブル Font20_Length を追加しました。25行目
diff --git a/font20.cpp b/font20.cpp
index 70a220f..fd51c93 100644
--- a/font20.cpp
+++ b/font20.cpp
@@ -40,6 +40,18 @@
#include <avr/pgmspace.h>
+
+const uint8_t Font20_Length[] PROGMEM =
+{
+
+ 1,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,2,3,1,2,1,2,1,3,3,1,1,1,1,3,3,
+ 2,1,1,1,1,1,1,0,2,2,2,1,1,1,1,1,
+ 1,2,3,2,2,4,3,2,3,5,4,4,3,2,2,2,
+ 2,2,4,3,4,2,2,2,2,3,2,1,1,1,1,1
+};
+
const uint8_t Font20_Table[] PROGMEM =
{
@@ -2135,6 +2147,7 @@ const uint8_t Font20_Table[] PROGMEM =
sFONT Font20 = {
+ Font20_Length,
Font20_Table,
14,
20,
7.font24``font16``font12``font8も同様の構造にしました
以上です。最後まで読んでいただき、ありがとうございました。