Basic SVG parser missing some element like eliptical arc, gradient, effect and defs

This commit is contained in:
Edouard Dupin 2012-03-27 18:32:44 +02:00
parent 1fd0741c21
commit dcd2bdb833
24 changed files with 650 additions and 144 deletions

View File

@ -228,18 +228,18 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
m_folder = ""; m_folder = "";
m_shortFilename = ""; m_shortFilename = "";
m_lineNumberOpen = 0; m_lineNumberOpen = 0;
TK_DEBUG("1 :Set Name : " << newFilename ); TK_VERBOSE("1 :Set Name : " << newFilename );
etk::UString destFilename; etk::UString destFilename;
if (newFilename.Size() == 0) { if (newFilename.Size() == 0) {
destFilename = "no-name"; destFilename = "no-name";
} else { } else {
destFilename = newFilename; destFilename = newFilename;
} }
TK_DEBUG("2 : Get file Name : " << destFilename << "start with '/'=" << destFilename.StartWith('/')); TK_VERBOSE("2 : Get file Name : " << destFilename << "start with '/'=" << destFilename.StartWith('/'));
if (true == destFilename.StartWith('/')) { if (true == destFilename.StartWith('/')) {
m_type = etk::FILE_TYPE_DIRECT; m_type = etk::FILE_TYPE_DIRECT;
if (type != etk::FILE_TYPE_DIRECT) { if (type != etk::FILE_TYPE_DIRECT) {
TK_DEBUG("Incompatible type with a file=\"" << newFilename << "\" ==> force it in direct mode ..."); TK_VERBOSE("Incompatible type with a file=\"" << newFilename << "\" ==> force it in direct mode ...");
} }
} else { } else {
if (type == etk::FILE_TYPE_DIRECT) { if (type == etk::FILE_TYPE_DIRECT) {
@ -262,14 +262,14 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
} }
} }
bool needUnpack = false; bool needUnpack = false;
#if ETK_DEBUG_LEVEL > 2 #if ETK_DEBUG_LEVEL > 3
char *mode = NULL; char *mode = NULL;
#endif #endif
switch (m_type) switch (m_type)
{ {
case etk::FILE_TYPE_DATA: case etk::FILE_TYPE_DATA:
{ {
#if ETK_DEBUG_LEVEL > 2 #if ETK_DEBUG_LEVEL > 3
mode = "FILE_TYPE_DATA"; mode = "FILE_TYPE_DATA";
#endif #endif
#if defined(DATA_IN_APK) #if defined(DATA_IN_APK)
@ -287,7 +287,7 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
if (-1 == m_idZipFile) { if (-1 == m_idZipFile) {
TK_ERROR("File Does not existed ... in APK : \"" << tmpFilename << "\""); TK_ERROR("File Does not existed ... in APK : \"" << tmpFilename << "\"");
} else { } else {
TK_INFO("File existed ... in APK : \"" << tmpFilename << "\" ==> id=" << m_idZipFile); TK_VERBOSE("File existed ... in APK : \"" << tmpFilename << "\" ==> id=" << m_idZipFile);
} }
#else #else
//etk::UString tmpFilename = destFilename; //etk::UString tmpFilename = destFilename;
@ -298,7 +298,7 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
break; break;
case etk::FILE_TYPE_USER_DATA: case etk::FILE_TYPE_USER_DATA:
{ {
#if ETK_DEBUG_LEVEL > 2 #if ETK_DEBUG_LEVEL > 3
mode = "FILE_TYPE_USER_DATA"; mode = "FILE_TYPE_USER_DATA";
#endif #endif
etk::UString tmpFilename = destFilename; etk::UString tmpFilename = destFilename;
@ -309,7 +309,7 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
break; break;
case etk::FILE_TYPE_CACHE: case etk::FILE_TYPE_CACHE:
{ {
#if ETK_DEBUG_LEVEL > 2 #if ETK_DEBUG_LEVEL > 3
mode = "FILE_TYPE_CACHE"; mode = "FILE_TYPE_CACHE";
#endif #endif
etk::UString tmpFilename = destFilename; etk::UString tmpFilename = destFilename;
@ -320,13 +320,13 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
break; break;
default: default:
// nothing to do ... // nothing to do ...
#if ETK_DEBUG_LEVEL > 2 #if ETK_DEBUG_LEVEL > 3
mode = "FILE_TYPE_DIRECT"; mode = "FILE_TYPE_DIRECT";
#endif #endif
needUnpack = true; needUnpack = true;
break; break;
} }
TK_DEBUG("3 : Get file Name : " << destFilename ); TK_VERBOSE("3 : Get file Name : " << destFilename );
if (true == needUnpack) { if (true == needUnpack) {
// Get the real Path of the current File // Get the real Path of the current File
ok = realpath(destFilename.Utf8Data(), buf); ok = realpath(destFilename.Utf8Data(), buf);
@ -336,10 +336,10 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
// Get the FileName // Get the FileName
etk::UString tmpFilename = destFilename.Extract(lastPos+1); etk::UString tmpFilename = destFilename.Extract(lastPos+1);
destFilename.Remove(lastPos, destFilename.Size() - lastPos); destFilename.Remove(lastPos, destFilename.Size() - lastPos);
TK_DEBUG("try to find :\"" << destFilename << "\" / \"" << tmpFilename << "\" "); TK_VERBOSE("try to find :\"" << destFilename << "\" / \"" << tmpFilename << "\" ");
ok = realpath(destFilename.Utf8Data(), buf); ok = realpath(destFilename.Utf8Data(), buf);
if (!ok) { if (!ok) {
TK_DEBUG("Can not find real Path name of \"" << destFilename << "\""); TK_VERBOSE("Can not find real Path name of \"" << destFilename << "\"");
m_shortFilename = tmpFilename; m_shortFilename = tmpFilename;
m_folder = destFilename; m_folder = destFilename;
} else { } else {
@ -348,7 +348,7 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
m_folder = destFilename; m_folder = destFilename;
} }
} else { } else {
TK_DEBUG("file : \"" << destFilename << "\" ==> No data???"); TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???");
// Basic ERROR ... // Basic ERROR ...
m_shortFilename = destFilename; m_shortFilename = destFilename;
} }
@ -360,7 +360,7 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
m_folder = destFilename.Extract(0, lastPos); m_folder = destFilename.Extract(0, lastPos);
} else { } else {
// Basic ERROR ... // Basic ERROR ...
TK_DEBUG("file : \"" << destFilename << "\" ==> No data???"); TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???");
m_shortFilename = destFilename; m_shortFilename = destFilename;
} }
} }
@ -371,11 +371,11 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
m_folder = destFilename.Extract(0, lastPos); m_folder = destFilename.Extract(0, lastPos);
} else { } else {
// Basic ERROR ... // Basic ERROR ...
TK_DEBUG("file : \"" << destFilename << "\" ==> No data???"); TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???");
m_shortFilename = destFilename; m_shortFilename = destFilename;
} }
} }
TK_DEBUG("Set FileName :\"" << m_folder << "\" / \"" << m_shortFilename << "\" mode=" << mode); TK_VERBOSE("Set FileName :\"" << m_folder << "\" / \"" << m_shortFilename << "\" mode=" << mode);
} }
int32_t etk::File::GetLineNumber(void) int32_t etk::File::GetLineNumber(void)
@ -431,7 +431,7 @@ bool etk::File::LoadDataZip(void)
struct zip_stat zipFileProperty; struct zip_stat zipFileProperty;
zip_stat_init(&zipFileProperty); zip_stat_init(&zipFileProperty);
zip_stat_index(s_APKArchive, m_idZipFile, 0, &zipFileProperty); zip_stat_index(s_APKArchive, m_idZipFile, 0, &zipFileProperty);
TK_DEBUG("LOAD data from the files : \"" << GetCompleateName() << "\""); TK_VERBOSE("LOAD data from the files : \"" << GetCompleateName() << "\"");
/* /*
TK_DEBUG(" name=" << zipFileProperty.name); TK_DEBUG(" name=" << zipFileProperty.name);
TK_DEBUG(" index=" << zipFileProperty.index); TK_DEBUG(" index=" << zipFileProperty.index);

View File

@ -113,8 +113,8 @@ void svg::Base::ParsePosition(const TiXmlNode *node, coord2D_ts &pos, coord2D_ts
{ {
pos.x = 0; pos.x = 0;
pos.y = 0; pos.y = 0;
size.x = m_paint.viewPort.x; size.x = 0;
size.y = m_paint.viewPort.y; size.y = 0;
const char * content = node->ToElement()->Attribute("x"); const char * content = node->ToElement()->Attribute("x");
if (NULL != content) { if (NULL != content) {
@ -243,6 +243,7 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
m_paint.stroke = ParseColor(outputValue); m_paint.stroke = ParseColor(outputValue);
} else if (0 == strcmp(outputType, "stroke-width") ) { } else if (0 == strcmp(outputType, "stroke-width") ) {
m_paint.strokeWidth = ParseLength(outputValue); m_paint.strokeWidth = ParseLength(outputValue);
//SVG_ERROR(" input : \"" << outputValue << "\" ==> " <<m_paint.strokeWidth);
} else if (0 == strcmp(outputType, "opacity") ) { } else if (0 == strcmp(outputType, "opacity") ) {
etkFloat_t opacity = ParseLength(outputValue); etkFloat_t opacity = ParseLength(outputValue);
opacity = etk_max(0.0, etk_min(1.0, opacity)); opacity = etk_max(0.0, etk_min(1.0, opacity));
@ -264,6 +265,28 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
} else { } else {
SVG_ERROR("not know " << outputType << " value : \"" << outputValue << "\", not in [nonzero,evenodd]"); SVG_ERROR("not know " << outputType << " value : \"" << outputValue << "\", not in [nonzero,evenodd]");
} }
} else if (0 == strcmp(outputType, "stroke-linecap") ) {
if (0 == strcmp(outputValue, "butt") ) {
m_paint.lineCap = svg::LINECAP_BUTT;
} else if (0 == strcmp(outputValue, "round") ) {
m_paint.lineCap = svg::LINECAP_ROUND;
} else if (0 == strcmp(outputValue, "square") ) {
m_paint.lineCap = svg::LINECAP_SQUARE;
} else {
m_paint.lineCap = svg::LINECAP_BUTT;
SVG_ERROR("not know " << outputType << " value : \"" << outputValue << "\", not in [butt,round,square]");
}
} else if (0 == strcmp(outputType, "stroke-linejoin") ) {
if (0 == strcmp(outputValue, "miter") ) {
m_paint.lineJoin = svg::LINEJOIN_MITER;
} else if (0 == strcmp(outputValue, "round") ) {
m_paint.lineJoin = svg::LINEJOIN_ROUND;
} else if (0 == strcmp(outputValue, "bevel") ) {
m_paint.lineJoin = svg::LINEJOIN_BEVEL;
} else {
m_paint.lineJoin = svg::LINEJOIN_MITER;
SVG_ERROR("not know " << outputType << " value : \"" << outputValue << "\", not in [miter,round,bevel]");
}
} else { } else {
SVG_ERROR("not know painting element in style balise : \"" << outputType << "\" with value : \"" << outputValue << "\""); SVG_ERROR("not know painting element in style balise : \"" << outputType << "\" with value : \"" << outputValue << "\"");
} }
@ -580,9 +603,11 @@ color8_ts svg::Base::ParseColor(const char *inputData)
* @param[in] node standart XML node * @param[in] node standart XML node
* @return true if no problem arrived * @return true if no problem arrived
*/ */
bool svg::Base::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Base::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
SVG_ERROR("NOT IMPLEMENTED"); SVG_ERROR("NOT IMPLEMENTED");
sizeMax.x = 0;
sizeMax.y = 0;
return false; return false;
} }

