Просмотр исходного кода

add get_serial_cache_font_width to calc the whole line ser_cache width

cuu 2 лет назад
Родитель
Сommit
3237703ec3

+ 9 - 1
Code/thermal_printer/devterm_thermal_printer.c

@@ -711,7 +711,15 @@ void parse_serial_stream(CONFIG*cfg,uint8_t input_ch){
           }
           //read utf8 codename
           //
-          a = (ser_cache.idx+1)*current_font.width+(ser_cache.idx)*0+ g_config.margin.width;          
+          if(cfg->font->mode == FONT_MODE_1) {
+              
+              a = get_serial_cache_font_width(&g_config);
+              a+= (ser_cache.idx)*0+ g_config.margin.width;
+
+          }else {
+              a = (ser_cache.idx+1)*current_font.width+(ser_cache.idx)*0+ g_config.margin.width;
+
+          }
           if( a >= MAX_DOTS)//got enough points to print
           {
             if(cfg->font->mode == FONT_MODE_1){

+ 18 - 1
Code/thermal_printer/printer.c

@@ -422,6 +422,24 @@ int glob_file(char*av) {
 }
 
 #endif
+uint16_t get_serial_cache_font_width(CONFIG*cfg) {
+	
+  int i;
+  uint8_t *ch;
+  uint32_t codename;
+  int w;
+  w = 0;
+  i = 0;
+  while( i <ser_cache.idx) {
+      ch = (uint8_t*)&ser_cache.data[i];
+      codename = utf8_to_utf32(ch);
+      FT_UInt gi = FT_Get_Char_Index ( cfg->face, codename);
+      FT_Load_Glyph ( cfg->face, gi, FT_LOAD_NO_BITMAP);
+      w +=  cfg->face->glyph->metrics.horiAdvance / 64;
+      i++;
+  }
+  return w+cfg->font->width;
+}
 
 //print with freetype font dots glyph
 uint8_t print_lines_ft(CONFIG*cfg) {
@@ -550,7 +568,6 @@ uint8_t print_lines_ft(CONFIG*cfg) {
           
           break;
         }
-        
       }
       rv = IsPaper();
       if( rv == IS_PAPER) {

+ 1 - 1
Code/thermal_printer/printer.h

@@ -29,7 +29,7 @@ void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_
 uint16_t read_adc(char*);
 uint16_t temperature();
 int glob_file(char*);
-
+uint16_t get_serial_cache_font_width(CONFIG*);
 uint8_t print_lines_ft(CONFIG*);
 uint8_t print_lines8(CONFIG*);