summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2809bf1)
raw | patch | inline | side by side (parent: 2809bf1)
author | ishmal <ishmal@users.sourceforge.net> | |
Sun, 25 Jun 2006 19:37:31 +0000 (19:37 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Sun, 25 Jun 2006 19:37:31 +0000 (19:37 +0000) |
src/extension/internal/odf.cpp | patch | blob | history | |
src/extension/internal/odf.h | patch | blob | history |
index f366a9fad76b17b6d87bc174c8cb6fe616a42a1e..fcb9c23d2389dd7fea5b9643d4ee32b013ab291b 100644 (file)
//# Shorthand notation
typedef org::w3c::dom::DOMString DOMString;
+typedef org::w3c::dom::XMLCh XMLCh;
typedef org::w3c::dom::io::OutputStreamWriter OutputStreamWriter;
typedef org::w3c::dom::io::BufferOutputStream BufferOutputStream;
typedef org::w3c::dom::io::StringOutputStream StringOutputStream;
/**
* Get the value of a node/attribute pair
*/
-static std::string getAttribute( Inkscape::XML::Node *node, char *attrName)
+static Glib::ustring getAttribute( Inkscape::XML::Node *node, char *attrName)
{
- std::string val;
+ Glib::ustring val;
char *valstr = (char *)node->attribute(attrName);
if (valstr)
val = (const char *)valstr;
/**
* Get the extension suffix from the end of a file name
*/
-static std::string getExtension(const std::string &fname)
+static Glib::ustring getExtension(const Glib::ustring &fname)
{
- std::string ext;
+ Glib::ustring ext;
unsigned int pos = fname.rfind('.');
if (pos == fname.npos)
}
-static std::string formatTransform(NR::Matrix &tf)
+static Glib::ustring formatTransform(NR::Matrix &tf)
{
- std::string str;
+ Glib::ustring str;
if (!tf.test_identity())
{
StringOutputStream outs;
}
+/**
+ * Encode a string, checking for XML entities, to
+ * make an XML string safe for output
+ */
+static Glib::ustring toXml(const Glib::ustring &str)
+{
+ Glib::ustring outbuf;
+ for (unsigned int i=0 ; i<str.size() ; i++)
+ {
+ XMLCh ch = (XMLCh) str[i];
+ if (ch == '&')
+ outbuf.append("&r;");
+ else if (ch == '<')
+ outbuf.append("<");
+ else if (ch == '>')
+ outbuf.append(">");
+ else if (ch == '"')
+ outbuf.append(""");
+ else if (ch == '\'')
+ outbuf.append("'");
+ else
+ outbuf.push_back(ch);
+ }
+ return outbuf;
+}
+
+
-static void gatherText(Inkscape::XML::Node *node, std::string &buf)
+static void gatherText(Inkscape::XML::Node *node, Glib::ustring &buf)
{
if (node->type() == Inkscape::XML::TEXT_NODE)
{
OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node)
{
- std::string nodeName = node->name();
- std::string id = getAttribute(node, "id");
+ Glib::ustring nodeName = node->name();
+ Glib::ustring id = getAttribute(node, "id");
//### First, check for metadata
if (nodeName == "metadata" || nodeName == "svg:metadata")
for (Inkscape::XML::Node *cchild = rchild->firstChild() ;
cchild ; cchild = cchild->next())
{
- std::string ccName = cchild->name();
- std::string ccVal;
+ Glib::ustring ccName = cchild->name();
+ Glib::ustring ccVal;
gatherText(cchild, ccVal);
//g_message("ccName: %s ccVal:%s", ccName.c_str(), ccVal.c_str());
metadata[ccName] = ccVal;
if (nodeName == "image" || nodeName == "svg:image")
{
//g_message("image");
- std::string href = getAttribute(node, "xlink:href");
+ Glib::ustring href = getAttribute(node, "xlink:href");
if (href.size() > 0)
{
- std::string oldName = href;
- std::string ext = getExtension(oldName);
+ Glib::ustring oldName = href;
+ Glib::ustring ext = getExtension(oldName);
if (ext == ".jpeg")
ext = ".jpg";
if (imageTable.find(oldName) == imageTable.end())
char buf[64];
snprintf(buf, 63, "Pictures/image%d%s",
(int)imageTable.size(), ext.c_str());
- std::string newName = buf;
+ Glib::ustring newName = buf;
imageTable[oldName] = newName;
- std::string comment = "old name was: ";
+ Glib::ustring comment = "old name was: ";
comment.append(oldName);
URI oldUri(oldName);
//g_message("oldpath:%s", oldUri.getNativePath().c_str());
if (gi.equals(*iter))
{
//map to existing gradientTable entry
- std::string gradientName = iter->name;
+ Glib::ustring gradientName = iter->name;
//g_message("found duplicate style:%s", gradientName.c_str());
gradientLookupTable[id] = gradientName;
gradientMatch = true;
{
char buf[16];
snprintf(buf, 15, "gradient%d", (int)gradientTable.size());
- std::string gradientName = buf;
+ Glib::ustring gradientName = buf;
gi.name = gradientName;
gradientTable.push_back(gi);
gradientLookupTable[id] = gradientName;
if (si.equals(*iter))
{
//map to existing styleTable entry
- std::string styleName = iter->name;
+ Glib::ustring styleName = iter->name;
//g_message("found duplicate style:%s", styleName.c_str());
styleLookupTable[id] = styleName;
styleMatch = true;
{
char buf[16];
snprintf(buf, 15, "style%d", (int)styleTable.size());
- std::string styleName = buf;
+ Glib::ustring styleName = buf;
si.name = styleName;
styleTable.push_back(si);
styleLookupTable[id] = styleName;
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");
outs.printf(" <!--List our images here-->\n");
- std::map<std::string, std::string>::iterator iter;
+ std::map<Glib::ustring, Glib::ustring>::iterator iter;
for (iter = imageTable.begin() ; iter!=imageTable.end() ; iter++)
{
- std::string oldName = iter->first;
- std::string newName = iter->second;
+ Glib::ustring oldName = iter->first;
+ Glib::ustring newName = iter->second;
- std::string ext = getExtension(oldName);
+ Glib::ustring ext = getExtension(oldName);
if (ext == ".jpeg")
ext = ".jpg";
outs.printf(" <manifest:file-entry manifest:media-type=\"");
time_t tim;
time(&tim);
- std::map<std::string, std::string>::iterator iter;
- std::string creator = "unknown";
+ std::map<Glib::ustring, Glib::ustring>::iterator iter;
+ Glib::ustring creator = "unknown";
iter = metadata.find("dc:creator");
if (iter != metadata.end())
creator = iter->second;
- std::string date = "";
+ Glib::ustring date = "";
iter = metadata.find("dc:date");
if (iter != metadata.end())
date = iter->second;
outs.printf("<office:meta>\n");
outs.printf(" <meta:generator>Inkscape.org - 0.45</meta:generator>\n");
outs.printf(" <meta:initial-creator>%s</meta:initial-creator>\n",
- creator.c_str());
+ toXml(creator).c_str());
outs.printf(" <meta:creation-date>%s</meta:creation-date>\n", date.c_str());
for (iter = metadata.begin() ; iter != metadata.end() ; iter++)
{
- std::string name = iter->first;
- std::string value = iter->second;
+ Glib::ustring name = iter->first;
+ Glib::ustring value = iter->second;
if (name.size() > 0 && value.size()>0)
{
outs.printf(" <%s>%s</%s>\n",
- name.c_str(), value.c_str(), name.c_str());
+ toXml(name).c_str(), toXml(value).c_str(), toXml(name).c_str());
}
}
outs.printf(" <meta:editing-cycles>2</meta:editing-cycles>\n");
SPItem *item = SP_ITEM(reprobj);
- std::string nodeName = node->name();
- std::string id = getAttribute(node, "id");
+ Glib::ustring nodeName = node->name();
+ Glib::ustring id = getAttribute(node, "id");
//### Get SVG-to-ODF transform
NR::Matrix tf = getODFTransform(item);
NR::Matrix itemTransform = getODFItemTransform(item);
- std::string itemTransformString = formatTransform(itemTransform);
+ Glib::ustring itemTransformString = formatTransform(itemTransform);
- std::string href = getAttribute(node, "xlink:href");
- std::map<std::string, std::string>::iterator iter = imageTable.find(href);
+ Glib::ustring href = getAttribute(node, "xlink:href");
+ std::map<Glib::ustring, Glib::ustring>::iterator iter = imageTable.find(href);
if (iter == imageTable.end())
{
g_warning("image '%s' not in table", href.c_str());
return false;
}
- std::string newName = iter->second;
+ Glib::ustring newName = iter->second;
outs.printf("<draw:frame ");
if (id.size() > 0)
if (id.size()>0)
outs.printf("id=\"%s\" ", id.c_str());
- std::map<std::string, std::string>::iterator siter;
+ std::map<Glib::ustring, Glib::ustring>::iterator siter;
siter = styleLookupTable.find(id);
if (siter != styleLookupTable.end())
{
- std::string styleName = siter->second;
+ Glib::ustring styleName = siter->second;
outs.printf("draw:style-name=\"%s\" ", styleName.c_str());
}
- std::map<std::string, std::string>::iterator giter;
+ std::map<Glib::ustring, Glib::ustring>::iterator giter;
giter = gradientLookupTable.find(id);
if (giter != gradientLookupTable.end())
{
- std::string gradientName = giter->second;
+ Glib::ustring gradientName = giter->second;
outs.printf("draw:fill-gradient-name=\"%s\" ",
gradientName.c_str());
}
index a9f9508a92fa339506f8ac9372cd5ad11c1c96da..d715c3702b8d8af2bbda5413478ec20d80f22c3a 100644 (file)
#include <dom/io/stringstream.h>
#include <dom/uri.h>
-#include <glib.h>
+#include <glibmm.h>
#include "extension/implementation/implementation.h"
return true;
}
- std::string name;
- std::string stroke;
- std::string strokeColor;
- std::string strokeWidth;
- std::string strokeOpacity;
- std::string fill;
- std::string fillColor;
- std::string fillOpacity;
+ Glib::ustring name;
+ Glib::ustring stroke;
+ Glib::ustring strokeColor;
+ Glib::ustring strokeWidth;
+ Glib::ustring strokeOpacity;
+ Glib::ustring fill;
+ Glib::ustring fillColor;
+ Glib::ustring fillOpacity;
};
return true;
}
- std::string name;
- std::string style;
+ Glib::ustring name;
+ Glib::ustring style;
double cx;
double cy;
double fx;
void reset();
//cc or dc metadata name/value pairs
- std::map<std::string, std::string> metadata;
+ std::map<Glib::ustring, Glib::ustring> metadata;
/* Style table
Uses a two-stage lookup to avoid style duplication.
but check for errors, of course
*/
//element id -> style entry name
- std::map<std::string, std::string> styleLookupTable;
+ std::map<Glib::ustring, Glib::ustring> styleLookupTable;
//style entry name -> style info
std::vector<StyleInfo> styleTable;
//element id -> gradient entry name
- std::map<std::string, std::string> gradientLookupTable;
+ std::map<Glib::ustring, Glib::ustring> gradientLookupTable;
//gradient entry name -> gradient info
std::vector<GradientInfo> gradientTable;
//for renaming image file names
- std::map<std::string, std::string> imageTable;
+ std::map<Glib::ustring, Glib::ustring> imageTable;
void preprocess(ZipFile &zf, Inkscape::XML::Node *node);