repr-io.cpp revision 6dda1569f72d2fedf3ea32f9cc29238fd35fe7aa
#define __SP_REPR_IO_C__
/*
* Dirty DOM-like tree
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdexcept>
#include "xml/attribute-record.h"
#include "xml/simple-document.h"
#include "io/uristream.h"
#include "io/gzipstream.h"
#include "prefs-utils.h"
static Node *sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map);
static gint sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar *default_ns, GHashTable *prefix_map);
static void sp_repr_write_stream_root_element (Node *repr, Writer &out, bool add_whitespace, gchar const *default_ns, int inlineattrs, int indent);
static void sp_repr_write_stream (Node *repr, Writer &out, gint indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, int inlineattrs, int indent);
static void sp_repr_write_stream_element (Node *repr, Writer &out, gint indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, List<AttributeRecord const> attributes, int inlineattrs, int indent);
#ifdef HAVE_LIBWMF
static char * sp_wmf_image_name (void * context);
#endif /* HAVE_LIBWMF */
class XmlSource
{
public:
: filename(0),
encoding(0),
fp(0),
firstFewLen(0),
dummy("x"),
instr(0),
gzin(0)
{
}
virtual ~XmlSource()
{
close();
if ( encoding ) {
encoding = 0;
}
}
char const* getEncoding() const { return encoding; }
int close();
private:
const char* filename;
char* encoding;
unsigned char firstFew[4];
int firstFewLen;
};
{
int retVal = -1;
if ( fp ) {
// First peek in the file to see what it is
if ( fp ) {
// first check for compression
//g_message(" the file being read is gzip'd. extract it");
fp = 0;
some = 0;
int single = 0;
{
if ( single >= 0 ) {
} else {
break;
}
}
}
int encSkip = 0;
encSkip = 2;
encSkip = 2;
} else if ( (some >= 3) && (firstFew[0] == 0xef) && (firstFew[1] == 0xbb) && (firstFew[2] == 0xbf) ) {
encSkip = 3;
}
if ( encSkip ) {
}
firstFewLen = some;
retVal = 0; // no error
}
}
return retVal;
}
{
int retVal = -1;
if ( context ) {
}
return retVal;
}
{
if ( context ) {
}
return 0;
}
{
int retVal = 0;
if ( firstFewLen > 0 ) {
if ( len < firstFewLen ) {
}
firstFewLen -= some;
} else if ( gzin ) {
int single = 0;
{
if ( single >= 0 ) {
} else {
break;
}
}
} else {
}
retVal = -1;
} else {
}
return retVal;
}
{
if ( gzin ) {
delete gzin;
gzin = 0;
}
if ( instr ) {
fp = 0;
delete instr;
instr = 0;
}
if ( fp ) {
fp = 0;
}
return 0;
}
/**
* Reads XML from a file, including WMF files, and returns the Document.
* The default namespace can also be specified, if desired.
*/
Document *
{
/* 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 bytesWritten = 0;
// TODO: need to replace with our own fopen and reading
#ifdef HAVE_LIBWMF
}
}
#endif // !HAVE_LIBWMF
if ( !doc ) {
&src,
src.getEncoding(),
}
}
if ( doc ) {
xmlFreeDoc( doc );
}
if ( localFilename ) {
g_free( localFilename );
}
return rdoc;
}
/**
* Reads and parses XML from a buffer, returning it as an Document
*/
Document *
{
if (doc)
xmlFreeDoc (doc);
return rdoc;
}
namespace Inkscape {
struct compare_quark_ids {
}
};
}
namespace {
static PrefixMap prefix_map;
} else {
if (prefix_end) {
return prefix;
} else {
return GQuark(0);
}
}
}
}
namespace {
}
}
}
}
}
/**
* Reads in a XML file to create a Document
*/
Document *
{
if (!root) {
} else {
break;
}
}
}
/* promote elements of SVG documents that don't use namespaces
* into the SVG namespace */
{
}
}
return rdoc;
}
sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar *default_ns, GHashTable *prefix_map)
{
} else {
}
if (prefix)
else
}
static Node *
sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map)
{
gchar c[256];
return NULL; // empty text node
xmlChar *p;
; // skip all whitespace
if (!(*p)) { // this is an all-whitespace node, and preserve == default
return NULL; // we do not preserve all-whitespace nodes unless we are asked to
}
}
/* TODO remember node->ns->prefix if node->ns != NULL */
/* TODO remember prop->ns->prefix if prop->ns != NULL */
}
}
if (crepr) {
}
}
return repr;
}
void
{
Inkscape::IO::OutputStreamWriter *out = compress ? new Inkscape::IO::OutputStreamWriter( *gout ) : new Inkscape::IO::OutputStreamWriter( bout );
/* fixme: do this The Right Way */
if (str) {
}
{
} else {
}
}
if ( out ) {
delete out;
}
if ( gout ) {
delete gout;
}
}
/* Returns TRUE if file successfully saved; FALSE if not
*/
bool
gchar const *default_ns)
{
return FALSE;
}
bool compress = false;
{
tmp[5] = 0;
{
//g_message("TIME TO COMPRESS THE OUTPUT FOR SVGZ");
compress = true;
}
}
}
return FALSE;
}
return FALSE;
}
return TRUE;
}
void
{
return;
}
/* (No doubt this function already exists elsewhere.) */
static void
{
if (!val) return;
switch (*val) {
}
}
}
namespace {
typedef std::map<Glib::QueryQuark, Inkscape::Util::ptr_shared<char>, Inkscape::compare_quark_ids> NSMap;
static LocalNameMap local_name_map;
} else {
if (prefix_end) {
return prefix_end + 1;
} else {
return name_string;
}
}
}
if (uri) {
} else if ( prefix != xml_prefix ) {
}
} else {
}
}
}
{
}
}
{
}
}
}
}
void
sp_repr_write_stream_root_element (Node *repr, Writer &out, bool add_whitespace, gchar const *default_ns,
int inlineattrs, int indent)
{
}
{
if ( prefix != xml_prefix ) {
if ( elide_prefix == prefix ) {
}
}
} else {
// if there are non-namespaced elements, we can't globally
// use a default namespace
elide_prefix = GQuark(0);
}
}
return sp_repr_write_stream_element(repr, out, 0, add_whitespace, elide_prefix, attributes, inlineattrs, indent);
}
void
{
sp_repr_write_stream_element(repr, out, indent_level, add_whitespace, elide_prefix, repr->attributeList(), inlineattrs, indent);
} else {
}
}
void
bool add_whitespace,
int inlineattrs, int indent)
{
bool loose;
if ( indent_level > 16 )
indent_level = 16;
if (add_whitespace && indent) {
for (gint i = 0; i < indent_level; i++) {
}
}
}
gchar const *element_name;
} else {
}
// if this is a <text> element, suppress formatting whitespace
// for its content and children:
}
{
if (!inlineattrs) {
if (indent) {
}
}
}
}
}
break;
}
}
if (repr->firstChild()) {
if (loose && add_whitespace) {
}
sp_repr_write_stream (child, out, (loose) ? (indent_level + 1) : 0, add_whitespace, elide_prefix, inlineattrs, indent);
}
for (gint i = 0; i < indent_level; i++) {
}
}
}
} else {
}
// text elements cannot nest, so we can output newline
// after closing text
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :