Parsing basic SVG, and try to generate PPM file to test result with the librairy agg
This commit is contained in:
parent
4446e2f750
commit
08289ff4fd
@ -15,9 +15,11 @@ LOCAL_EXPORT_LDLIBS :=
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||
-DSVG_DEBUG_LEVEL=3
|
||||
-DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\""
|
||||
else
|
||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||
-DSVG_DEBUG_LEVEL=1
|
||||
-DPARSER_SVG_VERSION_TAG_NAME="\"???-release\""
|
||||
endif
|
||||
|
||||
|
@ -4,6 +4,7 @@ FILE_LIST = parserSVG/Debug.cpp \
|
||||
parserSVG/Base.cpp \
|
||||
parserSVG/Circle.cpp \
|
||||
parserSVG/Ellipse.cpp \
|
||||
parserSVG/Group.cpp \
|
||||
parserSVG/Line.cpp \
|
||||
parserSVG/parserSVG.cpp \
|
||||
parserSVG/Path.cpp \
|
||||
|
@ -23,3 +23,292 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Base.h>
|
||||
#include <math.h>
|
||||
|
||||
svg::Base::Base(paintState_ts parentPaintState)
|
||||
{
|
||||
// copy the parent painting properties ...
|
||||
m_paint = parentPaintState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse the transform balise C String.
|
||||
* @param[in] inputString String data inside the transform attribute
|
||||
* @param[in,out] baseMatrice matrice that must be update
|
||||
* @return ---
|
||||
*/
|
||||
void svg::Base::ParseTransform(TiXmlNode *node)
|
||||
{
|
||||
SVG_CHECK_INOUT(node);
|
||||
const char * inputString = (char*)node->ToElement()->Attribute("transform");
|
||||
if (NULL == inputString) {
|
||||
return;
|
||||
}
|
||||
char tmpData[2048];
|
||||
for (int32_t iii=0; inputString[iii]=='\0' && iii<2047; iii++) {
|
||||
if (inputString[iii] == ',') {
|
||||
tmpData[iii] = ' ';
|
||||
} else {
|
||||
tmpData[iii] = inputString[iii];
|
||||
}
|
||||
// end of the string ...
|
||||
tmpData[iii+1] = '\0';
|
||||
}
|
||||
etkFloat_t base[6];
|
||||
etkFloat_t zzz[6];
|
||||
etkFloat_t angle, xxx, yyy;
|
||||
int32_t n;
|
||||
char * pointerOnData = tmpData;
|
||||
while (*pointerOnData) {
|
||||
base[0] = 1.0;
|
||||
base[1] = 0.0;
|
||||
base[2] = 0.0;
|
||||
base[3] = 1.0;
|
||||
base[4] = 0.0;
|
||||
base[5] = 0.0;
|
||||
if (sscanf(pointerOnData, "matrix (%f %f %f %f %f %f) %n", &base[0], &base[1], &base[2], &base[3], &base[4], &base[5], &n) == 6) {
|
||||
// nothing to do ...
|
||||
} else if (sscanf(pointerOnData, "translate (%f %f) %n", &base[4], &base[5], &n) == 2) {
|
||||
// nothing to do ...
|
||||
} else if (sscanf(pointerOnData, "translate (%f) %n", &base[4], &n) == 1) {
|
||||
// nothing to do ...
|
||||
} else if (sscanf(pointerOnData, "scale (%f %f) %n", &base[0], &base[3], &n) == 2) {
|
||||
// nothing to do ...
|
||||
} else if (sscanf(pointerOnData, "scale (%f) %n", &base[0], &n) == 1) {
|
||||
base[3] = base[0];
|
||||
} else if (sscanf(pointerOnData, "rotate (%f %f %f) %n", &angle, &xxx, &yyy, &n) == 3) {
|
||||
angle = angle / 180 * M_PI;
|
||||
base[0] = cos(angle);
|
||||
base[1] = sin(angle);
|
||||
base[2] = -sin(angle);
|
||||
base[3] = cos(angle);
|
||||
base[4] = -xxx * cos(angle) + yyy * sin(angle) + xxx;
|
||||
base[5] = -xxx * sin(angle) - yyy * cos(angle) + yyy;
|
||||
} else if (sscanf(pointerOnData, "rotate (%f) %n", &angle, &n) == 1) {
|
||||
angle = angle / 180 * M_PI;
|
||||
base[0] = cos(angle);
|
||||
base[1] = sin(angle);
|
||||
base[2] = -sin(angle);
|
||||
base[3] = cos(angle);
|
||||
} else if (sscanf(pointerOnData, "skewX (%f) %n", &angle, &n) == 1) {
|
||||
angle = angle / 180 * M_PI;
|
||||
base[2] = tan(angle);
|
||||
} else if (sscanf(pointerOnData, "skewY (%f) %n", &angle, &n) == 1) {
|
||||
angle = angle / 180 * M_PI;
|
||||
base[1] = tan(angle);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
zzz[0] = m_paint.matrix[0]*base[0] + m_paint.matrix[2]*base[1];
|
||||
zzz[1] = m_paint.matrix[1]*base[0] + m_paint.matrix[3]*base[1];
|
||||
zzz[2] = m_paint.matrix[0]*base[2] + m_paint.matrix[2]*base[3];
|
||||
zzz[3] = m_paint.matrix[1]*base[2] + m_paint.matrix[3]*base[3];
|
||||
zzz[4] = m_paint.matrix[0]*base[4] + m_paint.matrix[2]*base[5] + m_paint.matrix[4];
|
||||
zzz[5] = m_paint.matrix[1]*base[4] + m_paint.matrix[3]*base[5] + m_paint.matrix[5];
|
||||
memcpy(m_paint.matrix, zzz, sizeof(etkFloat_t) * 6 );
|
||||
pointerOnData += n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parse x, y, width, height attribute of the xml node
|
||||
* @param[in] node XML node
|
||||
* @param[out] pos parsed position
|
||||
* @param[out] size parsed dimention
|
||||
* @return ---
|
||||
*/
|
||||
void svg::Base::ParsePosition(const TiXmlNode *node, coord2D_ts &pos, coord2D_ts &size)
|
||||
{
|
||||
pos.x = 0;
|
||||
pos.y = 0;
|
||||
size.x = m_paint.viewPort.x;
|
||||
size.y = m_paint.viewPort.y;
|
||||
|
||||
const char * content = node->ToElement()->Attribute("x");
|
||||
if (NULL != content) {
|
||||
pos.x = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("y");
|
||||
if (NULL != content) {
|
||||
pos.y = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("width");
|
||||
if (NULL != content) {
|
||||
size.x = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("height");
|
||||
if (NULL != content) {
|
||||
size.y = ParseLength(content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parse a lenght of the xml element
|
||||
* @param[in] dataInput Data C String with the printed lenght
|
||||
* @return standart number of pixels
|
||||
*/
|
||||
etkFloat_t svg::Base::ParseLength(const char *dataInput)
|
||||
{
|
||||
int32_t numLength = strspn(dataInput, "0123456789+-.");
|
||||
const char *unit = dataInput + numLength;
|
||||
etkFloat_t n = atof(dataInput);
|
||||
etkFloat_t font_size = 20.0;
|
||||
|
||||
if (unit[0] == '\0') {
|
||||
return n;
|
||||
} else if (unit[0] == '%') { // xxx %
|
||||
return n / 100.0 * m_paint.viewPort.x;
|
||||
} else if (unit[0] == 'e' && unit[1] == 'm') { // xxx em
|
||||
return n * font_size;
|
||||
} else if (unit[0] == 'e' && unit[1] == 'x') { // xxx ex
|
||||
return n / 2.0 * font_size;
|
||||
} else if (unit[0] == 'p' && unit[1] == 'x') { // xxx px
|
||||
return n;
|
||||
} else if (unit[0] == 'p' && unit[1] == 't') { // xxx pt
|
||||
return n * 1.25;
|
||||
} else if (unit[0] == 'p' && unit[1] == 'c') { // xxx pc
|
||||
return n * 15.0;
|
||||
} else if (unit[0] == 'm' && unit[1] == 'm') { // xxx mm
|
||||
return n * 3.543307;
|
||||
} else if (unit[0] == 'c' && unit[1] == 'm') { // xxx cm
|
||||
return n * 35.43307;
|
||||
} else if (unit[0] == 'i' && unit[1] == 'n') { // xxx in
|
||||
return n * 90;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parse a Painting attribute of a specific node
|
||||
* @param[in] node : basic node of the XML that might be parsed
|
||||
* @return ---
|
||||
*/
|
||||
void svg::Base::ParsePaintAttr(const TiXmlNode *node)
|
||||
{
|
||||
const char * content = node->ToElement()->Attribute("fill");
|
||||
if (NULL != content) {
|
||||
m_paint.fill = ParseColor(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("stroke");
|
||||
if (NULL != content) {
|
||||
m_paint.stroke = ParseColor(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("stroke-width");
|
||||
if (NULL != content) {
|
||||
m_paint.strokeWidth = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("style");
|
||||
if (NULL != content) {
|
||||
const char *sss;
|
||||
if ((sss = strstr(content, "fill:"))) {
|
||||
sss += 5;
|
||||
while( sss[0] ==' '
|
||||
&& sss[0]!='\0' ) {
|
||||
sss++;
|
||||
}
|
||||
m_paint.fill = ParseColor(sss);
|
||||
}
|
||||
if ((sss = strstr(content, "stroke:"))) {
|
||||
sss += 7;
|
||||
while( sss[0] ==' '
|
||||
&& sss[0]!='\0' ) {
|
||||
sss++;
|
||||
}
|
||||
m_paint.stroke = ParseColor(sss);
|
||||
}
|
||||
if ((sss = strstr(content, "stroke-width:"))) {
|
||||
sss += 13;
|
||||
while( sss[0] ==' '
|
||||
&& sss[0]!='\0' ) {
|
||||
sss++;
|
||||
}
|
||||
m_paint.strokeWidth = ParseLength(sss);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse a color specification from the svg file
|
||||
* @param[in] inputData Data C String with the xml definition
|
||||
* @return the parsed color
|
||||
*/
|
||||
color_ts svg::Base::ParseColor(const char *inputData)
|
||||
{
|
||||
color_ts localColor;
|
||||
localColor.red =1.0;
|
||||
localColor.green=1.0;
|
||||
localColor.blue =1.0;
|
||||
localColor.alpha=1.0;
|
||||
|
||||
uint32_t red, green, blue;
|
||||
size_t len = strlen(inputData);
|
||||
|
||||
if( len == 4
|
||||
&& inputData[0] == '#') {
|
||||
if (sscanf(inputData + 1, "%1x%1x%1x", &red, &green, &blue) == 3) {
|
||||
localColor.red = (etkFloat_t)(red | red << 4) / 256.0;
|
||||
localColor.green= (etkFloat_t)(green | green << 4) / 256.0;
|
||||
localColor.blue = (etkFloat_t)(blue | blue << 4) / 256.0;
|
||||
}
|
||||
} else if( len == 7
|
||||
&& inputData[0] == '#') {
|
||||
if (sscanf(inputData + 1, "%2x%2x%2x", &red, &green, &blue) == 3) {
|
||||
localColor.red = (etkFloat_t)(red) / 256.0;
|
||||
localColor.green= (etkFloat_t)(green) / 256.0;
|
||||
localColor.blue = (etkFloat_t)(blue) / 256.0;
|
||||
}
|
||||
} else if( 10 <= len
|
||||
&& inputData[0] == 'r'
|
||||
&& inputData[1] == 'g'
|
||||
&& inputData[2] == 'b'
|
||||
&& inputData[3] == '('
|
||||
&& inputData[len - 1] == ')') {
|
||||
if (sscanf(inputData + 4, "%u,%u,%u", &red, &green, &blue) == 3) {
|
||||
localColor.red = (etkFloat_t)(red) / 256.0;
|
||||
localColor.green= (etkFloat_t)(green) / 256.0;
|
||||
localColor.blue = (etkFloat_t)(blue) / 256.0;
|
||||
} else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%", &localColor.red, &localColor.green, &localColor.blue) == 3) {
|
||||
// nothing to do ...
|
||||
}
|
||||
} else if( len == 4
|
||||
&& strcmp(inputData, "none") == 0) {
|
||||
localColor.alpha=0.0;
|
||||
} else if( 5 < len
|
||||
&& inputData[0] == 'u'
|
||||
&& inputData[1] == 'r'
|
||||
&& inputData[2] == 'l'
|
||||
&& inputData[3] == '(') {
|
||||
if (inputData[4] == '#') {
|
||||
// TODO : parse gradient ...
|
||||
}
|
||||
} else {
|
||||
// TODO : Might be a named color ... need to find it ...
|
||||
}
|
||||
return localColor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parse all the element needed in the basic node
|
||||
* @param[in] node standart XML node
|
||||
* @return true if no problem arrived
|
||||
*/
|
||||
bool svg::Base::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const char * svg::Base::SpacingDist(int32_t spacing)
|
||||
{
|
||||
static const char *tmpValue = " ";
|
||||
if (spacing>20) {
|
||||
spacing = 20;
|
||||
}
|
||||
return tmpValue + 20*4 - spacing*4;
|
||||
}
|
@ -26,20 +26,51 @@
|
||||
#define __SVG_BASE_H__
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/VectorType.h>
|
||||
|
||||
#include <tinyXML/tinyxml.h>
|
||||
|
||||
#include <agg-2.4/agg_basics.h>
|
||||
#include <agg-2.4/agg_rendering_buffer.h>
|
||||
#include <agg-2.4/agg_rasterizer_scanline_aa.h>
|
||||
#include <agg-2.4/agg_scanline_p.h>
|
||||
#include <agg-2.4/agg_renderer_scanline.h>
|
||||
#include <agg-2.4/agg_path_storage.h>
|
||||
#include <agg-2.4/agg_conv_transform.h>
|
||||
#include <agg-2.4/agg_bounding_rect.h>
|
||||
#include <agg-2.4/agg_color_rgba.h>
|
||||
#include <agg-2.4/agg_pixfmt_rgba.h>
|
||||
|
||||
namespace svg
|
||||
{
|
||||
#define MATRIX_SIZE (6)
|
||||
typedef struct {
|
||||
color_ts fill;
|
||||
color_ts stroke;
|
||||
etkFloat_t strokeWidth;
|
||||
coord2D_ts viewPort;
|
||||
etkFloat_t matrix[MATRIX_SIZE];
|
||||
} paintState_ts;
|
||||
|
||||
class Base
|
||||
{
|
||||
protected:
|
||||
color_ts m_fill;
|
||||
color_ts m_stroke;
|
||||
color_ts m_strokeWidth;
|
||||
paintState_ts m_paint;
|
||||
const char * SpacingDist(int32_t spacing);
|
||||
public:
|
||||
Base(void) { };
|
||||
Base(void) {};
|
||||
Base(paintState_ts parentPaintState);
|
||||
~Base(void) { };
|
||||
virtual bool Parse(TiXmlNode * node) = 0;
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
//specific drawing for AAG librairy ...
|
||||
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx) { };
|
||||
|
||||
virtual void Display(int32_t spacing) { };
|
||||
void ParseTransform(TiXmlNode *node);
|
||||
void ParsePosition(const TiXmlNode *node, coord2D_ts &pos, coord2D_ts &size);
|
||||
etkFloat_t ParseLength(const char *dataInput);
|
||||
void ParsePaintAttr(const TiXmlNode *node);
|
||||
color_ts ParseColor(const char *inputData);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Circle.h>
|
||||
|
||||
svg::Circle::Circle(void)
|
||||
svg::Circle::Circle(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
}
|
||||
@ -37,6 +37,40 @@ svg::Circle::~Circle(void)
|
||||
|
||||
bool svg::Circle::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
m_radius = 0.0;
|
||||
m_position.x = 0.0;
|
||||
m_position.y = 0.0;
|
||||
ParseTransform(node);
|
||||
ParsePaintAttr(node);
|
||||
|
||||
const char * content = node->ToElement()->Attribute("cx");
|
||||
if (NULL != content) {
|
||||
m_position.x = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("cy");
|
||||
if (NULL != content) {
|
||||
m_position.y = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("r");
|
||||
if (NULL != content) {
|
||||
m_radius = ParseLength(content);
|
||||
} else {
|
||||
SVG_ERROR("(l "<<node->Row()<<") Circle \"r\" is not present");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 > m_radius) {
|
||||
m_radius = 0;
|
||||
SVG_ERROR("(l "<<node->Row()<<") Circle \"r\" is negative");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void svg::Circle::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Circle " << m_position << " radius=" << m_radius);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -32,12 +32,13 @@ namespace svg
|
||||
class Circle : public svg::Base
|
||||
{
|
||||
private:
|
||||
coord2D_ts m_position; //!< position of the Circle
|
||||
etkFloat_t m_ratio; //!< Ratio of the Circle
|
||||
coord2D_ts m_position; //!< Position of the Circle
|
||||
etkFloat_t m_radius; //!< Radius of the Circle
|
||||
public:
|
||||
Circle(void);
|
||||
Circle(paintState_ts parentPaintState);
|
||||
~Circle(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -24,4 +24,4 @@
|
||||
|
||||
#include <parserSVG/Debug.h>
|
||||
|
||||
const char * parserSVGLibName = "tinySVG ";
|
||||
const char * parserSVGLibName = "parserSVG ";
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Ellipse.h>
|
||||
|
||||
svg::Ellipse::Ellipse(void)
|
||||
svg::Ellipse::Ellipse(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
}
|
||||
@ -37,5 +37,42 @@ svg::Ellipse::~Ellipse(void)
|
||||
|
||||
bool svg::Ellipse::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
ParseTransform(node);
|
||||
ParsePaintAttr(node);
|
||||
m_c.x = 0.0;
|
||||
m_c.y = 0.0;
|
||||
m_r.x = 0.0;
|
||||
m_r.y = 0.0;
|
||||
|
||||
const char * content = node->ToElement()->Attribute("cx");
|
||||
if (NULL != content) {
|
||||
m_c.x = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("cy");
|
||||
if (NULL != content) {
|
||||
m_c.y = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("rx");
|
||||
if (NULL != content) {
|
||||
m_r.x = ParseLength(content);
|
||||
} else {
|
||||
SVG_ERROR("(l "<<node->Row()<<") Ellipse \"rx\" is not present");
|
||||
return false;
|
||||
}
|
||||
content = node->ToElement()->Attribute("ry");
|
||||
if (NULL != content) {
|
||||
m_r.y = ParseLength(content);
|
||||
} else {
|
||||
SVG_ERROR("(l "<<node->Row()<<") Ellipse \"ry\" is not present");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void svg::Ellipse::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Ellipse c=" << m_c << " r=" << m_r);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,9 +35,10 @@ namespace svg
|
||||
coord2D_ts m_c; //!< C property of the ellipse
|
||||
coord2D_ts m_r; //!< R property of the ellipse
|
||||
public:
|
||||
Ellipse(void);
|
||||
Ellipse(paintState_ts parentPaintState);
|
||||
~Ellipse(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
};
|
||||
};
|
||||
|
||||
|
134
Sources/libparsersvg/parserSVG/Group.cpp
Normal file
134
Sources/libparsersvg/parserSVG/Group.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file parserSVG/Group.cpp
|
||||
* @brief Basic Group parsing (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 21/03/2012
|
||||
* @par Project
|
||||
* parserSVG
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Group.h>
|
||||
#include <etk/UString.h>
|
||||
#include <parserSVG/Base.h>
|
||||
#include <parserSVG/Circle.h>
|
||||
#include <parserSVG/Ellipse.h>
|
||||
#include <parserSVG/Line.h>
|
||||
#include <parserSVG/Path.h>
|
||||
#include <parserSVG/Polygon.h>
|
||||
#include <parserSVG/Polyline.h>
|
||||
#include <parserSVG/Rectangle.h>
|
||||
#include <parserSVG/Text.h>
|
||||
#include <parserSVG/Group.h>
|
||||
|
||||
svg::Group::Group(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
svg::Group::~Group(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool svg::Group::Parse(TiXmlNode * node)
|
||||
{
|
||||
// parse ...
|
||||
coord2D_ts pos;
|
||||
coord2D_ts size;
|
||||
ParseTransform(node);
|
||||
ParsePosition(node, pos, size);
|
||||
ParsePaintAttr(node);
|
||||
|
||||
// parse all sub node :
|
||||
for(TiXmlNode * child = node->FirstChild(); NULL != child; child = child->NextSibling() ) {
|
||||
svg::Base *elementParser = NULL;
|
||||
if (child->Type()==TiXmlNode::TINYXML_COMMENT) {
|
||||
// nothing to do, just proceed to next step
|
||||
} else {
|
||||
etk::UString localValue = child->Value();
|
||||
if (localValue == "g") {
|
||||
elementParser = new svg::Group(m_paint);
|
||||
} else if (localValue == "a") {
|
||||
// TODO ...
|
||||
} else if (localValue == "path") {
|
||||
elementParser = new svg::Path(m_paint);
|
||||
} else if (localValue == "rect") {
|
||||
elementParser = new svg::Rectangle(m_paint);
|
||||
} else if (localValue == "circle") {
|
||||
elementParser = new svg::Circle(m_paint);
|
||||
} else if (localValue == "ellipse") {
|
||||
elementParser = new svg::Ellipse(m_paint);
|
||||
} else if (localValue == "line") {
|
||||
elementParser = new svg::Line(m_paint);
|
||||
} else if (localValue == "polyline") {
|
||||
elementParser = new svg::Polyline(m_paint);
|
||||
} else if (localValue == "polygon") {
|
||||
elementParser = new svg::Polygon(m_paint);
|
||||
} else if (localValue == "text") {
|
||||
elementParser = new svg::Text(m_paint);
|
||||
} else {
|
||||
SVG_ERROR("(l "<<child->Row()<<") node not suported : \""<<localValue<<"\" must be [g,a,path,rect,circle,ellipse,line,polyline,polygon,text]");
|
||||
}
|
||||
if (NULL == elementParser) {
|
||||
SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" allocation error or not supported ...");
|
||||
} else {
|
||||
if (false == elementParser->Parse(child)) {
|
||||
SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" Sub Parsing ERROR");
|
||||
delete(elementParser);
|
||||
elementParser = NULL;
|
||||
} else {
|
||||
// add element in the system
|
||||
m_subElementList.PushBack(elementParser);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void svg::Group::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Group (START)");
|
||||
for (int32_t iii=0; iii<m_subElementList.Size(); iii++) {
|
||||
if (NULL != m_subElementList[iii]) {
|
||||
m_subElementList[iii]->Display(spacing+1);
|
||||
}
|
||||
}
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Group (STOP)");
|
||||
}
|
||||
|
||||
void svg::Group::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx)
|
||||
{
|
||||
uint32_t tmpColor = 0;
|
||||
tmpColor = ((int32_t)(m_paint.fill.red*256.))<<24;
|
||||
tmpColor += ((int32_t)(m_paint.fill.green*256.))<<16;
|
||||
tmpColor += ((int32_t)(m_paint.fill.blue*256.))<<8;
|
||||
tmpColor += ((int32_t)(m_paint.fill.alpha*256.));
|
||||
// New color. Every new color creates new path in the path object.
|
||||
colors.PushBack(agg::rgb8_packed(tmpColor));
|
||||
uint32_t tmpPathNew = path.start_new_path();
|
||||
pathIdx.PushBack(tmpPathNew);
|
||||
for (int32_t iii=0; iii<m_subElementList.Size(); iii++) {
|
||||
if (NULL != m_subElementList[iii]) {
|
||||
m_subElementList[iii]->AggDraw(path, colors, pathIdx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
47
Sources/libparsersvg/parserSVG/Group.h
Normal file
47
Sources/libparsersvg/parserSVG/Group.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file parserSVG/Group.h
|
||||
* @brief basic group parsing (Header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 21/03/2012
|
||||
* @par Project
|
||||
* parserSVG
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __SVG_GROUP_H__
|
||||
#define __SVG_GROUP_H__
|
||||
|
||||
#include <parserSVG/Base.h>
|
||||
#include <etk/VectorType.h>
|
||||
|
||||
namespace svg
|
||||
{
|
||||
class Group : public svg::Base
|
||||
{
|
||||
private:
|
||||
etk::VectorType<svg::Base *> m_subElementList; //!< group sub elements ...
|
||||
public:
|
||||
Group(paintState_ts parentPaintState);
|
||||
~Group(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -25,9 +25,12 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Line.h>
|
||||
|
||||
svg::Line::Line(void)
|
||||
svg::Line::Line(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
m_startPos.x = 0.0;
|
||||
m_startPos.y = 0.0;
|
||||
m_stopPos.x = 0.0;
|
||||
m_stopPos.y = 0.0;
|
||||
}
|
||||
|
||||
svg::Line::~Line(void)
|
||||
@ -37,5 +40,30 @@ svg::Line::~Line(void)
|
||||
|
||||
bool svg::Line::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
ParseTransform(node);
|
||||
ParsePaintAttr(node);
|
||||
|
||||
const char * content = node->ToElement()->Attribute("x1");
|
||||
if (NULL != content) {
|
||||
m_startPos.x = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("y1");
|
||||
if (NULL != content) {
|
||||
m_startPos.y = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("x2");
|
||||
if (NULL != content) {
|
||||
m_stopPos.x = ParseLength(content);
|
||||
}
|
||||
content = node->ToElement()->Attribute("y2");
|
||||
if (NULL != content) {
|
||||
m_stopPos.y = ParseLength(content);
|
||||
}
|
||||
}
|
||||
|
||||
void svg::Line::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Line " << m_startPos << " to " << m_stopPos);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,9 +35,10 @@ namespace svg
|
||||
coord2D_ts m_startPos; //!< Start line position
|
||||
coord2D_ts m_stopPos; //!< Stop line position
|
||||
public:
|
||||
Line(void);
|
||||
Line(paintState_ts parentPaintState);
|
||||
~Line(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Path.h>
|
||||
|
||||
svg::Path::Path(void)
|
||||
svg::Path::Path(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
}
|
||||
@ -37,5 +37,14 @@ svg::Path::~Path(void)
|
||||
|
||||
bool svg::Path::Parse(TiXmlNode * node)
|
||||
{
|
||||
ParseTransform(node);
|
||||
ParsePaintAttr(node);
|
||||
return false;
|
||||
}
|
||||
|
||||
void svg::Path::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Path");
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,9 +34,10 @@ namespace svg
|
||||
private:
|
||||
|
||||
public:
|
||||
Path(void);
|
||||
Path(paintState_ts parentPaintState);
|
||||
~Path(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Polygon.h>
|
||||
|
||||
svg::Polygon::Polygon(void)
|
||||
svg::Polygon::Polygon(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
}
|
||||
@ -37,5 +37,44 @@ svg::Polygon::~Polygon(void)
|
||||
|
||||
bool svg::Polygon::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
ParseTransform(node);
|
||||
ParsePaintAttr(node);
|
||||
|
||||
const char *sss = node->ToElement()->Attribute("points");
|
||||
if (NULL == sss) {
|
||||
SVG_ERROR("(l "<<node->Row()<<") polygon: missing points attribute");
|
||||
return false;
|
||||
}
|
||||
SVG_VERBOSE("Parse polygon : \"" << sss << "\"");
|
||||
while ('\0' != sss[0]) {
|
||||
coord2D_ts pos;
|
||||
int32_t n;
|
||||
if (sscanf(sss, "%f,%f %n", &pos.x, &pos.y, &n) == 2) {
|
||||
m_listPoint.PushBack(pos);
|
||||
sss += n;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void svg::Polygon::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Polygon nbPoint=" << m_listPoint.Size());
|
||||
}
|
||||
|
||||
|
||||
void svg::Polygon::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx)
|
||||
{
|
||||
if (m_listPoint.Size()<2) {
|
||||
// nothing to draw ...
|
||||
}
|
||||
path.move_to(m_listPoint[0].x, m_listPoint[0].y);
|
||||
for( int32_t iii=1; iii< m_listPoint.Size(); iii++) {
|
||||
path.line_to(m_listPoint[iii].x, m_listPoint[iii].y);
|
||||
}
|
||||
path.close_polygon();
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,9 +40,11 @@ namespace svg
|
||||
etk::VectorType<coord2D_ts> m_listPoint; //!< list of all point of the polygone
|
||||
PolygonMode_te m_diplayMode; //!< polygone specific display mode
|
||||
public:
|
||||
Polygon(void);
|
||||
Polygon(paintState_ts parentPaintState);
|
||||
~Polygon(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Polyline.h>
|
||||
|
||||
svg::Polyline::Polyline(void)
|
||||
svg::Polyline::Polyline(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
}
|
||||
@ -37,5 +37,31 @@ svg::Polyline::~Polyline(void)
|
||||
|
||||
bool svg::Polyline::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
ParseTransform(node);
|
||||
ParsePaintAttr(node);
|
||||
|
||||
const char *sss = node->ToElement()->Attribute("points");
|
||||
if (NULL == sss) {
|
||||
SVG_ERROR("(l "<<node->Row()<<") polyline: missing points attribute");
|
||||
return false;
|
||||
}
|
||||
SVG_VERBOSE("Parse polyline : \"" << sss << "\"");
|
||||
while ('\0' != sss[0]) {
|
||||
coord2D_ts pos;
|
||||
int32_t n;
|
||||
if (sscanf(sss, "%f,%f %n", &pos.x, &pos.y, &n) == 2) {
|
||||
m_listPoint.PushBack(pos);
|
||||
sss += n;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void svg::Polyline::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Polyline nbPoint=" << m_listPoint.Size());
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,9 +35,10 @@ namespace svg
|
||||
private:
|
||||
etk::VectorType<coord2D_ts> m_listPoint; //!< list of all point of the polyline
|
||||
public:
|
||||
Polyline(void);
|
||||
Polyline(paintState_ts parentPaintState);
|
||||
~Polyline(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,9 +25,14 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Rectangle.h>
|
||||
|
||||
svg::Rectangle::Rectangle(void)
|
||||
svg::Rectangle::Rectangle(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
m_position.x = 0.0;
|
||||
m_position.y = 0.0;
|
||||
m_size.x = 0.0;
|
||||
m_size.y = 0.0;
|
||||
m_roundedCorner.x = 0.0;
|
||||
m_roundedCorner.y = 0.0;
|
||||
}
|
||||
|
||||
svg::Rectangle::~Rectangle(void)
|
||||
@ -37,5 +42,23 @@ svg::Rectangle::~Rectangle(void)
|
||||
|
||||
bool svg::Rectangle::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
m_position.x = 0.0;
|
||||
m_position.y = 0.0;
|
||||
m_size.x = 0.0;
|
||||
m_size.y = 0.0;
|
||||
m_roundedCorner.x = 0.0;
|
||||
m_roundedCorner.y = 0.0;
|
||||
|
||||
ParseTransform(node);
|
||||
ParsePaintAttr(node);
|
||||
|
||||
ParsePosition(node, m_position, m_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void svg::Rectangle::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Rectangle");
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,10 @@ namespace svg
|
||||
coord2D_ts m_size; //!< size of the rectangle
|
||||
coord2D_ts m_roundedCorner; //!< property of the rounded corner
|
||||
public:
|
||||
Rectangle(void);
|
||||
Rectangle(paintState_ts parentPaintState);
|
||||
~Rectangle(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <parserSVG/Debug.h>
|
||||
#include <parserSVG/Text.h>
|
||||
|
||||
svg::Text::Text(void)
|
||||
svg::Text::Text(paintState_ts parentPaintState) : svg::Base(parentPaintState)
|
||||
{
|
||||
|
||||
}
|
||||
@ -39,3 +39,10 @@ bool svg::Text::Parse(TiXmlNode * node)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void svg::Text::Display(int32_t spacing)
|
||||
{
|
||||
SVG_DEBUG(SpacingDist(spacing) << "Text");
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,9 +34,10 @@ namespace svg
|
||||
private:
|
||||
|
||||
public:
|
||||
Text(void);
|
||||
Text(paintState_ts parentPaintState);
|
||||
~Text(void);
|
||||
virtual bool Parse(TiXmlNode * node);
|
||||
virtual void Display(int32_t spacing);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -34,12 +34,44 @@
|
||||
#include <parserSVG/Polyline.h>
|
||||
#include <parserSVG/Rectangle.h>
|
||||
#include <parserSVG/Text.h>
|
||||
#include <parserSVG/Group.h>
|
||||
|
||||
#include <agg-2.4/agg_basics.h>
|
||||
#include <agg-2.4/agg_rendering_buffer.h>
|
||||
#include <agg-2.4/agg_rasterizer_scanline_aa.h>
|
||||
#include <agg-2.4/agg_scanline_p.h>
|
||||
#include <agg-2.4/agg_renderer_scanline.h>
|
||||
#include <agg-2.4/agg_path_storage.h>
|
||||
#include <agg-2.4/agg_conv_transform.h>
|
||||
#include <agg-2.4/agg_bounding_rect.h>
|
||||
#include <agg-2.4/agg_color_rgba.h>
|
||||
#include <agg-2.4/agg_pixfmt_rgba.h>
|
||||
|
||||
svg::Parser::Parser(etk::File fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
m_version = "0.0";
|
||||
m_loadOK = false;
|
||||
m_paint.fill.red = 1.0;
|
||||
m_paint.fill.green = 1.0;
|
||||
m_paint.fill.blue = 1.0;
|
||||
m_paint.fill.alpha = 1.0;
|
||||
|
||||
m_paint.stroke.red = 1.0;
|
||||
m_paint.stroke.green = 1.0;
|
||||
m_paint.stroke.blue = 1.0;
|
||||
m_paint.stroke.alpha = 0.0;
|
||||
|
||||
m_paint.strokeWidth = 1.0;
|
||||
m_paint.viewPort.x = 1.0;
|
||||
m_paint.viewPort.y = 1.0;
|
||||
m_paint.matrix[0] = 1.0;
|
||||
m_paint.matrix[1] = 0.0;
|
||||
m_paint.matrix[2] = 0.0;
|
||||
m_paint.matrix[3] = 1.0;
|
||||
m_paint.matrix[4] = 0.0;
|
||||
m_paint.matrix[5] = 0.0;
|
||||
|
||||
// Start loading the XML :
|
||||
SVG_DEBUG("open file (SVG) \"" << m_fileName << "\"");
|
||||
|
||||
@ -66,9 +98,9 @@ svg::Parser::Parser(etk::File fileName)
|
||||
}
|
||||
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
|
||||
// load data from the file :
|
||||
fileName.fRead(fileBuffer, 1, fileSize);
|
||||
m_fileName.fRead(fileBuffer, 1, fileSize);
|
||||
// close the file:
|
||||
fileName.fClose();
|
||||
m_fileName.fClose();
|
||||
// load the XML from the memory
|
||||
XmlDocument.Parse((const char*)fileBuffer, 0, TIXML_ENCODING_UTF8);
|
||||
|
||||
@ -81,6 +113,13 @@ svg::Parser::Parser(etk::File fileName)
|
||||
if (NULL != version) {
|
||||
m_version = version;
|
||||
}
|
||||
// parse ...
|
||||
coord2D_ts pos;
|
||||
coord2D_ts size;
|
||||
ParseTransform(root);
|
||||
ParsePosition(root, pos, size);
|
||||
ParsePaintAttr(root);
|
||||
|
||||
// parse all sub node :
|
||||
for(TiXmlNode * child = root->FirstChild(); NULL != child; child = child->NextSibling() ) {
|
||||
svg::Base *elementParser = NULL;
|
||||
@ -89,25 +128,25 @@ svg::Parser::Parser(etk::File fileName)
|
||||
} else {
|
||||
etk::UString localValue = child->Value();
|
||||
if (localValue == "g") {
|
||||
// group ... not supported now ...
|
||||
elementParser = new svg::Group(m_paint);
|
||||
} else if (localValue == "a") {
|
||||
// TODO ...
|
||||
} else if (localValue == "path") {
|
||||
elementParser = new svg::Path();
|
||||
elementParser = new svg::Path(m_paint);
|
||||
} else if (localValue == "rect") {
|
||||
elementParser = new svg::Rectangle();
|
||||
elementParser = new svg::Rectangle(m_paint);
|
||||
} else if (localValue == "circle") {
|
||||
elementParser = new svg::Circle();
|
||||
elementParser = new svg::Circle(m_paint);
|
||||
} else if (localValue == "ellipse") {
|
||||
elementParser = new svg::Ellipse();
|
||||
elementParser = new svg::Ellipse(m_paint);
|
||||
} else if (localValue == "line") {
|
||||
elementParser = new svg::Line();
|
||||
elementParser = new svg::Line(m_paint);
|
||||
} else if (localValue == "polyline") {
|
||||
elementParser = new svg::Polyline();
|
||||
elementParser = new svg::Polyline(m_paint);
|
||||
} else if (localValue == "polygon") {
|
||||
elementParser = new svg::Polygon();
|
||||
elementParser = new svg::Polygon(m_paint);
|
||||
} else if (localValue == "text") {
|
||||
elementParser = new svg::Text();
|
||||
elementParser = new svg::Text(m_paint);
|
||||
} else {
|
||||
SVG_ERROR("(l "<<child->Row()<<") node not suported : \""<<localValue<<"\" must be [g,a,path,rect,circle,ellipse,line,polyline,polygon,text]");
|
||||
}
|
||||
@ -138,3 +177,354 @@ svg::Parser::~Parser(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void svg::Parser::DisplayDebug(void)
|
||||
{
|
||||
SVG_DEBUG("Main SVG node : ");
|
||||
for (int32_t iii=0; iii<m_subElementList.Size(); iii++) {
|
||||
if (NULL != m_subElementList[iii]) {
|
||||
m_subElementList[iii]->Display(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
frame_width = 320,
|
||||
frame_height = 200
|
||||
};
|
||||
|
||||
// Writing the buffer to a .PPM file, assuming it has
|
||||
// RGB-structure, one byte per color component
|
||||
//--------------------------------------------------
|
||||
bool write_ppm(const unsigned char* buf,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
const char* file_name)
|
||||
{
|
||||
FILE* fd = fopen(file_name, "wb");
|
||||
if(fd)
|
||||
{
|
||||
fprintf(fd, "P6 %d %d 255 ", width, height);
|
||||
for (uint32_t iii=0 ; iii<width*height; iii++) {
|
||||
fwrite(buf+iii*4, 1, 3, fd);
|
||||
}
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO : Color format system ... ==> todo Set the ewol format with this system ...
|
||||
typedef agg::rgba8 color_type;
|
||||
|
||||
|
||||
agg::rasterizer_scanline_aa<> g_rasterizer;
|
||||
agg::scanline_p8 g_scanline;
|
||||
agg::path_storage g_path;
|
||||
etk::VectorType<agg::rgba8> g_colorsList;
|
||||
etk::VectorType<uint32_t> g_pathLdxList;
|
||||
|
||||
agg::path_storage g_path2;
|
||||
etk::VectorType<agg::rgba8> g_colorsList2;
|
||||
etk::VectorType<uint32_t> g_pathLdxList2;
|
||||
double g_base_dx2 = 0;
|
||||
double g_base_dy2 = 0;
|
||||
|
||||
uint32_t g_npaths = 0;
|
||||
double g_x1 = 0;
|
||||
double g_y1 = 0;
|
||||
double g_x2 = 0;
|
||||
double g_y2 = 0;
|
||||
double g_base_dx = 0;
|
||||
double g_base_dy = 0;
|
||||
double g_angle = 0;
|
||||
double g_scale = 1.0;
|
||||
double g_skew_x = 0;
|
||||
double g_skew_y = 0;
|
||||
int g_nclick = 0;
|
||||
|
||||
typedef agg::renderer_base<agg::pixfmt_rgba32> renderer_base;
|
||||
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
|
||||
|
||||
|
||||
static char g_lion[] =
|
||||
"f2cc99\n"
|
||||
"M 69,18 L 82,8 L 99,3 L 118,5 L 135,12 L 149,21 L 156,13 L 165,9 L 177,13 L 183,28 L 180,50 L 164,91 L 155,107 L 154,114 L 151,121 L 141,127 L 139,136 L 155,206 L 157,251 L 126,342 L 133,357 L 128,376 L 83,376 L 75,368 L 67,350 L 61,350 L 53,369 L 4,369 L 2,361 L 5,354 L 12,342 L 16,321 L 4,257 L 4,244 L 7,218 L 9,179 L 26,127 L 43,93 L 32,77 L 30,70 L 24,67 L 16,49 L 17,35 L 18,23 L 30,12 L 40,7 L 53,7 L 62,12 L 69,18 L 69,18 L 69,18\n"
|
||||
"e5b27f\n"
|
||||
"M 142,79 L 136,74 L 138,82 L 133,78 L 133,84 L 127,78 L 128,85 L 124,80 L 125,87 L 119,82 L 119,90 L 125,99 L 125,96 L 128,100 L 128,94 L 131,98 L 132,93 L 135,97 L 136,93 L 138,97 L 139,94 L 141,98 L 143,94 L 144,85 L 142,79 L 142,79 L 142,79\n"
|
||||
"eb8080\n"
|
||||
"M 127,101 L 132,100 L 137,99 L 144,101 L 143,105 L 135,110 L 127,101 L 127,101 L 127,101\n"
|
||||
"f2cc99\n"
|
||||
"M 178,229 L 157,248 L 139,296 L 126,349 L 137,356 L 158,357 L 183,342 L 212,332 L 235,288 L 235,261 L 228,252 L 212,250 L 188,251 L 178,229 L 178,229 L 178,229\n"
|
||||
"9c826b\n"
|
||||
"M 56,229 L 48,241 L 48,250 L 57,281 L 63,325 L 71,338 L 81,315 L 76,321 L 79,311 L 83,301 L 75,308 L 80,298 L 73,303 L 76,296 L 71,298 L 74,292 L 69,293 L 74,284 L 78,278 L 71,278 L 74,274 L 68,273 L 70,268 L 66,267 L 68,261 L 60,266 L 62,259 L 65,253 L 57,258 L 59,251 L 55,254 L 55,248 L 60,237 L 54,240 L 58,234 L 54,236 L 56,229 L 56,229 L 56,229\n"
|
||||
"M 74,363 L 79,368 L 81,368 L 85,362 L 89,363 L 92,370 L 96,373 L 101,372 L 108,361 L 110,371 L 113,373 L 116,371 L 120,358 L 122,363 L 123,371 L 126,371 L 129,367 L 132,357 L 135,361 L 130,376 L 127,377 L 94,378 L 84,376 L 76,371 L 74,363 L 74,363 L 74,363\n"
|
||||
"M 212,250 L 219,251 L 228,258 L 236,270 L 235,287 L 225,304 L 205,332 L 177,343 L 171,352 L 158,357 L 166,352 L 168,346 L 168,339 L 165,333 L 155,327 L 155,323 L 161,320 L 165,316 L 169,316 L 167,312 L 171,313 L 168,308 L 173,309 L 170,306 L 177,306 L 175,308 L 177,311 L 174,311 L 176,316 L 171,315 L 174,319 L 168,320 L 168,323 L 175,327 L 179,332 L 183,326 L 184,332 L 189,323 L 190,328 L 194,320 L 194,325 L 199,316 L 201,320 L 204,313 L 206,316 L 208,310 L 211,305 L 219,298 L 226,288 L 229,279 L 228,266 L 224,259 L 217,253 L 212,250 L 212,250 L 212,250\n"
|
||||
"M 151,205 L 151,238 L 149,252 L 141,268 L 128,282 L 121,301 L 130,300 L 126,313 L 118,324 L 116,337 L 120,346 L 133,352 L 133,340 L 137,333 L 145,329 L 156,327 L 153,319 L 153,291 L 157,271 L 170,259 L 178,277 L 193,250 L 174,216 L 151,205 L 151,205 L 151,205\n"
|
||||
"M 78,127 L 90,142 L 95,155 L 108,164 L 125,167 L 139,175 L 150,206 L 152,191 L 141,140 L 121,148 L 100,136 L 78,127 L 78,127 L 78,127\n"
|
||||
"M 21,58 L 35,63 L 38,68 L 32,69 L 42,74 L 40,79 L 47,80 L 54,83 L 45,94 L 34,81 L 32,73 L 24,66 L 21,58 L 21,58 L 21,58\n"
|
||||
"M 71,34 L 67,34 L 66,27 L 59,24 L 54,17 L 48,17 L 39,22 L 30,26 L 28,31 L 31,39 L 38,46 L 29,45 L 36,54 L 41,61 L 41,70 L 50,69 L 54,71 L 55,58 L 67,52 L 76,43 L 76,39 L 68,44 L 71,34 L 71,34 L 71,34\n"
|
||||
"M 139,74 L 141,83 L 143,89 L 144,104 L 148,104 L 155,106 L 154,86 L 157,77 L 155,72 L 150,77 L 144,77 L 139,74 L 139,74 L 139,74\n"
|
||||
"M 105,44 L 102,53 L 108,58 L 111,62 L 112,55 L 105,44 L 105,44 L 105,44\n"
|
||||
"M 141,48 L 141,54 L 144,58 L 139,62 L 137,66 L 136,59 L 137,52 L 141,48 L 141,48 L 141,48\n"
|
||||
"M 98,135 L 104,130 L 105,134 L 108,132 L 108,135 L 112,134 L 113,137 L 116,136 L 116,139 L 119,139 L 124,141 L 128,140 L 133,138 L 140,133 L 139,140 L 126,146 L 104,144 L 98,135 L 98,135 L 98,135\n"
|
||||
"M 97,116 L 103,119 L 103,116 L 111,118 L 116,117 L 122,114 L 127,107 L 135,111 L 142,107 L 141,114 L 145,118 L 149,121 L 145,125 L 140,124 L 127,121 L 113,125 L 100,124 L 97,116 L 97,116 L 97,116\n"
|
||||
"M 147,33 L 152,35 L 157,34 L 153,31 L 160,31 L 156,28 L 161,28 L 159,24 L 163,25 L 163,21 L 165,22 L 170,23 L 167,17 L 172,21 L 174,18 L 175,23 L 176,22 L 177,28 L 177,33 L 174,37 L 176,39 L 174,44 L 171,49 L 168,53 L 164,57 L 159,68 L 156,70 L 154,60 L 150,51 L 146,43 L 144,35 L 147,33 L 147,33 L 147,33\n"
|
||||
"M 85,72 L 89,74 L 93,75 L 100,76 L 105,75 L 102,79 L 94,79 L 88,76 L 85,72 L 85,72 L 85,72\n"
|
||||
"M 86,214 L 79,221 L 76,232 L 82,225 L 78,239 L 82,234 L 78,245 L 81,243 L 79,255 L 84,250 L 84,267 L 87,254 L 90,271 L 90,257 L 95,271 L 93,256 L 95,249 L 92,252 L 93,243 L 89,253 L 89,241 L 86,250 L 87,236 L 83,245 L 87,231 L 82,231 L 90,219 L 84,221 L 86,214 L 86,214 L 86,214\n"
|
||||
"ffcc7f\n"
|
||||
"M 93,68 L 96,72 L 100,73 L 106,72 L 108,66 L 105,63 L 100,62 L 93,68 L 93,68 L 93,68\n"
|
||||
"M 144,64 L 142,68 L 142,73 L 146,74 L 150,73 L 154,64 L 149,62 L 144,64 L 144,64 L 144,64\n"
|
||||
"9c826b\n"
|
||||
"M 57,91 L 42,111 L 52,105 L 41,117 L 53,112 L 46,120 L 53,116 L 50,124 L 57,119 L 55,127 L 61,122 L 60,130 L 67,126 L 66,134 L 71,129 L 72,136 L 77,130 L 76,137 L 80,133 L 82,138 L 86,135 L 96,135 L 94,129 L 86,124 L 83,117 L 77,123 L 79,117 L 73,120 L 75,112 L 68,116 L 71,111 L 65,114 L 69,107 L 63,110 L 68,102 L 61,107 L 66,98 L 61,103 L 63,97 L 57,99 L 57,91 L 57,91 L 57,91\n"
|
||||
"M 83,79 L 76,79 L 67,82 L 75,83 L 65,88 L 76,87 L 65,92 L 76,91 L 68,96 L 77,95 L 70,99 L 80,98 L 72,104 L 80,102 L 76,108 L 85,103 L 92,101 L 87,98 L 93,96 L 86,94 L 91,93 L 85,91 L 93,89 L 99,89 L 105,93 L 107,85 L 102,82 L 92,80 L 83,79 L 83,79 L 83,79\n"
|
||||
"M 109,77 L 111,83 L 109,89 L 113,94 L 117,90 L 117,81 L 114,78 L 109,77 L 109,77 L 109,77\n"
|
||||
"M 122,128 L 127,126 L 134,127 L 136,129 L 134,130 L 130,128 L 124,129 L 122,128 L 122,128 L 122,128\n"
|
||||
"M 78,27 L 82,32 L 80,33 L 82,36 L 78,37 L 82,40 L 78,42 L 81,46 L 76,47 L 78,49 L 74,50 L 82,52 L 87,50 L 83,48 L 91,46 L 86,45 L 91,42 L 88,40 L 92,37 L 86,34 L 90,31 L 86,29 L 89,26 L 78,27 L 78,27 L 78,27\n"
|
||||
"M 82,17 L 92,20 L 79,21 L 90,25 L 81,25 L 94,28 L 93,26 L 101,30 L 101,26 L 107,33 L 108,28 L 111,40 L 113,34 L 115,45 L 117,39 L 119,54 L 121,46 L 124,58 L 126,47 L 129,59 L 130,49 L 134,58 L 133,44 L 137,48 L 133,37 L 137,40 L 133,32 L 126,20 L 135,26 L 132,19 L 138,23 L 135,17 L 142,18 L 132,11 L 116,6 L 94,6 L 78,11 L 92,12 L 80,14 L 90,16 L 82,17 L 82,17 L 82,17\n"
|
||||
"M 142,234 L 132,227 L 124,223 L 115,220 L 110,225 L 118,224 L 127,229 L 135,236 L 122,234 L 115,237 L 113,242 L 121,238 L 139,243 L 121,245 L 111,254 L 95,254 L 102,244 L 104,235 L 110,229 L 100,231 L 104,224 L 113,216 L 122,215 L 132,217 L 141,224 L 145,230 L 149,240 L 142,234 L 142,234 L 142,234\n"
|
||||
"M 115,252 L 125,248 L 137,249 L 143,258 L 134,255 L 125,254 L 115,252 L 115,252 L 115,252\n"
|
||||
"M 114,212 L 130,213 L 140,219 L 147,225 L 144,214 L 137,209 L 128,207 L 114,212 L 114,212 L 114,212\n"
|
||||
"M 102,263 L 108,258 L 117,257 L 131,258 L 116,260 L 109,265 L 102,263 L 102,263 L 102,263\n"
|
||||
"M 51,241 L 35,224 L 40,238 L 23,224 L 31,242 L 19,239 L 28,247 L 17,246 L 25,250 L 37,254 L 39,263 L 44,271 L 47,294 L 48,317 L 51,328 L 60,351 L 60,323 L 53,262 L 47,246 L 51,241 L 51,241 L 51,241\n"
|
||||
"M 2,364 L 9,367 L 14,366 L 18,355 L 20,364 L 26,366 L 31,357 L 35,364 L 39,364 L 42,357 L 47,363 L 53,360 L 59,357 L 54,369 L 7,373 L 2,364 L 2,364 L 2,364\n"
|
||||
"M 7,349 L 19,345 L 25,339 L 18,341 L 23,333 L 28,326 L 23,326 L 27,320 L 23,316 L 25,311 L 20,298 L 15,277 L 12,264 L 9,249 L 10,223 L 3,248 L 5,261 L 15,307 L 17,326 L 11,343 L 7,349 L 7,349 L 7,349\n"
|
||||
"M 11,226 L 15,231 L 25,236 L 18,227 L 11,226 L 11,226 L 11,226\n"
|
||||
"M 13,214 L 19,217 L 32,227 L 23,214 L 16,208 L 15,190 L 24,148 L 31,121 L 24,137 L 14,170 L 8,189 L 13,214 L 13,214 L 13,214\n"
|
||||
"M 202,254 L 195,258 L 199,260 L 193,263 L 197,263 L 190,268 L 196,268 L 191,273 L 188,282 L 200,272 L 194,272 L 201,266 L 197,265 L 204,262 L 200,258 L 204,256 L 202,254 L 202,254 L 202,254\n"
|
||||
"845433\n"
|
||||
"M 151,213 L 165,212 L 179,225 L 189,246 L 187,262 L 179,275 L 176,263 L 177,247 L 171,233 L 163,230 L 165,251 L 157,264 L 146,298 L 145,321 L 133,326 L 143,285 L 154,260 L 153,240 L 151,213 L 151,213 L 151,213\n"
|
||||
"M 91,132 L 95,145 L 97,154 L 104,148 L 107,155 L 109,150 L 111,158 L 115,152 L 118,159 L 120,153 L 125,161 L 126,155 L 133,164 L 132,154 L 137,163 L 137,152 L 142,163 L 147,186 L 152,192 L 148,167 L 141,143 L 124,145 L 105,143 L 91,132 L 91,132 L 91,132\n"
|
||||
"9c826b\n"
|
||||
"M 31,57 L 23,52 L 26,51 L 20,44 L 23,42 L 21,36 L 22,29 L 25,23 L 24,32 L 30,43 L 26,41 L 30,50 L 26,48 L 31,57 L 31,57 L 31,57\n"
|
||||
"M 147,21 L 149,28 L 155,21 L 161,16 L 167,14 L 175,15 L 173,11 L 161,9 L 147,21 L 147,21 L 147,21\n"
|
||||
"M 181,39 L 175,51 L 169,57 L 171,65 L 165,68 L 165,75 L 160,76 L 162,91 L 171,71 L 180,51 L 181,39 L 181,39 L 181,39\n"
|
||||
"M 132,346 L 139,348 L 141,346 L 142,341 L 147,342 L 143,355 L 133,350 L 132,346 L 132,346 L 132,346\n"
|
||||
"M 146,355 L 151,352 L 155,348 L 157,343 L 160,349 L 151,356 L 147,357 L 146,355 L 146,355 L 146,355\n"
|
||||
"M 99,266 L 100,281 L 94,305 L 86,322 L 78,332 L 72,346 L 73,331 L 91,291 L 99,266 L 99,266 L 99,266\n"
|
||||
"M 20,347 L 32,342 L 45,340 L 54,345 L 45,350 L 42,353 L 38,350 L 31,353 L 29,356 L 23,350 L 19,353 L 15,349 L 20,347 L 20,347 L 20,347\n"
|
||||
"M 78,344 L 86,344 L 92,349 L 88,358 L 84,352 L 78,344 L 78,344 L 78,344\n"
|
||||
"M 93,347 L 104,344 L 117,345 L 124,354 L 121,357 L 116,351 L 112,351 L 108,355 L 102,351 L 93,347 L 93,347 L 93,347\n"
|
||||
"000000\n"
|
||||
"M 105,12 L 111,18 L 113,24 L 113,29 L 119,34 L 116,23 L 112,16 L 105,12 L 105,12 L 105,12\n"
|
||||
"M 122,27 L 125,34 L 127,43 L 128,34 L 125,29 L 122,27 L 122,27 L 122,27\n"
|
||||
"M 115,13 L 122,19 L 122,15 L 113,10 L 115,13 L 115,13 L 115,13\n"
|
||||
"ffe5b2\n"
|
||||
"M 116,172 L 107,182 L 98,193 L 98,183 L 90,199 L 89,189 L 84,207 L 88,206 L 87,215 L 95,206 L 93,219 L 91,230 L 98,216 L 97,226 L 104,214 L 112,209 L 104,208 L 113,202 L 126,200 L 139,207 L 132,198 L 142,203 L 134,192 L 142,195 L 134,187 L 140,185 L 130,181 L 136,177 L 126,177 L 125,171 L 116,180 L 116,172 L 116,172 L 116,172\n"
|
||||
"M 74,220 L 67,230 L 67,221 L 59,235 L 63,233 L 60,248 L 70,232 L 65,249 L 71,243 L 67,256 L 73,250 L 69,262 L 73,259 L 71,267 L 76,262 L 72,271 L 78,270 L 76,275 L 82,274 L 78,290 L 86,279 L 86,289 L 92,274 L 88,275 L 87,264 L 82,270 L 82,258 L 77,257 L 78,247 L 73,246 L 77,233 L 72,236 L 74,220 L 74,220 L 74,220\n"
|
||||
"M 133,230 L 147,242 L 148,250 L 145,254 L 138,247 L 129,246 L 142,245 L 138,241 L 128,237 L 137,238 L 133,230 L 133,230 L 133,230\n"
|
||||
"M 133,261 L 125,261 L 116,263 L 111,267 L 125,265 L 133,261 L 133,261 L 133,261\n"
|
||||
"M 121,271 L 109,273 L 103,279 L 99,305 L 92,316 L 85,327 L 83,335 L 89,340 L 97,341 L 94,336 L 101,336 L 96,331 L 103,330 L 97,327 L 108,325 L 99,322 L 109,321 L 100,318 L 110,317 L 105,314 L 110,312 L 107,310 L 113,308 L 105,306 L 114,303 L 105,301 L 115,298 L 107,295 L 115,294 L 108,293 L 117,291 L 109,289 L 117,286 L 109,286 L 118,283 L 112,281 L 118,279 L 114,278 L 119,276 L 115,274 L 121,271 L 121,271 L 121,271\n"
|
||||
"M 79,364 L 74,359 L 74,353 L 76,347 L 80,351 L 83,356 L 82,360 L 79,364 L 79,364 L 79,364\n"
|
||||
"M 91,363 L 93,356 L 97,353 L 103,355 L 105,360 L 103,366 L 99,371 L 94,368 L 91,363 L 91,363 L 91,363\n"
|
||||
"M 110,355 L 114,353 L 118,357 L 117,363 L 113,369 L 111,362 L 110,355 L 110,355 L 110,355\n"
|
||||
"M 126,354 L 123,358 L 124,367 L 126,369 L 129,361 L 129,357 L 126,354 L 126,354 L 126,354\n"
|
||||
"M 30,154 L 24,166 L 20,182 L 23,194 L 29,208 L 37,218 L 41,210 L 41,223 L 46,214 L 46,227 L 52,216 L 52,227 L 61,216 L 59,225 L 68,213 L 73,219 L 70,207 L 77,212 L 69,200 L 77,202 L 70,194 L 78,197 L 68,187 L 76,182 L 64,182 L 58,175 L 58,185 L 53,177 L 50,186 L 46,171 L 44,182 L 39,167 L 36,172 L 36,162 L 30,166 L 30,154 L 30,154 L 30,154\n"
|
||||
"M 44,130 L 41,137 L 45,136 L 43,150 L 48,142 L 48,157 L 53,150 L 52,164 L 60,156 L 61,169 L 64,165 L 66,175 L 70,167 L 74,176 L 77,168 L 80,183 L 85,172 L 90,182 L 93,174 L 98,181 L 99,173 L 104,175 L 105,169 L 114,168 L 102,163 L 95,157 L 94,166 L 90,154 L 87,162 L 82,149 L 75,159 L 72,148 L 68,155 L 67,143 L 62,148 L 62,138 L 58,145 L 56,133 L 52,142 L 52,128 L 49,134 L 47,125 L 44,130 L 44,130 L 44,130\n"
|
||||
"M 13,216 L 19,219 L 36,231 L 22,223 L 16,222 L 22,227 L 12,224 L 13,220 L 16,220 L 13,216 L 13,216 L 13,216\n"
|
||||
"M 10,231 L 14,236 L 25,239 L 27,237 L 19,234 L 10,231 L 10,231 L 10,231\n"
|
||||
"M 9,245 L 14,242 L 25,245 L 13,245 L 9,245 L 9,245 L 9,245\n"
|
||||
"M 33,255 L 26,253 L 18,254 L 25,256 L 18,258 L 27,260 L 18,263 L 27,265 L 19,267 L 29,270 L 21,272 L 29,276 L 21,278 L 30,281 L 22,283 L 31,287 L 24,288 L 32,292 L 23,293 L 34,298 L 26,299 L 37,303 L 32,305 L 39,309 L 33,309 L 39,314 L 34,314 L 40,318 L 34,317 L 40,321 L 34,321 L 41,326 L 33,326 L 40,330 L 33,332 L 39,333 L 33,337 L 42,337 L 54,341 L 49,337 L 52,335 L 47,330 L 50,330 L 45,325 L 49,325 L 45,321 L 48,321 L 45,316 L 46,306 L 45,286 L 43,274 L 36,261 L 33,255 L 33,255 L 33,255\n"
|
||||
"M 7,358 L 9,351 L 14,351 L 17,359 L 11,364 L 7,358 L 7,358 L 7,358\n"
|
||||
"M 44,354 L 49,351 L 52,355 L 49,361 L 44,354 L 44,354 L 44,354\n"
|
||||
"M 32,357 L 37,353 L 40,358 L 36,361 L 32,357 L 32,357 L 32,357\n"
|
||||
"M 139,334 L 145,330 L 154,330 L 158,334 L 154,341 L 152,348 L 145,350 L 149,340 L 147,336 L 141,339 L 139,345 L 136,342 L 136,339 L 139,334 L 139,334 L 139,334\n"
|
||||
"M 208,259 L 215,259 L 212,255 L 220,259 L 224,263 L 225,274 L 224,283 L 220,292 L 208,300 L 206,308 L 203,304 L 199,315 L 197,309 L 195,318 L 193,313 L 190,322 L 190,316 L 185,325 L 182,318 L 180,325 L 172,321 L 178,320 L 176,313 L 186,312 L 180,307 L 188,307 L 184,303 L 191,302 L 186,299 L 195,294 L 187,290 L 197,288 L 192,286 L 201,283 L 194,280 L 203,277 L 198,275 L 207,271 L 200,269 L 209,265 L 204,265 L 212,262 L 208,259 L 208,259 L 208,259\n"
|
||||
"M 106,126 L 106,131 L 109,132 L 111,134 L 115,132 L 115,135 L 119,133 L 118,137 L 123,137 L 128,137 L 133,134 L 136,130 L 136,127 L 132,124 L 118,128 L 112,128 L 106,126 L 106,126 L 106,126\n"
|
||||
"M 107,114 L 101,110 L 98,102 L 105,97 L 111,98 L 119,102 L 121,108 L 118,112 L 113,115 L 107,114 L 107,114 L 107,114\n"
|
||||
"M 148,106 L 145,110 L 146,116 L 150,118 L 152,111 L 151,107 L 148,106 L 148,106 L 148,106\n"
|
||||
"M 80,55 L 70,52 L 75,58 L 63,57 L 72,61 L 57,61 L 67,66 L 57,67 L 62,69 L 54,71 L 61,73 L 54,77 L 63,78 L 53,85 L 60,84 L 56,90 L 69,84 L 63,82 L 75,76 L 70,75 L 77,72 L 72,71 L 78,69 L 72,66 L 81,67 L 78,64 L 82,63 L 80,60 L 86,62 L 80,55 L 80,55 L 80,55\n"
|
||||
"M 87,56 L 91,52 L 96,50 L 102,56 L 98,56 L 92,60 L 87,56 L 87,56 L 87,56\n"
|
||||
"M 85,68 L 89,73 L 98,76 L 106,74 L 96,73 L 91,70 L 85,68 L 85,68 L 85,68\n"
|
||||
"M 115,57 L 114,64 L 111,64 L 115,75 L 122,81 L 122,74 L 126,79 L 126,74 L 131,78 L 130,72 L 133,77 L 131,68 L 126,61 L 119,57 L 115,57 L 115,57 L 115,57\n"
|
||||
"M 145,48 L 143,53 L 147,59 L 151,59 L 150,55 L 145,48 L 145,48 L 145,48\n"
|
||||
"M 26,22 L 34,15 L 43,10 L 52,10 L 59,16 L 47,15 L 32,22 L 26,22 L 26,22 L 26,22\n"
|
||||
"M 160,19 L 152,26 L 149,34 L 154,33 L 152,30 L 157,30 L 155,26 L 158,27 L 157,23 L 161,23 L 160,19 L 160,19 L 160,19\n"
|
||||
"000000\n"
|
||||
"M 98,117 L 105,122 L 109,122 L 105,117 L 113,120 L 121,120 L 130,112 L 128,108 L 123,103 L 123,99 L 128,101 L 132,106 L 135,109 L 142,105 L 142,101 L 145,101 L 145,91 L 148,101 L 145,105 L 136,112 L 135,116 L 143,124 L 148,120 L 150,122 L 142,128 L 133,122 L 121,125 L 112,126 L 103,125 L 100,129 L 96,124 L 98,117 L 98,117 L 98,117\n"
|
||||
"M 146,118 L 152,118 L 152,115 L 149,115 L 146,118 L 146,118 L 146,118\n"
|
||||
"M 148,112 L 154,111 L 154,109 L 149,109 L 148,112 L 148,112 L 148,112\n"
|
||||
"M 106,112 L 108,115 L 114,116 L 118,114 L 106,112 L 106,112 L 106,112\n"
|
||||
"M 108,108 L 111,110 L 116,110 L 119,108 L 108,108 L 108,108 L 108,108\n"
|
||||
"M 106,104 L 109,105 L 117,106 L 115,104 L 106,104 L 106,104 L 106,104\n"
|
||||
"M 50,25 L 41,26 L 34,33 L 39,43 L 49,58 L 36,51 L 47,68 L 55,69 L 54,59 L 61,57 L 74,46 L 60,52 L 67,42 L 57,48 L 61,40 L 54,45 L 60,36 L 59,29 L 48,38 L 52,30 L 47,32 L 50,25 L 50,25 L 50,25\n"
|
||||
"M 147,34 L 152,41 L 155,49 L 161,53 L 157,47 L 164,47 L 158,43 L 168,44 L 159,40 L 164,37 L 169,37 L 164,33 L 169,34 L 165,28 L 170,30 L 170,25 L 173,29 L 175,27 L 176,32 L 173,36 L 175,39 L 172,42 L 172,46 L 168,49 L 170,55 L 162,57 L 158,63 L 155,58 L 153,50 L 149,46 L 147,34 L 147,34 L 147,34\n"
|
||||
"M 155,71 L 159,80 L 157,93 L 157,102 L 155,108 L 150,101 L 149,93 L 154,101 L 152,91 L 151,83 L 155,79 L 155,71 L 155,71 L 155,71\n"
|
||||
"M 112,78 L 115,81 L 114,91 L 112,87 L 113,82 L 112,78 L 112,78 L 112,78\n"
|
||||
"M 78,28 L 64,17 L 58,11 L 47,9 L 36,10 L 28,16 L 21,26 L 18,41 L 20,51 L 23,61 L 33,65 L 28,68 L 37,74 L 36,81 L 43,87 L 48,90 L 43,100 L 40,98 L 39,90 L 31,80 L 30,72 L 22,71 L 17,61 L 14,46 L 16,28 L 23,17 L 33,9 L 45,6 L 54,6 L 65,12 L 78,28 L 78,28 L 78,28\n"
|
||||
"M 67,18 L 76,9 L 87,5 L 101,2 L 118,3 L 135,8 L 149,20 L 149,26 L 144,19 L 132,12 L 121,9 L 105,7 L 89,8 L 76,14 L 70,20 L 67,18 L 67,18 L 67,18\n"
|
||||
"M 56,98 L 48,106 L 56,103 L 47,112 L 56,110 L 52,115 L 57,113 L 52,121 L 62,115 L 58,123 L 65,119 L 63,125 L 69,121 L 68,127 L 74,125 L 74,129 L 79,128 L 83,132 L 94,135 L 93,129 L 85,127 L 81,122 L 76,126 L 75,121 L 71,124 L 71,117 L 66,121 L 66,117 L 62,117 L 64,112 L 60,113 L 60,110 L 57,111 L 61,105 L 57,107 L 60,101 L 55,102 L 56,98 L 56,98 L 56,98\n"
|
||||
"M 101,132 L 103,138 L 106,134 L 106,139 L 112,136 L 111,142 L 115,139 L 114,143 L 119,142 L 125,145 L 131,142 L 135,138 L 140,134 L 140,129 L 143,135 L 145,149 L 150,171 L 149,184 L 145,165 L 141,150 L 136,147 L 132,151 L 131,149 L 126,152 L 125,150 L 121,152 L 117,148 L 111,152 L 110,148 L 105,149 L 104,145 L 98,150 L 96,138 L 94,132 L 94,130 L 98,132 L 101,132 L 101,132 L 101,132\n"
|
||||
"M 41,94 L 32,110 L 23,132 L 12,163 L 6,190 L 7,217 L 5,236 L 3,247 L 9,230 L 12,211 L 12,185 L 18,160 L 26,134 L 35,110 L 43,99 L 41,94 L 41,94 L 41,94\n"
|
||||
"M 32,246 L 41,250 L 50,257 L 52,267 L 53,295 L 53,323 L 59,350 L 54,363 L 51,365 L 44,366 L 42,360 L 40,372 L 54,372 L 59,366 L 62,353 L 71,352 L 75,335 L 73,330 L 66,318 L 68,302 L 64,294 L 67,288 L 63,286 L 63,279 L 59,275 L 58,267 L 56,262 L 50,247 L 42,235 L 44,246 L 32,236 L 35,244 L 32,246 L 32,246 L 32,246\n"
|
||||
"M 134,324 L 146,320 L 159,322 L 173,327 L 179,337 L 179,349 L 172,355 L 158,357 L 170,350 L 174,343 L 170,333 L 163,328 L 152,326 L 134,329 L 134,324 L 134,324 L 134,324\n"
|
||||
"M 173,339 L 183,334 L 184,338 L 191,329 L 194,332 L 199,323 L 202,325 L 206,318 L 209,320 L 213,309 L 221,303 L 228,296 L 232,289 L 234,279 L 233,269 L 230,262 L 225,256 L 219,253 L 208,252 L 198,252 L 210,249 L 223,250 L 232,257 L 237,265 L 238,277 L 238,291 L 232,305 L 221,323 L 218,335 L 212,342 L 200,349 L 178,348 L 173,339 L 173,339 L 173,339\n"
|
||||
"M 165,296 L 158,301 L 156,310 L 156,323 L 162,324 L 159,318 L 162,308 L 162,304 L 165,296 L 165,296 L 165,296\n"
|
||||
"M 99,252 L 105,244 L 107,234 L 115,228 L 121,228 L 131,235 L 122,233 L 113,235 L 109,246 L 121,239 L 133,243 L 121,243 L 110,251 L 99,252 L 99,252 L 99,252\n"
|
||||
"M 117,252 L 124,247 L 134,249 L 136,253 L 126,252 L 117,252 L 117,252 L 117,252\n"
|
||||
"M 117,218 L 132,224 L 144,233 L 140,225 L 132,219 L 117,218 L 117,218 L 117,218\n"
|
||||
"M 122,212 L 134,214 L 143,221 L 141,213 L 132,210 L 122,212 L 122,212 L 122,212\n"
|
||||
"M 69,352 L 70,363 L 76,373 L 86,378 L 97,379 L 108,379 L 120,377 L 128,378 L 132,373 L 135,361 L 133,358 L 132,366 L 127,375 L 121,374 L 121,362 L 119,367 L 117,374 L 110,376 L 110,362 L 107,357 L 106,371 L 104,375 L 97,376 L 90,375 L 90,368 L 86,362 L 83,364 L 86,369 L 85,373 L 78,370 L 73,362 L 71,351 L 69,352 L 69,352 L 69,352\n"
|
||||
"M 100,360 L 96,363 L 99,369 L 102,364 L 100,360 L 100,360 L 100,360\n"
|
||||
"M 115,360 L 112,363 L 114,369 L 117,364 L 115,360 L 115,360 L 115,360\n"
|
||||
"M 127,362 L 125,364 L 126,369 L 128,365 L 127,362 L 127,362 L 127,362\n"
|
||||
"M 5,255 L 7,276 L 11,304 L 15,320 L 13,334 L 6,348 L 2,353 L 0,363 L 5,372 L 12,374 L 25,372 L 38,372 L 44,369 L 42,367 L 36,368 L 31,369 L 30,360 L 27,368 L 20,370 L 16,361 L 15,368 L 10,369 L 3,366 L 3,359 L 6,352 L 11,348 L 17,331 L 19,316 L 12,291 L 9,274 L 5,255 L 5,255 L 5,255\n"
|
||||
"M 10,358 L 7,362 L 10,366 L 11,362 L 10,358 L 10,358 L 10,358\n"
|
||||
"M 25,357 L 22,360 L 24,366 L 27,360 L 25,357 L 25,357 L 25,357\n"
|
||||
"M 37,357 L 34,361 L 36,365 L 38,361 L 37,357 L 37,357 L 37,357\n"
|
||||
"M 49,356 L 46,359 L 47,364 L 50,360 L 49,356 L 49,356 L 49,356\n"
|
||||
"M 130,101 L 132,102 L 135,101 L 139,102 L 143,103 L 142,101 L 137,100 L 133,100 L 130,101 L 130,101 L 130,101\n"
|
||||
"M 106,48 L 105,52 L 108,56 L 109,52 L 106,48 L 106,48 L 106,48\n"
|
||||
"M 139,52 L 139,56 L 140,60 L 142,58 L 141,56 L 139,52 L 139,52 L 139,52\n"
|
||||
"M 25,349 L 29,351 L 30,355 L 33,350 L 37,348 L 42,351 L 45,347 L 49,345 L 44,343 L 36,345 L 25,349 L 25,349 L 25,349\n"
|
||||
"M 98,347 L 105,351 L 107,354 L 109,349 L 115,349 L 120,353 L 118,349 L 113,346 L 104,346 L 98,347 L 98,347 L 98,347\n"
|
||||
"M 83,348 L 87,352 L 87,357 L 89,351 L 87,348 L 83,348 L 83,348 L 83,348\n"
|
||||
"M 155,107 L 163,107 L 170,107 L 186,108 L 175,109 L 155,109 L 155,107 L 155,107 L 155,107\n"
|
||||
"M 153,114 L 162,113 L 175,112 L 192,114 L 173,114 L 154,115 L 153,114 L 153,114 L 153,114\n"
|
||||
"M 152,118 L 164,120 L 180,123 L 197,129 L 169,123 L 151,120 L 152,118 L 152,118 L 152,118\n"
|
||||
"M 68,109 L 87,106 L 107,106 L 106,108 L 88,108 L 68,109 L 68,109 L 68,109\n"
|
||||
"M 105,111 L 95,112 L 79,114 L 71,116 L 85,115 L 102,113 L 105,111 L 105,111 L 105,111\n"
|
||||
"M 108,101 L 98,99 L 87,99 L 78,99 L 93,100 L 105,102 L 108,101 L 108,101 L 108,101\n"
|
||||
"M 85,63 L 91,63 L 97,60 L 104,60 L 108,62 L 111,69 L 112,75 L 110,74 L 108,71 L 103,73 L 106,69 L 105,65 L 103,64 L 103,67 L 102,70 L 99,70 L 97,66 L 94,67 L 97,72 L 88,67 L 84,66 L 85,63 L 85,63 L 85,63\n"
|
||||
"M 140,74 L 141,66 L 144,61 L 150,61 L 156,62 L 153,70 L 150,73 L 152,65 L 150,65 L 151,68 L 149,71 L 146,71 L 144,66 L 143,70 L 143,74 L 140,74 L 140,74 L 140,74\n"
|
||||
"M 146,20 L 156,11 L 163,9 L 172,9 L 178,14 L 182,18 L 184,32 L 182,42 L 182,52 L 177,58 L 176,67 L 171,76 L 165,90 L 157,105 L 160,92 L 164,85 L 168,78 L 167,73 L 173,66 L 172,62 L 175,59 L 174,55 L 177,53 L 180,46 L 181,29 L 179,21 L 173,13 L 166,11 L 159,13 L 153,18 L 148,23 L 146,20 L 146,20 L 146,20\n"
|
||||
"M 150,187 L 148,211 L 150,233 L 153,247 L 148,267 L 135,283 L 125,299 L 136,292 L 131,313 L 122,328 L 122,345 L 129,352 L 133,359 L 133,367 L 137,359 L 148,356 L 140,350 L 131,347 L 129,340 L 132,332 L 140,328 L 137,322 L 140,304 L 154,265 L 157,244 L 155,223 L 161,220 L 175,229 L 186,247 L 185,260 L 176,275 L 178,287 L 185,277 L 188,261 L 196,253 L 189,236 L 174,213 L 150,187 L 150,187 L 150,187\n"
|
||||
"M 147,338 L 142,341 L 143,345 L 141,354 L 147,343 L 147,338 L 147,338 L 147,338\n"
|
||||
"M 157,342 L 156,349 L 150,356 L 157,353 L 163,346 L 162,342 L 157,342 L 157,342 L 157,342\n"
|
||||
"M 99,265 L 96,284 L 92,299 L 73,339 L 73,333 L 87,300 L 99,265 L 99,265 L 99,265\n";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uint32_t parse_lion(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx)
|
||||
{
|
||||
const char* ptr = g_lion;
|
||||
while(*ptr) {
|
||||
if(*ptr != 'M' && isalnum(*ptr)) {
|
||||
unsigned c = 0;
|
||||
sscanf(ptr, "%x", &c);
|
||||
|
||||
// New color. Every new color creates new path in the path object.
|
||||
path.close_polygon();
|
||||
colors.PushBack(agg::rgb8_packed(c));
|
||||
uint32_t tmpPathNew = path.start_new_path();
|
||||
pathIdx.PushBack(tmpPathNew);
|
||||
while(*ptr && *ptr != '\n'){
|
||||
ptr++;
|
||||
}
|
||||
if(*ptr == '\n') {
|
||||
ptr++;
|
||||
}
|
||||
} else {
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
|
||||
while(*ptr && *ptr != '\n') {
|
||||
int c = *ptr;
|
||||
|
||||
while(*ptr && !isdigit(*ptr)) ptr++;
|
||||
x = atof(ptr);
|
||||
|
||||
while(*ptr && isdigit(*ptr)) ptr++;
|
||||
while(*ptr && !isdigit(*ptr)) ptr++;
|
||||
y = atof(ptr);
|
||||
|
||||
if(c == 'M') {
|
||||
path.close_polygon();
|
||||
path.move_to(x, y);
|
||||
} else {
|
||||
path.line_to(x, y);
|
||||
}
|
||||
|
||||
while(*ptr && isdigit(*ptr)) ptr++;
|
||||
while(*ptr && *ptr != '\n' && !isalpha(*ptr)) ptr++;
|
||||
}
|
||||
if(*ptr == '\n') ptr++;
|
||||
}
|
||||
}
|
||||
path.arrange_orientations_all_paths(agg::path_flags_cw);
|
||||
return pathIdx.Size();
|
||||
}
|
||||
|
||||
|
||||
void svg::Parser::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx)
|
||||
{
|
||||
uint32_t tmpColor = 0;
|
||||
tmpColor = ((int32_t)(m_paint.fill.red*256.))<<24;
|
||||
tmpColor += ((int32_t)(m_paint.fill.green*256.))<<24;
|
||||
tmpColor += ((int32_t)(m_paint.fill.blue*256.))<<24;
|
||||
tmpColor += ((int32_t)(m_paint.fill.alpha*256.))<<24;
|
||||
// New color. Every new color creates new path in the path object.
|
||||
colors.PushBack(agg::rgb8_packed(tmpColor));
|
||||
uint32_t tmpPathNew = path.start_new_path();
|
||||
pathIdx.PushBack(tmpPathNew);
|
||||
for (int32_t iii=0; iii<m_subElementList.Size(); iii++) {
|
||||
if (NULL != m_subElementList[iii]) {
|
||||
m_subElementList[iii]->AggDraw(path, colors, pathIdx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void svg::Parser::GenerateTestFile(void)
|
||||
{
|
||||
|
||||
uint32_t g_npaths = parse_lion(g_path, g_colorsList, g_pathLdxList);
|
||||
agg::pod_array_adaptor<unsigned> path_idx(&g_pathLdxList[0], g_npaths);
|
||||
agg::bounding_rect(g_path, path_idx, 0, g_npaths, &g_x1, &g_y1, &g_x2, &g_y2);
|
||||
g_base_dx = (g_x2 - g_x1) / 2.0;
|
||||
g_base_dy = (g_y2 - g_y1) / 2.0;
|
||||
|
||||
AggDraw(g_path2, g_colorsList2, g_pathLdxList2);
|
||||
agg::pod_array_adaptor<unsigned> path_idx2(&g_pathLdxList2[0], g_pathLdxList2.Size() );
|
||||
agg::bounding_rect(g_path2, path_idx2, 0, g_pathLdxList2.Size(), &g_x1, &g_y1, &g_x2, &g_y2);
|
||||
g_base_dx2 = (g_x2 - g_x1) / 2.0;
|
||||
g_base_dy2 = (g_y2 - g_y1) / 2.0;
|
||||
|
||||
int width = 800;
|
||||
int height = 600;
|
||||
|
||||
unsigned char* buffer = new unsigned char[width * height * 4];
|
||||
memset(buffer, 255, width * height * 4);
|
||||
|
||||
agg::rendering_buffer rbuf(buffer, width, height, width * 4);
|
||||
agg::pixfmt_rgba32 pixf(rbuf);
|
||||
renderer_base rb(pixf);
|
||||
renderer_solid r(rb);
|
||||
|
||||
agg::trans_affine mtx;
|
||||
mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
|
||||
mtx *= agg::trans_affine_scaling(g_scale, g_scale);
|
||||
mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi);
|
||||
mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
|
||||
mtx *= agg::trans_affine_translation(width*0.3, height/2);
|
||||
|
||||
// This code renders the lion:
|
||||
agg::conv_transform<agg::path_storage, agg::trans_affine> trans(g_path, mtx);
|
||||
agg::render_all_paths(g_rasterizer, g_scanline, r, trans, &g_colorsList[0], &g_pathLdxList[0], g_npaths);
|
||||
// This code renders a second lion:
|
||||
|
||||
agg::trans_affine mtx2;
|
||||
mtx2 *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2);
|
||||
mtx2 *= agg::trans_affine_scaling(g_scale, g_scale);
|
||||
mtx2 *= agg::trans_affine_rotation(g_angle);// + agg::pi);
|
||||
mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
|
||||
mtx2 *= agg::trans_affine_translation(width*0.7, height/2);
|
||||
|
||||
agg::conv_transform<agg::path_storage, agg::trans_affine> trans2(g_path2, mtx2);
|
||||
agg::render_all_paths(g_rasterizer, g_scanline, r, trans2, &g_colorsList2[0], &g_pathLdxList2[0], g_pathLdxList2.Size());
|
||||
|
||||
write_ppm(buffer, width, height, "agg_test.ppm");
|
||||
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -31,17 +31,21 @@
|
||||
|
||||
namespace svg
|
||||
{
|
||||
class Parser
|
||||
class Parser : public svg::Base
|
||||
{
|
||||
private:
|
||||
etk::File m_fileName;
|
||||
bool m_loadOK;
|
||||
etk::UString m_version;
|
||||
etk::VectorType<svg::Base *> m_subElementList;
|
||||
|
||||
public:
|
||||
Parser(etk::File fileName);
|
||||
~Parser(void);
|
||||
bool IsLoadOk(void) { return m_loadOK; };
|
||||
void DisplayDebug(void);
|
||||
void GenerateTestFile(void);
|
||||
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx);
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user