GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/main.cpp Lines: 119 121 98.3 %
Date: 2025-04-24 04:07:07 Branches: 124 135 91.9 %

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 "string_utils.h"
12
#include "OptionParser.h"
13
14
using namespace std;
15
16
///Create the OptionParser of this program
17
/**	@return OptionParser of this program
18
*/
19
9
OptionParser createOptionParser(){
20
18
	OptionParser parser(true, __PROGRAM_VERSION__);
21
9
	parser.setExampleLongOption("phoenix_beamercreator --input=fileInput.png --output=output.tex");
22
9
	parser.setExampleShortOption("phoenix_beamercreator -i fileInput1.png fileInput2.png fileInput3.png fileInput4.png -o output.tex");
23
24

9
	parser.addOption("input", "i", OptionType::FILENAME, true, "list of input files");
25
26
18
	std::string defaultOutput("output.tex");
27

9
	parser.addOption("output", "o", defaultOutput, "name of the output tex file");
28
29

9
	parser.addOption("169", "169", OptionType::NONE, false, "make 16:9 presentation");
30
31
18
	std::string defaultColor("gray");
32

9
	parser.addOption("numbercolor", "n", defaultColor, "color of the slides' number (black, white, blue, green, red, yellow, gray(by default))");
33
34
18
	std::string defaultTextFootpage("black");
35

9
	parser.addOption("footpage", "f", defaultTextFootpage, "text to be written on the foot page");
36
37
18
	std::string defaultFootpageColor("white");
38

9
	parser.addOption("footpagecolor", "g", defaultFootpageColor, "color of the foot page (black, white, blue, green, red, yellow, white(by default))");
39
40
18
	return parser;
41
}
42
43
///Make the beamer tex header
44
/**	@param[out] fs : file to be completed
45
 * 	@param want169 : to have a 16:9 aspect ratio
46
*/
47
7
void saveBeamerHeaderTex(std::ofstream & fs, bool want169){
48
7
	if(want169){
49
2
		fs << "\\documentclass[hyperref={ bookmarks=false, pdftoolbar=false, pdfmenubar=false, pdftitle={Titre}, pdfauthor={Pierre Aubert}}, french, 9pt, aspectratio=169]{beamer}" << endl;
50
	}else{
51
5
		fs << "\\documentclass[hyperref={ bookmarks=false, pdftoolbar=false, pdfmenubar=false, pdftitle={Titre}, pdfauthor={Pierre Aubert}}, french, 9pt]{beamer}" << endl;
52
	}
53
7
	fs << "\\setbeamertemplate{footline}{}" << endl;
54
7
	fs << "\\setbeamertemplate{headline}{}" << endl;
55
7
	fs << "%To have textblock" << endl;
56
7
	fs << "\\usepackage[absolute,overlay]{textpos}" << endl;
57
58
7
	fs << "\\usepackage{calc}\n\n\n\\usepackage{amssymb}\n\\usepackage{color}\n\\usepackage{amsfonts}\n\\usepackage{bbm}\n\\pagestyle{empty}\n\n\n";
59
7
	fs << "\\usepackage{amsmath}\n\\usepackage{esint}\n\n";
60
7
	fs << "\\usepackage{multirow}" << endl;
61
7
	fs << "\\beamertemplatenavigationsymbolsempty" << endl;
62
7
	fs << "\\beamertemplatetransparentcovered" << endl;
63
64
7
	fs << "% marges qui pourissent l'existence pour les alignements" << endl;
65
7
	fs << "\\setbeamersize{text margin left=0.0cm}" << endl;
66
7
	fs << "\\setbeamersize{text margin right=0.0cm}" << endl;
67
68
7
	fs << "\\newcommand{\\R}{\\mathbb{R}}" << endl;
69
7
	fs << "\\newcommand{\\N}{\\mathbb{N}}" << endl;
70
7
	fs << "\\newcommand{\\Z}{\\mathbb{Z}}" << endl;
71
7
	fs << "\\newcommand{\\C}{\\mathbb{C}}" << endl;
72
7
	fs << "\\newcommand{\\Q}{\\mathbb{Q}}" << endl;
73
7
	fs << "\\newcommand{\\M}{\\mathbb{M}}" << endl;
74
7
	fs << "\\newcommand{\\normal}{\\mathcal{N}}" << endl;
75
7
	fs << "\\newcommand{\\uniform}{\\mathcal{U}}" << endl;
76
7
	fs << "\\newcommand{\\A}{\\mathcal{A}}" << endl;
77
7
	fs << "\\renewcommand{\\b}[1]{\\textbf{#1}}" << endl;
78
7
}
79
80
///Save the beamer background
81
/**	@param[out] fs : file to be written
82
 * 	@param filePng : name of the png file to be used as background
83
 * 	@param slideNumber : slide number
84
 * 	@param want169 : to have a 16:9 aspect ratio
85
*/
86
12
void saveBeamerBackground(std::ofstream & fs, const std::string & filePng, long unsigned int slideNumber, bool want169){
87
12
	if(want169){
88
4
		fs << "\\pgfdeclareimage[height=90mm, interpolate=true]{slide"<<slideNumber<<"}{"<<filePng<<"}" << endl;
89
	}else{
90
8
		fs << "\\pgfdeclareimage[height=96mm,width=128mm]{slide"<<slideNumber<<"}{"<<filePng<<"}" << endl;
91
	}
92
12
	fs << "\\setbeamertemplate{background}{\\pgfuseimage{slide"<<slideNumber<<"}}" << endl;
93
12
}
94
95
///Save the beamer slide number
96
/**	@param[out] fs : file to be written
97
 * 	@param slideNumber : slide number
98
 * 	@param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
99
 * 	@param footPage : string to be written in the footpage of the slides
100
 * 	@param footPageColor : color of the foot page
101
*/
102
12
void saveBeamerSlideNumber(std::ofstream & fs, long unsigned int slideNumber, const std::string & numberColor,
103
			const std::string & footPage, const std::string & footPageColor)
