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.

standard_char_set.cpp 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*************************
  2. * standard_char_set.cpp *
  3. *************************/
  4. /****************************************************************************
  5. * Written By Marcio Teixeira 2019 - Aleph Objects, Inc. *
  6. * *
  7. * This program is free software: you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * To view a copy of the GNU General Public License, go to the following *
  18. * location: <http://www.gnu.org/licenses/>. *
  19. ****************************************************************************/
  20. #include "../ftdi_extended.h"
  21. #if defined(FTDI_EXTENDED) && ENABLED(TOUCH_UI_USE_UTF8)
  22. constexpr static uint8_t std_font = 31;
  23. /* Lookup table of the char widths for standard ROMFONT 31 */
  24. uint8_t FTDI::StandardCharSet::std_char_width(char c) {
  25. static const uint8_t tbl[] PROGMEM = {
  26. 10, 11, 15, 26, 25, 31, 26, 10, 15, 14, 18, 24, 9, 18, 11, 17, 24, 24,
  27. 24, 24, 24, 24, 24, 24, 24, 24, 10, 10, 21, 23, 22, 20, 37, 27, 27, 26,
  28. 28, 23, 22, 28, 29, 12, 23, 26, 22, 35, 29, 28, 26, 29, 27, 26, 26, 28,
  29. 27, 36, 27, 26, 25, 12, 18, 12, 18, 21, 13, 23, 24, 22, 24, 22, 15, 24,
  30. 24, 10, 11, 22, 10, 36, 24, 24, 24, 24, 15, 22, 14, 24, 21, 32, 21, 21,
  31. 22, 15, 10, 15, 29, 10
  32. };
  33. return pgm_read_byte(&tbl[c - ' ']);
  34. }
  35. /**
  36. * Load bitmap data into RAMG. This function is called once at the start
  37. * of the program.
  38. *
  39. * Parameters:
  40. *
  41. * addr - Address in RAMG where the font data is written
  42. */
  43. void FTDI::StandardCharSet::load_data(uint32_t) {
  44. }
  45. /**
  46. * Populates the bitmap handles for the custom into the display list.
  47. * This function is called once at the start of each display list.
  48. *
  49. * Parameters:
  50. *
  51. * cmd - Object used for writing to the FTDI chip command queue.
  52. */
  53. void FTDI::StandardCharSet::load_bitmaps(CommandProcessor& cmd) {
  54. CLCD::FontMetrics std_fm(std_font);
  55. set_font_bitmap(cmd, std_fm, std_font);
  56. }
  57. /**
  58. * Renders a character at location x and y. The x position is incremented
  59. * by the width of the character.
  60. *
  61. * Parameters:
  62. *
  63. * cmd - If non-NULL the symbol is drawn to the screen.
  64. * If NULL, only increment position for text measurement.
  65. *
  66. * x, y - The location at which to draw the character. On output,
  67. * incremented to the location of the next character.
  68. *
  69. * fs - A scaling object used to scale the font. The display will
  70. * already be configured to scale bitmaps, but positions
  71. * must be scaled using fs.scale()
  72. *
  73. * c - The unicode code point to draw. If the renderer does not
  74. * support the character, it should draw nothing.
  75. */
  76. bool FTDI::StandardCharSet::render_glyph(CommandProcessor* cmd, int &x, int &y, font_size_t fs, utf8_char_t c) {
  77. uint8_t which = (c >= ' ' && c < 128) ? c : '?';
  78. uint8_t width = std_char_width(which);
  79. if (c == '\t') {
  80. // Special handling for the tab character
  81. which = ' ';
  82. width = std_char_width(' ');
  83. }
  84. // Draw the character
  85. if (cmd) ext_vertex2ii(*cmd, x, y, std_font, which);
  86. // Increment X to the next character position
  87. x += fs.scale(width);
  88. return true;
  89. }
  90. #endif // FTDI_EXTENDED && TOUCH_UI_USE_UTF8