Parsig of a basic svg is nowOK ==> many function is not OK ...

This commit is contained in:
Edouard Dupin 2012-03-22 17:45:05 +01:00
parent 08289ff4fd
commit 7598763314
24 changed files with 468 additions and 114 deletions

View File

@ -70,7 +70,7 @@ namespace etk{
return *this; return *this;
} }
CCout& operator << (unsigned int t) { CCout& operator << (unsigned int t) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "%d", t); snprintf(tmp, MAX_LOG_SIZE_TMP, "%u", t);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE); strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this; return *this;
} }
@ -144,6 +144,11 @@ namespace etk{
strncat(m_tmpChar, tmp, MAX_LOG_SIZE); strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this; return *this;
} }
CCout& operator << (color8_ts t) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "#%02X%02X%02X%02X", t.red, t.green, t.blue, t.alpha);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (clipping_ts t) { CCout& operator << (clipping_ts t) {
snprintf(tmp, MAX_LOG_SIZE_TMP, "origin=(%f,%f) size=(%f,%f)", t.x, t.y, t.w, t.h); snprintf(tmp, MAX_LOG_SIZE_TMP, "origin=(%f,%f) size=(%f,%f)", t.x, t.y, t.w, t.h);
strncat(m_tmpChar, tmp, MAX_LOG_SIZE); strncat(m_tmpChar, tmp, MAX_LOG_SIZE);

View File

@ -99,6 +99,13 @@ extern "C"
etkFloat_t blue; etkFloat_t blue;
etkFloat_t alpha; etkFloat_t alpha;
}color_ts; }color_ts;
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t alpha;
}color8_ts;
} }

View File

