index 0a1108b1ebbafb5eeaa70067ac7cee061fbe49ab..7098027c7847dd4dfc3316c1cff9b1ba0b50902d 100644 (file)
* 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 Authors
+ * Copyright (C) 2008,2009 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
for (SPObject const *obj = style->object; obj ; obj = obj->parent)
{
style = SP_OBJECT_STYLE(obj);
- if (style)
+ if (style) {
val *= SP_SCALE24_TO_FLOAT(style->opacity.value);
}
+ }
return val;
}
unsigned int a = SP_RGBA32_A_U(rgba);
char buf[80];
snprintf(buf, 79, "Color.rgb(0x%02x, 0x%02x, 0x%02x, %s)",
- r, g, b, DSTR((double)a/256.0));
+ r, g, b, DSTR((double)a/255.0));
JavaFXOutput::String s = buf;
return s;
}
*/
static JavaFXOutput::String sanatize(const JavaFXOutput::String &badstr){
JavaFXOutput::String good(badstr);
- for (int pos = 0; pos < badstr.length(); ++pos )
- if((badstr.at(pos)=='-')||(badstr.at(pos)==' '))
+ for (int pos = 0; pos < static_cast<int>(badstr.length()); ++pos )
+ if ((badstr.at(pos)=='-')||(badstr.at(pos)==' ')) {
good.replace(pos, 1, "_");
+ }
return good;
}
out("### NOTES:\n");
out("### ============\n");
out("### JavaFX information can be found at\n");
- out("### hhttps://openjfx.dev.java.net\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("\n\n");
// import javafx libraries we can need
- out("import javafx.application.*;\n");
out("import javafx.scene.*;\n");
- out("import javafx.scene.geometry.*;\n");
+ out("import javafx.scene.shape.*;\n");
out("import javafx.scene.transform.*;\n");
out("import javafx.scene.paint.*;\n");
out("\n");
// Write the tail of CustomNode
out(" ] // content\n");
- out(" transform: Translate { x : %s, y : %s }\n",
- DSTR((-minx) + border), DSTR((-miny) + border) );
+ out(" transforms: Translate { x : %s, y : %s }\n",
+ DSTR((-minx) + border), DSTR((-miny) + border) );
out(" } // Group\n");
out(" } // function create()\n");
out("} // class %s\n", name.c_str());
out("\n");
- // Frame
- out("Frame {\n");
- out(" title: \"%s\"\n", name.c_str());
- out(" width: %s\n", ISTR(maxx-minx + border * 2.0));
- out(" height: %s\n", ISTR(maxy-miny + border * 2.0));
- out(" visible: true\n");
-
// Stage
- out(" stage: Stage {\n");
- out(" content: %s{}\n", name.c_str());
- out(" } // Stage\n");
+// out(" stage: Stage {\n");
+// out(" content: %s{}\n", name.c_str());
+// out(" } // Stage\n");
- out("} // Frame\n");
out("\n");
{
SPLinearGradient *g = SP_LINEARGRADIENT(grad);
out(" /* create LinearGradient for %s */\n", jfxid.c_str());
- out(" private function %s(): LinearGradient {\n", jfxid.c_str());
+ out(" function %s(): LinearGradient {\n", jfxid.c_str());
out(" LinearGradient {\n");
std::vector<SPGradientStop> stops = g->vector.stops;
if (stops.size() > 0)
{
SPRadialGradient *g = SP_RADIALGRADIENT(grad);
out(" /* create RadialGradient for %s */\n", jfxid.c_str());
- out(" private function %s() {\n", jfxid.c_str());
+ out(" function %s() {\n", jfxid.c_str());
out(" RadialGradient {\n");
out(" centerX: %s\n", DSTR(g->cx.value));
out(" centerY: %s\n", DSTR(g->cy.value));
*/
bool JavaFXOutput::doStyle(SPStyle *style)
{
- if (!style)
+ if (!style) {
return true;
+ }
out(" opacity: %s\n", DSTR(effective_opacity(style)));
/**
* Fill
*/
- SPIPaint fill = style->fill;
+ SPIPaint const &fill = style->fill;
if (fill.isColor())
{
// see color.h for how to parse SPColor
if (fill.value.href && fill.value.href->getURI() ){
String uri = fill.value.href->getURI()->toString();
/* trim the anchor '#' from the front */
- if (uri.size() > 0 && uri[0]=='#')
+ if (uri.size() > 0 && uri[0]=='#') {
uri = uri.substr(1);
+ }
out(" fill: %s()\n", sanatize(uri).c_str());
}
}
*/
if (style->stroke_opacity.value > 0)
{
- SPIPaint stroke = style->stroke;
+ SPIPaint const &stroke = style->stroke;
out(" stroke: %s\n",
rgba(stroke.value.color, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)).c_str());
double strokewidth = style->stroke_width.value;
out(" strokeLineCap: %s\n", getStrokeLineCap(linecap).c_str());
out(" strokeLineJoin: %s\n", getStrokeLineJoin(linejoin).c_str());
out(" strokeMiterLimit: %s\n", DSTR(style->stroke_miterlimit.value));
- if(style->stroke_dasharray_set) {
- if(style->stroke_dashoffset_set) {
+ if (style->stroke_dasharray_set) {
+ if (style->stroke_dashoffset_set) {
out(" strokeDashOffset: %s\n", DSTR(style->stroke_dash.offset));
}
out(" strokeDashArray: [ ");
for(int i = 0; i < style->stroke_dash.n_dash; i++ ) {
- if(i > 0) {
+ if (i > 0) {
out(", %.2lf", style->stroke_dash.dash[i]);
}else {
out(" %.2lf", style->stroke_dash.dash[i]);
String jfxid = sanatize(id);
//### Get the Shape
- if (!SP_IS_SHAPE(item))//Bulia's suggestion. Allow all shapes
+ if (!SP_IS_SHAPE(item)) { //Bulia's suggestion. Allow all shapes
return true;
+ }
SPShape *shape = SP_SHAPE(item);
SPCurve *curve = shape->curve;
- if (curve->is_empty())
+ if (curve->is_empty()) {
return true;
+ }
nrShapes++;
out(" /** path %s */\n", jfxid.c_str());
- out(" private function %s() : Path {\n",jfxid.c_str());
+ out(" function %s() : Path {\n",jfxid.c_str());
out(" Path {\n");
out(" id: \"%s\"\n", jfxid.c_str());
/**
* Output the style information
*/
- if (!doStyle(SP_OBJECT_STYLE(shape)))
+ if (!doStyle(SP_OBJECT_STYLE(shape))) {
return false;
+ }
// convert the path to only lineto's and cubic curveto's:
Geom::Scale yflip(1.0, -1.0);
- Geom::Matrix tf = sp_item_i2d_affine(item) * yflip;
+ Geom::Matrix tf = item->i2d_affine() * yflip;
Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );
//Count the NR_CURVETOs/LINETOs (including closing line segment)
guint segmentCount = 0;
for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) {
segmentCount += (*it).size();
- if (it->closed())
+ if (it->closed()) {
segmentCount += 1;
+ }
}
out(" elements: [\n");
for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
{
//### LINE
- if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
+ if ( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
dynamic_cast<Geom::HLineSegment const *> (&*cit) ||
dynamic_cast<Geom::VLineSegment const *> (&*cit) )
{
nrNodes++;
}
//### BEZIER
- else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit))
+ else if (Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit))
{
std::vector<Geom::Point> points = cubic->points();
Geom::Point p1 = points[1];
Geom::Point p2 = points[2];
Geom::Point p3 = points[3];
- out(" CurveTo {\n");
+ out(" CubicCurveTo {\n");
out(" controlX1: %s\n", DSTR(p1[X]));
out(" controlY1: %s\n", DSTR(p1[Y]));
out(" controlX2: %s\n", DSTR(p2[X]));
double cminy = cminmax.min()[Y];
double cmaxy = cminmax.max()[Y];
- if (cminx < minx)
+ if (cminx < minx) {
minx = cminx;
- if (cmaxx > maxx)
+ }
+ if (cmaxx > maxx) {
maxx = cmaxx;
- if (cminy < miny)
+ }
+ if (cminy < miny) {
miny = cminy;
- if (cmaxy > maxy)
+ }
+ if (cmaxy > maxy) {
maxy = cmaxy;
+ }
return true;
}
using Geom::Y;
//### Get the Shape
- if (!SP_IS_SHAPE(item))//Bulia's suggestion. Allow all shapes
+ if (!SP_IS_SHAPE(item)) { //Bulia's suggestion. Allow all shapes
return true;
+ }
SPShape *shape = SP_SHAPE(item);
SPCurve *curve = shape->curve;
- if (curve->is_empty())
+ if (curve->is_empty()) {
return true;
+ }
nrShapes++;
/**
* Output the style information
*/
- if (!doStyle(SP_OBJECT_STYLE(shape)))
+ if (!doStyle(SP_OBJECT_STYLE(shape))) {
return false;
+ }
// convert the path to only lineto's and cubic curveto's:
Geom::Scale yflip(1.0, -1.0);
- Geom::Matrix tf = sp_item_i2d_affine(item) * yflip;
+ Geom::Matrix tf = item->i2d_affine() * yflip;
Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );
-
+
//Count the NR_CURVETOs/LINETOs (including closing line segment)
nrNodes = 0;
for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) {
nrNodes += (*it).size();
- if (it->closed())
+ if (it->closed()) {
nrNodes += 1;
+ }
}
char *dataStr = sp_svg_write_path(pathv);
out(" content: \"%s\"\n", dataStr);
free(dataStr);
- Geom::Rect cminmax( pathv.front().initialPoint(), pathv.front().initialPoint() );
+ Geom::Rect cminmax( pathv.front().initialPoint(), pathv.front().initialPoint() );
/**
- * Get the Min and Max X and Y extends for the Path.
+ * Get the Min and Max X and Y extends for the Path.
* ....For all Subpaths in the <path>
- */
+ */
for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)
{
cminmax.expandTo(pit->front().initialPoint());
/**
* For all segments in the subpath
- */
+ */
for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
{
cminmax.expandTo(cit->finalPoint());
double cminy = cminmax.min()[Y];
double cmaxy = cminmax.max()[Y];
- if (cminx < minx)
+ if (cminx < minx) {
minx = cminx;
- if (cmaxx > maxx)
+ }
+ if (cmaxx > maxx) {
maxx = cmaxx;
- if (cminy < miny)
+ }
+ if (cminy < miny) {
miny = cminy;
- if (cmaxy > maxy)
+ }
+ if (cmaxy > maxy) {
maxy = cmaxy;
+ }
return true;
}
* Check the type of node and process
*/
String id;
- if (!obj->id)
+ if (!obj->getId())
{
char buf[16];
sprintf(buf, "id%d", idindex++);
}
else
{
- id = obj->id;
+ id = obj->getId();
}
if (SP_IS_ITEM(obj))
{
SPItem *item = SP_ITEM(obj);
- if (!doCurve(item, id))
+ if (!doCurve(item, id)) {
return false;
}
+ }
else if (SP_IS_GRADIENT(obj))
{
SPGradient *grad = SP_GRADIENT(obj);
- if (!doGradient(grad, id))
+ if (!doGradient(grad, id)) {
return false;
}
+ }
/**
* Descend into children
- */
+ */
for (SPObject *child = obj->firstChild() ; child ; child = child->next)
{
- if (!doTreeRecursive(doc, child))
- return false;
- }
+ if (!doTreeRecursive(doc, child)) {
+ return false;
+ }
+ }
return true;
}
miny = bignum;
maxy = -bignum;
- if (!doTreeRecursive(doc, doc->root))
+ if (!doTreeRecursive(doc, doc->root)) {
return false;
+ }
return true;
* Check the type of node and process
*/
String id;
- if (!obj->id)
+ if (!obj->getId())
{
char buf[16];
sprintf(buf, "id%d", idindex++);
}
else
{
- id = obj->id;
+ id = obj->getId();
}
if (SP_IS_ITEM(obj)) {
if (SP_IS_SHAPE(item)) {//Bulia's suggestion. Allow all shapes
SPShape *shape = SP_SHAPE(item);
SPCurve *curve = shape->curve;
- if (!curve->is_empty())
- out(" %s(),\n", id.c_str());
+ if (!curve->is_empty()) {
+ String jfxid = sanatize(id);
+ out(" %s(),\n", jfxid.c_str());
+ }
}
}
else if (SP_IS_GRADIENT(obj)) {
//TODO: what to do with Gradient within body?????
//SPGradient *grad = SP_GRADIENT(reprobj);
- //if (!doGradient(grad, id))
+ //if (!doGradient(grad, id)) {
// return false;
+ //}
}
/**
*/
for (SPObject *child = obj->firstChild() ; child ; child = child->next)
{
- if (!doBody(doc, child))
- return false;
- }
+ if (!doBody(doc, child)) {
+ return false;
+ }
+ }
return true;
}
name = Glib::path_get_basename(filename_utf8);
int pos = name.find('.');
- if (pos > 0)
+ if (pos > 0) {
name = name.substr(0, pos);
+ }
//###### SAVE IN JAVAFX FORMAT TO BUFFER
//# Lets do the curves first, to get the stats
- if (!doTree(doc))
+ if (!doTree(doc)) {
return false;
+ }
String curveBuf = outbuf;
outbuf.clear();
- if (!doHeader())
+ if (!doHeader()) {
return false;
+ }
outbuf.append(curveBuf);
-#ifdef JAVAFX_SDK_1_0
out(" override function create(): Node {\n");
-#else
- out(" public function create(): Node {\n");
-#endif
out(" Group {\n");
out(" content: [\n");
idindex = 0;
doBody(doc, doc->root);
- if (!doTail())
+ if (!doTail()) {
return false;
+ }
{
fputc(*iter, f);
}
-
+
fclose(f);
-
+
return true;
}
bool JavaFXOutput::check (Inkscape::Extension::Extension */*module*/)
{
/* We don't need a Key
- if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_JFX))
+ if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_JFX)) {
return FALSE;
+ }
*/
return true;
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :