@@ -37,52 +37,47 @@ void PocketmageOled::oledWord(String word, bool allowLarge, bool showInfo, Strin
3737 if (showInfo && bottomText == " " ) infoBar ();
3838 else if (bottomText != " " ) {
3939 u8g2_.setFont (u8g2_font_5x7_tf);
40- u8g2_.drawStr ((dw - u8g2_.getStrWidth (bottomText.c_str ())) / 2 , dh, bottomText.c_str ());
40+ u8g2_.drawUTF8 ((dw - u8g2_.getUTF8Width (bottomText.c_str ())) / 2 , dh, bottomText.c_str ());
4141 }
4242
43+ // Changed all _tr fonts to _tf to include the extended UTF-8 character set
4344 if (allowLarge) {
44- /* u8g2_.setFont(u8g2_font_ncenB24_tr);
45- if (u8g2_.getStrWidth(word.c_str()) < dw) {
46- u8g2_.drawStr((dw - u8g2_.getStrWidth(word.c_str()))/2,16+12,word.c_str());
47- u8g2_.sendBuffer();
48- return;
49- }*/
50- u8g2_.setFont (u8g2_font_ncenB18_tr);
51- if (u8g2_.getStrWidth (word.c_str ()) < dw) {
52- u8g2_.drawStr ((dw - u8g2_.getStrWidth (word.c_str ()))/2 , 16 +5 , word.c_str ());
45+ u8g2_.setFont (u8g2_font_ncenB18_tf);
46+ if (u8g2_.getUTF8Width (word.c_str ()) < dw) {
47+ u8g2_.drawUTF8 ((dw - u8g2_.getUTF8Width (word.c_str ()))/2 , 16 +5 , word.c_str ());
5348 u8g2_.sendBuffer ();
5449 return ;
5550 }
5651 }
5752
58- u8g2_.setFont (u8g2_font_ncenB14_tr );
59- if (u8g2_.getStrWidth (word.c_str ()) < dw) {
60- u8g2_.drawStr ((dw - u8g2_.getStrWidth (word.c_str ()))/2 , 16 +3 , word.c_str ());
53+ u8g2_.setFont (u8g2_font_ncenB14_tf );
54+ if (u8g2_.getUTF8Width (word.c_str ()) < dw) {
55+ u8g2_.drawUTF8 ((dw - u8g2_.getUTF8Width (word.c_str ()))/2 , 16 +3 , word.c_str ());
6156 u8g2_.sendBuffer ();
6257 return ;
6358 }
6459
65- u8g2_.setFont (u8g2_font_ncenB12_tr );
66- if (u8g2_.getStrWidth (word.c_str ()) < dw) {
67- u8g2_.drawStr ((dw - u8g2_.getStrWidth (word.c_str ()))/2 , 16 +2 , word.c_str ());
60+ u8g2_.setFont (u8g2_font_ncenB12_tf );
61+ if (u8g2_.getUTF8Width (word.c_str ()) < dw) {
62+ u8g2_.drawUTF8 ((dw - u8g2_.getUTF8Width (word.c_str ()))/2 , 16 +2 , word.c_str ());
6863 u8g2_.sendBuffer ();
6964 return ;
7065 }
7166
72- u8g2_.setFont (u8g2_font_ncenB10_tr );
73- if (u8g2_.getStrWidth (word.c_str ()) < dw) {
74- u8g2_.drawStr ((dw - u8g2_.getStrWidth (word.c_str ()))/2 , 16 +1 , word.c_str ());
67+ u8g2_.setFont (u8g2_font_ncenB10_tf );
68+ if (u8g2_.getUTF8Width (word.c_str ()) < dw) {
69+ u8g2_.drawUTF8 ((dw - u8g2_.getUTF8Width (word.c_str ()))/2 , 16 +1 , word.c_str ());
7570 u8g2_.sendBuffer ();
7671 return ;
7772 }
7873
79- u8g2_.setFont (u8g2_font_ncenB08_tr );
80- if (u8g2_.getStrWidth (word.c_str ()) < dw) {
81- u8g2_.drawStr ((dw - u8g2_.getStrWidth (word.c_str ()))/2 , 16 , word.c_str ());
74+ u8g2_.setFont (u8g2_font_ncenB08_tf );
75+ if (u8g2_.getUTF8Width (word.c_str ()) < dw) {
76+ u8g2_.drawUTF8 ((dw - u8g2_.getUTF8Width (word.c_str ()))/2 , 16 , word.c_str ());
8277 u8g2_.sendBuffer ();
8378 return ;
8479 } else {
85- u8g2_.drawStr (dw - u8g2_.getStrWidth (word.c_str ()), 16 , word.c_str ());
80+ u8g2_.drawUTF8 (dw - u8g2_.getUTF8Width (word.c_str ()), 16 , word.c_str ());
8681 u8g2_.sendBuffer ();
8782 return ;
8883 }
@@ -93,14 +88,13 @@ void PocketmageOled::oledLine(String line, int input_pos, bool doProgressBar, St
9388 const uint16_t dw = u8g2_.getDisplayWidth ();
9489 const uint16_t dh = u8g2_.getDisplayHeight ();
9590
96- uint8_t mcl = EINK ().maxCharsPerLine ();
97- uint8_t maxLength = mcl;
9891 String left = " " ;
9992 u8g2_.clearBuffer ();
10093
10194 // PROGRESS BAR
10295 if (doProgressBar && line.length () > 0 ) {
103- const uint16_t charWidth = strWidth (line);
96+ // Fixed string measurement
97+ const uint16_t charWidth = u8g2_.getUTF8Width (line.c_str ());
10498
10599 // Restored global display reference
106100 const uint8_t progress = map (charWidth, 0 , display.width () - 5 , 0 , dw);
@@ -128,9 +122,9 @@ void PocketmageOled::oledLine(String line, int input_pos, bool doProgressBar, St
128122 // Display bottomMsg
129123 else {
130124 u8g2_.setFont (u8g2_font_5x7_tf);
131- u8g2_.drawStr (0 , dh, bottomMsg.c_str ());
125+ u8g2_.drawUTF8 (0 , dh, bottomMsg.c_str ());
132126
133- // Draw FN/Shift indicator
127+ // Draw FN/Shift indicator (Standard ASCII is fine here)
134128 int state = KB ().getKeyboardState ();
135129 switch (state) {
136130 case 1 : // SHIFT
@@ -147,47 +141,51 @@ void PocketmageOled::oledLine(String line, int input_pos, bool doProgressBar, St
147141 }
148142 }
149143
150- // DRAW LINE TEXT (unchanged)
151- u8g2_.setFont (u8g2_font_ncenB18_tr);
152- if (u8g2_.getStrWidth (line.c_str ()) < (dw - 5 )) {
144+ // DRAW LINE TEXT (Upgraded to full UTF-8 Font and Draw routines)
145+ u8g2_.setFont (u8g2_font_ncenB18_tf);
146+ int lineWidth = u8g2_.getUTF8Width (line.c_str ());
147+
148+ if (lineWidth < (dw - 5 )) {
153149 if (line.length () > 0 ) {
154150 if (input_pos == 0 ) {
155- u8g2_.drawStr (0 , 20 , line.c_str ());
151+ u8g2_.drawUTF8 (0 , 20 , line.c_str ());
156152 u8g2_.drawVLine (0 , 1 , 22 );
157153 } else if (input_pos == line.length ()) {
158- u8g2_.drawStr (0 , 20 , line.c_str ());
159- u8g2_.drawVLine (u8g2_. getStrWidth (line. c_str ()) + 2 , 1 , 22 );
154+ u8g2_.drawUTF8 (0 , 20 , line.c_str ());
155+ u8g2_.drawVLine (lineWidth + 2 , 1 , 22 );
160156 } else {
161157 left = line.substring (0 , input_pos);
162- u8g2_.drawStr (0 , 20 , line.c_str ());
163- u8g2_.drawVLine (u8g2_.getStrWidth (left.c_str ()), 1 , 22 );
158+ u8g2_.drawUTF8 (0 , 20 , line.c_str ());
159+ u8g2_.drawVLine (u8g2_.getUTF8Width (left.c_str ()), 1 , 22 );
164160 }
165161 } else {
166- u8g2_.drawStr (0 , 20 , line.c_str ());
162+ u8g2_.drawUTF8 (0 , 20 , line.c_str ());
163+ u8g2_.drawVLine (0 , 1 , 22 ); // Still draw the cursor when string is empty
167164 }
168165 } else {
169166 if (input_pos == 0 ) {
170- u8g2_.drawStr (0 , 20 , line.c_str ());
167+ u8g2_.drawUTF8 (0 , 20 , line.c_str ());
171168 u8g2_.drawVLine (0 , 1 , 22 );
172169 } else if (input_pos == line.length ()) {
173170 // show end of line, input scrolls left
174- u8g2_.drawStr (dw - 8 - u8g2_. getStrWidth (line. c_str ()) , 20 , line.c_str ());
171+ u8g2_.drawUTF8 (dw - 8 - lineWidth , 20 , line.c_str ());
175172 u8g2_.drawVLine (dw - 6 , 1 , 22 );
176173 } else {
177- // calc cursor pos
174+ // calc cursor pos using perfect UTF-8 string split math
178175 left = line.substring (0 , input_pos);
179- int cursor_offset = u8g2_.getStrWidth (left.c_str ());
176+ int cursor_offset = u8g2_.getUTF8Width (left.c_str ());
180177 int line_start = 0 ;
178+
181179 if (cursor_offset > (dw - 8 ) / 2 ) {
182180 // shift left
183181 line_start += ((dw - 8 ) / 2 ) - cursor_offset;
184- if (line_start + u8g2_. getStrWidth (line. c_str ()) < dw - 8 ) {
182+ if (line_start + lineWidth < dw - 8 ) {
185183 // shift back right
186- line_start += dw - 8 - (line_start + u8g2_. getStrWidth (line. c_str ()) );
184+ line_start += dw - 8 - (line_start + lineWidth );
187185 }
188186 cursor_offset += line_start;
189187 }
190- u8g2_.drawStr (line_start, 20 , line.c_str ());
188+ u8g2_.drawUTF8 (line_start, 20 , line.c_str ());
191189 u8g2_.drawVLine (cursor_offset, 1 , 22 );
192190 }
193191 }
0 commit comments