@ -27,7 +27,7 @@
#include <parserSVG/Base.h> #include <parserSVG/Base.h>
#include <math.h> #include <math.h>
svg::Base::Base(paintState_ts parentPaintState) svg::Base::Base(PaintState parentPaintState)
{ {
// copy the parent painting properties ... // copy the parent painting properties ...
m_paint = parentPaintState; m_paint = parentPaintState;
@ -231,54 +231,278 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
} }
} }
} }
typedef struct {
const char * colorName;
uint32_t color;
} colorList_ts;
const colorList_ts listOfColor[] = {
{ "none", 0x00000000},
{ "AliceBlue", 0xF0F8FFFF},
{ "AntiqueWhite", 0xFAEBD7FF},
{ "Aqua", 0x00FFFFFF},
{ "Aquamarine", 0x7FFFD4FF},
{ "Azure", 0xF0FFFFFF},
{ "Beige", 0xF5F5DCFF},
{ "Bisque", 0xFFE4C4FF},
{ "Black", 0x000000FF},
{ "BlanchedAlmond", 0xFFEBCDFF},
{ "Blue", 0x0000FFFF},
{ "BlueViolet", 0x8A2BE2FF},
{ "Brown", 0xA52A2AFF},
{ "BurlyWood", 0xDEB887FF},
{ "CadetBlue", 0x5F9EA0FF},
{ "Chartreuse", 0x7FFF00FF},
{ "Chocolate", 0xD2691EFF},
{ "Coral", 0xFF7F50FF},
{ "CornflowerBlue", 0x6495EDFF},
{ "Cornsilk", 0xFFF8DCFF},
{ "Crimson", 0xDC143CFF},
{ "Cyan", 0x00FFFFFF},
{ "DarkBlue", 0x00008BFF},
{ "DarkCyan", 0x008B8BFF},
{ "DarkGoldenRod", 0xB8860BFF},
{ "DarkGray", 0xA9A9A9FF},
{ "DarkGrey", 0xA9A9A9FF},
{ "DarkGreen", 0x006400FF},
{ "DarkKhaki", 0xBDB76BFF},
{ "DarkMagenta", 0x8B008BFF},
{ "DarkOliveGreen", 0x556B2FFF},
{ "Darkorange", 0xFF8C00FF},
{ "DarkOrchid", 0x9932CCFF},
{ "DarkRed", 0x8B0000FF},
{ "DarkSalmon", 0xE9967AFF},
{ "DarkSeaGreen", 0x8FBC8FFF},
{ "DarkSlateBlue", 0x483D8BFF},
{ "DarkSlateGray", 0x2F4F4FFF},
{ "DarkSlateGrey", 0x2F4F4FFF},
{ "DarkTurquoise", 0x00CED1FF},
{ "DarkViolet", 0x9400D3FF},
{ "DeepPink", 0xFF1493FF},
{ "DeepSkyBlue", 0x00BFFFFF},
{ "DimGray", 0x696969FF},
{ "DimGrey", 0x696969FF},
{ "DodgerBlue", 0x1E90FFFF},
{ "FireBrick", 0xB22222FF},
{ "FloralWhite", 0xFFFAF0FF},
{ "ForestGreen", 0x228B22FF},
{ "Fuchsia", 0xFF00FFFF},
{ "Gainsboro", 0xDCDCDCFF},
{ "GhostWhite", 0xF8F8FFFF},
{ "Gold", 0xFFD700FF},
{ "GoldenRod", 0xDAA520FF},
{ "Gray", 0x808080FF},
{ "Grey", 0x808080FF},
{ "Green", 0x008000FF},
{ "GreenYellow", 0xADFF2FFF},
{ "HoneyDew", 0xF0FFF0FF},
{ "HotPink", 0xFF69B4FF},
{ "IndianRed ", 0xCD5C5CFF},
{ "Indigo ", 0x4B0082FF},
{ "Ivory", 0xFFFFF0FF},
{ "Khaki", 0xF0E68CFF},
{ "Lavender", 0xE6E6FAFF},
{ "LavenderBlush", 0xFFF0F5FF},
{ "LawnGreen", 0x7CFC00FF},
{ "LemonChiffon", 0xFFFACDFF},
{ "LightBlue", 0xADD8E6FF},
{ "LightCoral", 0xF08080FF},
{ "LightCyan", 0xE0FFFFFF},
{ "LightGoldenRodYellow", 0xFAFAD2FF},
{ "LightGray", 0xD3D3D3FF},
{ "LightGrey", 0xD3D3D3FF},
{ "LightGreen", 0x90EE90FF},
{ "LightPink", 0xFFB6C1FF},
{ "LightSalmon", 0xFFA07AFF},
{ "LightSeaGreen", 0x20B2AAFF},
{ "LightSkyBlue", 0x87CEFAFF},
{ "LightSlateGray", 0x778899FF},
{ "LightSlateGrey", 0x778899FF},
{ "LightSteelBlue", 0xB0C4DEFF},
{ "LightYellow", 0xFFFFE0FF},
{ "Lime", 0x00FF00FF},
{ "LimeGreen", 0x32CD32FF},
{ "Linen", 0xFAF0E6FF},
{ "Magenta", 0xFF00FFFF},
{ "Maroon", 0x800000FF},
{ "MediumAquaMarine", 0x66CDAAFF},
{ "MediumBlue", 0x0000CDFF},
{ "MediumOrchid", 0xBA55D3FF},
{ "MediumPurple", 0x9370D8FF},
{ "MediumSeaGreen", 0x3CB371FF},
{ "MediumSlateBlue", 0x7B68EEFF},
{ "MediumSpringGreen", 0x00FA9AFF},
{ "MediumTurquoise", 0x48D1CCFF},
{ "MediumVioletRed", 0xC71585FF},
{ "MidnightBlue", 0x191970FF},
{ "MintCream", 0xF5FFFAFF},
{ "MistyRose", 0xFFE4E1FF},
{ "Moccasin", 0xFFE4B5FF},
{ "NavajoWhite", 0xFFDEADFF},
{ "Navy", 0x000080FF},
{ "OldLace", 0xFDF5E6FF},
{ "Olive", 0x808000FF},
{ "OliveDrab", 0x6B8E23FF},
{ "Orange", 0xFFA500FF},
{ "OrangeRed", 0xFF4500FF},
{ "Orchid", 0xDA70D6FF},
{ "PaleGoldenRod", 0xEEE8AAFF},
{ "PaleGreen", 0x98FB98FF},
{ "PaleTurquoise", 0xAFEEEEFF},
{ "PaleVioletRed", 0xD87093FF},
{ "PapayaWhip", 0xFFEFD5FF},
{ "PeachPuff", 0xFFDAB9FF},
{ "Peru", 0xCD853FFF},
{ "Pink", 0xFFC0CBFF},
{ "Plum", 0xDDA0DDFF},
{ "PowderBlue", 0xB0E0E6FF},
{ "Purple", 0x800080FF},
{ "Red", 0xFF0000FF},
{ "RosyBrown", 0xBC8F8FFF},
{ "RoyalBlue", 0x4169E1FF},
{ "SaddleBrown", 0x8B4513FF},
{ "Salmon", 0xFA8072FF},
{ "SandyBrown", 0xF4A460FF},
{ "SeaGreen", 0x2E8B57FF},
{ "SeaShell", 0xFFF5EEFF},
{ "Sienna", 0xA0522DFF},
{ "Silver", 0xC0C0C0FF},
{ "SkyBlue", 0x87CEEBFF},
{ "SlateBlue", 0x6A5ACDFF},
{ "SlateGray", 0x708090FF},
{ "SlateGrey", 0x708090FF},
{ "Snow", 0xFFFAFAFF},
{ "SpringGreen", 0x00FF7FFF},
{ "SteelBlue", 0x4682B4FF},
{ "Tan", 0xD2B48CFF},
{ "Teal", 0x008080FF},
{ "Thistle", 0xD8BFD8FF},
{ "Tomato", 0xFF6347FF},
{ "Turquoise", 0x40E0D0FF},
{ "Violet", 0xEE82EEFF},
{ "Wheat", 0xF5DEB3FF},
{ "White", 0xFFFFFFFF},
{ "WhiteSmoke", 0xF5F5F5FF},
{ "Yellow", 0xFFFF00FF},
{ "YellowGreen", 0x9ACD32FF}
};
const int32_t listOfColorSize = sizeof(listOfColor) / sizeof(colorList_ts);
bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen)
{
int32_t iii=0;
while ('\0' != *input1 && '\0' != *input2 && iii < maxLen) {
char in1 = *input1;
char in2 = *input2;
if (in1 != in2) {
if (in1 <= 'Z' && in1 >= 'A') {
in1 = in1 - 'A' + 'a';
}
if (in2 <= 'Z' && in2 >= 'A') {
in2 = in2 - 'A' + 'a';
}
if (in1 != in2) {
return false;
}
}
iii++;
input1++;
input2++;
}
return true;
}
/** /**
* @brief Parse a color specification from the svg file * @brief Parse a color specification from the svg file
* @param[in] inputData Data C String with the xml definition * @param[in] inputData Data C String with the xml definition
* @return the parsed color * @return the parsed color
*/ */
color_ts svg::Base::ParseColor(const char *inputData) color8_ts svg::Base::ParseColor(const char *inputData)
{ {
color_ts localColor; color8_ts localColor;
localColor.red =1.0; localColor.red =0xFF;
localColor.green=1.0; localColor.green=0xFF;
localColor.blue =1.0; localColor.blue =0xFF;
localColor.alpha=1.0; localColor.alpha=0xFF;
uint32_t red, green, blue; uint32_t red, green, blue, alpha;
float fred, fgreen, fblue, falpha;
size_t len = strlen(inputData); size_t len = strlen(inputData);
if( len == 4 if( len >=1
&& inputData[0] == '#') { && inputData[0] == '#') {
if (sscanf(inputData + 1, "%1x%1x%1x", &red, &green, &blue) == 3) { if(len == 4) {
localColor.red = (etkFloat_t)(red | red << 4) / 256.0; if (sscanf(inputData + 1, "%1x%1x%1x", &red, &green, &blue) == 3) {
localColor.green= (etkFloat_t)(green | green << 4) / 256.0; localColor.red = (red | red << 4);
localColor.blue = (etkFloat_t)(blue | blue << 4) / 256.0; localColor.green= (green | green << 4);
localColor.blue = (blue | blue << 4);
} else {
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\"");
}
} else if (len==5) {
if (sscanf(inputData + 1, "%1x%1x%1x%1x", &red, &green, &blue, &alpha) == 4) {
localColor.red = (red | red << 4);
localColor.green = (green | green << 4);
localColor.blue = (blue | blue << 4);
localColor.alpha = (alpha | alpha << 4);
} else {
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\"");
}
} else if (len == 7) {
if (sscanf(inputData + 1, "%2x%2x%2x", &red, &green, &blue) == 3) {
localColor.red = red;
localColor.green= green;
localColor.blue = blue;
} else {
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\"");
}
} else if (len == 9) {
if (sscanf(inputData + 1, "%2x%2x%2x%2x", &red, &green, &blue, &alpha) == 4) {
localColor.red = red;
localColor.green= green;
localColor.blue = blue;
localColor.alpha = alpha;
} else {
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\"");
}
} else {
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> unknown methode ...");
} }
} else if( len == 7 } else if( 4 <= len
&& 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[0] == 'r'
&& inputData[1] == 'g' && inputData[1] == 'g'
&& inputData[2] == 'b' && inputData[2] == 'b'
&& inputData[3] == '(' && inputData[3] == '(' ) {
&& inputData[len - 1] == ')') { if (sscanf(inputData + 4, "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
if (sscanf(inputData + 4, "%u,%u,%u", &red, &green, &blue) == 3) { localColor.red = etk_min(0xFF, red);
localColor.red = (etkFloat_t)(red) / 256.0; localColor.green= etk_min(0xFF, green);
localColor.green= (etkFloat_t)(green) / 256.0; localColor.blue = etk_min(0xFF, blue);
localColor.blue = (etkFloat_t)(blue) / 256.0; localColor.alpha = etk_min(0xFF, alpha);
} else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%", &localColor.red, &localColor.green, &localColor.blue) == 3) { } else if (sscanf(inputData + 4, "%u,%u,%u", &red, &green, &blue) == 3) {
// nothing to do ... localColor.red = etk_min(0xFF, red);
localColor.green= etk_min(0xFF, green);
localColor.blue = etk_min(0xFF, blue);
} else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%,%f%%", &fred, &fgreen, &fblue, &falpha) == 4) {
fred = etk_max(0.0, etk_min(1.0, fred));
fgreen= etk_max(0.0, etk_min(1.0, fgreen));
fblue = etk_max(0.0, etk_min(1.0, fblue));
falpha = etk_max(0.0, etk_min(1.0, falpha));
localColor.red = (uint8_t)(fred * 255.);
localColor.green= (uint8_t)(fgreen * 255.);
localColor.blue = (uint8_t)(fblue * 255.);
localColor.alpha = (uint8_t)(falpha * 255.);
} else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%", &fred, &fgreen, &fblue) == 3) {
fred = etk_max(0.0, etk_min(1.0, fred));
fgreen= etk_max(0.0, etk_min(1.0, fgreen));
fblue = etk_max(0.0, etk_min(1.0, fblue));
localColor.red = (uint8_t)(fred * 255.);
localColor.green= (uint8_t)(fgreen * 255.);
localColor.blue = (uint8_t)(fblue * 255.);
} else {
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> unknown methode ...");
} }
} else if( len == 4 } else if( 4 < len
&& strcmp(inputData, "none") == 0) {
localColor.alpha=0.0;
} else if( 5 < len
&& inputData[0] == 'u' && inputData[0] == 'u'
&& inputData[1] == 'r' && inputData[1] == 'r'
&& inputData[2] == 'l' && inputData[2] == 'l'
@ -286,9 +510,28 @@ color_ts svg::Base::ParseColor(const char *inputData)
if (inputData[4] == '#') { if (inputData[4] == '#') {
// TODO : parse gradient ... // TODO : parse gradient ...
} }
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> url(XXX) is not supported now ...");
} else { } else {
// TODO : Might be a named color ... need to find it ... bool findIt = false;
// direct named color ...
for (int32_t iii=0; iii<listOfColorSize; iii++) {
if (strnCmpNoCase(listOfColor[iii].colorName, inputData, strlen(listOfColor[iii].colorName)) == true) {
findIt = true;
localColor.red = (uint8_t)((0xFF000000 & listOfColor[iii].color) >> 24) ;
localColor.green= (uint8_t)((0x00FF0000 & listOfColor[iii].color) >> 16) ;
localColor.blue = (uint8_t)((0x0000FF00 & listOfColor[iii].color) >> 8) ;
localColor.alpha = (uint8_t)(0x000000FF & listOfColor[iii].color) ;
// stop searching
break;
}
}
// or color in reference ...
if (findIt == false) {
// TODO : Might be a named color ... need to find it ...
SVG_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> refs color not supported now ...");
}
} }
SVG_VERBOSE("Parse color : \"" << inputData << "\" ==> " << localColor);
return localColor; return localColor;
} }
@ -311,4 +554,18 @@ const char * svg::Base::SpacingDist(int32_t spacing)
spacing = 20; spacing = 20;
} }
return tmpValue + 20*4 - spacing*4; return tmpValue + 20*4 - spacing*4;
} }
void svg::Base::AggCheckChange(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
{
if (curentPaintProp != m_paint) {
SVG_INFO("add path color = " << m_paint.fill);
// New color. Every new color creates new path in the path object.
colors.PushBack(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha));
uint32_t tmpPathNew = path.start_new_path();
pathIdx.PushBack(tmpPathNew);
curentPaintProp = m_paint;
}
}

