diff --git a/src/slider/convert.py b/src/slider/convert.py index 5e212fdb02659870c36a0c8d94683d9e674d27b3..945207b15402324d47374e0bf3efdfe8e6d33eb2 100644 --- a/src/slider/convert.py +++ b/src/slider/convert.py @@ -63,6 +63,7 @@ def pdf2png(fin, fout=None, scale_to=None, page_to_convert=None): if scale_to is not None: cmd += f" -scale-to {scale_to}" execute_command(cmd.split()) + return fout + ".png" diff --git a/src/slider/slide.py b/src/slider/slide.py index 153ce68ef7755139e8fd5c127badb9b9eae1e4cb..ccd1043e2f32586a1fec298efc521724b4d39625 100644 --- a/src/slider/slide.py +++ b/src/slider/slide.py @@ -22,6 +22,11 @@ def fix_handout(s): s = s[:j2 + 1] + "[handout]" + s[j2 + 1:] return s + +def _get_osvg_labels(): + + pass + def set_svg_background_images(lecture_tex, verbose=False, fix_broken_osvg_files=False, recompile_on_change=True, @@ -43,6 +48,14 @@ def set_svg_background_images(lecture_tex, verbose=False, SVG_TMP_DIR = MAIN_TEX_DIR + "/" + SVG_EDIT_RELPATH + "/" + SVG_TMP_RELPATH SVG_OSVG_DIR = MAIN_TEX_DIR + "/" + SVG_EDIT_RELPATH force_fix_broken_osvg_files = [] if force_fix_broken_osvg_files is None else force_fix_broken_osvg_files + NO_SVG_TMP_DIR = SVG_TMP_DIR + "/no_svg_tmp" + + # if not os.path.isdir(NO_SVG_TMP_DIR): + # os.mkdir(NO_SVG_TMP_DIR) + + if os.path.isdir(NO_SVG_TMP_DIR): + for f in glob.glob(MAIN_TEX_DIR + "/*_NO_SVGS.*"): + shutil.move(f, MAIN_TEX_DIR + "/" + os.path.basename(f)) print("Slider is setting the background images for the .tex. file\n> %s" % os.path.abspath(lecture_tex)) if copy_template_resource_files: @@ -107,7 +120,6 @@ def set_svg_background_images(lecture_tex, verbose=False, lecture_tex_nosvg_pdf = lecture_tex_nosvg[:-4] + ".pdf" - # lecture_tex_nosvg_tex = recursive_tex_apply(lecture_tex_nosvg) if cache_contains_str(MAIN_TEX_DIR, key='all_tex', value=all_tex) and os.path.exists(lecture_tex_nosvg_pdf): print("slider> Cache contains nosvg tex file") @@ -176,26 +188,27 @@ def set_svg_background_images(lecture_tex, verbose=False, if clean_temporary_files: if verbose: - print("> SlideConverter: Removing temporary dirs...") + print("> Slider: Removing temporary dirs...") # raise Exception() DNE = SVG_OSVG_DIR + "/do_not_edit" if os.path.exists(SVG_TMP_DIR): - for v in glob.glob(SVG_TMP_DIR + "/*"): + for v in glob.glob(SVG_TMP_DIR + "/*.svg"): if not v.endswith("png"): os.remove(v) + if os.path.isdir(DNE): + shutil.rmtree(DNE) + if not os.path.isdir(NO_SVG_TMP_DIR): + os.mkdir(NO_SVG_TMP_DIR) - # for v in glob.glob(SVG_OSVG_DIR + "/x_do_not_edit*.pdf"): - # if not v.endswith("png"): - # os.remove(v) + for f in glob.glob(MAIN_TEX_DIR +"/*_NO_SVGS.*"): + shutil.move(f, NO_SVG_TMP_DIR +"/" + os.path.basename(f)) - # Not sure I want to do add this as an option right now. It makes everything slower... - # for f in glob.glob(lecture_tex[:-4] + '_NO_SVGS*'): - # os.remove(f) + # if os.path.exists(DNE): + # for v in glob.glob(DNE + "/*"): + # if not v.endswith("png"): + # os.remove(v) - if os.path.exists(DNE): - for v in glob.glob(DNE + "/*"): - if not v.endswith("png"): - os.remove(v) + a = 234 def slide_no_by_text(pdf_file, text): assert False diff --git a/tests/test_slider.py b/tests/test_slider.py index 09e886f547d60d576b6c67995ed8b6827b3a0def..ff3d4b96449ca3d417b48d412a4a4ef04cdb7874 100644 --- a/tests/test_slider.py +++ b/tests/test_slider.py @@ -1,5 +1,4 @@ import os -# import pytest import numpy as np from PIL import Image from unittest import TestCase @@ -8,9 +7,6 @@ import os import subprocess from slider.convert import pdf2png from slider.slider_cli import slider_cli -# import sys -# sys.path.append(os.path.dirname(os.path.abspath(__file__)) +"/../src") - def assert_images_equal(image_1: str, image_2: str): img1 = Image.open(image_1) @@ -64,11 +60,6 @@ class TestSlider(TestCase): s = f.read() i = s.find("</svg>") ss = s[:i] + RECT1 + RECT2 + s[i:] - - # pieces = s.split("</svg>") - - # ss = s.replace("</svg>", RECT + "</svg>") - # ss = pieces[0] + "<g>" + + pieces[1] with open(fn, 'w') as f: f.write(ss) slider_cli("automatic/index.tex", interactive=False) @@ -98,15 +89,26 @@ class TestConverter(TestCase): # Generate the output files. if os.path.isdir("./converted"): shutil.rmtree("./converted") - # if os.path.isdir("./test_images"): - # shutil.rmtree("./test_images") os.mkdir("converted") shutil.copyfile("slideshow.pdf", "converted/slideshow.pdf") from slider.slider_cli import slider_converter_cli slider_converter_cli("converted/slideshow.pdf") - pdf2png("converted/slideshow_converted.pdf", fout="converted/converted_10.png", page_to_convert=10) + out = pdf2png("converted/slideshow_converted.pdf", fout="converted/converted_10.png", page_to_convert=10) + print("output file was", os.path.abspath(out), "exists?", os.path.isfile(out)) + print("Current directory is", os.getcwd()) + print("Content of current dir is") + import glob + for f in glob.glob("./*"): + print(f) + print("Content of tests_images is") + shutil.copyfile("converted/converted_10.png", "tests_images/converted_10.png") + # pdf2png("automatic/index.pdf", fout="automatic/index_b.png", page_to_convert=2) + # shutil.copyfile("automatic/index_a.png", "tests_images/index_a.png") + # shutil.copyfile("automatic/index_b.png", "tests_images/index_b.png") + + # shutil.copyfile("automatic/index_a.png", "tests_images/index_a.png") diff --git a/tests/tests_images/index.pdf b/tests/tests_images/index.pdf index ff862bfebf0d34991171958576c81ccb315efe92..1b4bc477f333c138fb52a4b499510c920d9d651a 100644 Binary files a/tests/tests_images/index.pdf and b/tests/tests_images/index.pdf differ