forked from openlp/openlp
Added support for using the new mutool in mudraw mode
This commit is contained in:
parent
f4697a6051
commit
b7a32ebbb2
@ -160,7 +160,6 @@ def process_check_binary(program_path):
|
|||||||
"""
|
"""
|
||||||
program_type = None
|
program_type = None
|
||||||
runlog = check_binary_exists(program_path)
|
runlog = check_binary_exists(program_path)
|
||||||
print(runlog, type(runlog))
|
|
||||||
# Analyse the output to see it the program is mediainfo
|
# Analyse the output to see it the program is mediainfo
|
||||||
for line in runlog.splitlines():
|
for line in runlog.splitlines():
|
||||||
decoded_line = line.decode()
|
decoded_line = line.decode()
|
||||||
|
@ -77,6 +77,12 @@ class PdfController(PresentationController):
|
|||||||
if found_mudraw:
|
if found_mudraw:
|
||||||
program_type = 'mudraw'
|
program_type = 'mudraw'
|
||||||
break
|
break
|
||||||
|
found_mutool = re.search('usage: mutool.*', decoded_line, re.IGNORECASE)
|
||||||
|
if found_mutool:
|
||||||
|
# Test that mutool contains mudraw
|
||||||
|
if re.search('draw\s+--\s+convert document.*', runlog.decode(), re.IGNORECASE | re.MULTILINE):
|
||||||
|
program_type = 'mutool'
|
||||||
|
break
|
||||||
found_gs = re.search('GPL Ghostscript.*', decoded_line, re.IGNORECASE)
|
found_gs = re.search('GPL Ghostscript.*', decoded_line, re.IGNORECASE)
|
||||||
if found_gs:
|
if found_gs:
|
||||||
program_type = 'gs'
|
program_type = 'gs'
|
||||||
@ -101,6 +107,7 @@ class PdfController(PresentationController):
|
|||||||
"""
|
"""
|
||||||
log.debug('check_installed Pdf')
|
log.debug('check_installed Pdf')
|
||||||
self.mudrawbin = ''
|
self.mudrawbin = ''
|
||||||
|
self.mutoolbin = ''
|
||||||
self.gsbin = ''
|
self.gsbin = ''
|
||||||
self.also_supports = []
|
self.also_supports = []
|
||||||
# Use the user defined program if given
|
# Use the user defined program if given
|
||||||
@ -111,27 +118,36 @@ class PdfController(PresentationController):
|
|||||||
self.gsbin = pdf_program
|
self.gsbin = pdf_program
|
||||||
elif program_type == 'mudraw':
|
elif program_type == 'mudraw':
|
||||||
self.mudrawbin = pdf_program
|
self.mudrawbin = pdf_program
|
||||||
|
elif program_type == 'mutool':
|
||||||
|
self.mutoolbin = pdf_program
|
||||||
else:
|
else:
|
||||||
# Fallback to autodetection
|
# Fallback to autodetection
|
||||||
application_path = AppLocation.get_directory(AppLocation.AppDir)
|
application_path = AppLocation.get_directory(AppLocation.AppDir)
|
||||||
if is_win():
|
if is_win():
|
||||||
# for windows we only accept mudraw.exe in the base folder
|
# for windows we only accept mudraw.exe or mutool.exe in the base folder
|
||||||
application_path = AppLocation.get_directory(AppLocation.AppDir)
|
application_path = AppLocation.get_directory(AppLocation.AppDir)
|
||||||
if os.path.isfile(os.path.join(application_path, 'mudraw.exe')):
|
if os.path.isfile(os.path.join(application_path, 'mudraw.exe')):
|
||||||
self.mudrawbin = os.path.join(application_path, 'mudraw.exe')
|
self.mudrawbin = os.path.join(application_path, 'mudraw.exe')
|
||||||
|
elif os.path.isfile(os.path.join(application_path, 'mutool.exe')):
|
||||||
|
self.mutoolbin = os.path.join(application_path, 'mutool.exe')
|
||||||
else:
|
else:
|
||||||
DEVNULL = open(os.devnull, 'wb')
|
DEVNULL = open(os.devnull, 'wb')
|
||||||
# First try to find mupdf
|
# First try to find mudraw
|
||||||
self.mudrawbin = which('mudraw')
|
self.mudrawbin = which('mudraw')
|
||||||
# if mupdf isn't installed, fallback to ghostscript
|
# if mudraw isn't installed, try mutool
|
||||||
if not self.mudrawbin:
|
if not self.mudrawbin:
|
||||||
self.gsbin = which('gs')
|
self.mutoolbin = which('mutool')
|
||||||
# Last option: check if mudraw is placed in OpenLP base folder
|
# Check we got a working mutool
|
||||||
if not self.mudrawbin and not self.gsbin:
|
if not self.mutoolbin or self.process_check_binary(self.mutoolbin) != 'mutool':
|
||||||
|
self.gsbin = which('gs')
|
||||||
|
# Last option: check if mudraw or mutool is placed in OpenLP base folder
|
||||||
|
if not self.mudrawbin and not self.mutoolbin and not self.gsbin:
|
||||||
application_path = AppLocation.get_directory(AppLocation.AppDir)
|
application_path = AppLocation.get_directory(AppLocation.AppDir)
|
||||||
if os.path.isfile(os.path.join(application_path, 'mudraw')):
|
if os.path.isfile(os.path.join(application_path, 'mudraw.exe')):
|
||||||
self.mudrawbin = os.path.join(application_path, 'mudraw')
|
self.mudrawbin = os.path.join(application_path, 'mudraw.exe')
|
||||||
if self.mudrawbin:
|
elif os.path.isfile(os.path.join(application_path, 'mutool.exe')):
|
||||||
|
self.mutoolbin = os.path.join(application_path, 'mutool.exe')
|
||||||
|
if self.mudrawbin or self.mutoolbin:
|
||||||
self.also_supports = ['xps', 'oxps']
|
self.also_supports = ['xps', 'oxps']
|
||||||
return True
|
return True
|
||||||
elif self.gsbin:
|
elif self.gsbin:
|
||||||
@ -238,10 +254,18 @@ class PdfDocument(PresentationDocument):
|
|||||||
if not os.path.isdir(self.get_temp_folder()):
|
if not os.path.isdir(self.get_temp_folder()):
|
||||||
os.makedirs(self.get_temp_folder())
|
os.makedirs(self.get_temp_folder())
|
||||||
if self.controller.mudrawbin:
|
if self.controller.mudrawbin:
|
||||||
|
log.debug('loading presentation using mudraw')
|
||||||
runlog = check_output([self.controller.mudrawbin, '-w', str(size.width()), '-h', str(size.height()),
|
runlog = check_output([self.controller.mudrawbin, '-w', str(size.width()), '-h', str(size.height()),
|
||||||
'-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path],
|
'-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path],
|
||||||
startupinfo=self.startupinfo)
|
startupinfo=self.startupinfo)
|
||||||
|
elif self.controller.mutoolbin:
|
||||||
|
log.debug('loading presentation using mutool')
|
||||||
|
runlog = check_output([self.controller.mutoolbin, 'draw', '-w', str(size.width()), '-h',
|
||||||
|
str(size.height()),
|
||||||
|
'-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.file_path],
|
||||||
|
startupinfo=self.startupinfo)
|
||||||
elif self.controller.gsbin:
|
elif self.controller.gsbin:
|
||||||
|
log.debug('loading presentation using gs')
|
||||||
resolution = self.gs_get_resolution(size)
|
resolution = self.gs_get_resolution(size)
|
||||||
runlog = check_output([self.controller.gsbin, '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=png16m',
|
runlog = check_output([self.controller.gsbin, '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=png16m',
|
||||||
'-r' + str(resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4',
|
'-r' + str(resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4',
|
||||||
|
@ -235,7 +235,7 @@ class PresentationTab(SettingsTab):
|
|||||||
self, translate('PresentationPlugin.PresentationTab', 'Select mudraw or ghostscript binary.'),
|
self, translate('PresentationPlugin.PresentationTab', 'Select mudraw or ghostscript binary.'),
|
||||||
self.pdf_program_path.text())
|
self.pdf_program_path.text())
|
||||||
if filename:
|
if filename:
|
||||||
program_type = PdfController.check_binary(filename)
|
program_type = PdfController.process_check_binary(filename)
|
||||||
if not program_type:
|
if not program_type:
|
||||||
critical_error_message_box(UiStrings().Error,
|
critical_error_message_box(UiStrings().Error,
|
||||||
translate('PresentationPlugin.PresentationTab',
|
translate('PresentationPlugin.PresentationTab',
|
||||||
|
Loading…
Reference in New Issue
Block a user