diff --git a/rendercv/rendering.py b/rendercv/rendering.py index 79f5c48..72c67f1 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -3,6 +3,7 @@ import subprocess import os import re +import shutil from jinja2 import Environment, PackageLoader @@ -201,6 +202,15 @@ def print_today() -> str: return today.strftime("%B %d, %Y") +def get_path_to_fonts_directory() -> str: + """Return the path to the fonts directory. + + Returns: + str: The path to the fonts directory. + """ + return os.path.join(os.path.dirname(__file__), "templates", "fonts") + + def render_template(data): """Render the template using the given data. @@ -242,7 +252,10 @@ def render_template(data): environment.filters["make_it_italic"] = make_it_italic output_latex_file = template.render( - design=data.design.options, cv=data.cv, today=print_today() + design=data.design.options, + cv=data.cv, + today=print_today(), + fonts_directory=get_path_to_fonts_directory(), ) # Create an output file and write the rendered LaTeX code to it: @@ -251,6 +264,21 @@ def render_template(data): with open(output_file_path, "w") as file: file.write(output_latex_file) + # Copy the fonts directory to the output directory: + fonts_directory = get_path_to_fonts_directory() + output_fonts_directory = os.path.join(os.path.dirname(output_file_path), "fonts") + os.makedirs(output_fonts_directory, exist_ok=True) + for directory in os.listdir(fonts_directory): + if directory == "SourceSans3": + # copy the SourceSans3 fonts: + source_directory = os.path.join(fonts_directory, directory) + + shutil.copytree( + source_directory, + output_fonts_directory, + dirs_exist_ok=True, + ) + return output_file_path @@ -267,7 +295,7 @@ def run_latex(latex_file_path): if os.name == "nt": # remove all files except the .tex file for file in os.listdir(os.path.dirname(latex_file_path)): - if file.endswith(".tex"): + if file.endswith(".tex") or file == "fonts": continue os.remove(os.path.join(os.path.dirname(latex_file_path), file)) @@ -278,6 +306,7 @@ def run_latex(latex_file_path): "bin", "windows", ) + print("PDF generatation started!") subprocess.run( [ f"{tinytexPath}\\latexmk.exe", @@ -289,6 +318,12 @@ def run_latex(latex_file_path): "-file-line-error", ], cwd=os.path.dirname(latex_file_path), + stdout=subprocess.DEVNULL, ) + print("PDF generated successfully!") else: - print("Only Windows is supported for now.") + print( + "Only Windows is supported for now. But you can still use the generated" + " .tex file to generate the PDF. Go to overleaf.com and upload the .tex" + " file there to generate the PDF." + ) diff --git a/rendercv/templates/classic.tex.j2 b/rendercv/templates/classic.tex.j2 index ba358e1..e115c9b 100644 --- a/rendercv/templates/classic.tex.j2 +++ b/rendercv/templates/classic.tex.j2 @@ -17,7 +17,6 @@ \usepackage[explicit]{titlesec} % for customizing section titles \usepackage{tabularx} % for making tables with fixed width columns \usepackage{array} % tabularx requires this -\usepackage{xifthen} % for if-then-else statements \usepackage[dvipsnames]{xcolor} % for coloring text \definecolor{primaryColor}{RGB}{<>} % define primary color \usepackage{enumitem} % for customizing lists @@ -38,12 +37,15 @@ \setlength{\topskip}{0pt} % no top skip \pagenumbering{gobble} % no page numbering + \setmainfont{SourceSans3}[ + Path= fonts/, Extension = .ttf, UprightFont = *-Regular, ItalicFont = *-Italic, BoldFont = *-Bold, - BoldItalicFont = *-BoldItalic] % set main font + BoldItalicFont = *-BoldItalic +] \titleformat{\section}{ % make the font size of the section title large and color it with the primary color diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-Bold.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-Bold.ttf new file mode 100644 index 0000000..55f6138 Binary files /dev/null and b/rendercv/templates/fonts/SourceSans3/SourceSans3-Bold.ttf differ diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-BoldItalic.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-BoldItalic.ttf new file mode 100644 index 0000000..ddeed16 Binary files /dev/null and b/rendercv/templates/fonts/SourceSans3/SourceSans3-BoldItalic.ttf differ diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-Italic.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-Italic.ttf new file mode 100644 index 0000000..8ea9acf Binary files /dev/null and b/rendercv/templates/fonts/SourceSans3/SourceSans3-Italic.ttf differ diff --git a/rendercv/templates/fonts/SourceSans3/SourceSans3-Regular.ttf b/rendercv/templates/fonts/SourceSans3/SourceSans3-Regular.ttf new file mode 100644 index 0000000..803d4da Binary files /dev/null and b/rendercv/templates/fonts/SourceSans3/SourceSans3-Regular.ttf differ