Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
freetype.hpp
1 /*
2  Title --- font/freetype.hpp
3 
4  Copyright (C) 2013 Giacomo Trudu - wicker25[at]gmail[dot]com
5 
6  This file is part of Rpi-hw.
7 
8  Rpi-hw is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation version 3 of the License.
11 
12  Rpi-hw is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with Rpi-hw. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #include <rpi-hw/config.hpp>
23 
24 #if USE_FREETYPE
25 
26 #ifndef _RPI_HW_FONT_FREETYPE_HPP_
27 #define _RPI_HW_FONT_FREETYPE_HPP_
28 
29 #include <iostream>
30 #include <string>
31 
32 #include <sys/stat.h>
33 
34 // FreeType Headers
35 #include <ft2build.h>
36 #include FT_FREETYPE_H
37 #include FT_CACHE_H
38 #include FT_CACHE_CHARMAP_H
39 #include FT_CACHE_SMALL_BITMAPS_H
40 
41 #include <rpi-hw/types.hpp>
42 #include <rpi-hw/exception.hpp>
43 #include <rpi-hw/math.hpp>
44 #include <rpi-hw/utils.hpp>
45 
46 #include <rpi-hw/font/base.hpp>
47 
48 namespace rpihw { // Begin main namespace
49 
50 namespace font { // Begin fonts namespace
51 
52 //! The character sets supported by charmaps.
53 enum Encoding {
54 
55  ENCODING_NONE = FT_ENCODING_NONE,
56  ENCODING_UNICODE = FT_ENCODING_UNICODE,
57  ENCODING_MS_SYMBOL = FT_ENCODING_MS_SYMBOL,
58  ENCODING_SJIS = FT_ENCODING_SJIS,
59  ENCODING_GB2312 = FT_ENCODING_GB2312,
60  ENCODING_BIG5 = FT_ENCODING_BIG5,
61  ENCODING_WANSUNG = FT_ENCODING_WANSUNG,
62  ENCODING_JOHAB = FT_ENCODING_JOHAB,
63  ENCODING_ADOBE_LATIN_1 = FT_ENCODING_ADOBE_LATIN_1,
64  ENCODING_ADOBE_STANDARD = FT_ENCODING_ADOBE_STANDARD,
65  ENCODING_ADOBE_EXPERT = FT_ENCODING_ADOBE_EXPERT,
66  ENCODING_ADOBE_CUSTOM = FT_ENCODING_ADOBE_CUSTOM,
67  ENCODING_APPLE_ROMAN = FT_ENCODING_APPLE_ROMAN
68 };
69 
70 //! Function used by `FTC_Manager_New` to call the method `freetype::buildFace`.
71 FT_Error faceRequester( FTC_FaceID face_id, FT_Library library, FT_Pointer obj, FT_Face *face );
72 
73 /*!
74  @class freetype
75  @brief TrueType font.
76 */
77 class freetype : public font::base {
78 
79 public:
80 
81  /*!
82  @brief Constructor method.
83  @param[in] path The path to the font.
84  @param[in] height The height of the font.
85  @param[in] mode The fond rendering mode.
86  @param[in] encoding The character set used by the font.
87  */
88  freetype( const std::string &path, uint8_t height, RenderMode mode = font::RENDER_DEFAULT, Encoding encoding = ENCODING_NONE );
89 
90  //! Destructor method.
91  virtual ~freetype();
92 
93  //! Returns the path to the font.
94  virtual const std::string &getPath() const;
95 
96  /*!
97  @brief Sets the font size.
98  @param[in] height The height of the font.
99  */
100  virtual void setSize( uint8_t height );
101 
102  /*!
103  @brief Returns the width of a character.
104  @param[in] charcode The character code.
105  */
106  virtual uint8_t getWidth( uint32_t charcode ) const;
107 
108  //! Returns the height of the font.
109  virtual uint8_t getHeight() const;
110 
111  /*!
112  @brief Returns the data of the character font.
113  @param[in] charcode The character code.
114  @param[out] glyph The glyph of the character.
115  */
116  virtual void data( uint32_t charcode, glyph &glyph ) const;
117 
118  //! Builds the fresh new font object (don't use directly).
119  void buildFace( FTC_FaceID face_id, FT_Face *face );
120 
121 protected:
122 
123  //! Path to the font.
124  std::string m_path;
125 
126  //! The FreeType library instance.
127  FT_Library m_library;
128 
129  //! The cache manager.
130  FTC_Manager m_manager;
131 
132  //! Type of images in the glyph cache.
133  FTC_ImageType m_image_type;
134 
135  //! Charmap cache.
136  FTC_CMapCache m_cmap_cache;
137 
138  //! Small bitmap cache.
139  FTC_SBitCache m_sbit_cache;
140 
141  //! The character set used by the font.
143 
144  /*!
145  @brief Gets the bitmap of the character.
146  @param[in] charcode The character code.
147  @param[out] sbit The handle to the bitmap.
148  */
149  void getSBitChar( uint32_t charcode, FTC_SBit &sbit ) const;
150 };
151 
152 } // End of fonts namespace
153 
154 } // End of main namespace
155 
156 
157 // Include inline methods
158 #include <rpi-hw/font/freetype-inl.hpp>
159 
160 #endif /* _RPI_HW_FONT_FREETYPE_HPP_ */
161 
162 #endif /* USE_FREETYPE */
void buildFace(FTC_FaceID face_id, FT_Face *face)
Builds the fresh new font object (don&#39;t use directly).
RenderMode
The font rendering mode.
Definition: base.hpp:40
FT_Library m_library
The FreeType library instance.
Definition: freetype.hpp:127
FTC_CMapCache m_cmap_cache
Charmap cache.
Definition: freetype.hpp:136
freetype(const std::string &path, uint8_t height, RenderMode mode=font::RENDER_DEFAULT, Encoding encoding=ENCODING_NONE)
Constructor method.
virtual uint8_t getHeight() const
Returns the height of the font.
void getSBitChar(uint32_t charcode, FTC_SBit &sbit) const
Gets the bitmap of the character.
FT_Error faceRequester(FTC_FaceID face_id, FT_Library library, FT_Pointer obj, FT_Face *face)
Function used by FTC_Manager_New to call the method freetype::buildFace.
FTC_ImageType m_image_type
Type of images in the glyph cache.
Definition: freetype.hpp:133
virtual const std::string & getPath() const
Returns the path to the font.
virtual uint8_t getWidth(uint32_t charcode) const
Returns the width of a character.
Encoding m_encoding
The character set used by the font.
Definition: freetype.hpp:142
Generic font.
Definition: base.hpp:50
FTC_SBitCache m_sbit_cache
Small bitmap cache.
Definition: freetype.hpp:139
Simple glyph structure.
Definition: glyph.hpp:48
std::string m_path
Path to the font.
Definition: freetype.hpp:124
virtual ~freetype()
Destructor method.
virtual void data(uint32_t charcode, glyph &glyph) const
Returns the data of the character font.
virtual void setSize(uint8_t height)
Sets the font size.
Encoding
The character sets supported by charmaps.
Definition: freetype.hpp:53
TrueType font.
Definition: freetype.hpp:77
FTC_Manager m_manager
The cache manager.
Definition: freetype.hpp:130