-
Notifications
You must be signed in to change notification settings - Fork 4
/
Persian_Letters_WEMOS.ino
1203 lines (1164 loc) · 30.9 KB
/
Persian_Letters_WEMOS.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Persian/Arabic letters on WEMOS D1 mini with OLED Shield (usable with any 0.66" display).
// Add "SparkFun Micro OLED Breakout" library from "Library Manager" window and then Upload code !
//
// Copyright (C) 2018 Sadraldin Rastegar and Ramin Sangesari
// https://github.com/idreamsi/arduino-persian-reshaper
//
//////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Wire.h> // Include Wire if you're using I2C
#include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library
#define PIN_RESET 255 //
#define DC_JUMPER 0 // I2C Addres: 0 - 0x3C, 1 - 0x3D
MicroOLED oled(PIN_RESET, DC_JUMPER); // Example I2C declaration
#define setpixel(x, y, color) oled.pixel(x, y, color, NORM)
#define LCDWidth oled.getLCDWidth()
#define ALIGN_CENTER(t) (LCDWidth - ((LCDWidth - (LCDWidth - CalcTextWidth(t))) / 2)) - 2
#define ALIGN_RIGHT LCDWidth
#define ALIGN_LEFT(t) LCDWidth - CalcTextWidth(t)
//8x8 Persian Letters
//This is the font definition. You can use http://gurgleapps.com/tools/matrix to create your own font.
const unsigned char PeChar[71][8] PROGMEM = {
0x00, 0x1C, 0x20, 0x08, 0x08, 0x08, 0x08, 0x00, //0 alef1
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, //1 alef2
0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, //2 alef3
0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x02, //3 be1
0x00, 0x00, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x10, //4 be2
0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x07, //5 pe1
0x00, 0x00, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x38, //6 pe2
0x00, 0x03, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, //7 te1
0x00, 0x14, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x00, //8 te2
0x02, 0x05, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, //9 the1
0x08, 0x14, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x00, //10 the2
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x04, //11 jim1
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x3A, //12 jim2
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x1C, //13 che1
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x37, //14 che2
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x00, //15 hee1
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x38, //16 hee2
0x00, 0x20, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x00, //17 khe1
0x00, 0x20, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x38, //18 khe2
0x00, 0x00, 0x04, 0x02, 0x01, 0x12, 0x0C, 0x00, //19 dal
0x00, 0x10, 0x04, 0x02, 0x01, 0x12, 0x0C, 0x00, //20 zal
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x0C, //21 re
0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02, 0x0C, //22 ze
0x02, 0x05, 0x00, 0x01, 0x01, 0x01, 0x02, 0x0C, //23 zhe
0x00, 0x00, 0x00, 0x15, 0x15, 0x6A, 0x00, 0x00, //24 sin1
0x00, 0x00, 0x00, 0x15, 0x95, 0x9A, 0x90, 0x60, //25 sin2
0x04, 0x0A, 0x00, 0x15, 0x15, 0x6A, 0x00, 0x00, //26 shin1
0x04, 0x0A, 0x00, 0x15, 0x95, 0x9A, 0x90, 0x60, //27 shin2
0x00, 0x00, 0x06, 0x29, 0x31, 0x5E, 0x00, 0x00, //28 sad1
0x00, 0x00, 0x06, 0x49, 0x91, 0x9E, 0x90, 0x60, //29 sad2
0x00, 0x10, 0x06, 0x29, 0x31, 0x5E, 0x00, 0x00, //30 zad1
0x00, 0x10, 0x06, 0x49, 0x91, 0x9E, 0x90, 0x60, //31 zad2
0x00, 0x20, 0x26, 0x29, 0x31, 0x7E, 0x00, 0x00, //32 taa
0x00, 0x28, 0x26, 0x29, 0x31, 0x7E, 0x00, 0x00, //33 zaa
0x00, 0x00, 0x03, 0x04, 0x04, 0x0F, 0x00, 0x00, //34 ein1
0x00, 0x00, 0x1E, 0x22, 0x1C, 0x77, 0x00, 0x00, //35 ein2
0x00, 0x1E, 0x22, 0x1C, 0x24, 0x23, 0x20, 0x1C, //36 ein3
0x00, 0x03, 0x04, 0x04, 0x0F, 0x10, 0x10, 0x0F, //37 ein4
0x00, 0x08, 0x03, 0x04, 0x04, 0x0F, 0x00, 0x00, //38 qein1
0x08, 0x00, 0x1E, 0x22, 0x1C, 0x77, 0x00, 0x00, //39 qein2
0x40, 0x1E, 0x22, 0x1C, 0x24, 0x23, 0x20, 0x1C, //40 qein3
0x08, 0x03, 0x04, 0x04, 0x0F, 0x10, 0x10, 0x0F, //41 qein4
0x04, 0x00, 0x06, 0x09, 0x09, 0x1E, 0x00, 0x00, //42 fe1
0x04, 0x00, 0x06, 0x89, 0x89, 0x7E, 0x00, 0x00, //43 fe2
0x06, 0x00, 0x06, 0x09, 0x09, 0x1E, 0x00, 0x00, //44 qaf1
0x06, 0x00, 0x06, 0x09, 0x49, 0x47, 0x41, 0x3E, //45 qaf2
0x00, 0x0F, 0x10, 0x1E, 0x01, 0x3E, 0x00, 0x00, //46 kaf1
0x00, 0x07, 0x08, 0x8E, 0x81, 0x7E, 0x00, 0x00, //47 kaf2
0x07, 0x0F, 0x10, 0x1E, 0x01, 0x3E, 0x00, 0x00, //48 gaf1
0x07, 0x0F, 0x10, 0x9E, 0x81, 0x7E, 0x00, 0x00, //49 gaf2
0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00, //50 lam1
0x00, 0x01, 0x01, 0x11, 0x21, 0x22, 0x1C, 0x00, //51 lam2
0x00, 0x00, 0x06, 0x09, 0x09, 0x36, 0x00, 0x00, //52 mim1
0x00, 0x04, 0x0A, 0x19, 0x29, 0x46, 0x40, 0x20, //53 mim2
0x00, 0x02, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, //54 noon1
0x00, 0x00, 0x08, 0x21, 0x41, 0x41, 0x22, 0x1C, //55 noon2
0x00, 0x00, 0x06, 0x09, 0x09, 0x07, 0x01, 0x0E, //56 vaav
0x08, 0x04, 0x0A, 0x15, 0x09, 0x36, 0x00, 0x00, //57 he1
0x00, 0x00, 0x30, 0x48, 0x56, 0xE9, 0x50, 0x20, //58 he2
0x00, 0x07, 0x09, 0x09, 0x05, 0x00, 0x00, 0x00, //59 he3
0x00, 0x08, 0x04, 0x0A, 0x11, 0x11, 0x0E, 0x00, //60 he4
0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x06, //61 ye1
0x00, 0x00, 0x00, 0x4C, 0x92, 0x89, 0x84, 0x78, //62 ye2
0x00, 0x06, 0x29, 0x48, 0x46, 0x41, 0x21, 0x1E, //63 ye3
0x0C, 0x12, 0x10, 0x08, 0x04, 0x00, 0x04, 0x00, //64 soal
0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x00, //65 tajob
0x00, 0x00, 0x00, 0x04, 0x08, 0x0C, 0x0C, 0x00, //66 vir
0x10, 0x08, 0x04, 0x04, 0x04, 0x04, 0x08, 0x10, //67 kmn1
0x04, 0x08, 0x10, 0x10, 0x10, 0x10, 0x08, 0x04, //68 kmn2
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, //69 slash
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, //70 backslash
};
//Persian Numbers 8x8
const unsigned char num[10][8] PROGMEM = {
0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x06, 0x00, //0
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, //1
0x00, 0x09, 0x09, 0x0E, 0x08, 0x08, 0x08, 0x00, //2
0x00, 0x25, 0x25, 0x3A, 0x20, 0x20, 0x20, 0x00, //3
0x00, 0x03, 0x14, 0x14, 0x1F, 0x10, 0x10, 0x00, //4
0x00, 0x08, 0x04, 0x12, 0x21, 0x29, 0x16, 0x00, //5
0x00, 0x10, 0x21, 0x22, 0x1C, 0x08, 0x10, 0x00, //6
0x00, 0x11, 0x11, 0x0A, 0x0A, 0x04, 0x04, 0x00, //7
0x00, 0x04, 0x04, 0x0A, 0x0A, 0x11, 0x11, 0x00, //8
0x00, 0x06, 0x09, 0x09, 0x07, 0x01, 0x01, 0x00, //9
};
void setup() {
//Serial.begin(9600);
oled.begin();
oled.clear(PAGE);
oled.rect(0,0,oled.getLCDWidth(),oled.getLCDHeight(),WHITE,NORM);
char txt[] = "آی دریمز";
PutCharPE(txt,ALIGN_CENTER(txt),8,1,WHITE);
char txt2[] = "فارسی نویسی";
PutCharPE(txt2,ALIGN_CENTER(txt2),26,1,WHITE);
//To make them visible on the display hardware!
oled.display();
}
void loop() {
}
char* strreverse(char* s)
{
char* beg = s-1, *end = s, tmp;
while (*++end);
while (end-- > ++beg)
{
tmp = *beg;
*beg = *end;
*end = tmp;
}
return s;
}
void drawBitmapPE(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color) {
int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
uint8_t byte = 0;
for(int16_t j=0; j<h; j++, y++) {
for(int16_t i=0; i<w; i++) {
if(i & 7) byte <<= 1;
else byte = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
if(byte & 0x80) setpixel(x+i, y, color);
}
}
}
bool isFromTheSet1(unsigned char ch)
{
const unsigned char theSet1[18] = {
32, '\0', 199, 194, 207, 208, 209, 210,
184, 168, 191, 40, 41, 46, 33, 44,
58, 248};
int i = 0;
while (i < 18)
{
if(ch == theSet1[i])
return true;
++i;
}
return false;
}
bool isFromTheSet2(unsigned char ch)
{
const unsigned char theSet1[10] = {
32, '\0', 191, 40, 41, 46, 33, 44,
58, 248
};
int i = 0;
while (i < 10)
{
if(ch == theSet1[i])
return true;
++i;
}
return false;
}
void PutCharPE(char *Text, int x, int y, int dis, uint16_t color){
int cursor_x = x-8;
int cursor_y = y;
int stat = 0;
unsigned char qloghat = ' '; //Previous word
unsigned char loghat;
unsigned char bloghat; //Next word
unsigned char le;
int d;
while(le = *Text++){
//is Number ?
if (le >= '0' && le <= '9') {
d = le - '0';
loghat = le;
}
else if(le >= 128){
loghat = *Text++;
loghat += 32;
le += 32;
if(loghat == 207){
if(le == 218 || le == 250){
loghat = 144; //گ
}
}
else if(loghat == 166)
{
if(le == 218 || le == 250){ //چ
loghat = 141;
}
else
{
loghat = 228; //ن
}
}
}
else
{
loghat = le;
}
if(loghat==172)
{
if(le==248 || le==32)
{
loghat=44;
}
}
le = *Text++;
if(le >= 128)
{
bloghat = *Text++;
bloghat += 32;
le += 32;
if(bloghat == 207)
{
if(le == 218 || le == 250)
{
bloghat = 144; //گ
}
}
else if(bloghat == 166)
{
if(le == 218 || le == 250)
{ //چ
bloghat = 141;
}
else
{
bloghat = 228; //ن
}
}
*Text--;
*Text--;
}
else
{
bloghat = le;
*Text--;
}
if(bloghat==172)
{
if(le==248 || le==32)
{
bloghat=44;
}
}
int isunk = 0;
/*
Final: at the end of the word
Medial: at the middle of the word
Initial: at the beginning of the word
Isolated: the character alone (not part of a word).
*/
if (isFromTheSet1(qloghat))
if (isFromTheSet2(bloghat))
stat = 0; //Isolated
else
stat = 1; //Initial
else
if (isFromTheSet2(bloghat))
stat = 2; //Final
else
stat = 3; //Medial
switch(loghat){
case 48: //zero
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 7;
break;
case 49: //1
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 5;
break;
case 50: //2
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 7;
break;
case 51: //3
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 8;
break;
case 52: //4
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 8;
break;
case 53: //5
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 8;
break;
case 54: //6
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 8;
break;
case 55: //7
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 7;
break;
case 56: //8
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 7;
break;
case 57: //9
drawBitmapPE(cursor_x, cursor_y, num[d], 8, 8, color);
cursor_x -= 6;
break;
case 32: //فاصله
cursor_x -= 2;
break;
case 191: //؟
drawBitmapPE(cursor_x, cursor_y, PeChar[64], 8, 8, color);
cursor_x -= 6;
break;
case 47: // /
drawBitmapPE(cursor_x, cursor_y, PeChar[70], 8, 8, color);
cursor_x -= 8;
break;
case 33: //!
drawBitmapPE(cursor_x, cursor_y, PeChar[65], 8, 8, color);
cursor_x -= 3;
break;
case 46: //.
setpixel(cursor_x+6, cursor_y+5, color);
setpixel(cursor_x+6, cursor_y+6, color);
setpixel(cursor_x+5, cursor_y+5, color);
setpixel(cursor_x+5, cursor_y+6, color);
cursor_x -= 4;
break;
case 58: //:
setpixel(cursor_x+6, cursor_y+2, color);
setpixel(cursor_x+6, cursor_y+5, color);
cursor_x -= 3;
break;
case ',': //،
drawBitmapPE(cursor_x, cursor_y, PeChar[66], 8, 8, color);
cursor_x -= 5;
break;
case 40: //(
drawBitmapPE(cursor_x, cursor_y, PeChar[67], 8, 8, color);
cursor_x -= 7;
break;
case 41: //)
drawBitmapPE(cursor_x, cursor_y, PeChar[68], 8, 8, color);
cursor_x -= 7;
break;
case 194: //آ
drawBitmapPE(cursor_x, cursor_y, PeChar[0], 8, 8, color);
cursor_x -= 7;
break;
case 199: //ا
if(stat == 0 || stat == 1)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[1], 8, 8, color);
cursor_x -= 3;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[2], 8, 8, color);
cursor_x -= 2;
}
break;
case 200: //ب
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[3], 8, 8, color);
cursor_x -= 3;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[4], 8, 8, color);
cursor_x -= 8;
}
break;
case 222: //پ
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[5], 8, 8, color);
cursor_x -= 3;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[6], 8, 8, color);
cursor_x -= 8;
}
break;
case 202: //ت
if(stat == 1 || stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[7], 8, 8, color);
cursor_x -= 3;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[8], 8, 8, color);
cursor_x -= 8;
}
break;
case 203: //ث
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[9], 8, 8, color);
cursor_x -= 3;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[10], 8, 8, color);
cursor_x -= 8;
}
break;
case 204: //ج
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[11], 8, 8, color);
cursor_x -= 6;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[12], 8, 8, color);
cursor_x -= 8;
}
break;
case 141: //چ
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[13], 8, 8, color);
cursor_x -= 6;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[14], 8, 8, color);
cursor_x -= 8;
}
break;
case 205: //ح
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[15], 8, 8, color);
cursor_x -= 6;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[16], 8, 8, color);
cursor_x -= 8;
}
break;
case 206: //خ
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[17], 8, 8, color);
cursor_x -= 6;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[18], 8, 8, color);
cursor_x -= 8;
}
break;
case 207: //د
drawBitmapPE(cursor_x, cursor_y, PeChar[19], 8, 8, color);
cursor_x -= 6;
break;
case 208: //ذ
drawBitmapPE(cursor_x, cursor_y, PeChar[20], 8, 8, color);
cursor_x -= 6;
break;
case 209: //ر
drawBitmapPE(cursor_x, cursor_y, PeChar[21], 8, 8, color);
cursor_x -= 5;
break;
case 210: //ز
drawBitmapPE(cursor_x, cursor_y, PeChar[22], 8, 8, color);
cursor_x -= 5;
break;
case 184: //ژ
drawBitmapPE(cursor_x, cursor_y, PeChar[23], 8, 8, color);
cursor_x -= 5;
break;
case 211: //س
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[24], 8, 8, color);
cursor_x -= 7;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[25], 8, 8, color);
cursor_x -= 8;
}
break;
case 212: //ش
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[26], 8, 8, color);
cursor_x -= 7;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[27], 8, 8, color);
cursor_x -= 8;
}
break;
case 213: //ص
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[28], 8, 8, color);
cursor_x -= 7;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[29], 8, 8, color);
cursor_x -= 8;
}
break;
case 214: //ض
if(stat == 1 || stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[30], 8, 8, color);
cursor_x -= 7;
}
else if(stat == 0 || stat == 2){
drawBitmapPE(cursor_x, cursor_y, PeChar[31], 8, 8, color);
cursor_x -= 8;
}
break;
case 215: //ط
drawBitmapPE(cursor_x, cursor_y, PeChar[32], 8, 8, color);
cursor_x -= 7;
break;
case 216: //ظ
drawBitmapPE(cursor_x, cursor_y, PeChar[33], 8, 8, color);
cursor_x -= 7;
break;
case 217: //ع
if(stat == 0)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[37], 8, 8, color);
cursor_x -= 5;
}
else if(stat == 1)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[34], 8, 8, color);
cursor_x -= 4;
}
else if(stat == 2)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[36], 8, 8, color);
cursor_x -= 6;
}
else if(stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[35], 8, 8, color);
cursor_x -= 7;
}
break;
case 218: //غ
if(stat == 0){
drawBitmapPE(cursor_x, cursor_y, PeChar[41], 8, 8, color);
cursor_x -= 5;
}
else if(stat == 1)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[38], 8, 8, color);
cursor_x -= 4;
}
else if(stat == 2)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[40], 8, 8, color);
cursor_x -= 6;
}
else if(stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[39], 8, 8, color);
cursor_x -= 7;
}
break;
case 161: //ف
if(stat == 1 || stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[42], 8, 8, color);
cursor_x -= 5;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[43], 8, 8, color);
cursor_x -= 8;
}
break;
case 162: //ق
if(stat == 1 || stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[44], 8, 8, color);
cursor_x -= 5;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[45], 8, 8, color);
cursor_x -= 8;
}
break;
case 201: //ک
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[46], 8, 8, color);
cursor_x -= 6;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[47], 8, 8, color);
cursor_x -= 8;
}
break;
case 144: //گ
if(stat == 1 || stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[48], 8, 8, color);
cursor_x -= 6;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[49], 8, 8, color);
cursor_x -= 8;
}
break;
case 164: //ل
if(stat == 1 || stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[50], 8, 8, color);
cursor_x -= 2;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[51], 8, 8, color);
cursor_x -= 8;
}
break;
case 165: //م
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[52], 8, 8, color);
cursor_x -= 6;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[53], 8, 8, color);
cursor_x -= 8;
}
break;
case 228: //ن
if(stat == 1 || stat == 3){
drawBitmapPE(cursor_x, cursor_y, PeChar[54], 8, 8, color);
cursor_x -= 3;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[55], 8, 8, color);
cursor_x -= 9;
}
break;
case 168: //و
drawBitmapPE(cursor_x, cursor_y, PeChar[56], 8, 8, color);
cursor_x -= 5;
break;
case 167: //ه
if(stat == 0)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[60], 8, 8, color);
cursor_x -= 6;
}
else if(stat == 1)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[57], 8, 8, color);
cursor_x -= 6;
}
else if(stat == 2)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[59], 8, 8, color);
cursor_x -= 5;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[58], 8, 8, color);
cursor_x -= 8;
}
break;
case 172: //ی
if(stat == 1 || stat == 3)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[61], 8, 8, color);
cursor_x -= 3;
}
else if(stat == 2)
{
drawBitmapPE(cursor_x, cursor_y, PeChar[62], 8, 8, color);
cursor_x -= 8;
}
else
{
drawBitmapPE(cursor_x, cursor_y, PeChar[63], 8, 8, color);
cursor_x -= 8;
}
break;
default:
isunk = 1;
break;
}
if(isunk == 0)
{
qloghat = loghat;
}
if(cursor_x < 0){
cursor_x = LCDWidth - 8;
cursor_y += 8 + dis;
}
}
}
int CalcTextWidth (char *Text){
int dis = 1;
int cursor_x = -8;
int cursor_y = 0;
int stat = 0;
unsigned char qloghat = ' '; //Previous word
unsigned char loghat;
unsigned char bloghat; //Next word
unsigned char le;
int d;
while(le = *Text++){
//is Number ?
if (le >= '0' && le <= '9') {
d = le - '0';
loghat = le;
}
else if(le >= 128){
loghat = *Text++;
loghat += 32;
le += 32;
if(loghat == 207){
if(le == 218 || le == 250){
loghat = 144; //گ
}
}
else if(loghat == 166)
{
if(le == 218 || le == 250){ //چ
loghat = 141;
}
else
{
loghat = 228; //ن
}
}
}
else
{
loghat = le;
}
if(loghat==172)
{
if(le==248 || le==32)
{
loghat=44;
}
}
le = *Text++;
if(le >= 128)
{
bloghat = *Text++;
bloghat += 32;
le += 32;
if(bloghat == 207)
{
if(le == 218 || le == 250)
{
bloghat = 144; //گ
}
}
else if(bloghat == 166)
{
if(le == 218 || le == 250)
{ //چ
bloghat = 141;
}
else
{
bloghat = 228; //ن
}
}
*Text--;
*Text--;
}
else
{
bloghat = le;
*Text--;
}
if(bloghat==172)
{
if(le==248 || le==32)
{
bloghat=44;
}
}
int isunk = 0;
if (isFromTheSet1(qloghat))
if (isFromTheSet2(bloghat))
stat = 0; //Isolated
else
stat = 1; //Initial
else
if (isFromTheSet2(bloghat))
stat = 2; //Final
else
stat = 3; //Medial
switch(loghat){
case 48: //zero
cursor_x -= 7;
break;
case 49: //1
cursor_x -= 5;
break;
case 50: //2
cursor_x -= 7;
break;
case 51: //3
cursor_x -= 8;
break;
case 52: //4
cursor_x -= 8;
break;
case 53: //5
cursor_x -= 8;
break;
case 54: //6
cursor_x -= 8;
break;
case 55: //7
cursor_x -= 7;
break;
case 56: //8
cursor_x -= 7;
break;
case 57: //9
cursor_x -= 6;
break;
case 32: //فاصله
cursor_x -= 2;
break;
case 191: //؟
cursor_x -= 6;
break;
case 47: // /
cursor_x -= 8;
break;
case 33: //!
cursor_x -= 3;
break;
case 46: //.
cursor_x -= 4;
break;
case 58: //:
cursor_x -= 3;
break;
case ',': //،
cursor_x -= 5;
break;
case 40: //(
cursor_x -= 7;
break;
case 41: //)
cursor_x -= 7;
break;
case 194: //آ
cursor_x -= 7;
break;
case 199: //ا
if(stat == 0 || stat == 1)
{
cursor_x -= 3;
}
else
{
cursor_x -= 2;
}
break;
case 200: //ب
if(stat == 1 || stat == 3){
cursor_x -= 3;
}
else
{
cursor_x -= 8;
}
break;
case 222: //پ
if(stat == 1 || stat == 3){
cursor_x -= 3;
}
else
{
cursor_x -= 8;
}
break;
case 202: //ت
if(stat == 1 || stat == 3)
{
cursor_x -= 3;
}
else
{
cursor_x -= 8;
}
break;
case 203: //ث
if(stat == 1 || stat == 3){
cursor_x -= 3;
}
else
{
cursor_x -= 8;
}
break;
case 204: //ج
if(stat == 1 || stat == 3){
cursor_x -= 6;
}
else
{
cursor_x -= 8;
}
break;
case 141: //چ
if(stat == 1 || stat == 3){
cursor_x -= 6;
}
else
{
cursor_x -= 8;
}
break;
case 205: //ح
if(stat == 1 || stat == 3){
cursor_x -= 6;
}
else
{
cursor_x -= 8;
}
break;
case 206: //خ
if(stat == 1 || stat == 3){
cursor_x -= 6;
}
else
{
cursor_x -= 8;
}
break;
case 207: //د
cursor_x -= 6;
break;
case 208: //ذ
cursor_x -= 6;
break;
case 209: //ر
cursor_x -= 5;
break;