summaryrefslogtreecommitdiff
path: root/src/lib/evas/common
diff options
context:
space:
mode:
authorYoungbok Shin <youngb.shin@samsung.com>2015-03-19 19:02:02 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-03-19 19:02:03 +0900
commite197f8804f9a2bded1f7a0e5bccf5fb33c415d77 (patch)
tree72640ffb0fcc3b80a6addc7190bb7d503521cb31 /src/lib/evas/common
parent6616d11619796eb94755ac62f193dc4ec17c2b48 (diff)
evas: Support bitmap embedded color font.
Summary: Add the code for getting bitmap buffers from embedded color font, And draw the bitmap buffers as images. For drawing the bitmap buffers as images, evas_common_draw_context_font_ext_set internal API is changed to pass additional gl engine functions. T2139 @feature Test Plan: 1. Set a bitmap embedded color font to textblock. 2. Set a unicode emoticon text. 3. See the result. Please check the sample unicode in the following link. http://www.fileformat.info/info/unicode/char/1f3af/index.htm http://www.fileformat.info/info/unicode/char/1f555/index.htm http://www.fileformat.info/info/unicode/char/2600/index.htm http://www.fileformat.info/info/unicode/char/263a/index.htm Reviewers: tasn, woohyun, jpeg, raster Reviewed By: raster Subscribers: herdsman, cedric Differential Revision: https://phab.enlightenment.org/D2084
Diffstat (limited to 'src/lib/evas/common')
-rw-r--r--src/lib/evas/common/evas_draw.h5
-rw-r--r--src/lib/evas/common/evas_draw_main.c14
-rw-r--r--src/lib/evas/common/evas_font_draw.c135
-rw-r--r--src/lib/evas/common/evas_font_load.c9
-rw-r--r--src/lib/evas/common/evas_font_main.c37
5 files changed, 175 insertions, 25 deletions
diff --git a/src/lib/evas/common/evas_draw.h b/src/lib/evas/common/evas_draw.h
index 3f01a75..10cb26f 100644
--- a/src/lib/evas/common/evas_draw.h
+++ b/src/lib/evas/common/evas_draw.h
@@ -10,7 +10,10 @@ EAPI void evas_common_draw_context_font_ext_set (RGBA_D
10 void *data, 10 void *data,
11 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg), 11 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg),
12 void (*gl_free) (void *ext_dat), 12 void (*gl_free) (void *ext_dat),
13 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y)); 13 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y),
14 void *(*gl_image_new_from_data) (void *gc, unsigned int w, unsigned int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace),
15 void (*gl_image_free) (void *image),
16 void (*gl_image_draw) (void *gc, void *im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int smooth));
14EAPI void evas_common_draw_context_clip_clip (RGBA_Draw_Context *dc, int x, int y, int w, int h); 17EAPI void evas_common_draw_context_clip_clip (RGBA_Draw_Context *dc, int x, int y, int w, int h);
15EAPI void evas_common_draw_context_set_clip (RGBA_Draw_Context *dc, int x, int y, int w, int h); 18EAPI void evas_common_draw_context_set_clip (RGBA_Draw_Context *dc, int x, int y, int w, int h);
16EAPI void evas_common_draw_context_unset_clip (RGBA_Draw_Context *dc); 19EAPI void evas_common_draw_context_unset_clip (RGBA_Draw_Context *dc);
diff --git a/src/lib/evas/common/evas_draw_main.c b/src/lib/evas/common/evas_draw_main.c
index 27541bb..01ba20c 100644
--- a/src/lib/evas/common/evas_draw_main.c
+++ b/src/lib/evas/common/evas_draw_main.c
@@ -108,15 +108,21 @@ evas_common_draw_context_clear_cutouts(RGBA_Draw_Context *dc)
108 108
109EAPI void 109EAPI void
110evas_common_draw_context_font_ext_set(RGBA_Draw_Context *dc, 110evas_common_draw_context_font_ext_set(RGBA_Draw_Context *dc,
111 void *data, 111 void *data,
112 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg), 112 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg),
113 void (*gl_free) (void *ext_dat), 113 void (*gl_free) (void *ext_dat),
114 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y)) 114 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y),
115 void *(*gl_image_new_from_data) (void *gc, unsigned int w, unsigned int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace),
116 void (*gl_image_free) (void *image),
117 void (*gl_image_draw) (void *gc, void *im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int smooth))
115{ 118{
116 dc->font_ext.data = data; 119 dc->font_ext.data = data;
117 dc->font_ext.func.gl_new = gl_new; 120 dc->font_ext.func.gl_new = gl_new;
118 dc->font_ext.func.gl_free = gl_free; 121 dc->font_ext.func.gl_free = gl_free;
119 dc->font_ext.func.gl_draw = gl_draw; 122 dc->font_ext.func.gl_draw = gl_draw;
123 dc->font_ext.func.gl_image_new_from_data = gl_image_new_from_data;
124 dc->font_ext.func.gl_image_free = gl_image_free;
125 dc->font_ext.func.gl_image_draw = gl_image_draw;
120} 126}
121 127
122EAPI void 128EAPI void
diff --git a/src/lib/evas/common/evas_font_draw.c b/src/lib/evas/common/evas_font_draw.c
index b243667..367b8cd 100644
--- a/src/lib/evas/common/evas_font_draw.c
+++ b/src/lib/evas/common/evas_font_draw.c
@@ -23,6 +23,72 @@ evas_common_font_draw_init(void)
23{ 23{
24} 24}
25 25
26static void *
27_software_generic_image_new_from_data(int w, int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace)
28{
29#ifdef EVAS_CSERVE2
30 if (evas_cserve2_use_get())
31 {
32 Evas_Cache2 *cache = evas_common_image_cache2_get();
33 return evas_cache2_image_data(cache, w, h, image_data, alpha, cspace);
34 }
35#endif
36 return evas_cache_image_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
37}
38
39static void
40_software_generic_image_free(void *image)
41{
42#ifdef EVAS_CSERVE2
43 if (evas_cserve2_use_get() && evas_cache2_image_cached(image))
44 {
45 evas_cache2_image_close(image);
46 return;
47 }
48#endif
49 evas_cache_image_drop(image);
50}
51
52static void
53_software_generic_image_draw(void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth)
54{
55 RGBA_Image *im;
56
57 if (!image) return;
58 im = image;
59
60#ifdef BUILD_PIPE_RENDER
61 if ((eina_cpu_count() > 1))
62 {
63#ifdef EVAS_CSERVE2
64 if (evas_cserve2_use_get())
65 evas_cache2_image_load_data(&im->cache_entry);
66#endif
67 evas_common_rgba_image_scalecache_prepare((Image_Entry *)(im),
68 surface, context, smooth,
69 src_x, src_y, src_w, src_h,
70 dst_x, dst_y, dst_w, dst_h);
71
72 evas_common_pipe_image_draw(im, surface, context, smooth,
73 src_x, src_y, src_w, src_h,
74 dst_x, dst_y, dst_w, dst_h);
75 }
76 else
77#endif
78 {
79 evas_common_rgba_image_scalecache_prepare
80 (&im->cache_entry, surface, context, smooth,
81 src_x, src_y, src_w, src_h,
82 dst_x, dst_y, dst_w, dst_h);
83 evas_common_rgba_image_scalecache_do
84 (&im->cache_entry, surface, context, smooth,
85 src_x, src_y, src_w, src_h,
86 dst_x, dst_y, dst_w, dst_h);
87
88 evas_common_cpu_end_opt();
89 }
90}
91
26/* 92/*
27 * BiDi handling: We receive the shaped string + other props from text_props, 93 * BiDi handling: We receive the shaped string + other props from text_props,
28 * we need to reorder it so we'll have the visual string (the way we draw) 94 * we need to reorder it so we'll have the visual string (the way we draw)
@@ -42,29 +108,80 @@ evas_common_font_rgba_draw(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y,
42 EINA_INARRAY_FOREACH(glyphs->array, glyph) 108 EINA_INARRAY_FOREACH(glyphs->array, glyph)
43 { 109 {
44 RGBA_Font_Glyph *fg; 110 RGBA_Font_Glyph *fg;
45 int chr_x, chr_y, w; 111 int chr_x, chr_y, w, h;
46 112
47 fg = glyph->fg; 113 fg = glyph->fg;
114 w = fg->glyph_out->bitmap.width;
115 h = fg->glyph_out->bitmap.rows;
116
48 if ((!fg->ext_dat) && (dc->font_ext.func.gl_new)) 117 if ((!fg->ext_dat) && (dc->font_ext.func.gl_new))
49 { 118 {
50 /* extension calls */ 119 /* extension calls */
51 fg->ext_dat = dc->font_ext.func.gl_new(dc->font_ext.data, fg); 120 fg->ext_dat = dc->font_ext.func.gl_new(dc->font_ext.data, fg);
52 fg->ext_dat_free = dc->font_ext.func.gl_free; 121 fg->ext_dat_free = dc->font_ext.func.gl_free;
53 } 122 }
54 w = fg->glyph_out->bitmap.width; 123
124 if ((!fg->ext_dat) && FT_HAS_COLOR(fg->fi->src->ft.face))
125 {
126 if (dc->font_ext.func.gl_image_new_from_data)
127 {
128 /* extension calls */
129 fg->ext_dat = dc->font_ext.func.gl_image_new_from_data(dc->font_ext.data,
130 (unsigned int)w, (unsigned int)h,
131 (DATA32 *)fg->glyph_out->bitmap.buffer,
132 EINA_TRUE,
133 EVAS_COLORSPACE_ARGB8888);
134 fg->ext_dat_free = dc->font_ext.func.gl_image_free;
135 }
136 else
137 {
138 fg->ext_dat = _software_generic_image_new_from_data(w, h,
139 (DATA32 *)fg->glyph_out->bitmap.buffer,
140 EINA_TRUE,
141 EVAS_COLORSPACE_ARGB8888);
142 fg->ext_dat_free = _software_generic_image_free;
143 }
144 }
145
55 chr_x = x + glyph->x; 146 chr_x = x + glyph->x;
56 chr_y = y + glyph->y; 147 chr_y = y + glyph->y;
57 if (chr_x < (ext_x + ext_w)) 148 if (chr_x < (ext_x + ext_w))
58 { 149 {
59 if ((w > 0) && ((chr_x + w) > ext_x)) 150 if ((w > 0) && ((chr_x + w) > ext_x))
60 { 151 {
61 if ((fg->ext_dat) && (dc->font_ext.func.gl_draw)) 152 if (fg->glyph_out->rle)
62 dc->font_ext.func.gl_draw(dc->font_ext.data, (void *)dst, 153 {
63 dc, fg, chr_x, y - (chr_y - y)); 154 if ((fg->ext_dat) && (dc->font_ext.func.gl_draw))
64 else if (fg->glyph_out->rle) 155 {
65 evas_common_font_glyph_draw(fg, dc, dst, im_w, 156 dc->font_ext.func.gl_draw(dc->font_ext.data, (void *)dst,
66 chr_x, y - (chr_y - y), 157 dc, fg, chr_x, y - (chr_y - y));
67 ext_x, ext_y, ext_w, ext_h); 158 }
159 else
160 {
161 evas_common_font_glyph_draw(fg, dc, dst, im_w,
162 chr_x, y - (chr_y - y),
163 ext_x, ext_y, ext_w, ext_h);
164 }
165 }
166 else if ((fg->ext_dat) && FT_HAS_COLOR(fg->fi->src->ft.face))
167 {
168 if (dc->font_ext.func.gl_image_draw)
169 {
170 dc->font_ext.func.gl_image_draw(dc->font_ext.data,
171 fg->ext_dat,
172 0, 0, w, h,
173 chr_x, y - (chr_y - y), w, h,
174 EINA_TRUE);
175 }
176 else
177 {
178 _software_generic_image_draw(dc, dst,
179 fg->ext_dat,
180 0, 0, w, h,
181 chr_x, y - (chr_y - y), w, h,
182 EINA_TRUE);
183 }
184 }
68 } 185 }
69 } 186 }
70 else 187 else
diff --git a/src/lib/evas/common/evas_font_load.c b/src/lib/evas/common/evas_font_load.c
index 92fdd24..041fe00 100644
--- a/src/lib/evas/common/evas_font_load.c
+++ b/src/lib/evas/common/evas_font_load.c
@@ -446,6 +446,7 @@ evas_common_font_int_load_complete(RGBA_Font_Int *fi)
446 int i, maxd = 0x7fffffff; 446 int i, maxd = 0x7fffffff;
447 int chosen_size = 0; 447 int chosen_size = 0;
448 int chosen_size2 = 0; 448 int chosen_size2 = 0;
449 FT_Int strike_index = 0;
449 450
450 for (i = 0; i < fi->src->ft.face->num_fixed_sizes; i++) 451 for (i = 0; i < fi->src->ft.face->num_fixed_sizes; i++)
451 { 452 {
@@ -459,12 +460,18 @@ evas_common_font_int_load_complete(RGBA_Font_Int *fi)
459 maxd = cd; 460 maxd = cd;
460 chosen_size = s; 461 chosen_size = s;
461 chosen_size2 = fi->src->ft.face->available_sizes[i].y_ppem; 462 chosen_size2 = fi->src->ft.face->available_sizes[i].y_ppem;
463 strike_index = (FT_Int)i;
462 if (maxd == 0) break; 464 if (maxd == 0) break;
463 } 465 }
464 } 466 }
465 fi->real_size = chosen_size; 467 fi->real_size = chosen_size;
466 FTLOCK(); 468 FTLOCK();
467 error = FT_Set_Pixel_Sizes(fi->src->ft.face, 0, fi->real_size); 469
470 if (FT_HAS_FIXED_SIZES(fi->src->ft.face))
471 error = FT_Select_Size(fi->src->ft.face, strike_index);
472 else
473 error = FT_Set_Pixel_Sizes(fi->src->ft.face, 0, fi->real_size);
474
468 FTUNLOCK(); 475 FTUNLOCK();
469 if (error) 476 if (error)
470 { 477 {
diff --git a/src/lib/evas/common/evas_font_main.c b/src/lib/evas/common/evas_font_main.c
index 97961d0..7562d28 100644
--- a/src/lib/evas/common/evas_font_main.c
+++ b/src/lib/evas/common/evas_font_main.c
@@ -371,6 +371,12 @@ _glyph_free(RGBA_Font_Glyph *fg)
371 371
372 if (fg->glyph_out) 372 if (fg->glyph_out)
373 { 373 {
374 if ((!fg->glyph_out->rle) && (!fg->glyph_out->bitmap.rle_alloc))
375 {
376 FT_BitmapGlyph fbg = (FT_BitmapGlyph)fg->glyph;
377 FT_Bitmap_Done(evas_ft_lib, &(fbg->bitmap));
378 }
379
374 if ((fg->glyph_out->rle) && (fg->glyph_out->bitmap.rle_alloc)) 380 if ((fg->glyph_out->rle) && (fg->glyph_out->bitmap.rle_alloc))
375 free(fg->glyph_out->rle); 381 free(fg->glyph_out->rle);
376 fg->glyph_out->rle = NULL; 382 fg->glyph_out->rle = NULL;
@@ -501,8 +507,10 @@ evas_common_font_int_cache_glyph_get(RGBA_Font_Int *fi, FT_UInt idx)
501 evas_common_font_int_reload(fi); 507 evas_common_font_int_reload(fi);
502 FTLOCK(); 508 FTLOCK();
503 error = FT_Load_Glyph(fi->src->ft.face, idx, 509 error = FT_Load_Glyph(fi->src->ft.face, idx,
504 FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP | 510 (FT_HAS_COLOR(fi->src->ft.face) ?
505 hintflags[fi->hinting]); 511 (FT_LOAD_COLOR | hintflags[fi->hinting]) :
512 (FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP | hintflags[fi->hinting])));
513
506 FTUNLOCK(); 514 FTUNLOCK();
507 if (error) 515 if (error)
508 { 516 {
@@ -617,16 +625,25 @@ evas_common_font_int_cache_glyph_render(RGBA_Font_Glyph *fg)
617 fi->usage += size; 625 fi->usage += size;
618 if (fi->inuse) evas_common_font_int_use_increase(size); 626 if (fi->inuse) evas_common_font_int_use_increase(size);
619 627
620 fg->glyph_out->rle = evas_common_font_glyph_compress 628 if (!FT_HAS_COLOR(fi->src->ft.face))
621 (fbg->bitmap.buffer, fbg->bitmap.num_grays, fbg->bitmap.pixel_mode, 629 {
622 fbg->bitmap.pitch, fbg->bitmap.width, fbg->bitmap.rows, 630 fg->glyph_out->rle = evas_common_font_glyph_compress
623 &(fg->glyph_out->rle_size)); 631 (fbg->bitmap.buffer, fbg->bitmap.num_grays, fbg->bitmap.pixel_mode,
632 fbg->bitmap.pitch, fbg->bitmap.width, fbg->bitmap.rows,
633 &(fg->glyph_out->rle_size));
634 fg->glyph_out->bitmap.rle_alloc = EINA_TRUE;
624 635
625 fg->glyph_out->bitmap.buffer = NULL; 636 fg->glyph_out->bitmap.buffer = NULL;
626 637
627 // this may be technically incorrect as we go and free a bitmap buffer 638 // this may be technically incorrect as we go and free a bitmap buffer
628 // behind the ftglyph's back... 639 // behind the ftglyph's back...
629 FT_Bitmap_Done(evas_ft_lib, &(fbg->bitmap)); 640 FT_Bitmap_Done(evas_ft_lib, &(fbg->bitmap));
641 }
642 else
643 {
644 fg->glyph_out->rle = NULL;
645 fg->glyph_out->bitmap.rle_alloc = EINA_FALSE;
646 }
630 647
631 return EINA_TRUE; 648 return EINA_TRUE;
632} 649}