Changeset 364 for asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.c
- Timestamp:
- Feb 1, 2019, 9:57:09 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.c
r352 r364 1 1 /* 2 2 * TOPPERS ECHONET Lite Communication Middleware 3 * 3 * 4 4 * Copyright (C) 2018 Cores Co., Ltd. Japan 5 * 5 * 6 6 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ 7 7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 … … 26 26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを 27 27 * 免責すること. 28 * 28 * 29 29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お 30 30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 … … 32 32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ 33 33 * の責任を負わない. 34 * 34 * 35 35 * @(#) $Id$ 36 36 */ … … 41 41 #include <string.h> 42 42 #include <target_syssvc.h> 43 #ifndef ADAFRUIT_SSD1306 43 44 #include "adafruit_st7735.h" 45 #else 46 #include "adafruit_ssd1306.h" 47 #endif 44 48 #include "draw_font.h" 45 #include "misaki_font.h" 46 47 void get_bitmap_font(char *string, unsigned char *bitmap_data, unsigned long *use_chars) 48 { 49 unsigned long len, code; 50 unsigned char i,j,k; 51 unsigned long totalj, totalk; 49 50 void get_bitmap_font(const uint8_t *string, uint8_t *bitmap_data, uint32_t *use_chars) 51 { 52 uint32_t len, code; 53 uint8_t i, j, k; 54 uint32_t totalj, totalk; 52 55 53 56 *use_chars = 0; 54 57 len = 0; 55 if ((string[0] & 0x80) ==0) { len = 1; }58 if ((string[0] & 0x80) == 0) { len = 1; } 56 59 else if ((string[0] & 0xE0) == 0xC0) { len = 2; } 57 60 else if ((string[0] & 0xF0) == 0xE0) { len = 3; } 58 61 else if ((string[0] & 0xF8) == 0xF0) { len = 4; } 59 else { return; 62 else { return; } 60 63 61 64 j = k = totalj = totalk = 0; 62 65 63 if ( len == 1) {66 if (len == 1) { 64 67 code = string[0]; 65 memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], 8);68 memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], FONT_WIDTH * FONT_HEIGHT / 8); 66 69 *use_chars = 1; 67 70 return; 68 71 } 69 72 70 if ( len == 2) {73 if (len == 2) { 71 74 code = string[0]; 72 75 // 1バイト目サーチ 73 for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) {74 if ( Utf8CodeTable_2B_1st[i][0] == code) {76 for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) { 77 if (Utf8CodeTable_2B_1st[i][0] == code) { 75 78 code = string[1]; 76 for ( j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++) {77 if ( UTF8_2B_CODE_BITMAP[totalk].code == code) {78 memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, 8);79 for (j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++) { 80 if (UTF8_2B_CODE_BITMAP[totalk].code == code) { 81 memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8); 79 82 *use_chars = 2; 80 83 return; … … 90 93 } 91 94 92 if ( len == 3) {95 if (len == 3) { 93 96 code = string[0]; 94 97 // 1バイト目サーチ 95 for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) {96 if ( Utf8CodeTable_3B_1st[i][0] == code) {98 for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) { 99 if (Utf8CodeTable_3B_1st[i][0] == code) { 97 100 code = string[1]; 98 101 // 2バイト目サーチ 99 for ( j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++ ){100 if ( Utf8CodeTable_3B_2nd[totalj][0] == code) {102 for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) { 103 if (Utf8CodeTable_3B_2nd[totalj][0] == code) { 101 104 code = string[2]; 102 105 // 3バイト目サーチ 103 for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {106 for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) { 104 107 if (UTF8_3B_CODE_BITMAP[totalk].code == code) { 105 memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, 8);108 memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8); 106 109 *use_chars = 3; 107 110 return; … … 111 114 return; 112 115 } 113 else {/*読み飛ばすbitmap個数を蓄積*/116 else {/*読み飛ばすbitmap個数を蓄積*/ 114 117 totalk += Utf8CodeTable_3B_2nd[totalj][1]; 115 118 } … … 118 121 } 119 122 else {/*読み飛ばすbitmap個数を蓄積*/ 120 for ( j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {123 for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) { 121 124 totalk += Utf8CodeTable_3B_2nd[totalj][1]; 122 125 totalj++; … … 128 131 } 129 132 130 void lcd_drawFont(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color) 131 { 132 int i, j; 133 134 for(i = 0; i < 8; i++ ) { 135 for(j = 0; j < 8; j++ ) { 136 if (((bitmap_data[i] >> j) & 0x01) == 1){ 137 lcd_drawPixel(hlcd, x - j, y + i, color); 133 void lcd_drawFont(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color) 134 { 135 int i, j, b; 136 uint8_t *bitmap = bitmap_data; 137 138 b = 0x80; 139 for (i = 0; i < FONT_HEIGHT; i++) { 140 for (j = 0; j < FONT_WIDTH; j++) { 141 if ((*bitmap & b) != 0) { 142 lcd_drawPixel(hlcd, x + j, y + i, color); 138 143 } 139 144 else { 140 lcd_drawPixel(hlcd, x - j, y + i, back_color); 141 } 142 } 143 } 144 } 145 146 void lcd_drawFontHalf(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color) 147 { 148 int i, j; 149 150 for(i = 0; i < 8; i++ ) { 151 for(j = 4; j < 8; j++ ) { 152 if (((bitmap_data[i] >> j) & 0x01) == 1){ 153 lcd_drawPixel(hlcd, x - j, y + i, color); 145 lcd_drawPixel(hlcd, x + j, y + i, back_color); 146 } 147 b >>= 1; 148 if (b == 0) { 149 b = 0x80; 150 bitmap++; 151 } 152 } 153 } 154 } 155 156 void lcd_drawFontHalf(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color) 157 { 158 int i, j, b; 159 uint8_t *bitmap = bitmap_data; 160 161 b = 0x80; 162 for (i = 0; i < FONT_HEIGHT; i++) { 163 for (j = 0; j < FONT_HALF_WIDTH; j++) { 164 if ((*bitmap & b) != 0) { 165 lcd_drawPixel(hlcd, x + j, y + i, color); 154 166 } 155 167 else { 156 lcd_drawPixel(hlcd, x - j, y + i, back_color); 157 } 158 } 159 } 160 } 161 162 void lcd_drawString(LCD_Handler_t *hlcd, char *string, int x, int y, unsigned short color, unsigned short back_color ) 163 { 164 unsigned long current_top, use_chars, for_3B_hankaku_code; 165 unsigned char bitmap_data[8], ctrl_code; 166 int local_x, local_y; 168 lcd_drawPixel(hlcd, x + j, y + i, back_color); 169 } 170 b >>= 1; 171 if (b == 0) { 172 b = 0x80; 173 bitmap++; 174 } 175 } 176 } 177 } 178 179 void lcd_drawString(LCD_Handler_t *hlcd, const char *string, int x, int y, uint16_t color, uint16_t back_color) 180 { 181 uint32_t current_top, use_chars, for_3B_hankaku_code; 182 uint8_t bitmap_data[FONT_WIDTH * FONT_HEIGHT / 8], ctrl_code; 183 int local_x, local_y, len = strlen(string); 184 const uint8_t *code = (const uint8_t *)string; 167 185 168 186 local_x = x; … … 170 188 171 189 current_top = 0; 172 while( current_top < strlen(string) ) 173 { 174 memset(bitmap_data,0x0,8); 175 ctrl_code = string[current_top]; 176 get_bitmap_font(&string[current_top], bitmap_data, &use_chars); 177 if(use_chars == 0) 190 while (current_top < len) { 191 memset(bitmap_data, 0x0, FONT_WIDTH * FONT_HEIGHT / 8); 192 ctrl_code = code[current_top]; 193 get_bitmap_font(&code[current_top], bitmap_data, &use_chars); 194 if (use_chars == 0) 178 195 return; 179 196 180 197 //3バイトコード半角文字用 181 if (use_chars == 3) {198 if (use_chars == 3) { 182 199 for_3B_hankaku_code = 0; 183 for_3B_hankaku_code = ( (string[current_top]<< 16) |184 (string[current_top+1] <<8) |185 (string[current_top+2] ));200 for_3B_hankaku_code = ((code[current_top] << 16) | 201 (code[current_top + 1] << 8) | 202 (code[current_top + 2])); 186 203 } 187 204 … … 189 206 190 207 //1バイトコード半角文字 191 if ( use_chars == 1) {192 if (ctrl_code == 0x0D) { // CR208 if (use_chars == 1) { 209 if (ctrl_code == 0x0D) { // CR 193 210 local_x = X_LINE_TO_PIX(hlcd, 0); 194 211 continue; 195 212 } 196 if (ctrl_code == 0x0A) { // LF197 local_y = local_y + 8;213 if (ctrl_code == 0x0A) { // LF 214 local_y = local_y + FONT_HEIGHT; 198 215 continue; 199 216 } 200 217 201 if ( local_x >= hlcd->_width + 4) {218 if (local_x + FONT_HALF_WIDTH > hlcd->_width) { 202 219 local_x = X_LINE_HALF_TO_PIX(hlcd, 0); 203 local_y = local_y + 8;220 local_y = local_y + FONT_HEIGHT; 204 221 } 205 222 lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color); 206 local_x += 4;223 local_x += FONT_HALF_WIDTH; 207 224 continue; 208 225 } 209 226 210 227 //3バイトコード半角文字 211 if ( use_chars == 3) {212 if ( ( (0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF)) ||213 ( (0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F) )) {228 if (use_chars == 3) { 229 if (((0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF)) || 230 ((0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F))) { 214 231 //3バイトコード半角文字 215 if ( local_x >= hlcd->_width + 4) {232 if (local_x + FONT_HALF_WIDTH > hlcd->_width) { 216 233 local_x = X_LINE_HALF_TO_PIX(hlcd, 0); 217 local_y = local_y + 8;234 local_y = local_y + FONT_HEIGHT; 218 235 } 219 236 lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color); 220 local_x += 4;237 local_x += FONT_HALF_WIDTH; 221 238 continue; 222 239 } … … 224 241 225 242 //全角文字 226 if ( local_x >= hlcd->_width + 8) {243 if (local_x + FONT_WIDTH > hlcd->_width) { 227 244 local_x = X_LINE_TO_PIX(hlcd, 0); 228 local_y = local_y + 8;245 local_y = local_y + FONT_HEIGHT; 229 246 } 230 247 lcd_drawFont(hlcd, bitmap_data, local_x, local_y, color, back_color); 231 local_x += 8;232 } 233 } 234 248 local_x += FONT_WIDTH; 249 } 250 } 251
Note:
See TracChangeset
for help on using the changeset viewer.