View File

@ -54,7 +54,7 @@ namespace svg
Base(void) {}; Base(void) {};
Base(PaintState parentPaintState); Base(PaintState parentPaintState);
~Base(void) { }; ~Base(void) { };
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
//specific drawing for AAG librairy ... //specific drawing for AAG librairy ...
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans) { }; virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans) { };

View File

@ -38,7 +38,7 @@ svg::Circle::~Circle(void)
} }
bool svg::Circle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Circle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
m_radius = 0.0; m_radius = 0.0;
m_position.x = 0.0; m_position.x = 0.0;
@ -70,6 +70,8 @@ bool svg::Circle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
SVG_ERROR("(l "<<node->Row()<<") Circle \"r\" is negative"); SVG_ERROR("(l "<<node->Row()<<") Circle \"r\" is negative");
return false; return false;
} }
sizeMax.x = m_position.x + m_radius;
sizeMax.y = m_position.y + m_radius;
return true; return true;
} }
@ -92,11 +94,13 @@ void svg::Circle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTra
// set the filling mode : // set the filling mode :
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
agg::conv_transform<agg::ellipse, agg::trans_affine> trans(myCircle, mtx); if (m_paint.fill.alpha != 0x00) {
myRenderer.m_rasterizer.add_path(trans); agg::conv_transform<agg::ellipse, agg::trans_affine> trans(myCircle, mtx);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); myRenderer.m_rasterizer.add_path(trans);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
}
if (m_paint.strokeWidth > 0) { if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) {
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha));
// Drawing as an outline // Drawing as an outline
agg::conv_stroke<agg::ellipse> myCircleStroke(myCircle); agg::conv_stroke<agg::ellipse> myCircleStroke(myCircle);

View File

