[libgepub/rust-migration] Use libgepub_internals
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgepub/rust-migration] Use libgepub_internals
- Date: Thu, 9 Aug 2018 07:45:37 +0000 (UTC)
commit 2adfee8252574254152f9c19bf8c963cf034bfc0
Author: Daniel GarcĂa Moreno <danigm wadobo com>
Date: Wed Aug 8 18:21:02 2018 +0200
Use libgepub_internals
libgepub/gepub-archive.c | 182 ----------
libgepub/gepub-archive.h | 49 ---
libgepub/gepub-doc.c | 458 +++++-------------------
libgepub/gepub-doc.h | 3 -
libgepub/gepub.h | 2 -
libgepub/meson.build | 9 +-
subprojects/libgepub_internals/meson.build | 7 +-
subprojects/libgepub_internals/scripts/cargo.sh | 4 +-
tests/test-gepub.c | 96 -----
9 files changed, 98 insertions(+), 712 deletions(-)
---
diff --git a/libgepub/gepub-doc.c b/libgepub/gepub-doc.c
index 9d3219f..427822c 100644
--- a/libgepub/gepub-doc.c
+++ b/libgepub/gepub-doc.c
@@ -18,14 +18,40 @@
*/
#include <config.h>
+#include <gio/gio.h>
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
#include <string.h>
-#include "gepub-utils.h"
#include "gepub-doc.h"
-#include "gepub-archive.h"
-#include "gepub-text-chunk.h"
+
+
+// Rust
+void *epub_new(char *path);
+void epub_destroy(void *doc);
+void *epub_get_resource(void *doc, const char *path, int *size);
+void *epub_get_resource_by_id(void *doc, const char *id, int *size);
+void *epub_get_metadata(void *doc, const char *mdata);
+void *epub_get_resource_mime(void *doc, const char *path);
+void *epub_get_resource_mime_by_id(void *doc, const char *id);
+void *epub_get_current_mime(void *doc);
+void *epub_get_current(void *doc, int *size);
+void *epub_get_current_with_epub_uris(void *doc, int *size);
+void epub_set_page(void *doc, guint page);
+guint epub_get_num_pages(void *doc);
+guint epub_get_page(void *doc);
+gboolean epub_next_page(void *doc);
+gboolean epub_prev_page(void *doc);
+void *epub_get_cover(void *doc);
+void *epub_resource_path(void *doc, const char *id);
+void *epub_current_path(void *doc);
+void *epub_current_id(void *doc);
+void *epub_get_resources(void *doc);
+guint epub_resources_get_length(void *er);
+
+gchar *epub_resources_get_id(void *er, gint i);
+gchar *epub_resources_get_mime(void *er, gint i);
+gchar *epub_resources_get_path(void *er, gint i);
static GQuark
@@ -49,21 +75,12 @@ typedef enum {
-static void gepub_doc_fill_resources (GepubDoc *doc);
-static void gepub_doc_fill_spine (GepubDoc *doc);
static void gepub_doc_initable_iface_init (GInitableIface *iface);
struct _GepubDoc {
GObject parent;
-
- GepubArchive *archive;
- GBytes *content;
- gchar *content_base;
gchar *path;
- GHashTable *resources;
-
- GList *spine;
- GList *chapter;
+ void *rust_epub_doc;
};
struct _GepubDocClass {
@@ -95,24 +112,17 @@ gepub_doc_finalize (GObject *object)
{
GepubDoc *doc = GEPUB_DOC (object);
- g_clear_object (&doc->archive);
- g_clear_pointer (&doc->content, g_bytes_unref);
+ epub_destroy (doc->rust_epub_doc);
g_clear_pointer (&doc->path, g_free);
- g_clear_pointer (&doc->resources, g_hash_table_destroy);
-
- if (doc->spine) {
- g_list_foreach (doc->spine, (GFunc)g_free, NULL);
- g_clear_pointer (&doc->spine, g_list_free);
- }
G_OBJECT_CLASS (gepub_doc_parent_class)->finalize (object);
}
static void
gepub_doc_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GepubDoc *doc = GEPUB_DOC (object);
@@ -131,9 +141,9 @@ gepub_doc_set_property (GObject *object,
static void
gepub_doc_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GepubDoc *doc = GEPUB_DOC (object);
@@ -153,13 +163,6 @@ gepub_doc_get_property (GObject *object,
static void
gepub_doc_init (GepubDoc *doc)
{
- /* doc resources hashtable:
- * id : (mime, path)
- */
- doc->resources = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)gepub_resource_free);
}
static void
@@ -196,22 +199,10 @@ gepub_doc_initable_init (GInitable *initable,
GError **error)
{
GepubDoc *doc = GEPUB_DOC (initable);
- gchar *file;
- gint i = 0, len;
g_assert (doc->path != NULL);
-
- doc->archive = gepub_archive_new (doc->path);
- file = gepub_archive_get_root_file (doc->archive);
- if (!file) {
- if (error != NULL) {
- g_set_error (error, gepub_error_quark (), GEPUB_ERROR_INVALID,
- "Invalid epub file: %s", doc->path);
- }
- return FALSE;
- }
- doc->content = gepub_archive_read_entry (doc->archive, file);
- if (!doc->content) {
+ doc->rust_epub_doc = epub_new (doc->path);
+ if (!doc->rust_epub_doc) {
if (error != NULL) {
g_set_error (error, gepub_error_quark (), GEPUB_ERROR_INVALID,
"Invalid epub file: %s", doc->path);
@@ -219,21 +210,6 @@ gepub_doc_initable_init (GInitable *initable,
return FALSE;
}
- len = strlen (file);
- doc->content_base = g_strdup ("");
- for (i=0; i<len; i++) {
- if (file[i] == '/') {
- g_free (doc->content_base);
- doc->content_base = g_strndup (file, i+1);
- break;
- }
- }
-
- gepub_doc_fill_resources (doc);
- gepub_doc_fill_spine (doc);
-
- g_free (file);
-
return TRUE;
}
@@ -259,95 +235,6 @@ gepub_doc_new (const gchar *path, GError **error)
NULL);
}
-static void
-gepub_doc_fill_resources (GepubDoc *doc)
-{
- xmlDoc *xdoc = NULL;
- xmlNode *root_element = NULL;
- xmlNode *mnode = NULL;
- xmlNode *item = NULL;
- gchar *id, *tmpuri, *uri;
- GepubResource *res;
- const char *data;
- gsize size;
-
- data = g_bytes_get_data (doc->content, &size);
- xdoc = xmlRecoverMemory (data, size);
- root_element = xmlDocGetRootElement (xdoc);
- mnode = gepub_utils_get_element_by_tag (root_element, "manifest");
-
- item = mnode->children;
- while (item) {
- if (item->type != XML_ELEMENT_NODE ) {
- item = item->next;
- continue;
- }
-
- id = gepub_utils_get_prop (item, "id");
- tmpuri = gepub_utils_get_prop (item, "href");
- uri = g_strdup_printf ("%s%s", doc->content_base, tmpuri);
- g_free (tmpuri);
-
- res = g_malloc (sizeof (GepubResource));
- res->mime = gepub_utils_get_prop (item, "media-type");
- res->uri = uri;
- g_hash_table_insert (doc->resources, id, res);
- item = item->next;
- }
-
- xmlFreeDoc (xdoc);
-}
-
-static void
-gepub_doc_fill_spine (GepubDoc *doc)
-{
- xmlDoc *xdoc = NULL;
- xmlNode *root_element = NULL;
- xmlNode *snode = NULL;
- xmlNode *item = NULL;
- gchar *id;
- const char *data;
- gsize size;
- GList *spine = NULL;
-
- data = g_bytes_get_data (doc->content, &size);
- xdoc = xmlRecoverMemory (data, size);
- root_element = xmlDocGetRootElement (xdoc);
- snode = gepub_utils_get_element_by_tag (root_element, "spine");
-
- item = snode->children;
- while (item) {
- if (item->type != XML_ELEMENT_NODE ) {
- item = item->next;
- continue;
- }
-
- id = gepub_utils_get_prop (item, "idref");
-
- spine = g_list_prepend (spine, id);
- item = item->next;
- }
-
- doc->spine = g_list_reverse (spine);
- doc->chapter = doc->spine;
-
- xmlFreeDoc (xdoc);
-}
-
-/**
- * gepub_doc_get_content:
- * @doc: a #GepubDoc
- *
- * Returns: (transfer none): the document content
- */
-GBytes *
-gepub_doc_get_content (GepubDoc *doc)
-{
- g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
-
- return doc->content;
-}
-
/**
* gepub_doc_get_metadata:
* @doc: a #GepubDoc
@@ -358,45 +245,41 @@ gepub_doc_get_content (GepubDoc *doc)
gchar *
gepub_doc_get_metadata (GepubDoc *doc, const gchar *mdata)
{
- xmlDoc *xdoc = NULL;
- xmlNode *root_element = NULL;
- xmlNode *mnode = NULL;
- xmlNode *mdata_node = NULL;
- gchar *ret;
- xmlChar *text;
- const char *data;
- gsize size;
-
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (mdata != NULL, NULL);
- data = g_bytes_get_data (doc->content, &size);
- xdoc = xmlRecoverMemory (data, size);
- root_element = xmlDocGetRootElement (xdoc);
- mnode = gepub_utils_get_element_by_tag (root_element, "metadata");
- mdata_node = gepub_utils_get_element_by_tag (mnode, mdata);
-
- text = xmlNodeGetContent (mdata_node);
- ret = g_strdup ((const char *) text);
- xmlFree (text);
-
- xmlFreeDoc (xdoc);
-
- return ret;
+ return epub_get_metadata (doc->rust_epub_doc, mdata);
}
/**
* gepub_doc_get_resources:
* @doc: a #GepubDoc
*
- * Returns: (element-type utf8 Gepub.Resource) (transfer none): doc resource table
+ * Returns: (element-type utf8 Gepub.Resource) (transfer full): doc resource table
*/
GHashTable *
gepub_doc_get_resources (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- return doc->resources;
+ GHashTable *resources = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)gepub_resource_free);
+
+ void *res = epub_get_resources (doc->rust_epub_doc);
+ guint l = epub_resources_get_length (res);
+ gint i = 0;
+
+ for (i=0; i<l; i++) {
+ gchar *key = epub_resources_get_id (res, i);
+ GepubResource *r = g_malloc (sizeof (GepubResource));
+ r->uri = epub_resources_get_path (res, i);
+ r->mime = epub_resources_get_mime (res, i);
+ g_hash_table_insert (resources, key, r);
+ }
+
+ return resources;
}
/**
@@ -409,18 +292,12 @@ gepub_doc_get_resources (GepubDoc *doc)
GBytes *
gepub_doc_get_resource_by_id (GepubDoc *doc, const gchar *id)
{
- GepubResource *gres;
-
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (id != NULL, NULL);
- gres = g_hash_table_lookup (doc->resources, id);
- if (!gres) {
- // not found
- return NULL;
- }
-
- return gepub_archive_read_entry (doc->archive, gres->uri);
+ int size = 0;
+ guint8 *data = epub_get_resource_by_id (doc->rust_epub_doc, id, &size);
+ return g_bytes_new_take (data, size);
}
/**
@@ -436,7 +313,9 @@ gepub_doc_get_resource (GepubDoc *doc, const gchar *path)
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (path != NULL, NULL);
- return gepub_archive_read_entry (doc->archive, path);
+ int size = 0;
+ guint8 *data = epub_get_resource (doc->rust_epub_doc, path, &size);
+ return g_bytes_new_take (data, size);
}
/**
@@ -449,18 +328,10 @@ gepub_doc_get_resource (GepubDoc *doc, const gchar *path)
gchar *
gepub_doc_get_resource_mime_by_id (GepubDoc *doc, const gchar *id)
{
- GepubResource *gres;
-
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (id != NULL, NULL);
- gres = g_hash_table_lookup (doc->resources, id);
- if (!gres) {
- // not found
- return NULL;
- }
-
- return g_strdup (gres->mime);
+ return epub_get_resource_mime_by_id (doc->rust_epub_doc, id);
}
/**
@@ -473,25 +344,10 @@ gepub_doc_get_resource_mime_by_id (GepubDoc *doc, const gchar *id)
gchar *
gepub_doc_get_resource_mime (GepubDoc *doc, const gchar *path)
{
- GepubResource *gres;
- GList *keys;
-
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (path != NULL, NULL);
- keys = g_hash_table_get_keys (doc->resources);
-
- while (keys) {
- gres = ((GepubResource*)g_hash_table_lookup (doc->resources, keys->data));
- if (!strcmp (gres->uri, path))
- break;
- keys = keys->next;
- }
-
- if (keys)
- return g_strdup (gres->mime);
- else
- return NULL;
+ return epub_get_resource_mime (doc->rust_epub_doc, path);
}
/**
@@ -504,9 +360,8 @@ gchar *
gepub_doc_get_current_mime (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- g_return_val_if_fail (doc->chapter != NULL, NULL);
- return gepub_doc_get_resource_mime_by_id (doc, doc->chapter->data);
+ return epub_get_current_mime (doc->rust_epub_doc);
}
/**
@@ -519,9 +374,10 @@ GBytes *
gepub_doc_get_current (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- g_return_val_if_fail (doc->chapter != NULL, NULL);
- return gepub_doc_get_resource_by_id (doc, doc->chapter->data);
+ int size = 0;
+ guint8 *data = epub_get_current (doc->rust_epub_doc, &size);
+ return g_bytes_new_take (data, size);
}
/**
@@ -535,106 +391,11 @@ gepub_doc_get_current (GepubDoc *doc)
GBytes *
gepub_doc_get_current_with_epub_uris (GepubDoc *doc)
{
- GBytes *content, *replaced;
- gchar *path, *base;
-
- g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
-
- content = gepub_doc_get_current (doc);
- path = gepub_doc_get_current_path (doc);
- // getting the basepath of the current xhtml loaded
- base = g_path_get_dirname (path);
-
- replaced = gepub_utils_replace_resources (content, base);
-
- g_free (path);
- g_bytes_unref (content);
-
- return replaced;
-}
-
-/**
- * gepub_doc_get_text:
- * @doc: a #GepubDoc
- *
- * Returns: (element-type Gepub.TextChunk) (transfer full): the list of text in the current chapter.
- */
-GList *
-gepub_doc_get_text (GepubDoc *doc)
-{
- xmlDoc *xdoc = NULL;
- xmlNode *root_element = NULL;
- GBytes *current;
- const gchar *data;
- gsize size;
-
- GList *texts = NULL;
-
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- current = gepub_doc_get_current (doc);
- if (!current) {
- return NULL;
- }
- data = g_bytes_get_data (current, &size);
- xdoc = htmlReadMemory (data, size, "", NULL, HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR);
- root_element = xmlDocGetRootElement (xdoc);
- texts = gepub_utils_get_text_elements (root_element);
-
- g_bytes_unref (current);
- xmlFreeDoc (xdoc);
-
- return texts;
-}
-
-/**
- * gepub_doc_get_text_by_id:
- * @doc: a #GepubDoc
- * @id: the resource id
- *
- * Returns: (element-type Gepub.TextChunk) (transfer full): the list of text in the current chapter.
- */
-GList *
-gepub_doc_get_text_by_id (GepubDoc *doc, const gchar *id)
-{
- xmlDoc *xdoc = NULL;
- xmlNode *root_element = NULL;
- gsize size;
- const gchar *res;
- GBytes *contents;
-
- GList *texts = NULL;
-
- g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- g_return_val_if_fail (id != NULL, NULL);
-
- contents = gepub_doc_get_resource_by_id (doc, id);
- if (!contents) {
- return NULL;
- }
-
- res = g_bytes_get_data (contents, &size);
- xdoc = htmlReadMemory (res, size, "", NULL, HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR);
- root_element = xmlDocGetRootElement (xdoc);
- texts = gepub_utils_get_text_elements (root_element);
-
- g_bytes_unref (contents);
- xmlFreeDoc (xdoc);
-
- return texts;
-}
-
-static gboolean
-gepub_doc_set_chapter_internal (GepubDoc *doc,
- GList *chapter)
-{
- if (!chapter || doc->chapter == chapter)
- return FALSE;
-
- doc->chapter = chapter;
- g_object_notify_by_pspec (G_OBJECT (doc), properties[PROP_CHAPTER]);
-
- return TRUE;
+ int size = 0;
+ guint8 *data = epub_get_current_with_epub_uris (doc->rust_epub_doc, &size);
+ return g_bytes_new_take (data, size);
}
/**
@@ -647,9 +408,11 @@ gboolean
gepub_doc_go_next (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), FALSE);
- g_return_val_if_fail (doc->chapter != NULL, FALSE);
-
- return gepub_doc_set_chapter_internal (doc, doc->chapter->next);
+ gboolean isok = epub_next_page (doc->rust_epub_doc);
+ if (isok) {
+ g_object_notify_by_pspec (G_OBJECT (doc), properties[PROP_CHAPTER]);
+ }
+ return isok;
}
/**
@@ -662,9 +425,11 @@ gboolean
gepub_doc_go_prev (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), FALSE);
- g_return_val_if_fail (doc->chapter != NULL, FALSE);
-
- return gepub_doc_set_chapter_internal (doc, doc->chapter->prev);
+ gboolean isok = epub_prev_page (doc->rust_epub_doc);
+ if (isok) {
+ g_object_notify_by_pspec (G_OBJECT (doc), properties[PROP_CHAPTER]);
+ }
+ return isok;
}
/**
@@ -677,8 +442,7 @@ int
gepub_doc_get_n_chapters (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), 0);
-
- return g_list_length (doc->spine);
+ return epub_get_num_pages (doc->rust_epub_doc);
}
/**
@@ -691,10 +455,7 @@ int
gepub_doc_get_chapter (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), 0);
- g_return_val_if_fail (doc->spine != NULL, 0);
- g_return_val_if_fail (doc->chapter != NULL, 0);
-
- return g_list_position (doc->spine, doc->chapter);
+ return epub_get_page (doc->rust_epub_doc);
}
/**
@@ -706,16 +467,12 @@ gepub_doc_get_chapter (GepubDoc *doc)
*/
void
gepub_doc_set_chapter (GepubDoc *doc,
- gint index)
+ gint index)
{
- GList *chapter;
-
g_return_if_fail (GEPUB_IS_DOC (doc));
-
g_return_if_fail (index >= 0 && index <= gepub_doc_get_n_chapters (doc));
-
- chapter = g_list_nth (doc->spine, index);
- gepub_doc_set_chapter_internal (doc, chapter);
+ g_object_notify_by_pspec (G_OBJECT (doc), properties[PROP_CHAPTER]);
+ epub_set_page (doc->rust_epub_doc, index);
}
/**
@@ -728,25 +485,8 @@ gepub_doc_set_chapter (GepubDoc *doc,
gchar *
gepub_doc_get_cover (GepubDoc *doc)
{
- xmlDoc *xdoc = NULL;
- xmlNode *root_element = NULL;
- xmlNode *mnode = NULL;
- gchar *ret;
- const char *data;
- gsize size;
-
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- g_return_val_if_fail (doc->content != NULL, NULL);
-
- data = g_bytes_get_data (doc->content, &size);
- xdoc = xmlRecoverMemory (data, size);
- root_element = xmlDocGetRootElement (xdoc);
- mnode = gepub_utils_get_element_by_attr (root_element, "name", "cover");
- ret = gepub_utils_get_prop (mnode, "content");
-
- xmlFreeDoc (xdoc);
-
- return ret;
+ return epub_get_cover (doc->rust_epub_doc);
}
/**
@@ -759,18 +499,10 @@ gepub_doc_get_cover (GepubDoc *doc)
gchar *
gepub_doc_get_resource_path (GepubDoc *doc, const gchar *id)
{
- GepubResource *gres;
-
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (id != NULL, NULL);
- gres = g_hash_table_lookup (doc->resources, id);
- if (!gres) {
- // not found
- return NULL;
- }
-
- return g_strdup (gres->uri);
+ return epub_resource_path(doc->rust_epub_doc, id);
}
/**
@@ -783,9 +515,7 @@ gchar *
gepub_doc_get_current_path (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- g_return_val_if_fail (doc->chapter != NULL, NULL);
-
- return gepub_doc_get_resource_path (doc, doc->chapter->data);
+ return epub_current_path (doc->rust_epub_doc);
}
/**
@@ -799,7 +529,5 @@ const gchar *
gepub_doc_get_current_id (GepubDoc *doc)
{
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
- g_return_val_if_fail (doc->chapter != NULL, NULL);
-
- return doc->chapter->data;
+ return epub_current_id (doc->rust_epub_doc);
}
diff --git a/libgepub/gepub-doc.h b/libgepub/gepub-doc.h
index 01b8f8c..c6680a7 100644
--- a/libgepub/gepub-doc.h
+++ b/libgepub/gepub-doc.h
@@ -45,7 +45,6 @@ typedef struct _GepubResource GepubResource;
GType gepub_doc_get_type (void) G_GNUC_CONST;
GepubDoc *gepub_doc_new (const gchar *path, GError **error);
-GBytes *gepub_doc_get_content (GepubDoc *doc);
gchar *gepub_doc_get_metadata (GepubDoc *doc, const gchar *mdata);
GBytes *gepub_doc_get_resource (GepubDoc *doc, const gchar *path);
GBytes *gepub_doc_get_resource_by_id (GepubDoc *doc, const gchar *id);
@@ -53,8 +52,6 @@ GHashTable *gepub_doc_get_resources (GepubDoc *doc);
gchar *gepub_doc_get_resource_mime (GepubDoc *doc, const gchar *path);
gchar *gepub_doc_get_resource_mime_by_id (GepubDoc *doc, const gchar *id);
gchar *gepub_doc_get_current_mime (GepubDoc *doc);
-GList *gepub_doc_get_text (GepubDoc *doc);
-GList *gepub_doc_get_text_by_id (GepubDoc *doc, const gchar *id);
GBytes *gepub_doc_get_current (GepubDoc *doc);
GBytes *gepub_doc_get_current_with_epub_uris (GepubDoc *doc);
gchar *gepub_doc_get_cover (GepubDoc *doc);
diff --git a/libgepub/gepub.h b/libgepub/gepub.h
index a8f7fd2..cdc1c3c 100644
--- a/libgepub/gepub.h
+++ b/libgepub/gepub.h
@@ -1,8 +1,6 @@
#ifndef _GEPUB__H_
#define _GEPUB__H_
-#include "gepub-archive.h"
-#include "gepub-text-chunk.h"
#include "gepub-doc.h"
#include "gepub-widget.h"
diff --git a/libgepub/meson.build b/libgepub/meson.build
index 4485a5a..e9d2759 100644
--- a/libgepub/meson.build
+++ b/libgepub/meson.build
@@ -1,7 +1,5 @@
headers = files(
- 'gepub-archive.h',
'gepub-doc.h',
- 'gepub-text-chunk.h',
'gepub-widget.h',
'gepub.h'
)
@@ -11,13 +9,8 @@ install_headers(
subdir: gepub_lib_name
)
-private_headers = files('gepub-utils.h')
-
sources = files(
- 'gepub-archive.c',
'gepub-doc.c',
- 'gepub-text-chunk.c',
- 'gepub-utils.c',
'gepub-widget.c'
)
@@ -80,7 +73,7 @@ if get_option('introspection') and get_option('default_library') == 'shared'
libgepub_gir = gnome.generate_gir(
libgepub,
header: 'gepub.h',
- sources: sources + headers + private_headers,
+ sources: sources + headers,
namespace: gepub_gir_ns,
nsversion: gepub_api_version,
includes: gir_incs,
diff --git a/subprojects/libgepub_internals/meson.build b/subprojects/libgepub_internals/meson.build
index edaf389..2a4bb40 100644
--- a/subprojects/libgepub_internals/meson.build
+++ b/subprojects/libgepub_internals/meson.build
@@ -32,12 +32,9 @@ cargo_build = custom_target('cargo-build',
# arguments: ['@CURRENT_SOURCE_DIR@', '@OUTPUT@'],
# output: '@BASENAME@.a')
#libfiles = gen.process('libgepub_internals')
-libgepub_internals_lib = static_library('epub_internals', cargo_build)
-
-cc = meson.get_compiler('c')
-libdir = meson.current_build_dir()
-#libgepub_internals_lib = cc.find_library('gepub_internals', dirs: [libdir], required: false)
+libgepub_internals_lib = static_library('gepub_internals', cargo_build)
libgepub_internals_dep = declare_dependency(
link_with: libgepub_internals_lib,
+ sources: cargo_build,
)
diff --git a/subprojects/libgepub_internals/scripts/cargo.sh b/subprojects/libgepub_internals/scripts/cargo.sh
index e2aa50e..62cee6e 100755
--- a/subprojects/libgepub_internals/scripts/cargo.sh
+++ b/subprojects/libgepub_internals/scripts/cargo.sh
@@ -3,8 +3,8 @@
if [[ $DEBUG = true ]]
then
echo "DEBUG MODE"
- cargo build --manifest-path $1/Cargo.toml && cp $1/target/debug/libepub_internals.a $2
+ cargo build --manifest-path $1/Cargo.toml && cp $1/target/debug/libgepub_internals.a $2
else
echo "RELEASE MODE"
- cargo build --manifest-path $1/Cargo.toml --release && cp $1/target/release/libepub_internals.a $2.a
+ cargo build --manifest-path $1/Cargo.toml --release && cp $1/target/release/libgepub_internals.a $2.a
fi
diff --git a/tests/test-gepub.c b/tests/test-gepub.c
index 1d6c0d8..53b85d7 100644
--- a/tests/test-gepub.c
+++ b/tests/test-gepub.c
@@ -28,39 +28,6 @@ reload_current_chapter (GepubWidget *widget)
g_free (txt);
}
-static void
-update_text (GepubDoc *doc)
-{
- GList *l, *chunks;
- GtkTextIter start, end;
-
- gtk_text_buffer_get_start_iter (page_buffer, &start);
- gtk_text_buffer_get_end_iter (page_buffer, &end);
- gtk_text_buffer_delete (page_buffer, &start, &end);
-
- chunks = gepub_doc_get_text (doc);
-
- for (l=chunks; l; l = l->next) {
- GepubTextChunk *chunk = GEPUB_TEXT_CHUNK (l->data);
- if (chunk->type == GEPUBTextHeader) {
- gtk_text_buffer_insert_at_cursor (page_buffer, "\n", -1);
- gtk_text_buffer_get_end_iter (page_buffer, &end);
- gtk_text_buffer_insert_with_tags_by_name (page_buffer, &end, chunk->text, -1, "head", NULL);
- gtk_text_buffer_insert_at_cursor (page_buffer, "\n", -1);
- } else if (chunk->type == GEPUBTextNormal) {
- gtk_text_buffer_insert_at_cursor (page_buffer, "\n", -1);
- gtk_text_buffer_insert_at_cursor (page_buffer, chunk->text, -1);
- gtk_text_buffer_insert_at_cursor (page_buffer, "\n", -1);
- } else if (chunk->type == GEPUBTextItalic) {
- gtk_text_buffer_get_end_iter (page_buffer, &end);
- gtk_text_buffer_insert_with_tags_by_name (page_buffer, &end, chunk->text, -1, "italic", NULL);
- } else if (chunk->type == GEPUBTextBold) {
- gtk_text_buffer_get_end_iter (page_buffer, &end);
- gtk_text_buffer_insert_with_tags_by_name (page_buffer, &end, chunk->text, -1, "bold", NULL);
- }
- }
-}
-
#if 0
static void
print_replaced_text (GepubDoc *doc)
@@ -116,38 +83,9 @@ button_pressed (GtkButton *button, GepubWidget *widget)
l = l ? l : 1.5;
gepub_widget_set_lineheight (widget, l - 0.1);
}
- update_text (doc);
//print_replaced_text (doc);
}
-static void
-test_open (const char *path)
-{
- GepubArchive *a;
- GList *list_files;
- gint i;
- gint size;
-
- a = gepub_archive_new (path);
- list_files = gepub_archive_list_files (a);
- if (!list_files) {
- PTEST ("ERROR: BAD epub file");
- g_object_unref (a);
- return;
- }
-
- size = g_list_length (list_files);
- PTEST ("%d\n", size);
- for (i = 0; i < size; i++) {
- PTEST ("file: %s\n", (char *)g_list_nth_data (list_files, i));
- g_free (g_list_nth_data (list_files, i));
- }
-
- g_list_free (list_files);
-
- g_object_unref (a);
-}
-
static void
find_xhtml (gchar *key, GepubResource *value, gpointer data)
{
@@ -160,48 +98,17 @@ find_xhtml (gchar *key, GepubResource *value, gpointer data)
static void
test_read (const char *path)
{
- GepubArchive *a;
GList *list_files = NULL;
- const guchar *buffer;
gchar *file = NULL;
- gsize bufsize;
- GBytes *bytes;
GepubDoc *doc;
GHashTable *ht;
- a = gepub_archive_new (path);
-
doc = gepub_doc_new (path, NULL);
ht = (GHashTable*)gepub_doc_get_resources (doc);
g_hash_table_foreach (ht, (GHFunc)find_xhtml, &file);
- bytes = gepub_archive_read_entry (a, file);
- if (bytes) {
- buffer = g_bytes_get_data (bytes, &bufsize);
- PTEST ("doc:%s\n----\n%s\n-----\n", file, buffer);
- g_bytes_unref (bytes);
- }
-
g_list_foreach (list_files, (GFunc)g_free, NULL);
g_list_free (list_files);
-
- g_object_unref (a);
-}
-
-static void
-test_root_file (const char *path)
-{
- GepubArchive *a;
- gchar *root_file = NULL;
-
- a = gepub_archive_new (path);
-
- root_file = gepub_archive_get_root_file (a);
- PTEST ("root file: %s\n", root_file);
- if (root_file)
- g_free (root_file);
-
- g_object_unref (a);
}
static void
@@ -353,7 +260,6 @@ main (int argc, char **argv)
gtk_text_buffer_create_tag (page_buffer, "bold", "weight", PANGO_WEIGHT_BOLD, "foreground", "#ff0000",
NULL);
gtk_text_buffer_create_tag (page_buffer, "italic", "style", PANGO_STYLE_ITALIC, "foreground", "#005500",
NULL);
gtk_text_buffer_create_tag (page_buffer, "head", "size-points", 20.0, NULL);
- update_text (doc);
gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (textview2));
gtk_widget_set_size_request (GTK_WIDGET (textview2), 500, 300);
@@ -429,9 +335,7 @@ main (int argc, char **argv)
// Testing all
- TEST(test_open, argv[1])
TEST(test_read, argv[1])
- TEST(test_root_file, argv[1])
TEST(test_doc_name, argv[1])
TEST(test_doc_resources, argv[1])
TEST(test_doc_spine, argv[1])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]