View File

@ -44,33 +44,68 @@
namespace svg namespace svg
{ {
#define MATRIX_SIZE (6) #define MATRIX_SIZE (6)
typedef struct { class PaintState {
color_ts fill; public :
color_ts stroke; PaintState(void) {};
etkFloat_t strokeWidth; ~PaintState(void) {};
coord2D_ts viewPort; color8_ts fill;
etkFloat_t matrix[MATRIX_SIZE]; color8_ts stroke;
} paintState_ts; etkFloat_t strokeWidth;
coord2D_ts viewPort;
etkFloat_t matrix[MATRIX_SIZE];
bool operator!= (const svg::PaintState& paintExt) const
{
if( fill.red != paintExt.fill.red
|| fill.green != paintExt.fill.green
|| fill.blue != paintExt.fill.blue
|| fill.alpha != paintExt.fill.alpha) {
return true;
}
if( stroke.red != paintExt.stroke.red
|| stroke.green != paintExt.stroke.green
|| stroke.blue != paintExt.stroke.blue
|| stroke.alpha != paintExt.stroke.alpha) {
return true;
}
if (strokeWidth != paintExt.strokeWidth) {
return true;
}
if( viewPort.x != paintExt.viewPort.x
|| viewPort.y != paintExt.viewPort.y) {
return true;
}
if( matrix[0] != paintExt.matrix[0]
|| matrix[1] != paintExt.matrix[1]
|| matrix[2] != paintExt.matrix[2]
|| matrix[3] != paintExt.matrix[3]
|| matrix[4] != paintExt.matrix[4]
|| matrix[5] != paintExt.matrix[5]) {
return true;
}
return false;
}
};
class Base class Base
{ {
protected: protected:
paintState_ts m_paint; PaintState m_paint;
const char * SpacingDist(int32_t spacing); const char * SpacingDist(int32_t spacing);
public: public:
Base(void) {}; Base(void) {};
Base(paintState_ts parentPaintState); Base(PaintState parentPaintState);
~Base(void) { }; ~Base(void) { };
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
//specific drawing for AAG librairy ... //specific drawing for AAG librairy ...
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx) { }; virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp) { };
virtual void AggCheckChange(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp);
virtual void Display(int32_t spacing) { }; virtual void Display(int32_t spacing) { };
void ParseTransform(TiXmlNode *node); void ParseTransform(TiXmlNode *node);
void ParsePosition(const TiXmlNode *node, coord2D_ts &pos, coord2D_ts &size); void ParsePosition(const TiXmlNode *node, coord2D_ts &pos, coord2D_ts &size);
etkFloat_t ParseLength(const char *dataInput); etkFloat_t ParseLength(const char *dataInput);
void ParsePaintAttr(const TiXmlNode *node); void ParsePaintAttr(const TiXmlNode *node);
color_ts ParseColor(const char *inputData); color8_ts ParseColor(const char *inputData);
}; };
}; };

