svgparser.cpp revision 31c0d56f2ec3810c7917d23ebaba028dcee1f118
/**
* Phoebe DOM Implementation.
*
* This is a C++ approximation of the W3C DOM model, which follows
* fairly closely the specifications in the various .idl files, copies of
* which are provided for reference. Most important is this one:
*
*
* Authors:
* Bob Jamison
*
* Copyright (C) 2005 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
*/
#include "svgparser.h"
#include "dom/cssparser.h"
#include "dom/charclass.h"
#include <stdarg.h>
#define SVG_NAMESPACE "http://www.w3.org/2000/svg"
namespace org
{
namespace w3c
{
namespace dom
{
namespace svg
{
//#########################################################################
//# M E S S A G E S
//#########################################################################
/**
*
*/
{
}
//#########################################################################
//# P A R S I N G
//#########################################################################
/**
* Get the character at the position and record the fact
*/
{
if (p >= parselen)
return 0;
//printf("%c", ch);
lastPosition = p;
return ch;
}
/**
* Test if the given substring exists at the given position
* in parsebuf. Use get() in case of out-of-bounds
*/
{
while (*str)
{
return false;
}
return true;
}
/**
*
*/
{
while (p < parselen)
{
//# XML COMMENT
if (match(p, "<!--"))
{
p+=4;
bool done=false;
while (p<parselen)
{
if (match(p, "-->"))
{
p+=3;
done=true;
break;
}
p++;
}
lastPosition = p;
if (!done)
{
error("unterminated <!-- .. --> comment");
return -1;
}
}
//# C comment
else if (match(p, "/*"))
{
p+=2;
bool done=false;
while (p<parselen)
{
if (match(p, "*/"))
{
p+=2;
done=true;
break;
}
p++;
}
lastPosition = p;
if (!done)
{
error("unterminated /* .. */ comment");
return -1;
}
}
else if (!isWhitespace(get(p)))
break;
else
p++;
}
lastPosition = p;
return p;
}
/**
* get a word from the buffer
*/
{
return p;
p++;
while (p < parselen)
{
{
p++;
}
else if (ch == '\\')
{
p+=2;
}
else
break;
}
return p;
}
# if 0
/**
* get a word from the buffer
*/
{
int p=p0;
//allow sign
if (get(p) == '-')
{
p++;
}
while (p < parselen)
{
break;
p++;
}
{
p++;
while (p < parselen)
{
break;
p++;
}
}
if (p>p0)
{
{
return p;
}
}
//not a number
return p0;
}
#endif
/**
* get a word from the buffer
*/
{
int p=p0;
char buf[64];
int i;
for (i=0 ; i<63 && p<parselen ; i++)
{
}
buf[i] = '\0';
{
return p;
}
//not a number
return p0;
}
{
//printf("transform:%s\n", str.c_str());
int p = 0;
while (p < parselen)
{
p = skipwhite(p);
if (p2<0)
return false;
if (p2<=p)
{
error("transform: need transform name");
//return false;
break;
}
p = p2;
//printf("transform name:%s\n", name.c_str());
//######### MATRIX
if (name == "matrix")
{
p = skipwhite(p);
if (get(p++) != '(')
{
error("matrix transform needs opening '('");
return false;
}
int nrVals = 0;
double vals[6];
bool seenBrace = false;
{
p = skipwhite(p);
double val = 0.0;
if (p2<0)
return false;
if (p2<=p)
{
error("matrix() expected number");
return false;
}
if (ch == ',')
{
p++;
p = skipwhite(p);
}
if (ch == ')')
{
seenBrace = true;
p++;
break;
}
}
if (!seenBrace)
{
error("matrix() needs closing brace");
return false;
}
if (nrVals != 6)
{
error("matrix() requires exactly 6 arguments");
return false;
}
//We got our arguments
//printf("translate: %f %f %f %f %f %f\n",
// vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]);
}
//######### TRANSLATE
else if (name == "translate")
{
p = skipwhite(p);
if (get(p++) != '(')
{
error("matrix transform needs opening '('");
return false;
}
p = skipwhite(p);
double x = 0.0;
if (p2<0)
return false;
if (p2<=p)
{
error("translate() expected 'x' value");
return false;
}
if (get(p) == ',')
{
p++;
p = skipwhite(p);
}
double y = 0.0;
if (p2<0)
return false;
if (p2<=p) //no y specified. use default
y = 0.0;
if (get(p++) != ')')
{
error("translate() needs closing ')'");
return false;
}
//printf("translate: %f %f\n", x, y);
transform.setTranslate(x, y);
}
//######### SCALE
else if (name == "scale")
{
p = skipwhite(p);
if (get(p++) != '(')
{
error("scale transform needs opening '('");
return false;
}
p = skipwhite(p);
double x = 0.0;
if (p2<0)
return false;
if (p2<=p)
{
error("scale() expected 'x' value");
return false;
}
if (get(p) == ',')
{
p++;
p = skipwhite(p);
}
double y = 0.0;
if (p2<0)
return false;
if (p2<=p) //no y specified. use default
y = x; // y is same as x. uniform scaling
if (get(p++) != ')')
{
error("scale() needs closing ')'");
return false;
}
//printf("scale: %f %f\n", x, y);
}
//######### ROTATE
else if (name == "rotate")
{
p = skipwhite(p);
if (get(p++) != '(')
{
error("rotate transform needs opening '('");
return false;
}
p = skipwhite(p);
double angle = 0.0;
if (p2<0)
return false;
if (p2<=p)
{
error("rotate() expected 'angle' value");
return false;
}
if (get(p) == ',')
{
p++;
p = skipwhite(p);
}
double cx = 0.0;
double cy = 0.0;
if (p2>p)
{
if (get(p) == ',')
{
p++;
p = skipwhite(p);
}
if (p2<0)
return false;
if (p2<=p)
{
error("rotate() arguments should be either rotate(angle) or rotate(angle, cx, cy)");
return false;
}
}
if (get(p++) != ')')
{
error("rotate() needs closing ')'");
return false;
}
//printf("rotate: %f %f %f\n", angle, cx, cy);
}
//######### SKEWX
else if (name == "skewX")
{
p = skipwhite(p);
if (get(p++) != '(')
{
error("skewX transform needs opening '('");
return false;
}
p = skipwhite(p);
double x = 0.0;
if (p2<0)
return false;
if (p2<=p)
{
error("skewX() expected 'x' value");
return false;
}
if (get(p++) != ')')
{
error("skewX() needs closing ')'");
return false;
}
//printf("skewX: %f\n", x);
}
//######### SKEWY
else if (name == "skewY")
{
p = skipwhite(p);
if (get(p++) != '(')
{
error("skewY transform needs opening '('");
return false;
}
p = skipwhite(p);
double y = 0.0;
if (p2<0)
return false;
if (p2<=p)
{
error("skewY() expected 'y' value");
return false;
}
if (get(p++) != ')')
{
error("skewY() needs closing ')'");
return false;
}
//printf("skewY: %f\n", y);
}
//### NONE OF THE ABOVE
else
{
}
p = skipwhite(p);
if (ch == ',')
{
p++;
p = skipwhite(p);
}
}//WHILE p<parselen
return true;
}
/**
*
*/
{
if (!parent || !sourceElem)
{
error("NULL source element");
return false;
}
//printf("namespaceURI:%s\n", namespaceURI.c_str());
if (namespaceURI != SVG_NAMESPACE)
{
newElement = new SVGSVGElementImpl();
}
else //## SVG!!
{
//####################################################
//## ATTRIBUTES
//####################################################
{
//printf("CSS:%s\n", style.c_str());
{
error("parsing style attribute");
}
else
{
//printf("##parsed!\n");
}
}
{
if (!parseTransform(transform))
{
error("parsing transform attribute");
}
else
{
//printf("##parsed!\n");
}
}
//####################################################
//## ELEMENT - SPECIFIC
//####################################################
if (tagName == "svg")
{
newElement = new SVGSVGElementImpl();
}
else if (tagName == "title")
{
newElement = new SVGTitleElementImpl();
}
else if (tagName == "desc")
{
newElement = new SVGDescElementImpl();
}
else if (tagName == "defs")
{
newElement = new SVGDefsElementImpl();
}
else if (tagName == "style")
{
newElement = new SVGStyleElementImpl();
}
else if (tagName == "g")
{
newElement = new SVGGElementImpl();
}
else if (tagName == "path")
{
newElement = new SVGPathElementImpl();
}
}
for (int i=0 ; i<nodeCount ; i++)
{
{
}
{
}
{
//ElementImplPtr childElement = dynamic_cast<ElementImpl *>(child.get());
//parseElement(newElement, childElement);
}
}
return true;
}
/**
*
*/
{
if (!src)
{
error("NULL source document");
return NULL;
}
{
return NULL;
}
return doc;
}
} //namespace svg
} //namespace dom
} //namespace w3c
} //namespace org
/*#########################################################################
## E N D O F F I L E
#########################################################################*/