X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Flegacy_lyxpreview2ppm.py;h=6ee5870df62d38516eb7eea39132b31c22e8bd97;hb=975f304185eca53d62de8b36e6fc5f95b2da4fd9;hp=c40cd8962c534ca8c1f6829b181c169d74657f64;hpb=7c14ff94e31990eb0932f55942edb75f30f6b24d;p=features.git diff --git a/lib/scripts/legacy_lyxpreview2ppm.py b/lib/scripts/legacy_lyxpreview2ppm.py index c40cd8962c..6ee5870df6 100644 --- a/lib/scripts/legacy_lyxpreview2ppm.py +++ b/lib/scripts/legacy_lyxpreview2ppm.py @@ -97,8 +97,8 @@ def usage(prog_name): # Use write_metrics_info to create the .metrics file with this info def legacy_extract_metrics_info(log_file): - log_re = re.compile("Preview: ([ST])") - data_re = re.compile("(-?[0-9]+) (-?[0-9]+) (-?[0-9]+) (-?[0-9]+)") + log_re = re.compile(b"Preview: ([ST])") + data_re = re.compile(b"(-?[0-9]+) (-?[0-9]+) (-?[0-9]+) (-?[0-9]+)") tp_ascent = 0.0 tp_descent = 0.0 @@ -106,12 +106,12 @@ def legacy_extract_metrics_info(log_file): success = 0 results = [] try: - for line in open(log_file, 'r').readlines(): + for line in open(log_file, 'rb').readlines(): match = log_re.match(line) if match == None: continue - snippet = (match.group(1) == 'S') + snippet = (match.group(1) == b'S') success = 1 match = data_re.search(line) if match == None: @@ -154,10 +154,10 @@ def legacy_extract_metrics_info(log_file): return results def extract_resolution(log_file, dpi): - fontsize_re = re.compile("Preview: Fontsize") - magnification_re = re.compile("Preview: Magnification") - extract_decimal_re = re.compile("([0-9\.]+)") - extract_integer_re = re.compile("([0-9]+)") + fontsize_re = re.compile(b"Preview: Fontsize") + magnification_re = re.compile(b"Preview: Magnification") + extract_decimal_re = re.compile(br"([0-9\.]+)") + extract_integer_re = re.compile(b"([0-9]+)") found_fontsize = 0 found_magnification = 0 @@ -167,7 +167,7 @@ def extract_resolution(log_file, dpi): fontsize = 10.0 try: - for line in open(log_file, 'r').readlines(): + for line in open(log_file, 'rb').readlines(): if found_fontsize and found_magnification: break @@ -201,6 +201,7 @@ def extract_resolution(log_file, dpi): def legacy_latex_file(latex_file, fg_color, bg_color): + use_polyglossia_re = re.compile(b"\\s*\\\\usepackage{polyglossia}") use_preview_re = re.compile(b"\\s*\\\\usepackage\\[([^]]+)\\]{preview}") fg_color_gr = make_texcolor(fg_color, True) bg_color_gr = make_texcolor(bg_color, True) @@ -216,33 +217,58 @@ def legacy_latex_file(latex_file, fg_color, bg_color): warning('Warning in legacy_latex_file! Unable to open "%s"' % latex_file) warning(repr(sys.exc_info()[0]) + ',' + repr(sys.exc_info()[1])) + polyglossia = False for line in f.readlines(): if success: tmp.write(line) continue match = use_preview_re.match(line) + polymatch = use_polyglossia_re.match(line) + # Package order: + # * if polyglossia is used, we need to load color before that + # (also, we do not have to load lmodern) + # * else, color should be loaded before preview if match == None: - tmp.write(line) - continue + if polymatch == None: + tmp.write(line) + continue + else: + tmp.write(b""" +\\usepackage{color} +\\definecolor{lyxfg}{rgb}{%s} +\\definecolor{lyxbg}{rgb}{%s} +\\pagecolor{lyxbg} +\\usepackage{polyglossia} +""" % (fg_color_gr, bg_color_gr)) + polyglossia = True + continue success = 1 - # Package order: color should be loaded before preview # Preview options: add the options lyx and tightpage - tmp.write(b""" + previewopts = match.group(1) + if not polyglossia: + tmp.write(b""" \\usepackage{color} -\\definecolor{fg}{rgb}{%s} -\\definecolor{bg}{rgb}{%s} -\\pagecolor{bg} +\\definecolor{lyxfg}{rgb}{%s} +\\definecolor{lyxbg}{rgb}{%s} +\\pagecolor{lyxbg} \\usepackage[%s,tightpage]{preview} \\makeatletter \\def\\t@a{cmr} \\if\\f@family\\t@a \\IfFileExists{lmodern.sty}{\\usepackage{lmodern}}{\\usepackage{ae,aecompl}} \\fi -\\g@addto@macro\\preview{\\begingroup\\color{bg}\\special{ps::clippath fill}\\color{fg}} +\\g@addto@macro\\preview{\\begingroup\\color{lyxbg}\\special{ps::clippath fill}\\color{lyxfg}} \\g@addto@macro\\endpreview{\\endgroup} \\makeatother -""" % (fg_color_gr, bg_color_gr, match.group(1))) - +""" % (fg_color_gr, bg_color_gr, previewopts)) + else: + tmp.write(b""" +\\usepackage[%s,tightpage]{preview} +\\makeatletter +\\g@addto@macro\\preview{\\begingroup\\color{lyxbg}\\special{ps::clippath fill}\\color{lyxfg}} +\\g@addto@macro\\endpreview{\\endgroup} +\\makeatother +""" % previewopts) if success: copyfileobj(tmp, open(latex_file,"wb"), 1)