odf.cpp revision b2378d678ae292bc345791df0c36cca466556f1b
/**
* OpenDocument <drawing> input and output
*
* This is an an entry in the extensions mechanism to begin to enable
* the inputting and outputting of OpenDocument Format (ODF) files from
* within Inkscape. Although the initial implementations will be very lossy
* do to the differences in the models of SVG and ODF, they will hopefully
* improve greatly with time.
*
*
* Authors:
* Bob Jamison
*
* Copyright (C) 2006 Bob Jamison
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "odf.h"
//# System includes
#include <stdio.h>
#include <time.h>
#include <vector>
//# Inkscape includes
#include "clear-n_.h"
#include "inkscape.h"
#include <style.h>
#include "libnr/n-art-bpath.h"
#include "xml/attribute-record.h"
#include "sp-image.h"
#include "sp-path.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "text-editing.h"
//# DOM-specific includes
#include "dom/io/domstream.h"
#include "dom/io/bufferstream.h"
//# Shorthand notation
namespace Inkscape
{
namespace Extension
{
namespace Internal
{
//#define pxToCm 0.0275
#define pxToCm 0.0333
#define piToRad 0.0174532925
#define docHeightCm 22.86
//########################################################################
//# O U T P U T
//########################################################################
{
if (valstr)
return val;
}
{
{
ext = "";
}
else
{
}
return ext;
}
/**
* Method descends into the repr tree, converting image and style info
* into forms compatible in ODF.
*/
void
{
{
//g_message("image");
{
if (ext == ".jpeg")
ext = ".jpg";
{
char buf[64];
if (ze)
{
}
else
{
}
}
}
}
if (!reprobj)
return;
if (!SP_IS_ITEM(reprobj))
{
return;
}
{
{
char buf[16];
//g_message("## %s %lx", id.c_str(), (unsigned int)fillCol);
}
{
char buf[16];
}
}
/*
//Look for style values in the svg element
Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attr =
node->attributeList();
for ( ; attr ; ++attr)
{
if (!attr->key || !attr->value)
{
g_warning("null key or value in attribute");
continue;
}
//g_message("key:%s value:%s", g_quark_to_string(attr->key),
// g_quark_to_string(attr->value) );
std::string attrName = (const char *)g_quark_to_string(attr->key);
std::string attrValue = (const char *)attr->value;
//g_message("tag:'%s' key:'%s' value:'%s'",
// nodeName.c_str(), attrName.c_str(), attrValue.c_str() );
if (attrName == "style")
{
StyleInfo si(attrName, attrValue);
if (styleTable.find(attrValue) != styleTable.end())
{
//g_message("duplicate style");
}
else
{
char buf[16];
snprintf(buf, 15, "style%d", styleTable.size());
std::string attrName = buf;
//Map from value-->name . Looks backwards, i know
styleTable[attrValue] = si;
//g_message("mapping '%s' to '%s'",
// attrValue.c_str(), attrName.c_str());
}
}
}
*/
}
{
outs.printf("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n");
outs.printf("<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">\n");
outs.printf(" <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>\n");
outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>\n");
outs.printf(" <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>\n");
{
if (ext == ".jpeg")
ext = ".jpg";
if (ext == ".gif")
else if (ext == ".png")
else if (ext == ".jpg")
}
//Make our entry
return true;
}
{
//Make our entry
return true;
}
{
outs.printf("<style:style style:name=\"grx1\" style:family=\"graphic\" style:parent-style-name=\"standard\">\n");
//## Dump our style table
{
if (s.getFill() != "none")
if (s.getStroke() != "none")
{
}
}
return true;
}
static void
{
bool closed = false;
{
{
case NR_LINETO:
break;
case NR_CURVETO:
break;
case NR_MOVETO_OPEN:
case NR_MOVETO:
if (closed)
break;
default:
break;
}
}
if (closed)
}
{
//# Get the SPItem, if applicable
if (!reprobj)
return true;
if (!SP_IS_ITEM(reprobj))
{
return true;
}
//Flip Y into document coordinates
//# Do our stuff
//g_message("##### %s #####", nodeName.c_str());
{
//# Iterate through the children
{
return false;
}
return true;
}
{
else
//# Iterate through the children
{
return false;
}
return true;
}
{
{
return false;
}
return true;
}
else if (SP_IS_SHAPE(item))
{
//g_message("### %s is a shape", nodeName.c_str());
}
{
}
if (curve)
{
//Inkscape::XML::Node *repr = sp_repr_new("svg:path");
/* Transformation */
//repr->setAttribute("transform", SP_OBJECT_REPR(item)->attribute("transform"));
/* Rotation center */
//sp_repr_set_attr(repr, "inkscape:transform-center-x", SP_OBJECT_REPR(item)->attribute("inkscape:transform-center-x"));
//sp_repr_set_attr(repr, "inkscape:transform-center-y", SP_OBJECT_REPR(item)->attribute("inkscape:transform-center-y"));
/* Definition */
x, y);
}
return true;
}
{
//AffineTransform trans = new AffineTransform();
//trans.scale(12.0, 12.0);
if (!writeStyle(outs))
{
g_warning("Failed to write styles");
return false;
}
{
g_warning("Failed to convert SVG tree");
return false;
}
//Make our entry
return true;
}
/**
* Descends into the SVG tree, mapping things to ODF when appropriate
*/
void
{
styleTable.clear();
imageTable.clear();
if (!writeManifest(zf))
{
g_warning("Failed to write manifest");
return;
}
{
g_warning("Failed to write metafile");
return;
}
{
g_warning("Failed to write content");
return;
}
{
return;
}
}
/**
* This is the definition of PovRay output. This function just
* calls the extension system with the memory allocated XML that
* describes the data.
*/
void
{
"<inkscape-extension>\n"
"<id>org.inkscape.output.odf</id>\n"
"<output>\n"
"<extension>.odg</extension>\n"
"<mimetype>text/x-povray-script</mimetype>\n"
"</output>\n"
"</inkscape-extension>",
new OdfOutput());
}
/**
* Make sure that we are in the database
*/
bool
{
/* We don't need a Key
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV))
return FALSE;
*/
return TRUE;
}
//########################################################################
//# I N P U T
//########################################################################
//#######################
//# L A T E R !!! :-)
//#######################
} //namespace Internal
} //namespace Extension
} //namespace Inkscape
//########################################################################
//# E N D O F F I L E
//########################################################################
/*
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 :