Subversion Repositories libOLED

Rev

Rev 3 | Rev 13 | 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) :
  16.       m_height (height), m_width (width), m_spacing (spacing), m_chars (chars), m_data (
  17.           data)
  18.   {
  19.   }
  20.  
  21.   virtual char
  22.   getPixel (char c, int x, int y) =0;
  23.  
  24.   // character width
  25.   uint8_t
  26.   width ()
  27.   {
  28.     return m_width;
  29.   }
  30.  
  31.   // character height
  32.   uint8_t
  33.   height ()
  34.   {
  35.     return m_height;
  36.   }
  37.  
  38.   uint8_t
  39.   chars ()
  40.   {
  41.     return m_chars;
  42.   }
  43.  
  44.   uint8_t
  45.   spacing ()
  46.   {
  47.     return m_spacing;
  48.   }
  49. protected:
  50.   uint8_t const m_height;
  51.   uint8_t const m_width;
  52.   uint8_t const m_spacing;
  53.   uint8_t const m_chars;
  54.   char const *m_data;
  55. };
  56.  
  57. class font5x7_t : public font_t
  58. {
  59. public:
  60.   font5x7_t (char const *data) :
  61.       font_t (7, 5, 6, 96, data)
  62.   {
  63.   }
  64.   ;
  65.  
  66.   char
  67.   getPixel (char c, int x, int y) override;
  68.  
  69. };
  70.  
  71. class font10x18_t : public font_t
  72. {
  73. public:
  74.   font10x18_t (char const *data) :
  75.       font_t (18, 10, 10, 96, data)
  76.   {
  77.   }
  78.   ;
  79.  
  80.   char
  81.   getPixel (char c, int x, int y) override;
  82. };
  83.  
  84. // defined fonts
  85. // original 5x7
  86. extern font5x7_t small_font;
  87.  
  88. // lucida font
  89. // in 10x18
  90. extern font10x18_t large_font;
  91.