iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleFont.H
Go to the documentation of this file.
1 /*! @file
2  @author Unknown
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 // //////////////////////////////////////////////////////////////////// //
36 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 //
37 // by the University of Southern California (USC) and the iLab at USC. //
38 // See http://iLab.usc.edu for information about this project. //
39 // //////////////////////////////////////////////////////////////////// //
40 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
41 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
42 // in Visual Environments, and Applications'' by Christof Koch and //
43 // Laurent Itti, California Institute of Technology, 2001 (patent //
44 // pending; application number 09/912,225 filed July 23, 2001; see //
45 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). //
46 // //////////////////////////////////////////////////////////////////// //
47 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. //
48 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can //
49 // Public License as published by the Free Software Foundation; either //
50 // version 2 of the License, or (at your option) any later version. //
51 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope //
52 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write //
53 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, //
54 // Boston, MA 02111-1307 USA. //
55 // //////////////////////////////////////////////////////////////////// //
56 
57 
58 #ifndef INCLUDE_NRT_IMAGEPROC_DRAWING_SIMPLEFONT_H
59 #define INCLUDE_NRT_IMAGEPROC_DRAWING_SIMPLEFONT_H
60 
61 #include <nrt/Core/Image/Image.H>
62 
63 namespace nrt
64 {
65 
66  //! A simple font class
67  /*! This is a very impoverished (by today's standards...) font class that allows one to write text into Image
68  objects. The SimpleFont definitions only support fixed width and consist of the 95 following characters (the first
69  one is a space):
70 
71  \verbatim
72  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
73  \endverbatim
74 
75  as created by saliency/src/AppMedia/app-font2c.C in the INVT toolkit from an image of these characters.
76  The function nrt::drawText() uses SimpleFont to render text into Image arrys of pixels.
77 
78  \ingroup textdrawing
79  \see textdrawing */
80  class SimpleFont
81  {
82  public:
83  //! Constructor
84  SimpleFont(const uint cw, const uint ch, const unsigned char *cdata);
85 
86  //! Destructor
87  ~SimpleFont();
88 
89  //! Pseudo-constructor to get a font with fixed width
90  /*! Supported widths include: 6, 7, 8, 9, 10, 14 and 20. */
91  static SimpleFont FIXED(const uint width);
92 
93  //! Get a standard font with width <= maxwidth
94  /*! If no font satisfies this criterion, return the smallest available font */
95  static SimpleFont fixedMaxWidth(const uint maxwidth);
96 
97  //! Get a standard font with height <= maxheight
98  /*! If no font satisfies this criterion, return the smallest available font */
99  static SimpleFont fixedMaxHeight(const uint maxheight);
100 
101  //! Return the n'th standard font (n must be less than numStdFonts())
102  static SimpleFont stdFont(const size_t n);
103 
104  //! Return the number of standard fonts
105  static size_t numStdFonts();
106 
107  //! Helper function to get a pointer to a specific char
108  /*! a Pointer to 'space' is returned if c < 32 or c > 126 */
109  const unsigned char* charptr(const int c) const;
110 
111  //! Width of each char, in pixels
112  uint w() const;
113 
114  //! Height of each char, in pixels
115  uint h() const;
116 
117  //! Equality operator; return true if the two fonts share the same data
118  bool operator==(SimpleFont const & f) const;
119 
120  //! Inequality operator
121  bool operator!=(SimpleFont const & f) const;
122 
123  private:
124  uint ww; // Width of each char, in pixels
125  uint hh; // Height of each char, in pixels
126  unsigned char const * data; // Pointer to the pixel data
127  };
128 
129 }
130 
131 #endif // INCLUDE_NRT_IMAGEPROC_DRAWING_SIMPLEFONT_H