14 #ifndef DYNAMICTEXTFONT_H
15 #define DYNAMICTEXTFONT_H
30 #include FT_FREETYPE_H
34 typedef struct hb_font_t hb_font_t;
41 class EXPCL_PANDA_TEXT DynamicTextFont :
public TextFont,
public FreetypeFont {
43 DynamicTextFont(
const Filename &font_filename,
int face_index = 0);
44 DynamicTextFont(
const char *font_data,
int data_length,
int face_index);
45 DynamicTextFont(
const DynamicTextFont ©);
46 virtual ~DynamicTextFont();
48 virtual PT(
TextFont) make_copy()
const;
50 INLINE
const std::string &get_name()
const;
52 INLINE
bool set_point_size(PN_stdfloat point_size);
53 INLINE PN_stdfloat get_point_size()
const;
54 MAKE_PROPERTY(point_size, get_point_size, set_point_size);
56 INLINE
bool set_pixels_per_unit(PN_stdfloat pixels_per_unit);
57 INLINE PN_stdfloat get_pixels_per_unit()
const;
58 MAKE_PROPERTY(pixels_per_unit, get_pixels_per_unit, set_pixels_per_unit);
60 INLINE
bool set_scale_factor(PN_stdfloat scale_factor);
61 INLINE PN_stdfloat get_scale_factor()
const;
62 MAKE_PROPERTY(scale_factor, get_scale_factor, set_scale_factor);
64 INLINE
void set_native_antialias(
bool native_antialias);
65 INLINE
bool get_native_antialias()
const;
66 MAKE_PROPERTY(native_antialias, get_native_antialias, set_native_antialias);
68 INLINE
int get_font_pixel_size()
const;
69 MAKE_PROPERTY(font_pixel_size, get_font_pixel_size);
74 INLINE
void set_texture_margin(
int texture_margin);
75 INLINE
int get_texture_margin()
const;
76 INLINE
void set_poly_margin(PN_stdfloat poly_margin);
77 INLINE PN_stdfloat get_poly_margin()
const;
78 MAKE_PROPERTY(texture_margin, get_texture_margin, set_texture_margin);
79 MAKE_PROPERTY(poly_margin, get_poly_margin, set_poly_margin);
81 INLINE
void set_page_size(
const LVecBase2i &page_size);
82 INLINE
void set_page_size(
int x_size,
int y_size);
83 INLINE
const LVecBase2i &get_page_size()
const;
84 INLINE
int get_page_x_size()
const;
85 INLINE
int get_page_y_size()
const;
86 MAKE_PROPERTY(page_size, get_page_size, set_page_size);
88 INLINE
void set_minfilter(SamplerState::FilterType filter);
89 INLINE SamplerState::FilterType get_minfilter()
const;
90 INLINE
void set_magfilter(SamplerState::FilterType filter);
91 INLINE SamplerState::FilterType get_magfilter()
const;
92 INLINE
void set_anisotropic_degree(
int anisotropic_degree);
93 INLINE
int get_anisotropic_degree()
const;
94 MAKE_PROPERTY(minfilter, get_minfilter, set_minfilter);
95 MAKE_PROPERTY(magfilter, get_magfilter, set_magfilter);
96 MAKE_PROPERTY(anisotropic_degree, get_anisotropic_degree, set_anisotropic_degree);
98 INLINE
void set_render_mode(RenderMode render_mode);
99 INLINE RenderMode get_render_mode()
const;
100 MAKE_PROPERTY(render_mode, get_render_mode, set_render_mode);
102 INLINE
void set_fg(
const LColor &fg);
103 INLINE
const LColor &get_fg()
const;
104 INLINE
void set_bg(
const LColor &bg);
105 INLINE
const LColor &get_bg()
const;
106 INLINE
void set_outline(
const LColor &outline_color, PN_stdfloat outline_width,
107 PN_stdfloat outline_feather);
108 INLINE
const LColor &get_outline_color()
const;
109 INLINE PN_stdfloat get_outline_width()
const;
110 INLINE PN_stdfloat get_outline_feather()
const;
111 INLINE Texture::Format get_tex_format()
const;
112 MAKE_PROPERTY(fg, get_fg, set_fg);
113 MAKE_PROPERTY(bg, get_bg, set_bg);
114 MAKE_PROPERTY(tex_format, get_tex_format);
116 int get_num_pages()
const;
117 DynamicTextPage *get_page(
int n)
const;
118 MAKE_SEQ(get_pages, get_num_pages, get_page);
119 MAKE_SEQ_PROPERTY(pages, get_num_pages, get_page);
121 int garbage_collect();
124 virtual void write(std::ostream &out,
int indent_level)
const;
127 virtual bool get_glyph(
int character, CPT(
TextGlyph) &glyph);
128 virtual PN_stdfloat
get_kerning(
int first,
int second)
const;
130 bool get_glyph_by_index(
int character,
int glyph_index, CPT(
TextGlyph) &glyph);
131 hb_font_t *get_hb_font()
const;
135 void update_filters();
136 void determine_tex_format();
137 CPT(
TextGlyph) make_glyph(
int character, FT_Face face,
int glyph_index);
138 void copy_bitmap_to_texture(
const FT_Bitmap &bitmap, DynamicTextGlyph *glyph);
139 void copy_pnmimage_to_texture(
const PNMImage &image, DynamicTextGlyph *glyph);
140 void blend_pnmimage_to_texture(
const PNMImage &image, DynamicTextGlyph *glyph,
142 DynamicTextGlyph *slot_glyph(
int character,
int x_size,
int y_size, PN_stdfloat advance);
144 void render_wireframe_contours(
TextGlyph *glyph);
145 void render_polygon_contours(
TextGlyph *glyph,
bool face,
bool extrude);
148 PN_stdfloat _poly_margin;
149 LVecBase2i _page_size;
151 SamplerState::FilterType _minfilter;
152 SamplerState::FilterType _magfilter;
153 int _anisotropic_degree;
155 RenderMode _render_mode;
157 LColor _fg, _bg, _outline_color;
158 PN_stdfloat _outline_width;
159 PN_stdfloat _outline_feather;
161 Texture::Format _tex_format;
162 bool _needs_image_processing;
164 typedef pvector< PT(DynamicTextPage) > Pages;
177 EmptyGlyphs _empty_glyphs;
179 mutable hb_font_t *_hb_font;
185 static void init_type() {
186 TextFont::init_type();
188 TextFont::get_class_type());
191 return get_class_type();
193 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
201 INLINE std::ostream &operator << (std::ostream &out,
const DynamicTextFont &dtf);
205 #endif // HAVE_FREETYPE