@ -37,7 +37,7 @@ namespace svg
public: public:
Circle(PaintState parentPaintState); Circle(PaintState parentPaintState);
~Circle(void); ~Circle(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -37,7 +37,7 @@ svg::Ellipse::~Ellipse(void)
} }
bool svg::Ellipse::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Ellipse::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
ParseTransform(node); ParseTransform(node);
ParsePaintAttr(node); ParsePaintAttr(node);
@ -72,6 +72,8 @@ bool svg::Ellipse::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
SVG_ERROR("(l "<<node->Row()<<") Ellipse \"ry\" is not present"); SVG_ERROR("(l "<<node->Row()<<") Ellipse \"ry\" is not present");
return false; return false;
} }
sizeMax.x = m_c.x + m_r.x;
sizeMax.y = m_c.y + m_r.y;
return true; return true;
} }
@ -95,11 +97,13 @@ void svg::Ellipse::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr
// set the filling mode : // set the filling mode :
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
agg::conv_transform<agg::ellipse, agg::trans_affine> trans(myEllipse, mtx); if (m_paint.fill.alpha != 0x00) {
myRenderer.m_rasterizer.add_path(trans); agg::conv_transform<agg::ellipse, agg::trans_affine> trans(myEllipse, mtx);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); myRenderer.m_rasterizer.add_path(trans);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
}
if (m_paint.strokeWidth > 0) { if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) {
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha));
// Drawing as an outline // Drawing as an outline
agg::conv_stroke<agg::ellipse> myEllipseStroke(myEllipse); agg::conv_stroke<agg::ellipse> myEllipseStroke(myEllipse);

View File

