PhoenixBeamerCreator  1.0.0
Tool to create Beamer presentation
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
2/***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6****************************************/
7
8#include <fstream>
9#include <iostream>
10
11#include "PPath.h"
12#include "OptionParser.h"
13
15
17OptionParser createOptionParser(){
18 OptionParser parser(true, __PROGRAM_VERSION__);
19 parser.setExampleLongOption("phoenix_beamercreator --input=fileInput.png --output=output.tex");
20 parser.setExampleShortOption("phoenix_beamercreator -i fileInput1.png fileInput2.png fileInput3.png fileInput4.png -o output.tex");
21
22 parser.addOption("input", "i", OptionType::FILENAME, true, "list of input files");
23
24 PString defaultOutput("output.tex");
25 parser.addOption("output", "o", defaultOutput, "name of the output tex file");
26
27 parser.addOption("169", "169", OptionType::NONE, false, "make 16:9 presentation");
28
29 PString defaultColor("gray");
30 parser.addOption("numbercolor", "n", defaultColor, "color of the slides' number (black, white, blue, green, red, yellow, gray(by default))");
31
32 PString defaultTextFootpage("black");
33 parser.addOption("footpage", "f", defaultTextFootpage, "text to be written on the foot page");
34
35 PString defaultFootpageColor("white");
36 parser.addOption("footpagecolor", "g", defaultFootpageColor, "color of the foot page (black, white, blue, green, red, yellow, white(by default))");
37
38 return parser;
39}
40
42
45void saveBeamerHeaderTex(std::ofstream & fs, bool want169){
46 if(want169){
47 fs << "\\documentclass[hyperref={ bookmarks=false, pdftoolbar=false, pdfmenubar=false, pdftitle={Titre}, pdfauthor={Pierre Aubert}}, french, 9pt, aspectratio=169]{beamer}" << std::endl;
48 }else{
49 fs << "\\documentclass[hyperref={ bookmarks=false, pdftoolbar=false, pdfmenubar=false, pdftitle={Titre}, pdfauthor={Pierre Aubert}}, french, 9pt]{beamer}" << std::endl;
50 }
51 fs << "\\setbeamertemplate{footline}{}" << std::endl;
52 fs << "\\setbeamertemplate{headline}{}" << std::endl;
53 fs << "%To have textblock" << std::endl;
54 fs << "\\usepackage[absolute,overlay]{textpos}" << std::endl;
55
56 fs << "\\usepackage{calc}\n\n\n\\usepackage{amssymb}\n\\usepackage{color}\n\\usepackage{amsfonts}\n\\usepackage{bbm}\n\\pagestyle{empty}\n\n\n";
57 fs << "\\usepackage{amsmath}\n\\usepackage{esint}\n\n";
58 fs << "\\usepackage{multirow}" << std::endl;
59 fs << "\\beamertemplatenavigationsymbolsempty" << std::endl;
60 fs << "\\beamertemplatetransparentcovered" << std::endl;
61
62 fs << "% marges qui pourissent l'existence pour les alignements" << std::endl;
63 fs << "\\setbeamersize{text margin left=0.0cm}" << std::endl;
64 fs << "\\setbeamersize{text margin right=0.0cm}" << std::endl;
65
66 fs << "\\newcommand{\\R}{\\mathbb{R}}" << std::endl;
67 fs << "\\newcommand{\\N}{\\mathbb{N}}" << std::endl;
68 fs << "\\newcommand{\\Z}{\\mathbb{Z}}" << std::endl;
69 fs << "\\newcommand{\\C}{\\mathbb{C}}" << std::endl;
70 fs << "\\newcommand{\\Q}{\\mathbb{Q}}" << std::endl;
71 fs << "\\newcommand{\\M}{\\mathbb{M}}" << std::endl;
72 fs << "\\newcommand{\\normal}{\\mathcal{N}}" << std::endl;
73 fs << "\\newcommand{\\uniform}{\\mathcal{U}}" << std::endl;
74 fs << "\\newcommand{\\A}{\\mathcal{A}}" << std::endl;
75 fs << "\\renewcommand{\\b}[1]{\\textbf{#1}}" << std::endl;
76}
77
79
84void saveBeamerBackground(std::ofstream & fs, const PPath & filePng, long unsigned int slideNumber, bool want169){
85 if(want169){
86 fs << "\\pgfdeclareimage[height=90mm, interpolate=true]{slide"<<slideNumber<<"}{"<<filePng<<"}" << std::endl;
87 }else{
88 fs << "\\pgfdeclareimage[height=96mm,width=128mm]{slide"<<slideNumber<<"}{"<<filePng<<"}" << std::endl;
89 }
90 fs << "\\setbeamertemplate{background}{\\pgfuseimage{slide"<<slideNumber<<"}}" << std::endl;
91}
92
94
100void saveBeamerSlideNumber(std::ofstream & fs, long unsigned int slideNumber, const PString & numberColor,
101 const PString & footPage, const PString & footPageColor)
102{
103 if(slideNumber != 0lu){
104 if(footPage != ""){
105 fs << "\t\\begin{textblock*}{0.9\\textwidth}(0.01\\textwidth,0.97\\textheight)" << std::endl;
106 fs << "\t\t\\large{\\color{"<<footPageColor<<"} " << footPage << "}" << std::endl;
107 fs << "\t\\end{textblock*}" << std::endl;
108 }
109 fs << "\t\\begin{textblock*}{0.1\\textwidth}(0.960\\textwidth,0.98\\textheight)" << std::endl;
110 fs << "\t\t\\textbf{\\Large{\\color{"<<numberColor<<"} " << (slideNumber + 1lu) << "}}" << std::endl;
111 fs << "\t\\end{textblock*}" << std::endl;
112 }
113}
114
116
124void saveBeamerSlideTex(std::ofstream & fs, const PPath & fileTex, long unsigned int slideNumber, bool want169, const PString & numberColor,
125 const PString & footPage, const PString & footPageColor)
126{
127 PPath backGroundFile(CMAKE_INSTALL_PREFIX "/share/BeamerCreator/theme2.png");
128 if(slideNumber == 0){
129 backGroundFile = PPath(CMAKE_INSTALL_PREFIX "/share/BeamerCreator/firstTheme.png");
130 }
131 saveBeamerBackground(fs, backGroundFile, slideNumber, want169);
132
133 fs << "\\frame{"<<std::endl;
134 fs << fileTex.loadFileContent() << std::endl;
135 saveBeamerSlideNumber(fs, slideNumber, numberColor, footPage, footPageColor);
136 fs << "}" << std::endl << std::endl;
137}
138
139
140
142
150void saveBeamerSlidePng(std::ofstream & fs, const PPath & filePng, long unsigned int slideNumber, bool want169, const PString & numberColor,
151 const PString & footPage, const PString & footPageColor)
152{
153 saveBeamerBackground(fs, filePng, slideNumber, want169);
154 fs << "\\frame{"<<std::endl;
155 saveBeamerSlideNumber(fs, slideNumber, numberColor, footPage, footPageColor);
156 fs << "}" << std::endl << std::endl;
157}
158
160
168void saveBeamerSlide(std::ofstream & fs, const PPath & filePng, long unsigned int slideNumber, bool want169, const PString & numberColor,
169 const PString & footPage, const PString & footPageColor)
170{
171 //Check if the extention is not png
172 // If the extention is tex I need to put the content into a slide
173 // I need also to add the theme and the page number
174
175 PPath fileExtention(filePng.getExtension());
176 if(fileExtention == "png"){
177 saveBeamerSlidePng(fs, filePng, slideNumber, want169, numberColor, footPage, footPageColor);
178 }else if(fileExtention == "tex"){
179 saveBeamerSlideTex(fs, filePng, slideNumber, want169, numberColor, footPage, footPageColor);
180 }else{
181 std::cerr << "saveBeamerSlide : unknown extention '"<<fileExtention<<"' of file '"<<filePng<<"'" << std::endl;
182 }
183}
184
186
193void makeTexSlides(const PPath & outputFileName, const std::vector<PPath> & listInputFile, bool want169, const PString & numberColor,
194 const PString & footPage, const PString & footPageColor)
195{
196 if(outputFileName == "" || listInputFile.size() == 0lu){return;}
197
198 std::ofstream fs;
199 fs.open(outputFileName.c_str());
200 if(!fs.is_open()){
201 std::cerr << "makeTexSlides : can't open file '" << outputFileName << "'" << std::endl;
202 return;
203 }
204 saveBeamerHeaderTex(fs, want169);
205
206 fs << "\\begin{document}" << std::endl;
207 PString previousFile("");
208 long unsigned int i(-1lu);
209 for(std::vector<PPath>::const_iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
210 PPath currentFileName(it->getFileName());
211
212 if(previousFile.size() < 6lu || currentFileName.size() < 6lu){
213 ++i;
214 }else{
215 if(previousFile.substr(0, previousFile.size() - 6lu) != currentFileName.substr(0, currentFileName.size() - 6lu)){
216 ++i;
217 }
218 }
219 previousFile = currentFileName;
220 saveBeamerSlide(fs, *it, i, want169, numberColor, footPage, footPageColor);
221 }
222
223 fs << "\\end{document}" << std::endl;
224
225 fs.close();
226}
227
228int main(int argc, char** argv){
229 OptionParser parser = createOptionParser();
230 parser.parseArgument(argc, argv);
231
232 const OptionMode & defaultMode = parser.getDefaultMode();
233 std::vector<PPath> listInputFile;
234 defaultMode.getValue(listInputFile, "input");
235
236 PString outputFile("output.tex");
237 defaultMode.getValue(outputFile, "output");
238
239 PString numberColor("gray");
240 defaultMode.getValue(numberColor, "numbercolor");
241
242 PString footPage("");
243 defaultMode.getValue(footPage, "footpage");
244
245 PString footPageColor("white");
246 defaultMode.getValue(footPageColor, "footpagecolor");
247
248 bool is169 = defaultMode.isOptionExist("169");
249 makeTexSlides(outputFile, listInputFile, is169, numberColor, footPage, footPageColor);
250 return 0;
251}
252
void saveBeamerSlideNumber(std::ofstream &fs, long unsigned int slideNumber, const PString &numberColor, const PString &footPage, const PString &footPageColor)
Save the beamer slide number.
Definition main.cpp:100
void saveBeamerSlidePng(std::ofstream &fs, const PPath &filePng, long unsigned int slideNumber, bool want169, const PString &numberColor, const PString &footPage, const PString &footPageColor)
Make the beamer tex slide.
Definition main.cpp:150
int main(int argc, char **argv)
Definition main.cpp:228
void saveBeamerSlide(std::ofstream &fs, const PPath &filePng, long unsigned int slideNumber, bool want169, const PString &numberColor, const PString &footPage, const PString &footPageColor)
Make the beamer tex slide.
Definition main.cpp:168
void saveBeamerBackground(std::ofstream &fs, const PPath &filePng, long unsigned int slideNumber, bool want169)
Save the beamer background.
Definition main.cpp:84
void saveBeamerSlideTex(std::ofstream &fs, const PPath &fileTex, long unsigned int slideNumber, bool want169, const PString &numberColor, const PString &footPage, const PString &footPageColor)
Save the beamer slide with a tex file.
Definition main.cpp:124
void saveBeamerHeaderTex(std::ofstream &fs, bool want169)
Make the beamer tex header.
Definition main.cpp:45
void makeTexSlides(const PPath &outputFileName, const std::vector< PPath > &listInputFile, bool want169, const PString &numberColor, const PString &footPage, const PString &footPageColor)
Make the tex slides.
Definition main.cpp:193
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition main.cpp:17