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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*************
  2. * unicode.h *
  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. #pragma once
  21. class CommandProcessor;
  22. namespace FTDI {
  23. #ifdef TOUCH_UI_USE_UTF8
  24. typedef uint16_t utf8_char_t;
  25. /**
  26. * Converts a 32-bit codepoint into UTF-8. This compile-time function
  27. * will be useful until the u8'a' character literal becomes more common.
  28. */
  29. constexpr uint32_t utf8(const uint32_t c) {
  30. return (c < 0x7F ) ? c :
  31. (c < 0x7FF) ? (0x0000C080 | ((c & 0b011111000000) << 2) | (c & 0b111111)) :
  32. (c < 0xFFFF) ? (0x00E08080 | ((c & 0b001111000000000000) << 4) | ((c & 0b111111000000) << 2) | (c & 0b111111)) :
  33. (0xF0808080 | ((c & 0b000111000000000000000000) << 6) | ((c & 0b111111000000000000) << 4) | ((c & 0b111111000000) << 2) | (c & 0b111111));
  34. }
  35. /* Returns true if the string has UTF8 string characters */
  36. bool has_utf8_chars(progmem_str str);
  37. bool has_utf8_chars(const char *str);
  38. /* Returns the next character in a UTF8 string and increments the
  39. * pointer to the next character */
  40. utf8_char_t get_utf8_char_and_inc(const char *&c);
  41. /* Returns the next character in a UTF8 string, without incrementing */
  42. inline utf8_char_t get_utf8_char(const char *c) {return get_utf8_char_and_inc(c);}
  43. void load_utf8_data(uint16_t addr);
  44. #else
  45. typedef char utf8_char_t;
  46. inline utf8_char_t get_utf8_char_and_inc(const char *&c) {return *c++;}
  47. inline utf8_char_t get_utf8_char(const char *c) {return *c;}
  48. inline void load_utf8_data(uint16_t) {}
  49. #endif
  50. void load_utf8_bitmaps(CommandProcessor& cmd);
  51. uint16_t get_utf8_char_width(utf8_char_t, font_size_t);
  52. uint16_t get_utf8_text_width(progmem_str, font_size_t);
  53. uint16_t get_utf8_text_width(const char *, font_size_t);
  54. void draw_utf8_text(CommandProcessor&, int x, int y, progmem_str, font_size_t, uint16_t options = 0);
  55. void draw_utf8_text(CommandProcessor&, int x, int y, const char *, font_size_t, uint16_t options = 0);
  56. // Similar to CLCD::FontMetrics, but can be used with UTF8 encoded strings.
  57. struct FontMetrics {
  58. #ifdef TOUCH_UI_USE_UTF8
  59. font_size_t fs;
  60. #else
  61. CLCD::FontMetrics fm;
  62. #endif
  63. inline void load(uint8_t rom_font_size) {
  64. #ifdef TOUCH_UI_USE_UTF8
  65. fs = font_size_t::from_romfont(rom_font_size);
  66. #else
  67. fm.load(rom_font_size);
  68. #endif
  69. }
  70. inline uint16_t get_char_width(utf8_char_t c) const {
  71. #ifdef TOUCH_UI_USE_UTF8
  72. return get_utf8_char_width(c, fs);
  73. #else
  74. return fm.char_widths[(uint8_t)c];
  75. #endif
  76. }
  77. inline uint8_t get_height() const {
  78. #ifdef TOUCH_UI_USE_UTF8
  79. return fs.get_height();
  80. #else
  81. return fm.height;
  82. #endif
  83. }
  84. inline FontMetrics(uint8_t rom_font_size) {
  85. load(rom_font_size);
  86. }
  87. };
  88. }