/*
* A simple utility for exporting Inkscape svg Shapes as JavaFX paths.
*
* For information on the JavaFX file format, see:
*
* Authors:
* Bob Jamison <ishmal@inkscape.org>
* Silveira Neto <silveiraneto@gmail.com>
* Jim Clarke <Jim.Clarke@sun.com>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2008,2009 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <glibmm/miscutils.h>
#include "javafx-out.h"
#include <inkscape.h>
#include <inkscape-version.h>
#include <sp-path.h>
#include <sp-linear-gradient.h>
#include <sp-radial-gradient.h>
#include <style.h>
#include <display/canvas-bpath.h>
#include "helper/geom-curves.h"
#include "sp-root.h"
#include <string>
#include <stdio.h>
#include <stdarg.h>
#include "extension/extension.h"
namespace Inkscape
{
namespace Extension
{
namespace Internal
{
//########################################################################
//# M E S S A G E S
//########################################################################
{
}
//########################################################################
//# U T I L I T Y
//########################################################################
/**
* Got this method from Bulia, and modified it a bit. It basically
* starts with this style, gets its SPObject parent, walks up the object
* tree and finds all of the opacities and multiplies them.
*
* We use this for our "flat" object output. If the code is modified
* to reflect a tree of <groups>, then this will be unneccessary.
*/
{
{
}
}
return val;
}
//########################################################################
//# OUTPUT FORMATTING
//########################################################################
name(),
outbuf(),
foutbuf(),
nrNodes(0),
nrShapes(0),
idindex(0),
minx(0),
miny(0),
maxx(0),
maxy(0)
{
}
/**
* We want to control floating output format.
* Especially to avoid localization. (decimal ',' for example)
*/
{
"%.8f", (gdouble)d);
return s;
}
/**
* Format an rgba() string
*/
{
unsigned int r = SP_RGBA32_R_U(rgba);
unsigned int g = SP_RGBA32_G_U(rgba);
unsigned int b = SP_RGBA32_B_U(rgba);
unsigned int a = SP_RGBA32_A_U(rgba);
r, g, b, DSTR((double)a/255.0));
return s;
}
/**
* Format an rgba() string for a color and a 0.0-1.0 alpha
*/
{
}
/**
* Map Inkscape linecap styles to JavaFX
*/
switch(value) {
case SP_STROKE_LINECAP_BUTT:
return "StrokeLineCap.BUTT";
case SP_STROKE_LINECAP_ROUND:
return "StrokeLineCap.ROUND";
case SP_STROKE_LINECAP_SQUARE:
return "StrokeLineCap.SQUARE";
default:
return "INVALID LINE CAP";
}
}
/**
* Map Inkscape linejoin styles to JavaFX
*/
switch(value) {
case SP_STROKE_LINEJOIN_MITER:
return "StrokeLineJoin.MITER";
case SP_STROKE_LINEJOIN_ROUND:
return "StrokeLineJoin.ROUND";
case SP_STROKE_LINEJOIN_BEVEL:
return "StrokeLineJoin.BEVEL";
default:
return "INVALID LINE JOIN";
}
}
/**
* Replace illegal characters for JavaFX for a underscore.
*/
}
return good;
}
/**
* Output data to the buffer, printf()-style
*/
{
}
/**
* Output the file header
*/
{
out("/*###################################################################\n");
out("### This JavaFX document was generated by Inkscape\n");
out("### http://www.inkscape.org\n");
out("#####################################################################\n");
out("### NOTES:\n");
out("### ============\n");
out("### JavaFX information can be found at\n");
out("### http://www.javafx.com/\n");
out("###\n");
out("### If you have any problems with this output, please see the\n");
out("### Inkscape project at http://www.inkscape.org, or visit\n");
out("### the #inkscape channel on irc.freenode.net . \n");
out("###\n");
out("###################################################################*/\n");
out("\n\n");
out("/*###################################################################\n");
out("## Exports in this file\n");
out("##==========================\n");
out("###################################################################*/\n");
out("\n\n");
// import javafx libraries we can need
out("import javafx.scene.shape.*;\n");
out("import javafx.scene.transform.*;\n");
out("\n");
out("\n\n");
// Creates a class extended from CustomNode
return true;
}
/**
* Output the file footer
*/
{
// Write the tail of CustomNode
out(" ] // content\n");
out(" transforms: Translate { x : %s, y : %s }\n",
out(" } // Group\n");
out(" } // function create()\n");
out("\n");
// Stage
// out(" stage: Stage {\n");
// out(" content: %s{}\n", name.c_str());
// out(" } // Stage\n");
out("\n");
out("/*###################################################################\n");
out("###################################################################*/\n");
out("\n\n");
return true;
}
/**
* Output gradient information to the buffer
*/
{
if (SP_IS_LINEARGRADIENT(grad))
{
out(" LinearGradient {\n");
{
out(" stops:\n");
out(" [\n");
{
out(" Stop {\n");
out(" },\n");
}
out(" ]\n");
}
out(" };\n");
out("\n\n");
}
else if (SP_IS_RADIALGRADIENT(grad))
{
out(" RadialGradient {\n");
{
out(" stops:\n");
out(" [\n");
{
out(" Stop {\n");
out(" },\n");
}
out(" ]\n");
}
out(" };\n");
out("\n\n");
}
else
{
return false;
}
return true;
}
/**
* Output an element's style attribute
*/
{
if (!style) {
return true;
}
/**
* Fill
*/
{
// see color.h for how to parse SPColor
out(" fill: %s\n",
}
else if (fill.isPaintserver()){
/* trim the anchor '#' from the front */
}
}
}
/**
* Stroke
*/
/**
*NOTE: Things in style we can use:
* SPIPaint stroke;
* SPILength stroke_width;
* SPIEnum stroke_linecap;
* SPIEnum stroke_linejoin;
* SPIFloat stroke_miterlimit;
* SPIDashArray stroke_dasharray;
* SPILength stroke_dashoffset;
* SPIScale24 stroke_opacity;
*/
{
out(" stroke: %s\n",
}
out(" strokeDashArray: [ ");
if (i > 0) {
}else {
}
}
out(" ]\n");
}
}
return true;
}
#if 1
/**
* Output the curve data to buffer
*/
{
using Geom::X;
using Geom::Y;
//### Get the Shape
return true;
}
return true;
}
nrShapes++;
out(" Path {\n");
/**
* Output the style information
*/
return false;
}
// convert the path to only lineto's and cubic curveto's:
//Count the NR_CURVETOs/LINETOs (including closing line segment)
segmentCount += 1;
}
}
out(" elements: [\n");
unsigned int segmentNr = 0;
nrNodes += segmentCount;
/**
* For all Subpaths in the <path>
*/
{
out(" MoveTo {\n");
out(" },\n");
/**
* For all segments in the subpath
*/
{
//### LINE
{
out(" LineTo {\n");
out(" },\n");
nrNodes++;
}
//### BEZIER
{
out(" CubicCurveTo {\n");
out(" },\n");
nrNodes++;
}
else
{
g_error ("logical error, because pathv_to_linear_and_cubic_beziers was used");
}
segmentNr++;
}
{
out(" ClosePath {},\n");
}
}
out(" ] // elements\n");
out(" }; // Path\n");
}
}
}
}
return true;
}
#else
/**
* Output the curve data to buffer
*/
{
using Geom::X;
using Geom::Y;
//### Get the Shape
return true;
}
return true;
}
nrShapes++;
out(" SVGPath \n");
out(" {\n");
/**
* Output the style information
*/
return false;
}
// convert the path to only lineto's and cubic curveto's:
//Count the NR_CURVETOs/LINETOs (including closing line segment)
nrNodes = 0;
nrNodes += 1;
}
}
/**
* Get the Min and Max X and Y extends for the Path.
* ....For all Subpaths in the <path>
*/
{
/**
* For all segments in the subpath
*/
{
}
}
out(" },\n");
}
}
}
}
return true;
}
#endif /* #if o */
/**
* Output the tree data to buffer
*/
{
/**
* Check the type of node and process
*/
{
}
else
{
}
if (SP_IS_ITEM(obj))
{
return false;
}
}
else if (SP_IS_GRADIENT(obj))
{
return false;
}
}
/**
* Descend into children
*/
{
return false;
}
}
return true;
}
/**
* Output the curve data to buffer
*/
{
return false;
}
return true;
}
{
/**
* Check the type of node and process
*/
{
}
else
{
}
if (SP_IS_ITEM(obj)) {
//### Get the Shape
}
}
}
else if (SP_IS_GRADIENT(obj)) {
//TODO: what to do with Gradient within body?????
//SPGradient *grad = SP_GRADIENT(reprobj);
//if (!doGradient(grad, id)) {
// return false;
//}
}
/**
* Descend into children
*/
{
return false;
}
}
return true;
}
//########################################################################
//# M A I N O U T P U T
//########################################################################
/**
* Set values back to initial state
*/
{
nrNodes = 0;
nrShapes = 0;
idindex = 0;
}
/**
* Saves the <paths> of an Inkscape SVG file as JavaFX spline definitions
*/
{
reset();
if (pos > 0) {
}
//###### SAVE IN JAVAFX FORMAT TO BUFFER
//# Lets do the curves first, to get the stats
return false;
}
if (!doHeader()) {
return false;
}
out(" override function create(): Node {\n");
out(" Group {\n");
out(" content: [\n");
idindex = 0;
if (!doTail()) {
return false;
}
//###### WRITE TO FILE
if (!f)
{
return false;
}
{
}
fclose(f);
return true;
}
//########################################################################
//# EXTENSION API
//########################################################################
#include "clear-n_.h"
/**
* API call to save document
*/
void
{
/* N.B. The name `filename_utf8' represents the fact that we want it to be in utf8; whereas in
* fact we know that some callers of Extension::save pass something in the filesystem's
* encoding, while others do g_filename_to_utf8 before calling.
*
* In terms of safety, it's best to make all callers pass actual filenames, since in general
* one can't round-trip from filename to utf8 back to the same filename. Whereas the argument
* for passing utf8 filenames is one of convenience: we often want to pass to g_warning or
* store as a string (rather than a byte stream) in XML, or the like. */
{
}
}
/**
* Make sure that we are in the database
*/
{
/* We don't need a Key
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_JFX)) {
return FALSE;
}
*/
return true;
}
/**
* This is the definition of JavaFX output. This function just
* calls the extension system with the memory allocated XML that
* describes the data.
*/
void
{
"<id>org.inkscape.output.jfx</id>\n"
"<output>\n"
"<extension>.fx</extension>\n"
"<mimetype>text/x-javafx-script</mimetype>\n"
"</output>\n"
"</inkscape-extension>",
new JavaFXOutput());
}
} // namespace Internal
} // namespace Extension
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :