Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 djview4 (4.10.6-3) unstable; urgency=medium
 .
   * update QT_SELECT value (closes: #880327)
Author: Barak A. Pearlmutter <bap@debian.org>
Bug-Debian: https://bugs.debian.org/880327

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2017-10-30

--- djview4-4.10.6.orig/mac/qlgenerator_src/GeneratePreviewForURL.m
+++ djview4-4.10.6/mac/qlgenerator_src/GeneratePreviewForURL.m
@@ -1,9 +1,43 @@
+
 #include <CoreFoundation/CoreFoundation.h>
 #include <CoreServices/CoreServices.h>
 #include <QuickLook/QuickLook.h>
+
+#import <Foundation/Foundation.h>
 #import <Cocoa/Cocoa.h>
 
-#include "ddjvuRef.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "libdjvu/ddjvuapi.h"
+
+
+/* handle ddjvu messages */
+
+static void
+handle(ddjvu_context_t *ctx, int wait)
+{
+  const ddjvu_message_t *msg;
+  if (!ctx)
+    return;
+  if (wait)
+    msg = ddjvu_message_wait(ctx);
+  while ((msg = ddjvu_message_peek(ctx)))
+    {
+      switch(msg->m_any.tag)
+        {
+	case DDJVU_ERROR:
+	  NSLog(@"%s", msg->m_error.message);
+	  if (msg->m_error.filename)
+	    NSLog(@"'%s:%d'",
+		  msg->m_error.filename, msg->m_error.lineno);
+	default:
+	  break;
+        }
+      ddjvu_message_pop(ctx);
+    }
+}
 
 /* -----------------------------------------------------------------------------
    Generate a preview for file
@@ -16,150 +50,160 @@ GeneratePreviewForURL(void *thisInterfac
                       QLPreviewRequestRef preview,
                       CFURLRef url,
                       CFStringRef contentTypeUTI,
-                      CFDictionaryRef options)
+                      CFDictionaryRef cfOptions)
 {
-    CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview);
-    char *ddjvu = ddjvuPath(bundle);
-    if (ddjvu != NULL) {
-        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];        
-        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-        NSDictionary *domain = [defaults persistentDomainForName:@"org.djvu.qlgenerator"];
-        CFUUIDRef uuid = NULL;
-        CFStringRef uuidString;
-        BOOL debug = FALSE;
-        NSString *tmpPath = nil;
-        
-        if (domain && [domain objectForKey:@"previewpages"])
-            if ([[domain objectForKey:@"previewpages"] intValue] == 0)
-                goto poppool;
-
-        if (domain && [domain objectForKey:@"debug"]) {
-            debug = [[domain objectForKey:@"debug"] boolValue];
-        }
-        
-        uuid = CFUUIDCreate(kCFAllocatorDefault);
-        if (uuid) {
-            uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuid);
-            if (uuidString) {
-                tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:
-                           [NSString stringWithFormat:@"djvuql-%@", uuidString]];
-                CFRelease(uuidString);
-            }
-            CFRelease(uuid);
-        }
-        if (tmpPath) {
-            const char *cmd = NULL;
-            CFStringRef cmdRef;
-            int page = 0;
-            int pages = 1;
-            int maxpages = 5;
-            int width = 612;    // default 8.5x11 in points
-            int height = 792;
-            CGSize size;
-            MDItemRef mditem = NULL;
-            NSString *source = (NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
-            NSString *dest = nil;
-            NSFileManager *fmgr = [NSFileManager defaultManager];
-            [fmgr createDirectoryAtPath:tmpPath attributes:nil];
-            
-            mditem = MDItemCreate(kCFAllocatorDefault, (CFStringRef)source);
-            if (mditem) {
-                CFTypeRef ref = NULL;
-                ref = MDItemCopyAttribute(mditem, kMDItemNumberOfPages);
-                if (ref) {
-                    CFNumberGetValue(ref, kCFNumberIntType, &pages);
-                    CFRelease(ref);
-                }
-                ref = MDItemCopyAttribute(mditem, kMDItemPageWidth);
-                if (ref) {
-                    CFNumberGetValue(ref, kCFNumberIntType, &width);
-                    CFRelease(ref);
-                }
-                ref = MDItemCopyAttribute(mditem, kMDItemPageHeight);
-                if (ref) {
-                    CFNumberGetValue(ref, kCFNumberIntType, &height);
-                    CFRelease(ref);
-                }
-                CFRelease(mditem);                
-            }
-            
-            if (domain && [domain objectForKey:@"previewpages"])
-                maxpages = [[domain objectForKey:@"previewpages"] intValue];
-            
-            if (debug) {
-                NSLog(@"metadata: pages=%d, width=%d, height=%d", pages, width, height);
-                NSLog(@"maxpages=%d", maxpages);                
-            }
-                        
-            CGRect rect = CGRectMake(0, 0, width, height);
-            CGContextRef c;
-            c = QLPreviewRequestCreatePDFContext(preview, &rect, NULL, NULL);
-            
-            page = 0;
-            do {
-                page++;
-                dest = [tmpPath stringByAppendingPathComponent:[[source lastPathComponent] stringByAppendingFormat:@"_t_p%04d.tiff", page]];
-                size = CGSizeMake(width, height);
-                cmdRef = CFStringCreateWithFormat(NULL, NULL, 
-						  CFSTR("\"%s\" -format=tiff -page=%d -size=%dx%d \"%s\" \"%s\""), 
-						  ddjvu, page, width, height, 
-						  [source fileSystemRepresentation], [dest fileSystemRepresentation]);
-                cmd = CFStringGetCStringPtr(cmdRef, CFStringGetSystemEncoding());
-                if (cmd != NULL) {
-                    if (debug)
-                        NSLog(@"%s", cmd);
-                    if ((system(cmd) == 0) && ([fmgr fileExistsAtPath:dest])) {
-                        NSURL *durl = [NSURL fileURLWithPath:dest];
-                        CGImageSourceRef  sourceRef;
-                        
-                        sourceRef = CGImageSourceCreateWithURL((CFURLRef)durl, NULL);
-                        if(sourceRef) {
-                            CGImageRef imageRef = NULL;
-                            imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL);
-                            if (imageRef) {
-                                CGFloat offset = height * (page-1);
-                                CGRectOffset(rect, 0.0, offset);
-                                CGPDFContextBeginPage(c, NULL);
-                                CGContextSaveGState(c);
-                                CGContextDrawImage(c, rect, imageRef);
-                                if (page == maxpages && maxpages < pages) {
-                                    CGAffineTransform m;
-                                    CFURLRef more = CFBundleCopyResourceURL(bundle, CFSTR("more_pages"), CFSTR("pdf"), NULL);
-                                    CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL(more);
-                                    CGPDFPageRef pdf = CGPDFDocumentGetPage(doc, 1);
-                                    CGFloat offset = height * page;
-                                    CGRectOffset(rect, 0.0, offset);
-                                    CGContextSaveGState(c);
-                                    m = CGPDFPageGetDrawingTransform(pdf, kCGPDFMediaBox, rect, 0, true);
-                                    CGContextConcatCTM(c, m);
-                                    CGContextDrawPDFPage(c, pdf);
-                                    CGContextRestoreGState(c);
-                                    CFRelease(doc);
-                                }
-                                CGContextRestoreGState(c);
-                                CGPDFContextEndPage(c);
-                                CFRelease(imageRef);
-                            }
-                            CFRelease(sourceRef);
-                        }
-                    }
-                }
-                CFRelease(cmdRef);
-            } while (page < pages && page < maxpages);
-
-            CGPDFContextClose(c);
-            QLPreviewRequestFlushContext(preview, c);
-            CFRelease(c);
-            [fmgr removeFileAtPath:tmpPath handler:nil];
-            [source release];
-        }
-    poppool:
-        [pool release];
+  ddjvu_context_t *ctx = 0;
+  ddjvu_document_t *doc = 0;
+  ddjvu_format_t *fmt = 0;
+  ddjvu_page_t *pag = 0;
+  CGContextRef *cg = 0;
+  
+  @autoreleasepool {
+    
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    NSDictionary *domain = [defaults persistentDomainForName:@"org.djvu.qlgenerator"];
+    NSString *path = [(NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle) autorelease];
+    int width, height;
+    int npages, page, maxpages = 5;
+    
+    /* Defaults */
+    if (domain && [domain objectForKey:@"previewpages"])
+      maxpages = [[domain objectForKey:@"previewpages"] intValue];
+    if (maxpages <= 0)
+      goto pop;
+    
+    /* Create context and document */
+    if (! (ctx = ddjvu_context_create([[[NSProcessInfo processInfo] processName]
+					cStringUsingEncoding:NSASCIIStringEncoding]))) {
+      NSLog(@"Cannot create djvu context for '%@'.", path);
+      goto pop;
+    }
+    if (! (doc = ddjvu_document_create_by_filename(ctx, [path fileSystemRepresentation], TRUE))) {
+      NSLog(@"Cannot open djvu document '%@'.", path);
+      goto pop;
     }
-    return noErr;
+    while (! ddjvu_document_decoding_done(doc))
+      handle(ctx, TRUE);
+    if (ddjvu_document_decoding_error(doc)) {
+      NSLog(@"Djvu document decoding error '%@'.", path);
+      goto pop;
+    }
+    
+    /* Loop on pages */
+    fmt = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL);
+    ddjvu_format_set_row_order(fmt, TRUE);
+    npages = ddjvu_document_get_pagenum(doc);
+    for (page=0; page<npages && page<maxpages; page++)
+      {
+        int pw, ph, dpi;
+        ddjvu_rect_t rrect;
+        NSBitmapImageRep *bitmap;
+        NSDictionary *dict;
+        NSData *data;
+        CGRect cgrect;
+        CGImageRef cgimg;
+
+        @autoreleasepool {
+          
+          /* Decode page */
+          pag = ddjvu_page_create_by_pageno(doc, page);
+          while (! ddjvu_page_decoding_done(pag))
+            handle(ctx, TRUE);
+          if (ddjvu_page_decoding_error(pag)) {
+            NSLog(@"Djvu page decoding error '%@' (page %d).", path, page);
+            goto pop;
+          }
+          
+          /* Obtain page size at 100 dpi */
+          pw = ddjvu_page_get_width(pag);
+          ph = ddjvu_page_get_height(pag);
+          dpi = ddjvu_page_get_resolution(pag);
+          if (pw <= 0 || ph <= 0 || dpi <= 0) {
+            NSLog(@"Djvu page decoding error '%@' (page %d).", path, page);
+            goto pop;
+          }
+          rrect.x = rrect.y = 0;
+          rrect.w = pw * 150 / dpi;
+          rrect.h = ph * 150 / dpi;
+          
+          /* Render page */
+	  bitmap = [[NSBitmapImageRep alloc] autorelease];
+	  bitmap = [bitmap initWithBitmapDataPlanes:NULL
+					 pixelsWide:rrect.w
+					 pixelsHigh:rrect.h
+				      bitsPerSample:8
+				    samplesPerPixel:3
+					   hasAlpha:FALSE
+					   isPlanar:NO
+				     colorSpaceName:NSCalibratedRGBColorSpace
+					bytesPerRow:rrect.w * 3
+				       bitsPerPixel:24 ];
+	if (! ddjvu_page_render(pag, DDJVU_RENDER_COLOR, &rrect, &rrect,
+                                  fmt, rrect.w * 3, [bitmap bitmapData]) ) {
+            NSLog(@"Djvu page rendering error '%@' (page %d).", path, page);
+            goto pop;
+          }
+	  
+          /* Draw bitmap into CG */
+          cgrect.origin.x = cgrect.origin.y = 0;
+          cgrect.size.width = rrect.w;
+          cgrect.size.height = rrect.h;
+          [bitmap setSize:cgrect.size];
+          if (! cg)
+            cg = QLPreviewRequestCreatePDFContext(preview, &cgrect, NULL, NULL);
+          data = [NSData dataWithBytes:&cgrect length:sizeof(cgrect)];
+          dict = [NSDictionary dictionaryWithObject:data forKey:kCGPDFContextMediaBox];
+          CGPDFContextBeginPage(cg, (CFDictionaryRef)dict);
+          cgimg = [bitmap CGImage];
+          CGContextDrawImage(cg, cgrect, cgimg);
+
+          /* Show when there are more pages (old qlgenerator) */
+          if (page+1 == maxpages && page+1 < npages) {
+            CGAffineTransform m;
+            CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview);
+            CFURLRef more = CFBundleCopyResourceURL(bundle,CFSTR("more_pages"),CFSTR("pdf"),NULL);
+            CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL(more);
+            CGPDFPageRef pdf = CGPDFDocumentGetPage(doc, 1);
+            CGContextSaveGState(cg);
+            m = CGPDFPageGetDrawingTransform(pdf, kCGPDFMediaBox, cgrect, 0, true);
+            CGContextConcatCTM(cg, m);
+            CGContextDrawPDFPage(cg, pdf);
+            CGContextRestoreGState(cg);
+            CFRelease(doc);
+          }
+
+          /* Cleanup */
+          CGPDFContextEndPage(cg);
+          ddjvu_page_release(pag);
+          pag = 0;
+        }  /* @autoreleasepool */
+      }
+    /* Flush pdf context */
+    if (cg)
+      {
+        CGPDFContextClose(cg);
+	QLPreviewRequestFlushContext(preview, cg);	
+      }
+  } /* @autoreleasepool */
+  /* Cleanup */
+ pop:
+  if (cg)
+    CFRelease(cg);
+  if (pag)
+    ddjvu_page_release(pag);
+  if (fmt)
+    ddjvu_format_release(fmt);
+  if (doc)
+    ddjvu_document_release(doc);
+  if (ctx)
+    ddjvu_context_release(ctx);
+  return noErr;
 }
 
