1 | /*
|
---|
2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
3 | *
|
---|
4 | * Copyright (C) 2018 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
11 | * スコード中に含まれていること.
|
---|
12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
15 | * の無保証規定を掲載すること.
|
---|
16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
18 | * と.
|
---|
19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
22 | * 報告すること.
|
---|
23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
27 | * 免責すること.
|
---|
28 | *
|
---|
29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
33 | * の責任を負わない.
|
---|
34 | *
|
---|
35 | * @(#) $Id$
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <kernel.h>
|
---|
39 | #include <t_syslog.h>
|
---|
40 | #include <t_stdlib.h>
|
---|
41 | #include <string.h>
|
---|
42 | #include <target_syssvc.h>
|
---|
43 | #ifndef ADAFRUIT_SSD1306
|
---|
44 | #include "adafruit_st7735.h"
|
---|
45 | #else
|
---|
46 | #include "adafruit_ssd1306.h"
|
---|
47 | #endif
|
---|
48 | #include "draw_font.h"
|
---|
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;
|
---|
55 |
|
---|
56 | *use_chars = 0;
|
---|
57 | len = 0;
|
---|
58 | if ((string[0] & 0x80) == 0) { len = 1; }
|
---|
59 | else if ((string[0] & 0xE0) == 0xC0) { len = 2; }
|
---|
60 | else if ((string[0] & 0xF0) == 0xE0) { len = 3; }
|
---|
61 | else if ((string[0] & 0xF8) == 0xF0) { len = 4; }
|
---|
62 | else { return; }
|
---|
63 |
|
---|
64 | j = k = totalj = totalk = 0;
|
---|
65 |
|
---|
66 | if (len == 1) {
|
---|
67 | code = string[0];
|
---|
68 | memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
69 | *use_chars = 1;
|
---|
70 | return;
|
---|
71 | }
|
---|
72 |
|
---|
73 | if (len == 2) {
|
---|
74 | code = string[0];
|
---|
75 | // 1バイト目サーチ
|
---|
76 | for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) {
|
---|
77 | if (Utf8CodeTable_2B_1st[i][0] == code) {
|
---|
78 | code = string[1];
|
---|
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);
|
---|
82 | *use_chars = 2;
|
---|
83 | return;
|
---|
84 | }
|
---|
85 | totalk++;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | else {
|
---|
89 | totalk += Utf8CodeTable_2B_1st[i][1];
|
---|
90 | }
|
---|
91 | }
|
---|
92 | return;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (len == 3) {
|
---|
96 | code = string[0];
|
---|
97 | // 1バイト目サーチ
|
---|
98 | for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) {
|
---|
99 | if (Utf8CodeTable_3B_1st[i][0] == code) {
|
---|
100 | code = string[1];
|
---|
101 | // 2バイト目サーチ
|
---|
102 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
103 | if (Utf8CodeTable_3B_2nd[totalj][0] == code) {
|
---|
104 | code = string[2];
|
---|
105 | // 3バイト目サーチ
|
---|
106 | for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
|
---|
107 | if (UTF8_3B_CODE_BITMAP[totalk].code == code) {
|
---|
108 | memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
109 | *use_chars = 3;
|
---|
110 | return;
|
---|
111 | }
|
---|
112 | totalk++;
|
---|
113 | }
|
---|
114 | return;
|
---|
115 | }
|
---|
116 | else {/*読み飛ばすbitmap個数を蓄積*/
|
---|
117 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
118 | }
|
---|
119 | totalj++;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | else {/*読み飛ばすbitmap個数を蓄積*/
|
---|
123 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
124 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
125 | totalj++;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | return;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
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);
|
---|
143 | }
|
---|
144 | else {
|
---|
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);
|
---|
166 | }
|
---|
167 | else {
|
---|
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;
|
---|
185 |
|
---|
186 | local_x = x;
|
---|
187 | local_y = y;
|
---|
188 |
|
---|
189 | current_top = 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)
|
---|
195 | return;
|
---|
196 |
|
---|
197 | //3バイトコード半角文字用
|
---|
198 | if (use_chars == 3) {
|
---|
199 | for_3B_hankaku_code = 0;
|
---|
200 | for_3B_hankaku_code = ((code[current_top] << 16) |
|
---|
201 | (code[current_top + 1] << 8) |
|
---|
202 | (code[current_top + 2]));
|
---|
203 | }
|
---|
204 |
|
---|
205 | current_top += use_chars;
|
---|
206 |
|
---|
207 | //1バイトコード半角文字
|
---|
208 | if (use_chars == 1) {
|
---|
209 | if (ctrl_code == 0x0D) { // CR
|
---|
210 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
211 | continue;
|
---|
212 | }
|
---|
213 | if (ctrl_code == 0x0A) { // LF
|
---|
214 | local_y = local_y + FONT_HEIGHT;
|
---|
215 | continue;
|
---|
216 | }
|
---|
217 |
|
---|
218 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
219 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
220 | local_y = local_y + FONT_HEIGHT;
|
---|
221 | }
|
---|
222 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
223 | local_x += FONT_HALF_WIDTH;
|
---|
224 | continue;
|
---|
225 | }
|
---|
226 |
|
---|
227 | //3バイトコード半角文字
|
---|
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))) {
|
---|
231 | //3バイトコード半角文字
|
---|
232 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
233 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
234 | local_y = local_y + FONT_HEIGHT;
|
---|
235 | }
|
---|
236 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
237 | local_x += FONT_HALF_WIDTH;
|
---|
238 | continue;
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 | //全角文字
|
---|
243 | if (local_x + FONT_WIDTH > hlcd->_width) {
|
---|
244 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
245 | local_y = local_y + FONT_HEIGHT;
|
---|
246 | }
|
---|
247 | lcd_drawFont(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
248 | local_x += FONT_WIDTH;
|
---|
249 | }
|
---|
250 | }
|
---|
251 |
|
---|