7#include "convertToString.h"
9#include "OptionParser.h"
10#include "pxml_utils.h"
18 OptionParser parser(
true, __PROGRAM_VERSION__);
19 parser.setExampleLongOption(
"phoenix_inkscapesplitter --input=file.svg --output=output/dir/");
20 parser.setExampleShortOption(
"phoenix_inkscapesplitter -i file1.svg file1.svg fileN.svg -o output/dir/");
22 parser.addOption(
"input",
"i", OptionType::FILENAME,
true,
"list of input files to be treated");
24 PString defaultOutputDir(
".");
25 parser.addOption(
"output",
"o", defaultOutputDir,
"Output directory");
35 long unsigned int end;
44typedef std::vector<long unsigned int>
PSlide;
56 if(pxml_getAttrIfExist(attrXml, layerXml,
"inkscape:label")){
57 attr = attrXml.getValue();
67 long unsigned int i(0lu);
68 for(PVecXml::const_iterator itLayer(vecLayer.begin()); itLayer != vecLayer.end(); ++itLayer){
70 std::cout <<
"\tlayer '" << inkscapeLabel <<
"'";
71 PVecString listNb(inkscapeLabel.split(
'-'));
72 long unsigned int begin(0lu), end(0lu);
73 bool isBeginDefined(
false), isEndDefine(
false);
75 for(PVecString::iterator it(listNb.begin()); it != listNb.end(); ++it){
78 end = atol(it->c_str());
81 begin = atol(it->c_str());
82 isBeginDefined =
true;
85 if(*it ==
"N" && isBeginDefined){
87 std::cout <<
"\t=> until end";
92 std::cout << std::endl;
93 if(!isBeginDefined && !isEndDefine){
100 if(isEndDefine){layer.
end = end;}
101 else{layer.
end = begin;}
102 vecLayerSlide.push_back(layer);
112 long unsigned int i(0lu);
113 for(PVecLayer::const_iterator it(vecLayerSlide.begin()); it != vecLayerSlide.end(); ++it){
114 if(index >= it->begin && index <= it->end){
126 if(vecLayerSlide.size() == 0lu){
return;}
127 PVecLayer::iterator it(vecLayerSlide.begin());
128 long unsigned int minSlide(it->begin), maxSlide(it->end);
130 while(it != vecLayerSlide.end()){
131 if(it->begin < minSlide){minSlide = it->begin;}
132 if(it->end > maxSlide){maxSlide = it->end;}
135 for(PVecLayer::iterator itCmd(vecLayerSlide.begin()); itCmd != vecLayerSlide.end(); ++itCmd){
136 if(itCmd->command ==
"UntilEnd"){
137 itCmd->end = maxSlide;
140 for(
long unsigned int i(minSlide); i < maxSlide + 1lu; ++i){
143 vecSlide.push_back(slide);
153 return "0" + valueToString(i);
155 return valueToString(i);
168 const PVecSlide & vecSlides,
const PVecXml & vecLayerXml,
const PXml & lighRoot,
bool isInkscapeExist)
170 long unsigned int i(0lu);
171 for(PVecSlide::const_iterator itSlide(vecSlides.begin()); itSlide != vecSlides.end(); ++itSlide){
172 PXml tmpRoot(lighRoot);
174 PXml * svgPtr = pxml_getChildPtr(tmpRoot,
"svg");
175 const PSlide & slide = *itSlide;
176 for(PSlide::const_iterator it(slide.begin()); it != slide.end(); ++it){
178 PXml tmpLayer(vecLayerXml[*it]);
179 pxml_setAttr(tmpLayer,
"style",
"display:inline");
180 svgPtr->getVecChild().push_back(tmpLayer);
183 PPath outputSlide(PPath(
"./") + baseOutputName + PPath(
"_") +
getSlideNumber(i) + PPath(
".svg"));
185 PString slideContent(pxml_baliseStr(tmpRoot,
true));
191 if(!outputSlide.saveFileContent(slideContent)){
192 std::cerr <<
"saveSlides : can't save svg file '"<<outputSlide<<
"'" << std::endl;
196 PPath outputSlidePng(baseOutputName + PPath(
"_") +
getSlideNumber(i) + PPath(
".png"));
198 PString command(PString(
"convert ") + outputSlide + PString(
" ") + outputSlidePng);
201 if(system(command.c_str()) != 0){
202 std::cerr <<
"saveSlides : can't create png file with command '"<<command<<
"'" << std::endl;
203 return !isInkscapeExist;
206 command = PString(
"rm ") + outputSlide;
207 if(system(command.c_str()) != 0){
208 std::cerr <<
"saveSlides : can't remove temporary svg file with command '"<<command<<
"'" << std::endl;
222 if(inputFile ==
""){
return false;}
224 if(!pxml_parserFile(root, inputFile)){
225 std::cerr <<
"processFileSvg : can't load file '"<<inputFile<<
"'" << std::endl;
234 if(!pxml_getChildIfExist(svgBalise, root,
"svg")){
235 std::cerr <<
"processFileSvg : can't find 'svg' balise in root" << std::endl;
245 if(!pxml_getVecChildIfExist(vecLayer, svgBalise,
"g")){
246 std::cerr <<
"processFileSvg : can't find 'g' balise in svg" << std::endl;
249 long unsigned int nbCalque(vecLayer.size());
250 std::cout <<
"processFileSvg : get " << nbCalque <<
" layer";
251 if(nbCalque > 1lu){std::cout <<
"s";}
252 std::cout << std::endl;
256 if(vecLayerSlide.size() == 0lu){
257 std::cerr <<
"processFileSvg : no layer defined with -begin-end synthax" << std::endl;
264 PXml * svgPtr = pxml_getChildPtr(lighRoot,
"svg");
265 PXml svgNoLayer(pxml_eraseVecChild(*svgPtr,
"g"));
266 *svgPtr = svgNoLayer;
269 PString baseOutputSlideName(inputFile.getFileName().eraseExtension());
271 bool b =
saveSlides(outputMode, baseOutputSlideName, vecSlides, vecLayer, lighRoot, isInkscapeExist);
281 if(listInputFile.size() == 0lu){
282 std::cerr <<
"processFiles : no input file" << std::endl;
285 bool isInkscapeExist = system(
"inkscape --version") == 0;
287 for(std::vector<PPath>::const_iterator it(listInputFile.begin()); it != listInputFile.end() && b; ++it){
293int main(
int argc,
char** argv){
295 parser.parseArgument(argc, argv);
297 const OptionMode & defaultMode = parser.getDefaultMode();
298 std::vector<PPath> listInputFile;
299 defaultMode.getValue(listInputFile,
"input");
std::vector< PSlide > PVecSlide
Define the layer in slide.
std::vector< PLayer > PVecLayer
Vector of layer.
PString getInkscapeLabel(const PXml &layerXml)
Get the inkscape label of current PXml.
void createVecSlide(PVecSlide &vecSlide, PVecLayer &vecLayerSlide)
Create the vector of slides.
int main(int argc, char **argv)
void createSlideWithLayer(PSlide &slide, const PVecLayer &vecLayerSlide, long unsigned int index)
Create the slide to be generated.
bool saveSlides(POutoutMode &outputMode, const PPath &baseOutputName, const PVecSlide &vecSlides, const PVecXml &vecLayerXml, const PXml &lighRoot, bool isInkscapeExist)
Save the slides.
int processFiles(const std::vector< PPath > &listInputFile)
Process all the input files.
void createVectorSlide(PVecLayer &vecLayerSlide, const PVecXml &vecLayer)
Create the vector of slide layer.
bool processFileSvg(const PPath &inputFile, bool isInkscapeExist)
Process all the input files.
OptionParser createOptionParser()
Create the OptionParser of this program.
PString getSlideNumber(long unsigned int i)
Convert the slide index into string.
std::vector< long unsigned int > PSlide
Slide composed of layer.
void pinkscape_loadSlideMap(PMapSlide &mapFormula, const PPath &baseOutputName)
Load the map file of all the formulae if it exists.
void pinkscape_saveSlideMap(const PMapSlide &mapFormula, const PPath &baseOutputName)
Save the map file of the formulae to avoid extra latex call.
bool pinkscape_isSlideKnown(POutoutMode &outputMode, const PPath &outputSlide, const PString &slideContent)
Check if the slide we are going to save was already saved (with the same content) or not.
Get the begin and end slide for current layer.
long unsigned int end
Last slide where the layer has to be printed.
long unsigned int begin
first slide where the layer has to be printed
PString command
Extra command.
Output mode of the html backend.
PMapSlide mapSlide
Map of the formula which are already saved as png files.