mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-13 10:48:49 +01:00
cjk with printer_set_font
This commit is contained in:
parent
ffa3fa0aa9
commit
ab06c8f192
@ -1,9 +1,10 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
#include <freetype/freetype.h>
|
// clang-format off
|
||||||
#include <freetype2/ft2build.h>
|
#include <freetype2/ft2build.h>
|
||||||
|
#include <freetype/freetype.h>
|
||||||
|
// clang-format on
|
||||||
/// raspberry pi CM3
|
/// raspberry pi CM3
|
||||||
|
|
||||||
#define BCM_GPIO_28 28
|
#define BCM_GPIO_28 28
|
||||||
|
|||||||
@ -89,6 +89,9 @@ void init_printer() {
|
|||||||
img_cache.need_print = 0;
|
img_cache.need_print = 0;
|
||||||
img_cache.revert_bits = 0;
|
img_cache.revert_bits = 0;
|
||||||
|
|
||||||
|
ser_cache.idx = 0;
|
||||||
|
ser_cache.utf8idx = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
current_font.width=5; current_font.height=7; current_font.data =
|
current_font.width=5; current_font.height=7; current_font.data =
|
||||||
font_pcf_5x7_ISO8859_1_5x7; current_font.width=6;current_font.height=12;
|
font_pcf_5x7_ISO8859_1_5x7; current_font.width=6;current_font.height=12;
|
||||||
@ -103,15 +106,15 @@ void init_printer() {
|
|||||||
current_font.width=8;current_font.height=16; current_font.data=
|
current_font.width=8;current_font.height=16; current_font.data=
|
||||||
font_ttf_Px437_PS2thin2_8x16;
|
font_ttf_Px437_PS2thin2_8x16;
|
||||||
*/
|
*/
|
||||||
current_font.width = 16;
|
// auto detect TTF ,switch to FONT_MODE_1
|
||||||
current_font.height = 16;
|
if (getenv("TTF") && access(getenv("TTF"), F_OK) != -1) {
|
||||||
current_font.data = font_ttf_Px437_PS2thin1_8x16;
|
printf("TTF=%s\n", getenv("TTF"));
|
||||||
current_font.file = "NotoSansCJK-Regular.ttf";
|
current_font.width = 12;
|
||||||
|
current_font.height = 12;
|
||||||
|
current_font.data = NULL;
|
||||||
|
current_font.file = getenv("TTF");
|
||||||
current_font.mode = FONT_MODE_1;
|
current_font.mode = FONT_MODE_1;
|
||||||
|
|
||||||
ser_cache.idx = 0;
|
|
||||||
ser_cache.utf8idx = 0;
|
|
||||||
|
|
||||||
if (init_ft(current_font.file, &face, &ft, current_font.width,
|
if (init_ft(current_font.file, &face, &ft, current_font.width,
|
||||||
current_font.height, &error)) {
|
current_font.height, &error)) {
|
||||||
g_config.face = face;
|
g_config.face = face;
|
||||||
@ -121,6 +124,12 @@ void init_printer() {
|
|||||||
g_config.face = NULL;
|
g_config.face = NULL;
|
||||||
g_config.ft = NULL;
|
g_config.ft = NULL;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
current_font.mode = FONT_MODE_0;
|
||||||
|
current_font.width = 8;
|
||||||
|
current_font.height = 16;
|
||||||
|
current_font.data = font_ttf_Px437_PS2thin2_8x16;
|
||||||
|
}
|
||||||
|
|
||||||
g_config.line_space = 0;
|
g_config.line_space = 0;
|
||||||
g_config.align = ALIGN_LEFT;
|
g_config.align = ALIGN_LEFT;
|
||||||
@ -404,7 +413,7 @@ void printer_set_font(CONFIG *cfg, uint8_t fnbits) {
|
|||||||
uint8_t ret;
|
uint8_t ret;
|
||||||
ret = MID(fnbits, 0, 3);
|
ret = MID(fnbits, 0, 3);
|
||||||
|
|
||||||
if (cfg->font->mode == 0) {
|
if (cfg->font->mode == FONT_MODE_0) {
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
cfg->font->width = 8;
|
cfg->font->width = 8;
|
||||||
cfg->font->height = 16;
|
cfg->font->height = 16;
|
||||||
@ -436,10 +445,30 @@ void printer_set_font(CONFIG *cfg, uint8_t fnbits) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg->font->mode == 1) {
|
if (cfg->font->mode == FONT_MODE_1) {
|
||||||
|
if (ret == 0) {
|
||||||
|
cfg->font->width = 12;
|
||||||
|
cfg->font->height = 12;
|
||||||
|
}
|
||||||
|
if (ret == 1) {
|
||||||
|
cfg->font->width = 14;
|
||||||
|
cfg->font->height = 14;
|
||||||
|
}
|
||||||
|
if (ret == 2) {
|
||||||
cfg->font->width = 16;
|
cfg->font->width = 16;
|
||||||
cfg->font->height = 16;
|
cfg->font->height = 16;
|
||||||
}
|
}
|
||||||
|
if (ret == 3) {
|
||||||
|
cfg->font->width = 18;
|
||||||
|
cfg->font->height = 18;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == 4) {
|
||||||
|
cfg->font->width = 20;
|
||||||
|
cfg->font->height = 20;
|
||||||
|
}
|
||||||
|
change_ft_size(cfg->face, cfg->font->width, cfg->font->height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_cmd(CONFIG *cfg, uint8_t *cmd, uint8_t cmdidx) {
|
void parse_cmd(CONFIG *cfg, uint8_t *cmd, uint8_t cmdidx) {
|
||||||
|
|||||||
@ -31,6 +31,16 @@ bool init_ft(const char *ttf_file, FT_Face *face, FT_Library *ft,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool change_ft_size(FT_Face face, int req_size_w, int req_size_h) {
|
||||||
|
bool ret = false;
|
||||||
|
if (FT_Set_Pixel_Sizes(face, req_size_w, req_size_h) == 0) {
|
||||||
|
ret = true;
|
||||||
|
} else {
|
||||||
|
printf("Can't set font size");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
/*===========================================================================
|
/*===========================================================================
|
||||||
done_ft
|
done_ft
|
||||||
Clean up after we've finished wih the FreeType librar
|
Clean up after we've finished wih the FreeType librar
|
||||||
|
|||||||
@ -20,6 +20,8 @@ typedef int32_t UTF32;
|
|||||||
bool init_ft(const char *ttf_file, FT_Face *face, FT_Library *ft,
|
bool init_ft(const char *ttf_file, FT_Face *face, FT_Library *ft,
|
||||||
int req_size_w, int req_size_h, char **error);
|
int req_size_w, int req_size_h, char **error);
|
||||||
|
|
||||||
|
bool change_ft_size(FT_Face face, int req_size_w, int req_size_h);
|
||||||
|
|
||||||
int face_get_line_spacing(FT_Face face);
|
int face_get_line_spacing(FT_Face face);
|
||||||
|
|
||||||
int get_slice_len(const char lb);
|
int get_slice_len(const char lb);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user