main.cc 5.9 KB
Newer Older
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
1
#include <iostream>
2
3
4
#include <string>
#include <string>
#include <cstdlib>
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
5
6
7
8
9
#include "xml_transform.hh"

int main(int argc, char **argv)
{

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
10
  std::string man;
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
11
12
  man = "xml_transform\n"
    "OPTIONS:\n\n"
13

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
14
    "HTML output:\n"
15
16
17
18
19
20
21
22
    "\t\033[01m--html\033[00m\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.html\033[00m"
    "\t\t\tCreates HTML file, images are embedded inside in base 64 format.\n"
    "\t\033[01m--html-base64\033[00m \033[04minput.xml\033[00m \033[04moutput.html\033[00m"
    "\t\t\tSame as --html but input is a XML file with images encoded in base 64 inside.\n"

    "\t\033[01m--html-full\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput_dir\033[00m"
    "\t\t\tCreates HTML file without converting images in base 64. Images + HTML file are placed in output_dir.\n\n"

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
23
    "PDF output:\n"
24
25
26
27
28
29
30
31
32
33
    "\t\033[01m--pdf\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.pdf\033[00m"
    "\t\t\tCreates PDF file, images are embedded inside in base 64 format.\n"
    "\t\033[01m--pdf-base64\033[00m \033[04minput.xml\033[00m \033[04moutput.pdf\033[00m"
    "\t\t\tSame as --pdf but input is a XML file with images encoded in base 64 inside.\n\n"

    "SVG output (experimental, may not work with all files):\n"
    "\t\033[01m--svg\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.svg\033[00m"
    "\t\t\tCreates SVG file, images are embedded inside in base 64 format.\n"
    "\t\033[01m--svg-base64\033[00m \033[04minput.xml\033[00m \033[04moutput.svg\033[00m"
    "\t\t\tSame as --svg but input is a XML file with images encoded in base 64 inside.\n\n"
34
35

    "OpenDocument output:\n"
36
37
38
    "\t\033[01m--oo-doc\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.odt\033[00m"
    "\t\t\tCreates Open Document Writer (odt) file.\n\n"

39
    "Base 64 operations:\n"
40
41
42
    "\t\033[01m--to-base64\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.xml\033[00m"
    "\t\t\tCreates a container XML file. It will contain regions which are cropped and converted in base 64.\n"

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
43
    "\t\033[01m--to-base64-no-crop\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.xml\033[00m"
44
45
46
47
48
    "\t\tSame as --to-base64 but only the full picture will be converted, regions are not cropped\n"

    "\t\033[01m--from-base64\033[00m \033[04minput.xml\033[00m \033[04moutput_dir\033[00m"
    "\t\t\tDecodes a XML file which has been encoded in base 64, regions will be converted into png files and saved in output_dir.\n\n"

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
49
50
51
    "Requirements:\n"
    "PDF : fop >= 0.95\n"
    "HTML : xsltproc\n"
52
    "SVG : trunk version of fop\n"
53
    "OpenDocument : ooconvert (included)";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
54
55
56
  if (argc > 4)
    {
      std::string html = "--html";
57
58
      std::string html_full = "--html-full";
      std::string open = "--oo-doc";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
59
      std::string pdf = "--pdf";
60
      std::string svg = "--svg";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
61
62
      std::string to_base64 = "--to-base64";
      std::string to_base64nocrop = "--to-base64-no-crop";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
63

64
      if (html_full.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
65
66
67
	{
	  XmlTransform xmlt(argv[2], argv[3], argv[4]);
	  xmlt.createHTML(false);
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

	  QString cmd = "sh templates/xml_transform.sh html " + xmlt.out() + "output.xml " +  xmlt.out() + "output.html";
	  return system (cmd.toAscii().constData());
	}
      else if (html.compare(argv[1]) == 0)
	{
	  QTemporaryFile tmp;
	  tmp.open();
	  tmp.fileName();

	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), tmp.fileName());
	  xmlt.toBase64(false);

	  QString cmd = "sh templates/xml_transform.sh html-base64 " + tmp.fileName() + " " + argv[4];
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
83
	}
84
      else if (pdf.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
85
	{
86
87
88
89
90
91
92
93
94
	  QTemporaryFile tmp;
	  tmp.open();
	  tmp.fileName();

	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), tmp.fileName());
	  xmlt.toBase64(false);

	  QString cmd = "sh templates/xml_transform.sh pdf " + tmp.fileName() + " " + argv[4];
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
95
	}
96
      else if (svg.compare(argv[1]) == 0)
97
	{
98
99
100
101
102
103
104
105
106
	  QTemporaryFile tmp;
	  tmp.open();
	  tmp.fileName();

	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), tmp.fileName());
	  xmlt.toBase64(false);

	  QString cmd = "sh templates/xml_transform.sh svg " + tmp.fileName() + " " + argv[4];
	  return system (cmd.toAscii().constData());
107
	}
108
      else if (open.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
109
	{
110
111
112
113
114
115
	  QString dir = QDir::tempPath() + "/xml_transform." + argv[4];
	  XmlTransform xmlt(argv[2], argv[3], dir);
	  xmlt.createOpen();

	  QString cmd = "sh templates/xml_transform.sh oo-doc " + dir + " " + argv[4];
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
	}
      else if (to_base64.compare(argv[1]) == 0)
	{
	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
	  xmlt.toBase64(false);
	}
      else if (to_base64nocrop.compare(argv[1]) == 0)
	{
	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
	  xmlt.toBase64(true);
	}
      else
	std::cout << man << std::endl;
    }
  else if (argc > 3)
    {
132
133
134
      std::string pdf_base64 = "--pdf-base64";
      std::string svg_base64 = "--svg-base64";
      std::string html_base64 = "--html-base64";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
135
136
      std::string from_base64 = "--from-base64";

137
      if (svg_base64.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
138
	{
139
140
	  QString cmd = "sh templates/xml_transform.sh svg " + QString(argv[2]) + " " + QString(argv[3]);
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
141
	}
142
      else if (pdf_base64.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
143
	{
144
145
	  QString cmd = "sh templates/xml_transform.sh pdf " + QString(argv[2]) + " " + QString(argv[3]);
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
146
	}
147
      else if (html_base64.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
148
	{
149
150
	  QString cmd = "sh templates/xml_transform.sh html-base64 " + QString(argv[2]) + " " + QString(argv[3]);
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
151
152
153
154
155
156
	}
      else if (from_base64.compare(argv[1]) == 0)
	{
	  XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
	  xmlt.fromBase64();
	}
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
157
158
159
160
161
162
163
164
      else
	std::cout << man << std::endl;
    }
  else
    std::cout << man << std::endl;

  return 0;
}