I am new to Arduino programming and also not good at English. So sorry for bad English.
Recently I decided to made an project with Arduino Uno/Mega and display like st7735, ssd1302, sh1106, nokia5110 or any other display, because I have a collection of all of them.
In my project I need to show some Bengali word like "আমার সোনার " , "বাংলা আমি" "মুহিত আব্দ" etc.
So I search for such a library which support to display Unicode, Ascci letter and sentence.
I test Adafruit_GFX which is not working for me. Finally I got a library from olikraus and that is U8g2_for_Adafruit_GFX . This is an amazing library for me.
Because it support many native language like Bengali with huge number of font and icon.
But when I want to show Bengali word "আমার"
on my ST7735 display. But it show me the output আম ার
and want to show Bengali word "মুহিত"
on my ST7735 display but it show me the output ম ুহ িত
.
olikraus provide me a solution of this problem and it works fine for most of all Bengali letter or word. He solved it by reducing distance between the given letter. I attached it below code:
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <U8g2_for_Adafruit_GFX.h>
#define TFT_CS 8
#define TFT_RST 7
#define TFT_DC 6
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;
const uint16_t distance_adjust_table[] =
{
/* first char, second char, gap reduction value */
0x09AE, 0x9BE, 12, /* reduce distance between ম and া by 12 */
/* add more pairs here... */
0x09B8, 0x09CB, 14, //reduce distance between স and ো
0x09A8, 0x09BE, 12, //reduce distance between ন and া
0x09AE, 0x09BF, 16, //reduce distance between ম and ি
0x09AC, 0x09BE, 12, //reduce distance between ব and া
0x09BE, 0x0982, 12, //reduce distance between া and ং
0x09B2, 0x09BE, 12, //reduce distance between ল and া
0x09AC, 0x09CD, 12, //reduce distance between ব and ্
0x09CD, 0x09A6, 12, //reduce distance between ্ and দ
/* this line terminates the table */
0xffff, 0xffff, 0xffff
};
/* get distance from the distance table */
uint16_t get_distance_adjust(uint16_t e1, uint16_t e2)
{
uint16_t i;
i = 0;
for(;;)
{
if ( distance_adjust_table[i] == 0x0ffff )
break;
if ( distance_adjust_table[i] == e1 && distance_adjust_table[i+1] == e2 )
return distance_adjust_table[i+2];
i+=3;
}
return 0;
}
int16_t draw_string(U8G2_FOR_ADAFRUIT_GFX &u8g2, int16_t x, int16_t y, const char *str)
{
uint16_t e_prev = 0x0ffff;
uint16_t e;
uint16_t delta, adjust, sum;
delta = 0;
adjust = 0;
u8g2.utf8_state = 0;
sum = 0;
for(;;)
{
e = u8g2.utf8_next((uint8_t)*str);
if ( e == 0x0ffff )
break;
str++;
if ( e != 0x0fffe )
{
delta = u8g2_GetGlyphWidth(&(u8g2.u8g2), e);
adjust = get_distance_adjust(e_prev, e);
e_prev = e;
u8g2_DrawGlyph(&(u8g2.u8g2), x-adjust, y, e);
x += delta-adjust;
sum += delta-adjust;
}
}
return sum;
}
void setup(void) {
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(0);
tft.fillScreen(ST77XX_BLACK);
u8g2_for_adafruit_gfx.begin(tft);
}
void loop() {
u8g2_for_adafruit_gfx.setFontMode(1); // use u8g2 transparent mode (this is default)
u8g2_for_adafruit_gfx.setFontDirection(0); // left to right (this is default)
u8g2_for_adafruit_gfx.setForegroundColor(ST77XX_WHITE); // apply Adafruit GFX color
u8g2_for_adafruit_gfx.setCursor(0,20); // start writing at this position
u8g2_for_adafruit_gfx.setFont(u8g2_font_unifont_t_bengali); // select Bengali font
draw_string(u8g2_for_adafruit_gfx, 0,20, "আমার সোনার");
draw_string(u8g2_for_adafruit_gfx, 0,40, "বাংলা আমি"); // draw Bengali string
draw_string(u8g2_for_adafruit_gfx, 0,60, "আব্দ ল্লাহ");
}
In Bengali letter there are some compound letter like " ব্দ " which is formed from "ব+্+দ" , and letter "ম্ম" is formed "ম+্+ম" . If this type of compound letter work then I can complete my main project perfectly.
Now I need to display this " ব্দ " , "ম্ম" type of compound letter . I think this is difficult task than the previous one. But don't know how to do this.
If some know how to do this types of work please mention me.