Code

add placeholder for expert contributors
authorishmal <ishmal@users.sourceforge.net>
Wed, 30 Jul 2008 12:01:02 +0000 (12:01 +0000)
committerishmal <ishmal@users.sourceforge.net>
Wed, 30 Jul 2008 12:01:02 +0000 (12:01 +0000)
src/extension/init.cpp
src/extension/internal/CMakeLists.txt
src/extension/internal/Makefile_insert
src/extension/internal/javafx-out.cpp [new file with mode: 0644]
src/extension/internal/javafx-out.h [new file with mode: 0644]

index b46126ef6890243b504eae8bec399589ef54afd8..0ce3dc100abbc96b76bab783ea4077542284a48d 100644 (file)
@@ -47,6 +47,7 @@
 # include "internal/pdf-input-cairo.h"
 #endif
 #include "internal/pov-out.h"
+#include "internal/javafx-out.h"
 #include "internal/odf.h"
 #include "internal/latex-pstricks-out.h"
 #include "internal/latex-pstricks.h"
@@ -182,6 +183,7 @@ init()
     Internal::EmfWin32::init();
 #endif
     Internal::PovOutput::init();
+    Internal::JavaFXOutput::init();
     Internal::OdfOutput::init();
     Internal::PrintLatex::init();
     Internal::LatexOutput::init();
index 4437102fc0b5492b7e1e3052898c965c4af785e9..44fe34abde247264f9a445b3b8512392cec31973 100644 (file)
@@ -25,6 +25,7 @@ pdf-cairo.cpp
 pdfinput
 pdf-input-cairo.cpp
 pov-out.cpp
+javafx-out.cpp
 ps.cpp
 ps-out.cpp
 svg.cpp
index 73303ffca1b1abdd058fa7d5d2ac029b931fb615..0bab68456deca0653bbac7498d30701985f443e6 100644 (file)
@@ -120,6 +120,8 @@ extension_internal_libinternal_a_SOURCES =  \
        extension/internal/cairo-png-out.cpp \
        extension/internal/eps-out.h    \
        extension/internal/eps-out.cpp  \
+       extension/internal/javafx-out.cpp       \
+       extension/internal/javafx-out.h \
        extension/internal/gdkpixbuf-input.h    \
        extension/internal/gdkpixbuf-input.cpp  \
        extension/internal/pdfinput/svg-builder.h \
