1 #include "bcdisplayinfo.h"
10 #define _(String) gettext(String)
11 #define gettext_noop(String) String
12 #define N_(String) gettext_noop (String)
14 #include "empty_svg.h"
18 PLUGIN_THREAD_OBJECT(SvgMain, SvgThread, SvgWin)
25 SvgWin::SvgWin(SvgMain *client, int x, int y)
26 : BC_Window(client->gui_string,
37 this->client = client;
44 int SvgWin::create_objects()
48 // add_tool(new BC_Title(x, y, _("In X:")));
50 // in_x = new SvgCoord(this, client, x, y, &client->config.in_x);
51 // in_x->create_objects();
54 // add_tool(new BC_Title(x, y, _("In Y:")));
56 // in_y = new SvgCoord(this, client, x, y, &client->config.in_y);
57 // in_y->create_objects();
60 // add_tool(new BC_Title(x, y, _("In W:")));
62 // in_w = new SvgCoord(this, client, x, y, &client->config.in_w);
63 // in_w->create_objects();
66 // add_tool(new BC_Title(x, y, _("In H:")));
68 // in_h = new SvgCoord(this, client, x, y, &client->config.in_h);
69 // in_h->create_objects();
75 add_tool(new BC_Title(x, y, _("Out X:")));
77 out_x = new SvgCoord(this, client, x, y, &client->config.out_x);
78 out_x->create_objects();
81 add_tool(new BC_Title(x, y, _("Out Y:")));
83 out_y = new SvgCoord(this, client, x, y, &client->config.out_y);
84 out_y->create_objects();
87 add_tool(new BC_Title(x, y, _("Out W:")));
89 out_w = new SvgCoord(this, client, x, y, &client->config.out_w);
90 out_w->create_objects();
93 add_tool(new BC_Title(x, y, _("Out H:")));
95 out_h = new SvgCoord(this, client, x, y, &client->config.out_h);
96 out_h->create_objects();
100 add_tool(new_svg_button = new NewSvgButton(client, this, x, y));
101 add_tool(edit_svg_button = new EditSvgButton(client, this, x+190, y));
102 add_tool(svg_file_title = new BC_Title(x, y+26, client->config.svg_file));
111 int SvgWin::close_event()
117 SvgCoord::SvgCoord(SvgWin *win,
122 : BC_TumbleTextBox(win,
130 //printf("SvgWidth::SvgWidth %f\n", client->config.w);
131 this->client = client;
136 SvgCoord::~SvgCoord()
140 int SvgCoord::handle_event()
142 *value = atof(get_text());
144 client->send_configure_change();
148 NewSvgButton::NewSvgButton(SvgMain *client, SvgWin *window, int x, int y)
149 : BC_GenericButton(x, y, _("New/Open SVG..."))
151 this->client = client;
152 this->window = window;
155 int NewSvgButton::handle_event()
162 void NewSvgButton::run()
164 // ======================================= get path from user
166 //printf("NewSvgButton::run 1\n");
167 char directory[1024], filename[1024];
168 sprintf(directory, "~");
169 client->defaults->get("DIRECTORY", directory);
171 // Loop until file is chosen
173 NewSvgWindow *new_window;
175 new_window = new NewSvgWindow(client, window, directory);
176 new_window->create_objects();
177 new_window->update_filter("*.svg");
178 result = new_window->run_window();
179 client->defaults->update("DIRECTORY", new_window->get_path());
180 strcpy(filename, new_window->get_path());
183 // Extend the filename with .svg
184 if(strlen(filename) < 4 ||
185 strcasecmp(&filename[strlen(filename) - 4], ".svg"))
187 strcat(filename, ".svg");
190 // ======================================= try to save it
191 if(filename[0] == 0) return; // no filename given
192 if(result == 1) return; // user cancelled
194 if(in = fopen(filename, "rb"))
202 in = fopen(filename, "w+");
204 size = (((unsigned long)empty_svg[0]) << 24) +
205 (((unsigned long)empty_svg[1]) << 16) +
206 (((unsigned long)empty_svg[2]) << 8) +
207 ((unsigned long)empty_svg[3]);
208 printf("in: %p size: %li\n", in, size);
209 // FIXME this is not cool on different arhitectures
211 fwrite(empty_svg+4, size, 1, in);
214 } while(result); // file doesn't exist so repeat
216 // find out starting pixel width and height of the svg
217 // FIXME - currenlty works only for mm units
221 xml_file.read_from_file(filename);
223 result = xml_file.read_tag();
224 // printf("tag_title: %s\n", xml_file.tag.get_title());
225 if (xml_file.tag.title_is("svg\n"))
227 char *wvalue, *hvalue;
230 wvalue = xml_file.tag.get_property("width");
231 slen = strlen(wvalue);
232 if (slen<3 || strcmp(wvalue+slen-2, "mm"))
234 printf(_("SVG Width is currently only supported in milimeters: %s, falling back to 100\n"), wvalue);
241 hvalue = xml_file.tag.get_property("height");
242 slen = strlen(hvalue);
243 if (slen<3 || strcmp(hvalue+slen-2, "mm"))
245 printf(_("SVG Height is currently only supported in milimeters: %s, falling back to 100\n"), hvalue);
251 client->config.in_w = w;
252 client->config.in_h = h;
253 client->config.out_w = w;
254 client->config.out_h = h;
255 client->config.in_x = 0;
256 client->config.in_y = 0;
257 // client->config.out_x = 0;
258 // client->config.out_y = 0;
260 window->out_w->update(wvalue);
261 window->out_h->update(hvalue);
268 window->svg_file_title->update(filename);
270 strcpy(client->config.svg_file, filename);
271 client->need_reconfigure = 1;
272 client->force_png_render = 1;
273 client->send_configure_change();
276 if(quit_now) window->set_done(0);
280 EditSvgButton::EditSvgButton(SvgMain *client, SvgWin *window, int x, int y)
281 : BC_GenericButton(x, y, _("Edit"))
283 this->client = client;
284 this->window = window;
287 int EditSvgButton::handle_event()
291 if (!editing && client->config.svg_file[0] != 0)
294 editing_lock.unlock();
298 editing_lock.unlock();
303 void EditSvgButton::run()
305 // ======================================= get path from user
311 char filename_png[1024];
312 SvgSodipodiThread *sodipodi_thread = new SvgSodipodiThread(client, window);
314 strcpy(filename_png, client->config.svg_file);
315 strcat(filename_png, ".png");
316 result = stat (filename_png, &st_png);
317 last_update = st_png.st_mtime;
321 sodipodi_thread->start();
322 while (sodipodi_thread->running()) {
323 pausetimer.delay(200); // poll file every 200ms
325 result = stat (filename_png, &st_png);
326 // printf("checking: %s %li\n", filename_png, st_png.st_mtime);
327 // Check if PNG is newer then what we have in memory
328 if (last_update < st_png.st_mtime) {
330 // printf("updated\n");
331 client->send_configure_change();
332 last_update = st_png.st_mtime;
336 sodipodi_thread->join();
339 editing_lock.unlock();
343 SvgSodipodiThread::SvgSodipodiThread(SvgMain *client, SvgWin *window)
346 this->client = client;
347 this->window = window;
350 SvgSodipodiThread::~SvgSodipodiThread()
352 // what do we do? kill sodipodi?
356 void SvgSodipodiThread::run()
360 char filename_png[1024];
361 strcpy(filename_png, client->config.svg_file);
362 strcat(filename_png, ".png");
364 sprintf(command, "sodipodi --cinelerra-export-file=%s --export-width=%i --export-height=%i %s",
365 filename_png, (int)client->config.in_w, (int)client->config.in_h, client->config.svg_file);
366 printf(_("Running external SVG editor: %s\n"), command);
376 NewSvgWindow::NewSvgWindow(SvgMain *client, SvgWin *window, char *init_directory)
378 BC_WindowBase::get_resources()->filebox_h / 2,
380 _("SVG Plugin: Pick SVG file"),
381 _("Open an existing SVG file or create a new one"))
383 this->window = window;
386 NewSvgWindow::~NewSvgWindow() {}