Merge lp:~ballogy/gloobus-preview/xps-support into lp:gloobus-preview

Proposed by Balló György
Status: Merged
Merged at revision: 301
Proposed branch: lp:~ballogy/gloobus-preview/xps-support
Merge into: lp:gloobus-preview
Diff against target: 335 lines (+185/-14)
11 files modified
configure.ac (+3/-1)
src/Makefile.am (+2/-1)
src/gloobus-preview-plugin-manager.cpp (+1/-0)
src/plugin-gstreamer-audio/Makefile.am (+2/-2)
src/plugin-gstreamer-audio/plugin-gstreamer-audio.cpp (+6/-8)
src/plugin-gstreamer-audio/plugin-gstreamer-audio.h (+2/-2)
src/plugin-xps/Makefile.am (+13/-0)
src/plugin-xps/xps-loader.cpp (+106/-0)
src/plugin-xps/xps-loader.h (+23/-0)
src/plugin-xps/xps-plugin.cpp (+14/-0)
src/plugin-xps/xps-plugin.h (+13/-0)
To merge this branch: bzr merge lp:~ballogy/gloobus-preview/xps-support
Reviewer Review Type Date Requested Status
Gloobus Developers Pending
Review via email: mp+245348@code.launchpad.net

Description of the change

Add support for XPS document format

It introduces a new libgxps based plugin.

To post a comment you must log in.
293. By Balló György

