Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LEDMatrix_Master by
8x8fontsLib.cpp
00001 #include "mbed.h" 00002 #include "displayCom.h" 00003 #include "kfont8.h" 00004 #include "8x8fontsLib.h" 00005 #include "unicode2SJIS.h" 00006 00007 00008 00009 00010 extern unsigned short unicode2SJIS(char c); 00011 00012 00013 int offsety = 0; 00014 bool kstate = false; 00015 unsigned char kbuf; 00016 00017 const unsigned char *findface(unsigned short c){ 00018 const unsigned char *p = NULL; 00019 int i, sum; 00020 for(sum = i = 0; i < countof(font8table); i++){ 00021 if(font8table[i].start <= c && c <= font8table[i].end){ 00022 p = &font8[(sum + c - font8table[i].start) << 3]; 00023 break; 00024 } 00025 sum += font8table[i].end - font8table[i].start + 1; 00026 } 00027 return p; 00028 } 00029 00030 // draw 8x8 font 00031 // charWidth 1~8 00032 00033 void drawkanji(unsigned short c,unsigned char color, signed short posX, unsigned char posY,unsigned char charWidth){ 00034 unsigned char i = 0; 00035 const unsigned char *p = findface(c); 00036 if(p == NULL) return; 00037 00038 if(color == COLOR_G || color == COLOR_C || color == COLOR_Y || color == COLOR_W) 00039 { 00040 for(i=0;i<charWidth;i++) 00041 { 00042 if( (posX+(7-i)) >= 0) 00043 { 00044 ImageBuf[0][ posX+(7-i) ] = p[i]<<posY; 00045 } 00046 } 00047 } 00048 if(color == COLOR_R || color == COLOR_Y || color == COLOR_M || color == COLOR_W) 00049 { 00050 for(i=0;i<charWidth;i++) 00051 { 00052 if( (posX+(7-i)) >= 0) 00053 { 00054 ImageBuf[1][ posX+(7-i) ] = p[i]<<posY; 00055 } 00056 } 00057 } 00058 if(color == COLOR_B || color == COLOR_C || color == COLOR_M || color == COLOR_W) 00059 { 00060 for(i=0;i<charWidth;i++) 00061 { 00062 if( (posX+(7-i)) >= 0) 00063 { 00064 00065 ImageBuf[2][ posX+(7-i) ] = p[i]<<posY; 00066 } 00067 } 00068 } 00069 } 00070 00071 void drawc(unsigned char c, unsigned char color, signed short posX, unsigned char posY, unsigned char charWidth){ 00072 if(kstate) 00073 { // 2nd byte of shift-jis 00074 kstate = false; 00075 drawkanji( (kbuf << 8 | c),color,posX,posY,charWidth); 00076 } 00077 else if((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)){ // 1st byte of shift-jis 00078 kstate = true; 00079 kbuf = c; 00080 } 00081 else 00082 { 00083 drawkanji( unicode2SJIS_Table[c],color,posX,posY,charWidth); 00084 } 00085 } 00086 00087 void drawStr8x8(char *str, unsigned char color, signed short posX, unsigned char posY){ 00088 unsigned char c = 0; 00089 unsigned char f_2byteChar = 0; 00090 unsigned char countChar = 0; 00091 signed short tmp_posX = 0; 00092 00093 c = *str; 00094 while( (c != '\0') && (posX>=(countChar*8)) ) 00095 { 00096 drawc(c,color,(posX-(countChar*8)),posY,8); 00097 if( ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)) && f_2byteChar != 1 ) 00098 { // 1st byte of shift-jis 00099 f_2byteChar = 1; 00100 } 00101 else if(f_2byteChar == 1) 00102 { 00103 f_2byteChar = 0; 00104 countChar++; 00105 } 00106 else 00107 { 00108 f_2byteChar = 0; 00109 countChar++; 00110 } 00111 str++; 00112 c = *str; 00113 } 00114 if( ((posX%8) != 0) && (c != '\0') ) 00115 { 00116 tmp_posX = posX%8; 00117 tmp_posX = tmp_posX-8; 00118 do{ 00119 drawc(c,color,tmp_posX,posY,8); 00120 if( ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)) && (f_2byteChar != 1)){ 00121 f_2byteChar = 1; 00122 str++; 00123 c = *str; 00124 } 00125 else if(f_2byteChar == 1) 00126 { 00127 f_2byteChar = 0; 00128 countChar++; 00129 } 00130 else 00131 { 00132 f_2byteChar = 0; 00133 countChar++; 00134 } 00135 }while( (f_2byteChar == 1) ); 00136 } 00137 }
Generated on Tue Jul 12 2022 16:59:14 by
1.7.2
