Edje_edit font_del
authortiago <tiago@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 26 Apr 2010 18:19:49 +0000 (18:19 +0000)
committertiago <tiago@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 26 Apr 2010 18:19:49 +0000 (18:19 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@48339 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/Edje_Edit.h
src/lib/edje_edit.c

index f7ae0f8..a0d0a82 100644 (file)
@@ -742,6 +742,15 @@ edje_edit_font_add(
    const char* alias       ///< The file alias, or NULL to use filename
 );
 
+/**Remove a ttf font to the edje file.
+ * If font can't be deleted EINA_FALSE is returned.
+ */
+EAPI Eina_Bool         ///@return EINA_TRUE on success or EINA_FALSE on failure
+edje_edit_font_del(
+   Evas_Object *obj,       ///< The edje object
+   const char* alias       ///< The file alias
+);
+
 /**Get font name for a given part state. Remember to free the returned string using edje_edit_string_free().*/
 EAPI const char *          ///@return The name of the font used in the given part state
 edje_edit_state_font_get(
@@ -2223,6 +2232,17 @@ EAPI Eina_List * edje_edit_fonts_list_get(Evas_Object *obj);
  */
 EAPI Eina_Bool edje_edit_font_add(Evas_Object *obj, const char *path, const char* alias);
 
+/** Delete font from the edje file.
+ *
+ * The font will be removed from all the groups in the edje, not only the current one.
+ *
+ * @param obj Object being edited.
+ * @param alias The font alias
+ *
+ * @return EINA_TRUE if font deleted, EINA_FALSE otherwise.
+ */
+EAPI Eina_Bool edje_edit_font_del(Evas_Object *obj, const char* alias);
+
 /** Get font name for a given part state.
  *
  * Remember to free the returned string using edje_edit_string_free().
index fde18ff..c39a671 100644 (file)
@@ -4297,6 +4297,93 @@ edje_edit_font_add(Evas_Object *obj, const char* path, const char* alias)
    return EINA_TRUE;
 }
 
+EAPI Eina_Bool
+edje_edit_font_del(Evas_Object *obj, const char* alias)
+{
+   Edje_Font_Directory_Entry *fnt;
+
+   GET_ED_OR_RETURN(EINA_FALSE);
+
+   INF("DEL FONT: %s\n", alias);
+
+   if (!alias) return EINA_FALSE;
+   if (!ed->file) return EINA_FALSE;
+   if (!ed->path) return EINA_FALSE;
+
+   if (!ed->file->font_dir)
+     return EINA_TRUE;
+
+   fnt = eina_hash_find(ed->file->font_hash, alias);
+   if (!fnt)
+     {
+       WRN("Unable to find font entry part \"%s\"", alias);
+       return EINA_TRUE;
+     }
+
+   ed->file->font_dir->entries = eina_list_remove(
+                                      ed->file->font_dir->entries,
+                                      fnt);
+
+   if (!eina_hash_del_by_key(ed->file->font_hash, alias))
+     {
+       ERR("Unable to remove font \"%s\" of fonts hash", alias);
+
+       ed->file->font_dir->entries = eina_list_append(
+                                         ed->file->font_dir->entries,
+                                         fnt);
+       return EINA_FALSE;
+     }
+
+   /* Erase font to edje file */
+   {
+      char entry[PATH_MAX];
+      Eet_File *eetf;
+
+      /* open the eet file */
+      eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE);
+      if (!eetf)
+       {
+          ERR("Unable to open \"%s\" for writing output", ed->path);
+          eina_hash_direct_add(ed->file->font_hash, fnt->entry, fnt);
+          ed->file->font_dir->entries = eina_list_append(
+                                            ed->file->font_dir->entries,
+                                            fnt);
+          return EINA_FALSE;
+       }
+
+      snprintf(entry, sizeof(entry), "fonts/%s", alias);
+
+      if (eet_delete(eetf, entry) <= 0)
+        {
+           ERR("Unable to delete \"%s\" font entry", entry);
+           eet_close(eetf);
+          eina_hash_direct_add(ed->file->font_hash, fnt->entry, fnt);
+          ed->file->font_dir->entries = eina_list_append(
+                                            ed->file->font_dir->entries,
+                                            fnt);
+           return EINA_FALSE;
+        }
+
+      /* write the edje_file */
+      if (!_edje_edit_update_edje_file(ed, eetf))
+       {
+          eet_close(eetf);
+          eina_hash_direct_add(ed->file->font_hash, fnt->entry, fnt);
+          ed->file->font_dir->entries = eina_list_append(
+                                            ed->file->font_dir->entries,
+                                            fnt);
+          return EINA_FALSE;
+       }
+      eet_close(eetf);
+   }
+
+   free((char *)fnt->entry);
+   free((char *)fnt->path);
+   free(fnt);
+
+   return EINA_TRUE;
+}
+
 EAPI const char *
 edje_edit_state_font_get(Evas_Object *obj, const char *part, const char *state, double value)
 {