diff --git a/src/extension/internal/javafx-out.cpp b/src/extension/internal/javafx-out.cpp
new file mode 100644 (file)
index 0000000..8ca1298
--- /dev/null
@@ -0,0 +1,474 @@
+/*\r
+ * A simple utility for exporting Inkscape svg Shapes as JavaFX paths.\r
+ *\r
+ *  For information on the JavaFX file format, see:\r
+ *      https://openjfx.dev.java.net/\r
+ *\r
+ * Authors:\r
+ *   Bob Jamison <ishmal@inkscape.org>\r
+ *\r
+ * Copyright (C) 2008 Authors\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+\r
+#ifdef HAVE_CONFIG_H\r
+# include <config.h>\r
+#endif\r
+#include "javafx-out.h"\r
+#include <inkscape.h>\r
+#include <inkscape_version.h>\r
+#include <sp-path.h>\r
+#include <style.h>\r
+#include <display/curve.h>\r
+#include <libnr/n-art-bpath.h>\r
+#include <extension/system.h>\r
+#include <2geom/pathvector.h>\r
+#include <2geom/rect.h>\r
+#include <2geom/bezier-curve.h>\r
+#include <2geom/hvlinesegment.h>\r
+#include "helper/geom.h"\r
+#include <io/sys.h>\r
+\r
+#include <string>\r
+#include <stdio.h>\r
+#include <stdarg.h>\r
+\r
+\r
+namespace Inkscape\r
+{\r
+namespace Extension\r
+{\r
+namespace Internal\r
+{\r
+\r
+\r
+\r
+\r
+//########################################################################\r
+//# U T I L I T Y\r
+//########################################################################\r
+\r
+\r
+\r
+/**\r
+ * This function searches the Repr tree recursively from the given node,\r
+ * and adds refs to all nodes with the given name, to the result vector\r
+ */\r
+static void\r
+findElementsByTagName(std::vector<Inkscape::XML::Node *> &results,\r
+                      Inkscape::XML::Node *node,\r
+                      char const *name)\r
+{\r
+    if ( !name || strcmp(node->name(), name) == 0 )\r
+        results.push_back(node);\r
+\r
+    for (Inkscape::XML::Node *child = node->firstChild() ; child ;\r
+              child = child->next())\r
+        findElementsByTagName( results, child, name );\r
+\r
+}\r
+\r
+\r
+\r
+//########################################################################\r
+//# OUTPUT FORMATTING\r
+//########################################################################\r
+\r
+\r
+/**\r
+ * We want to control floating output format\r
+ */\r
+static JavaFXOutput::String dstr(double d)\r
+{\r
+    char dbuf[G_ASCII_DTOSTR_BUF_SIZE+1];\r
+    g_ascii_formatd(dbuf, G_ASCII_DTOSTR_BUF_SIZE,\r
+                  "%.8f", (gdouble)d);\r
+    JavaFXOutput::String s = dbuf;\r
+    return s;\r
+}\r
+\r
+\r
+\r
+\r
+/**\r
+ *  Output data to the buffer, printf()-style\r
+ */\r
+void JavaFXOutput::out(const char *fmt, ...)\r
+{\r
+    va_list args;\r
+    va_start(args, fmt);\r
+    gchar *output = g_strdup_vprintf(fmt, args);\r
+    va_end(args);\r
+    outbuf.append(output);\r
+    g_free(output);\r
+}\r
+\r
+\r
+/**\r
+ * Output the file header\r
+ */\r
+bool JavaFXOutput::doHeader(gchar const *uri)\r
+{\r
+    time_t tim = time(NULL);\r
+    out("/*###################################################################\n");\r
+    out("### This JavaFX document was generated by Inkscape\n");\r
+    out("### http://www.inkscape.org\n");\r
+    out("### Created: %s", ctime(&tim));\r
+    out("### Version: %s\n", INKSCAPE_VERSION);\r
+    out("#####################################################################\n");\r
+    out("### NOTES:\n");\r
+    out("### ============\n");\r
+    out("### JavaFX information can be found at\n");\r
+    out("### hhttps://openjfx.dev.java.net\n");\r
+    out("###\n");\r
+    out("### If you have any problems with this output, please see the\n");\r
+    out("### Inkscape project at http://www.inkscape.org, or visit\n");\r
+    out("### the #inkscape channel on irc.freenode.net . \n");\r
+    out("###\n");\r
+    out("###################################################################*/\n");\r
+    out("\n\n");\r
+    out("/*###################################################################\n");\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("\n");\r
+    out("public class %s extends CompositeNode {\n", uri);\r
+    out("\n");\r
+    out("\n\n\n");\r
+    return true;\r
+}\r
+\r
+\r
+\r
+/**\r
+ *  Output the file footer\r
+ */\r
+bool JavaFXOutput::doTail(gchar const *uri)\r
+{\r
+    out("} // end class $s\n", uri);\r
+    out("\n\n");\r
+    out("/*###################################################################\n");\r
+    out("### E N D    F I L E\n");\r
+    out("###################################################################*/\n");\r
+    out("\n\n");\r
+    return true;\r
+}\r
+\r
+\r
+\r
+/**\r
+ *  Output the curve data to buffer\r
+ */\r
+bool JavaFXOutput::doCurves(SPDocument *doc, gchar const *uri)\r
+{\r
+    using Geom::X;\r
+    using Geom::Y;\r
+    \r
+\r
+    std::vector<Inkscape::XML::Node *>results;\r
+    findElementsByTagName(results, doc->rroot, NULL);\r
+    //findElementsByTagName(results, SP_ACTIVE_DOCUMENT->rroot, NULL);\r
+    if (results.size() == 0)\r
+        return true;\r
+\r
+    out("function composeNode()\n");\r
+    out("{\n");\r
+    out("Group\n");\r
+    out("    {\n");\r
+    out("    content:\n");\r
+    out("        [\n");\r
+\r
+    for (unsigned int indx = 0; indx < results.size() ; indx++)\r
+        {\r
+        //### Fetch the object from the repr info\r
+        Inkscape::XML::Node *rpath = results[indx];\r
+        char *str  = (char *) rpath->attribute("id");\r
+        if (!str)\r
+            continue;\r
+\r
+        String id = str;\r
+        SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(rpath);\r
+        if (!reprobj)\r
+            continue;\r
+\r
+        //### Get the transform of the item\r
+        if (!SP_IS_ITEM(reprobj))\r
+            continue;\r
+\r
+        SPItem *item = SP_ITEM(reprobj);\r
+        Geom::Matrix tf = sp_item_i2d_affine(item);\r
+\r
+        //### Get the Shape\r
+        if (!SP_IS_SHAPE(reprobj))//Bulia's suggestion.  Allow all shapes\r
+            continue;\r
+\r
+        SPShape *shape = SP_SHAPE(reprobj);\r
+        SPCurve *curve = shape->curve;\r
+        if (curve->is_empty())\r
+            continue;\r
+            \r
+        nrShapes++;\r
+\r
+        out("        /*###################################################\n");\r
+        out("        ### PATH:  %s\n", id.c_str());\r
+        out("        ###################################################*/\n");\r
+        out("        Path \n");\r
+        out("        {\n");\r
+        out("        name : \"%s\"\n", id.c_str());\r
+\r
+        //Try to get the fill color of the shape\r
+        SPStyle *style = SP_OBJECT_STYLE(shape);\r
+        /* fixme: Handle other fill types, even if this means translating gradients to a single\r
+           flat colour. */\r
+        if (style && (style->fill.isColor()))\r
+            {\r
+            // see color.h for how to parse SPColor\r
+            gint alpha = 0xffffffff;\r
+            guint32 rgba = style->fill.value.color.toRGBA32(alpha);\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
+            out("        fill: rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",\r
+                                   r, g, b, a);\r
+            }\r
+\r
+\r
+        // convert the path to only lineto's and cubic curveto's:\r
+        Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );\r
+\r
+        //Count the NR_CURVETOs/LINETOs (including closing line segment)\r
+        guint segmentCount = 0;\r
+        for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) {\r
+            segmentCount += (*it).size();\r
+            if (it->closed())\r
+                segmentCount += 1;\r
+        }\r
+\r
+        out("        d :\n");\r
+        out("            [\n");\r
+\r
+        int segmentNr = 0;\r
+\r
+        nrSegments += segmentCount;\r
+\r
+        for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) {\r
+\r
+\r
+            for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit) {\r
+\r
+                //### LINE\r
+                if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||\r
+                    dynamic_cast<Geom::HLineSegment const *>(&*cit) ||\r
+                    dynamic_cast<Geom::VLineSegment const *>(&*cit) )\r
+                {\r
+                    out("            LineTo {\n");\r
+                    out("                x: %s\n", dstr(cit->initialPoint()[X]).c_str());\r
+                    out("                y: %s\n", dstr(cit->initialPoint()[Y]).c_str());\r
+                    out("                absolute: true\n");\r
+                    out("                }");\r
+                    nrNodes++;\r
+                }\r
+                //### BEZIER\r
+                else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit)) {\r
+                    std::vector<Geom::Point> points = cubic->points();\r
+                    out("            CurveTo {\n");\r
+                    out("                x1: %s\n", dstr(points[0][X]).c_str());\r
+                    out("                y1: %s\n", dstr(points[0][Y]).c_str());\r
+                    out("                x2: %s\n", dstr(points[1][X]).c_str());\r
+                    out("                y2: %s\n", dstr(points[1][Y]).c_str());\r
+                    out("                x3: %s\n", dstr(points[2][X]).c_str());\r
+                    out("                y3: %s\n", dstr(points[3][Y]).c_str());\r
+                    out("                smooth: false\n");\r
+                    out("                absolute: true\n");\r
+                    out("                }");\r
+                    nrNodes++;\r
+                }\r
+                else {\r
+                    g_error ("logical error, because pathv_to_linear_and_cubic_beziers was used");\r
+                }\r
+\r
+                if (segmentNr <= segmentCount)\r
+                    out(",\n");\r
+                else\r
+                    out("\n");\r
+\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
+\r
+        }//for\r
+\r
+    out("        ] // content\n");\r
+    out("    } // Group\n");\r
+    out("} // function composeNode()\n");\r
+\r
+    return true;\r
+\r
+}\r
+\r
+\r
+\r
+\r
+//########################################################################\r
+//# M A I N    O U T P U T\r
+//########################################################################\r
+\r
+\r
+\r
+/**\r
+ *  Set values back to initial state\r
+ */\r
+void JavaFXOutput::reset()\r
+{\r
+    nrNodes    = 0;\r
+    nrSegments = 0;\r
+    nrShapes   = 0;\r
+    outbuf.clear();\r
+}\r
+\r
+\r
+\r
+/**\r
+ * Saves the <paths> of an Inkscape SVG file as JavaFX spline definitions\r
+ */\r
+bool JavaFXOutput::saveDocument(SPDocument *doc, gchar const *uri)\r
+{\r
+    reset();\r
+\r
+    //###### SAVE IN POV FORMAT TO BUFFER\r
+    //# Lets do the curves first, to get the stats\r
+    if (!doCurves(doc, uri))\r
+        return false;\r
+    String curveBuf = outbuf;\r
+    outbuf.clear();\r
+\r
+    if (!doHeader(uri))\r
+        return false;\r
+    \r
+    outbuf.append(curveBuf);\r
+    \r
+    if (!doTail(uri))\r
+        return false;\r
+\r
+\r
+\r
+\r
+    //###### WRITE TO FILE\r
+    FILE *f = Inkscape::IO::fopen_utf8name(uri, "w");\r
+    if (!f)\r
+        {\r
+        g_warning("Could open JavaFX file '%s' for writing", uri);\r
+        return false;\r
+        }\r
+\r
+    for (String::iterator iter = outbuf.begin() ; iter!=outbuf.end(); iter++)\r
+        {\r
+        fputc(*iter, f);\r
+        }\r
+        \r
+    fclose(f);\r
+    \r
+    return true;\r
+}\r
+\r
+\r
+\r
+\r
+//########################################################################\r
+//# EXTENSION API\r
+//########################################################################\r
+\r
+\r
+\r
+#include "clear-n_.h"\r
+\r
+\r
+\r
+/**\r
+ * API call to save document\r
+*/\r
+void\r
+JavaFXOutput::save(Inkscape::Extension::Output */*mod*/,\r
+                        SPDocument *doc, gchar const *uri)\r
+{\r
+    if (!saveDocument(doc, uri))\r
+        {\r
+        g_warning("Could not save JavaFX file '%s'", uri);\r
+        }\r
+}\r
+\r
+\r
+\r
+/**\r
+ * Make sure that we are in the database\r
+ */\r
+bool JavaFXOutput::check (Inkscape::Extension::Extension */*module*/)\r
+{\r
+    /* We don't need a Key\r
+    if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_JFX))\r
+        return FALSE;\r
+    */\r
+\r
+    return true;\r
+}\r
+\r
+\r
+\r
+/**\r
+ * This is the definition of JavaFX output.  This function just\r
+ * calls the extension system with the memory allocated XML that\r
+ * describes the data.\r
+*/\r
+void\r
+JavaFXOutput::init()\r
+{\r
+    Inkscape::Extension::build_from_mem(\r
+        "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"\r
+            "<name>" N_("JavaFX Output") "</name>\n"\r
+            "<id>org.inkscape.output.jfx</id>\n"\r
+            "<output>\n"\r
+                "<extension>.fx</extension>\n"\r
+                "<mimetype>text/x-javafx-script</mimetype>\n"\r
+                "<filetypename>" N_("JavaFX (*.fx)") "</filetypename>\n"\r
+                "<filetypetooltip>" N_("JavaFX Raytracer File") "</filetypetooltip>\n"\r
+            "</output>\n"\r
+        "</inkscape-extension>",\r
+        new JavaFXOutput());\r
+}\r
+\r
+\r
+\r
+\r
+\r
+}  // namespace Internal\r
+}  // namespace Extension\r
+}  // namespace Inkscape\r
+\r
+\r
+/*\r
+  Local Variables:\r
+  mode:c++\r
+  c-file-style:"stroustrup"\r
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+  indent-tabs-mode:nil\r
+  fill-column:99\r
+  End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
diff --git a/src/extension/internal/javafx-out.h b/src/extension/internal/javafx-out.h
new file mode 100644 (file)
index 0000000..6f2dbd4
--- /dev/null
@@ -0,0 +1,123 @@
+/*\r
+ * A simple utility for exporting Inkscape svg Shapes as PovRay bezier\r
+ * prisms.  Note that this is output-only, and would thus seem to be\r
+ * better placed as an 'export' rather than 'output'.  However, Export\r
+ * handles all or partial documents, while this outputs ALL shapes in\r
+ * the current SVG document.\r
+ *\r
+ * Authors:\r
+ *   Bob Jamison <ishmal@inkscape.org>\r
+ *\r
+ * Copyright (C) 2008 Authors\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#ifndef EXTENSION_INTERNAL_JAVAFX_OUT_H\r
+#define EXTENSION_INTERNAL_JAVAFX_OUT_H\r
+\r
+#include <glib.h>\r
+#include "extension/implementation/implementation.h"\r
+\r
+namespace Inkscape\r
+{\r
+namespace Extension\r
+{\r
+namespace Internal\r
+{\r
+\r
+\r
+\r
+/**\r
+ * Output the current svg document in JavaFX format.\r
+ * \r
+ * For information, @see:  \r
+ * https://openjfx.dev.java.net/\r
+ */ \r
+class JavaFXOutput : public Inkscape::Extension::Implementation::Implementation\r
+{\r
+\r
+\r
+public:\r
+\r
+    /**\r
+     * Our internal String definition\r
+     */\r
+    typedef Glib::ustring String;\r
+\r
+\r
+    /**\r
+     * Check whether we can actually output using this module\r
+     */\r
+       virtual bool check (Inkscape::Extension::Extension * module);\r
+\r
+    /**\r
+     * API call to perform the output to a file\r
+     */\r
+       virtual void save (Inkscape::Extension::Output *mod,\r
+                  SPDocument *doc, const gchar *uri);\r
+\r
+    /**\r
+     * Inkscape runtime startup call.\r
+     */\r
+       static void init(void);\r
+       \r
+    /**\r
+     * Reset variables to initial state\r
+     */\r
+       void reset();\r
+       \r
+private:\r
+\r
+    \r
+    //For formatted output\r
+       String outbuf;\r
+       \r
+\r
+       /**\r
+        * Format text to our output buffer\r
+        */\r
+       void out(const char *fmt, ...) G_GNUC_PRINTF(2,3);\r
+\r
+       //Output the parts of the file\r
+\r
+    /**\r
+     * Output the file header\r
+     */\r
+       bool doHeader(gchar const *uri);\r
+\r
+    /**\r
+     * Output the SVG document's curve data as POV curves\r
+     */\r
+       bool doCurves(SPDocument *doc, gchar const *uri);\r
+\r
+    /**\r
+     * Output the file footer\r
+     */\r
+       bool doTail(gchar const *uri);\r
+\r
+\r
+\r
+    /**\r
+     * Actual method to save document\r
+     */\r
+       bool saveDocument(SPDocument *doc, const gchar *uri);\r
+\r
+    //For statistics\r
+    int nrNodes;\r
+    int nrSegments;\r
+    int nrShapes;\r
+\r
+};\r
+\r
+\r
+\r
+\r
+}  // namespace Internal\r
+}  // namespace Extension\r
+}  // namespace Inkscape\r
+\r
+\r
+\r
+#endif /* EXTENSION_INTERNAL_POV_OUT_H */\r
+\r