Panda3D

Loading...
Searching...
No Matches
freetypeFont.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 freetypeFont.h
10 * @author drose
11 * @date 2003-09-07
12 */
13
14#ifndef FREETYPEFONT_H
15#define FREETYPEFONT_H
16
17#include "pandabase.h"
18
19#ifdef HAVE_FREETYPE
20
21#include "config_pnmtext.h"
22#include "filename.h"
23#include "pvector.h"
24#include "pmap.h"
25#include "pnmImage.h"
26#include "namable.h"
27#include "freetypeFace.h"
28
29#include <ft2build.h>
30#include FT_FREETYPE_H
31
32 class NurbsCurveResult;
33
34/**
35 * This is a common base class for both DynamicTextFont and PNMTextMaker.
36 * Both of these are utility classes that use the FreeType library to generate
37 * glyphs from fonts; this class abstracts out that common wrapper around
38 * FreeType.
39 */
40 class EXPCL_PANDA_PNMTEXT FreetypeFont : public Namable {
41 protected:
42 FreetypeFont();
43 FreetypeFont(const FreetypeFont &copy);
44
45 bool load_font(const Filename &font_filename, int face_index);
46 bool load_font(const char *font_data, int data_length, int face_index);
47 void unload_font();
48
49PUBLISHED:
50 INLINE ~FreetypeFont();
51
52 enum WindingOrder {
53 WO_default,
54 WO_left,
55 WO_right,
56
57 WO_invalid,
58 };
59
60 INLINE bool set_point_size(PN_stdfloat point_size);
61 INLINE PN_stdfloat get_point_size() const;
62
63 INLINE bool set_pixels_per_unit(PN_stdfloat pixels_per_unit);
64 INLINE PN_stdfloat get_pixels_per_unit() const;
65
66 INLINE bool set_pixel_size(PN_stdfloat pixel_size);
67 INLINE PN_stdfloat get_pixel_size() const;
68
69 INLINE bool set_scale_factor(PN_stdfloat scale_factor);
70 INLINE PN_stdfloat get_scale_factor() const;
71
72 INLINE void set_native_antialias(bool native_antialias);
73 INLINE bool get_native_antialias() const;
74
75 INLINE int get_font_pixel_size() const;
76
77 INLINE PN_stdfloat get_line_height() const;
78 INLINE PN_stdfloat get_space_advance() const;
79
80 INLINE static PN_stdfloat get_points_per_unit();
81 INLINE static PN_stdfloat get_points_per_inch();
82
83 INLINE void set_winding_order(WindingOrder winding_order);
84 INLINE WindingOrder get_winding_order() const;
85 MAKE_PROPERTY(winding_order, get_winding_order, set_winding_order);
86
87 public:
88 static WindingOrder string_winding_order(const std::string &string);
89
90 protected:
91 INLINE FT_Face acquire_face() const;
92 INLINE void release_face(FT_Face face) const;
93
94 bool load_glyph(FT_Face face, int glyph_index, bool prerender = true);
95 void copy_bitmap_to_pnmimage(const FT_Bitmap &bitmap, PNMImage &image);
96 void render_distance_field(PNMImage &image, int radius, int min_x, int min_y);
97
98 void decompose_outline(FT_Outline &outline);
99
100 private:
101 bool reset_scale();
102
103 static int outline_move_to(const FT_Vector *to, void *user);
104 static int outline_line_to(const FT_Vector *to, void *user);
105 static int outline_conic_to(const FT_Vector *control,
106 const FT_Vector *to, void *user);
107 static int outline_cubic_to(const FT_Vector *control1,
108 const FT_Vector *control2,
109 const FT_Vector *to, void *user);
110 int outline_nurbs(NurbsCurveResult *ncr);
111
112 protected:
113 PN_stdfloat _point_size;
114 PN_stdfloat _requested_pixels_per_unit;
115 PN_stdfloat _tex_pixels_per_unit;
116 PN_stdfloat _requested_scale_factor;
117 PN_stdfloat _scale_factor;
118 bool _native_antialias;
119 PN_stdfloat _font_pixels_per_unit;
120 WindingOrder _winding_order;
121
122 int _font_pixel_size;
123 PN_stdfloat _line_height;
124 PN_stdfloat _space_advance;
125
126 PT(FreetypeFace) _face;
127 int _char_size;
128 int _dpi;
129 int _pixel_width;
130 int _pixel_height;
131
132 class ContourPoint {
133 public:
134 INLINE ContourPoint(const LPoint2 &p, const LVector2 &in,
135 const LVector2 &out);
136 INLINE ContourPoint(PN_stdfloat px, PN_stdfloat py, PN_stdfloat tx, PN_stdfloat ty);
137 INLINE void connect_to(const LVector2 &out);
138 LPoint2 _p;
139 LVector2 _in, _out; // tangents into and out of the vertex.
140
141 // Circular arc approximation of the curve from previous point. If radius
142 // is 0, this is a straight line.
143 LPoint2 _center;
144 PN_stdfloat _radius;
145 };
146 typedef pvector<ContourPoint> Points;
147
148 class Contour {
149 public:
150 Points _points;
151 bool _is_solid;
152 int _start_vertex;
153 };
154
155 typedef pvector<Contour> Contours;
156 Contours _contours;
157 LPoint2 _q; // The "current point".
158
159 protected:
160 static const PN_stdfloat _points_per_unit;
161 static const PN_stdfloat _points_per_inch;
162};
163
164#include "freetypeFont.I"
165
166EXPCL_PANDA_PNMTEXT std::ostream &operator << (std::ostream &out, FreetypeFont::WindingOrder wo);
167EXPCL_PANDA_PNMTEXT std::istream &operator >> (std::istream &in, FreetypeFont::WindingOrder &wo);
168
169#endif // HAVE_FREETYPE
170
171#endif
Namable
A base class for all things which can have a name.
Definition namable.h:26
NurbsCurveResult
The result of a NurbsCurveEvaluator.
Definition nurbsCurveResult.h:35
config_pnmtext.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
freetypeFace.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
freetypeFont.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
namable.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.
pnmImage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.