14 #ifdef HAVE_FT2BUILD_H 16 #include FT_FREETYPE_H 32 #ifdef HAVE_FT2BUILD_H 33 static int convert_str(
const char *,
const char *,
unsigned char **);
34 static void release_convert_str(
unsigned char *);
35 static void set_matrix(FT_Matrix *);
36 static void draw_text(FT_Face, FT_Vector *, FT_Matrix *,
37 const unsigned char *,
int,
int,
struct rectangle *);
38 static void draw_bitmap(FT_Bitmap *, FT_Int, FT_Int);
39 static void set_text_box(FT_Bitmap *, FT_Int, FT_Int,
struct rectangle *);
42 static void draw_main(
double x,
double y,
const char *
string,
45 #ifdef HAVE_FT2BUILD_H 65 ans = FT_Init_FreeType(&library);
70 ans = FT_New_Face(library, filename, font_index, &face);
71 if (ans == FT_Err_Unknown_File_Format) {
73 FT_Done_FreeType(library);
78 FT_Done_FreeType(library);
86 ans = FT_Set_Char_Size(face,
94 FT_Done_FreeType(library);
104 outlen = convert_str(encoding,
string, &out);
109 draw_text(face, &pen, &matrix, out, outlen, 0, box);
112 release_convert_str(out);
116 FT_Done_FreeType(library);
120 #ifdef HAVE_FT2BUILD_H 121 static void set_matrix(FT_Matrix * matrix)
130 static int convert_str(
const char *from,
const char *in,
unsigned char **out)
133 const unsigned char *p1;
140 p1 = (
const unsigned char *)in;
148 cd = iconv_open(
"UCS-2BE", from);
149 if (cd == (iconv_t) -1)
151 if (iconv(cd, (
char **)&p1, &len, (
char **)&p2, &i) == (
size_t) -1)
158 for (i = 0; i <= len; i++)
161 p2[2 * i + 1] = p1[i];
169 static void release_convert_str(
unsigned char *out)
174 static void draw_text(FT_Face face, FT_Vector * pen, FT_Matrix * matrix,
175 const unsigned char *out,
int len,
int color,
180 FT_GlyphSlot slot = face->glyph;
183 for (i = 0; i < len; i += 2) {
184 ch = (out[i] << 8) | out[i + 1];
188 FT_Set_Transform(face, matrix, pen);
190 ans = FT_Load_Char(face, ch, FT_LOAD_NO_BITMAP);
193 ans = FT_Render_Glyph(face->glyph, ft_render_mode_normal);
198 draw_bitmap(&slot->bitmap, slot->bitmap_left,
201 set_text_box(&slot->bitmap, slot->bitmap_left,
205 pen->x += slot->advance.x;
206 pen->y += slot->advance.y;
210 static void set_text_box(FT_Bitmap *bitmap, FT_Int x, FT_Int y,
struct rectangle *box)
212 FT_Int xMax = x + bitmap->width;
213 FT_Int yMax = y + bitmap->rows;
215 if ((x == xMax) || (y == yMax))
227 static void draw_bitmap(FT_Bitmap * bitmap, FT_Int x, FT_Int y)
229 static unsigned char *buf;
232 int bw = bitmap->width;
233 int bh = bitmap->rows;
234 const unsigned char *sbuf = bitmap->buffer;
236 double x1, y1, x2, y2;
245 if (w <= 0 || h <= 0)
248 offset = ((int)y1 - y) * bw + (int)x1 - x;
250 if (nalloc < w * h) {
255 for (j = 0; j < h; j++)
256 for (i = 0; i < w; i++)
257 buf[j * w + i] = sbuf[offset + j * bw + i];
const char * font_get_encoding(void)
void COM_Bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
void G_free(void *)
Free allocated memory.
const char * font_get_freetype_name(void)
void soft_text_freetype(const char *string)
void get_text_ext_freetype(const char *string, double *top, double *bot, double *left, double *rite)
void COM_Pos_abs(double, double)