31 _is_valid = load_font(font_filename, face_index);
39 PNMTextMaker(
const char *font_data,
int data_length,
int face_index) {
41 _is_valid = load_font(font_data, data_length, face_index);
50 _is_valid(copy._is_valid),
52 _interior_flag(copy._interior_flag),
54 _interior(copy._interior),
55 _distance_field_radius(copy._distance_field_radius)
105 wstring::const_iterator ti;
106 for (ti = text.begin(); ti != text.end(); ++ti) {
109 if (_interior_flag) {
110 glyph->
place(dest_image, xp, yp, _fg, _interior);
112 glyph->
place(dest_image, xp, yp, _fg);
126 wstring::const_iterator ti;
127 for (ti = text.begin(); ti != text.end(); ++ti) {
141 FT_Face face = acquire_face();
142 int glyph_index = FT_Get_Char_Index(face, character);
146 gi = _glyphs.find(glyph_index);
147 if (gi != _glyphs.end()) {
152 _glyphs.insert(Glyphs::value_type(glyph_index, glyph));
162 _interior_flag =
false;
163 _fg.set(0.0f, 0.0f, 0.0f, 1.0f);
164 _interior.set(0.5f, 0.5f, 0.5f, 1.0f);
165 _distance_field_radius = 0;
172 make_glyph(
int glyph_index) {
173 FT_Face face = acquire_face();
174 if (!load_glyph(face, glyph_index)) {
179 FT_GlyphSlot slot = face->glyph;
181 FT_Bitmap &bitmap = slot->bitmap;
183 double advance = slot->advance.x / 64.0;
187 if (bitmap.width == 0 || bitmap.rows == 0) {
189 glyph->rescale(_scale_factor);
192 PNMImage &glyph_image = glyph->_image;
194 if (_distance_field_radius != 0) {
196 decompose_outline(slot->outline);
198 PN_stdfloat tex_x_size, tex_y_size, tex_x_orig, tex_y_orig;
204 FT_Outline_Get_CBox(&slot->outline, &bounds);
206 bounds.xMin = bounds.xMin & ~63;
207 bounds.yMin = bounds.yMin & ~63;
208 bounds.xMax = (bounds.xMax + 63) & ~63;
209 bounds.yMax = (bounds.yMax + 63) & ~63;
211 tex_x_size = (bounds.xMax - bounds.xMin) >> 6;
212 tex_y_size = (bounds.yMax - bounds.yMin) >> 6;
213 tex_x_orig = (bounds.xMin >> 6);
214 tex_y_orig = (bounds.yMax >> 6);
216 if (tex_x_size == 0 || tex_y_size == 0) {
221 int int_x_size = (int)ceil(tex_x_size);
222 int int_y_size = (int)ceil(tex_y_size);
224 outline = _distance_field_radius;
225 int_x_size += outline * 2;
226 int_y_size += outline * 2;
228 glyph_image.
clear(int_x_size, int_y_size, 1);
229 render_distance_field(glyph_image, outline, bounds.xMin, bounds.yMin);
231 glyph->_top = tex_y_orig + outline * _scale_factor;
232 glyph->_left = tex_x_orig + outline * _scale_factor;
236 glyph_image.
clear(bitmap.width, bitmap.rows, 3);
237 copy_bitmap_to_pnmimage(bitmap, glyph_image);
239 glyph->_top = slot->bitmap_top;
240 glyph->_left = slot->bitmap_left;
242 if (_interior_flag) {
243 glyph->determine_interior();
247 glyph->rescale(_scale_factor);
260 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_advance() const
Returns the number of pixels by which the pen should be advanced after rendering this glyph.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
This object uses the Freetype library to generate text directly into an image.
void place(PNMImage &dest_image, int xp, int yp, const LColor &fg)
Copies the glyph to the indicated destination image at the indicated origin.
The name of a file, such as a texture file or an Egg file.
int calc_width(const std::string &text)
Returns the width in pixels of the indicated line of text.
void clear()
Frees all memory allocated for the image, and clears all its parameters (size, color,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A single glyph in a PNMTextMaker.
PNMTextGlyph * get_glyph(int character)
Returns the glyph for the indicated index, or NULL if it is not defined in the font.