Package: gworkspace / 0.9.4-1

popplerkit.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
Description: Support PopplerKit.
 .
 GWorkspace uses PDFKit for the PDF inspector and extractor.  However,
 it can't be packaged for Debian as it is based on xpdf with the whole
 xpdf source bundled.  OTOH, PopplerKit has incomplete API and is
 unsupported upstream.
 .
 The current patch is not ready to be forwarded upstream:
 - additional testing is necessary;
 - need to check whether PDFKit build was not broken accidentally;
 - no support for the extractor yet (due to PoplerKit API limitations).
Author: Hubert Chathi <uhoreg@debian.org>
Author: Yavor Doganov <yavor@gnu.org>
Forwarded: no
Last-Update: 2017-12-23
---

--- gworkspace.orig/Inspector/ContentViewers/GNUmakefile.in
+++ gworkspace/Inspector/ContentViewers/GNUmakefile.in
@@ -29,6 +29,10 @@
   IBViewViewer
 endif
 
+ifeq ($(POPPLERKIT),yes)
+SUBPROJECTS += PdfViewer
+endif
+
 -include GNUmakefile.preamble
 
 -include GNUmakefile.local
--- gworkspace.orig/Inspector/ContentViewers/PdfViewer/GNUmakefile.in
+++ gworkspace/Inspector/ContentViewers/PdfViewer/GNUmakefile.in
@@ -9,7 +9,11 @@
 
 OBJCFLAGS += -Wall
 
+ifeq ($(PDFKIT),yes)
 PdfViewer_GUI_LIBS += -lPDFKit
+else
+PdfViewer_GUI_LIBS += -lPopplerKit
+endif
 
 PdfViewer_OBJC_FILES = PdfViewer.m 
 
--- gworkspace.orig/Inspector/aclocal.m4
+++ gworkspace/Inspector/aclocal.m4
@@ -48,4 +48,30 @@
 ])
 
 
