Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/lib/engines/common


Modified Files:
        evas_font_draw.c evas_font_load.c evas_font_main.c 
        evas_font_query.c 


Log Message:


added in loading froms from memory buffers at the engine level, and now an
api to set a font "source" (blank is normal filing system) but the source can
be a device or file etc. in this case it currently supports eet files as the
source and then the font name is used as a key in th eet file as to where to
find the font - edb support would be trivial to add. :) if the font is not
found in the "source" it falls back to the font path etc.

===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_draw.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- evas_font_draw.c    15 Jan 2004 14:58:03 -0000      1.8
+++ evas_font_draw.c    23 Jan 2004 02:13:37 -0000      1.9
@@ -17,14 +17,14 @@
    fg = evas_hash_find(fn->glyphs, key);
    if (fg) return fg;
    
-   error = FT_Load_Glyph(fn->ft.face, index, FT_LOAD_NO_BITMAP);
+   error = FT_Load_Glyph(fn->src->ft.face, index, FT_LOAD_NO_BITMAP);
    if (error) return NULL;
    
    fg = malloc(sizeof(struct _RGBA_Font_Glyph));
    if (!fg) return NULL;
    memset(fg, 0, (sizeof(struct _RGBA_Font_Glyph)));
    
-   error = FT_Get_Glyph(fn->ft.face->glyph, &(fg->glyph));
+   error = FT_Get_Glyph(fn->src->ft.face->glyph, &(fg->glyph));
    if (error) 
      {
        free(fg);
@@ -90,7 +90,8 @@
    
    pen_x = x << 8;
    pen_y = y << 8;
-   use_kerning = FT_HAS_KERNING(fn->ft.face);
+   evas_common_font_size_use(fn);
+   use_kerning = FT_HAS_KERNING(fn->src->ft.face);
    prev_index = 0;
    func = evas_common_draw_func_blend_alpha_get(dst);
    for (c = 0, chr = 0; text[chr];)
@@ -102,12 +103,12 @@
        
        gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
        if (gl == 0) break;
-       index = FT_Get_Char_Index(fn->ft.face, gl);
+       index = FT_Get_Char_Index(fn->src->ft.face, gl);
        if ((use_kerning) && (prev_index) && (index))
          {
             FT_Vector delta;
             
-            FT_Get_Kerning(fn->ft.face, prev_index, index,
+            FT_Get_Kerning(fn->src->ft.face, prev_index, index,
                            ft_kerning_default, &delta);
             pen_x += delta.x << 2;
          }
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_load.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- evas_font_load.c    15 Jan 2004 14:58:03 -0000      1.5
+++ evas_font_load.c    23 Jan 2004 02:13:38 -0000      1.6
@@ -4,94 +4,236 @@
 
 static int                font_cache_usage = 0;
 static int                font_cache = 0;
+static Evas_Object_List * fonts_src = NULL;
 static Evas_Object_List * fonts = NULL;
 
 static int font_modify_cache_cb(Evas_Hash *hash, const char *key, void *data, void 
*fdata);
 static int font_flush_free_glyph_cb(Evas_Hash *hash, const char *key, void *data, 
void *fdata);
 
-/* FIXME: */
-/* we should share face handles and have different ft sizes from the same */
-/* face (if applicable) */
+RGBA_Font_Source *
+evas_common_font_source_memory_load(const char *name, const void *data, int data_size)
+{
+   int error;
+   RGBA_Font_Source *fs;
+   
+   fs = malloc(sizeof(RGBA_Font_Source));
+   if (!fs) return NULL;
+   fs->name = strdup(name);
+   fs->file = NULL;
+   fs->data = malloc(data_size);
+   if (!fs->data)
+     {
+       if (fs->name) free(fs->name);
+       free(fs);
+       return NULL;
+     }
+   memcpy(fs->data, data, data_size);
+   fs->data_size = data_size;
+   error = FT_New_Memory_Face(evas_ft_lib, fs->data, fs->data_size, 0, 
&(fs->ft.face));
+   if (error)
+     {
+       if (fs->name) free(fs->name);
+       if (fs->data) free(fs->data);
+       free(fs);
+       return NULL;
+     }
+   
+   fs->references = 1;
+   
+   fonts_src = evas_object_list_prepend(fonts_src, fs);   
+   return fs;
+}
+
+RGBA_Font_Source *
+evas_common_font_source_load(const char *name)
+{
+   int error;
+   RGBA_Font_Source *fs;
+   
+   fs = malloc(sizeof(RGBA_Font_Source));
+   if (!fs) return NULL;
+   fs->name = strdup(name);
+   fs->file = strdup(name);
+   error = FT_New_Face(evas_ft_lib, fs->file, 0, &(fs->ft.face));
+   if (error)
+     {
+       if (fs->name) free(fs->name);
+       if (fs->file) free(fs->file);
+       free(fs);
+       return NULL;
+     }
+   
+   fs->references = 1;
+   
+   fonts_src = evas_object_list_prepend(fonts_src, fs);   
+   return fs;
+}
+
+RGBA_Font_Source *
+evas_common_font_source_find(const char *name)
+{
+   Evas_Object_List *l;
+   
+   if (!name) return NULL;
+   for (l = fonts_src; l; l = l->next)
+     {
+       RGBA_Font_Source *fs;
+       
+       fs = (RGBA_Font_Source *)l;
+       if ((fs->name) && (!strcmp(name, fs->name)))
+         {
+            fs->references++;       
+            fonts_src = evas_object_list_remove(fonts_src, fs);
+            fonts_src = evas_object_list_prepend(fonts_src, fs);            
+            return fs;
+         }
+     }
+   return NULL;
+}
+
+void
+evas_common_font_source_free(RGBA_Font_Source *fs)
+{
+   fs->references--;
+   if (fs->references > 0) return;
+   
+   fonts_src = evas_object_list_remove(fonts_src, fs);
+   if (fs->name) free(fs->name);
+   if (fs->file) free(fs->file);
+   if (fs->data) free(fs->data);
+   FT_Done_Face(fs->ft.face);
+   free(fs);
+}
+
+void
+evas_common_font_size_use(RGBA_Font *fn)
+{
+   if (fn->src->current_size == fn->real_size) return;
+   FT_Set_Char_Size(fn->src->ft.face, 0, fn->real_size, 96, 96);
+   fn->src->current_size = fn->real_size;
+}
+
+RGBA_Font *
+evas_common_font_memory_load(const char *name, int size, const void *data, int 
data_size)
+{
+   RGBA_Font *fn;
+
+   fn = evas_common_font_find(name, size);
+   if (fn) return fn;
+   
+   fn = malloc(sizeof(RGBA_Font));   
+   if (!fn) return NULL;
+   
+   fn->src = evas_common_font_source_find(name);
+   if (!fn->src) fn->src = evas_common_font_source_memory_load(name, data, data_size);
+
+   if (!fn->src)
+     {
+       free(fn);
+       return NULL;
+     }
+   
+   fn->size = size;
+
+   return evas_common_font_load_init(fn);
+}
 
 RGBA_Font *
 evas_common_font_load(const char *name, int size)
 {
-   int error;
    RGBA_Font *fn;
-   char *file;
 
    fn = evas_common_font_find(name, size);
    if (fn) return fn;
    
    fn = malloc(sizeof(RGBA_Font));   
-   file = (char *)name;
+   if (!fn) return NULL;
    
-   error = FT_New_Face(evas_ft_lib, file, 0, &(fn->ft.face));
-   if (error)
+   fn->src = evas_common_font_source_find(name);
+   if (!fn->src) fn->src = evas_common_font_source_load(name);
+
+   if (!fn->src)
      {
        free(fn);
        return NULL;
      }
-   error = FT_Set_Char_Size(fn->ft.face, 0, (size * 64), 96, 96);
+   
+   fn->size = size;
+
+   return evas_common_font_load_init(fn);
+}
+
+RGBA_Font *
+evas_common_font_load_init(RGBA_Font *fn)
+{
+   int error;
+   
+   fn->real_size = fn->size * 64;
+   error = FT_Set_Char_Size(fn->src->ft.face, 0, (fn->size * 64), 96, 96);
    if (error)
-     error = FT_Set_Pixel_Sizes(fn->ft.face, 0, size);
+     {
+       error = FT_Set_Pixel_Sizes(fn->src->ft.face, 0, fn->size);
+       fn->real_size = fn->size;
+     }
    if (error)
      {
        int i;
        int chosen_size = 0;
        int chosen_width = 0;
 
-       for (i = 0; i < fn->ft.face->num_fixed_sizes; i++)
+       for (i = 0; i < fn->src->ft.face->num_fixed_sizes; i++)
          {
             int s;
             int d, cd;
             
-            s = fn->ft.face->available_sizes[i].height;
-            cd = chosen_size - size;
+            s = fn->src->ft.face->available_sizes[i].height;
+            cd = chosen_size - fn->size;
             if (cd < 0) cd = -cd;
-            d = s - size;
+            d = s - fn->size;
             if (d < 0) d = -d;
             if (d < cd)
               {
-                 chosen_width = fn->ft.face->available_sizes[i].width;
+                 chosen_width = fn->src->ft.face->available_sizes[i].width;
                  chosen_size = s;
               }
             if (d == 0) break;
          }
-       error = FT_Set_Pixel_Sizes(fn->ft.face, chosen_width, chosen_size);
+       error = FT_Set_Pixel_Sizes(fn->src->ft.face, chosen_width, chosen_size);
        if (error)
          {
             /* couldn't choose the size anyway... what now? */
          }
+       fn->real_size = chosen_size;
      }
+   fn->src->current_size = fn->real_size;
 
 #if 0 /* debugging to look at charmaps in a ttf */
-   printf("%i\n", fn->ft.face->num_charmaps);
+   printf("%i\n", fn->src->ft.face->num_charmaps);
      {
        int i;
        
-       for (i = 0; i < fn->ft.face->num_charmaps; i++)
+       for (i = 0; i < fn->src->ft.face->num_charmaps; i++)
          {
             printf("%i: %x, %c\n", 
-                   i, fn->ft.face->charmaps[i]->encoding,
-                   fn->ft.face->charmaps[i]->encoding);
+                   i, fn->src->ft.face->charmaps[i]->encoding,
+                   fn->src->ft.face->charmaps[i]->encoding);
          }
      }
 #endif   
-   error = FT_Select_Charmap(fn->ft.face, ft_encoding_unicode);
+   error = FT_Select_Charmap(fn->src->ft.face, ft_encoding_unicode);
    if (error)
      {
 /* disable this for now...
-       error = FT_Select_Charmap(fn->ft.face, ft_encoding_latin_2);
+       error = FT_Select_Charmap(fn->src->ft.face, ft_encoding_latin_2);
        if (error)
          {
-            error = FT_Select_Charmap(fn->ft.face, ft_encoding_sjis);
+            error = FT_Select_Charmap(fn->src->ft.face, ft_encoding_sjis);
             if (error)
               {
-                 error = FT_Select_Charmap(fn->ft.face, ft_encoding_gb2312);
+                 error = FT_Select_Charmap(fn->src->ft.face, ft_encoding_gb2312);
                  if (error)
                    {
-                      error = FT_Select_Charmap(fn->ft.face, ft_encoding_big5);
+                      error = FT_Select_Charmap(fn->src->ft.face, ft_encoding_big5);
                       if (error)
                         {
                         }
@@ -101,16 +243,9 @@
  */
      }
    
-   fn->file = strdup(file);
-   fn->name = strdup(file);
-   fn->size = size;
-
    fn->glyphs = NULL;
-   
    fn->usage = 0;
-   
    fn->references = 1;
-   
    fonts = evas_object_list_prepend(fonts, fn);
    return fn;
 }
@@ -145,13 +280,11 @@
 void
 evas_common_font_modify_cache_by(RGBA_Font *fn, int dir)
 {
-   int sz_name = 0, sz_file = 0, sz_hash = 0;
+   int sz_hash = 0;
    
-   if (fn->name) sz_name = strlen(fn->name);
-   if (fn->file) sz_file = strlen(fn->file);
    if (fn->glyphs) sz_hash = sizeof(Evas_Hash);
    evas_hash_foreach(fn->glyphs, font_modify_cache_cb, &dir);
-   font_cache_usage += dir * (sizeof(RGBA_Font) + sz_name + sz_file + sz_hash +
+   font_cache_usage += dir * (sizeof(RGBA_Font) + sz_hash +
                              sizeof(FT_FaceRec) + 16384); /* fudge values */
 }
 
@@ -212,9 +345,8 @@
    evas_hash_foreach(fn->glyphs, font_flush_free_glyph_cb, NULL);
    evas_hash_free(fn->glyphs);
    
-   if (fn->file) free(fn->file);
-   if (fn->name) free(fn->name);
-   FT_Done_Face(fn->ft.face);
+   evas_common_font_source_free(fn->src);
+   
    free(fn);
 }
 
@@ -228,7 +360,7 @@
        RGBA_Font *fn;
        
        fn = (RGBA_Font *)l;
-       if ((fn->size == size) && (!strcmp(name, fn->name)))
+       if ((fn->size == size) && (!strcmp(name, fn->src->name)))
          {
             if (fn->references == 0) evas_common_font_modify_cache_by(fn, -1);
             fn->references++;
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- evas_font_main.c    15 Jan 2004 14:58:03 -0000      1.7
+++ evas_font_main.c    23 Jan 2004 02:13:41 -0000      1.8
@@ -34,9 +34,9 @@
    int val;
    int ret;
    
-   val = (int)fn->ft.face->ascender;
-   fn->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
-   ret = (val * fn->ft.face->size->metrics.y_scale) / (fn->ft.face->units_per_EM * 
fn->ft.face->units_per_EM);
+   val = (int)fn->src->ft.face->ascender;
+   fn->src->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
+   ret = (val * fn->src->ft.face->size->metrics.y_scale) / 
(fn->src->ft.face->units_per_EM * fn->src->ft.face->units_per_EM);
    return ret;
 }
 
@@ -46,9 +46,10 @@
    int val;
    int ret;
    
-   val = -(int)fn->ft.face->descender;
-   fn->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
-   ret = (val * fn->ft.face->size->metrics.y_scale) / (fn->ft.face->units_per_EM * 
fn->ft.face->units_per_EM);
+   evas_common_font_size_use(fn);
+   val = -(int)fn->src->ft.face->descender;
+   fn->src->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
+   ret = (val * fn->src->ft.face->size->metrics.y_scale) / 
(fn->src->ft.face->units_per_EM * fn->src->ft.face->units_per_EM);
    return ret;
 }
 
