Cafu Engine
FontGenerator.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_FONTWIZARD_FONT_GENERATOR_HPP_INCLUDED
8 #define CAFU_FONTWIZARD_FONT_GENERATOR_HPP_INCLUDED
9 
10 #include <ft2build.h>
11 #include FT_FREETYPE_H
12 
13 #include "wx/wx.h"
14 
15 #include "Templates/Array.hpp"
16 
17 
18 struct GlyphInfoT;
20 struct BitmapT;
21 
22 
24 {
25  public:
26 
27  struct FontDataT
28  {
29  FT_Face FTFontFace;
31  ArrayT<unsigned long> CharToGlyphInfoNr;
32  ArrayT<GlyphInfoT> GlyphInfos;
33  };
34 
35 
37  ~FontGeneratorT();
38 
39  /// Generates a Cafu font from a .ttf font file.
40  /// @param FontFile The ttf file to create the Cafu font from.
41  /// @param DebugPNGs Add debug information to the created texture images?
42  /// @return Whether the font has been successfully generated.
43  bool GenerateFont(const wxString& FontFile, bool DebugPNGs=false);
44 
45  /// Saves all files related to this font into a directory.
46  /// @param Directory The directory into which the font files are saved.
47  /// @param MaterialBaseName The name of the material to be created for this font. Empty string means that no material is created.
48  void SaveFont(const wxString& Directory, const wxString& MaterialBaseName="") const;
49 
50  /// Gets the number of sizes created for this font.
51  /// @return Number of font sizes.
52  unsigned long GetNrOfSizes() const;
53 
54  /// Gets an array of font bitmaps for the passed font size.
55  /// @param SizeNr The size number for which the bitmaps should be returned (if this size number is not existant an empty array is returned).
56  /// @return Array of all font bitmaps for this font size.
57  ArrayT<BitmapT*> GetBitmaps(unsigned long SizeNr) const;
58 
59 
60  private:
61 
62  FT_Library m_FTLib;
63  bool m_FTInited;
64  bool m_DebugPNGs;
65 
66  ArrayT<FontDataT> m_FontData; ///< Contains font data for different font sizes.
67 
68 
69  void ProcessNewGlyph(FT_Face& Face, GlyphInfoT& Glyph, RectBitmapAllocatorT& RBA);
70  void ClearFontData();
71 
72  FontGeneratorT(const FontGeneratorT&); ///< Use of the Copy Constructor is not allowed.
73  void operator = (const FontGeneratorT&); ///< Use of the Assignment Operator is not allowed.
74 };
75 
76 #endif
Definition: FontGenerator.hpp:27
unsigned long GetNrOfSizes() const
Gets the number of sizes created for this font.
Definition: FontGenerator.cpp:327
void SaveFont(const wxString &Directory, const wxString &MaterialBaseName="") const
Saves all files related to this font into a directory.
Definition: FontGenerator.cpp:219
bool GenerateFont(const wxString &FontFile, bool DebugPNGs=false)
Generates a Cafu font from a .ttf font file.
Definition: FontGenerator.cpp:144
This class represents a RGBA bitmap.
Definition: Bitmap.hpp:20
Definition: FontGenerator.hpp:23
ArrayT< BitmapT * > GetBitmaps(unsigned long SizeNr) const
Gets an array of font bitmaps for the passed font size.
Definition: FontGenerator.cpp:333
Definition: MakeFont.cpp:37
This class "allocates" rectangular areas in larger bitmaps.
Definition: MakeFont.cpp:73