NotePublic/Ecology/01Studio/pyBoard/Demo/01Studio中文显示例程/tftch.py

59 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 定义常用颜色
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
def printCh(display, text, x, y, dic={}, size=1, color=(0,0,0), backcolor=(255,255,255)):
font_size = [0, 16, 24, 32, 40, 48] # 分别对应 size=1, 2, 3, 4, 5 的字体尺寸0 无效。
xs = x
# 定义字体颜色,RGB888转RGB565
fc = ((color[0]>>3)<<11) + ((color[1]>>2)<<5) + (color[2]>>3) # 字体
bc = ((backcolor[0]>>3)<<11) + ((backcolor[1]>>2)<<5) + (backcolor[2]>>3) # 字体背景颜色
#
for i in range(0, len(text)):
#
if text[i] in dic:
ch_buf =dic[text[i]] # 汉子对应码表
rgb_buf = []
#
for i in range(0, len(ch_buf)):
for j in range(0, 8):
if (ch_buf[i] << j) & 0x80 == 0x00:
rgb_buf.append(bc & 0xff)
rgb_buf.append(bc >> 8)
else:
rgb_buf.append(fc & 0xff)
rgb_buf.append(fc >> 8)
# if
# for
# for
display.write_buf(bytearray(rgb_buf), xs, y, font_size[size], font_size[size])
#
xs += font_size[size]
else:
display.printStr(text[i], xs, y, color, size=size)
xs += int(font_size[size]/2)
# if
# for
# printChinese
if __name__ == '__main__':
import fonts
from tftlcd import LCD24
########################
# 构建1.5寸LCD对象并初始化
########################
d = LCD24(portrait=1) #默认方向竖屏
#
#填充白色
d.fill(BLACK)
#
printCh(d, '零一科技01Tech', 0, 0, dic=fonts.hanzi_16x16_dict, size=1, color=RED, backcolor=BLACK)
printCh(d, '零一科技01Tech', 0, 16, dic=fonts.hanzi_24x24_dict, size=2, color=GREEN, backcolor=BLACK)
printCh(d, '零一科技01Tech', 0, 40, dic=fonts.hanzi_32x32_dict, size=3, color=BLUE, backcolor=BLACK)
printCh(d, '零一科技01Tech', 0, 72, dic=fonts.hanzi_40x40_dict, size=4, color=WHITE, backcolor=BLACK)
printCh(d, '零一科技01Tech', 0, 120, dic=fonts.hanzi_48x48_dict, size=5, color=WHITE, backcolor=BLACK)
# __main__