+
 void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
 {
     // implement only if supported
 }
+
+
--- djview4-4.10.6.orig/mac/qlgenerator_src/GenerateThumbnailForURL.m
+++ djview4-4.10.6/mac/qlgenerator_src/GenerateThumbnailForURL.m
@@ -1,10 +1,43 @@
+
 #include <CoreFoundation/CoreFoundation.h>
 #include <CoreServices/CoreServices.h>
 #include <QuickLook/QuickLook.h>
+
+#import <Foundation/Foundation.h>
 #import <Cocoa/Cocoa.h>
-#include <ApplicationServices/ApplicationServices.h>
 
-#include "ddjvuRef.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "libdjvu/ddjvuapi.h"
+
+
+/* handle ddjvu messages */
+
+static void
+handle(ddjvu_context_t *ctx, int wait)
+{
+  const ddjvu_message_t *msg;
+  if (!ctx)
+    return;
+  if (wait)
+    msg = ddjvu_message_wait(ctx);
+  while ((msg = ddjvu_message_peek(ctx)))
+    {
+      switch(msg->m_any.tag)
+        {
+	case DDJVU_ERROR:
+	  NSLog(@"%s", msg->m_error.message);
+	  if (msg->m_error.filename)
+	    NSLog(@"'%s:%d'",
+		  msg->m_error.filename, msg->m_error.lineno);
+	default:
+	  break;
+        }
+      ddjvu_message_pop(ctx);
+    }
+}
 
 /* -----------------------------------------------------------------------------
     Generate a thumbnail for file
@@ -20,87 +53,84 @@ GenerateThumbnailForURL(void *thisInterf
                         CFDictionaryRef options,
                         CGSize maxSize)
 {
-    char *ddjvu = ddjvuPath(QLThumbnailRequestGetGeneratorBundle(thumbnail));
-    if (ddjvu != NULL) {
-        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-        NSDictionary *domain = [defaults persistentDomainForName:@"org.djvu.qlgenerator"];
-        CFUUIDRef uuid;
-        CFStringRef uuidString;
-        NSString *tmpPath = nil;
-        BOOL debug = FALSE;
-        
-        if (domain && [domain objectForKey:@"debug"]) {
-            debug = [[domain objectForKey:@"debug"] boolValue];
-        }
-        if (domain && [domain objectForKey:@"thumbnail"] &&
-            ([[domain objectForKey:@"thumbnail"] boolValue] == FALSE))
-        {
-            if (debug)
-                NSLog(@"skip thumbnail for %@", url);
-            CFStringRef ext = CFURLCopyPathExtension(url);
-            if (ext) {
-                NSImage *img = [[NSWorkspace sharedWorkspace] iconForFileType:(NSString*)ext];
-                if (img) {
-                    NSData *data = [img TIFFRepresentation];
-                    QLThumbnailRequestSetImageWithData(thumbnail, (CFDataRef)data, NULL);
-                }
-                CFRelease(ext);
-            }
-        } else {
-            if (debug) {
-                CFShow(contentTypeUTI);
-                CFShow(options);            
-            }
-            
-            uuid = CFUUIDCreate(kCFAllocatorDefault);
-            if (uuid) {
-                uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuid);
-                if (uuidString) {
-                    tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:
-                               [NSString stringWithFormat:@"djvuql-%@", uuidString]];
-                    CFRelease(uuidString);
-                }
-                CFRelease(uuid);
-            }
-            if (tmpPath) {
-                NSFileManager *fmgr = [NSFileManager defaultManager];
-                const char *cmd = NULL;
-                CFStringRef cmdRef;
-                int page = 1;
-                NSString *source = (NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
-                NSString *dest = [tmpPath stringByAppendingPathComponent:[[source lastPathComponent] stringByAppendingFormat:@"_t_p%d.tiff", page]];
-                [fmgr createDirectoryAtPath:tmpPath attributes:nil];            
-                cmdRef = CFStringCreateWithFormat(NULL, NULL, 
-						  CFSTR("\"%s\" -format=tiff -page=%d -size=%dx%d \"%s\" \"%s\""), 
-						  ddjvu, page, (int)maxSize.width, (int)maxSize.height, 
-						  [source fileSystemRepresentation], [dest fileSystemRepresentation]);
-                cmd = CFStringGetCStringPtr(cmdRef, CFStringGetSystemEncoding());
-                if (cmd != NULL) {
-                    if (debug)
-                        NSLog(@"ddjvu: %s", cmd);
-                    if (system(cmd) == 0) {
-                        NSURL *durl = [NSURL fileURLWithPath:dest];
-                        CGImageRef imageRef = NULL;
-                        CGImageSourceRef  sourceRef;
-                        
-                        sourceRef = CGImageSourceCreateWithURL((CFURLRef)durl, NULL);
-                        if(sourceRef) {
-                            imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL);
-                            if (imageRef)
-                                QLThumbnailRequestSetImage(thumbnail, imageRef, NULL);
-                            CFRelease(sourceRef);
-                        }
-                    }
-                }
-                [fmgr removeFileAtPath:tmpPath handler:nil];
-                CFRelease(cmdRef);
-                [source release];
-            }
-        }
-        [pool release];
+  ddjvu_context_t *ctx = 0;
+  ddjvu_document_t *doc = 0;
+  ddjvu_format_t *fmt = 0;
+  
+  @autoreleasepool {
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    NSDictionary *domain = [defaults persistentDomainForName:@"org.djvu.qlgenerator"];
+    NSString *path = [(NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle) autorelease];
+    NSBitmapImageRep *bitmap;
+    NSSize size;
+    int width, height;
+    
+    /* If not generating thumbnails */
+    if (domain && [domain objectForKey:@"thumbnails"])
+      if ([[domain objectForKey:@"thumbnails"] boolValue] == FALSE)
+	goto pop;
+    
+    /* Create context and document */
+    if (! (ctx = ddjvu_context_create([[[NSProcessInfo processInfo] processName]
+					cStringUsingEncoding:NSASCIIStringEncoding]))) {
+      NSLog(@"Cannot create djvu context for '%@'.", path);
+      goto pop;
+    }
+    if (! (doc = ddjvu_document_create_by_filename_utf8(ctx, [path fileSystemRepresentation], TRUE))) {
+      NSLog(@"Cannot open djvu document '%@'.", path);
+      goto pop;
+    }
+    while (! ddjvu_document_decoding_done(doc))
+      handle(ctx, TRUE);
+    if (ddjvu_document_decoding_error(doc)) {
+      NSLog(@"Djvu document decoding error '%@'.", path);
+      goto pop;
+    }
+    
+    /* Prepare thumbnail */
+    while (ddjvu_thumbnail_status(doc, 0, 1) < DDJVU_JOB_OK)
+      handle(ctx, TRUE);
+    if (ddjvu_thumbnail_status(doc, 0, 0) != DDJVU_JOB_OK) {
+      NSLog(@"Djvu thumbnail generation error '%@'.", path);
+      goto pop;
+    }
+    
+    /* Get thumbnail image */
+    width = (int) maxSize.width;
+    height = (int) maxSize.height;
+    fmt = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL);
+    ddjvu_format_set_row_order(fmt, TRUE);
+    bitmap = [[NSBitmapImageRep alloc] autorelease];
+    bitmap = [bitmap initWithBitmapDataPlanes:NULL
+				   pixelsWide:width
+				   pixelsHigh:height
+				bitsPerSample:8
+			      samplesPerPixel:3
+				     hasAlpha:FALSE
+				     isPlanar:NO
+			       colorSpaceName:NSCalibratedRGBColorSpace
+				  bytesPerRow:width*3
+				 bitsPerPixel:24 ];
+    if (!ddjvu_thumbnail_render(doc, 0, &width, &height, fmt, width*3, [bitmap bitmapData])) {
+      NSLog(@"Djvu thumbnail rendering error '%@'.", path);
+      goto pop;
     }