104
{
105
12
	if(slideNumber != 0lu){
106
6
		if(footPage != ""){
107
5
			fs << "\t\\begin{textblock*}{0.9\\textwidth}(0.01\\textwidth,0.97\\textheight)" << endl;
108
5
			fs << "\t\t\\large{\\color{"<<footPageColor<<"} " << footPage << "}" << endl;
109
5
			fs << "\t\\end{textblock*}" << endl;
110
		}
111
6
		fs << "\t\\begin{textblock*}{0.1\\textwidth}(0.960\\textwidth,0.98\\textheight)" << endl;
112
6
		fs << "\t\t\\textbf{\\Large{\\color{"<<numberColor<<"} " << (slideNumber + 1lu) << "}}" << endl;
113
6
		fs << "\t\\end{textblock*}" << endl;
114
	}
115
12
}
116
117
///Save the beamer slide with a tex file
118
/**	@param[out] fs : file to be written
119
 * 	@param fileTex : name of the tex file to be red
120
 * 	@param slideNumber : slide number
121
 * 	@param want169 : to have a 16:9 aspect ratio
122
 * 	@param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
123
 * 	@param footPage : string to be written in the footpage of the slides
124
 * 	@param footPageColor : color of the foot page
125
*/
126
11
void saveBeamerSlideTex(std::ofstream & fs, const std::string & fileTex, long unsigned int slideNumber, bool want169, const std::string & numberColor,
127
			const std::string & footPage, const std::string & footPageColor)
128
{
129
22
	std::string backGroundFile(CMAKE_INSTALL_PREFIX "/share/BeamerCreator/theme2.png");
130
11
	if(slideNumber == 0){
131
6
		backGroundFile = CMAKE_INSTALL_PREFIX "/share/BeamerCreator/firstTheme.png";
132
	}
133
11
	saveBeamerBackground(fs, backGroundFile, slideNumber, want169);
134
135
11
	fs << "\\frame{"<<endl;
136
11
	fs << getFileContent(fileTex) << endl;
137
11
	saveBeamerSlideNumber(fs, slideNumber, numberColor, footPage, footPageColor);
138
11
	fs << "}" << endl << endl;
139
11
}
140
141
142
143
///Make the beamer tex slide
144
/**	@param[out] fs : file to be completed
145
 * 	@param filePng : file png to be in the slide
146
 * 	@param slideNumber : slide number
147
 * 	@param want169 : to have a 16:9 aspect ratio
148
 * 	@param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
149
 * 	@param footPage : string to be written in the footpage of the slides
150
 * 	@param footPageColor : color of the foot page
151
*/
152
1
void saveBeamerSlidePng(std::ofstream & fs, const std::string & filePng, long unsigned int slideNumber, bool want169, const std::string & numberColor,
153
			const std::string & footPage, const std::string & footPageColor)
