cnxfont.hxx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cnxfont.hxx
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXFONT_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXFONT_HXX
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include <nuttx/nx/nxglib.h>
  29. #include <nuttx/nx/nxfonts.h>
  30. #include "graphics/nxwidgets/nxconfig.hxx"
  31. /****************************************************************************
  32. * Pre-Processor Definitions
  33. ****************************************************************************/
  34. /****************************************************************************
  35. * Implementation Classes
  36. ****************************************************************************/
  37. #if defined(__cplusplus)
  38. namespace NXWidgets
  39. {
  40. class CNxString;
  41. struct SBitmap;
  42. /**
  43. * Class defining the properties of one font.
  44. */
  45. class CNxFont
  46. {
  47. private:
  48. enum nx_fontid_e m_fontId; /**< The font ID. */
  49. NXHANDLE m_fontHandle; /**< The font handle */
  50. FAR const struct nx_font_s *m_pFontSet; /** < The font set metrics */
  51. nxgl_mxpixel_t m_fontColor; /**< Color to draw the font with when rendering. */
  52. nxgl_mxpixel_t m_transparentColor; /**< Background color that should not be rendered. */
  53. public:
  54. /**
  55. * CNxFont Constructor.
  56. *
  57. * @param fontid The font ID to use.
  58. * @param fontColor The font color to use.
  59. * @param transparentColor The color in the font bitmap used as the
  60. * background color.
  61. */
  62. CNxFont(enum nx_fontid_e fontid, nxgl_mxpixel_t fontColor,
  63. nxgl_mxpixel_t transparentColor);
  64. /**
  65. * CNxFont Destructor.
  66. */
  67. ~CNxFont() { }
  68. /**
  69. * Checks if supplied character is blank in the current font.
  70. *
  71. * @param letter The character to check.
  72. * @return True if the glyph contains any pixels to be drawn. False if
  73. * the glyph is blank.
  74. */
  75. const bool isCharBlank(const nxwidget_char_t letter) const;
  76. /**
  77. * Gets the color currently being used as the drawing color.
  78. *
  79. * @return The current drawing color.
  80. */
  81. inline const nxgl_mxpixel_t getColor() const
  82. {
  83. return m_fontColor;
  84. }
  85. /**
  86. * Sets the color to use as the drawing color. If set, this overrides
  87. * the colors present in a non-monochrome font.
  88. * @param color The new drawing color.
  89. */
  90. inline void setColor(const nxgl_mxpixel_t color)
  91. {
  92. m_fontColor = color;
  93. }
  94. /**
  95. * Get the color currently being used as the transparent background
  96. * color.
  97. * @return The transparent background color.
  98. */
  99. inline const nxgl_mxpixel_t getTransparentColor() const
  100. {
  101. return m_transparentColor;
  102. }
  103. /**
  104. * Sets the transparent background color to a new value.
  105. * @param color The new background color.
  106. */
  107. inline void setTransparentColor(const nxgl_mxpixel_t color)
  108. {
  109. m_transparentColor = color;
  110. }
  111. /**
  112. * Draw an individual character of the font to the specified bitmap.
  113. *
  114. * @param bitmap The bitmap to draw to.
  115. * @param letter The character to output.
  116. */
  117. void drawChar(FAR SBitmap *bitmap, nxwidget_char_t letter);
  118. /**
  119. * Get the width of a string in pixels when drawn with this font.
  120. *
  121. * @param text The string to check.
  122. * @return The width of the string in pixels.
  123. */
  124. nxgl_coord_t getStringWidth(const CNxString &text) const;
  125. inline nxgl_coord_t getStringWidth(FAR const CNxString *text) const
  126. {
  127. return getStringWidth(*text);
  128. }
  129. /**
  130. * Get the width of a portion of a string in pixels when drawn with this
  131. * font.
  132. *
  133. * @param text The string to check.
  134. * @param startIndex The start point of the substring within the string.
  135. * @param length The length of the substring in chars.
  136. * @return The width of the substring in pixels.
  137. */
  138. nxgl_coord_t getStringWidth(const CNxString &text,
  139. int startIndex, int length) const;
  140. inline nxgl_coord_t getStringWidth(FAR const CNxString *text,
  141. int startIndex, int length) const
  142. {
  143. return getStringWidth(*text, startIndex, length);
  144. }
  145. /**
  146. * Gets font metrics for a particular character
  147. *
  148. *
  149. * @param letter The character to get the width of.
  150. * @param metrics The location to return the font metrics
  151. */
  152. void getCharMetrics(nxwidget_char_t letter,
  153. FAR struct nx_fontmetric_s *metrics) const;
  154. /**
  155. * Get the width of an individual character.
  156. *
  157. * @param letter The character to get the width of.
  158. * @return The width of the character in pixels.
  159. */
  160. nxgl_coord_t getCharWidth(nxwidget_char_t letter) const;
  161. /**
  162. * Get the height of an individual character.
  163. *
  164. * @param letter The letter to get the height of.
  165. * @return The height of the character in pixels.
  166. */
  167. inline nxgl_coord_t getCharHeight(nxwidget_char_t letter) const;
  168. /**
  169. * Gets the maximum width of the font.
  170. *
  171. * @return The height of the font.
  172. */
  173. inline const uint8_t getMaxWidth(void) const
  174. {
  175. return m_pFontSet->mxwidth;
  176. }
  177. /**
  178. * Gets the height of the font.
  179. *
  180. * @return The height of the font.
  181. */
  182. inline const uint8_t getHeight(void) const
  183. {
  184. return m_pFontSet->mxheight;
  185. }
  186. };
  187. }
  188. #endif // __cplusplus
  189. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXFONT_HXX