-    return noErr;
+    size.width = width;
+    size.height = height;
+    [bitmap setSize: size];
+    [bitmap setPixelsWide: width];
+    [bitmap setPixelsHigh: height];
+    QLThumbnailRequestSetImageWithData(thumbnail, (CFDataRef)[bitmap TIFFRepresentation], NULL);
+  }
+  /* Cleanup */
+ pop:
+  if (fmt)
+    ddjvu_format_release(fmt);
+  if (doc)
+    ddjvu_document_release(doc);
+  if (ctx)
+    ddjvu_context_release(ctx);
+  return noErr;
 }
 
 void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)
--- djview4-4.10.6.orig/mac/qlgenerator_src/Makefile.am
+++ djview4-4.10.6/mac/qlgenerator_src/Makefile.am
@@ -4,10 +4,11 @@ mactoolsdir = ${libdir}/djview/mactools
 mactools_LTLIBRARIES = qlgenerator.la
 
 qlgenerator_la_SOURCES = \
-  GeneratePreviewForURL.m GenerateThumbnailForURL.m \
-  ddjvuRef.h ddjvuRef.c main.c 
+  GeneratePreviewForURL.m GenerateThumbnailForURL.m main.c
 
 qlgenerator_la_OBJCFLAGS = -w
+qlgenerator_la_CFLAGS = ${DDJVUAPI_CFLAGS}
+qlgenerator_la_LIBADD = ${DDJVUAPI_LIBS} 
 
 qlgenerator_la_LDFLAGS = -module -avoid-version \
   -framework System -framework CoreFoundation -framework CoreServices \
