[dev] update to the nec vecter implementation

This commit is contained in:
Edouard DUPIN 2013-01-28 08:08:11 +01:00
parent c305574cfd
commit b8287243a8
11 changed files with 82 additions and 109 deletions

View File

@ -111,26 +111,24 @@ void svg::Base::ParseTransform(TiXmlNode *node)
*/
void svg::Base::ParsePosition(const TiXmlNode *node, etk::Vector2D<float> &pos, etk::Vector2D<float> &size)
{
pos.x = 0;
pos.y = 0;
size.x = 0;
size.y = 0;
pos.setValue(0,0);
size.setValue(0,0);
const char * content = node->ToElement()->Attribute("x");
if (NULL != content) {
pos.x = ParseLength(content);
pos.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("y");
if (NULL != content) {
pos.y = ParseLength(content);
pos.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("width");
if (NULL != content) {
size.x = ParseLength(content);
size.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("height");
if (NULL != content) {
size.y = ParseLength(content);
size.setY(ParseLength(content));
}
}
@ -153,7 +151,7 @@ float svg::Base::ParseLength(const char *dataInput)
if (unit[0] == '\0' || unit[0] == ';' ) {
return n;
} else if (unit[0] == '%') { // xxx %
return n / 100.0 * m_paint.viewPort.x;
return n / 100.0 * m_paint.viewPort.x();
} else if (unit[0] == 'e' && unit[1] == 'm') { // xxx em
return n * font_size;
} else if (unit[0] == 'e' && unit[1] == 'x') { // xxx ex
@ -438,8 +436,7 @@ draw::Color svg::Base::ParseColor(const char *inputData)
bool svg::Base::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Vector2D<float>& sizeMax)
{
SVG_ERROR("NOT IMPLEMENTED");
sizeMax.x = 0;
sizeMax.y = 0;
sizeMax.setValue(0,0);
return false;
}

View File

@ -41,8 +41,7 @@ svg::Circle::~Circle(void)
bool svg::Circle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Vector2D<float>& sizeMax)
{
m_radius = 0.0;
m_position.x = 0.0;
m_position.y = 0.0;
m_position.setValue(0,0);;
ParseTransform(node);
ParsePaintAttr(node);
@ -51,11 +50,11 @@ bool svg::Circle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::V
const char * content = node->ToElement()->Attribute("cx");
if (NULL != content) {
m_position.x = ParseLength(content);
m_position.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("cy");
if (NULL != content) {
m_position.y = ParseLength(content);
m_position.setY(ParseLength(content));
}
content = node->ToElement()->Attribute("r");
if (NULL != content) {
@ -70,8 +69,7 @@ bool svg::Circle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::V
SVG_ERROR("(l "<<node->Row()<<") Circle \"r\" is negative");
return false;
}
sizeMax.x = m_position.x + m_radius;
sizeMax.y = m_position.y + m_radius;
sizeMax.setValue(m_position.x() + m_radius, m_position.y() + m_radius);
return true;
}
@ -85,7 +83,7 @@ void svg::Circle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTra
{
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a));
// Creating an ellipse
agg::ellipse myCircle(m_position.x, m_position.y, m_radius, m_radius, 0);
agg::ellipse myCircle(m_position.x(), m_position.y(), m_radius, m_radius, 0);
// Calculate transformation matrix ...
agg::trans_affine mtx = m_transformMatrix;

View File

@ -45,35 +45,32 @@ bool svg::Ellipse::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::
// add the property of the parrent modifications ...
m_transformMatrix *= parentTrans;
m_c.x = 0.0;
m_c.y = 0.0;
m_r.x = 0.0;
m_r.y = 0.0;
m_c.setValue(0,0);
m_r.setValue(0,0);
const char * content = node->ToElement()->Attribute("cx");
if (NULL != content) {
m_c.x = ParseLength(content);
m_c.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("cy");
if (NULL != content) {
m_c.y = ParseLength(content);
m_c.setY(ParseLength(content));
}
content = node->ToElement()->Attribute("rx");
if (NULL != content) {
m_r.x = ParseLength(content);
m_r.setX(ParseLength(content));
} else {
SVG_ERROR("(l "<<node->Row()<<") Ellipse \"rx\" is not present");
return false;
}
content = node->ToElement()->Attribute("ry");
if (NULL != content) {
m_r.y = ParseLength(content);
m_r.setY(ParseLength(content));
} else {
SVG_ERROR("(l "<<node->Row()<<") Ellipse \"ry\" is not present");
return false;
}
sizeMax.x = m_c.x + m_r.x;
sizeMax.y = m_c.y + m_r.y;
sizeMax.setValue(m_c.x() + m_r.x(), m_c.y() + m_r.y());
return true;
}
@ -88,7 +85,7 @@ void svg::Ellipse::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr
{
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a));
// Creating an ellipse
agg::ellipse myEllipse(m_c.x, m_c.y, m_r.x, m_r.y, 0);
agg::ellipse myEllipse(m_c.x(), m_c.y(), m_r.x(), m_r.y(), 0);
// Calculate transformation matrix ...
agg::trans_affine mtx = m_transformMatrix;

View File

@ -49,8 +49,8 @@ svg::Group::~Group(void)
bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Vector2D<float>& sizeMax)
{
// parse ...
etk::Vector2D<float> pos;
etk::Vector2D<float> size;
etk::Vector2D<float> pos(0,0);
etk::Vector2D<float> size(0,0);
ParseTransform(node);
ParsePosition(node, pos, size);
ParsePaintAttr(node);
@ -61,9 +61,8 @@ bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Ve
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;
etk::Vector2D<float> tmpPos;
sizeMax.setValue(0,0);
vec2 tmpPos(0,0);
// parse all sub node :
for(TiXmlNode * child = node->FirstChild(); NULL != child; child = child->NextSibling() ) {
svg::Base *elementParser = NULL;
@ -102,8 +101,8 @@ bool svg::Group::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Ve
delete(elementParser);
elementParser = NULL;
} else {
sizeMax.x = etk_max(sizeMax.x, tmpPos.x);
sizeMax.y = etk_max(sizeMax.y, tmpPos.y);
sizeMax.setValue(etk_max(sizeMax.x(), tmpPos.x()),
etk_max(sizeMax.y(), tmpPos.y()));
// add element in the system
m_subElementList.PushBack(elementParser);
}

View File

@ -29,10 +29,8 @@
svg::Line::Line(PaintState parentPaintState) : svg::Base(parentPaintState)
{
m_startPos.x = 0.0;
m_startPos.y = 0.0;
m_stopPos.x = 0.0;
m_stopPos.y = 0.0;
m_startPos.setValue(0,0);
m_stopPos.setValue(0,0);
}
svg::Line::~Line(void)
@ -52,22 +50,22 @@ bool svg::Line::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Vec
const char * content = node->ToElement()->Attribute("x1");
if (NULL != content) {
m_startPos.x = ParseLength(content);
m_startPos.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("y1");
if (NULL != content) {
m_startPos.y = ParseLength(content);
m_startPos.setY(ParseLength(content));
}
content = node->ToElement()->Attribute("x2");
if (NULL != content) {
m_stopPos.x = ParseLength(content);
m_stopPos.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("y2");
if (NULL != content) {
m_stopPos.y = ParseLength(content);
m_stopPos.setY(ParseLength(content));
}
sizeMax.x = etk_max(m_startPos.x, m_stopPos.x);
sizeMax.y = etk_max(m_startPos.y, m_stopPos.y);
sizeMax.setValue(etk_max(m_startPos.x(), m_stopPos.x()),
etk_max(m_startPos.y(), m_stopPos.y()));
return true;
}
@ -81,8 +79,8 @@ void svg::Line::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans
{
agg::path_storage path;
path.start_new_path();
path.move_to(m_startPos.x, m_startPos.y);
path.line_to(m_stopPos.x, m_stopPos.y);
path.move_to(m_startPos.x(), m_startPos.y());
path.line_to(m_stopPos.x(), m_stopPos.y());
/*
// configure the end of the line :
switch (m_paint.lineCap) {

View File

@ -54,17 +54,16 @@ bool svg::Polygon::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::
SVG_ERROR("(l "<<node->Row()<<") polygon: missing points attribute");
return false;
}
sizeMax.x = 0;
sizeMax.y = 0;
sizeMax.setValue(0,0);
SVG_VERBOSE("Parse polygon : \"" << sss << "\"");
while ('\0' != sss[0]) {
etk::Vector2D<float> pos;
vec2 pos(0,0);
int32_t n;
if (sscanf(sss, "%f,%f%n", &pos.x, &pos.y, &n) == 2) {
if (sscanf(sss, "%f,%f%n", &pos.m_floats[0], &pos.m_floats[1], &n) == 2) {
m_listPoint.PushBack(pos);
sss += n;
sizeMax.x = etk_max(sizeMax.x, pos.x);
sizeMax.y = etk_max(sizeMax.y, pos.y);
sizeMax.setValue(etk_max(sizeMax.x(), pos.x()),
etk_max(sizeMax.y(), pos.y()));
if(sss[0] == ' ' || sss[0] == ',') {
sss++;
}
@ -87,9 +86,9 @@ void svg::Polygon::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr
agg::path_storage path;
path.start_new_path();
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++) {
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();
/*

View File

@ -52,16 +52,15 @@ bool svg::Polyline::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk:
SVG_ERROR("(l "<<node->Row()<<") polyline: missing points attribute");
return false;
}
sizeMax.x = 0;
sizeMax.y = 0;
sizeMax.setValue(0,0);
SVG_VERBOSE("Parse polyline : \"" << sss << "\"");
while ('\0' != sss[0]) {
etk::Vector2D<float> pos;
int32_t n;
if (sscanf(sss, "%f,%f %n", &pos.x, &pos.y, &n) == 2) {
if (sscanf(sss, "%f,%f %n", &pos.m_floats[0], &pos.m_floats[1], &n) == 2) {
m_listPoint.PushBack(pos);
sizeMax.x = etk_max(sizeMax.x, pos.x);
sizeMax.y = etk_max(sizeMax.y, pos.y);
sizeMax.setValue(etk_max(sizeMax.x(), pos.x()),
etk_max(sizeMax.y(), pos.y()));
sss += n;
} else {
break;
@ -80,9 +79,9 @@ void svg::Polyline::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicT
{
agg::path_storage path;
path.start_new_path();
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++) {
path.line_to(m_listPoint[iii].x, m_listPoint[iii].y);
path.line_to(m_listPoint[iii].x(), m_listPoint[iii].y());
}
/*
// configure the end of the line :

View File

@ -29,12 +29,9 @@
svg::Rectangle::Rectangle(PaintState parentPaintState) : svg::Base(parentPaintState)
{
m_position.x = 0.0;
m_position.y = 0.0;
m_size.x = 0.0;
m_size.y = 0.0;
m_roundedCorner.x = 0.0;
m_roundedCorner.y = 0.0;
m_position.setValue(0,0);
m_size.setValue(0,0);
m_roundedCorner.setValue(0,0);
}
svg::Rectangle::~Rectangle(void)
@ -44,12 +41,9 @@ svg::Rectangle::~Rectangle(void)
bool svg::Rectangle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Vector2D<float>& sizeMax)
{
m_position.x = 0.0;
m_position.y = 0.0;
m_size.x = 0.0;
m_size.y = 0.0;
m_roundedCorner.x = 0.0;
m_roundedCorner.y = 0.0;
m_position.setValue(0,0);
m_size.setValue(0,0);
m_roundedCorner.setValue(0,0);
ParseTransform(node);
ParsePaintAttr(node);
@ -61,14 +55,14 @@ bool svg::Rectangle::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk
const char * content = node->ToElement()->Attribute("rx");
if (NULL != content) {
m_roundedCorner.x = ParseLength(content);
m_roundedCorner.setX(ParseLength(content));
}
content = node->ToElement()->Attribute("ry");
if (NULL != content) {
m_roundedCorner.y = ParseLength(content);
m_roundedCorner.setY(ParseLength(content));
}
sizeMax.x = m_position.x + m_size.x + m_paint.strokeWidth;
sizeMax.y = m_position.y + m_size.y + m_paint.strokeWidth;
sizeMax.setValue(m_position.x() + m_size.x() + m_paint.strokeWidth,
m_position.y() + m_size.y() + m_paint.strokeWidth);
return true;
}
@ -81,8 +75,8 @@ void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basic
{
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a));
// Creating a rounded rectangle
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);
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.normalize_radius();
agg::trans_affine mtx = m_transformMatrix;

View File

@ -31,8 +31,7 @@
svg::Renderer::Renderer(uint32_t width, uint32_t height)
{
m_allocatedSize = 0;
m_size.x = width;
m_size.y = height;
m_size.setValue(width, height);
int32_t dataSize = ((int32_t)width * (int32_t)height * DATA_ALLOCATION_ELEMENT);
m_allocatedSize = dataSize;
@ -49,7 +48,7 @@ svg::Renderer::Renderer(uint32_t width, uint32_t height)
memset(m_buffer, 0x00, dataSize * sizeof(uint8_t) );
m_renderingBuffer = new agg::rendering_buffer(m_buffer, m_size.x, m_size.y, m_size.x * DATA_ALLOCATION_ELEMENT);
m_renderingBuffer = new agg::rendering_buffer(m_buffer, m_size.x(), m_size.y(), m_size.x() * DATA_ALLOCATION_ELEMENT);
if (NULL == m_renderingBuffer) {
SVG_ERROR("Allocation of the m_renderingBuffer for SVG drawing error");
return;
@ -98,8 +97,8 @@ void svg::Renderer::WritePpm(etk::UString fileName)
}
FILE* fd = fopen(fileName.c_str(), "wb");
if(NULL != fd) {
int32_t sizeX = m_size.x;
int32_t sizeY = m_size.y;
int32_t sizeX = m_size.x();
int32_t sizeY = m_size.y();
SVG_DEBUG("Generate ppm : " << m_size);
fprintf(fd, "P6 %d %d 255 ", sizeX, sizeY);
for (int32_t iii=0 ; iii<sizeX*sizeY; iii++) {

View File

@ -37,8 +37,7 @@ svg::Text::~Text(void)
bool svg::Text::Parse(TiXmlNode * node, agg::trans_affine& parentTrans, etk::Vector2D<float>& sizeMax)
{
sizeMax.x = 0;
sizeMax.y = 0;
sizeMax.setValue(0,0);
SVG_ERROR("NOT IMPLEMENTED");
return false;
}

View File

@ -56,13 +56,11 @@ svg::Parser::Parser(etk::UString fileName) : m_renderedElement(NULL)
m_paint.stroke = (int32_t)0xFFFFFF00;
m_paint.strokeWidth = 1.0;
m_paint.viewPort.x = 255;
m_paint.viewPort.y = 255;
m_paint.viewPort.setValue(255,255);
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;
m_size.setValue(0,0);
// Start loading the XML :
SVG_DEBUG("open file (SVG) \"" << m_fileName << "\"");
@ -119,11 +117,9 @@ svg::Parser::Parser(etk::UString fileName) : m_renderedElement(NULL)
SVG_VERBOSE("parsed .ROOT trans : (" << m_transformMatrix.sx << "," << m_transformMatrix.shy << "," << m_transformMatrix.shx << "," << m_transformMatrix.sy << "," << m_transformMatrix.tx << "," << m_transformMatrix.ty << ")");
etk::Vector2D<float> maxSize;
maxSize.x = 0.0;
maxSize.y = 0.0;
vec2 maxSize(0,0);
etk::Vector2D<float> size;
vec2 size;
// parse all sub node :
for(TiXmlNode * child = root->FirstChild(); NULL != child; child = child->NextSibling() ) {
svg::Base *elementParser = NULL;
@ -177,11 +173,11 @@ svg::Parser::Parser(etk::UString fileName) : m_renderedElement(NULL)
delete(elementParser);
elementParser = NULL;
} else {
if (maxSize.x<size.x) {
maxSize.x=size.x;
if (maxSize.x()<size.x()) {
maxSize.setX(size.x());
}
if (maxSize.y<size.y) {
maxSize.y=size.y;
if (maxSize.y()<size.y()) {
maxSize.setY(size.y());
}
// add element in the system
m_subElementList.PushBack(elementParser);
@ -190,12 +186,10 @@ svg::Parser::Parser(etk::UString fileName) : m_renderedElement(NULL)
}
}
}
if (m_size.x==0 || m_size.y==0) {
m_size.x=(int32_t)maxSize.x;
m_size.y=(int32_t)maxSize.y;
if (m_size.x()==0 || m_size.y()==0) {
m_size.setValue((int32_t)maxSize.x(), (int32_t)maxSize.y());
} else {
m_size.x=(int32_t)m_size.x;
m_size.y=(int32_t)m_size.y;
m_size.setValue((int32_t)m_size.x(), (int32_t)m_size.y());
}
}
if (NULL != fileBuffer) {
@ -237,11 +231,11 @@ void svg::Parser::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTra
void svg::Parser::GenerateTestFile(void)
{
int32_t SizeX = m_size.x;
int32_t SizeX = m_size.x();
if (SizeX == 0) {
SizeX = 64;
}
int32_t SizeY = m_size.y;
int32_t SizeY = m_size.y();
if (SizeY == 0) {
SizeY = 64;
}
@ -292,7 +286,7 @@ void svg::Parser::GenerateAnImage(int32_t sizeX, int32_t sizeY)
// create the first element matrix modification ...
agg::trans_affine basicTrans;
//basicTrans *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
basicTrans *= agg::trans_affine_scaling(SizeX/m_size.x, SizeY/m_size.y);
basicTrans *= agg::trans_affine_scaling(SizeX/m_size.x(), SizeY/m_size.y());
//basicTrans *= agg::trans_affine_rotation(g_angle);// + agg::pi);
//basicTrans *= agg::trans_affine_skewing(2.0, 5.0);
//basicTrans *= agg::trans_affine_translation(width*0.3, height/2);
@ -307,7 +301,7 @@ void svg::Parser::GenerateAnImage(int32_t sizeX, int32_t sizeY)
void svg::Parser::GenerateAnImage(etk::Vector2D<int32_t> size, draw::Image& output)
{
GenerateAnImage(size.x, size.y);
GenerateAnImage(size.x(), size.y());
output.Resize(size);
draw::Color tmpp(0,0,0,0);
output.SetFillColor(tmpp);