PhoenixSlider  1.0.0
Create HTML presentation automatically
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_slider --input=fileInput.png --output=output.html");
20 parser.setExampleShortOption("phoenix_slider -i fileInput1.png fileInput2.png fileInput3.mp4 fileInput4.png -o output.html");
21
22 parser.addOption("input", "i", OptionType::FILENAME, true, "list of input files");
23
24 PString defaultOutput("output.html");
25 parser.addOption("output", "o", defaultOutput, "name of the output HTML file");
26
27 PString defaultColor("black");
28 parser.addOption("numbercolor", "n", defaultColor, "color of the slides' number (black, white, blue, green, red, yellow, gray(by default))");
29
30 PString defaultTextFootpage("");
31 parser.addOption("footpage", "f", defaultTextFootpage, "text to be written on the foot page");
32
33 PString defaultFootpageColor("white");
34 parser.addOption("footpagecolor", "g", defaultFootpageColor, "color of the foot page (black, white, blue, green, red, yellow, white(by default))");
35
36 return parser;
37}
38
40
44void slider_saveHtmlHeader(std::ofstream & fs, const PString & numberColor, const PString & footPageColor){
45 fs << "<!DOCTYPE html>\n";
46 fs << "<html>\n";
47 fs << "\t<head>\n";
48 fs << "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
49 fs << "\t\t<style>\n";
50 fs << "\t\t\t* {box-sizing: border-box;}\n";
51 fs << "\t\t\tbody {\n";
52// fs << "\t\t\t\tfont-family: Verdana, sans-serif;\n";
53 fs << "\t\t\t\tfont-family: Arial, sans-serif;\n";
54 fs << "\t\t\t\tbackground-color: black;\n";
55// fs << "\t\t\t\t/* margin: auto; */\n";
56 fs << "\t\t\t}\n";
57 fs << "\t\t\t.mySlides {\n";
58 fs << "\t\t\t\tdisplay: none;\n";
59 fs << "\t\t\t\tvertical-align: middle;\n";
60 fs << "\t\t\t}\n";
61 fs << "\t\t\timg {\n";
62 fs << "\t\t\t\tvertical-align: middle;\n";
63 fs << "\t\t\t}\n";
64 fs << "\t\t\t\n";
65 fs << "\t\t\t/* Slideshow container */\n";
66 fs << "\t\t\t.slideshow-container {\n";
67// fs << "\t\t\t\t/* max-width: 1000px; */ /*Limite pour rien la taille des slides*/\n";
68 fs << "\t\t\t\tposition: relative;\n";
69 fs << "\t\t\t\tmargin: auto;\n";
70 fs << "\t\t\t}\n";
71 fs << "\t\t\t\n";
72 fs << "\t\t\t/* Caption text */\n";
73 fs << "\t\t\t.text {\n";
74// fs << "\t\t\t\t/* color: #f2f2f2; */\n";
75 fs << "\t\t\t\tcolor: "<<footPageColor<<";\n";
76// fs << "\t\t\t\t/* color: black; */\n";
77 fs << "\t\t\t\tfont-size: 30px;\n";
78 fs << "\t\t\t\tpadding: 8px 12px;\n";
79 fs << "\t\t\t\tposition: absolute;\n";
80 fs << "\t\t\t\tbottom: 8px;\n";
81 fs << "\t\t\t\tmargin-left: 40px;\n";
82// fs << "\t\t\t\twidth: 100%;\n";
83 fs << "\t\t\t\ttext-align: left;\n";
84 fs << "\t\t\t}\n";
85 fs << "\t\t\t\n";
86 fs << "\t\t\t/* Number text (1/3 etc) */\n";
87 fs << "\t\t\t.numbertext {\n";
88// fs << "\t\t\t\t/* color: #f2f2f2; */\n";
89 fs << "\t\t\t\tcolor: "<<numberColor<<";\n";
90 fs << "\t\t\t\tfont-size: 40px;\n";
91 fs << "\t\t\t\tpadding: 8px 12px;\n";
92 fs << "\t\t\t\tposition: absolute;\n";
93// fs << "\t\t\t\t/* top: 0; */\n";
94 fs << "\t\t\t\tbottom: 8px;\n";
95 fs << "\t\t\t\twidth: 100%;\n";
96 fs << "\t\t\t\ttext-align: right;\n";
97 fs << "\t\t\t}\n";
98 fs << "\t\t\t\n";
99 fs << "\t\t\t.slideContent{\n";
100 fs << "\t\t\t\tcolor: "<<footPageColor<<";\n";
101 fs << "\t\t\t\tdisplay: block;\n";
102 fs << "\t\t\t\tposition: absolute;\n";
103 fs << "\t\t\t\twidth: 100%;\n";
104 fs << "\t\t\t\ttop: 0px;\n";
105 fs << "\t\t\t}\n";
106
107 fs << "\t\t\t.slideContent h1{\n";
108 fs << "\t\t\t\tcolor: "<<footPageColor<<";\n";
109 fs << "\t\t\t\ttext-align: center;\n";
110 fs << "\t\t\t\tfont-size: 60px;\n";
111 fs << "\t\t\t}\n";
112
113 fs << "\t\t\t.slideContent .slidebody{\n";
114 fs << "\t\t\t\tcolor: "<<footPageColor<<";\n";
115 fs << "\t\t\t\tmargin-left: 40px;\n";
116 fs << "\t\t\t\ttext-align: left;\n";
117 fs << "\t\t\t\tfont-size: 40px;\n";
118 fs << "\t\t\t}\n";
119
120// fs << "\t\t\t/*.vertical-center {\n";
121// fs << "\t\t\t\tmargin: 0;\n";
122// fs << "\t\t\t\tposition: absolute;\n";
123// fs << "\t\t\t\ttop: 50%;\n";
124// fs << "\t\t\t\t-ms-transform: translateY(-50%);\n";
125// fs << "\t\t\t\ttransform: translateY(-50%);\n";
126// fs << "\t\t\t}*/\n";
127// fs << \t"\t\t\n";
128 fs << "\t\t\t/* The dots/bullets/indicators */\n";
129 fs << "\t\t\t.dot {\n";
130 fs << "\t\t\t\theight: 15px;\n";
131 fs << "\t\t\t\twidth: 15px;\n";
132 fs << "\t\t\t\tmargin: 0 2px;\n";
133 fs << "\t\t\t\tbackground-color: #bbb;\n";
134 fs << "\t\t\t\tborder-radius: 50%;\n";
135 fs << "\t\t\t\tdisplay: inline-block;\n";
136 fs << "\t\t\t\ttransition: background-color 0.6s ease;\n";
137 fs << "\t\t\t}\n";
138 fs << "\t\t\t\n";
139 fs << "\t\t\t.active {\n";
140 fs << "\t\t\t\tbackground-color: #717171;\n";
141 fs << "\t\t\t}\n";
142 fs << "\t\t\t\n";
143 fs << "\t\t\t/* Fading animation */\n";
144 fs << "\t\t\t.fade {\n";
145 fs << "\t\t\t\tanimation-name: fade;\n";
146 fs << "\t\t\t\tanimation-duration: 1.5s;\n";
147 fs << "\t\t\t}\n";
148 fs << "\t\t\t\n";
149 fs << "\t\t\t@keyframes fade {\n";
150 fs << "\t\t\t\tfrom {opacity: .4}\n";
151 fs << "\t\t\t\tto {opacity: 1}\n";
152 fs << "\t\t\t}\n";
153 fs << "\t\t\t\n";
154 fs << "\t\t\t/* On smaller screens, decrease text size */\n";
155 fs << "\t\t\t@media only screen and (max-width: 300px) {\n";
156 fs << "\t\t\t\t.text {font-size: 11px}\n";
157 fs << "\t\t\t}\n";
158 fs << "\t\t</style>\n";
159 fs << "\t</head>\n";
160}
161
163
165void slider_saveJavascript(std::ofstream & fs){
166 fs << "<script>\n";
167 fs << "let slideIndex = 1;\n";
168 fs << "showSlides(slideIndex);\n";
169 fs << "\n";
170 fs << "// Next/previous controls\n";
171 fs << "function plusSlides(n){\n";
172 fs << "\tshowSlides(slideIndex += n);\n";
173 fs << "}\n";
174 fs << "\n";
175 fs << "// Thumbnail image controls\n";
176 fs << "function currentSlide(n){\n";
177 fs << "\tshowSlides(slideIndex = n);\n";
178 fs << "}\n";
179 fs << "\n";
180 fs << "function showSlides(n) {\n";
181 fs << "\tlet i;\n";
182 fs << "\tlet slides = document.getElementsByClassName(\"mySlides\");\n";
183// fs << "\t// let dots = document.getElementsByClassName(\"dot\");\n";
184 fs << "\tif(n > slides.length){slideIndex = 1}\n";
185 fs << "\tif(n < 1){slideIndex = slides.length}\n";
186 fs << "\tfor(i = 0; i < slides.length; i++){\n";
187 fs << "\t\tslides[i].style.display = \"none\";\n";
188 fs << "\t}\n";
189// fs << "\t// for (i = 0; i < dots.length; i++) {\n";
190// fs << "\t// dots[i].className = dots[i].className.replace(\" active\", \"\");\n";
191// fs << "\t// }\n";
192 fs << "\tslides[slideIndex-1].style.display = \"block\";\n";
193// fs << "\t// dots[slideIndex-1].className += \" active\";\n";
194 fs << "}\n";
195 fs << "\n";
196 fs << "document.onkeydown = function(e){\n";
197 fs << "\tswitch(e.keyCode){\n";
198 fs << "\t\tcase 37:\n";
199 fs << "\t\t\t//left\n";
200 fs << "\t\t\te.preventDefault();\n";
201 fs << "\t\t\tslideIndex--;\n";
202 fs << "\t\t\tshowSlides(slideIndex);\n";
203 fs << "\t\t\tbreak;\n";
204 fs << "\t\tcase 39:\n";
205 fs << "\t\t\t//right\n";
206 fs << "\t\t\te.preventDefault();\n";
207 fs << "\t\t\tslideIndex++;\n";
208 fs << "\t\t\tshowSlides(slideIndex);\n";
209 fs << "\t\t\tbreak;\n";
210 fs << "\t}\n";
211 fs << "}\n";
212 fs << "</script>\n";
213}
214
216
220void slider_saveHtmlSlideNumber(std::ofstream & fs, long unsigned int slideNumber, const PString & footPage){
221 if(slideNumber != 0lu){
222 fs << "\t\t\t\t<div class=\"numbertext\">"<<(slideNumber + 1lu)<<"</div>\n";
223
224 if(footPage != ""){
225 fs << "\t\t\t\t<div class=\"text\">"<<footPage<<"</div>\n";
226 }
227 }
228}
229
231
236void slider_saveHtmlSlidePng(std::ofstream & fs, const PPath & filePng, long unsigned int slideNumber, const PString & footPage)
237{
238 fs << "\t\t\t<div class=\"mySlides\">\n";
239 slider_saveHtmlSlideNumber(fs, slideNumber, footPage);
240 fs << "\t\t\t\t<img src=\""<<filePng<<"\" style=\"width:100%\">\n";
241// fs << "\t\t\t\t<div class=\"text\">Caption One</div>\n";
242 fs << "\t\t\t</div>\n";
243}
244
246
251void slider_saveHtmlSlideMp4(std::ofstream & fs, const PPath & fileMp4, long unsigned int slideNumber, const PString & footPage){
252 PString loopAttribute("");
253 if(fileMp4.size() > 8lu){
254 PString baseName(fileMp4.eraseExtension());
255 if(baseName.substr(baseName.size() - 4lu, baseName.size()) == "loop"){
256 loopAttribute = " loop";
257 }
258 }
259
260 fs << "\t\t\t<div class=\"mySlides\">\n";
261 slider_saveHtmlSlideNumber(fs, slideNumber, footPage);
262 fs << "\t\t\t\t<video style=\"width:100%\" autoplay muted"<<loopAttribute<<">\n";
263 fs << "\t\t\t\t <!-- Be careful, if you do not have sound, check if the video has MP3 sound and not AC3 -->\n";
264 fs << "\t\t\t\t <source src=\""<<fileMp4<<"\" type=\"video/mp4\">\n";
265 fs << "\t\t\t\t</video>\n";
266
267// fs << "\t\t\t\t<div class=\"text\">Caption One</div>\n";
268 fs << "\t\t\t</div>\n";
269}
270
272
277void slider_saveHtmlSlideHtml(std::ofstream & fs, const PPath & fileTex, long unsigned int slideNumber, const PString & footPage)
278{
279 PString backGroundFile(CMAKE_INSTALL_PREFIX "/share/PhoenixSlider/theme2.png");
280 if(slideNumber == 0){
281 backGroundFile = CMAKE_INSTALL_PREFIX "/share/PhoenixSlider/firstTheme.png";
282 }
283 fs << "\t\t\t<div class=\"mySlides\">\n";
284 slider_saveHtmlSlideNumber(fs, slideNumber, footPage);
285 fs << "\t\t\t\t<img src=\""<<backGroundFile<<"\" style=\"width:100%\">\n";
286 fs << "\t\t\t\t<div class=\"slideContent\">\n";
287 fs << fileTex.loadFileContent() << std::endl;
288 fs << "\t\t\t\t</div>\n";
289 fs << "\t\t\t</div>\n";
290}
291
293
298void slider_saveHtmlSlide(std::ofstream & fs, const PPath & filePng, long unsigned int slideNumber, const PString & footPage){
299 //Check if the extention is png or mp4
300 // If the extention is html I need to put the content into a slide
301 // I need also to add the theme and the page number
302
303 PString fileExtention(filePng.getExtension());
304 if(fileExtention == "png"){
305 slider_saveHtmlSlidePng(fs, filePng, slideNumber, footPage);
306 }else if(fileExtention == "mp4"){
307 slider_saveHtmlSlideMp4(fs, filePng, slideNumber, footPage);
308 }else if(fileExtention == "html"){
309 slider_saveHtmlSlideHtml(fs, filePng, slideNumber, footPage);
310 }else{
311 std::cerr << "slider_saveHtmlSlide : unknown extention '"<<fileExtention<<"' of file '"<<filePng<<"'" << std::endl;
312 }
313}
314
316
322void slider_makeHtmlSlides(const PPath & outputFileName, const PVecPath & listInputFile, const PString & numberColor,
323 const PString & footPage, const PString & footPageColor)
324{
325 if(outputFileName == "" || listInputFile.size() == 0lu){return;}
326
327 std::ofstream fs;
328 fs.open(outputFileName.c_str());
329 if(!fs.is_open()){
330 std::cerr << "slider_makeHtmlSlides : can't open file '" << outputFileName << "'" << std::endl;
331 return;
332 }
333 slider_saveHtmlHeader(fs, numberColor, footPageColor);
334
335 fs << "\t<body>" << std::endl;
336 fs << "\t\t<div class=\"slideshow-container\">" << std::endl;
337 PString previousFile("");
338 long unsigned int i(-1lu);
339 for(PVecPath::const_iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
340 PVecString listFileName = it->split('/');
341 PString currentFileName(listFileName.back());
342
343 if(previousFile.size() < 6lu || currentFileName.size() < 6lu){
344 ++i;
345 }else{
346 if(previousFile.substr(0, previousFile.size() - 6lu) != currentFileName.substr(0, currentFileName.size() - 6lu)){
347 ++i;
348 }
349 }
350 previousFile = currentFileName;
351 slider_saveHtmlSlide(fs, *it, i, footPage);
352 }
353 fs << "\t\t</div>" << std::endl;
354 fs << "\t\t<br>" << std::endl;
356 fs << "\t</body>" << std::endl;
357 fs << "</html>\n" << std::endl;
358
359 fs.close();
360}
361
362int main(int argc, char** argv){
363 OptionParser parser = createOptionParser();
364 parser.parseArgument(argc, argv);
365
366 const OptionMode & defaultMode = parser.getDefaultMode();
367 PVecPath listInputFile;
368 defaultMode.getValue(listInputFile, "input");
369
370 PPath outputFile("output.html");
371 defaultMode.getValue(outputFile, "output");
372
373 PString numberColor("black");
374 defaultMode.getValue(numberColor, "numbercolor");
375
376 PString footPage("");
377 defaultMode.getValue(footPage, "footpage");
378
379 PString footPageColor("white");
380 defaultMode.getValue(footPageColor, "footpagecolor");
381
382 slider_makeHtmlSlides(outputFile, listInputFile, numberColor, footPage, footPageColor);
383 return 0;
384}
385
void slider_makeHtmlSlides(const PPath &outputFileName, const PVecPath &listInputFile, const PString &numberColor, const PString &footPage, const PString &footPageColor)
Make the tex slides.
Definition main.cpp:322
int main(int argc, char **argv)
Definition main.cpp:362
void slider_saveHtmlSlideNumber(std::ofstream &fs, long unsigned int slideNumber, const PString &footPage)
Save the HTML slide number.
Definition main.cpp:220
void slider_saveHtmlSlidePng(std::ofstream &fs, const PPath &filePng, long unsigned int slideNumber, const PString &footPage)
Make the html png slide.
Definition main.cpp:236
void slider_saveJavascript(std::ofstream &fs)
Make the HTML slider javascript.
Definition main.cpp:165
void slider_saveHtmlSlide(std::ofstream &fs, const PPath &filePng, long unsigned int slideNumber, const PString &footPage)
Make the beamer tex slide.
Definition main.cpp:298
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition main.cpp:17
void slider_saveHtmlHeader(std::ofstream &fs, const PString &numberColor, const PString &footPageColor)
Make the HTML slider header.
Definition main.cpp:44
void slider_saveHtmlSlideMp4(std::ofstream &fs, const PPath &fileMp4, long unsigned int slideNumber, const PString &footPage)
Make the html mp4 slide.
Definition main.cpp:251
void slider_saveHtmlSlideHtml(std::ofstream &fs, const PPath &fileTex, long unsigned int slideNumber, const PString &footPage)
Save the html slide with a html file.
Definition main.cpp:277