@ -37,7 +37,7 @@ namespace svg
public: public:
Ellipse(PaintState parentPaintState); Ellipse(PaintState parentPaintState);
~Ellipse(void); ~Ellipse(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -46,7 +46,7 @@ svg::Group::~Group(void)
} }
bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
// parse ... // parse ...
coord2D_ts pos; coord2D_ts pos;
@ -61,6 +61,9 @@ bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
SVG_VERBOSE("parsed G2. trans : (" << m_transformMatrix.sx << "," << m_transformMatrix.shy << "," << m_transformMatrix.shx << "," << m_transformMatrix.sy << "," << m_transformMatrix.tx << "," << m_transformMatrix.ty << ")"); SVG_VERBOSE("parsed G2. trans : (" << m_transformMatrix.sx << "," << m_transformMatrix.shy << "," << m_transformMatrix.shx << "," << m_transformMatrix.sy << "," << m_transformMatrix.tx << "," << m_transformMatrix.ty << ")");
sizeMax.x = 0;
sizeMax.y = 0;
coord2D_ts tmpPos;
// parse all sub node : // parse all sub node :
for(TiXmlNode * child = node->FirstChild(); NULL != child; child = child->NextSibling() ) { for(TiXmlNode * child = node->FirstChild(); NULL != child; child = child->NextSibling() ) {
svg::Base *elementParser = NULL; svg::Base *elementParser = NULL;
@ -94,11 +97,13 @@ bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
if (NULL == elementParser) { if (NULL == elementParser) {
SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" allocation error or not supported ..."); SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" allocation error or not supported ...");
} else { } else {
if (false == elementParser->Parse(child, m_transformMatrix)) { if (false == elementParser->Parse(child, m_transformMatrix, tmpPos)) {
SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" Sub Parsing ERROR"); SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" Sub Parsing ERROR");
delete(elementParser); delete(elementParser);
elementParser = NULL; elementParser = NULL;
} else { } else {
sizeMax.x = etk_max(sizeMax.x, tmpPos.x);
sizeMax.y = etk_max(sizeMax.y, tmpPos.y);
// add element in the system // add element in the system
m_subElementList.PushBack(elementParser); m_subElementList.PushBack(elementParser);
} }
@ -110,7 +115,7 @@ bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
void svg::Group::Display(int32_t spacing) void svg::Group::Display(int32_t spacing)
{ {
SVG_DEBUG(SpacingDist(spacing) << "Group (START) fill=" << m_paint.fill << " stroke=" << m_paint.stroke); SVG_DEBUG(SpacingDist(spacing) << "Group (START) fill=" << m_paint.fill << " stroke=" << m_paint.stroke << " stroke-width=" << m_paint.strokeWidth );
for (int32_t iii=0; iii<m_subElementList.Size(); iii++) { for (int32_t iii=0; iii<m_subElementList.Size(); iii++) {
if (NULL != m_subElementList[iii]) { if (NULL != m_subElementList[iii]) {
m_subElementList[iii]->Display(spacing+1); m_subElementList[iii]->Display(spacing+1);

View File

@ -37,7 +37,7 @@ namespace svg
public: public:
Group(PaintState parentPaintState); Group(PaintState parentPaintState);
~Group(void); ~Group(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -40,7 +40,7 @@ svg::Line::~Line(void)
} }
bool svg::Line::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Line::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
// line must have a minimum size... // line must have a minimum size...
m_paint.strokeWidth = 1; m_paint.strokeWidth = 1;
@ -66,6 +66,8 @@ bool svg::Line::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
if (NULL != content) { if (NULL != content) {
m_stopPos.y = ParseLength(content); m_stopPos.y = ParseLength(content);
} }
sizeMax.x = etk_max(m_startPos.x, m_stopPos.x);
sizeMax.y = etk_max(m_startPos.y, m_stopPos.y);
return true; return true;
} }
@ -81,8 +83,31 @@ void svg::Line::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans
path.start_new_path(); path.start_new_path();
path.move_to(m_startPos.x, m_startPos.y); path.move_to(m_startPos.x, m_startPos.y);
path.line_to(m_stopPos.x, m_stopPos.y); path.line_to(m_stopPos.x, m_stopPos.y);
//path.close_polygon(); /*
// configure the end of the line :
switch (m_paint.lineCap) {
case svg::LINECAP_SQUARE:
path.line_cap(agg::square_cap);
break;
case svg::LINECAP_ROUND:
path.line_cap(agg::round_cap);
break;
default: // svg::LINECAP_BUTT
path.line_cap(agg::butt_cap);
break;
}
switch (m_paint.lineJoin) {
case svg::LINEJOIN_BEVEL:
path.line_join(agg::bevel_join);
break;
case svg::LINEJOIN_ROUND:
path.line_join(agg::round_join);
break;
default: // svg::LINEJOIN_MITER
path.line_join(agg::miter_join);
break;
}
*/
agg::trans_affine mtx = m_transformMatrix; agg::trans_affine mtx = m_transformMatrix;
mtx *= basicTrans; mtx *= basicTrans;

View File

@ -37,7 +37,7 @@ namespace svg
public: public:
Line(PaintState parentPaintState); Line(PaintState parentPaintState);
~Line(void); ~Line(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -24,6 +24,11 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Path.h> #include <parserSVG/Path.h>
#include <agg-2.4/agg_conv_stroke.h>
#include <agg-2.4/agg_conv_dash.h>
#include <agg-2.4/agg_conv_curve.h>
#include <agg-2.4/agg_conv_contour.h>
#include <agg-2.4/agg_conv_smooth_poly1.h>
svg::Path::Path(PaintState parentPaintState) : svg::Base(parentPaintState) svg::Path::Path(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
@ -50,7 +55,7 @@ const char * extractCmd(const char * input, char& cmd, etk::VectorType<float>& o
return NULL; return NULL;
} }
cmd = input[0]; cmd = input[0];
SVG_DEBUG("Find command : " << cmd); SVG_VERBOSE("Find command : " << cmd);
if (input[1] == '\0') { if (input[1] == '\0') {
return &input[1]; return &input[1];
} }
@ -59,8 +64,9 @@ const char * extractCmd(const char * input, char& cmd, etk::VectorType<float>& o
float element; float element;
char spacer[10]; char spacer[10];
int32_t nbElementRead; int32_t nbElementRead;
while(sscanf(&input[iii], "%1[, ]%f%n", spacer, &element, &nbElementRead) == 2) { while( sscanf(&input[iii], "%1[, ]%f%n", spacer, &element, &nbElementRead) == 2
SVG_DEBUG("Find element : " << element); || sscanf(&input[iii], "%f%n", &element, &nbElementRead) == 1) {
SVG_VERBOSE("Find element : " << element);
outputList.PushBack(element); outputList.PushBack(element);
iii += nbElementRead; iii += nbElementRead;
} }
@ -72,7 +78,7 @@ const char * extractCmd(const char * input, char& cmd, etk::VectorType<float>& o
return outputPointer; return outputPointer;
} }
bool svg::Path::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Path::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
ParseTransform(node); ParseTransform(node);
ParsePaintAttr(node); ParsePaintAttr(node);
@ -80,18 +86,13 @@ bool svg::Path::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
// add the property of the parrent modifications ... // add the property of the parrent modifications ...
m_transformMatrix *= parentTrans; m_transformMatrix *= parentTrans;
//m_listElement
const char *elementXML = node->ToElement()->Attribute("d"); const char *elementXML = node->ToElement()->Attribute("d");
if (NULL == elementXML) { if (NULL == elementXML) {
SVG_ERROR("(l "<<node->Row()<<") path: missing 'p' attribute"); SVG_ERROR("(l "<<node->Row()<<") path: missing 'p' attribute");
return false; return false;
} }
SVG_DEBUG("Parse Path : \"" << elementXML << "\""); SVG_VERBOSE("Parse Path : \"" << elementXML << "\"");
coord2D_ts currentPos;
currentPos.x = 0;
currentPos.y = 0;
char command; char command;
etk::VectorType<float> listDot; etk::VectorType<float> listDot;
@ -99,8 +100,184 @@ bool svg::Path::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
for( const char *sss=extractCmd(elementXML, command, listDot); for( const char *sss=extractCmd(elementXML, command, listDot);
NULL != sss; NULL != sss;
sss=extractCmd(sss, command, listDot) ) { sss=extractCmd(sss, command, listDot) ) {
pathBasic_ts pathElement;
// later ... memset(&pathElement, 0, 1*sizeof(pathBasic_ts));
switch(command) {
case 'M': // Move To (absolute)
case 'L': // Line To (absolute)
case 'V': // Vertical Line To (absolute)
case 'H': // Horizantal Line To (absolute)
case 'Q': // Quadratic Bezier curve (absolute)
case 'T': // smooth quadratic Bezier curve to (absolute)
case 'C': // curve to (absolute)
case 'S': // smooth curve to (absolute)
case 'A': // elliptical Arc (absolute)
case 'Z': // closepath (absolute)
pathElement.relative = false;
break;
default : // else (relative)
pathElement.relative = true;
break;
}
switch(command) {
case 'M': // Move To (absolute)
case 'm': // Move To (relative)
// 2 Elements ...
if(listDot.Size()%2 != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_MOVETO;
for(int32_t iii=0; iii<listDot.Size(); iii+=2) {
pathElement.element[0] = listDot[iii];
pathElement.element[1] = listDot[iii+1];
m_listElement.PushBack(pathElement);
}
break;
case 'L': // Line To (absolute)
case 'l': // Line To (relative)
// 2 Elements ...
if(listDot.Size()%2 != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_LINETO;
for(int32_t iii=0; iii<listDot.Size(); iii+=2) {
pathElement.element[0] = listDot[iii];
pathElement.element[1] = listDot[iii+1];
m_listElement.PushBack(pathElement);
}
break;
case 'V': // Vertical Line To (absolute)
case 'v': // Vertical Line To (relative)
// 1 Element ...
if(listDot.Size() == 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_LINETO_V;
for(int32_t iii=0; iii<listDot.Size(); iii+=1) {
pathElement.element[0] = listDot[iii];
m_listElement.PushBack(pathElement);
}
break;
case 'H': // Horizantal Line To (absolute)
case 'h': // Horizantal Line To (relative)
// 1 Element ...
if(listDot.Size() == 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_LINETO_H;
for(int32_t iii=0; iii<listDot.Size(); iii+=1) {
pathElement.element[0] = listDot[iii];
m_listElement.PushBack(pathElement);
}
break;
case 'Q': // Quadratic Bezier curve (absolute)
case 'q': // Quadratic Bezier curve (relative)
// 4 Elements ...
if(listDot.Size()%4 != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_BEZIER_CURVETO;
for(int32_t iii=0; iii<listDot.Size(); iii+=4) {
pathElement.element[0] = listDot[iii];
pathElement.element[1] = listDot[iii+1];
pathElement.element[2] = listDot[iii+2];
pathElement.element[3] = listDot[iii+3];
m_listElement.PushBack(pathElement);
}
break;
case 'T': // smooth quadratic Bezier curve to (absolute)
case 't': // smooth quadratic Bezier curve to (relative)
// 2 Elements ...
if(listDot.Size()%2 != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_BEZIER_SMOTH_CURVETO;
for(int32_t iii=0; iii<listDot.Size(); iii+=2) {
pathElement.element[0] = listDot[iii];
pathElement.element[1] = listDot[iii+1];
m_listElement.PushBack(pathElement);
}
break;
case 'C': // curve to (absolute)
case 'c': // curve to (relative)
// 6 Elements ...
if(listDot.Size()%6 != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_CURVETO;
for(int32_t iii=0; iii<listDot.Size(); iii+=6) {
pathElement.element[0] = listDot[iii];
pathElement.element[1] = listDot[iii+1];
pathElement.element[2] = listDot[iii+2];
pathElement.element[3] = listDot[iii+3];
pathElement.element[4] = listDot[iii+4];
pathElement.element[5] = listDot[iii+5];
m_listElement.PushBack(pathElement);
}
break;
case 'S': // smooth curve to (absolute)
case 's': // smooth curve to (relative)
// 4 Elements ...
if(listDot.Size()%4 != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_SMOTH_CURVETO;
for(int32_t iii=0; iii<listDot.Size(); iii+=4) {
pathElement.element[0] = listDot[iii];
pathElement.element[1] = listDot[iii+1];
pathElement.element[2] = listDot[iii+2];
pathElement.element[3] = listDot[iii+3];
m_listElement.PushBack(pathElement);
}
break;
case 'A': // elliptical Arc (absolute)
case 'a': // elliptical Arc (relative)
// 7 Elements ...
if(listDot.Size()%7 != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_ELLIPTIC;
for(int32_t iii=0; iii<listDot.Size(); iii+=7) {
pathElement.element[0] = listDot[iii];
pathElement.element[1] = listDot[iii+1];
pathElement.element[2] = listDot[iii+2];
pathElement.element[3] = listDot[iii+3];
pathElement.element[4] = listDot[iii+4];
pathElement.element[5] = listDot[iii+5];
pathElement.element[6] = listDot[iii+6];
m_listElement.PushBack(pathElement);
}
break;
case 'Z': // closepath (absolute)
case 'z': // closepath (relative)
// 0 Element ...
if(listDot.Size() != 0) {
SVG_WARNING("the PATH command "<< command << " has not the good number of element = " << listDot.Size() );
break;
}
pathElement.cmd = svg::PATH_ENUM_STOP;
m_listElement.PushBack(pathElement);
break;
default:
SVG_ERROR ("Unknow error : \"" << command << "\"");
}
} }
return true; return true;
@ -112,3 +289,184 @@ void svg::Path::Display(int32_t spacing)
} }
void svg::Path::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans)
{
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha));
agg::path_storage path;
path.start_new_path();
for(int32_t iii=0; iii<m_listElement.Size(); iii++) {
switch (m_listElement[iii].cmd) {
case PATH_ENUM_STOP:
AbstractCloseSubpath(path);
break;
case PATH_ENUM_MOVETO:
AbstractMoveTo(path, m_listElement[iii].relative,
m_listElement[iii].element[0],
m_listElement[iii].element[1] );
break;
case PATH_ENUM_LINETO:
AbstractLineTo(path, m_listElement[iii].relative,
m_listElement[iii].element[0],
m_listElement[iii].element[1] );
break;
case PATH_ENUM_LINETO_H:
AbstractHLineTo(path, m_listElement[iii].relative,
m_listElement[iii].element[0] );
break;
case PATH_ENUM_LINETO_V:
AbstractVLineTo(path, m_listElement[iii].relative,
m_listElement[iii].element[0] );
break;
case PATH_ENUM_CURVETO:
AbstractCurve4(path, m_listElement[iii].relative,
m_listElement[iii].element[0],
m_listElement[iii].element[1],
m_listElement[iii].element[2],
m_listElement[iii].element[3],
m_listElement[iii].element[4],
m_listElement[iii].element[5] );
//SVG_INFO(" draw : PATH_ENUM_CURVETO");
break;
case PATH_ENUM_SMOTH_CURVETO:
AbstractCurve4(path, m_listElement[iii].relative,
m_listElement[iii].element[0],
m_listElement[iii].element[1],
m_listElement[iii].element[2],
m_listElement[iii].element[3] );
//SVG_INFO(" draw : PATH_ENUM_SMOTH_CURVETO");
break;
case PATH_ENUM_BEZIER_CURVETO:
AbstractCurve3(path, m_listElement[iii].relative,
m_listElement[iii].element[0],
m_listElement[iii].element[1],
m_listElement[iii].element[2],
m_listElement[iii].element[3] );
//SVG_INFO(" draw : PATH_ENUM_BEZIER_CURVETO");
break;
case PATH_ENUM_BEZIER_SMOTH_CURVETO:
AbstractCurve3(path, m_listElement[iii].relative,
m_listElement[iii].element[0],
m_listElement[iii].element[1] );
//SVG_INFO(" draw : PATH_ENUM_BEZIER_SMOTH_CURVETO");
break;
case PATH_ENUM_ELLIPTIC:
SVG_TODO("Elliptic arc is not implemented NOW ...");
break;
default:
SVG_ERROR("Unknow PATH commant (internal error)");
break;
}
}
agg::trans_affine mtx = m_transformMatrix;
mtx *= basicTrans;
agg::conv_curve<agg::path_storage> curve(path);
if (m_paint.fill.alpha != 0x00) {
agg::conv_transform<agg::conv_curve<agg::path_storage>, agg::trans_affine> trans(curve, mtx);
// set the filling mode :
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
myRenderer.m_rasterizer.add_path(trans);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
}
if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) {
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha));
// Drawing as an outline
agg::conv_stroke<agg::conv_curve<agg::path_storage> > myPolygonStroke(curve);
myPolygonStroke.width(m_paint.strokeWidth);
agg::conv_transform<agg::conv_stroke<agg::conv_curve<agg::path_storage> >, agg::trans_affine> transStroke(myPolygonStroke, mtx);
// set the filling mode :
myRenderer.m_rasterizer.filling_rule(agg::fill_non_zero);
myRenderer.m_rasterizer.add_path(transStroke);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
}
}
void svg::Path::AbstractMoveTo(agg::path_storage& path, bool rel, double x, double y)
{
if(true == rel) {
path.rel_to_abs(&x, &y);
}
path.move_to(x, y);
}
void svg::Path::AbstractLineTo(agg::path_storage& path, bool rel, double x, double y)
{
if(true == rel) {
path.rel_to_abs(&x, &y);
}
path.line_to(x, y);
}
void svg::Path::AbstractHLineTo(agg::path_storage& path, bool rel, double x)
{
double x2 = 0.0;
double y2 = 0.0;
if(0!=path.total_vertices()) {
path.vertex(path.total_vertices() - 1, &x2, &y2);
if(true == rel) {
x += x2;
}
path.line_to(x, y2);
}
}
void svg::Path::AbstractVLineTo(agg::path_storage& path, bool rel, double y)
{
double x2 = 0.0;
double y2 = 0.0;
if(path.total_vertices()) {
path.vertex(path.total_vertices() - 1, &x2, &y2);
if(true == rel) {
y += y2;
}
path.line_to(x2, y);
}
}
void svg::Path::AbstractCurve3(agg::path_storage& path, bool rel, double x1, double y1, double x, double y)
{
if(true == rel) {
path.rel_to_abs(&x1, &y1);
path.rel_to_abs(&x, &y);
}
path.curve3(x1, y1, x, y);
}
void svg::Path::AbstractCurve3(agg::path_storage& path, bool rel, double x, double y)
{
if(true == rel) {
path.curve3_rel(x, y);
} else {
path.curve3(x, y);
}
}
void svg::Path::AbstractCurve4(agg::path_storage& path, bool rel, double x1, double y1, double x2, double y2, double x, double y)
{
if(true == rel) {
path.rel_to_abs(&x1, &y1);
path.rel_to_abs(&x2, &y2);
path.rel_to_abs(&x, &y);
}
path.curve4(x1, y1, x2, y2, x, y);
}
void svg::Path::AbstractCurve4(agg::path_storage& path, bool rel, double x2, double y2, double x, double y)
{
if(true == rel) {
path.curve4_rel(x2, y2, x, y);
} else {
path.curve4(x2, y2, x, y);
}
}
void svg::Path::AbstractCloseSubpath(agg::path_storage& path)
{
path.end_poly(agg::path_flags_close);
}

View File

@ -26,13 +26,16 @@
#define __SVG_PATH_H__ #define __SVG_PATH_H__
#include <parserSVG/Base.h> #include <parserSVG/Base.h>
#include <agg-2.4/agg_path_storage.h>
namespace svg namespace svg
{ {
typedef enum { typedef enum {
PATH_ENUM_STOP, PATH_ENUM_STOP,
PATH_ENUM_GOTO, PATH_ENUM_MOVETO,
PATH_ENUM_LINETO, PATH_ENUM_LINETO,
PATH_ENUM_LINETO_H,
PATH_ENUM_LINETO_V,
PATH_ENUM_CURVETO, PATH_ENUM_CURVETO,
PATH_ENUM_SMOTH_CURVETO, PATH_ENUM_SMOTH_CURVETO,
PATH_ENUM_BEZIER_CURVETO, PATH_ENUM_BEZIER_CURVETO,
@ -42,45 +45,8 @@ namespace svg
typedef struct { typedef struct {
pathEnum_te cmd; pathEnum_te cmd;
union { bool relative;
struct{ etkFloat_t element[7];
etkFloat_t x;
etkFloat_t y;
} position_s;
struct{
etkFloat_t x1;
etkFloat_t y1;
etkFloat_t x2;
etkFloat_t y2;
etkFloat_t x3;
etkFloat_t y3;
}curveto_s;
struct{
etkFloat_t x1;
etkFloat_t y1;
etkFloat_t x2;
etkFloat_t y2;
}shorthandSmoothCurveto_s;
struct{
etkFloat_t x1;
etkFloat_t y1;
etkFloat_t x2;
etkFloat_t y2;
}quadraticBezierCurveto_s;
struct{
etkFloat_t x;
etkFloat_t y;
} shorthandSmoothQuadraticBezierCurveto_s;
struct{
etkFloat_t rx;
etkFloat_t ry;
etkFloat_t rotation;
etkFloat_t large_arc;
etkFloat_t sweep;
etkFloat_t x;
etkFloat_t y;
}ellipticArc_s;
};
}pathBasic_ts; }pathBasic_ts;
class Path : public svg::Base class Path : public svg::Base
@ -90,8 +56,19 @@ namespace svg
public: public:
Path(PaintState parentPaintState); Path(PaintState parentPaintState);
~Path(void); ~Path(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
private:
void AbstractMoveTo(agg::path_storage& path, bool rel, double x, double y);
void AbstractLineTo(agg::path_storage& path, bool rel, double x, double y);
void AbstractHLineTo(agg::path_storage& path, bool rel, double x);
void AbstractVLineTo(agg::path_storage& path, bool rel, double y);
void AbstractCurve3(agg::path_storage& path, bool rel, double x1, double y1, double x, double y);
void AbstractCurve3(agg::path_storage& path, bool rel, double x, double y);
void AbstractCurve4(agg::path_storage& path, bool rel, double x1, double y1, double x2, double y2, double x, double y);
void AbstractCurve4(agg::path_storage& path, bool rel, double x2, double y2, double x, double y);
void AbstractCloseSubpath(agg::path_storage& path);
}; };
}; };

View File

@ -37,7 +37,7 @@ svg::Polygon::~Polygon(void)
} }
bool svg::Polygon::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Polygon::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
ParseTransform(node); ParseTransform(node);
ParsePaintAttr(node); ParsePaintAttr(node);
@ -54,6 +54,8 @@ bool svg::Polygon::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
SVG_ERROR("(l "<<node->Row()<<") polygon: missing points attribute"); SVG_ERROR("(l "<<node->Row()<<") polygon: missing points attribute");
return false; return false;
} }
sizeMax.x = 0;
sizeMax.y = 0;
SVG_VERBOSE("Parse polygon : \"" << sss << "\""); SVG_VERBOSE("Parse polygon : \"" << sss << "\"");
while ('\0' != sss[0]) { while ('\0' != sss[0]) {
coord2D_ts pos; coord2D_ts pos;
@ -61,6 +63,8 @@ bool svg::Polygon::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
if (sscanf(sss, "%f,%f %n", &pos.x, &pos.y, &n) == 2) { if (sscanf(sss, "%f,%f %n", &pos.x, &pos.y, &n) == 2) {
m_listPoint.PushBack(pos); m_listPoint.PushBack(pos);
sss += n; sss += n;
sizeMax.x = etk_max(sizeMax.x, pos.x);
sizeMax.y = etk_max(sizeMax.y, pos.y);
} else { } else {
break; break;
} }
@ -85,19 +89,44 @@ void svg::Polygon::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr
path.line_to(m_listPoint[iii].x, m_listPoint[iii].y); path.line_to(m_listPoint[iii].x, m_listPoint[iii].y);
} }
path.close_polygon(); path.close_polygon();
/*
// configure the end of the line :
switch (m_paint.lineCap) {
case svg::LINECAP_SQUARE:
path.line_cap(agg::square_cap);
break;
case svg::LINECAP_ROUND:
path.line_cap(agg::round_cap);
break;
default: // svg::LINECAP_BUTT
path.line_cap(agg::butt_cap);
break;
}
switch (m_paint.lineJoin) {
case svg::LINEJOIN_BEVEL:
path.line_join(agg::bevel_join);
break;
case svg::LINEJOIN_ROUND:
path.line_join(agg::round_join);
break;
default: // svg::LINEJOIN_MITER
path.line_join(agg::miter_join);
break;
}
*/
agg::trans_affine mtx = m_transformMatrix; agg::trans_affine mtx = m_transformMatrix;
mtx *= basicTrans; mtx *= basicTrans;
agg::conv_transform<agg::path_storage, agg::trans_affine> trans(path, mtx); if (m_paint.fill.alpha != 0x00) {
// set the filling mode : agg::conv_transform<agg::path_storage, agg::trans_affine> trans(path, mtx);
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); // set the filling mode :
myRenderer.m_rasterizer.add_path(trans); myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); myRenderer.m_rasterizer.add_path(trans);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
}
if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) {
if (m_paint.strokeWidth > 0) {
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha));
// Drawing as an outline // Drawing as an outline
agg::conv_stroke<agg::path_storage> myPolygonStroke(path); agg::conv_stroke<agg::path_storage> myPolygonStroke(path);

