javafx-out.cpp revision 41c1aa8f1639eadc4b1599d72380c061f7f82987
/*
* 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>
*
* Copyright (C) 2008 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#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 "helper/geom-curves.h"
#include <string>
#include <stdio.h>
#include <stdarg.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.
*/
{
double val = 1.0;
{
if (style)
}
return val;
}
//########################################################################
//# OUTPUT FORMATTING
//########################################################################
/**
* We want to control floating output format
*/
{
"%.8f", (gdouble)d);
return s;
}
/**
* Format an rgba() string
*/
{
double r = SP_RGBA32_R_F(rgba);
double g = SP_RGBA32_G_F(rgba);
double b = SP_RGBA32_B_F(rgba);
double a = SP_RGBA32_A_F(rgba);
char buf[128];
return s;
}
/**
* Format an rgba() string for a color and a 0.0-1.0 alpha
*/
{
}
/**
* Output data to the buffer, printf()-style
*/
{
}
/**
* Output header data to the buffer, printf()-style
*/
{
}
/**
* Output the file header
*/
bool JavaFXOutput::doHeader()
{
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("### hhttps://openjfx.dev.java.net\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");
out("import javafx.application.*;\n");
out("import javafx.scene.transform.*;\n");
out("\n");
out("import java.lang.System;\n");
out("\n\n");
out("\n\n");
out("\n\n");
out("public function create() : Node\n");
out("{\n");
out("return Group\n");
out(" {\n");
out(" content:\n");
out(" [\n");
return true;
}
/**
* Output the file footer
*/
bool JavaFXOutput::doTail()
{
int border = 25.0;
out(" ] // content\n");
out(" transform: [ Translate.translate(%s, %s), ]\n",
out(" } // Group\n");
out("} // end function create()\n");
out("\n\n");
out("}\n");
out("/*###################################################################\n");
out("###################################################################*/\n");
out("\n\n\n\n");
out("\n");
out("Frame {\n");
out(" title: \"TestFrame\"\n");
out(" closeAction: function()\n");
out(" {\n");
out(" System.exit( 0 );\n");
out(" }\n");
out(" visible: true\n");
out(" stage: Stage {\n");
out(" }\n");
out("}\n");
out("\n\n");
out("/*###################################################################\n");
out("###################################################################*/\n");
out("\n\n");
return true;
}
/**
* Output gradient information to the buffer
*/
{
if (SP_IS_LINEARGRADIENT(grad))
{
fout("{\n");
fout(" return LinearGradient\n");
fout(" {\n");
{
fout(" stops:\n");
fout(" [\n");
{
fout(" Stop\n");
fout(" {\n");
fout(" },\n");
}
fout(" ]\n");
}
fout(" }\n");
fout("}\n");
fout("\n\n");
}
else if (SP_IS_RADIALGRADIENT(grad))
{
fout("{\n");
fout(" return RadialGradient\n");
fout(" {\n");
{
fout(" stops:\n");
fout(" [\n");
{
fout(" Stop\n");
fout(" {\n");
fout(" },\n");
}
fout(" ]\n");
}
fout(" }\n");
fout("}\n");
fout("\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())
{
{
}
}
/**
* Stroke
*/
/**
*NOTE: Things in style we can use:
* SPIPaint stroke;
* SPILength stroke_width;
* SPIEnum stroke_linecap;
* SPIEnum stroke_linejoin;
* SPIFloat stroke_miterlimit;
* NRVpathDash stroke_dash;
* unsigned stroke_dasharray_set : 1;
* unsigned stroke_dasharray_inherit : 1;
* unsigned stroke_dashoffset_set : 1;
* SPIScale24 stroke_opacity;
*/
{
out(" stroke: %s\n",
}
return true;
}
/**
* 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;
}
/**
* Output the tree data to buffer
*/
{
/**
* Check the type of node and process
*/
{
char buf[16];
}
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
*/
{
double bignum = 1000000.0;
return false;
return true;
}
//########################################################################
//# M A I N O U T P U T
//########################################################################
/**
* Set values back to initial state
*/
void JavaFXOutput::reset()
{
nrNodes = 0;
nrShapes = 0;
idindex = 0;
}
/**
* Saves the <paths> of an Inkscape SVG file as JavaFX spline definitions
*/
{
reset();
if (pos > 0)
//###### SAVE IN POV FORMAT TO BUFFER
//# Lets do the curves first, to get the stats
return false;
if (!doHeader())
return false;
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
{
{
}
}
/**
* 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
JavaFXOutput::init()
{
"<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:encoding=utf-8:textwidth=99 :