Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New source hierarchy.

  • Loading branch information...
commit 1b915c1d19d098a0adb336b7aae43ed33ff90972 1 parent 66597dd
@agambier authored
View
7 include/svg.h
@@ -45,9 +45,10 @@ typedef struct _svgItem {
union {
svgTitle tTitle; /* tKind==SVG_ITEM_KIND_TITLE */
- svgDesc tDesc; /* tKind==SVG_ITEM_KIND_DESC */
- svgLine tLine; /* tKind==SVG_ITEM_KIND_LINE */
- svgRect tRect; /* tKind==SVG_ITEM_KIND_RECT */
+ svgDesc tDesc; /* tKind==SVG_ITEM_KIND_DESC */
+ svgLine tLine; /* tKind==SVG_ITEM_KIND_LINE */
+ svgRect tRect; /* tKind==SVG_ITEM_KIND_RECT */
+ svgCircle tCircle; /* tKind==SVG_ITEM_KIND_CIRCLE */
} tObject ;
} svgItem ;
View
38 include/svg_parser.h
@@ -0,0 +1,38 @@
+#ifndef __svg_parser_h__
+#define __svg_parser_h__
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include "svg_types.h"
+#include "svg.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define SVG_TAG_GROUP "g"
+#define SVG_TAG_PATH "path"
+#define SVG_TAG_RECT "rect"
+#define SVG_TAG_CIRCLE "circle"
+#define SVG_TAG_ELLIPSE "ellipse"
+#define SVG_TAG_LINE "line"
+#define SVG_TAG_POLYLINE "polyline"
+#define SVG_TAG_POLYGON "polygon"
+#define SVG_TAG_TITLE "title"
+#define SVG_TAG_DESC "desc"
+
+svgItem* svgParseTitle( xmlNodePtr ptXmlNode );
+svgItem* svgParseDesc( xmlNodePtr ptXmlNode );
+svgItem* svgParseGroup( xmlNodePtr ptXmlNode );
+svgItem* svgParsePath( xmlNodePtr ptXmlNode );
+svgItem* svgParseRect( xmlNodePtr ptXmlNode );
+svgItem* svgParseLine( xmlNodePtr ptXmlNode );
+svgItem* svgParseLine( xmlNodePtr ptXmlNode );
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // __svg_parser_h__
View
11 include/svg_types.h
@@ -55,16 +55,19 @@ typedef svgLength svgCoordinate;
// ----- SVG Objects -----
// -- Title --
+// (http://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#DescriptionAndTitleElements)
typedef struct _svgTitle {
char *szText;
} svgTitle ;
// -- Description --
+// (http://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#DescriptionAndTitleElements)
typedef struct _svgDesc {
char *szText;
} svgDesc ;
// -- Line --
+// (http://www.w3.org/TR/2011/REC-SVG11-20110816/shapes.html#LineElement)
typedef struct _svgLine {
svgCoordinate tX1;
svgCoordinate tY1;
@@ -73,6 +76,7 @@ typedef struct _svgLine {
} svgLine ;
// -- Rect --
+// (http://www.w3.org/TR/2011/REC-SVG11-20110816/shapes.html#RectElement)
typedef struct _svgRect {
svgCoordinate tX;
svgCoordinate tY;
@@ -82,6 +86,13 @@ typedef struct _svgRect {
svgLength tRadiusY;
} svgRect ;
+// -- Circle --
+// (http://www.w3.org/TR/2011/REC-SVG11-20110816/shapes.html#CircleElement)
+typedef struct _svgCircle {
+ svgCoordinate tX;
+ svgCoordinate tY;
+ svgLength tRadius;
+} svgCircle ;
#ifdef __cplusplus
}
View
21 include/svg_xml.h
@@ -0,0 +1,21 @@
+#ifndef __svg_xml_h__
+#define __svg_xml_h__
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+xmlNodePtr GetChild( xmlNodePtr ptXmlNode, xmlElementType tType, char *szChildName );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // __svg_xml_h__
View
216 sources/svg.c
@@ -4,221 +4,7 @@
#include <libxml/tree.h>
#include <unistd.h>
#include "svg.h"
-
-#define SVG_TAG_GROUP "g"
-#define SVG_TAG_PATH "path"
-#define SVG_TAG_RECT "rect"
-#define SVG_TAG_CIRCLE "circle"
-#define SVG_TAG_ELLIPSE "ellipse"
-#define SVG_TAG_LINE "line"
-#define SVG_TAG_POLYLINE "polyline"
-#define SVG_TAG_POLYGON "polygon"
-#define SVG_TAG_TITLE "title"
-#define SVG_TAG_DESC "desc"
-
-
-xmlNodePtr GetChild( xmlNodePtr ptXmlNode, xmlElementType tType, char *szChildName )
-{
- xmlNodePtr ptXmlChild;
-
- if( ptXmlNode==NULL || szChildName==NULL )
- return NULL;
-
- ptXmlChild = ptXmlNode->children;
- while( ptXmlChild!=NULL )
- {
- if( ptXmlChild->type==tType && strcmp( ( char* )ptXmlChild->name, szChildName )==0 )
- break;
- }
-
- return ptXmlChild;
-}
-
-svgItem* svgNewItem( xmlNodePtr ptXmlNode )
-{
- svgItem *ptItem = NULL;
- char *szValue;
-
- if( ptXmlNode==NULL )
- return NULL;
-
- ptItem = ( svgItem* )malloc( sizeof( *ptItem ) );
- if( ptItem==NULL )
- {
- svgSetLastError( SVG_ERR_NOT_ENOUGH_RAM, "Not enough RAM to create SVG drawing." );
- return NULL;
- }
- memset( ptItem, 0, sizeof( *ptItem ) );
-
- // ID
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"id" ) )!=NULL )
- ptItem->szId = strdup( szValue );
-
- return ptItem;
-}
-
-svgItem* svgParseTitle( xmlNodePtr ptXmlNode )
-{
- svgItem *ptItem = NULL;
- xmlNodePtr ptXmlValue;
-
- if( ptXmlNode==NULL )
- return NULL;
- if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_TITLE )!=0 )
- return NULL;
-
- // Read common values to all kind of item
- ptItem = svgNewItem( ptXmlNode );
- if( ptItem==NULL )
- return NULL;
-
- ptItem->tKind = SVG_ITEM_KIND_TITLE;
-
- if( ( ptXmlValue = GetChild( ptXmlNode, XML_TEXT_NODE, "text" ) )!=NULL ) {
- if( ptXmlValue->content!=NULL )
- ptItem->tObject.tTitle.szText = strdup( ( char* )ptXmlValue->content );
- }
-
- return ptItem;
-}
-
-svgItem* svgParseDesc( xmlNodePtr ptXmlNode )
-{
- svgItem *ptItem = NULL;
- xmlNodePtr ptXmlValue;
-
- if( ptXmlNode==NULL )
- return NULL;
- if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_DESC )!=0 )
- return NULL;
-
- // Read common values to all kind of item
- ptItem = svgNewItem( ptXmlNode );
- if( ptItem==NULL )
- return NULL;
-
- ptItem->tKind = SVG_ITEM_KIND_DESC;
-
- if( ( ptXmlValue = GetChild( ptXmlNode, XML_TEXT_NODE, "text" ) )!=NULL ) {
- if( ptXmlValue->content!=NULL )
- ptItem->tObject.tTitle.szText = strdup( ( char* )ptXmlValue->content );
- }
-
- return ptItem;
-}
-
-svgItem* svgParseGroup( xmlNodePtr ptXmlNode )
-{
- svgItem *ptItem = NULL;
- char *szValue;
-
- if( ptXmlNode==NULL )
- return NULL;
- if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_GROUP )!=0 )
- return NULL;
-
- // Read common values to all kind of item
- ptItem = svgNewItem( ptXmlNode );
- if( ptItem==NULL )
- return NULL;
-
- ptItem->tKind = SVG_ITEM_KIND_GROUP;
-
- return ptItem;
-}
-
-svgItem* svgParsePath( xmlNodePtr ptXmlNode )
-{
- svgItem *ptItem = NULL;
- char *szValue;
-
- if( ptXmlNode==NULL )
- return NULL;
- if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_PATH )!=0 )
- return NULL;
-
- // Read common values to all kind of item
- ptItem = svgNewItem( ptXmlNode );
- if( ptItem==NULL )
- return NULL;
-
- ptItem->tKind = SVG_ITEM_KIND_PATH;
-
- return ptItem;
-}
-
-svgItem* svgParseRect( xmlNodePtr ptXmlNode )
-{
- svgItem *ptItem = NULL;
- char *szValue;
-
- if( ptXmlNode==NULL )
- return NULL;
- if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_RECT )!=0 )
- return NULL;
-
- // Read common values to all kind of item
- ptItem = svgNewItem( ptXmlNode );
- if( ptItem==NULL )
- return NULL;
-
- ptItem->tKind = SVG_ITEM_KIND_RECT;
-
- // x
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x" ) )!=NULL )
- svgStringToCoordinate( szValue, &ptItem->tObject.tRect.tX );
- // y
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y" ) )!=NULL )
- svgStringToCoordinate( szValue, &ptItem->tObject.tRect.tY );
- // width
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"width" ) )!=NULL )
- svgStringToLength( szValue, &ptItem->tObject.tRect.tWidth );
- // height
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"height" ) )!=NULL )
- svgStringToLength( szValue, &ptItem->tObject.tRect.tHeight );
- // rx
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"rx" ) )!=NULL )
- svgStringToLength( szValue, &ptItem->tObject.tRect.tRadiusX );
- // ry
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"ry" ) )!=NULL )
- svgStringToLength( szValue, &ptItem->tObject.tRect.tRadiusY );
-
- return ptItem;
-}
-
-svgItem* svgParseLine( xmlNodePtr ptXmlNode )
-{
- svgItem *ptItem = NULL;
- char *szValue;
-
- if( ptXmlNode==NULL )
- return NULL;
- if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_LINE )!=0 )
- return NULL;
-
- // Read common values to all kind of item
- ptItem = svgNewItem( ptXmlNode );
- if( ptItem==NULL )
- return NULL;
-
- ptItem->tKind = SVG_ITEM_KIND_LINE;
-
- // x1
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x1" ) )!=NULL )
- svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tX1 );
- // Y1
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y1" ) )!=NULL )
- svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tY1 );
- // X2
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x2" ) )!=NULL )
- svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tX2 );
- // Y2
- if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y2" ) )!=NULL )
- svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tY2 );
-
-
- return ptItem;
-}
+#include "svg_parser.h"
svgDrawing* svgParseFile( const char *szFile )
{
View
229 sources/svg_parser.c
@@ -0,0 +1,229 @@
+#include <stdio.h>
+#include <string.h>
+#include "svg_parser.h"
+#include "svg_xml.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+svgItem* svgNewItem( xmlNodePtr ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ char *szValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+
+ ptItem = ( svgItem* )malloc( sizeof( *ptItem ) );
+ if( ptItem==NULL )
+ {
+ svgSetLastError( SVG_ERR_NOT_ENOUGH_RAM, "Not enough RAM to create SVG drawing." );
+ return NULL;
+ }
+ memset( ptItem, 0, sizeof( *ptItem ) );
+
+ // ID
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"id" ) )!=NULL )
+ ptItem->szId = strdup( szValue );
+
+ return ptItem;
+}
+
+svgItem* svgParseTitle( xmlNode * ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ xmlNodePtr ptXmlValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+ if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_TITLE )!=0 )
+ return NULL;
+
+ // Read common values to all kind of item
+ ptItem = svgNewItem( ptXmlNode );
+ if( ptItem==NULL )
+ return NULL;
+
+ ptItem->tKind = SVG_ITEM_KIND_TITLE;
+
+ if( ( ptXmlValue = GetChild( ptXmlNode, XML_TEXT_NODE, "text" ) )!=NULL ) {
+ if( ptXmlValue->content!=NULL )
+ ptItem->tObject.tTitle.szText = strdup( ( char* )ptXmlValue->content );
+ }
+
+ return ptItem;
+}
+
+svgItem* svgParseDesc( xmlNodePtr ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ xmlNodePtr ptXmlValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+ if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_DESC )!=0 )
+ return NULL;
+
+ // Read common values to all kind of item
+ ptItem = svgNewItem( ptXmlNode );
+ if( ptItem==NULL )
+ return NULL;
+
+ ptItem->tKind = SVG_ITEM_KIND_DESC;
+
+ if( ( ptXmlValue = GetChild( ptXmlNode, XML_TEXT_NODE, "text" ) )!=NULL ) {
+ if( ptXmlValue->content!=NULL )
+ ptItem->tObject.tTitle.szText = strdup( ( char* )ptXmlValue->content );
+ }
+
+ return ptItem;
+}
+
+svgItem* svgParseGroup( xmlNodePtr ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ char *szValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+ if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_GROUP )!=0 )
+ return NULL;
+
+ // Read common values to all kind of item
+ ptItem = svgNewItem( ptXmlNode );
+ if( ptItem==NULL )
+ return NULL;
+
+ ptItem->tKind = SVG_ITEM_KIND_GROUP;
+
+ return ptItem;
+}
+
+svgItem* svgParsePath( xmlNodePtr ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ char *szValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+ if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_PATH )!=0 )
+ return NULL;
+
+ // Read common values to all kind of item
+ ptItem = svgNewItem( ptXmlNode );
+ if( ptItem==NULL )
+ return NULL;
+
+ ptItem->tKind = SVG_ITEM_KIND_PATH;
+
+ return ptItem;
+}
+
+svgItem* svgParseRect( xmlNodePtr ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ char *szValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+ if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_RECT )!=0 )
+ return NULL;
+
+ // Read common values to all kind of item
+ ptItem = svgNewItem( ptXmlNode );
+ if( ptItem==NULL )
+ return NULL;
+
+ ptItem->tKind = SVG_ITEM_KIND_RECT;
+
+ // x
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tRect.tX );
+ // y
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tRect.tY );
+ // width
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"width" ) )!=NULL )
+ svgStringToLength( szValue, &ptItem->tObject.tRect.tWidth );
+ // height
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"height" ) )!=NULL )
+ svgStringToLength( szValue, &ptItem->tObject.tRect.tHeight );
+ // rx
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"rx" ) )!=NULL )
+ svgStringToLength( szValue, &ptItem->tObject.tRect.tRadiusX );
+ // ry
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"ry" ) )!=NULL )
+ svgStringToLength( szValue, &ptItem->tObject.tRect.tRadiusY );
+
+ return ptItem;
+}
+
+svgItem* svgParseLine( xmlNodePtr ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ char *szValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+ if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_LINE )!=0 )
+ return NULL;
+
+ // Read common values to all kind of item
+ ptItem = svgNewItem( ptXmlNode );
+ if( ptItem==NULL )
+ return NULL;
+
+ ptItem->tKind = SVG_ITEM_KIND_LINE;
+
+ // x1
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x1" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tX1 );
+ // Y1
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y1" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tY1 );
+ // X2
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x2" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tX2 );
+ // Y2
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y2" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tY2 );
+
+
+ return ptItem;
+}
+
+svgItem* svgParseCircle( xmlNodePtr ptXmlNode )
+{
+ svgItem *ptItem = NULL;
+ char *szValue;
+
+ if( ptXmlNode==NULL )
+ return NULL;
+ if( strcmp( ( char* )ptXmlNode->name, SVG_TAG_CIRCLE )!=0 )
+ return NULL;
+
+ // Read common values to all kind of item
+ ptItem = svgNewItem( ptXmlNode );
+ if( ptItem==NULL )
+ return NULL;
+
+ ptItem->tKind = SVG_ITEM_KIND_LINE;
+
+ // x1
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x1" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tX1 );
+ // Y1
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y1" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tY1 );
+ // X2
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"x2" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tX2 );
+ // Y2
+ if( ( szValue = ( char* )xmlGetProp( ptXmlNode, ( xmlChar* )"y2" ) )!=NULL )
+ svgStringToCoordinate( szValue, &ptItem->tObject.tLine.tY2 );
+
+
+ return ptItem;
+}
View
20 sources/svg_xml.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <string.h>
+#include "svg_xml.h"
+
+xmlNodePtr GetChild( xmlNodePtr ptXmlNode, xmlElementType tType, char *szChildName )
+{
+ xmlNodePtr ptXmlChild;
+
+ if( ptXmlNode==NULL || szChildName==NULL )
+ return NULL;
+
+ ptXmlChild = ptXmlNode->children;
+ while( ptXmlChild!=NULL )
+ {
+ if( ptXmlChild->type==tType && strcmp( ( char* )ptXmlChild->name, szChildName )==0 )
+ break;
+ }
+
+ return ptXmlChild;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.