Ignore:
Timestamp:
Feb 1, 2019, 9:57:09 PM (5 years ago)
Author:
coas-nagasima
Message:

TINETとSocket APIなどを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.c

    r352 r364  
    11/*
    22 *  TOPPERS ECHONET Lite Communication Middleware
    3  * 
     3 *
    44 *  Copyright (C) 2018 Cores Co., Ltd. Japan
    5  * 
     5 *
    66 *  上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
    77 *  ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
     
    2626 *      由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
    2727 *      免責すること.
    28  * 
     28 *
    2929 *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
    3030 *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
     
    3232 *  アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
    3333 *  の責任を負わない.
    34  * 
     34 *
    3535 *  @(#) $Id$
    3636 */
     
    4141#include <string.h>
    4242#include <target_syssvc.h>
     43#ifndef ADAFRUIT_SSD1306
    4344#include "adafruit_st7735.h"
     45#else
     46#include "adafruit_ssd1306.h"
     47#endif
    4448#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
     50void 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;
    5255
    5356        *use_chars = 0;
    5457        len = 0;
    55         if      ((string[0] & 0x80) ==    0) { len = 1; }
     58        if ((string[0] & 0x80) == 0) { len = 1; }
    5659        else if ((string[0] & 0xE0) == 0xC0) { len = 2; }
    5760        else if ((string[0] & 0xF0) == 0xE0) { len = 3; }
    5861        else if ((string[0] & 0xF8) == 0xF0) { len = 4; }
    59         else { return;  }
     62        else { return; }
    6063
    6164        j = k = totalj = totalk = 0;
    6265
    63         if( len == 1 ) {
     66        if (len == 1) {
    6467                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);
    6669                *use_chars = 1;
    6770                return;
    6871        }
    6972
    70         if( len == 2 ) {
     73        if (len == 2) {
    7174                code = string[0];
    7275                // 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) {
    7578                                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);
    7982                                                *use_chars = 2;
    8083                                                return;
     
    9093        }
    9194
    92         if( len == 3 ) {
     95        if (len == 3) {
    9396                code = string[0];
    9497                // 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) {
    97100                                code = string[1];
    98101                                // 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) {
    101104                                                code = string[2];
    102105                                                // 3バイト目サーチ
    103                                                 for( k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
     106                                                for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
    104107                                                        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);
    106109                                                                *use_chars = 3;
    107110                                                                return;
     
    111114                                                return;
    112115                                        }
    113                                         else{/*読み飛ばすbitmap個数を蓄積*/
     116                                        else {/*読み飛ばすbitmap個数を蓄積*/
    114117                                                totalk += Utf8CodeTable_3B_2nd[totalj][1];
    115118                                        }
     
    118121                        }
    119122                        else {/*読み飛ばすbitmap個数を蓄積*/
    120                                 for( j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++ ) {
     123                                for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
    121124                                        totalk += Utf8CodeTable_3B_2nd[totalj][1];
    122125                                        totalj++;
     
    128131}
    129132
    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);
     133void 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);
    138143                        }
    139144                        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
     156void 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);
    154166                        }
    155167                        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
     179void 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;
    167185
    168186        local_x = x;
     
    170188
    171189        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)
    178195                        return;
    179196
    180197                //3バイトコード半角文字用
    181                 if(use_chars == 3) {
     198                if (use_chars == 3) {
    182199                        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]));
    186203                }
    187204
     
    189206
    190207                //1バイトコード半角文字
    191                 if ( use_chars == 1 ) {
    192                         if(ctrl_code == 0x0D) { // CR
     208                if (use_chars == 1) {
     209                        if (ctrl_code == 0x0D) { // CR
    193210                                local_x = X_LINE_TO_PIX(hlcd, 0);
    194211                                continue;
    195212                        }
    196                         if(ctrl_code == 0x0A) { // LF
    197                                 local_y = local_y + 8;
     213                        if (ctrl_code == 0x0A) { // LF
     214                                local_y = local_y + FONT_HEIGHT;
    198215                                continue;
    199216                        }
    200217
    201                         if ( local_x >= hlcd->_width + 4 ) {
     218                        if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
    202219                                local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
    203                                 local_y = local_y + 8;
     220                                local_y = local_y + FONT_HEIGHT;
    204221                        }
    205222                        lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
    206                         local_x += 4;
     223                        local_x += FONT_HALF_WIDTH;
    207224                        continue;
    208225                }
    209226
    210227                //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))) {
    214231                                //3バイトコード半角文字
    215                                 if ( local_x >= hlcd->_width + 4 ) {
     232                                if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
    216233                                        local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
    217                                         local_y = local_y + 8;
     234                                        local_y = local_y + FONT_HEIGHT;
    218235                                }
    219236                                lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
    220                                 local_x += 4;
     237                                local_x += FONT_HALF_WIDTH;
    221238                                continue;
    222239                        }
     
    224241
    225242                //全角文字
    226                 if ( local_x >= hlcd->_width + 8 ) {
     243                if (local_x + FONT_WIDTH > hlcd->_width) {
    227244                        local_x = X_LINE_TO_PIX(hlcd, 0);
    228                         local_y = local_y + 8;
     245                        local_y = local_y + FONT_HEIGHT;
    229246                }
    230247                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.