Panda3D
 All Classes Functions Variables Enumerations
pnmTextMaker.h
00001 // Filename: pnmTextMaker.h
00002 // Created by:  drose (03Apr02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PNMTEXTMAKER_H
00016 #define PNMTEXTMAKER_H
00017 
00018 #include "pandabase.h"
00019 #include "pmap.h"
00020 #include "freetypeFont.h"
00021 #include "textEncoder.h"
00022 
00023 #include <ft2build.h>
00024 #include FT_FREETYPE_H
00025 
00026 class Filename;
00027 class PNMImage;
00028 class PNMTextGlyph;
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : PNMTextMaker
00032 // Description : This object uses the Freetype library to generate
00033 //               text directly into an image.  It is different from
00034 //               the TextNode/DynamicTextFont interface, which use the
00035 //               Freetype library to generate text in the scene graph,
00036 //               to be rendered onscreen via the Panda render
00037 //               traversal.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDA_PNMTEXT PNMTextMaker : public FreetypeFont {
00040 PUBLISHED:
00041   PNMTextMaker(const Filename &font_filename, int face_index);
00042   PNMTextMaker(const char *font_data, int data_length, int face_index);
00043   PNMTextMaker(const PNMTextMaker &copy);
00044   ~PNMTextMaker();
00045 
00046   enum Alignment {
00047     A_left,
00048     A_right,
00049     A_center,
00050   };
00051 
00052   INLINE bool is_valid() const;
00053 
00054   INLINE void set_align(Alignment align_type);
00055   INLINE Alignment get_align() const;
00056 
00057   INLINE void set_interior_flag(bool interior_flag);
00058   INLINE bool get_interior_flag() const;
00059 
00060   INLINE void set_fg(const LColor &fg);
00061   INLINE const LColor &get_fg() const;
00062 
00063   INLINE void set_interior(const LColor &interior);
00064   INLINE const LColor &get_interior() const;
00065 
00066   INLINE int generate_into(const string &text,
00067                            PNMImage &dest_image, int x, int y);
00068   int generate_into(const wstring &text,
00069                     PNMImage &dest_image, int x, int y);
00070   INLINE int calc_width(const string &text);
00071   int calc_width(const wstring &text);
00072 
00073   PNMTextGlyph *get_glyph(int character);
00074 
00075 private:
00076   void initialize();
00077   PNMTextGlyph *make_glyph(int glyph_index);
00078   void empty_cache();
00079 
00080   bool _is_valid;
00081 
00082   typedef pmap<int, PNMTextGlyph *> Glyphs;
00083   Glyphs _glyphs;
00084 
00085   Alignment _align;
00086   bool _interior_flag;
00087   LColor _fg;
00088   LColor _interior;
00089 };
00090 
00091 #include "pnmTextMaker.I"
00092 
00093 #endif
 All Classes Functions Variables Enumerations