14 #include "pnmTextMaker.h"
15 #include "pnmTextGlyph.h"
30 _is_valid = load_font(font_filename, face_index);
41 PNMTextMaker(
const char *font_data,
int data_length,
int face_index) {
43 _is_valid = load_font(font_data, data_length, face_index);
54 _is_valid(copy._is_valid),
56 _interior_flag(copy._interior_flag),
58 _interior(copy._interior)
106 xp = x - (width / 2);
115 wstring::const_iterator ti;
116 for (ti = text.begin(); ti != text.end(); ++ti) {
119 if (_interior_flag) {
120 glyph->
place(dest_image, xp, yp, _fg, _interior);
122 glyph->
place(dest_image, xp, yp, _fg);
139 wstring::const_iterator ti;
140 for (ti = text.begin(); ti != text.end(); ++ti) {
156 FT_Face face = acquire_face();
157 int glyph_index = FT_Get_Char_Index(face, character);
161 gi = _glyphs.find(glyph_index);
162 if (gi != _glyphs.end()) {
167 _glyphs.insert(Glyphs::value_type(glyph_index, glyph));
180 _interior_flag =
false;
181 _fg.set(0.0f, 0.0f, 0.0f, 1.0f);
182 _interior.set(0.5f, 0.5f, 0.5f, 1.0f);
192 make_glyph(
int glyph_index) {
193 FT_Face face = acquire_face();
194 if (!load_glyph(face, glyph_index)) {
199 FT_GlyphSlot slot = face->glyph;
201 FT_Bitmap &bitmap = slot->bitmap;
203 double advance = slot->advance.x / 64.0;
207 if (bitmap.width == 0 || bitmap.rows == 0) {
209 glyph->rescale(_scale_factor);
212 PNMImage &glyph_image = glyph->_image;
213 glyph_image.
clear(bitmap.width, bitmap.rows, 3);
214 copy_bitmap_to_pnmimage(bitmap, glyph_image);
216 glyph->_top = slot->bitmap_top;
217 glyph->_left = slot->bitmap_left;
219 if (_interior_flag) {
220 glyph->determine_interior();
222 glyph->rescale(_scale_factor);
237 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
int calc_width(const string &text)
Returns the width in pixels of the indicated line of text.
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...
This object uses the Freetype library to generate text directly into an image.
int generate_into(const 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 ...
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 get_advance() const
Returns the number of pixels by which the pen should be advanced after rendering this glyph...
void clear()
Frees all memory allocated for the image, and clears all its parameters (size, color, type, etc).
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.