View File

@ -25,7 +25,7 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Circle.h> #include <parserSVG/Circle.h>
svg::Circle::Circle(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Circle::Circle(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
} }

View File

@ -35,7 +35,7 @@ namespace svg
coord2D_ts m_position; //!< Position of the Circle coord2D_ts m_position; //!< Position of the Circle
etkFloat_t m_radius; //!< Radius of the Circle etkFloat_t m_radius; //!< Radius of the Circle
public: public:
Circle(paintState_ts parentPaintState); Circle(PaintState parentPaintState);
~Circle(void); ~Circle(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);

View File

@ -25,7 +25,7 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Ellipse.h> #include <parserSVG/Ellipse.h>
svg::Ellipse::Ellipse(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Ellipse::Ellipse(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
} }

View File

@ -35,7 +35,7 @@ namespace svg
coord2D_ts m_c; //!< C property of the ellipse coord2D_ts m_c; //!< C property of the ellipse
coord2D_ts m_r; //!< R property of the ellipse coord2D_ts m_r; //!< R property of the ellipse
public: public:
Ellipse(paintState_ts parentPaintState); Ellipse(PaintState parentPaintState);
~Ellipse(void); ~Ellipse(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);

View File

@ -36,7 +36,7 @@
#include <parserSVG/Text.h> #include <parserSVG/Text.h>
#include <parserSVG/Group.h> #include <parserSVG/Group.h>
svg::Group::Group(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Group::Group(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
} }
@ -104,7 +104,7 @@ bool svg::Group::Parse(TiXmlNode * node)
void svg::Group::Display(int32_t spacing) void svg::Group::Display(int32_t spacing)
{ {
SVG_DEBUG(SpacingDist(spacing) << "Group (START)"); SVG_DEBUG(SpacingDist(spacing) << "Group (START) fill=" << m_paint.fill << " stroke=" << m_paint.stroke);
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);
@ -113,20 +113,12 @@ void svg::Group::Display(int32_t spacing)
SVG_DEBUG(SpacingDist(spacing) << "Group (STOP)"); SVG_DEBUG(SpacingDist(spacing) << "Group (STOP)");
} }
void svg::Group::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx) void svg::Group::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
{ {
uint32_t tmpColor = 0; AggCheckChange(path, colors, pathIdx, curentPaintProp);
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++) { for (int32_t iii=0; iii<m_subElementList.Size(); iii++) {
if (NULL != m_subElementList[iii]) { if (NULL != m_subElementList[iii]) {
m_subElementList[iii]->AggDraw(path, colors, pathIdx); m_subElementList[iii]->AggDraw(path, colors, pathIdx, curentPaintProp);
} }
} }

View File

@ -35,11 +35,11 @@ namespace svg
private: private:
etk::VectorType<svg::Base *> m_subElementList; //!< group sub elements ... etk::VectorType<svg::Base *> m_subElementList; //!< group sub elements ...
public: public:
Group(paintState_ts parentPaintState); Group(PaintState parentPaintState);
~Group(void); ~Group(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx); virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp);
}; };
}; };

