由於要在一款嵌入式平臺上移植一款pdf閱讀器,所以在網上想找找有沒有開源的,然後找來研究研究,所以遇到cikada.
由於cikada所用的clutter版本比較高,而我現在用的纔是clutter-1.0.
而且我是用命令行編譯的,用它自帶的編譯方法編譯不通過.
所以有以下幾個地方要修改:
一.在cikada.c文件中:
以下代碼要註釋掉:
bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); context = g_option_context_new (_("- Cikada is a presentation tool for PDF slides")); g_option_context_add_main_entries (context, _ckd_entries, PACKAGE); if (!g_option_context_parse (context, &argc, &argv, NULL)) return -1; if (argv[1] == NULL) { g_print (_("You should input PDF file name!\n")); return -1; }
二.在ckd-page.c中,
修改以下幾處:
1.將static gboolean ckd_page_render (ClutterCairoTexture *actor, cairo_t *cr, gpointer user_data)函數刪除. 相應的,將static void ckd_page_set_property (GObject *obj, guint prop_id, const GValue *value, GParamSpec *pspec)函數中的g_signal_connect (priv->cairo_texture, "draw", G_CALLBACK (ckd_page_render), self);這一句刪除
因爲在clutter-1.0中,clutter_cairo_texture還沒有draw信號.
2.在static void ckd_page_set_property (GObject *obj, guint prop_id, const GValue *value, GParamSpec *pspec)函數中,case PROP_PDF_PAGE: 代碼塊中,有w, h只定義,但沒有取得數據,而且在priv->cairo_texture = clutter_cairo_texture_new (priv->quality * w, priv->quality * h);中就使用了.此處存疑.
作以下修改:在priv->cairo_texture = clutter_cairo_texture_new (w, h);語句前,添加
w = priv->pdf_width; h = priv->pdf_height;
3.在static void ckd_page_paint (ClutterActor *actor)中,在clutter_actor_paint (priv->cairo_texture);這條語句後面添加以下代碼:
guint w, h; clutter_cairo_texture_clear ( CLUTTER_CAIRO_TEXTURE (priv->cairo_texture)); cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (priv->cairo_texture)); w = priv->pdf_width * priv->quality; h = priv->pdf_height * priv->quality; cairo_rectangle (cr, 0, 0, w, h); cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0); cairo_fill (cr); cairo_scale (cr, priv->quality, priv->quality); poppler_page_render (priv->pdf_page, cr); cairo_destroy(cr);
4.爲了讓cairo_texture自繪,要實現actor_class的map和unmap函數.故在ckd-page.c文件中添加以下兩個函數實現:
static void ckd_page_map (ClutterActor *actor) { g_debug ("Enter ckd_page_map."); CkdPagePriv *priv = CKD_PAGE_GET_PRIVATE (actor); CLUTTER_ACTOR_CLASS (ckd_page_parent_class)->map(actor); if (CLUTTER_IS_ACTOR (priv->cairo_texture)) clutter_actor_map (priv->cairo_texture); } static void ckd_page_unmap (ClutterActor *actor) { g_debug ("Enter ckd_page_unmap."); CkdPagePriv *priv = CKD_PAGE_GET_PRIVATE (actor); if (CLUTTER_IS_ACTOR (priv->cairo_texture)) clutter_actor_unmap (priv->cairo_texture); CLUTTER_ACTOR_CLASS (ckd_page_parent_class)->unmap(actor); }
5.在static void ckd_page_class_init (CkdPageClass *klass)函數中,map和unmap函數指針賦於它它的父類虛函數.
故在actor_class->allocate = ckd_page_allocate;語句後面添加以下兩句:actor_class->map = ckd_page_map; actor_class->unmap = ckd_page_unmap;
作如上修改後,就可以使用命令行編譯運行了:
gcc ckd-page.c ckd-slides.c ckd-page-fade.c ckd-page-manager.c cikada.c -o cikada `pkg-config --cflags --libs clutter-1.0 poppler-glib`
致謝:http://garfileo.is-programmer.com/tag/clutter
原作者的代碼也可以此網站上找到下載鏈接.
如有疑問聯繫:[email protected]