Logo Search packages:      
Sourcecode: inkscape version File versions

Inkscape::XML::Document* sp_repr_read_file ( const gchar *  filename,
const gchar *  default_ns 
)

Reads XML from a file, including WMF files, and returns the Document. The default namespace can also be specified, if desired.

Definition at line 255 of file repr-io.cpp.

{
    xmlDocPtr doc = 0;
    Document * rdoc = 0;

    xmlSubstituteEntitiesDefault(1);

    g_return_val_if_fail (filename != NULL, NULL);
    g_return_val_if_fail (Inkscape::IO::file_test( filename, G_FILE_TEST_EXISTS ), NULL);
    /* fixme: A file can disappear at any time, including between now and when we actually try to
     * open it.  Get rid of the above test once we're sure that we correctly handle
     * non-existence. */

    // TODO: bulia, please look over
    gsize bytesRead = 0;
    gsize bytesWritten = 0;
    GError* error = NULL;
    // TODO: need to replace with our own fopen and reading
    gchar* localFilename = g_filename_from_utf8 ( filename,
                                 -1,  &bytesRead,  &bytesWritten, &error);
    g_return_val_if_fail( localFilename != NULL, NULL );

    Inkscape::IO::dump_fopen_call( filename, "N" );

#ifdef HAVE_LIBWMF
    if (strlen (localFilename) > 4) {
        if ( (strcmp (localFilename + strlen (localFilename) - 4,".wmf") == 0)
             || (strcmp (localFilename + strlen (localFilename) - 4,".WMF") == 0)) {
            doc = sp_wmf_convert (localFilename);
        }
    }
#endif // !HAVE_LIBWMF

    if ( !doc ) {
        XmlSource src;

        if ( (src.setFile(filename) == 0) ) {
            doc = xmlReadIO( XmlSource::readCb,
                             XmlSource::closeCb,
                             &src,
                             localFilename,
                             src.getEncoding(),
                             XML_PARSE_NOENT );
        }
    }

    rdoc = sp_repr_do_read( doc, default_ns );
    if ( doc ) {
        xmlFreeDoc( doc );
    }

    if ( localFilename ) {
        g_free( localFilename );
    }

    return rdoc;
}


Generated by  Doxygen 1.6.0   Back to index