154
{
155
1
	saveBeamerBackground(fs, filePng, slideNumber, want169);
156
1
	fs << "\\frame{"<<endl;
157
1
	saveBeamerSlideNumber(fs, slideNumber, numberColor, footPage, footPageColor);
158
1
	fs << "}" << endl << endl;
159
1
}
160
161
///Make the beamer tex slide
162
/**	@param[out] fs : file to be completed
163
 * 	@param filePng : file png to be in the slide
164
 * 	@param slideNumber : slide number
165
 * 	@param want169 : to have a 16:9 aspect ratio
166
 * 	@param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
167
 * 	@param footPage : string to be written in the footpage of the slides
168
 * 	@param footPageColor : color of the foot page
169
*/
170
13
void saveBeamerSlide(std::ofstream & fs, const std::string & filePng, long unsigned int slideNumber, bool want169, const std::string & numberColor,
171
			const std::string & footPage, const std::string & footPageColor)
172
{
173
	//Check if the extention is not png
174
	//	If the extention is tex I need to put the content into a slide
175
	//	I need also to add the theme and the page number
176
177
26
	std::string fileExtention(getExtention(filePng));
178
13
	if(fileExtention == "png"){
179
1
		saveBeamerSlidePng(fs, filePng, slideNumber, want169, numberColor, footPage, footPageColor);
180
12
	}else if(fileExtention == "tex"){
181
11
		saveBeamerSlideTex(fs, filePng, slideNumber, want169, numberColor, footPage, footPageColor);
182
	}else{
183

1
		cerr << "saveBeamerSlide : unknown extention '"<<fileExtention<<"' of file '"<<filePng<<"'" << endl;
184
	}
185
13
}
186
187
///Make the tex slides
188
/**	@param outputFileName : output file name
189
 * 	@param listInputFile : list of the png slides input
190
 * 	@param want169 : to have a 16:9 aspect ratio
191
 * 	@param numberColor : color of the slide number (black, white, red, blue, green, yellow, gray(by default))
192
 * 	@param footPage : string to be written in the footpage of the slides
193
 * 	@param footPageColor : color of the foot page
194
*/
195
9
void makeTexSlides(const std::string & outputFileName, const std::list<std::string> & listInputFile, bool want169, const std::string & numberColor,
196
			const std::string & footPage, const std::string & footPageColor)
197
{
198

9
	if(outputFileName == "" || listInputFile.size() == 0lu){return;}
199
200
7
	std::ofstream fs;
201
7
	fs.open(outputFileName.c_str());
202
7
	if(!fs.is_open()){
203
		std::cerr << "makeTexSlides : can't open file '" << outputFileName << "'" << std::endl;
204
		return;
205
	}
206
7
	saveBeamerHeaderTex(fs, want169);
207
208
7
	fs << "\\begin{document}" << endl;
209
14
	std::string previousFile("");
210
7
	long unsigned int i(-1lu);
211
20
	for(std::list<std::string>::const_iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
212
26
		std::list<std::string> listFileName = cutStringList(*it, '/');
213
26
		std::string currentFileName(listFileName.back());
214
215

13
		if(previousFile.size() < 6lu || currentFileName.size() < 6lu){
216
7
			++i;
217
		}else{
218

6
			if(previousFile.substr(0, previousFile.size() - 6lu) != currentFileName.substr(0, currentFileName.size() - 6lu)){
219
6
				++i;
220
			}
221
		}
222
13
		previousFile = currentFileName;
223
13
		saveBeamerSlide(fs, *it, i, want169, numberColor, footPage, footPageColor);
224
	}
225
226
7
	fs << "\\end{document}" << endl;
227
228
7
	fs.close();
229
}
230
231
9
int main(int argc, char** argv){
232
18
	OptionParser parser = createOptionParser();
233
9
	parser.parseArgument(argc, argv);
234
235
9
	const OptionMode & defaultMode = parser.getDefaultMode();
236
18
	std::list<std::string> listInputFile;
237
9
	defaultMode.getValue(listInputFile, "input");
238
239
18
	std::string outputFile("output.tex");
240
9
	defaultMode.getValue(outputFile, "output");
241
242
18
	std::string numberColor("gray");
243
9
	defaultMode.getValue(numberColor, "numbercolor");
244
245
18
	std::string footPage("");
246
9
	defaultMode.getValue(footPage, "footpage");
247
248
9
	std::string footPageColor("white");
249
9
	defaultMode.getValue(footPageColor, "footpagecolor");
250
251
9
	bool is169 = defaultMode.isOptionExist("169");
252
9
	makeTexSlides(outputFile, listInputFile, is169, numberColor, footPage, footPageColor);
253
9
	return 0;
254
}
255