View File

@ -42,7 +42,7 @@ namespace svg
public: public:
Polygon(PaintState parentPaintState); Polygon(PaintState parentPaintState);
~Polygon(void); ~Polygon(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -37,7 +37,7 @@ svg::Polyline::~Polyline(void)
} }
bool svg::Polyline::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Polyline::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
// line must have a minimum size... // line must have a minimum size...
m_paint.strokeWidth = 1; m_paint.strokeWidth = 1;
@ -52,12 +52,16 @@ bool svg::Polyline::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
SVG_ERROR("(l "<<node->Row()<<") polyline: missing points attribute"); SVG_ERROR("(l "<<node->Row()<<") polyline: missing points attribute");
return false; return false;
} }
sizeMax.x = 0;
sizeMax.y = 0;
SVG_VERBOSE("Parse polyline : \"" << sss << "\""); SVG_VERBOSE("Parse polyline : \"" << sss << "\"");
while ('\0' != sss[0]) { while ('\0' != sss[0]) {
coord2D_ts pos; coord2D_ts pos;
int32_t n; int32_t n;
if (sscanf(sss, "%f,%f %n", &pos.x, &pos.y, &n) == 2) { if (sscanf(sss, "%f,%f %n", &pos.x, &pos.y, &n) == 2) {
m_listPoint.PushBack(pos); m_listPoint.PushBack(pos);
sizeMax.x = etk_max(sizeMax.x, pos.x);
sizeMax.y = etk_max(sizeMax.y, pos.y);
sss += n; sss += n;
} else { } else {
break; break;
@ -80,7 +84,31 @@ void svg::Polyline::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicT
for( int32_t iii=1; iii< m_listPoint.Size(); iii++) { for( int32_t iii=1; iii< m_listPoint.Size(); iii++) {
path.line_to(m_listPoint[iii].x, m_listPoint[iii].y); path.line_to(m_listPoint[iii].x, m_listPoint[iii].y);
} }
//path.close_polygon(); /*
// configure the end of the line :
switch (m_paint.lineCap) {
case svg::LINECAP_SQUARE:
path.line_cap(agg::square_cap);
break;
case svg::LINECAP_ROUND:
path.line_cap(agg::round_cap);
break;
default: // svg::LINECAP_BUTT
path.line_cap(agg::butt_cap);
break;
}
switch (m_paint.lineJoin) {
case svg::LINEJOIN_BEVEL:
path.line_join(agg::bevel_join);
break;
case svg::LINEJOIN_ROUND:
path.line_join(agg::round_join);
break;
default: // svg::LINEJOIN_MITER
path.line_join(agg::miter_join);
break;
}
*/
agg::trans_affine mtx = m_transformMatrix; agg::trans_affine mtx = m_transformMatrix;
mtx *= basicTrans; mtx *= basicTrans;

View File

@ -37,7 +37,7 @@ namespace svg
public: public:
Polyline(PaintState parentPaintState); Polyline(PaintState parentPaintState);
~Polyline(void); ~Polyline(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -42,7 +42,7 @@ svg::Rectangle::~Rectangle(void)
} }
bool svg::Rectangle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Rectangle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
m_position.x = 0.0; m_position.x = 0.0;
m_position.y = 0.0; m_position.y = 0.0;
@ -67,6 +67,8 @@ bool svg::Rectangle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans)
if (NULL != content) { if (NULL != content) {
m_roundedCorner.y = ParseLength(content); m_roundedCorner.y = ParseLength(content);
} }
sizeMax.x = m_position.x + m_size.x + m_paint.strokeWidth;
sizeMax.y = m_position.y + m_size.y + m_paint.strokeWidth;
return true; return true;
} }
@ -79,7 +81,7 @@ void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basic
{ {
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha)); myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha));
// Creating a rounded rectangle // Creating a rounded rectangle
agg::rounded_rect rect_r(m_position.x, m_position.y, m_size.x, m_size.y, m_roundedCorner.x); agg::rounded_rect rect_r(m_position.x, m_position.y, m_position.x+m_size.x, m_position.y+m_size.y, m_roundedCorner.x);
rect_r.radius(m_roundedCorner.x, m_roundedCorner.y); rect_r.radius(m_roundedCorner.x, m_roundedCorner.y);
rect_r.normalize_radius(); rect_r.normalize_radius();
@ -87,13 +89,15 @@ void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basic
// herited modifications ... // herited modifications ...
mtx *= basicTrans; mtx *= basicTrans;
agg::conv_transform<agg::rounded_rect, agg::trans_affine> trans(rect_r, mtx); if (m_paint.fill.alpha != 0x00) {
// set the filling mode : agg::conv_transform<agg::rounded_rect, agg::trans_affine> trans(rect_r, mtx);
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero); // set the filling mode :
myRenderer.m_rasterizer.add_path(trans); myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea); myRenderer.m_rasterizer.add_path(trans);
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
}
if (m_paint.strokeWidth > 0) { if (m_paint.strokeWidth > 0 && m_paint.stroke.alpha!=0x00 ) {
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha)); myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.red, m_paint.stroke.green, m_paint.stroke.blue, m_paint.stroke.alpha));
// Drawing as an outline // Drawing as an outline
agg::conv_stroke<agg::rounded_rect> rect_p(rect_r); agg::conv_stroke<agg::rounded_rect> rect_p(rect_r);

