Subversion Repositories libOLED

Rev

Rev 4 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // font class library
  2. #pragma once
  3. #include <cstdint>
  4.  
  5. class font_t
  6. {
  7. public:
  8.   /// \param height - pixel character height
  9.   /// \param width  - pixel character width
  10.   /// \param spacing - character to character spacing
  11.   /// \param chars  - number of characters in character set
  12.   /// \param data - constant data
  13.   font_t(uint8_t const height, uint8_t const width,
  14.          uint8_t const spacing, uint8_t const chars,
  15.          char const *data) : m_height(height), m_width(width), m_spacing(spacing), m_chars(chars), m_data(data)
  16.   {
  17.   }
  18.  
  19.   virtual char
  20.   getPixel(char c, int x, int y) = 0;
  21.  
  22.   // character width
  23.   uint8_t
  24.   width()
  25.   {
  26.     return m_width;
  27.   }
  28.  
  29.   // character height
  30.   uint8_t
  31.   height()
  32.   {
  33.     return m_height;
  34.   }
  35.  
  36.   uint8_t
  37.   chars()
  38.   {
  39.     return m_chars;
  40.   }
  41.  
  42.   uint8_t
  43.   spacing()
  44.   {
  45.     return m_spacing;
  46.   }
  47.  
  48. protected:
  49.   /// @brief Pixel height
  50.   uint8_t const m_height;
  51.   /// @brief Bitmap width
  52.   uint8_t const m_width;
  53.   /// @brief Spacing between characters
  54.   uint8_t const m_spacing;
  55.   /// @brief Number of characters in the character set bit map
  56.   uint8_t const m_chars;
  57.   char const *m_data;
  58. };
  59.  
  60. class font5x7_t : public font_t
  61. {
  62. public:
  63.   // one byte of pixels per character row.
  64.   font5x7_t(unsigned char_count, char const *data) : font_t(7, 5, 6, char_count, data){};
  65.  
  66.   char
  67.   getPixel(char c, int x, int y) override;
  68. };
  69.  
  70. class font10x18_t : public font_t
  71. {
  72. public:
  73.   // XBM format
  74.   font10x18_t(unsigned char_count, char const *data) : font_t(18, 10, 10, char_count, data){};
  75.  
  76.   char
  77.   getPixel(char c, int x, int y) override;
  78. };
  79.  
  80. // defined fonts
  81. // original 5x7
  82. extern font5x7_t small_font;
  83.  
  84. // lucida font
  85. // in 10x18
  86. extern font10x18_t large_font;
  87.