VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
grglyph.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file grglyph.h
19 ///
20 
21 #ifndef GR_GLYPH__H
22 #define GR_GLYPH__H
23 
24 #include "gdef.h"
25 #include <vector>
26 #include <string>
27 
28 namespace Gr
29 {
30  class Glyph ;
31 }
32 
33 /// \class Gr::Glyph
34 /// A class for mapping characters to 8x8 glyphs.
35 ///
36 class Gr::Glyph
37 {
38 public:
39  typedef std::vector<bool> row_type ;
40  typedef std::vector<row_type> matrix_type ;
41 
42  static matrix_type matrix( char c ) ;
43  ///< Returns a glyph matrix for the given character.
44 
45  template <typename Tout>
46  static void output( const std::string & s , Tout & out_functor ) ;
47  ///< Calls an (x,y,bool) functor for all the glyph points corresponding
48  ///< to the given line of text, with no support for line-wrapping.
49  ///<
50  ///< The functor call order is suitable for a raster scan, ie. the
51  ///< x parameter varies fastest and traverses the whole string before
52  ///< the y parameter is incremented.
53  ///<
54  ///< An 'off' pixel is added at the end of each characer raster scan
55  ///< (including the last character), so there are nine horizontal
56  ///< pixels per character and a total of eight vertical pixels.
57 
58 private:
59  Glyph() ;
60  static bool point( char , unsigned int , unsigned int ) ;
61  static unsigned int * row( char ) ;
62 } ;
63 
64 namespace Gr
65 {
66  template <typename Tout>
67  void Glyph::output( const std::string & s , Tout & out )
68  {
69  for( unsigned int dy = 0U ; dy < 8U ; dy++ )
70  {
71  unsigned int n = 0U ;
72  std::string::const_iterator const end = s.end() ;
73  for( std::string::const_iterator p = s.begin() ; p != end ; ++p , n++ )
74  {
75  for( unsigned int dx = 0U ; dx < 8U ; dx++ )
76  out( (n*9U) + dx , dy , point(*p,dx,dy) ) ;
77  out( (n*9U) + 8U , dy , false ) ;
78  }
79  }
80  }
81 }
82 
83 #endif
static matrix_type matrix(char c)
Returns a glyph matrix for the given character.
Definition: grglyph.cpp:293
A class for mapping characters to 8x8 glyphs.
Definition: grglyph.h:36
static void output(const std::string &s, Tout &out_functor)
Calls an (x,y,bool) functor for all the glyph points corresponding to the given line of text...
Definition: grglyph.h:67