View File

@ -38,7 +38,7 @@ namespace svg
public: public:
Rectangle(PaintState parentPaintState); Rectangle(PaintState parentPaintState);
~Rectangle(void); ~Rectangle(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -40,13 +40,25 @@
namespace svg namespace svg
{ {
#define MATRIX_SIZE (6) typedef enum {
LINECAP_BUTT,
LINECAP_ROUND,
LINECAP_SQUARE,
} lineCap_te;
typedef enum {
LINEJOIN_MITER,
LINEJOIN_ROUND,
LINEJOIN_BEVEL,
} lineJoin_te;
class PaintState { class PaintState {
public: public:
color8_ts fill; color8_ts fill;
color8_ts stroke; color8_ts stroke;
etkFloat_t strokeWidth; etkFloat_t strokeWidth;
bool flagEvenOdd; bool flagEvenOdd;
lineCap_te lineCap;
lineJoin_te lineJoin;
coord2D_ts viewPort; coord2D_ts viewPort;
}; };

View File

@ -35,8 +35,10 @@ svg::Text::~Text(void)
} }
bool svg::Text::Parse(TiXmlNode * node, agg::trans_affine& parentTrans) bool svg::Text::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax)
{ {
sizeMax.x = 0;
sizeMax.y = 0;
SVG_ERROR("NOT IMPLEMENTED"); SVG_ERROR("NOT IMPLEMENTED");
return false; return false;
} }