View File

@ -25,7 +25,7 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Line.h> #include <parserSVG/Line.h>
svg::Line::Line(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Line::Line(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
m_startPos.x = 0.0; m_startPos.x = 0.0;
m_startPos.y = 0.0; m_startPos.y = 0.0;

View File

@ -35,7 +35,7 @@ namespace svg
coord2D_ts m_startPos; //!< Start line position coord2D_ts m_startPos; //!< Start line position
coord2D_ts m_stopPos; //!< Stop line position coord2D_ts m_stopPos; //!< Stop line position
public: public:
Line(paintState_ts parentPaintState); Line(PaintState parentPaintState);
~Line(void); ~Line(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);

View File

@ -25,7 +25,7 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Path.h> #include <parserSVG/Path.h>
svg::Path::Path(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Path::Path(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
} }

View File

@ -34,7 +34,7 @@ namespace svg
private: private:
public: public:
Path(paintState_ts parentPaintState); Path(PaintState parentPaintState);
~Path(void); ~Path(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);

View File

@ -25,7 +25,7 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Polygon.h> #include <parserSVG/Polygon.h>
svg::Polygon::Polygon(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Polygon::Polygon(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
} }
@ -65,11 +65,13 @@ void svg::Polygon::Display(int32_t spacing)
} }
void svg::Polygon::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx) void svg::Polygon::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
{ {
if (m_listPoint.Size()<2) { if (m_listPoint.Size()<2) {
// nothing to draw ... // nothing to draw ...
return;
} }
AggCheckChange(path, colors, pathIdx, curentPaintProp);
path.move_to(m_listPoint[0].x, m_listPoint[0].y); path.move_to(m_listPoint[0].x, m_listPoint[0].y);
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);

View File

@ -40,11 +40,11 @@ namespace svg
etk::VectorType<coord2D_ts> m_listPoint; //!< list of all point of the polygone etk::VectorType<coord2D_ts> m_listPoint; //!< list of all point of the polygone
PolygonMode_te m_diplayMode; //!< polygone specific display mode PolygonMode_te m_diplayMode; //!< polygone specific display mode
public: public:
Polygon(paintState_ts parentPaintState); Polygon(PaintState parentPaintState);
~Polygon(void); ~Polygon(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx); virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp);
}; };
}; };

