コード例 #1
0
ファイル: system.cpp プロジェクト: Grandrogue/inkscape_metal
/**
 * \return   The module created
 * \brief    This function creates a module from a filename of an
 *           XML description.
 * \param    filename  The file holding the XML description of the module.
 *
 * This function calls build_from_reprdoc with using sp_repr_read_file to create the reprdoc.
 */
Extension *
build_from_file(gchar const *filename)
{
    Inkscape::XML::Document *doc = sp_repr_read_file(filename, INKSCAPE_EXTENSION_URI);
    Extension *ext = build_from_reprdoc(doc, NULL);
    if (ext != NULL)
        Inkscape::GC::release(doc);
    else
        g_warning("Unable to create extension from definition file %s.\n", filename);
    return ext;
}
コード例 #2
0
/**
 * Fetches document from URI, or creates new, if NULL; public document
 * appears in document list.
 */
SPDocument *
sp_document_new(gchar const *uri, unsigned int keepalive, bool make_new)
{
    SPDocument *doc;
    Inkscape::XML::Document *rdoc;
    gchar *base = NULL;
    gchar *name = NULL;

    if (uri) {
        Inkscape::XML::Node *rroot;
        gchar *s, *p;
        /* Try to fetch repr from file */
        rdoc = sp_repr_read_file(uri, SP_SVG_NS_URI);
        /* If file cannot be loaded, return NULL without warning */
        if (rdoc == NULL) return NULL;
        rroot = rdoc->root();
        /* If xml file is not svg, return NULL without warning */
        /* fixme: destroy document */
        if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;
        s = g_strdup(uri);
        p = strrchr(s, '/');
        if (p) {
            name = g_strdup(p + 1);
            p[1] = '\0';
            base = g_strdup(s);
        } else {
            base = NULL;
            name = g_strdup(uri);
        }
        g_free(s);
    } else {
        rdoc = sp_repr_document_new("svg:svg");
    }

    if (make_new) {
        base = NULL;
        uri = NULL;
        name = g_strdup_printf(_("New document %d"), ++doc_count);
    }

    //# These should be set by now
    g_assert(name);

    doc = sp_document_create(rdoc, uri, base, name, keepalive);

    g_free(base);
    g_free(name);

    return doc;
}