summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aa3003a)
raw | patch | inline | side by side (parent: aa3003a)
author | ishmal <ishmal@users.sourceforge.net> | |
Thu, 7 Aug 2008 18:45:31 +0000 (18:45 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Thu, 7 Aug 2008 18:45:31 +0000 (18:45 +0000) |
src/extension/internal/javafx-out.cpp | patch | blob | history | |
src/extension/internal/javafx-out.h | patch | blob | history |
index 29c2bdab0eafdb6da0fd42325a48d9e3386a4793..e31d06b129ad7e5cfec7d5388f439f926b91ca2c 100644 (file)
#include <sp-radial-gradient.h>\r
#include <style.h>\r
#include <display/curve.h>\r
+#include <svg/svg.h>\r
#include <extension/system.h>\r
#include <2geom/pathvector.h>\r
#include <2geom/rect.h>\r
for (SPObject const *obj = style->object; obj ; obj = obj->parent)\r
{\r
style = SP_OBJECT_STYLE(obj);\r
- if (!style)\r
- return val;\r
- val *= SP_SCALE24_TO_FLOAT(style->opacity.value);\r
+ if (style)\r
+ val *= SP_SCALE24_TO_FLOAT(style->opacity.value);\r
}\r
return val;\r
}\r
*/\r
static JavaFXOutput::String rgba(guint32 rgba)\r
{\r
- unsigned int r = SP_RGBA32_R_U(rgba);\r
- unsigned int g = SP_RGBA32_G_U(rgba);\r
- unsigned int b = SP_RGBA32_B_U(rgba);\r
- unsigned int a = SP_RGBA32_A_U(rgba);\r
- char buf[80];\r
- snprintf(buf, 79, "rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x)",\r
- r, g, b, a);\r
+ double r = SP_RGBA32_R_F(rgba);\r
+ double g = SP_RGBA32_G_F(rgba);\r
+ double b = SP_RGBA32_B_F(rgba);\r
+ double a = SP_RGBA32_A_F(rgba);\r
+ char buf[128];\r
+ snprintf(buf, 79, "Color.color(%s, %s, %s, %s)", \r
+ dstr(r).c_str(), dstr(g).c_str(), dstr(b).c_str(), dstr(a).c_str());\r
JavaFXOutput::String s = buf;\r
return s;\r
}\r
out("## Exports in this file\n");\r
out("##==========================\n");\r
out("## Shapes : %d\n", nrShapes);\r
- out("## Segments : %d\n", nrSegments);\r
out("## Nodes : %d\n", nrNodes);\r
out("###################################################################*/\n");\r
out("\n\n");\r
- out("import javafx.ui.UIElement;\n");\r
- out("import javafx.ui.*;\n");\r
- out("import javafx.ui.canvas.*;\n");\r
+ out("import javafx.application.*;\n");\r
+ out("import javafx.scene.*;\n");\r
+ out("import javafx.scene.geometry.*;\n");\r
+ out("import javafx.scene.paint.*;\n");\r
+ out("import javafx.scene.transform.*;\n");\r
out("\n");\r
out("import java.lang.System;\n");\r
out("\n\n");\r
- out("public class %s extends CompositeNode {\n", name.c_str());\r
- for (unsigned int i = 0 ; i < linearGradients.size() ; i++)\r
- {\r
- out(" public function %s(): LinearGradient;\n",\r
- linearGradients[i].c_str());\r
- }\r
- for (unsigned int i = 0 ; i < radialGradients.size() ; i++)\r
- {\r
- out(" public function %s(): RadialGradient;\n",\r
- radialGradients[i].c_str());\r
- }\r
- out("}\n");\r
+ out("public class %s extends CustomNode {\n", name.c_str());\r
out("\n\n");\r
outbuf.append(foutbuf);\r
out("\n\n");\r
- out("function %s.composeNode() =\n", name.c_str());\r
- out("Group\n");\r
+ out("public function create() : Node\n");\r
+ out("{\n");\r
+ out("return Group\n");\r
out(" {\n");\r
out(" content:\n");\r
out(" [\n");\r
{\r
int border = 25.0;\r
out(" ] // content\n");\r
- out(" transform: [ translate(%s, %s), ]\n",\r
+ out(" transform: [ Translate.translate(%s, %s), ]\n",\r
dstr((-minx) + border).c_str(), dstr((-miny) + border).c_str());\r
- out(" }; // Group\n");\r
- out("// end function %s.composeNode()\n", name.c_str());\r
+ out(" } // Group\n");\r
+ out("} // end function create()\n");\r
+ out("\n\n");\r
+ out("}\n");\r
+ out("/*###################################################################\n");\r
+ out("### E N D C L A S S %s\n", name.c_str());\r
+ out("###################################################################*/\n");\r
out("\n\n\n\n");\r
+ out("\n");\r
out("Frame {\n");\r
- out(" title: \"Test\"\n");\r
- out(" width: %s\n", dstr(maxx-minx + border * 2.0).c_str());\r
- out(" height: %s\n", dstr(maxy-miny + border * 2.0).c_str());\r
- out(" onClose: function()\n");\r
+ out(" title: \"TestFrame\"\n");\r
+ out(" width: (%s).intValue()\n", dstr(maxx-minx + border * 2.0).c_str());\r
+ out(" height: (%s).intValue()\n", dstr(maxy-miny + border * 2.0).c_str());\r
+ out(" closeAction: function()\n");\r
out(" {\n");\r
- out(" return System.exit( 0 );\n");\r
+ out(" System.exit( 0 );\n");\r
out(" }\n");\r
out(" visible: true\n");\r
- out(" content: Canvas {\n");\r
+ out(" stage: Stage {\n");\r
out(" content: %s{}\n", name.c_str());\r
out(" }\n");\r
out("}\n");\r
+ out("\n\n");\r
out("/*###################################################################\n");\r
out("### E N D C L A S S %s\n", name.c_str());\r
out("###################################################################*/\n");\r
if (SP_IS_LINEARGRADIENT(grad))\r
{\r
SPLinearGradient *g = SP_LINEARGRADIENT(grad);\r
- linearGradients.push_back(id);\r
- fout("function %s.%s() =\n", name.c_str(), id.c_str());\r
- fout(" [\n");\r
- fout(" LinearGradient\n");\r
+ fout("function %s() : LinearGradient\n", id.c_str());\r
+ fout("{\n");\r
+ fout(" return LinearGradient\n");\r
fout(" {\n");\r
std::vector<SPGradientStop> stops = g->vector.stops;\r
if (stops.size() > 0)\r
}\r
fout(" ]\n");\r
}\r
- fout(" },\n");\r
- fout(" ];\n");\r
+ fout(" }\n");\r
+ fout("}\n");\r
fout("\n\n");\r
}\r
else if (SP_IS_RADIALGRADIENT(grad))\r
{\r
SPRadialGradient *g = SP_RADIALGRADIENT(grad);\r
- radialGradients.push_back(id);\r
- fout("function %s.%s() =\n", name.c_str(), id.c_str());\r
- fout(" [\n");\r
- fout(" RadialGradient\n");\r
+ fout("function %s() : RadialGradient\n", id.c_str());\r
+ fout("{\n");\r
+ fout(" return RadialGradient\n");\r
fout(" {\n");\r
- fout(" cx: %s\n", dstr(g->cx.value).c_str());\r
- fout(" cy: %s\n", dstr(g->cy.value).c_str());\r
+ fout(" centerX: %s\n", dstr(g->cx.value).c_str());\r
+ fout(" centerY: %s\n", dstr(g->cy.value).c_str());\r
fout(" focusX: %s\n", dstr(g->fx.value).c_str());\r
fout(" focusY: %s\n", dstr(g->fy.value).c_str());\r
fout(" radius: %s\n", dstr(g->r.value).c_str());\r
- fout(" gradientUnits: OBJECT_BOUNDING_BOX\n");\r
- fout(" spreadMethod: PAD\n");\r
std::vector<SPGradientStop> stops = g->vector.stops;\r
if (stops.size() > 0)\r
{\r
}\r
fout(" ]\n");\r
}\r
- fout(" },\n");\r
- fout(" ];\n");\r
+ fout(" }\n");\r
+ fout("}\n");\r
fout("\n\n");\r
}\r
else\r
\r
nrShapes++;\r
\r
- out(" /*###################################################\n");\r
- out(" ### PATH: %s\n", id.c_str());\r
- out(" ###################################################*/\n");\r
- out(" Path \n");\r
+ out(" SVGPath \n");\r
out(" {\n");\r
out(" id: \"%s\"\n", id.c_str());\r
\r
Geom::Scale yflip(1.0, -1.0);\r
Geom::Matrix tf = sp_item_i2d_affine(item) * yflip;\r
Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );\r
-\r
+ \r
//Count the NR_CURVETOs/LINETOs (including closing line segment)\r
- guint segmentCount = 0;\r
+ nrNodes = 0;\r
for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) {\r
- segmentCount += (*it).size();\r
+ nrNodes += (*it).size();\r
if (it->closed())\r
- segmentCount += 1;\r
+ nrNodes += 1;\r
}\r
\r
- out(" d:\n");\r
- out(" [\n");\r
-\r
- unsigned int segmentNr = 0;\r
-\r
- nrSegments += segmentCount;\r
+ char *dataStr = sp_svg_write_path(pathv);\r
+ out(" content: \"%s\"\n", dataStr);\r
+ free(dataStr);\r
\r
Geom::Rect cminmax( pathv.front().initialPoint(), pathv.front().initialPoint() ); \r
\r
/**\r
- * For all Subpaths in the <path>\r
+ * Get the Min and Max X and Y extends for the Path. \r
+ * ....For all Subpaths in the <path>\r
*/ \r
for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)\r
{\r
- Geom::Point p = pit->front().initialPoint();\r
- cminmax.expandTo(p);\r
- out(" MoveTo {\n");\r
- out(" x: %s\n", dstr(p[X]).c_str());\r
- out(" y: %s\n", dstr(p[Y]).c_str());\r
- out(" absolute: true\n");\r
- out(" },\n");\r
- \r
+ cminmax.expandTo(pit->front().initialPoint());\r
/**\r
* For all segments in the subpath\r
*/ \r
for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)\r
{\r
- //### LINE\r
- if( is_straight_curve(*cit) )\r
- {\r
- Geom::Point p = cit->finalPoint();\r
- out(" LineTo {\n");\r
- out(" x: %s\n", dstr(p[X]).c_str());\r
- out(" y: %s\n", dstr(p[Y]).c_str());\r
- out(" absolute: true\n");\r
- out(" },\n");\r
- nrNodes++;\r
- }\r
- //### BEZIER\r
- else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit))\r
- {\r
- std::vector<Geom::Point> points = cubic->points();\r
- Geom::Point p1 = points[1];\r
- Geom::Point p2 = points[2];\r
- Geom::Point p3 = points[3];\r
- out(" CurveTo {\n");\r
- out(" x1: %s\n", dstr(p1[X]).c_str());\r
- out(" y1: %s\n", dstr(p1[Y]).c_str());\r
- out(" x2: %s\n", dstr(p2[X]).c_str());\r
- out(" y2: %s\n", dstr(p2[Y]).c_str());\r
- out(" x3: %s\n", dstr(p3[X]).c_str());\r
- out(" y3: %s\n", dstr(p3[Y]).c_str());\r
- out(" absolute: true\n");\r
- out(" },\n");\r
- nrNodes++;\r
- }\r
- else\r
- {\r
- g_error ("logical error, because pathv_to_linear_and_cubic_beziers was used");\r
- }\r
- segmentNr++;\r
cminmax.expandTo(cit->finalPoint());\r
}\r
- if (pit->closed())\r
- {\r
- out(" ClosePath {},\n");\r
- }\r
}\r
\r
- out(" ] // d\n");\r
- out(" }, // Path\n");\r
-\r
- \r
- out(" /*###################################################\n");\r
- out(" ### end path %s\n", id.c_str());\r
- out(" ###################################################*/\n\n\n\n");\r
+ out(" },\n");\r
\r
double cminx = cminmax.min()[X];\r
double cmaxx = cminmax.max()[X];\r
\r
\r
/**\r
- * Output the curve data to buffer\r
+ * Output the tree data to buffer\r
*/\r
-bool JavaFXOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)\r
+bool JavaFXOutput::doTreeRecursive(SPDocument *doc, SPObject *obj)\r
{\r
/**\r
* Check the type of node and process\r
*/\r
String id;\r
- char *idstr = (char *) node->attribute("id");\r
- if (!idstr)\r
+ if (!obj->id)\r
{\r
char buf[16];\r
sprintf(buf, "id%d", idindex++);\r
@@ -559,18 +496,17 @@ bool JavaFXOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)
}\r
else\r
{\r
- id = idstr;\r
+ id = obj->id;\r
}\r
- SPObject *reprobj = doc->getObjectByRepr(node);\r
- if (SP_IS_ITEM(reprobj))\r
+ if (SP_IS_ITEM(obj))\r
{\r
- SPItem *item = SP_ITEM(reprobj);\r
+ SPItem *item = SP_ITEM(obj);\r
if (!doCurve(item, id))\r
return false;\r
}\r
- else if (SP_IS_GRADIENT(reprobj))\r
+ else if (SP_IS_GRADIENT(obj))\r
{\r
- SPGradient *grad = SP_GRADIENT(reprobj);\r
+ SPGradient *grad = SP_GRADIENT(obj);\r
if (!doGradient(grad, id))\r
return false;\r
}\r
@@ -578,10 +514,9 @@ bool JavaFXOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)
/**\r
* Descend into children\r
*/ \r
- for (Inkscape::XML::Node *child = node->firstChild() ; child ;\r
- child = child->next())\r
+ for (SPObject *child = obj->firstChild() ; child ; child = child->next)\r
{\r
- if (!doCurvesRecursive(doc, child))\r
+ if (!doTreeRecursive(doc, child))\r
return false;\r
}\r
\r
@@ -592,7 +527,7 @@ bool JavaFXOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)
/**\r
* Output the curve data to buffer\r
*/\r
-bool JavaFXOutput::doCurves(SPDocument *doc)\r
+bool JavaFXOutput::doTree(SPDocument *doc)\r
{\r
\r
double bignum = 1000000.0;\r
miny = bignum;\r
maxy = -bignum;\r
\r
- if (!doCurvesRecursive(doc, doc->rroot))\r
+ if (!doTreeRecursive(doc, doc->root))\r
return false;\r
\r
return true;\r
void JavaFXOutput::reset()\r
{\r
nrNodes = 0;\r
- nrSegments = 0;\r
nrShapes = 0;\r
idindex = 0;\r
name.clear();\r
outbuf.clear();\r
foutbuf.clear();\r
- linearGradients.clear();\r
- radialGradients.clear();\r
}\r
\r
\r
//###### SAVE IN POV FORMAT TO BUFFER\r
//# Lets do the curves first, to get the stats\r
\r
- if (!doCurves(doc))\r
+ if (!doTree(doc))\r
return false;\r
String curveBuf = outbuf;\r
outbuf.clear();\r
index 917cc529a3ed069343ae70c149bb4b6c0df383dc..c82dfa0df8784d6ec8d7401396dfaabf8aa0b709 100644 (file)
* Output the SVG document's curve data as POV curves\r
*/\r
bool doCurve(SPItem *item, const String &id);\r
- bool doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node);\r
- bool doCurves(SPDocument *doc);\r
+ bool doTreeRecursive(SPDocument *doc, SPObject *obj);\r
+ bool doTree(SPDocument *doc);\r
\r
/**\r
* Output the file footer\r
\r
//For statistics\r
int nrNodes;\r
- int nrSegments;\r
int nrShapes;\r
\r
int idindex;\r
double maxx;\r
double maxy;\r
\r
- std::vector<String> linearGradients;\r
- std::vector<String> radialGradients;\r
\r
};\r
\r