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) {