View File

@ -36,7 +36,7 @@ namespace svg
public: public:
Text(PaintState parentPaintState); Text(PaintState parentPaintState);
~Text(void); ~Text(void);
virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans); virtual bool Parse(TiXmlNode * node, agg::trans_affine& parentTrans, coord2D_ts& sizeMax);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
}; };
}; };

View File

@ -62,11 +62,14 @@ svg::Parser::Parser(etk::File fileName)
m_paint.stroke.blue = 0xFF; m_paint.stroke.blue = 0xFF;
m_paint.stroke.alpha = 0; m_paint.stroke.alpha = 0;
m_paint.strokeWidth = 0xFF; m_paint.strokeWidth = 1.0;
m_paint.viewPort.x = 0xFF; m_paint.viewPort.x = 255;
m_paint.viewPort.y = 0xFF; m_paint.viewPort.y = 255;
m_paint.flagEvenOdd = false; m_paint.flagEvenOdd = false;
m_paint.lineJoin = svg::LINEJOIN_MITER;
m_paint.lineCap = svg::LINECAP_BUTT;
m_size.x = 0.0;
m_size.y = 0.0;
// Start loading the XML : // Start loading the XML :
SVG_DEBUG("open file (SVG) \"" << m_fileName << "\""); SVG_DEBUG("open file (SVG) \"" << m_fileName << "\"");
@ -111,13 +114,17 @@ svg::Parser::Parser(etk::File fileName)
} }
// parse ... // parse ...
coord2D_ts pos; coord2D_ts pos;
coord2D_ts size;
ParseTransform(root); ParseTransform(root);
ParsePosition(root, pos, size); ParsePosition(root, pos, m_size);
ParsePaintAttr(root); ParsePaintAttr(root);
SVG_VERBOSE("parsed .ROOT trans : (" << m_transformMatrix.sx << "," << m_transformMatrix.shy << "," << m_transformMatrix.shx << "," << m_transformMatrix.sy << "," << m_transformMatrix.tx << "," << m_transformMatrix.ty << ")"); SVG_VERBOSE("parsed .ROOT trans : (" << m_transformMatrix.sx << "," << m_transformMatrix.shy << "," << m_transformMatrix.shx << "," << m_transformMatrix.sy << "," << m_transformMatrix.tx << "," << m_transformMatrix.ty << ")");
coord2D_ts maxSize;
maxSize.x = 0.0;
maxSize.y = 0.0;
coord2D_ts size;
// parse all sub node : // parse all sub node :
for(TiXmlNode * child = root->FirstChild(); NULL != child; child = child->NextSibling() ) { for(TiXmlNode * child = root->FirstChild(); NULL != child; child = child->NextSibling() ) {
svg::Base *elementParser = NULL; svg::Base *elementParser = NULL;
@ -125,10 +132,15 @@ svg::Parser::Parser(etk::File fileName)
// nothing to do, just proceed to next step // nothing to do, just proceed to next step
} else { } else {
etk::UString localValue = child->Value(); etk::UString localValue = child->Value();
bool normalNoElement = false;
if (localValue == "g") { if (localValue == "g") {
elementParser = new svg::Group(m_paint); elementParser = new svg::Group(m_paint);
} else if (localValue == "a") { } else if (localValue == "a") {
// TODO ... SVG_INFO("Note : 'a' balise is parsed like a g balise ...");
elementParser = new svg::Group(m_paint);
} else if (localValue == "title") {
m_title = "TODO : set the title here ...";
normalNoElement = true;
} else if (localValue == "path") { } else if (localValue == "path") {
elementParser = new svg::Path(m_paint); elementParser = new svg::Path(m_paint);
} else if (localValue == "rect") { } else if (localValue == "rect") {
@ -146,24 +158,38 @@ svg::Parser::Parser(etk::File fileName)
} else if (localValue == "text") { } else if (localValue == "text") {
elementParser = new svg::Text(m_paint); elementParser = new svg::Text(m_paint);
} else { } else {
SVG_ERROR("(l "<<child->Row()<<") node not suported : \""<<localValue<<"\" must be [g,a,path,rect,circle,ellipse,line,polyline,polygon,text]"); SVG_ERROR("(l "<<child->Row()<<") node not suported : \""<<localValue<<"\" must be [title,g,a,path,rect,circle,ellipse,line,polyline,polygon,text]");
} }
if (NULL == elementParser) { if (false == normalNoElement) {
SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" allocation error or not supported ..."); if (NULL == elementParser) {
} else { SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" allocation error or not supported ...");
if (false == elementParser->Parse(child, m_transformMatrix)) {
SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" Sub Parsing ERROR");
delete(elementParser);
elementParser = NULL;
} else { } else {
// add element in the system if (false == elementParser->Parse(child, m_transformMatrix, size)) {
m_subElementList.PushBack(elementParser); SVG_ERROR("(l "<<child->Row()<<") error on node: \""<<localValue<<"\" Sub Parsing ERROR");
delete(elementParser);
elementParser = NULL;
} else {
if (maxSize.x<size.x) {
maxSize.x=size.x;
}
if (maxSize.y<size.y) {
maxSize.y=size.y;
}
// add element in the system
m_subElementList.PushBack(elementParser);
}
} }
} }
} }
} }
if (m_size.x==0 || m_size.y==0) {
m_size.x=(int32_t)maxSize.x;
m_size.y=(int32_t)maxSize.y;
} else {
m_size.x=(int32_t)m_size.x;
m_size.y=(int32_t)m_size.y;
}
} }
if (NULL != fileBuffer) { if (NULL != fileBuffer) {
delete[] fileBuffer; delete[] fileBuffer;
} }
@ -178,7 +204,7 @@ svg::Parser::~Parser(void)
void svg::Parser::DisplayDebug(void) void svg::Parser::DisplayDebug(void)
{ {
SVG_DEBUG("Main SVG node : "); SVG_DEBUG("Main SVG node : size=" << m_size);
for (int32_t iii=0; iii<m_subElementList.Size(); iii++) { for (int32_t iii=0; iii<m_subElementList.Size(); iii++) {
if (NULL != m_subElementList[iii]) { if (NULL != m_subElementList[iii]) {
m_subElementList[iii]->Display(1); m_subElementList[iii]->Display(1);
@ -200,18 +226,23 @@ void svg::Parser::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTra
void svg::Parser::GenerateTestFile(void) void svg::Parser::GenerateTestFile(void)
{ {
float coefmult = 2; float coefmult = 2;
int width = 800*coefmult; int32_t SizeX = m_size.x;
int height = 600*coefmult; if (SizeX == 0) {
SizeX = 50;
svg::Renderer * myRenderer = new svg::Renderer(width, height); }
int32_t SizeY = m_size.y;
if (SizeY == 0) {
SizeY = 50;
}
svg::Renderer * myRenderer = new svg::Renderer(SizeX, SizeY);
// create the first element matrix modification ... // create the first element matrix modification ...
agg::trans_affine basicTrans; agg::trans_affine basicTrans;
//basicTrans *= agg::trans_affine_translation(-g_base_dx, -g_base_dy); //basicTrans *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
basicTrans *= agg::trans_affine_scaling(2, 2); //basicTrans *= agg::trans_affine_scaling(2, 2);
//basicTrans *= agg::trans_affine_rotation(g_angle);// + agg::pi); //basicTrans *= agg::trans_affine_rotation(g_angle);// + agg::pi);
//basicTrans *= agg::trans_affine_skewing(2.0, 5.0); //basicTrans *= agg::trans_affine_skewing(2.0, 5.0);
//basicTrans *= agg::trans_affine_translation(width*0.3, height/2); //basicTrans *= agg::trans_affine_translation(width*0.3, height/2);
basicTrans *= agg::trans_affine_translation(width/2, height/2); //basicTrans *= agg::trans_affine_translation(width/3, height/3);
AggDraw(*myRenderer, basicTrans); AggDraw(*myRenderer, basicTrans);

View File

@ -37,7 +37,9 @@ namespace svg
etk::File m_fileName; etk::File m_fileName;
bool m_loadOK; bool m_loadOK;
etk::UString m_version; etk::UString m_version;
etk::UString m_title;
etk::VectorType<svg::Base *> m_subElementList; etk::VectorType<svg::Base *> m_subElementList;
coord2D_ts m_size;
public: public:
Parser(etk::File fileName); Parser(etk::File fileName);