--- djview4-4.10.6.orig/mac/qlgenerator_src/main.c
+++ djview4-4.10.6/mac/qlgenerator_src/main.c
@@ -37,19 +37,27 @@
 // -----------------------------------------------------------------------------
 
 // The thumbnail generation function to be implemented in GenerateThumbnailForURL.c
-OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize);
-void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail);
+OSStatus
+GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail,
+			CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options,
+			CGSize maxSize);
+
+void
+CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail);
 
 // The preview generation function to be implemented in GeneratePreviewForURL.c
-OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);
-void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview);
+OSStatus
+GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
+		      CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);
+
+void
+CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview);
 
 // The layout for an instance of QuickLookGeneratorPlugIn
-typedef struct __QuickLookGeneratorPluginType
-{
-    void        *conduitInterface;
-    CFUUIDRef    factoryID;
-    UInt32       refCount;
+typedef struct __QuickLookGeneratorPluginType {
+  void        *conduitInterface;
+  CFUUIDRef    factoryID;
+  UInt32       refCount;
 } QuickLookGeneratorPluginType;
 
 // -----------------------------------------------------------------------------
--- djview4-4.10.6.orig/mac/skel/Library/QuickLook/DjVu.qlgenerator/Contents/Info.plist
+++ djview4-4.10.6/mac/skel/Library/QuickLook/DjVu.qlgenerator/Contents/Info.plist
@@ -3,7 +3,7 @@
 <plist version="1.0">
 <dict>
 	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
+	<string>en</string>
 	<key>CFBundleDocumentTypes</key>
 	<array>
 		<dict>
@@ -11,16 +11,14 @@
 			<string>QLGenerator</string>
 			<key>LSItemContentTypes</key>
 			<array>
-				<string>org.djvu.DjView</string>
 				<string>org.djvuzone.djvulibre.djvu</string>
 				<string>com.lizardtech.djvu</string>
+				<string>public.djvu</string>
 			</array>
 		</dict>
 	</array>
 	<key>CFBundleExecutable</key>
 	<string>djvu</string>
-	<key>CFBundleGetInfoString</key>
-	<string>1.1, Copyright 2007, 2009 Corpus Callosum Corporation</string>
 	<key>CFBundleIdentifier</key>
 	<string>org.djvu.qlgenerator</string>
 	<key>CFBundleInfoDictionaryVersion</key>
@@ -28,9 +26,9 @@
 	<key>CFBundleName</key>
 	<string>djvu</string>
 	<key>CFBundleShortVersionString</key>
-	<string>1.1</string>
+	<string>3.5.21</string>
 	<key>CFBundleVersion</key>
-	<string>1.1</string>
+	<string>3.5.21</string>
 	<key>CFPlugInDynamicRegisterFunction</key>
 	<string></string>
 	<key>CFPlugInDynamicRegistration</key>
@@ -49,8 +47,14 @@
 	</dict>
 	<key>CFPlugInUnloadFunction</key>
 	<string></string>
+	<key>NSHumanReadableCopyright</key>
+	<string>Copyright 2016 Leon Bottou</string>
 	<key>QLNeedsToBeRunInMainThread</key>
 	<false/>
+	<key>QLPreviewHeight</key>
+	<real>600</real>
+	<key>QLPreviewWidth</key>
+	<real>800</real>
 	<key>QLSupportsConcurrentRequests</key>
 	<true/>
 	<key>QLThumbnailMinimumSize</key>
--- djview4-4.10.6.orig/mac/skel/Library/Spotlight/DjVu.mdimporter/Contents/Info.plist
+++ djview4-4.10.6/mac/skel/Library/Spotlight/DjVu.mdimporter/Contents/Info.plist
@@ -3,22 +3,14 @@
 <plist version="1.0">
 <dict>
 	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
+	<string>en</string>
 	<key>CFBundleDocumentTypes</key>
 	<array>
 		<dict>
-			<key>CFBundleTypeExtensions</key>
-			<array>
-				<string>djvu</string>
-				<string>djv</string>
-			</array>
-			<key>CFBundleTypeName</key>
-			<string>DjVu file</string>
 			<key>CFBundleTypeRole</key>
 			<string>MDImporter</string>
 			<key>LSItemContentTypes</key>
 			<array>
-				<string>org.djvu.DjView</string>
 				<string>org.djvuzone.djvulibre.djvu</string>
 				<string>com.lizardtech.djvu</string>
 				<string>public.djvu</string>
@@ -27,8 +19,6 @@
 	</array>
 	<key>CFBundleExecutable</key>
 	<string>DjVu</string>
-	<key>CFBundleGetInfoString</key>
-	<string>1.3, Copyright Corpus Callosum Corporation 2006</string>
 	<key>CFBundleIdentifier</key>
 	<string>org.djvuzone.djvulibre.MDImporter.DjVu</string>
 	<key>CFBundleInfoDictionaryVersion</key>
@@ -36,7 +26,7 @@
 	<key>CFBundleName</key>
 	<string>DjVu Importer for Spotlight</string>
 	<key>CFBundleShortVersionString</key>
-	<string>1.3</string>
+	<string>3.5.21</string>
 	<key>CFBundleVersion</key>
 	<string>3.5.21</string>
 	<key>CFPlugInDynamicRegisterFunction</key>
@@ -57,6 +47,10 @@
 	</dict>
 	<key>CFPlugInUnloadFunction</key>
 	<string></string>
+	<key>LSMinimumSystemVersion</key>
+	<string>10.7</string>
+	<key>NSHumanReadableCopyright</key>
+	<string>Copyright Corpus Callosum Corporation 2006</string>
 	<key>UTExportedTypeDeclarations</key>
 	<array>
 		<dict>
@@ -77,35 +71,6 @@
 			<key>UTTypeTagSpecification</key>
 			<dict>
 				<key>com.apple.ostype</key>
-				<string>AT&amp;T</string>
-				<key>public.filename-extension</key>
-				<array>
-					<string>djvu</string>
-					<string>djv</string>
-				</array>
-			</dict>
-		</dict>
-	</array>
-	<key>UTImportedTypeDeclarations</key>
-	<array>
-		<dict>
-			<key>UTTypeConformsTo</key>
-			<array>
-				<string>com.lizardtech.djvu</string>
-				<string>org.djvuzone.djvulibre.djvu</string>
-				<string>public.djvu</string>
-				<string>public.composite-content</string>
-				<string>public.data</string>
-			</array>
-			<key>UTTypeDescription</key>
-			<string>DjVu File</string>
-			<key>UTTypeIdentifier</key>
-			<string>com.lizardtech.djvu</string>
-			<key>UTTypeReferenceURL</key>
-			<string>http://www.lizardtech.com/</string>
-			<key>UTTypeTagSpecification</key>
-			<dict>
-				<key>com.apple.ostype</key>
 				<string>AT&amp;T</string>
 				<key>public.filename-extension</key>
 				<array>
--- djview4-4.10.6.orig/nsdejavu/nsdejavu.1.in
+++ djview4-4.10.6/nsdejavu/nsdejavu.1.in
@@ -213,7 +213,7 @@ tag:
 .SH INTERFACING THE DJVIEW PLUGIN WITH JAVASCRIPT
 Recent versions of the 
 .B djview4
-plugin can be controlled from the JavaScript intepreter of 
+plugin can be controlled from the JavaScript interpreter of 
 browsers implementing the Mozilla NPRuntime API.
 To access the plugin object,
 include the attribute
--- djview4-4.10.6.orig/src/djview.1
+++ djview4-4.10.6/src/djview.1
@@ -755,7 +755,7 @@ is active.
 Most features can be accessed using the menus, 
 the toolbar, the side bar or the pop-up menu
 shown when the right mouse button is depressed over a DjVu image.  
-Detailled help can be accessed by clicking the contextual 
+Detailed help can be accessed by clicking the contextual 
 help icon from the toolbar and then clicking on various 
 section of the djview user interface.
 
--- djview4-4.10.6.orig/src/djview.cpp
+++ djview4-4.10.6/src/djview.cpp
@@ -137,7 +137,12 @@ QDjViewApplication::QDjViewApplication(i
   extern void qt_mac_set_native_menubar(bool);
   qt_mac_set_native_menubar(false);
 #endif
-
+  
+  // Enable highdpi pixmaps
+#if QT_VERSION >= 0x50200
+  setAttribute(Qt::AA_UseHighDpiPixmaps, true);
+#endif
+  
   // Wire session management signals
   connect(this, SIGNAL(saveStateRequest(QSessionManager&)),
           this, SLOT(saveSessionState(QSessionManager&)) );
--- djview4-4.10.6.orig/src/djview.plist
+++ djview4-4.10.6/src/djview.plist
@@ -51,7 +51,9 @@
         <true/>
 	<key>LSItemContentTypes</key>
 	<array>
+	  <string>org.djvuzone.djvulibre.djvu</string>
 	  <string>com.lizardtech.djvu</string>
+	  <string>public.djvu</string>
 	</array>
       </dict>
     </array>
--- djview4-4.10.6.orig/src/djview.pro
+++ djview4-4.10.6/src/djview.pro
@@ -59,7 +59,7 @@ macx {
   RESOURCES.files = images/DjVu.icns
   QMAKE_BUNDLE_DATA += RESOURCES
   QMAKE_INFO_PLIST = djview.plist
-  QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
+  QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
 } 
 
 # --- windows stuff
--- djview4-4.10.6.orig/src/djview_cs.ts
+++ djview4-4.10.6/src/djview_cs.ts
@@ -2239,7 +2239,7 @@ Chcete jej nahradit?</translation>
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;Informace o dokumentu&lt;/b&gt;&lt;br/&gt;Tento panel zobrazuje informace o dokumentu a jeho souborech, z kterých se skládá. Na záložce &lt;tt&gt;Soubor&lt;/tt&gt; uvidíte informace o souboru vybraném v seznamu podílových souborů. Dvojklikem na podílový soubor zobrazíte odpovídající stránku v hlavním okně.&lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/djview_de.ts
+++ djview4-4.10.6/src/djview_de.ts
@@ -2251,7 +2251,7 @@ Soll die Datei überschrieben werden?</t
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;Dokument Informationen&lt;/b&gt;&lt;br&gt;Diese Seite zeigt Informationen über das Dokument und seine abhängigen Dateien. Die Detailinformationen zu der jeweils ausgewählten Datei findet man im &lt;tt&gt;Datei&lt;/tt&gt; tab. Durch einen Doppelklick wird die jeweilige Seite im Hauptfenster dargestellt. &lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/djview_es.ts
+++ djview4-4.10.6/src/djview_es.ts
@@ -2247,7 +2247,7 @@ Do you want to replace it?</source>
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;Información del documento&lt;/b&gt;&lt;br&gt;Este panel muestra información acerca del documento y sus componentes. Seleccionar un componente mostrara información detallada en la pestaña &lt;tt&gt;Archivo&lt;/tt&gt;. Doble click en un componente mostrara la correspondiente página en la ventana principal. &lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/djview_fr.ts
+++ djview4-4.10.6/src/djview_fr.ts
@@ -2334,7 +2334,7 @@ Voulez-vous le remplacer?</translation>
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;Information sur le document&lt;/b&gt;&lt;br&gt;Ce panneau montre les informations sur le document et les fichiers qui le composent. Sélectionnez un nom de fichier pour afficher ses informations sous l&apos;index &lt;tt&gt;Fichier&lt;/tt&gt;. Double-cliquez un nom de fichier pour montrer la page correspondante &lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/djview_ru.ts
+++ djview4-4.10.6/src/djview_ru.ts
@@ -2251,7 +2251,7 @@ Do you want to replace it?</source>
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;Информация о документе&lt;/b&gt;&lt;br&gt;Эта панель показывает информацию о документе и его файлах-компонентах. Выберите файл для просмотра подробной информации во вкладке &lt;tt&gt;Файл&lt;/tt&gt;. Вы можете перейти к странице двойным щелчком по соответствующей строке. &lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/djview_uk.ts
+++ djview4-4.10.6/src/djview_uk.ts
@@ -2256,7 +2256,7 @@ Do you want to replace it?</source>
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;Інформація про документ&lt;/b&gt;&lt;br&gt;Ця панель показує інформацію про документ та файли, з яких його складено. Оберіть файл-компонент, щоб побачити детальну інформацію на сторінці &lt;tt&gt;Файл&lt;/tt&gt;. Двічі клацніть на файлі-компоненті, щоб побачити відповідну сторінку у головному вікні. &lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/djview_zh_cn.ts
+++ djview4-4.10.6/src/djview_zh_cn.ts
@@ -2245,7 +2245,7 @@ Do you want to replace it?</source>
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;文档信息&lt;/b&gt;&lt;br&gt;此面板显示文档及其组成文件的信息。 选中组成文件可显示其详细信息于 &lt;tt&gt;文件&lt;/tt&gt; 页中。 双击组成文件可在主窗口中显示其页面。 &lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/djview_zh_tw.ts
+++ djview4-4.10.6/src/djview_zh_tw.ts
@@ -2245,7 +2245,7 @@ Do you want to replace it?</source>
     </message>
     <message>
         <location filename="qdjviewdialogs.cpp" line="324"/>
-        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailled information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
+        <source>&lt;html&gt;&lt;b&gt;Document information&lt;/b&gt;&lt;br&gt;This panel shows information about the document and its component files. Select a component file to display detailed information in the &lt;tt&gt;File&lt;/tt&gt; tab. Double click a component file to show the corresponding page in the main window. &lt;/html&gt;</source>
         <translation>&lt;html&gt;&lt;b&gt;文件資訊&lt;/b&gt;&lt;br&gt;此面板察看文件及其組成檔案的資訊。 選中組成檔案可察看其詳細資訊於 &lt;tt&gt;檔案&lt;/tt&gt; 頁中。 按兩下組成檔案可在主視窗中察看其頁面。 &lt;/html&gt;</translation>
     </message>
     <message>
--- djview4-4.10.6.orig/src/qdjviewdialogs.cpp
+++ djview4-4.10.6/src/qdjviewdialogs.cpp
@@ -324,7 +324,7 @@ QDjViewInfoDialog::QDjViewInfoDialog(QDj
   wd->setWhatsThis(tr("<html><b>Document information</b><br>"
                       "This panel shows information about the document and "
                       "its component files. Select a component file "
-                      "to display detailled information in the <tt>File</tt> "
+                      "to display detailed information in the <tt>File</tt> "
                       "tab. Double click a component file to show "
                       "the corresponding page in the main window. "
                       "</html>"));
--- djview4-4.10.6.orig/src/qdjviewsidebar.cpp
+++ djview4-4.10.6/src/qdjviewsidebar.cpp
@@ -603,9 +603,14 @@ QDjViewThumbnails::Model::makeIcon(int p
   if (doc)
     {
       // render thumbnail
-      int w = size;
-      int h = size;
-      QImage img(size, size, QImage::Format_RGB32);
+#if QT_VERSION >= 0x50200
+      int dpr = djview->devicePixelRatio();
+#else
+      int dpr = 1;
+#endif
+      int w = size * dpr;
+      int h = size * dpr;
+      QImage img(size*dpr, size*dpr, QImage::Format_RGB32);
       int status = ddjvu_thumbnail_status(*doc, pageno, 0);
       if (status == DDJVU_JOB_NOTSTARTED)
         {
@@ -614,9 +619,9 @@ QDjViewThumbnails::Model::makeIcon(int p
       else if (ddjvu_thumbnail_render(*doc, pageno, &w, &h, format, 
                                       img.bytesPerLine(), (char*)img.bits() ))
         {
-          QPixmap pixmap(size,size);
+          QPixmap pixmap(size*dpr,size*dpr);
           pixmap.fill();
-          QPoint dst((size-w)/2, (size-h)/2);
+          QPoint dst((size*dpr-w)/2, (size*dpr-h)/2);
           QRect src(0,0,w,h);
           QPainter painter;
           painter.begin(&pixmap);
@@ -625,6 +630,9 @@ QDjViewThumbnails::Model::makeIcon(int p
           painter.setPen(Qt::darkGray);
           painter.drawRect(dst.x(), dst.y(), w-1, h-1);
           painter.end();
+#if QT_VERSION >= 0x50200
+          pixmap.setDevicePixelRatio(dpr);
+#endif
           return QIcon(pixmap);
         }
     }
