Various fixes for ghostscript. Tried to support windows+mupdf.

This commit is contained in:
Tomas Groth 2013-07-16 22:59:52 +02:00
parent b23abd0378
commit fa537260f6
1 changed files with 34 additions and 17 deletions

View File

@ -31,9 +31,10 @@ import os
import logging import logging
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
import re import re
from subprocess import check_output, call from subprocess import check_output, CalledProcessError
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.utils import AppLocation
from openlp.core.lib import ScreenList from openlp.core.lib import ScreenList
from presentationcontroller import PresentationController, PresentationDocument from presentationcontroller import PresentationController, PresentationDocument
@ -54,9 +55,11 @@ class PdfController(PresentationController):
log.debug(u'Initialising') log.debug(u'Initialising')
self.process = None self.process = None
PresentationController.__init__(self, plugin, u'Pdf', PdfDocument) PresentationController.__init__(self, plugin, u'Pdf', PdfDocument)
self.supports = [u'pdf', u'xps'] self.supports = [u'pdf']
self.mudrawbin = u'' self.mudrawbin = u''
self.gsbin = u'' self.gsbin = u''
if self.check_installed() and self.mudrawbin != u'':
self.also_supports = [u'xps']
self.viewer = None self.viewer = None
def check_available(self): def check_available(self):
@ -70,20 +73,34 @@ class PdfController(PresentationController):
""" """
Check the viewer is installed. Check the viewer is installed.
""" """
application_path = AppLocation.get_directory(AppLocation.AppDir)
print application_path
log.debug(u'check_installed Pdf') log.debug(u'check_installed Pdf')
# First try to find mupdf if os.name != u'nt':
try: # First try to find mupdf
self.mudrawbin = check_output([u'which', u'mudraw']).rstrip('\n')
except CalledProcessError:
self.mudrawbin = u''
# if mupdf isn't installed, fallback to ghostscript
if self.mudrawbin == u'':
try: try:
self.gsbin = check_output([u'which', u'gs']).rstrip('\n') self.mudrawbin = check_output([u'which', u'mudraw']).rstrip('\n')
except CalledProcessError: except CalledProcessError:
self.gsbin = u'' self.mudrawbin = u''
# if mupdf isn't installed, fallback to ghostscript
if self.mudrawbin == u'':
try:
self.gsbin = check_output([u'which', u'gs']).rstrip('\n')
except CalledProcessError:
self.gsbin = u''
# Last option: check if mudraw is placed in OpenLP base folder
if self.mudrawbin == u'' and self.gsbin == u'':
application_path = AppLocation.get_directory(AppLocation.AppDir)
if os.path.isfile(application_path + u'/../mudraw'):
self.mudrawbin = application_path + u'/../mudraw'
else:
# for windows we only accept mudraw.exe in the base folder
application_path = AppLocation.get_directory(AppLocation.AppDir)
if os.path.isfile(application_path + u'/../mudraw.exe'):
self.mudrawbin = application_path + u'/../mudraw.exe'
if self.mudrawbin == u'' and self.gsbin == u'': if self.mudrawbin == u'' and self.gsbin == u'':
return False return False
else: else:
@ -155,8 +172,8 @@ quit \n\
height = 0 height = 0
for line in runlog.splitlines(): for line in runlog.splitlines():
try: try:
width = re.search(u'.*Size: x: (\d+), y: \d+.*', line).group(1) width = re.search(u'.*Size: x: (\d+\.?\d*), y: \d+.*', line).group(1)
height = re.search(u'.*Size: x: \d+, y: (\d+).*', line).group(1) height = re.search(u'.*Size: x: \d+\.?\d*, y: (\d+\.?\d*).*', line).group(1)
break; break;
except AttributeError: except AttributeError:
pass pass
@ -164,11 +181,11 @@ quit \n\
# Calculate the ratio from pdf to screen # Calculate the ratio from pdf to screen
if width > 0 and height > 0: if width > 0 and height > 0:
width_ratio = size.right() / float(width) width_ratio = size.right() / float(width)
heigth_ratio = size.bottom() / float(height) height_ratio = size.bottom() / float(height)
# return the resolution that should be used. 72 is default. # return the resolution that should be used. 72 is default.
if width_ratio > heigth_ratio: if width_ratio > height_ratio:
return int(heigth_ratio * 72) return int(height_ratio * 72)
else: else:
return int(width_ratio * 72) return int(width_ratio * 72)
else: else: