From 3213941c5ce5354e2e91184d5473294fa05e68d8 Mon Sep 17 00:00:00 2001 From: ishmal Date: Sun, 25 Jun 2006 16:03:02 +0000 Subject: [PATCH] Add metadata --- src/extension/internal/odf.cpp | 70 ++++++++++++++++++++++++++++++---- src/extension/internal/odf.h | 3 ++ 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 14fa01e40..1c29d65ff 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -1015,6 +1015,22 @@ static void analyzeTransform(NR::Matrix &tf, +static void gatherText(Inkscape::XML::Node *node, std::string &buf) +{ + if (node->type() == Inkscape::XML::TEXT_NODE) + { + char *s = (char *)node->content(); + if (s) + buf.append(s); + } + + for (Inkscape::XML::Node *child = node->firstChild() ; + child != NULL; child = child->next()) + { + gatherText(child, buf); + } + +} /** * FIRST PASS. @@ -1028,6 +1044,28 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) std::string nodeName = node->name(); std::string id = getAttribute(node, "id"); + //### First, check for metadata + if (nodeName == "metadata" || nodeName == "svg:metadata") + { + Inkscape::XML::Node *mchild = node->firstChild() ; + if (!mchild || strcmp(mchild->name(), "rdf:RDF")) + return; + Inkscape::XML::Node *rchild = mchild->firstChild() ; + if (!rchild || strcmp(rchild->name(), "cc:Work")) + return; + for (Inkscape::XML::Node *cchild = rchild->firstChild() ; + cchild ; cchild = cchild->next()) + { + std::string ccName = cchild->name(); + std::string ccVal; + gatherText(cchild, ccVal); + //g_message("ccName: %s ccVal:%s", ccName.c_str(), ccVal.c_str()); + metadata[ccName] = ccVal; + } + return; + } + + //Now consider items. SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(node); if (!reprobj) return; @@ -1039,7 +1077,6 @@ OdfOutput::preprocess(ZipFile &zf, Inkscape::XML::Node *node) //### Get SVG-to-ODF transform NR::Matrix tf = getODFTransform(item); - if (nodeName == "image" || nodeName == "svg:image") { //g_message("image"); @@ -1297,6 +1334,16 @@ bool OdfOutput::writeMeta(ZipFile &zf) time_t tim; time(&tim); + std::map::iterator iter; + std::string creator = "unknown"; + iter = metadata.find("dc:creator"); + if (iter != metadata.end()) + creator = iter->second; + std::string date = ""; + iter = metadata.find("dc:date"); + if (iter != metadata.end()) + date = iter->second; + outs.printf("\n"); outs.printf("\n"); outs.printf("\n"); @@ -1320,12 +1367,20 @@ bool OdfOutput::writeMeta(ZipFile &zf) outs.printf("xmlns:anim=\"urn:oasis:names:tc:opendocument:xmlns:animation:1.0\"\n"); outs.printf("office:version=\"1.0\">\n"); outs.printf("\n"); - outs.printf(" Inkscape.org - 0.44\n"); - outs.printf(" clark kent\n"); - outs.printf(" 2006-04-13T17:12:29\n"); - outs.printf(" clark kent\n"); - outs.printf(" 2006-04-13T17:13:20\n"); - outs.printf(" en-US\n"); + outs.printf(" Inkscape.org - 0.45\n"); + outs.printf(" %s\n", + creator.c_str()); + outs.printf(" %s\n", date.c_str()); + for (iter = metadata.begin() ; iter != metadata.end() ; iter++) + { + std::string name = iter->first; + std::string value = iter->second; + if (name.size() > 0 && value.size()>0) + { + outs.printf(" <%s>%s\n", + name.c_str(), value.c_str(), name.c_str()); + } + } outs.printf(" 2\n"); outs.printf(" PT56S\n"); outs.printf(" \n"); @@ -1878,6 +1933,7 @@ bool OdfOutput::writeContent(ZipFile &zf, Inkscape::XML::Node *node) void OdfOutput::reset() { + metadata.clear(); styleTable.clear(); styleLookupTable.clear(); gradientTable.clear(); diff --git a/src/extension/internal/odf.h b/src/extension/internal/odf.h index 4c288f7f2..a9f9508a9 100644 --- a/src/extension/internal/odf.h +++ b/src/extension/internal/odf.h @@ -243,6 +243,9 @@ private: void reset(); + //cc or dc metadata name/value pairs + std::map metadata; + /* Style table Uses a two-stage lookup to avoid style duplication. Use like: -- 2.30.2