GCC Code Coverage Report


Directory: ./
File: src/main.cpp
Date: 2025-03-14 11:56:07
Exec Total Coverage
Lines: 122 124 98.4%
Branches: 129 141 91.5%

Line Branch Exec Source
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
14 ///Create the OptionParser of this program
15 /** @return OptionParser of this program
16 */
17 9 OptionParser createOptionParser(){
18
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 OptionParser parser(true, __PROGRAM_VERSION__);
19
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 parser.setExampleLongOption("phoenix_beamercreator --input=fileInput.png --output=output.tex");
20
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 parser.setExampleShortOption("phoenix_beamercreator -i fileInput1.png fileInput2.png fileInput3.png fileInput4.png -o output.tex");
21
22
4/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
9 parser.addOption("input", "i", OptionType::FILENAME, true, "list of input files");
23
24
1/1
✓ Branch 1 taken 9 times.
9 PString defaultOutput("output.tex");
25
5/5
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
9 parser.addOption("output", "o", defaultOutput, "name of the output tex file");
26
27
4/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
9 parser.addOption("169", "169", OptionType::NONE, false, "make 16:9 presentation");
28
29
1/1
✓ Branch 1 taken 9 times.
9 PString defaultColor("gray");
30
5/5
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
9 parser.addOption("numbercolor", "n", defaultColor, "color of the slides' number (black, white, blue, green, red, yellow, gray(by default))");
31
32
1/1
✓ Branch 1 taken 9 times.
9 PString defaultTextFootpage("black");
33
5/5
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
9 parser.addOption("footpage", "f", defaultTextFootpage, "text to be written on the foot page");
34
35
1/1
✓ Branch 1 taken 9 times.
9 PString defaultFootpageColor("white");
36
5/5
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
9 parser.addOption("footpagecolor", "g", defaultFootpageColor, "color of the foot page (black, white, blue, green, red, yellow, white(by default))");
37
38 18 return parser;
39 9 }
40
41 ///Make the beamer tex header
42 /** @param[out] fs : file to be completed
43 * @param want169 : to have a 16:9 aspect ratio
44 */
45 7 void saveBeamerHeaderTex(std::ofstream & fs, bool want169){
46
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
7 if(want169){
47 2 fs << "\\documentclass[hyperref={ bookmarks=false, pdftoolbar=false, pdfmenubar=false, pdftitle={Titre}, pdfauthor={Pierre Aubert}}, french, 9pt, aspectratio=169]{beamer}" << std::endl;
48 }else{
49 5 fs << "\\documentclass[hyperref={ bookmarks=false, pdftoolbar=false, pdfmenubar=false, pdftitle={Titre}, pdfauthor={Pierre Aubert}}, french, 9pt]{beamer}" << std::endl;
50 }
51 7 fs << "\\setbeamertemplate{footline}{}" << std::endl;
52 7 fs << "\\setbeamertemplate{headline}{}" << std::endl;
53 7 fs << "%To have textblock" << std::endl;
54 7 fs << "\\usepackage[absolute,overlay]{textpos}" << std::endl;
55
56 7 fs << "\\usepackage{calc}\n\n\n\\usepackage{amssymb}\n\\usepackage{color}\n\\usepackage{amsfonts}\n\\usepackage{bbm}\n\\pagestyle{empty}\n\n\n";
57 7 fs << "\\usepackage{amsmath}\n\\usepackage{esint}\n\n";
58 7 fs << "\\usepackage{multirow}" << std::endl;
59 7 fs << "\\beamertemplatenavigationsymbolsempty" << std::endl;
60 7 fs << "\\beamertemplatetransparentcovered" << std::endl;
61
62 7 fs << "% marges qui pourissent l'existence pour les alignements" << std::endl;
63 7 fs << "\\setbeamersize{text margin left=0.0cm}" << std::endl;
64 7 fs << "\\setbeamersize{text margin right=0.0cm}" << std::endl;
65
66 7 fs << "\\newcommand{\\R}{\\mathbb{R}}" << std::endl;
67 7 fs << "\\newcommand{\\N}{\\mathbb{N}}" << std::endl;
68 7 fs << "\\newcommand{\\Z}{\\mathbb{Z}}" << std::endl;
69 7 fs << "\\newcommand{\\C}{\\mathbb{C}}" << std::endl;
70 7 fs << "\\newcommand{\\Q}{\\mathbb{Q}}" << std::endl;
71 7 fs << "\\newcommand{\\M}{\\mathbb{M}}" << std::endl;
72 7 fs << "\\newcommand{\\normal}{\\mathcal{N}}" << std::endl;
73 7 fs << "\\newcommand{\\uniform}{\\mathcal{U}}" << std::endl;
74 7 fs << "\\newcommand{\\A}{\\mathcal{A}}" << std::endl;
75 7 fs << "\\renewcommand{\\b}[1]{\\textbf{#1}}" << std::endl;
76 7 }
77
78 ///Save the beamer background
79 /** @param[out] fs : file to be written
80 * @param filePng : name of the png file to be used as background
81 * @param slideNumber : slide number
82 * @param want169 : to have a 16:9 aspect ratio
83 */
84 12 void saveBeamerBackground(std::ofstream & fs, const PPath & filePng, long unsigned int slideNumber, bool want169){
85
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if(want169){
86 4 fs << "\\pgfdeclareimage[height=90mm, interpolate=true]{slide"<<slideNumber<<"}{"<<filePng<<"}" << std::endl;
87 }else{
88 8 fs << "\\pgfdeclareimage[height=96mm,width=128mm]{slide"<<slideNumber<<"}{"<<filePng<<"}" << std::endl;
89 }
90 12 fs << "\\setbeamertemplate{background}{\\pgfuseimage{slide"<<slideNumber<<"}}" << std::endl;
91 12 }
92
93 ///Save the beamer slide number
94 /** @param[out] fs : file to be written
95 * @param slideNumber : slide number
96 * @param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
97 * @param footPage : string to be written in the footpage of the slides
98 * @param footPageColor : color of the foot page
99 */
100 12 void saveBeamerSlideNumber(std::ofstream & fs, long unsigned int slideNumber, const PString & numberColor,
101 const PString & footPage, const PString & footPageColor)
102 {
103
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(slideNumber != 0lu){
104
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
6 if(footPage != ""){
105 5 fs << "\t\\begin{textblock*}{0.9\\textwidth}(0.01\\textwidth,0.97\\textheight)" << std::endl;
106 5 fs << "\t\t\\large{\\color{"<<footPageColor<<"} " << footPage << "}" << std::endl;
107 5 fs << "\t\\end{textblock*}" << std::endl;
108 }
109 6 fs << "\t\\begin{textblock*}{0.1\\textwidth}(0.960\\textwidth,0.98\\textheight)" << std::endl;
110 6 fs << "\t\t\\textbf{\\Large{\\color{"<<numberColor<<"} " << (slideNumber + 1lu) << "}}" << std::endl;
111 6 fs << "\t\\end{textblock*}" << std::endl;
112 }
113 12 }
114
115 ///Save the beamer slide with a tex file
116 /** @param[out] fs : file to be written
117 * @param fileTex : name of the tex file to be red
118 * @param slideNumber : slide number
119 * @param want169 : to have a 16:9 aspect ratio
120 * @param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
121 * @param footPage : string to be written in the footpage of the slides
122 * @param footPageColor : color of the foot page
123 */
124 11 void 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
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 PPath backGroundFile(CMAKE_INSTALL_PREFIX "/share/BeamerCreator/theme2.png");
128
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 5 times.
11 if(slideNumber == 0){
129
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 backGroundFile = PPath(CMAKE_INSTALL_PREFIX "/share/BeamerCreator/firstTheme.png");
130 }
131
1/1
✓ Branch 1 taken 11 times.
11 saveBeamerBackground(fs, backGroundFile, slideNumber, want169);
132
133
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 fs << "\\frame{"<<std::endl;
134
3/3
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
11 fs << fileTex.loadFileContent() << std::endl;
135
1/1
✓ Branch 1 taken 11 times.
11 saveBeamerSlideNumber(fs, slideNumber, numberColor, footPage, footPageColor);
136
3/3
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
11 fs << "}" << std::endl << std::endl;
137 11 }
138
139
140
141 ///Make the beamer tex slide
142 /** @param[out] fs : file to be completed
143 * @param filePng : file png to be in the slide
144 * @param slideNumber : slide number
145 * @param want169 : to have a 16:9 aspect ratio
146 * @param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
147 * @param footPage : string to be written in the footpage of the slides
148 * @param footPageColor : color of the foot page
149 */
150 1 void 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 1 saveBeamerBackground(fs, filePng, slideNumber, want169);
154 1 fs << "\\frame{"<<std::endl;
155 1 saveBeamerSlideNumber(fs, slideNumber, numberColor, footPage, footPageColor);
156 1 fs << "}" << std::endl << std::endl;
157 1 }
158
159 ///Make the beamer tex slide
160 /** @param[out] fs : file to be completed
161 * @param filePng : file png to be in the slide
162 * @param slideNumber : slide number
163 * @param want169 : to have a 16:9 aspect ratio
164 * @param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
165 * @param footPage : string to be written in the footpage of the slides
166 * @param footPageColor : color of the foot page
167 */
168 13 void 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
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 PPath fileExtention(filePng.getExtension());
176
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
13 if(fileExtention == "png"){
177
1/1
✓ Branch 1 taken 1 times.
1 saveBeamerSlidePng(fs, filePng, slideNumber, want169, numberColor, footPage, footPageColor);
178
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 1 times.
12 }else if(fileExtention == "tex"){
179
1/1
✓ Branch 1 taken 11 times.
11 saveBeamerSlideTex(fs, filePng, slideNumber, want169, numberColor, footPage, footPageColor);
180 }else{
181
6/6
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 std::cerr << "saveBeamerSlide : unknown extention '"<<fileExtention<<"' of file '"<<filePng<<"'" << std::endl;
182 }
183 13 }
184
185 ///Make the tex slides
186 /** @param outputFileName : output file name
187 * @param listInputFile : list of the png slides input
188 * @param want169 : to have a 16:9 aspect ratio
189 * @param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
190 * @param footPage : string to be written in the footpage of the slides
191 * @param footPageColor : color of the foot page
192 */
193 9 void makeTexSlides(const PPath & outputFileName, const std::vector<PPath> & listInputFile, bool want169, const PString & numberColor,
194 const PString & footPage, const PString & footPageColor)
195 {
196
6/6
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 7 times.
9 if(outputFileName == "" || listInputFile.size() == 0lu){return;}
197
198
1/1
✓ Branch 1 taken 7 times.
7 std::ofstream fs;
199
1/1
✓ Branch 2 taken 7 times.
7 fs.open(outputFileName.c_str());
200
2/3
✓ Branch 1 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
7 if(!fs.is_open()){
201 std::cerr << "makeTexSlides : can't open file '" << outputFileName << "'" << std::endl;
202 return;
203 }
204
1/1
✓ Branch 1 taken 7 times.
7 saveBeamerHeaderTex(fs, want169);
205
206
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 fs << "\\begin{document}" << std::endl;
207
1/1
✓ Branch 1 taken 7 times.
7 PString previousFile("");
208 7 long unsigned int i(-1lu);
209
2/2
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 7 times.
20 for(std::vector<PPath>::const_iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
210
1/1
✓ Branch 2 taken 13 times.
13 PPath currentFileName(it->getFileName());
211
212
5/6
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 7 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 6 times.
13 if(previousFile.size() < 6lu || currentFileName.size() < 6lu){
213 7 ++i;
214 }else{
215
3/4
✓ Branch 2 taken 6 times.
✓ Branch 6 taken 6 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
6 if(previousFile.substr(0, previousFile.size() - 6lu) != currentFileName.substr(0, currentFileName.size() - 6lu)){
216 6 ++i;
217 }
218 }
219
1/1
✓ Branch 1 taken 13 times.
13 previousFile = currentFileName;
220
1/1
✓ Branch 2 taken 13 times.
13 saveBeamerSlide(fs, *it, i, want169, numberColor, footPage, footPageColor);
221 13 }
222
223
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 fs << "\\end{document}" << std::endl;
224
225
1/1
✓ Branch 1 taken 7 times.
7 fs.close();
226
1/2
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 }
227
228 9 int main(int argc, char** argv){
229
1/1
✓ Branch 1 taken 9 times.
9 OptionParser parser = createOptionParser();
230
1/1
✓ Branch 1 taken 9 times.
9 parser.parseArgument(argc, argv);
231
232
1/1
✓ Branch 1 taken 9 times.
9 const OptionMode & defaultMode = parser.getDefaultMode();
233 9 std::vector<PPath> listInputFile;
234
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 defaultMode.getValue(listInputFile, "input");
235
236
1/1
✓ Branch 1 taken 9 times.
9 PString outputFile("output.tex");
237
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 defaultMode.getValue(outputFile, "output");
238
239
1/1
✓ Branch 1 taken 9 times.
9 PString numberColor("gray");
240
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 defaultMode.getValue(numberColor, "numbercolor");
241
242
1/1
✓ Branch 1 taken 9 times.
9 PString footPage("");
243
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 defaultMode.getValue(footPage, "footpage");
244
245
1/1
✓ Branch 1 taken 9 times.
9 PString footPageColor("white");
246
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 defaultMode.getValue(footPageColor, "footpagecolor");
247
248
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 bool is169 = defaultMode.isOptionExist("169");
249
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 makeTexSlides(outputFile, listInputFile, is169, numberColor, footPage, footPageColor);
250 9 return 0;
251 9 }
252
253