Move to the agg color system
This commit is contained in:
parent
fc100697e3
commit
2037fb3efc
@ -221,14 +221,14 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
|
||||
const char * content = node->ToElement()->Attribute("fill");
|
||||
if (NULL != content) {
|
||||
m_paint.fill = ParseColor(content);
|
||||
if (m_paint.fill.alpha == 0) {
|
||||
if (m_paint.fill.a == 0) {
|
||||
fillNone = true;
|
||||
}
|
||||
}
|
||||
content = node->ToElement()->Attribute("stroke");
|
||||
if (NULL != content) {
|
||||
m_paint.stroke = ParseColor(content);
|
||||
if (m_paint.stroke.alpha == 0) {
|
||||
if (m_paint.stroke.a == 0) {
|
||||
strokeNone = true;
|
||||
}
|
||||
}
|
||||
@ -240,20 +240,20 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
|
||||
if (NULL != content) {
|
||||
float opacity = ParseLength(content);
|
||||
opacity = etk_max(0.0, etk_min(1.0, opacity));
|
||||
m_paint.fill.alpha = opacity*0xFF;
|
||||
m_paint.stroke.alpha = opacity*0xFF;
|
||||
m_paint.fill.a = opacity*0xFF;
|
||||
m_paint.stroke.a = opacity*0xFF;
|
||||
}
|
||||
content = node->ToElement()->Attribute("fill-opacity");
|
||||
if (NULL != content) {
|
||||
float opacity = ParseLength(content);
|
||||
opacity = etk_max(0.0, etk_min(1.0, opacity));
|
||||
m_paint.fill.alpha = opacity*0xFF;
|
||||
m_paint.fill.a = opacity*0xFF;
|
||||
}
|
||||
content = node->ToElement()->Attribute("stroke-opacity");
|
||||
if (NULL != content) {
|
||||
float opacity = ParseLength(content);
|
||||
opacity = etk_max(0.0, etk_min(1.0, opacity));
|
||||
m_paint.stroke.alpha = opacity*0xFF;
|
||||
m_paint.stroke.a = opacity*0xFF;
|
||||
}
|
||||
content = node->ToElement()->Attribute("fill-rule");
|
||||
if (NULL != content) {
|
||||
@ -303,13 +303,13 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
|
||||
if (0 == strcmp(outputType, "fill") ) {
|
||||
m_paint.fill = ParseColor(outputValue);
|
||||
SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.fill);
|
||||
if (m_paint.fill.alpha == 0) {
|
||||
if (m_paint.fill.a == 0) {
|
||||
fillNone = true;
|
||||
}
|
||||
} else if (0 == strcmp(outputType, "stroke") ) {
|
||||
m_paint.stroke = ParseColor(outputValue);
|
||||
SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.stroke);
|
||||
if (m_paint.stroke.alpha == 0) {
|
||||
if (m_paint.stroke.a == 0) {
|
||||
strokeNone = true;
|
||||
}
|
||||
} else if (0 == strcmp(outputType, "stroke-width") ) {
|
||||
@ -318,18 +318,18 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
|
||||
} else if (0 == strcmp(outputType, "opacity") ) {
|
||||
float opacity = ParseLength(outputValue);
|
||||
opacity = etk_max(0.0, etk_min(1.0, opacity));
|
||||
m_paint.fill.alpha = opacity*0xFF;
|
||||
m_paint.stroke.alpha = opacity*0xFF;
|
||||
m_paint.fill.a = opacity*0xFF;
|
||||
m_paint.stroke.a = opacity*0xFF;
|
||||
SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.fill);
|
||||
} else if (0 == strcmp(outputType, "fill-opacity") ) {
|
||||
float opacity = ParseLength(outputValue);
|
||||
opacity = etk_max(0.0, etk_min(1.0, opacity));
|
||||
m_paint.fill.alpha = opacity*0xFF;
|
||||
m_paint.fill.a = opacity*0xFF;
|
||||
SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.fill);
|
||||
} else if (0 == strcmp(outputType, "stroke-opacity") ) {
|
||||
float opacity = ParseLength(outputValue);
|
||||
opacity = etk_max(0.0, etk_min(1.0, opacity));
|
||||
m_paint.stroke.alpha = opacity*0xFF;
|
||||
m_paint.stroke.a = opacity*0xFF;
|
||||
SVG_VERBOSE(" input : \"" << outputValue << "\" ==> " << m_paint.stroke);
|
||||
} else if (0 == strcmp(outputType, "fill-rule") ) {
|
||||
if (0 == strcmp(outputValue, "nonzero") ) {
|
||||
@ -370,10 +370,10 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
|
||||
}
|
||||
// check if somewere none is set to the filling:
|
||||
if (true == fillNone) {
|
||||
m_paint.fill.alpha = 0;
|
||||
m_paint.fill.a = 0;
|
||||
}
|
||||
if (true == strokeNone) {
|
||||
m_paint.stroke.alpha = 0;
|
||||
m_paint.stroke.a = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -407,9 +407,9 @@ bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen)
|
||||
* @param[in] inputData Data C String with the xml definition
|
||||
* @return the parsed color
|
||||
*/
|
||||
etk::Color svg::Base::ParseColor(const char *inputData)
|
||||
draw::Color svg::Base::ParseColor(const char *inputData)
|
||||
{
|
||||
etk::Color localColor = etk::color::white;
|
||||
draw::Color localColor = draw::color::white;
|
||||
|
||||
size_t len = strlen(inputData);
|
||||
|
||||
@ -460,7 +460,7 @@ void svg::Base::AggCheckChange(agg::path_storage& path, etk::Vector<agg::rgba8>
|
||||
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));
|
||||
colors.PushBack(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.a));
|
||||
uint32_t tmpPathNew = path.start_new_path();
|
||||
pathIdx.PushBack(tmpPathNew);
|
||||
curentPaintProp = m_paint;
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/Vector.h>
|
||||
#include <etk/Color.h>
|
||||
#include <draw/Color.h>
|
||||
|
||||
#include <tinyXML/tinyxml.h>
|
||||
#include <parserSVG/Renderer.h>
|
||||
@ -64,7 +64,7 @@ namespace svg
|
||||
void ParsePosition(const TiXmlNode *node, Vector2D<float> &pos, Vector2D<float> &size);
|
||||
float ParseLength(const char *dataInput);
|
||||
void ParsePaintAttr(const TiXmlNode *node);
|
||||
etk::Color ParseColor(const char *inputData);
|
||||
draw::Color ParseColor(const char *inputData);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -83,7 +83,7 @@ void svg::Circle::Display(int32_t spacing)
|
||||
|
||||
void svg::Circle::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));
|
||||
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);
|
||||
|
||||
@ -94,14 +94,14 @@ void svg::Circle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTra
|
||||
// set the filling mode :
|
||||
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
|
||||
|
||||
if (m_paint.fill.alpha != 0x00) {
|
||||
if (m_paint.fill.a != 0x00) {
|
||||
agg::conv_transform<agg::ellipse, agg::trans_affine> trans(myCircle, mtx);
|
||||
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));
|
||||
if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) {
|
||||
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
||||
// Drawing as an outline
|
||||
agg::conv_stroke<agg::ellipse> myCircleStroke(myCircle);
|
||||
myCircleStroke.width(m_paint.strokeWidth);
|
||||
|
@ -86,7 +86,7 @@ void svg::Ellipse::Display(int32_t spacing)
|
||||
|
||||
void svg::Ellipse::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));
|
||||
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);
|
||||
|
||||
@ -97,14 +97,14 @@ void svg::Ellipse::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr
|
||||
// set the filling mode :
|
||||
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
|
||||
|
||||
if (m_paint.fill.alpha != 0x00) {
|
||||
if (m_paint.fill.a != 0x00) {
|
||||
agg::conv_transform<agg::ellipse, agg::trans_affine> trans(myEllipse, mtx);
|
||||
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));
|
||||
if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) {
|
||||
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
||||
// Drawing as an outline
|
||||
agg::conv_stroke<agg::ellipse> myEllipseStroke(myEllipse);
|
||||
myEllipseStroke.width(m_paint.strokeWidth);
|
||||
|
@ -112,7 +112,7 @@ void svg::Line::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans
|
||||
mtx *= basicTrans;
|
||||
|
||||
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.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
||||
// Drawing as an outline
|
||||
agg::conv_stroke<agg::path_storage> myPolygonStroke(path);
|
||||
myPolygonStroke.width(m_paint.strokeWidth);
|
||||
|
@ -347,7 +347,7 @@ 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));
|
||||
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a));
|
||||
|
||||
agg::path_storage path;
|
||||
path.start_new_path();
|
||||
@ -421,15 +421,15 @@ void svg::Path::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans
|
||||
mtx *= basicTrans;
|
||||
|
||||
agg::conv_curve<agg::path_storage> curve(path);
|
||||
if (m_paint.fill.alpha != 0x00) {
|
||||
if (m_paint.fill.a != 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));
|
||||
if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) {
|
||||
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
||||
// Drawing as an outline
|
||||
agg::conv_stroke<agg::conv_curve<agg::path_storage> > myPolygonStroke(curve);
|
||||
myPolygonStroke.width(m_paint.strokeWidth);
|
||||
|
@ -82,7 +82,7 @@ void svg::Polygon::Display(int32_t spacing)
|
||||
|
||||
void svg::Polygon::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));
|
||||
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.r, m_paint.fill.g, m_paint.fill.b, m_paint.fill.a));
|
||||
|
||||
agg::path_storage path;
|
||||
path.start_new_path();
|
||||
@ -121,7 +121,7 @@ void svg::Polygon::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr
|
||||
agg::trans_affine mtx = m_transformMatrix;
|
||||
mtx *= basicTrans;
|
||||
|
||||
if (m_paint.fill.alpha != 0x00) {
|
||||
if (m_paint.fill.a != 0x00) {
|
||||
agg::conv_transform<agg::path_storage, agg::trans_affine> trans(path, mtx);
|
||||
// set the filling mode :
|
||||
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
|
||||
@ -129,8 +129,8 @@ void svg::Polygon::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTr
|
||||
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));
|
||||
if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) {
|
||||
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
||||
// Drawing as an outline
|
||||
agg::conv_stroke<agg::path_storage> myPolygonStroke(path);
|
||||
myPolygonStroke.width(m_paint.strokeWidth);
|
||||
|
@ -114,7 +114,7 @@ void svg::Polyline::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicT
|
||||
mtx *= basicTrans;
|
||||
|
||||
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.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
||||
// Drawing as an outline
|
||||
agg::conv_stroke<agg::path_storage> myPolygonStroke(path);
|
||||
myPolygonStroke.width(m_paint.strokeWidth);
|
||||
|
@ -79,7 +79,7 @@ void svg::Rectangle::Display(int32_t spacing)
|
||||
|
||||
void svg::Rectangle::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));
|
||||
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);
|
||||
@ -89,7 +89,7 @@ void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basic
|
||||
// herited modifications ...
|
||||
mtx *= basicTrans;
|
||||
|
||||
if (m_paint.fill.alpha != 0x00) {
|
||||
if (m_paint.fill.a != 0x00) {
|
||||
agg::conv_transform<agg::rounded_rect, agg::trans_affine> trans(rect_r, mtx);
|
||||
// set the filling mode :
|
||||
myRenderer.m_rasterizer.filling_rule((m_paint.flagEvenOdd)?agg::fill_even_odd:agg::fill_non_zero);
|
||||
@ -97,8 +97,8 @@ void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basic
|
||||
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));
|
||||
if (m_paint.strokeWidth > 0 && m_paint.stroke.a!=0x00 ) {
|
||||
myRenderer.m_renderArea->color(agg::rgba8(m_paint.stroke.r, m_paint.stroke.g, m_paint.stroke.b, m_paint.stroke.a));
|
||||
// Drawing as an outline
|
||||
agg::conv_stroke<agg::rounded_rect> rect_p(rect_r);
|
||||
// set the filling mode :
|
||||
|
@ -26,7 +26,7 @@
|
||||
#define __SVG_RENDERER_H__
|
||||
|
||||
#include <etk/UString.h>
|
||||
#include <etk/Color.h>
|
||||
#include <draw/Color.h>
|
||||
|
||||
#include <agg/agg_basics.h>
|
||||
#include <agg/agg_rendering_buffer.h>
|
||||
@ -54,8 +54,8 @@ namespace svg
|
||||
|
||||
class PaintState {
|
||||
public:
|
||||
etk::Color fill;
|
||||
etk::Color stroke;
|
||||
draw::Color fill;
|
||||
draw::Color stroke;
|
||||
float strokeWidth;
|
||||
bool flagEvenOdd;
|
||||
lineCap_te lineCap;
|
||||
|
@ -52,15 +52,8 @@ svg::Parser::Parser(etk::File fileName) : m_renderedElement(NULL)
|
||||
m_fileName = fileName;
|
||||
m_version = "0.0";
|
||||
m_loadOK = true;
|
||||
m_paint.fill.red = 0xFF;
|
||||
m_paint.fill.green = 0;
|
||||
m_paint.fill.blue = 0;
|
||||
m_paint.fill.alpha = 0xFF;
|
||||
|
||||
m_paint.stroke.red = 0xFF;
|
||||
m_paint.stroke.green = 0xFF;
|
||||
m_paint.stroke.blue = 0xFF;
|
||||
m_paint.stroke.alpha = 0;
|
||||
m_paint.fill = (int32_t)0xFF0000FF;
|
||||
m_paint.stroke = (int32_t)0xFFFFFF00;
|
||||
|
||||
m_paint.strokeWidth = 1.0;
|
||||
m_paint.viewPort.x = 255;
|
||||
|
Loading…
x
Reference in New Issue
Block a user