From: ishmal Date: Thu, 1 May 2008 19:15:49 +0000 (+0000) Subject: Clean up. More commenting. Smarten SvgParser and rename to SvgReader. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=65386fefd36ba90b988a435ec53a4066960263aa;p=inkscape.git Clean up. More commenting. Smarten SvgParser and rename to SvgReader. --- diff --git a/src/dom/svg.h b/src/dom/svg.h index 1d6e2df5d..09a58a7e5 100644 --- a/src/dom/svg.h +++ b/src/dom/svg.h @@ -35,6 +35,9 @@ * This API follows: * http://www.w3.org/TR/SVG11/svgdom.html * + * This file defines the main SVG-DOM Node types. Other non-Node types are + * defined in svgtypes.h. + * */ diff --git a/src/dom/svgimpl.cpp b/src/dom/svgimpl.cpp index 9343c311d..2c85fa21e 100644 --- a/src/dom/svgimpl.cpp +++ b/src/dom/svgimpl.cpp @@ -10,7 +10,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005 Bob Jamison + * Copyright (C) 2005-2008 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -29,7 +29,11 @@ #include "svgimpl.h" - +/** + * This is the .cpp side of the SVG implementations classes. Note that many + * of the sections for each of the classes is empty. This is because that class + * has been implemented totally in svgimpl.h + */ namespace org { @@ -161,7 +165,7 @@ bool SVGSVGElementImpl::animationsPaused( ) * */ NodeList SVGSVGElementImpl::getIntersectionList(const SVGRect &/*rect*/, - const SVGElementPtr /*referenceElement*/ ) + const SVGElementPtr /*referenceElement*/ ) { NodeList list; return list; @@ -171,7 +175,7 @@ NodeList SVGSVGElementImpl::getIntersectionList(const SVGRect &/*rect*/, * */ NodeList SVGSVGElementImpl::getEnclosureList(const SVGRect &/*rect*/, - const SVGElementPtr /*referenceElement*/ ) + const SVGElementPtr /*referenceElement*/ ) { NodeList list; return list; diff --git a/src/dom/svgimpl.h b/src/dom/svgimpl.h index 2ea09be3c..b3e2066d5 100644 --- a/src/dom/svgimpl.h +++ b/src/dom/svgimpl.h @@ -1719,7 +1719,7 @@ public: * */ virtual double getSubStringLength(unsigned long charnum, - unsigned long nchars ) + unsigned long nchars ) throw( DOMException ); /** diff --git a/src/dom/svgparser.cpp b/src/dom/svgparser.cpp index 186fd40ff..956112c25 100644 --- a/src/dom/svgparser.cpp +++ b/src/dom/svgparser.cpp @@ -25,12 +25,18 @@ * 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 + * + * ======================================================================= + * NOTES + * + * */ #include "svgparser.h" #include "dom/cssparser.h" #include "dom/ucd.h" +#include "xmlreader.h" #include @@ -54,10 +60,10 @@ namespace svg /** * */ -void SvgParser::error(char const *fmt, ...) +void SvgReader::error(char const *fmt, ...) { va_list args; - fprintf(stderr, "SvgParser:error:"); + fprintf(stderr, "SvgReader:error:"); va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args) ; @@ -73,7 +79,7 @@ void SvgParser::error(char const *fmt, ...) /** * Get the character at the position and record the fact */ -XMLCh SvgParser::get(int p) +XMLCh SvgReader::get(int p) { if (p >= parselen) return 0; @@ -89,7 +95,7 @@ XMLCh SvgParser::get(int p) * Test if the given substring exists at the given position * in parsebuf. Use get() in case of out-of-bounds */ -bool SvgParser::match(int pos, char const *str) +bool SvgReader::match(int pos, char const *str) { while (*str) { @@ -102,7 +108,7 @@ bool SvgParser::match(int pos, char const *str) /** * */ -int SvgParser::skipwhite(int p) +int SvgReader::skipwhite(int p) { while (p < parselen) { @@ -162,7 +168,7 @@ int SvgParser::skipwhite(int p) /** * get a word from the buffer */ -int SvgParser::getWord(int p, DOMString &result) +int SvgReader::getWord(int p, DOMString &result) { XMLCh ch = get(p); if (!uni_is_letter(ch)) @@ -195,7 +201,7 @@ int SvgParser::getWord(int p, DOMString &result) /** * get a word from the buffer */ -int SvgParser::getNumber(int p0, double &result) +int SvgReader::getNumber(int p0, double &result) { int p=p0; @@ -249,7 +255,7 @@ int SvgParser::getNumber(int p0, double &result) /** * get a word from the buffer */ -int SvgParser::getNumber(int p0, double &result) +int SvgReader::getNumber(int p0, double &result) { int p=p0; @@ -278,7 +284,7 @@ int SvgParser::getNumber(int p0, double &result) } -bool SvgParser::parseTransform(const DOMString &str) +bool SvgReader::parseTransform(const DOMString &str) { parsebuf = str; parselen = str.size(); @@ -593,7 +599,7 @@ bool SvgParser::parseTransform(const DOMString &str) /** * */ -bool SvgParser::parseElement(SVGElementImplPtr parent, +bool SvgReader::parseElement(SVGElementImplPtr parent, ElementImplPtr sourceElem) { if (!parent || !sourceElem) @@ -726,7 +732,7 @@ bool SvgParser::parseElement(SVGElementImplPtr parent, /** * */ -SVGDocumentPtr SvgParser::parse(const DocumentPtr src) +SVGDocumentPtr SvgReader::parse(const DocumentPtr src) { if (!src) { @@ -749,6 +755,44 @@ SVGDocumentPtr SvgParser::parse(const DocumentPtr src) +/** + * + */ +SVGDocumentPtr SvgReader::parse(const DOMString &buf) +{ + /* remember, smartptrs are null-testable*/ + SVGDocumentPtr svgdoc; + XmlReader parser; + DocumentPtr doc = parser.parse(buf); + if (!doc) + { + return svgdoc; + } + svgdoc = parse(doc); + return svgdoc; +} + + + +/** + * + */ +SVGDocumentPtr SvgReader::parseFile(const DOMString &fileName) +{ + /* remember, smartptrs are null-testable*/ + SVGDocumentPtr svgdoc; + XmlReader parser; + DocumentPtr doc = parser.parseFile(fileName); + if (!doc) + { + return svgdoc; + } + svgdoc = parse(doc); + return svgdoc; +} + + + } //namespace svg } //namespace dom diff --git a/src/dom/svgparser.h b/src/dom/svgparser.h index cb3ac15d4..8e53fe656 100644 --- a/src/dom/svgparser.h +++ b/src/dom/svgparser.h @@ -13,7 +13,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005-2007 Bob Jamison + * Copyright (C) 2005-2008 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,19 @@ * 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 + * + * ======================================================================= + * NOTES + * + * This parser takes an XML document, as a file, string, or DOM Document, + * and attempts to parse it as an SVG-DOM SVGDocument. + * + * Look in svg.h and svgtypes.h for the classes which are the target of this + * parser. + * + * They loosely follow the specification: + * http://www.w3.org/TR/SVG11/svgdom.html + * */ @@ -43,35 +56,45 @@ namespace svg { -class SvgParser +class SvgReader { public: /** * */ - SvgParser() + SvgReader() { } /** * */ - SvgParser(const SvgParser &/*other*/) + SvgReader(const SvgReader &/*other*/) { } /** * */ - virtual ~SvgParser() + virtual ~SvgReader() { } /** * */ - SVGDocumentPtr parse(const DocumentPtr sourceDoc); + SVGDocumentPtr parse(const DocumentPtr /*sourceDoc*/); + + /** + * + */ + SVGDocumentPtr parse(const DOMString &/*buffer*/); + + /** + * + */ + SVGDocumentPtr parseFile(const DOMString &/*fileName*/); diff --git a/src/dom/svgtypes.h b/src/dom/svgtypes.h index 36bb1fcdf..674add792 100644 --- a/src/dom/svgtypes.h +++ b/src/dom/svgtypes.h @@ -13,7 +13,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2006 Bob Jamison + * Copyright (C) 2006-2008 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,16 @@ * 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 + * + * ======================================================================= + * NOTES + * + * This API follows: + * http://www.w3.org/TR/SVG11/svgdom.html + * + * This file contains the definitions of the non-Node SVG classes. DOM Nodes + * for SVG are defined in svg.h. + * */ diff --git a/src/dom/xmlreader.cpp b/src/dom/xmlreader.cpp index 825851479..fc4eee51f 100644 --- a/src/dom/xmlreader.cpp +++ b/src/dom/xmlreader.cpp @@ -49,9 +49,9 @@ namespace dom //######################################################################### struct EntityInfo { - char *escape; + const char *escape; int escapeLength; - char *value; + const char *value; }; @@ -75,7 +75,7 @@ static EntityInfo entityTable[] = /** * */ -void XmlReader::error(char *fmt, ...) +void XmlReader::error(const char *fmt, ...) { va_list args; fprintf(stderr, "XmlReader:error at line %d, column %d:", lineNr, colNr); @@ -156,7 +156,7 @@ int XmlReader::peek(int p) * Test if the given substring exists at the given position * in parsebuf. Use peek() in case of out-of-bounds */ -bool XmlReader::match(int pos, char const *str) +bool XmlReader::match(int pos, const char *str) { while (*str) { @@ -883,8 +883,9 @@ XmlReader::parse(const DOMString &str) { DocumentPtr doc = parse(str, 0, str.size()); + if (!doc) + return doc; doc->normalizeDocument(); - return doc; } @@ -892,12 +893,15 @@ XmlReader::parse(const DOMString &str) * */ org::w3c::dom::DocumentPtr -XmlReader::parseFile(char *fileName) +XmlReader::parseFile(const DOMString &fileName) { - + DocumentPtr doc; + DOMString buf = loadFile(fileName); + if (buf.size() == 0) + return doc; /*doc still null*/ - DocumentPtr doc = parse(buf, 0, buf.size()); + doc = parse(buf, 0, buf.size()); return doc; } @@ -912,16 +916,19 @@ XmlReader::parseFile(char *fileName) * */ org::w3c::dom::DOMString -XmlReader::loadFile(char *fileName) +XmlReader::loadFile(const DOMString &fileName) { + DOMString buf; - if (!fileName) - return NULL; - FILE *f = fopen(fileName, "rb"); + if (fileName.size() == 0) + return buf; + FILE *f = fopen(fileName.c_str(), "rb"); if (!f) - return NULL; + { + //error here + return buf; + } - DOMString buf; while (!feof(f)) { int ch = fgetc(f); diff --git a/src/dom/xmlreader.h b/src/dom/xmlreader.h index fbd62c179..3f97d87c9 100644 --- a/src/dom/xmlreader.h +++ b/src/dom/xmlreader.h @@ -13,7 +13,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005-2007 Bob Jamison + * Copyright (C) 2005-2008 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -74,12 +74,12 @@ public: /** * */ - org::w3c::dom::DocumentPtr parseFile(char *fileName); + org::w3c::dom::DocumentPtr parseFile(const DOMString &fileName); private: - void error(char *format, ...) + void error(const char *format, ...) #ifdef G_GNUC_PRINTF G_GNUC_PRINTF(2, 3) #endif @@ -116,7 +116,7 @@ private: int len; //length of parsed region DOMString parsebuf; - DOMString loadFile(char *fileName); + DOMString loadFile(const DOMString &fileName); int lineNr; int colNr;