Better error handling

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2014-12-23 16:22:50 +0000
3+++ configure.ac 2014-12-23 19:06:15 +0000
4@@ -49,7 +49,8 @@
5 PKG_CHECK_MODULES(POPPLER, poppler-glib)
6 PKG_CHECK_MODULES(SPECTRE, libspectre >= 0.2.2)
7 PKG_CHECK_MODULES(DJVU, ddjvuapi)
8-PKG_CHECK_MODULES(TAGLIB, taglib)
9+#PKG_CHECK_MODULES(TAGLIB, taglib)
10+PKG_CHECK_MODULES(GXPS, libgxps)
11 PKG_CHECK_MODULES(FREETYPE,freetype2)
12 PKG_CHECK_MODULES(GLIB, glib-2.0)
13 PKG_CHECK_MODULES(DBUS, dbus-glib-1)
14@@ -87,6 +88,7 @@
15 src/plugin-ps/Makefile
16 src/plugin-text/Makefile
17 src/plugin-ttf/Makefile
18+ src/plugin-xps/Makefile
19 src/loaders/PSD/Makefile
20 src/loaders/XCF/Makefile
21 data/Makefile
22
23=== modified file 'src/Makefile.am'
24--- src/Makefile.am 2014-12-23 16:22:50 +0000
25+++ src/Makefile.am 2014-12-23 19:06:15 +0000
26@@ -12,7 +12,8 @@
27 plugin-pixbuf \
28 plugin-ps \
29 plugin-text \
30- plugin-ttf
31+ plugin-ttf \
32+ plugin-xps
33
34 #CXXFLAGS = -Werror -g #If -O2 iDocument threads don't work
35 AM_CXXFLAGS = -Wall #-g -O0
36
37=== modified file 'src/gloobus-preview-plugin-manager.cpp'
38--- src/gloobus-preview-plugin-manager.cpp 2014-12-20 21:05:12 +0000
39+++ src/gloobus-preview-plugin-manager.cpp 2014-12-23 19:06:15 +0000
40@@ -107,4 +107,5 @@
41 #include "plugin-ps/ps-plugin.h"
42 #include "plugin-text/plugin-text.h"
43 #include "plugin-ttf/plugin-ttf.h"
44+#include "plugin-xps/xps-plugin.h"
45 }
46
47=== modified file 'src/plugin-gstreamer-audio/Makefile.am'
48--- src/plugin-gstreamer-audio/Makefile.am 2010-04-19 18:00:37 +0000
49+++ src/plugin-gstreamer-audio/Makefile.am 2014-12-23 19:06:15 +0000
50@@ -1,7 +1,7 @@
51 plugindir = $(prefix)/lib/gloobus/
52
53-AM_CPPFLAGS += $(GTK_CFLAGS) $(GSTREAMER_CFLAGS) $(GDK_CFLAGS) $(TAGLIB_CFLAGS)
54-AM_LDFLAGS = $(GTK_LIBS) $(GSTREAMER_LIBS) $(GDK_LIBS) $(TAGLIB_LIBS)
55+AM_CPPFLAGS += $(GTK_CFLAGS) $(GSTREAMER_CFLAGS) $(GDK_CFLAGS) #$(TAGLIB_CFLAGS)
56+AM_LDFLAGS = $(GTK_LIBS) $(GSTREAMER_LIBS) $(GDK_LIBS) #$(TAGLIB_LIBS)
57
58 plugin_LTLIBRARIES = audio.la
59 audio_la_SOURCES = plugin-gstreamer-audio.cpp
60
61=== modified file 'src/plugin-gstreamer-audio/plugin-gstreamer-audio.cpp'
62--- src/plugin-gstreamer-audio/plugin-gstreamer-audio.cpp 2014-12-23 10:30:25 +0000
63+++ src/plugin-gstreamer-audio/plugin-gstreamer-audio.cpp 2014-12-23 19:06:15 +0000
64@@ -38,12 +38,12 @@
65 pix_reflection = ui->pixbuf_reflect(pix_cover);
66 g_object_unref(temp);
67
68- load_info();
69+ //load_info(); // Use GStreamer instead of taglib
70
71 return true;
72 }
73
74-void iAudio::load_info( void )
75+/*void iAudio::load_info( void )
76 {
77 TagLib::FileRef file(m_filename.c_str());
78
79@@ -54,7 +54,7 @@
80 this->title = title.toCString(true);
81 this->artist = artist.toCString(true);
82 this->album = album.toCString(true);
83-}
84+}*/
85
86 void iAudio::end( void )
87 {
88@@ -166,7 +166,7 @@
89 {
90 GdkPixbuf *temp = NULL;
91
92- TagLib::MPEG::File file(m_filename.c_str());
93+/* TagLib::MPEG::File file(m_filename.c_str());
94 TagLib::ID3v2::Tag *tagv2 = file.ID3v2Tag();
95 if(tagv2) {
96 TagLib::ID3v2::FrameListMap tags = tagv2->frameListMap();
97@@ -187,7 +187,7 @@
98 if(temp)
99 return temp;
100 }
101- }
102+ }*/
103
104 // If there is no cover attached, load cover.jpg, then if there is not cover.jpg, try to load
105 // cover.png, and there is not cover.png, then, load the default theme icon for audio/mpeg using the
106@@ -262,7 +262,7 @@
107 case GST_MESSAGE_TAG: {
108 GstTagList *tags = NULL;
109 gst_message_parse_tag (message, &tags);
110- //audio->handle_tags (tags); // FIXME: uncomment when handle_tags() works well
111+ audio->handle_tags (tags);
112 gst_tag_list_free (tags);
113 break;
114 }
115@@ -272,8 +272,6 @@
116
117 void iAudio::handle_tags( GstTagList *tags )
118 {
119- // FIXME: this works very bad for now, so we still have to use TagLib
120-
121 gchar *title, *artist, *album, *info;
122
123 if( !gst_tag_list_get_string_index (tags, GST_TAG_TITLE, 0, &title) )
124
125=== modified file 'src/plugin-gstreamer-audio/plugin-gstreamer-audio.h'
126--- src/plugin-gstreamer-audio/plugin-gstreamer-audio.h 2012-04-13 12:53:01 +0000
127+++ src/plugin-gstreamer-audio/plugin-gstreamer-audio.h 2014-12-23 19:06:15 +0000
128@@ -3,10 +3,10 @@
129
130 #ifndef PLUGIN_LOADER
131
132-#include <taglib/fileref.h>
133+/*#include <taglib/fileref.h>
134 #include <taglib/mpegfile.h>
135 #include <taglib/attachedpictureframe.h>
136-#include <taglib/id3v2tag.h>
137+#include <taglib/id3v2tag.h>*/
138 #include <config.h>
139 #include <string>
140
141
142=== added directory 'src/plugin-xps'
143=== added file 'src/plugin-xps/Makefile.am'
144--- src/plugin-xps/Makefile.am 1970-01-01 00:00:00 +0000
145+++ src/plugin-xps/Makefile.am 2014-12-23 19:06:15 +0000
146@@ -0,0 +1,13 @@
147+plugindir = $(prefix)/lib/gloobus/
148+officeplugindir = $(prefix)/lib/gloobus/
149+
150+AM_CPPFLAGS += $(GTK_CFLAGS) $(GXPS_CFLAGS)
151+AM_LDFLAGS = $(GTK_LIBS) $(GXPS_LIBS)
152+
153+plugin_LTLIBRARIES = xps.la
154+xps_la_SOURCES = xps-plugin.cpp xps-loader.cpp
155+xps_la_LDFLAGS = -module -export-dynamic $(AM_LDFLAGS)
156+
157+noinst_HEADERS = \
158+ xps-loader.h \
159+ xps-plugin.h
160
161=== added file 'src/plugin-xps/xps-loader.cpp'
162--- src/plugin-xps/xps-loader.cpp 1970-01-01 00:00:00 +0000
163+++ src/plugin-xps/xps-loader.cpp 2014-12-23 19:06:15 +0000
164@@ -0,0 +1,106 @@
165+#include "xps-loader.h"
166+
167+#include "../gloobus-preview-defines.h"
168+
169+XpsLoader::XpsLoader ():xps_document_(NULL) {}
170+
171+XpsLoader::~XpsLoader ()
172+{
173+ if (xps_document_) {
174+ g_object_unref(xps_document_);
175+ }
176+}
177+
178+DocumentState XpsLoader::loadDocument( GFile *file )
179+{
180+ GError *error = NULL;
181+ DocumentState state = DOCUMENT_NONE;
182+
183+ GXPSFile * xps_file = gxps_file_new (file, &error);
184+ if (!xps_file) {
185+ g_warning ("Error opening XPS file: %s\n", error->message);
186+ g_error_free (error);
187+ return DOCUMENT_INVALID;
188+ }
189+
190+ xps_document_ = gxps_file_get_document (xps_file, 0, &error);
191+ if (!xps_document_) {
192+ g_warning ("Error loading XPS document: %s\n", error->message);
193+ g_error_free (error);
194+ state = DOCUMENT_INVALID;
195+ } else {
196+ state = DOCUMENT_LOADED;
197+ }
198+
199+ return state;
200+}
201+
202+int XpsLoader::getPagesNumber (void)
203+{
204+ return gxps_document_get_n_pages(xps_document_);
205+}
206+
207+void XpsLoader::getPageSize (int index, int *width, int *height)
208+{
209+ GError *error = NULL;
210+ GXPSPage *page = gxps_document_get_page (xps_document_, index, &error);
211+ if (!page) {
212+ g_warning ("Error loading page %d: %s\n", index, error->message);
213+ g_error_free (error);
214+ return;
215+ }
216+
217+ double page_width, page_height;
218+ gxps_page_get_size (page, &page_width, &page_height);
219+
220+ if (width) {
221+ *width = page_width;
222+ }
223+ if (height) {
224+ *height = page_height;
225+ }
226+
227+ g_object_unref(page);
228+}
229+
230+cairo_surface_t * XpsLoader::getPage(int index, double scale)
231+{
232+ GXPSPage *page;
233+ gdouble page_width, page_height;
234+ gdouble width, height;
235+ cairo_t *cr;
236+ cairo_surface_t *surface;
237+ GError *error = NULL;
238+
239+ page = gxps_document_get_page (xps_document_, index, &error);
240+ if (!page) {
241+ g_warning ("Error loading page %d: %s\n", index, error->message);
242+ g_error_free (error);
243+ return NULL;
244+ }
245+
246+ gxps_page_get_size (page, &page_width, &page_height);
247+ width = page_width * scale;
248+ height = page_height * scale;
249+
250+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
251+ cr = cairo_create (surface);
252+
253+ if (scale != 1.0) {
254+ cairo_scale (cr, scale, scale);
255+ }
256+ cairo_set_source_rgb (cr, 1., 1., 1.);
257+ cairo_paint (cr);
258+
259+ gxps_page_render (page, cr, &error);
260+
261+ cairo_destroy (cr);
262+ g_object_unref(page);
263+
264+ if (error) {
265+ g_warning ("Error rendering page %d: %s\n", index, error->message);
266+ g_error_free (error);
267+ }
268+
269+ return surface;
270+}
271
272=== added file 'src/plugin-xps/xps-loader.h'
273--- src/plugin-xps/xps-loader.h 1970-01-01 00:00:00 +0000
274+++ src/plugin-xps/xps-loader.h 2014-12-23 19:06:15 +0000
275@@ -0,0 +1,23 @@
276+#ifndef XPS_LOADER_H
277+#define XPS_LOADER_H
278+
279+#include <libgxps/gxps.h>
280+
281+#include "../document-loader.h"
282+
283+class XpsLoader : public DocumentLoader
284+{
285+ private:
286+ GXPSDocument *xps_document_;
287+
288+ public:
289+ XpsLoader ();
290+ virtual ~XpsLoader ();
291+
292+ virtual DocumentState loadDocument( GFile *file );
293+ virtual int getPagesNumber();
294+ virtual void getPageSize( int index, int *width, int *height );
295+ virtual cairo_surface_t *getPage( int index, double scale );
296+};
297+
298+#endif /* XPS_LOADER_H */
299
300=== added file 'src/plugin-xps/xps-plugin.cpp'
301--- src/plugin-xps/xps-plugin.cpp 1970-01-01 00:00:00 +0000
302+++ src/plugin-xps/xps-plugin.cpp 2014-12-23 19:06:15 +0000
303@@ -0,0 +1,14 @@
304+#include "../document-plugin.h"
305+#include "xps-loader.h"
306+
307+extern "C" interface * create() {
308+ return new DocumentPlugin(new XpsLoader());
309+}
310+
311+extern "C" void destroy(interface * p) {
312+ delete static_cast<DocumentPlugin*>(p);
313+}
314+
315+extern "C" int getVersion() {
316+ return MANAGER_VERSION;
317+}
318
319=== added file 'src/plugin-xps/xps-plugin.h'
320--- src/plugin-xps/xps-plugin.h 1970-01-01 00:00:00 +0000
321+++ src/plugin-xps/xps-plugin.h 2014-12-23 19:06:15 +0000
322@@ -0,0 +1,13 @@
323+#ifndef XPS_PLUGIN_H
324+#define XPS_PLUGIN_H
325+
326+#ifdef PLUGIN_LOADER
327+
328+PluginManager::register_plugin("xps");
329+
330+PluginManager::register_filetype("application/oxps", 1);
331+PluginManager::register_filetype("application/vnd.ms-xpsdocument",1);
332+
333+#endif
334+
335+#endif /* XPS_PLUGIN_H */

Subscribers

People subscribed via source and target branches