My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gb2312_puhui16.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "pic_manager.h"
  25. #include <lvgl.h>
  26. #include "../../../../inc/MarlinConfig.h"
  27. #if HAS_SPI_FLASH_FONT
  28. typedef struct {
  29. uint16_t min;
  30. uint16_t max;
  31. uint8_t bpp;
  32. uint8_t reserved[3];
  33. } x_header_t;
  34. typedef struct {
  35. uint32_t pos;
  36. } x_table_t;
  37. typedef struct {
  38. uint8_t adv_w;
  39. uint8_t box_w;
  40. } glyph_dsc_t;
  41. static x_header_t __g_xbf_hd = { .min = 0, .max = 0, .bpp = 0 };
  42. static uint8_t __g_font_buf[63];
  43. static uint8_t *__user_font_getdata(int offset, int size) {
  44. //ZERO(__g_font_buf);
  45. get_spi_flash_data((char *)__g_font_buf, offset, size);
  46. return __g_font_buf;
  47. //return &buf_test[offset];
  48. }
  49. static const uint8_t * __user_font_get_bitmap(const lv_font_t * font, uint32_t unicode_letter) {
  50. if (__g_xbf_hd.max == 0) {
  51. uint8_t *p = __user_font_getdata(0, sizeof(x_header_t));
  52. memcpy(&__g_xbf_hd, p, sizeof(x_header_t));
  53. }
  54. if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min)
  55. return NULL;
  56. uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4;
  57. uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4);
  58. if (p_pos[0] != 0) {
  59. uint32_t pos = p_pos[0];
  60. //glyph_dsc_t * gdsc = (glyph_dsc_t*)__user_font_getdata(pos, 2);
  61. __user_font_getdata(pos, 2);
  62. //return __user_font_getdata(pos+2, gdsc->box_w*__g_xbf_hd.bpp/8);
  63. return __user_font_getdata(pos + 2, sizeof(__g_font_buf));
  64. }
  65. return NULL;
  66. }
  67. static bool __user_font_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) {
  68. if (__g_xbf_hd.max == 0) {
  69. uint8_t *p = __user_font_getdata(0, sizeof(x_header_t));
  70. memcpy(&__g_xbf_hd, p, sizeof(x_header_t));
  71. }
  72. if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min)
  73. return NULL;
  74. uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4;
  75. uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4);
  76. if (p_pos[0] != 0) {
  77. glyph_dsc_t * gdsc = (glyph_dsc_t*)__user_font_getdata(p_pos[0], 2);
  78. dsc_out->adv_w = gdsc->adv_w;
  79. dsc_out->box_h = font->line_height;
  80. dsc_out->box_w = gdsc->box_w;
  81. dsc_out->ofs_x = 0;
  82. dsc_out->ofs_y = 0;
  83. dsc_out->bpp = __g_xbf_hd.bpp;
  84. return true;
  85. }
  86. return false;
  87. }
  88. /*lv_font_t gb2312_puhui32 = {
  89. .get_glyph_bitmap = __user_font_get_bitmap,
  90. .get_glyph_dsc = __user_font_get_glyph_dsc,
  91. .line_height = 25,
  92. .base_line = 0,
  93. };*/
  94. lv_font_t gb2312_puhui32;
  95. void init_gb2312_font() {
  96. gb2312_puhui32.get_glyph_bitmap = __user_font_get_bitmap;
  97. gb2312_puhui32.get_glyph_dsc = __user_font_get_glyph_dsc;
  98. gb2312_puhui32.line_height = 21;
  99. gb2312_puhui32.base_line = 0;
  100. }
  101. #endif // HAS_SPI_FLASH_FONT
  102. #endif // HAS_TFT_LVGL_UI