9 #include <grass/config.h>
14 #ifdef HAVE_FT2BUILD_H
16 #include FT_FREETYPE_H
19 #include <grass/gis.h>
23 # define RpD ((2 * M_PI) / 360.)
24 # define D2R(d) (double)(d * RpD)
30 #ifdef HAVE_FT2BUILD_H
31 static int convert_str(
const char *,
const char *,
unsigned char **);
32 static void release_convert_str(
unsigned char *);
33 static void set_matrix(FT_Matrix *,
double);
34 static void draw_text(FT_Face, FT_Vector *, FT_Matrix *,
35 const unsigned char *,
int,
int);
36 static void draw_bitmap(FT_Bitmap *, FT_Int, FT_Int);
37 static void set_text_box(FT_Bitmap *, FT_Int, FT_Int);
40 static int fdont_draw = 0;
41 static int ft, fb, fl, fr;
43 static void draw_main(
int x,
int y,
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);
89 FT_Set_Char_Size(face, (
int)(text_size_x * 64),
90 (
int)(text_size_y * 64), 100, 100);
100 FT_Done_FreeType(library);
110 outlen = convert_str(charset,
string, &out);
113 set_matrix(&matrix,
D2R(text_rotation));
115 draw_text(face, &pen, &matrix, out, outlen, 0);
118 release_convert_str(out);
122 FT_Done_FreeType(library);
126 #ifdef HAVE_FT2BUILD_H
127 static void set_matrix(FT_Matrix * matrix,
double rotation)
130 matrix->xx = (FT_Fixed) (cos(rotation) * 0x10000);
131 matrix->xy = (FT_Fixed) (-sin(rotation) * 0x10000);
132 matrix->yx = (FT_Fixed) (sin(rotation) * 0x10000);
133 matrix->yy = (FT_Fixed) (cos(rotation) * 0x10000);
136 static int convert_str(
const char *from,
const char *in,
unsigned char **out)
139 const unsigned char *p1;
145 *out = G_calloc(1, res);
155 if ((cd = iconv_open(
"UCS-2BE", from)) < 0)
157 ret = iconv(cd, (
char **)&p1, &len, (
char **)&p2, &i);
163 for (i = 0; i <= len; i++)
166 p2[2 * i + 1] = p1[i];
174 static void release_convert_str(
unsigned char *out)
179 static void draw_text(FT_Face face, FT_Vector * pen, FT_Matrix * matrix,
180 const unsigned char *out,
int len,
int color)
184 FT_GlyphSlot slot = face->glyph;
187 for (i = 0; i < len; i += 2) {
188 ch = (out[i] << 8) | out[i + 1];
192 FT_Set_Transform(face, matrix, pen);
194 ans = FT_Load_Char(face, ch, FT_LOAD_NO_BITMAP);
197 ans = FT_Render_Glyph(face->glyph, ft_render_mode_normal);
202 draw_bitmap(&slot->bitmap, slot->bitmap_left,
205 set_text_box(&slot->bitmap, slot->bitmap_left,
209 pen->x += slot->advance.x;
210 pen->y += slot->advance.y;
214 static void set_text_box(FT_Bitmap * bitmap, FT_Int x, FT_Int y)
216 FT_Int xMax = x + bitmap->width;
217 FT_Int yMax = y + bitmap->rows;
219 if ((x == xMax) || (y == yMax))
231 static void draw_bitmap(FT_Bitmap * bitmap, FT_Int x, FT_Int y)
233 static unsigned char *
buf;
236 int bw = bitmap->width;
237 int bh = bitmap->rows;
238 const unsigned char *sbuf = bitmap->buffer;
240 double x1, y1, x2, y2;
244 x2 = x1 + (double)bw;
245 y2 = y1 + (double)bh;
249 if (w <= 0 || h <= 0)
252 offset = ((
int)y1 - y) * bw + (
int)x1 - x;
254 if (nalloc < w * h) {
256 buf = G_realloc(buf, nalloc);
259 for (j = 0; j <
h; j++)
260 for (i = 0; i <
w; i++)
261 buf[j * w + i] = sbuf[offset + j * bw + i];
269 double text_size_x,
double text_size_y,
270 double text_rotation,
const char *
string)
274 draw_main(x, y, text_size_x, text_size_y, text_rotation,
string);
278 double text_size_x,
double text_size_y,
279 double text_rotation,
const char *
string)
290 draw_main(0, y, text_size_x, text_size_y, text_rotation,
string);
void G_free(void *buf)
Free allocated memory.
void COM_Move_abs(int, int)
void get_text_ext_freetype(int *, int *, int *, int *)
void DRV_draw_bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
const char * font_get_charset(void)
const char * font_get_freetype_name(void)
void soft_text_freetype(int, int, double, double, double, const char *)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
void soft_text_ext_freetype(int, int, double, double, double, const char *)
tuple h
panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size")) panel...