14 #ifdef HAVE_FT2BUILD_H
16 #include FT_FREETYPE_H
34 #ifdef HAVE_FT2BUILD_H
35 static int convert_str(
const char *,
const char *,
unsigned char **);
36 static void release_convert_str(
unsigned char *);
37 static void set_matrix(FT_Matrix *);
38 static void draw_text(FT_Face, FT_Vector *, FT_Matrix *,
const unsigned char *,
40 static void draw_bitmap(FT_Bitmap *, FT_Int, FT_Int);
41 static void set_text_box(FT_Bitmap *, FT_Int, FT_Int,
struct rectangle *);
44 static void draw_main(
double x,
double y,
const char *
string,
47 #ifdef HAVE_FT2BUILD_H
67 ans = FT_Init_FreeType(&library);
72 ans = FT_New_Face(library, filename, font_index, &face);
73 if (ans == FT_Err_Unknown_File_Format) {
75 FT_Done_FreeType(library);
80 FT_Done_FreeType(library);
88 ans = FT_Set_Char_Size(face, (
int)(
text_size_x * 64),
94 FT_Done_FreeType(library);
104 outlen = convert_str(encoding,
string, &out);
109 draw_text(face, &pen, &matrix, out, outlen, 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,
struct rectangle *box)
179 FT_GlyphSlot slot = face->glyph;
182 for (i = 0; i < len; i += 2) {
183 ch = (out[i] << 8) | out[i + 1];
187 FT_Set_Transform(face, matrix, pen);
189 ans = FT_Load_Char(face, ch, FT_LOAD_NO_BITMAP);
192 ans = FT_Render_Glyph(face->glyph, ft_render_mode_normal);
197 draw_bitmap(&slot->bitmap, slot->bitmap_left,
200 set_text_box(&slot->bitmap, slot->bitmap_left,
204 pen->x += slot->advance.x;
205 pen->y += slot->advance.y;
209 static void set_text_box(FT_Bitmap *bitmap, FT_Int
x, FT_Int y,
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];
270 double *left,
double *rite)
void G_free(void *)
Free allocated memory.
void COM_Bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
void COM_Pos_abs(double, double)
const char * font_get_encoding(void)
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)