View File

@ -25,7 +25,7 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Polyline.h> #include <parserSVG/Polyline.h>
svg::Polyline::Polyline(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Polyline::Polyline(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
} }

View File

@ -35,7 +35,7 @@ namespace svg
private: private:
etk::VectorType<coord2D_ts> m_listPoint; //!< list of all point of the polyline etk::VectorType<coord2D_ts> m_listPoint; //!< list of all point of the polyline
public: public:
Polyline(paintState_ts parentPaintState); Polyline(PaintState parentPaintState);
~Polyline(void); ~Polyline(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);

View File

@ -24,8 +24,10 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Rectangle.h> #include <parserSVG/Rectangle.h>
#include <agg-2.4/agg_rounded_rect.h>
#include <agg-2.4/agg_conv_stroke.h>
svg::Rectangle::Rectangle(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Rectangle::Rectangle(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
m_position.x = 0.0; m_position.x = 0.0;
m_position.y = 0.0; m_position.y = 0.0;
@ -59,6 +61,37 @@ bool svg::Rectangle::Parse(TiXmlNode * node)
void svg::Rectangle::Display(int32_t spacing) void svg::Rectangle::Display(int32_t spacing)
{ {
SVG_DEBUG(SpacingDist(spacing) << "Rectangle"); SVG_DEBUG(SpacingDist(spacing) << "Rectangle : pos=" << m_position << " size=" << m_size << " corner=" << m_roundedCorner);
} }
void svg::Rectangle::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
{
if (m_size.x<=0 && m_size.y<=0) {
// nothing to draw ...
return;
}
AggCheckChange(path, colors, pathIdx, curentPaintProp);
#if 1
path.move_to(m_position.x, m_position.y);
//path.move_to(0, 0);
path.line_rel(m_size.x, 0);
path.line_rel(0, m_size.y);
path.line_rel(-m_size.x, 0);
path.line_rel(0, -m_size.y);
path.close_polygon();
#else
// Creating a rounded rectangle
agg::rounded_rect r(m_position.x, m_position.y, m_size.x, m_size.y, m_roundedCorner.x);
r.normalize_radius();
// Drawing as an outline
agg::conv_stroke<agg::rounded_rect> p(r);
p.width(1.0);
path.add_path(p);
#endif
}

View File

@ -36,10 +36,11 @@ namespace svg
coord2D_ts m_size; //!< size of the rectangle coord2D_ts m_size; //!< size of the rectangle
coord2D_ts m_roundedCorner; //!< property of the rounded corner coord2D_ts m_roundedCorner; //!< property of the rounded corner
public: public:
Rectangle(paintState_ts parentPaintState); Rectangle(PaintState parentPaintState);
~Rectangle(void); ~Rectangle(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp);
}; };
}; };

