Panda3D

Loading...
Searching...
No Matches
pnmTextMaker.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pnmTextMaker.h
10 * @author drose
11 * @date 2002-04-03
12 */
13
14#ifndef PNMTEXTMAKER_H
15#define PNMTEXTMAKER_H
16
17#include "pandabase.h"
18#include "pmap.h"
19#include "freetypeFont.h"
20#include "textEncoder.h"
21
22#include <ft2build.h>
23#include FT_FREETYPE_H
24
25 class Filename;
26 class PNMImage;
27 class PNMTextGlyph;
28
29/**
30 * This object uses the Freetype library to generate text directly into an
31 * image. It is different from the TextNode/DynamicTextFont interface, which
32 * use the Freetype library to generate text in the scene graph, to be
33 * rendered onscreen via the Panda render traversal.
34 */
35 class EXPCL_PANDA_PNMTEXT PNMTextMaker : public FreetypeFont {
36PUBLISHED:
37 explicit PNMTextMaker(const Filename &font_filename, int face_index);
38 explicit PNMTextMaker(const char *font_data, int data_length, int face_index);
39 explicit PNMTextMaker(const FreetypeFont &copy);
40 PNMTextMaker(const PNMTextMaker &copy);
41 ~PNMTextMaker();
42
43 enum Alignment {
44 A_left,
45 A_right,
46 A_center,
47 };
48
49 INLINE bool is_valid() const;
50
51 INLINE void set_align(Alignment align_type);
52 INLINE Alignment get_align() const;
53
54 INLINE void set_interior_flag(bool interior_flag);
55 INLINE bool get_interior_flag() const;
56
57 INLINE void set_fg(const LColor &fg);
58 INLINE const LColor &get_fg() const;
59
60 INLINE void set_interior(const LColor &interior);
61 INLINE const LColor &get_interior() const;
62
63 INLINE void set_distance_field_radius(int radius);
64 INLINE int get_distance_field_radius() const;
65
66 INLINE int generate_into(const std::string &text,
67 PNMImage &dest_image, int x, int y);
68 int generate_into(const std::wstring &text,
69 PNMImage &dest_image, int x, int y);
70 INLINE int calc_width(const std::string &text);
71 int calc_width(const std::wstring &text);
72
73 PNMTextGlyph *get_glyph(int character);
74
75 private:
76 void initialize();
77 PNMTextGlyph *make_glyph(int glyph_index);
78 void empty_cache();
79
80 bool _is_valid;
81
82 typedef pmap<int, PNMTextGlyph *> Glyphs;
83 Glyphs _glyphs;
84
85 Alignment _align;
86 bool _interior_flag;
87 LColor _fg;
88 LColor _interior;
89 int _distance_field_radius;
90};
91
92#include "pnmTextMaker.I"
93
94#endif
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
PNMImage
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition pnmImage.h:58
PNMTextGlyph
A single glyph in a PNMTextMaker.
Definition pnmTextGlyph.h:25
PNMTextMaker::PNMTextMaker
PNMTextMaker(const Filename &font_filename, int face_index)
The constructor expects the name of some font file that FreeType can read, along with face_index,...
Definition pnmTextMaker.cxx:29
PNMTextMaker::get_distance_field_radius
int get_distance_field_radius() const
Returns the radius previously set with set_distance_field_radius, or 0 otherwise.
Definition pnmTextMaker.I:116
PNMTextMaker::generate_into
int generate_into(const std::string &text, PNMImage &dest_image, int x, int y)
Generates a single line of text into the indicated image at the indicated position; the return value ...
Definition pnmTextMaker.I:125
PNMTextMaker::get_glyph
PNMTextGlyph * get_glyph(int character)
Returns the glyph for the indicated index, or NULL if it is not defined in the font.
Definition pnmTextMaker.cxx:140
PNMTextMaker::calc_width
int calc_width(const std::string &text)
Returns the width in pixels of the indicated line of text.
Definition pnmTextMaker.I:135
PNMTextMaker::set_fg
void set_fg(const LColor &fg)
Sets the foreground color of text that will be generated by future calls to generate_into().
Definition pnmTextMaker.I:70
PNMTextMaker::set_interior
void set_interior(const LColor &interior)
Sets the color that will be used to render the interior portions of hollow fonts in future calls to g...
Definition pnmTextMaker.I:89
PNMTextMaker::set_distance_field_radius
void set_distance_field_radius(int radius)
If this is set to something other than 0, Panda will generate a signed distance field with the given ...
Definition pnmTextMaker.I:107
PNMTextMaker::get_fg
const LColor & get_fg() const
Returns the foreground color of text that will be generated by future calls to generate_into().
Definition pnmTextMaker.I:79
PNMTextMaker::set_interior_flag
void set_interior_flag(bool interior_flag)
Sets the flag that indicates whether the interior of hollow fonts is identified as a preprocess as ea...
Definition pnmTextMaker.I:49
PNMTextMaker::is_valid
bool is_valid() const
Returns true if the PNMTextMaker is valid and ready to generate text, false otherwise.
Definition pnmTextMaker.I:19
PNMTextMaker::get_interior
const LColor & get_interior() const
Returns the color that will be used to render the interior portions of hollow fonts.
Definition pnmTextMaker.I:98
freetypeFont.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pnmTextMaker.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
textEncoder.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.