+AC_DEFUN([GW_CHECK_POPPLERKIT],
+[AC_REQUIRE([AC_PROG_OBJC])
+AC_LANG_PUSH([Objective C])
 
+OLD_OBJCFLAGS=$OBJCFLAGS
+OBJCFLAGS="$OBJCFLAGS `gnustep-config --objc-flags`"
+OLD_LIBS="$LIBS"
+LIBS="$LIBS `gnustep-config --gui-libs` -lPopplerKit"
+
+AC_CACHE_CHECK([for PopplerKit], [gw_cv_lib_popplerkit],
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM(
+	[[@%:@import <PopplerKit/PopplerDocument.h>]],
+        [[[PopplerDocument class];]])],
+	[gw_cv_lib_popplerkit=yes],
+	[gw_cv_lib_popplerkit=no])])
+AS_IF([test "x$gw_cv_lib_popplerkit" = xyes],
+	[have_popplerkit=yes
+	AC_DEFINE([HAVE_POPPLERKIT], [1],
+		  [Define if the PopplerKit framework is available])],
+	[have_popplerkit=no])
+
+LIBS="$OLD_LIBS"
+OBJCFLAGS="$OLD_OBJCFLAGS"
+
+AC_LANG_POP([Objective C])
+AC_SUBST([have_popplerkit])
+])
--- gworkspace.orig/Inspector/configure.ac
+++ gworkspace/Inspector/configure.ac
@@ -88,7 +88,10 @@
 
 if test "$have_pdfkit" = "no"; then
   AC_MSG_NOTICE([The PDFKit framework can't be found.])
-  AC_MSG_NOTICE([The pdf viewer will not be built.])  
+  GW_CHECK_POPPLERKIT
+  AS_IF([test "$have_popplerkit" = no],
+    [AC_MSG_NOTICE([The PopplerKit framework can't be found.])
+     AC_MSG_NOTICE([The pdf viewer will not be built.])])
 fi
 
 AC_SUBST(have_pdfkit)
--- gworkspace.orig/Inspector/inspector.make.in
+++ gworkspace/Inspector/inspector.make.in
@@ -3,5 +3,6 @@
 #
 
 PDFKIT=@have_pdfkit@
+POPPLERKIT=@have_popplerkit@
 SH_PATH=@SH_PATH@
 FILE_PATH=@FILE_PATH@
--- gworkspace.orig/Inspector/ContentViewers/PdfViewer/PdfViewer.h
+++ gworkspace/Inspector/ContentViewers/PdfViewer/PdfViewer.h
@@ -44,8 +44,12 @@
 @class NSTextField;
 @class NSWorkspace;
 @class NSButton;
+#if !HAVE_POPPLERKIT
 @class PDFDocument;
 @class PDFImageRep;
+#else
+@class PopplerDocument;
+#endif
 @class NSImage;
 
 @interface PdfViewer : NSView <ContentViewersProtocol>
@@ -60,8 +64,13 @@
   NSButton *editButt;
 
   NSString *pdfPath;
+#if !HAVE_POPPLERKIT
   PDFDocument *pdfDoc;
   PDFImageRep *imageRep;
+#else
+  PopplerDocument *pdfDoc;
+  id <PopplerBufferedRenderer> pdfRenderer;
+#endif
   
   id <ContentInspectorProtocol>inspector;
   NSFileManager *fm;
--- gworkspace.orig/Inspector/ContentViewers/PdfViewer/PdfViewer.m
+++ gworkspace/Inspector/ContentViewers/PdfViewer/PdfViewer.m
@@ -22,11 +22,16 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
  */
 
+#include <config.h>
 #include <math.h>
 
 #import <AppKit/AppKit.h>
+#if !HAVE_POPPLERKIT
 #import <PDFKit/PDFDocument.h>
 #import <PDFKit/PDFImageRep.h>
+#else
+#import <PopplerKit/PopplerKit.h>
+#endif
 #import "PdfViewer.h"
 
 #define MAXPAGES 9999
@@ -38,8 +43,12 @@
 - (void)dealloc
 {
   TEST_RELEASE (pdfPath);	
+#if !HAVE_POPPLERKIT
   TEST_RELEASE (pdfDoc);
   TEST_RELEASE (imageRep);
+#else
+  TEST_RELEASE (pdfRenderer);
+#endif
   RELEASE (backButt);
   RELEASE (nextButt);
   RELEASE (scroll);
@@ -160,7 +169,11 @@
 
 - (void)displayPath:(NSString *)path
 {
+#if !HAVE_POPPLERKIT
   PDFDocument *doc;
+#else
+  PopplerDocument *doc;
+#endif
   
   ASSIGN (pdfPath, path);
 
@@ -170,11 +183,21 @@
   
   [editButt setEnabled: NO];	
   
+#if !HAVE_POPPLERKIT
   doc = [PDFDocument documentFromFile: pdfPath];
 
   if ([doc isOk] && ([doc errorCode] == 0)) {
-    int npages;
     NSSize imageSize;
+#else
+  NS_DURING
+    doc = [PopplerDocument documentWithPath: pdfPath];
+  NS_HANDLER
+    doc = nil;
+  NS_ENDHANDLER
+
+  if (doc) {
+#endif
+    int npages;
 	  NSBundle *bundle;
 	  NSString *imagePath;
 	  NSImage *miniPage;
@@ -236,6 +259,7 @@
 		[matrix sizeToCells];
 		RELEASE (miniPage);	    
 
+#if !HAVE_POPPLERKIT
     DESTROY (imageRep);
     ASSIGN (pdfDoc, doc);
 
@@ -243,6 +267,16 @@
                                     [pdfDoc pageHeight: 1]);
     imageRep = [[PDFImageRep alloc] initWithDocument: pdfDoc];
     [imageRep setSize: imageSize];
+#else
+    DESTROY (pdfRenderer);
+    ASSIGN (pdfDoc, doc);
+
+    if ([PopplerCairoImageRenderer isSupported])
+      pdfRenderer = [[PopplerCairoImageRenderer alloc] initWithDocument:
+							 pdfDoc];
+    else
+      pdfRenderer = [[PopplerSplashRenderer alloc] initWithDocument: pdfDoc];
+#endif
 
   } else {
     if (valid) {
@@ -286,17 +320,28 @@
     return;
 
   imsize = [imageView bounds].size;
+#if !HAVE_POPPLERKIT
   unscaledSize = NSMakeSize([pdfDoc pageWidth: index], [pdfDoc pageHeight: index]);
+#else
+  unscaledSize = [[pdfDoc page: index] size];
+  float scaleFactor = 1.0;
+  NSImageRep *imageRep;
+#endif
 
   if ((imsize.width < unscaledSize.width) || (imsize.height < unscaledSize.height))
     {
       float rw, rh;
+#if !HAVE_POPPLERKIT
       NSSize scaledSize;
       float xfactor, yfactor;  
+#endif
 
       rw = imsize.width / unscaledSize.width;
       rh = imsize.height / unscaledSize.height;
 
+#if HAVE_POPPLERKIT
+      scaleFactor = rw <= rh ? rw : rh;
+#else
       if (rw <= rh)
 	{
 	  scaledSize.width = unscaledSize.width * rw;
@@ -312,10 +357,15 @@
       yfactor = scaledSize.height / unscaledSize.height * PDFResolution;
 
       [imageRep setResolution: (xfactor < yfactor ? xfactor : yfactor)];
+#endif
     }
 
+#if !HAVE_POPPLERKIT
   [imageRep setPageNum: index];
-  
+#else
+  imageRep = [pdfRenderer renderPage: [pdfDoc page: index] scale: scaleFactor];
+#endif
+
   image = [[NSImage alloc] initWithSize: [imageRep size]];
   [image setBackgroundColor: [NSColor whiteColor]];
   [image setScalesWhenResized: YES];