View File

@ -25,7 +25,7 @@
#include <parserSVG/Debug.h> #include <parserSVG/Debug.h>
#include <parserSVG/Text.h> #include <parserSVG/Text.h>
svg::Text::Text(paintState_ts parentPaintState) : svg::Base(parentPaintState) svg::Text::Text(PaintState parentPaintState) : svg::Base(parentPaintState)
{ {
} }

View File

@ -34,7 +34,7 @@ namespace svg
private: private:
public: public:
Text(paintState_ts parentPaintState); Text(PaintState parentPaintState);
~Text(void); ~Text(void);
virtual bool Parse(TiXmlNode * node); virtual bool Parse(TiXmlNode * node);
virtual void Display(int32_t spacing); virtual void Display(int32_t spacing);

View File

@ -52,19 +52,19 @@ svg::Parser::Parser(etk::File fileName)
m_fileName = fileName; m_fileName = fileName;
m_version = "0.0"; m_version = "0.0";
m_loadOK = false; m_loadOK = false;
m_paint.fill.red = 1.0; m_paint.fill.red = 0xFF;
m_paint.fill.green = 1.0; m_paint.fill.green = 0;
m_paint.fill.blue = 1.0; m_paint.fill.blue = 0;
m_paint.fill.alpha = 1.0; m_paint.fill.alpha = 0xFF;
m_paint.stroke.red = 1.0; m_paint.stroke.red = 0xFF;
m_paint.stroke.green = 1.0; m_paint.stroke.green = 0xFF;
m_paint.stroke.blue = 1.0; m_paint.stroke.blue = 0xFF;
m_paint.stroke.alpha = 0.0; m_paint.stroke.alpha = 0;
m_paint.strokeWidth = 1.0; m_paint.strokeWidth = 0xFF;
m_paint.viewPort.x = 1.0; m_paint.viewPort.x = 0xFF;
m_paint.viewPort.y = 1.0; m_paint.viewPort.y = 0xFF;
m_paint.matrix[0] = 1.0; m_paint.matrix[0] = 1.0;
m_paint.matrix[1] = 0.0; m_paint.matrix[1] = 0.0;
m_paint.matrix[2] = 0.0; m_paint.matrix[2] = 0.0;
@ -230,6 +230,10 @@ etk::VectorType<agg::rgba8> g_colorsList2;
etk::VectorType<uint32_t> g_pathLdxList2; etk::VectorType<uint32_t> g_pathLdxList2;
double g_base_dx2 = 0; double g_base_dx2 = 0;
double g_base_dy2 = 0; double g_base_dy2 = 0;
double g_x12 = 0;
double g_y12 = 0;
double g_x22 = 0;
double g_y22 = 0;
uint32_t g_npaths = 0; uint32_t g_npaths = 0;
double g_x1 = 0; double g_x1 = 0;
@ -407,11 +411,12 @@ uint32_t parse_lion(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors
const char* ptr = g_lion; const char* ptr = g_lion;
while(*ptr) { while(*ptr) {
if(*ptr != 'M' && isalnum(*ptr)) { if(*ptr != 'M' && isalnum(*ptr)) {
unsigned c = 0; uint32_t c = 0;
sscanf(ptr, "%x", &c); sscanf(ptr, "%x", &c);
// New color. Every new color creates new path in the path object. // New color. Every new color creates new path in the path object.
path.close_polygon(); path.close_polygon();
SVG_ERROR("printed color 1 = " << c);
colors.PushBack(agg::rgb8_packed(c)); colors.PushBack(agg::rgb8_packed(c));
uint32_t tmpPathNew = path.start_new_path(); uint32_t tmpPathNew = path.start_new_path();
pathIdx.PushBack(tmpPathNew); pathIdx.PushBack(tmpPathNew);
@ -453,43 +458,49 @@ uint32_t parse_lion(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors
} }
void svg::Parser::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx) void svg::Parser::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
{ {
uint32_t tmpColor = 0; SVG_ERROR("printed color X = " << m_paint.fill);
tmpColor = ((int32_t)(m_paint.fill.red*256.))<<24; colors.PushBack(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha));
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(); uint32_t tmpPathNew = path.start_new_path();
pathIdx.PushBack(tmpPathNew); pathIdx.PushBack(tmpPathNew);
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]->AggDraw(path, colors, pathIdx); m_subElementList[iii]->AggDraw(path, colors, pathIdx, curentPaintProp);
} }
} }
// this permit to have not the display of the layer substraction ...
path.arrange_orientations_all_paths(agg::path_flags_cw);
} }
#include <agg-2.4/agg_rounded_rect.h>
#include <agg-2.4/agg_conv_stroke.h>
void svg::Parser::GenerateTestFile(void) void svg::Parser::GenerateTestFile(void)
{ {
g_path.remove_all();
g_colorsList.Clear();
g_pathLdxList.Clear();
uint32_t g_npaths = parse_lion(g_path, g_colorsList, g_pathLdxList); 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::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); 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_dx = (g_x2 - g_x1) / 2.0;
g_base_dy = (g_y2 - g_y1) / 2.0; g_base_dy = (g_y2 - g_y1) / 2.0;
AggDraw(g_path2, g_colorsList2, g_pathLdxList2); g_path2.remove_all();
g_colorsList2.Clear();
g_pathLdxList2.Clear();
PaintState curentPaintProp;
AggDraw(g_path2, g_colorsList2, g_pathLdxList2, curentPaintProp);
agg::pod_array_adaptor<unsigned> path_idx2(&g_pathLdxList2[0], g_pathLdxList2.Size() ); 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); agg::bounding_rect(g_path2, path_idx2, 0, g_pathLdxList2.Size(), &g_x12, &g_y12, &g_x22, &g_y22);
g_base_dx2 = (g_x2 - g_x1) / 2.0; g_base_dx2 = (g_x22 - g_x12) / 2.0;
g_base_dy2 = (g_y2 - g_y1) / 2.0; g_base_dy2 = (g_y22 - g_y12) / 2.0;
int width = 800; float coefmult = 2;
int height = 600; int width = 800*coefmult;
int height = 600*coefmult;
unsigned char* buffer = new unsigned char[width * height * 4]; unsigned char* buffer = new unsigned char[width * height * 4];
memset(buffer, 255, width * height * 4); memset(buffer, 255, width * height * 4);
@ -501,7 +512,7 @@ void svg::Parser::GenerateTestFile(void)
agg::trans_affine mtx; agg::trans_affine mtx;
mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy); mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
mtx *= agg::trans_affine_scaling(g_scale, g_scale); mtx *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi); 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_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
mtx *= agg::trans_affine_translation(width*0.3, height/2); mtx *= agg::trans_affine_translation(width*0.3, height/2);
@ -509,19 +520,30 @@ void svg::Parser::GenerateTestFile(void)
// This code renders the lion: // This code renders the lion:
agg::conv_transform<agg::path_storage, agg::trans_affine> trans(g_path, mtx); 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); agg::render_all_paths(g_rasterizer, g_scanline, r, trans, &g_colorsList[0], &g_pathLdxList[0], g_npaths);
// This code renders a second lion: // This code renders a second svg syctem ...:
agg::trans_affine mtx2; agg::trans_affine mtx2;
mtx2 *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2); mtx2 *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2);
mtx2 *= agg::trans_affine_scaling(g_scale, g_scale); mtx2 *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
mtx2 *= agg::trans_affine_rotation(g_angle);// + agg::pi); mtx2 *= 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_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
mtx2 *= agg::trans_affine_translation(width*0.7, height/2); mtx2 *= agg::trans_affine_translation(width*0.7, height/2);
agg::conv_transform<agg::path_storage, agg::trans_affine> trans2(g_path2, mtx2); agg::conv_transform<agg::path_storage, agg::trans_affine> trans2(g_path2, mtx2);
//g_rasterizer.add_path(trans2);
agg::render_all_paths(g_rasterizer, g_scanline, r, trans2, &g_colorsList2[0], &g_pathLdxList2[0], g_pathLdxList2.Size()); 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"); // Creating a rounded rectangle
agg::rounded_rect rect_r(50, 50, 100, 120, 18);
rect_r.normalize_radius();
// Drawing as an outline
agg::conv_stroke<agg::rounded_rect> rect_p(rect_r);
rect_p.width(1.0);
g_rasterizer.add_path(rect_p);
agg::render_scanlines(g_rasterizer, g_scanline, r);
etk::UString tmpFileOut = etk::UString("zzz_out_") + m_fileName.GetShortFilename() + ".ppm";
write_ppm(buffer, width, height, tmpFileOut.Utf8Data());
delete [] buffer; delete [] buffer;
} }

View File

@ -45,7 +45,7 @@ namespace svg
bool IsLoadOk(void) { return m_loadOK; }; bool IsLoadOk(void) { return m_loadOK; };
void DisplayDebug(void); void DisplayDebug(void);
void GenerateTestFile(void); void GenerateTestFile(void);
virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx); virtual void AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp);
}; };
}; };