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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. get_spi_flash_data((char *)__g_font_buf, offset, size);
  45. return __g_font_buf;
  46. }
  47. static const uint8_t * __user_font_get_bitmap(const lv_font_t * font, uint32_t unicode_letter) {
  48. if (__g_xbf_hd.max == 0) {
  49. uint8_t *p = __user_font_getdata(0, sizeof(x_header_t));
  50. memcpy(&__g_xbf_hd, p, sizeof(x_header_t));
  51. }
  52. if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min)
  53. return nullptr;
  54. uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4;
  55. uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4);
  56. if (p_pos[0] != 0) {
  57. uint32_t pos = p_pos[0];
  58. __user_font_getdata(pos, 2);
  59. return __user_font_getdata(pos + 2, sizeof(__g_font_buf));
  60. }
  61. return nullptr;
  62. }
  63. 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) {
  64. if (__g_xbf_hd.max == 0) {
  65. uint8_t *p = __user_font_getdata(0, sizeof(x_header_t));
  66. memcpy(&__g_xbf_hd, p, sizeof(x_header_t));
  67. }
  68. if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min)
  69. return false;
  70. uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4;
  71. uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4);
  72. if (p_pos[0] != 0) {
  73. glyph_dsc_t * gdsc = (glyph_dsc_t*)__user_font_getdata(p_pos[0], 2);
  74. dsc_out->adv_w = gdsc->adv_w;
  75. dsc_out->box_h = font->line_height;
  76. dsc_out->box_w = gdsc->box_w;
  77. dsc_out->ofs_x = 0;
  78. dsc_out->ofs_y = 0;
  79. dsc_out->bpp = __g_xbf_hd.bpp;
  80. return true;
  81. }
  82. return false;
  83. }
  84. lv_font_t gb2312_puhui32;
  85. void init_gb2312_font() {
  86. gb2312_puhui32.get_glyph_bitmap = __user_font_get_bitmap;
  87. gb2312_puhui32.get_glyph_dsc = __user_font_get_glyph_dsc;
  88. gb2312_puhui32.line_height = 21;
  89. gb2312_puhui32.base_line = 0;
  90. }
  91. #endif // HAS_SPI_FLASH_FONT
  92. #endif // HAS_TFT_LVGL_UI