@@ -58,9 +59,10 @@
    int val;
    int ret;
    
-   val = (int)fn->ft.face->bbox.yMax;
-   fn->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
-   ret = (val * fn->ft.face->size->metrics.y_scale) / (fn->ft.face->units_per_EM * 
fn->ft.face->units_per_EM);
+   evas_common_font_size_use(fn);
+   val = (int)fn->src->ft.face->bbox.yMax;
+   fn->src->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
+   ret = (val * fn->src->ft.face->size->metrics.y_scale) / 
(fn->src->ft.face->units_per_EM * fn->src->ft.face->units_per_EM);
    return ret;
 }
 
@@ -70,9 +72,10 @@
    int val;
    int ret;
    
-   val = -(int)fn->ft.face->bbox.yMin;
-   fn->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
-   ret = (val * fn->ft.face->size->metrics.y_scale) / (fn->ft.face->units_per_EM * 
fn->ft.face->units_per_EM);
+   evas_common_font_size_use(fn);
+   val = -(int)fn->src->ft.face->bbox.yMin;
+   fn->src->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
+   ret = (val * fn->src->ft.face->size->metrics.y_scale) / 
(fn->src->ft.face->units_per_EM * fn->src->ft.face->units_per_EM);
    return ret;
 }
 
@@ -82,9 +85,10 @@
    int val;
    int ret;
    
