From c344ff4314343e494f7a76b8cb5c649829113036 Mon Sep 17 00:00:00 2001 From: ishmal Date: Mon, 12 May 2008 20:20:57 +0000 Subject: [PATCH] minor changes for svg document --- src/dom/Makefile.mingw | 4 +++- src/dom/dom.h | 12 +++++----- src/dom/svgimpl.cpp | 7 ++++++ src/dom/svgimpl.h | 10 ++------- src/dom/svgreader.cpp | 48 ++++++++++++++++++++++++++++------------ src/dom/svgreader.h | 17 ++++++++++---- src/dom/work/testdom.cpp | 2 +- src/dom/work/testsvg.cpp | 28 +++++------------------ 8 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/dom/Makefile.mingw b/src/dom/Makefile.mingw index 4d382c8c0..17c28b63b 100644 --- a/src/dom/Makefile.mingw +++ b/src/dom/Makefile.mingw @@ -177,7 +177,9 @@ work/testzip.o OBJ = $(DOMOBJ) -all: testdom.exe testhttp.exe \ +all: testsvg.exe + +tests: testdom.exe testhttp.exe \ testsvg.exe testuri.exe testxpath.exe testzip.exe testdom.exe: libdom.a work/testdom.o diff --git a/src/dom/dom.h b/src/dom/dom.h index c1d9428d0..540e7361c 100644 --- a/src/dom/dom.h +++ b/src/dom/dom.h @@ -57,8 +57,8 @@ * Then below, select one of the corresponding typedefs. */ -#include -//#include +//#include +#include //# Unfortunate hack for a name collision #ifdef SEVERITY_ERROR @@ -79,11 +79,11 @@ namespace dom * This is the org::w3c::dom::DOMString definition. * Which type do we want? */ -typedef Glib::ustring DOMString; -typedef gunichar XMLCh; +//typedef Glib::ustring DOMString; +//typedef gunichar XMLCh; -//typedef std::string DOMString; -//typedef unsigned short XMLCh; +typedef std::string DOMString; +typedef unsigned short XMLCh; /** diff --git a/src/dom/svgimpl.cpp b/src/dom/svgimpl.cpp index 2c85fa21e..fc0af59c9 100644 --- a/src/dom/svgimpl.cpp +++ b/src/dom/svgimpl.cpp @@ -96,6 +96,13 @@ ElementPtr SVGDocumentImpl::createElementNS(const DOMString& namespaceURI, //# Non-API methods //################## +void SVGDocumentImpl::init() +{ + title = ""; + referrer = ""; + domain = ""; + rootElement = new SVGSVGElementImpl(); +} diff --git a/src/dom/svgimpl.h b/src/dom/svgimpl.h index b3e2066d5..80800098a 100644 --- a/src/dom/svgimpl.h +++ b/src/dom/svgimpl.h @@ -153,19 +153,13 @@ protected: friend class SvgParser; - void init() - { - title = ""; - referrer = ""; - domain = ""; - rootElement = NULL; - } + void init(); DOMString title; DOMString referrer; DOMString domain; DOMString url; - SVGSVGElementPtr rootElement; + SVGSVGElementImplPtr rootElement; }; diff --git a/src/dom/svgreader.cpp b/src/dom/svgreader.cpp index 4fd081743..fb4b3c62e 100644 --- a/src/dom/svgreader.cpp +++ b/src/dom/svgreader.cpp @@ -60,10 +60,10 @@ namespace svg /** * */ -void SvgReader::error(char const *fmt, ...) +void SVGReader::error(char const *fmt, ...) { va_list args; - fprintf(stderr, "SvgReader:error:"); + fprintf(stderr, "SVGReader:error: "); va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args) ; @@ -71,6 +71,20 @@ void SvgReader::error(char const *fmt, ...) } +/** + * + */ +void SVGReader::trace(char const *fmt, ...) +{ + va_list args; + fprintf(stdout, "SVGReader: "); + va_start(args, fmt); + vfprintf(stdout, fmt, args); + va_end(args) ; + fprintf(stdout, "\n"); +} + + //######################################################################### //# P A R S I N G @@ -79,7 +93,7 @@ void SvgReader::error(char const *fmt, ...) /** * Get the character at the position and record the fact */ -XMLCh SvgReader::get(int p) +XMLCh SVGReader::get(int p) { if (p >= parselen) return 0; @@ -95,7 +109,7 @@ XMLCh SvgReader::get(int p) * Test if the given substring exists at the given position * in parsebuf. Use get() in case of out-of-bounds */ -bool SvgReader::match(int pos, char const *str) +bool SVGReader::match(int pos, char const *str) { while (*str) { @@ -108,7 +122,7 @@ bool SvgReader::match(int pos, char const *str) /** * */ -int SvgReader::skipwhite(int p) +int SVGReader::skipwhite(int p) { while (p < parselen) { @@ -168,7 +182,7 @@ int SvgReader::skipwhite(int p) /** * get a word from the buffer */ -int SvgReader::getWord(int p, DOMString &result) +int SVGReader::getWord(int p, DOMString &result) { XMLCh ch = get(p); if (!uni_is_letter(ch)) @@ -201,7 +215,7 @@ int SvgReader::getWord(int p, DOMString &result) /** * get a word from the buffer */ -int SvgReader::getNumber(int p0, double &result) +int SVGReader::getNumber(int p0, double &result) { int p=p0; @@ -255,7 +269,7 @@ int SvgReader::getNumber(int p0, double &result) /** * get a word from the buffer */ -int SvgReader::getNumber(int p0, double &result) +int SVGReader::getNumber(int p0, double &result) { int p=p0; @@ -284,7 +298,7 @@ int SvgReader::getNumber(int p0, double &result) } -bool SvgReader::parseTransform(const DOMString &str) +bool SVGReader::parseTransform(const DOMString &str) { parsebuf = str; parselen = str.size(); @@ -599,10 +613,15 @@ bool SvgReader::parseTransform(const DOMString &str) /** * */ -bool SvgReader::parseElement(SVGElementImplPtr parent, +bool SVGReader::parseElement(SVGElementImplPtr parent, ElementImplPtr sourceElem) { - if (!parent || !sourceElem) + if (!parent) + { + error("NULL dest element"); + return false; + } + if (!sourceElem) { error("NULL source element"); return false; @@ -732,7 +751,7 @@ bool SvgReader::parseElement(SVGElementImplPtr parent, /** * */ -SVGDocumentPtr SvgReader::parse(const DocumentPtr src) +SVGDocumentPtr SVGReader::parse(const DocumentPtr src) { if (!src) { @@ -758,7 +777,7 @@ SVGDocumentPtr SvgReader::parse(const DocumentPtr src) /** * */ -SVGDocumentPtr SvgReader::parse(const DOMString &buf) +SVGDocumentPtr SVGReader::parse(const DOMString &buf) { /* remember, smartptrs are null-testable*/ SVGDocumentPtr svgdoc; @@ -777,7 +796,7 @@ SVGDocumentPtr SvgReader::parse(const DOMString &buf) /** * */ -SVGDocumentPtr SvgReader::parseFile(const DOMString &fileName) +SVGDocumentPtr SVGReader::parseFile(const DOMString &fileName) { /* remember, smartptrs are null-testable*/ SVGDocumentPtr svgdoc; @@ -785,6 +804,7 @@ SVGDocumentPtr SvgReader::parseFile(const DOMString &fileName) DocumentPtr doc = parser.parseFile(fileName); if (!doc) { + error("Could not load xml doc"); return svgdoc; } svgdoc = parse(doc); diff --git a/src/dom/svgreader.h b/src/dom/svgreader.h index cfc41287e..2a0106cac 100644 --- a/src/dom/svgreader.h +++ b/src/dom/svgreader.h @@ -56,28 +56,28 @@ namespace svg { -class SvgReader +class SVGReader { public: /** * */ - SvgReader() + SVGReader() { } /** * */ - SvgReader(const SvgReader &/*other*/) + SVGReader(const SVGReader &/*other*/) { } /** * */ - virtual ~SvgReader() + virtual ~SVGReader() { } @@ -151,6 +151,15 @@ private: #endif ; + /** + * + */ + void trace(char const *format, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + DOMString parsebuf; diff --git a/src/dom/work/testdom.cpp b/src/dom/work/testdom.cpp index bd6cf6bfb..41a831aaa 100644 --- a/src/dom/work/testdom.cpp +++ b/src/dom/work/testdom.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 diff --git a/src/dom/work/testsvg.cpp b/src/dom/work/testsvg.cpp index b347d2415..56d8108b0 100644 --- a/src/dom/work/testsvg.cpp +++ b/src/dom/work/testsvg.cpp @@ -10,7 +10,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005-2006 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,35 +29,18 @@ +#include "svgreader.h" #include "lsimpl.h" using namespace org::w3c::dom; -bool doTest(char *filename) +bool doTest(char *fileName) { - ls::DOMImplementationLSImpl domImpl; - ls::LSInput input = domImpl.createLSInput(); - ls::LSParser &parser = domImpl.createLSParser(0, ""); - - DOMString buf; - FILE *f = fopen(filename, "rb"); - if (!f) - { - printf("Cannot open %s for reading\n", filename); - return false; - } - while (!feof(f)) - { - int ch = fgetc(f); - buf.push_back(ch); - } - fclose(f); - input.setStringData(buf); - printf("######## PARSE ######################################\n"); - DocumentPtr doc = parser.parse(input); + svg::SVGReader parser; + svg::SVGDocumentPtr doc = parser.parseFile(fileName); if (!doc) { @@ -67,6 +50,7 @@ bool doTest(char *filename) //### OUTPUT printf("######## SERIALIZE ##################################\n"); + ls::DOMImplementationLSImpl domImpl; ls::LSSerializer &serializer = domImpl.createLSSerializer(); ls::LSOutput output = domImpl.createLSOutput(); io::StdWriter writer; -- 2.30.2