Fix character encoding for new tree category reports

Fixes #10418.
This commit is contained in:
Nick Hall 2018-02-10 00:08:20 +00:00
parent ba4453213a
commit 2fbb9878c2

View File

@ -25,7 +25,7 @@
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import os import os
import shutil from subprocess import Popen, PIPE
from io import StringIO from io import StringIO
import tempfile import tempfile
import logging import logging
@ -97,6 +97,7 @@ _NOTESIZE = [{'name': _("Tiny"), 'value': "tiny"},
if win(): if win():
_LATEX_FOUND = search_for("lualatex.exe") _LATEX_FOUND = search_for("lualatex.exe")
DETACHED_PROCESS = 8
else: else:
_LATEX_FOUND = search_for("lualatex") _LATEX_FOUND = search_for("lualatex")
@ -582,7 +583,7 @@ class TreeTexDoc(TreeDocBase):
if self._filename[-4:] != ".tex": if self._filename[-4:] != ".tex":
self._filename += ".tex" self._filename += ".tex"
with open(self._filename, "w") as texfile: with open(self._filename, 'w', encoding='utf-8') as texfile:
texfile.write(self._tex.getvalue()) texfile.write(self._tex.getvalue())
@ -605,11 +606,14 @@ class TreePdfDoc(TreeDocBase):
self._filename += ".pdf" self._filename += ".pdf"
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, 'temp.tex'), "w") as texfile: args = ['lualatex', '-output-directory', tmpdir,
texfile.write(self._tex.getvalue()) '-jobname', self._filename[:-4]]
os.system('lualatex -output-directory %s temp.tex >/dev/null' if win():
% tmpdir) proc = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE,
shutil.copy(os.path.join(tmpdir, 'temp.pdf'), self._filename) creationflags=DETACHED_PROCESS)
else:
proc = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
proc.communicate(input=self._tex.getvalue().encode('utf-8'))
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------