-   val = (int)fn->ft.face->height;
-   fn->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
-   ret = (val * fn->ft.face->size->metrics.y_scale) / (fn->ft.face->units_per_EM * 
fn->ft.face->units_per_EM);
+   evas_common_font_size_use(fn);
+   val = (int)fn->src->ft.face->height;
+   fn->src->ft.face->units_per_EM = 2048; /* nasy hack - need to have correct val */
+   ret = (val * fn->src->ft.face->size->metrics.y_scale) / 
(fn->src->ft.face->units_per_EM * fn->src->ft.face->units_per_EM);
    return ret;
 }
 
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/evas/src/lib/engines/common/evas_font_query.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- evas_font_query.c   15 Jan 2004 14:58:03 -0000      1.10
+++ evas_font_query.c   23 Jan 2004 02:13:42 -0000      1.11
@@ -14,7 +14,8 @@
    end_x = 0;
    pen_x = 0;
    pen_y = 0;
-   use_kerning = FT_HAS_KERNING(fn->ft.face);
+   evas_common_font_size_use(fn);
+   use_kerning = FT_HAS_KERNING(fn->src->ft.face);
    prev_index = 0;
    for (chr = 0; text[chr];)
      {
@@ -25,12 +26,12 @@
        
        gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
        if (gl == 0) break;
-       index = FT_Get_Char_Index(fn->ft.face, gl);
+       index = FT_Get_Char_Index(fn->src->ft.face, gl);
        if ((use_kerning) && (prev_index) && (index))
          {
             FT_Vector delta;
             
-            FT_Get_Kerning(fn->ft.face, prev_index, index,
+            FT_Get_Kerning(fn->src->ft.face, prev_index, index,
                            ft_kerning_default, &delta);
             pen_x += delta.x << 2;
          }
@@ -64,7 +65,8 @@
    if (!text[0]) return 0;
    gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);   
    if (gl == 0) return 0;
-   index = FT_Get_Char_Index(fn->ft.face, gl);
+   evas_common_font_size_use(fn);
+   index = FT_Get_Char_Index(fn->src->ft.face, gl);
    fg = evas_common_font_cache_glyph_get(fn, index);
    if (!fg) return 0;
    return fg->glyph_out->left;
@@ -83,7 +85,8 @@
    start_x = 0;
    pen_x = 0;
    pen_y = 0;
-   use_kerning = FT_HAS_KERNING(fn->ft.face);
+   evas_common_font_size_use(fn);
+   use_kerning = FT_HAS_KERNING(fn->src->ft.face);
    prev_index = 0;
    for (chr = 0; text[chr];)     
      {
@@ -94,12 +97,12 @@
        
        gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
        if (gl == 0) break;
-       index = FT_Get_Char_Index(fn->ft.face, gl);
+       index = FT_Get_Char_Index(fn->src->ft.face, gl);
        if ((use_kerning) && (prev_index) && (index))
          {
             FT_Vector delta;
             
-            FT_Get_Kerning(fn->ft.face, prev_index, index,
+            FT_Get_Kerning(fn->src->ft.face, prev_index, index,
                            ft_kerning_default, &delta);
             pen_x += delta.x << 2;
          }
@@ -130,7 +133,8 @@
    
    pen_x = 0;
    pen_y = 0;
-   use_kerning = FT_HAS_KERNING(fn->ft.face);
+   evas_common_font_size_use(fn);
+   use_kerning = FT_HAS_KERNING(fn->src->ft.face);
    prev_index = 0;
    prev_chr_end = 0;
    asc = evas_common_font_max_ascent_get(fn);
@@ -147,11 +151,11 @@
        pchr = chr;
        gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
        if (gl == 0) break;
-       index = FT_Get_Char_Index(fn->ft.face, gl);
+       index = FT_Get_Char_Index(fn->src->ft.face, gl);
        kern = 0;
        if ((use_kerning) && (prev_index) && (index))
          {
-            FT_Get_Kerning(fn->ft.face, prev_index, index,
+            FT_Get_Kerning(fn->src->ft.face, prev_index, index,
                            ft_kerning_default, &delta);
             kern = delta.x << 2;
             pen_x += kern;
@@ -203,7 +207,8 @@
    
    pen_x = 0;
    pen_y = 0;
-   use_kerning = FT_HAS_KERNING(fn->ft.face);
+   evas_common_font_size_use(fn);
+   use_kerning = FT_HAS_KERNING(fn->src->ft.face);
    prev_index = 0;
    prev_chr_end = 0;
    asc = evas_common_font_max_ascent_get(fn);
@@ -220,11 +225,11 @@
        pchr = chr;
        gl = evas_common_font_utf8_get_next((unsigned char *)text, &chr);
        if (gl == 0) break;
-       index = FT_Get_Char_Index(fn->ft.face, gl);
+       index = FT_Get_Char_Index(fn->src->ft.face, gl);
        kern = 0;
        if ((use_kerning) && (prev_index) && (index))
          {
-            FT_Get_Kerning(fn->ft.face, prev_index, index,
+            FT_Get_Kerning(fn->src->ft.face, prev_index, index,
                            ft_kerning_default, &delta);
             kern = delta.x << 2;
             pen_x += kern;




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to