start abstraction of the AGG lib
This commit is contained in:
parent
7e984ca41f
commit
062b67e1b7
@ -16,7 +16,8 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
|||||||
-DETK_DEBUG_LEVEL=3 \
|
-DETK_DEBUG_LEVEL=3 \
|
||||||
-DEWOL_DEBUG_LEVEL=3 \
|
-DEWOL_DEBUG_LEVEL=3 \
|
||||||
-DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \
|
-DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \
|
||||||
-DVERSION_BUILD_TIME="\"pasd_heure\""
|
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
||||||
|
-Wall
|
||||||
else
|
else
|
||||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||||
-Wno-write-strings \
|
-Wno-write-strings \
|
||||||
|
@ -17,7 +17,8 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
|||||||
-DEWOL_DEBUG_LEVEL=3 \
|
-DEWOL_DEBUG_LEVEL=3 \
|
||||||
-DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \
|
-DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \
|
||||||
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
||||||
-DEWOL_USE_FREE_TYPE
|
-DEWOL_USE_FREE_TYPE \
|
||||||
|
-Wall
|
||||||
else
|
else
|
||||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||||
-Wno-write-strings \
|
-Wno-write-strings \
|
||||||
|
@ -15,7 +15,8 @@ LOCAL_EXPORT_LDLIBS :=
|
|||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||||
-DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\""
|
-DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\"" \
|
||||||
|
-Wall -Wextra
|
||||||
else
|
else
|
||||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||||
-DPARSER_SVG_VERSION_TAG_NAME="\"???-release\""
|
-DPARSER_SVG_VERSION_TAG_NAME="\"???-release\""
|
||||||
|
@ -15,11 +15,12 @@ LOCAL_EXPORT_LDLIBS :=
|
|||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||||
-DSVG_DEBUG_LEVEL=3
|
-DSVG_DEBUG_LEVEL=3 \
|
||||||
-DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\""
|
-DPARSER_SVG_VERSION_TAG_NAME="\"???-debug\"" \
|
||||||
|
-Wall
|
||||||
else
|
else
|
||||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||||
-DSVG_DEBUG_LEVEL=1
|
-DSVG_DEBUG_LEVEL=1 \
|
||||||
-DPARSER_SVG_VERSION_TAG_NAME="\"???-release\""
|
-DPARSER_SVG_VERSION_TAG_NAME="\"???-release\""
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
FILE_LIST = parserSVG/Debug.cpp \
|
FILE_LIST = parserSVG/Base.cpp \
|
||||||
parserSVG/Base.cpp \
|
|
||||||
parserSVG/Circle.cpp \
|
parserSVG/Circle.cpp \
|
||||||
|
parserSVG/Debug.cpp \
|
||||||
parserSVG/Ellipse.cpp \
|
parserSVG/Ellipse.cpp \
|
||||||
parserSVG/Group.cpp \
|
parserSVG/Group.cpp \
|
||||||
parserSVG/Line.cpp \
|
parserSVG/Line.cpp \
|
||||||
@ -11,5 +11,6 @@ FILE_LIST = parserSVG/Debug.cpp \
|
|||||||
parserSVG/Polygon.cpp \
|
parserSVG/Polygon.cpp \
|
||||||
parserSVG/Polyline.cpp \
|
parserSVG/Polyline.cpp \
|
||||||
parserSVG/Rectangle.cpp \
|
parserSVG/Rectangle.cpp \
|
||||||
|
parserSVG/Renderer.cpp \
|
||||||
parserSVG/Stroking.cpp \
|
parserSVG/Stroking.cpp \
|
||||||
parserSVG/Text.cpp
|
parserSVG/Text.cpp
|
||||||
|
@ -155,10 +155,13 @@ etkFloat_t svg::Base::ParseLength(const char *dataInput)
|
|||||||
{
|
{
|
||||||
int32_t numLength = strspn(dataInput, "0123456789+-.");
|
int32_t numLength = strspn(dataInput, "0123456789+-.");
|
||||||
const char *unit = dataInput + numLength;
|
const char *unit = dataInput + numLength;
|
||||||
|
//SVG_INFO(" ==> \"" << dataInput << "\"");
|
||||||
etkFloat_t n = atof(dataInput);
|
etkFloat_t n = atof(dataInput);
|
||||||
|
//SVG_INFO(" ==> ?? = " << n );
|
||||||
etkFloat_t font_size = 20.0;
|
etkFloat_t font_size = 20.0;
|
||||||
|
|
||||||
if (unit[0] == '\0') {
|
// note : ";" is for the parsing of the style elements ...
|
||||||
|
if (unit[0] == '\0' || unit[0] == ';' ) {
|
||||||
return n;
|
return n;
|
||||||
} else if (unit[0] == '%') { // xxx %
|
} else if (unit[0] == '%') { // xxx %
|
||||||
return n / 100.0 * m_paint.viewPort.x;
|
return n / 100.0 * m_paint.viewPort.x;
|
||||||
@ -223,11 +226,22 @@ void svg::Base::ParsePaintAttr(const TiXmlNode *node)
|
|||||||
}
|
}
|
||||||
if ((sss = strstr(content, "stroke-width:"))) {
|
if ((sss = strstr(content, "stroke-width:"))) {
|
||||||
sss += 13;
|
sss += 13;
|
||||||
|
SVG_VERBOSE(" find a stroke width ... : " << sss);
|
||||||
while( sss[0] ==' '
|
while( sss[0] ==' '
|
||||||
&& sss[0]!='\0' ) {
|
&& sss[0]!='\0' ) {
|
||||||
sss++;
|
sss++;
|
||||||
}
|
}
|
||||||
m_paint.strokeWidth = ParseLength(sss);
|
m_paint.strokeWidth = ParseLength(sss);
|
||||||
|
SVG_VERBOSE(" ==> " << m_paint.strokeWidth);
|
||||||
|
}
|
||||||
|
if ((sss = strstr(content, "opacity:"))) {
|
||||||
|
sss += 8;
|
||||||
|
while( sss[0] ==' '
|
||||||
|
&& sss[0]!='\0' ) {
|
||||||
|
sss++;
|
||||||
|
}
|
||||||
|
etkFloat_t opacity = ParseLength(sss);
|
||||||
|
m_paint.opacity = etk_max(0.0, etk_min(1.0, opacity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -557,7 +571,7 @@ const char * svg::Base::SpacingDist(int32_t spacing)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void svg::Base::AggCheckChange(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
|
void svg::Base::AggCheckChange(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
|
||||||
{
|
{
|
||||||
if (curentPaintProp != m_paint) {
|
if (curentPaintProp != m_paint) {
|
||||||
@ -569,3 +583,4 @@ void svg::Base::AggCheckChange(agg::path_storage& path, etk::VectorType<agg::rgb
|
|||||||
curentPaintProp = m_paint;
|
curentPaintProp = m_paint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <etk/VectorType.h>
|
#include <etk/VectorType.h>
|
||||||
|
|
||||||
#include <tinyXML/tinyxml.h>
|
#include <tinyXML/tinyxml.h>
|
||||||
|
#include <parserSVG/Renderer.h>
|
||||||
|
|
||||||
#include <agg-2.4/agg_basics.h>
|
#include <agg-2.4/agg_basics.h>
|
||||||
#include <agg-2.4/agg_rendering_buffer.h>
|
#include <agg-2.4/agg_rendering_buffer.h>
|
||||||
@ -43,49 +44,6 @@
|
|||||||
|
|
||||||
namespace svg
|
namespace svg
|
||||||
{
|
{
|
||||||
#define MATRIX_SIZE (6)
|
|
||||||
class PaintState {
|
|
||||||
public :
|
|
||||||
PaintState(void) {};
|
|
||||||
~PaintState(void) {};
|
|
||||||
color8_ts fill;
|
|
||||||
color8_ts stroke;
|
|
||||||
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:
|
||||||
@ -97,8 +55,7 @@ namespace svg
|
|||||||
~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, PaintState &curentPaintProp) { };
|
virtual void AggDraw(svg::Renderer& myRenderer, svg::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);
|
||||||
|
@ -113,14 +113,13 @@ 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, PaintState &curentPaintProp)
|
void svg::Group::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp)
|
||||||
{
|
{
|
||||||
AggCheckChange(path, colors, pathIdx, curentPaintProp);
|
curentPaintProp = m_paint;
|
||||||
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, curentPaintProp);
|
m_subElementList[iii]->AggDraw(myRenderer, curentPaintProp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace svg
|
|||||||
~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, PaintState &curentPaintProp);
|
virtual void AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,18 +65,47 @@ 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, PaintState &curentPaintProp)
|
#include <agg-2.4/agg_basics.h>
|
||||||
|
#include <agg-2.4/agg_rendering_buffer.h>
|
||||||
|
#include <agg-2.4/agg_rasterizer_scanline_aa.h>
|
||||||
|
#include <agg-2.4/agg_scanline_p.h>
|
||||||
|
#include <agg-2.4/agg_renderer_scanline.h>
|
||||||
|
#include <agg-2.4/agg_path_storage.h>
|
||||||
|
#include <agg-2.4/agg_conv_transform.h>
|
||||||
|
#include <agg-2.4/agg_bounding_rect.h>
|
||||||
|
#include <agg-2.4/agg_color_rgba.h>
|
||||||
|
#include <agg-2.4/agg_pixfmt_rgba.h>
|
||||||
|
|
||||||
|
void svg::Polygon::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp)
|
||||||
{
|
{
|
||||||
if (m_listPoint.Size()<2) {
|
curentPaintProp = m_paint;
|
||||||
// nothing to draw ...
|
agg::path_storage path;
|
||||||
return;
|
etk::VectorType<agg::rgba8> colorsList;
|
||||||
}
|
etk::VectorType<uint32_t> pathListId;
|
||||||
AggCheckChange(path, colors, pathIdx, curentPaintProp);
|
|
||||||
|
// New color. Every new color creates new path in the path object.
|
||||||
|
colorsList.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();
|
||||||
|
pathListId.PushBack(tmpPathNew);
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
path.close_polygon();
|
path.close_polygon();
|
||||||
|
|
||||||
|
|
||||||
|
agg::trans_affine mtx;
|
||||||
|
//mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
|
||||||
|
//mtx *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
|
||||||
|
//mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi);
|
||||||
|
//mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
|
||||||
|
//mtx *= agg::trans_affine_translation(width*0.3, height/2);
|
||||||
|
mtx *= agg::trans_affine_translation(myRenderer.m_size.x*0.5, myRenderer.m_size.x/2);
|
||||||
|
|
||||||
|
// This code renders the lion:
|
||||||
|
agg::conv_transform<agg::path_storage, agg::trans_affine> trans(path, mtx);
|
||||||
|
|
||||||
|
agg::render_all_paths( myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea, trans, &colorsList[0], &pathListId[0], pathListId.Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace svg
|
|||||||
~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, PaintState &curentPaintProp);
|
virtual void AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +56,14 @@ bool svg::Rectangle::Parse(TiXmlNode * node)
|
|||||||
|
|
||||||
ParsePosition(node, m_position, m_size);
|
ParsePosition(node, m_position, m_size);
|
||||||
|
|
||||||
|
const char * content = node->ToElement()->Attribute("rx");
|
||||||
|
if (NULL != content) {
|
||||||
|
m_roundedCorner.x = ParseLength(content);
|
||||||
|
}
|
||||||
|
content = node->ToElement()->Attribute("ry");
|
||||||
|
if (NULL != content) {
|
||||||
|
m_roundedCorner.y = ParseLength(content);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,33 +73,40 @@ void svg::Rectangle::Display(int32_t spacing)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void svg::Rectangle::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp)
|
||||||
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) {
|
myRenderer.m_renderArea->color(agg::rgba8(m_paint.fill.red, m_paint.fill.green, m_paint.fill.blue, m_paint.fill.alpha));
|
||||||
// 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
|
// Creating a rounded rectangle
|
||||||
agg::rounded_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_size.x, m_size.y, m_roundedCorner.x);
|
||||||
r.normalize_radius();
|
rect_r.radius(m_roundedCorner.x, m_roundedCorner.y);
|
||||||
|
rect_r.normalize_radius();
|
||||||
|
|
||||||
// Drawing as an outline
|
myRenderer.m_rasterizer.add_path(rect_r);
|
||||||
agg::conv_stroke<agg::rounded_rect> p(r);
|
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
|
||||||
p.width(1.0);
|
|
||||||
path.add_path(p);
|
if (m_paint.strokeWidth > 0) {
|
||||||
#endif
|
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::rounded_rect> rect_p(rect_r);
|
||||||
|
rect_p.width(m_paint.strokeWidth);
|
||||||
|
myRenderer.m_rasterizer.add_path(rect_p);
|
||||||
|
agg::render_scanlines(myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
agg::trans_affine mtx;
|
||||||
|
//mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
|
||||||
|
//mtx *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
|
||||||
|
//mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi);
|
||||||
|
//mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
|
||||||
|
//mtx *= agg::trans_affine_translation(width*0.3, height/2);
|
||||||
|
mtx *= agg::trans_affine_translation(myRenderer.m_size.x*0.5, myRenderer.m_size.x/2);
|
||||||
|
|
||||||
|
// This code renders the lion:
|
||||||
|
agg::conv_transform<agg::path_storage, agg::trans_affine> trans(path, mtx);
|
||||||
|
|
||||||
|
agg::render_all_paths( myRenderer.m_rasterizer, myRenderer.m_scanLine, *myRenderer.m_renderArea, trans, &colorsList[0], &pathListId[0], pathListId.Size());
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace svg
|
|||||||
~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);
|
virtual void AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
107
Sources/libparsersvg/parserSVG/Renderer.cpp
Normal file
107
Sources/libparsersvg/parserSVG/Renderer.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
*******************************************************************************
|
||||||
|
* @file parserSVG/Renderer.cpp
|
||||||
|
* @brief Basic SVG renderer for the AGG librairy (Sources)
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @date 23/03/2012
|
||||||
|
* @par Project
|
||||||
|
* parserSVG
|
||||||
|
*
|
||||||
|
* @par Copyright
|
||||||
|
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY.
|
||||||
|
*
|
||||||
|
* Licence summary :
|
||||||
|
* You can modify and redistribute the sources code and binaries.
|
||||||
|
* You can send me the bug-fix
|
||||||
|
*
|
||||||
|
* Term of the licence in in the file licence.txt.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <parserSVG/Debug.h>
|
||||||
|
#include <parserSVG/Renderer.h>
|
||||||
|
|
||||||
|
// 4 is for the RGBA ...
|
||||||
|
#define DATA_ALLOCATION_ELEMENT (4)
|
||||||
|
|
||||||
|
svg::Renderer::Renderer(uint32_t width, uint32_t height)
|
||||||
|
{
|
||||||
|
m_size.x = width;
|
||||||
|
m_size.y = height;
|
||||||
|
|
||||||
|
int32_t dataSize = ((int32_t)width * (int32_t)height * DATA_ALLOCATION_ELEMENT);
|
||||||
|
|
||||||
|
// allocate Data
|
||||||
|
SVG_DEBUG("Allocate buffer : " << dataSize);
|
||||||
|
|
||||||
|
ETK_MALLOC(m_buffer, dataSize, uint8_t);
|
||||||
|
if (NULL == m_buffer) {
|
||||||
|
SVG_ERROR("Allocation of the output buffer for SVG drawing error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(m_buffer, 0xFF, dataSize * sizeof(uint8_t) );
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pixFrame = new agg::pixfmt_rgba32(*m_renderingBuffer);
|
||||||
|
if (NULL == m_pixFrame) {
|
||||||
|
SVG_ERROR("Allocation of the m_pixFrame for SVG drawing error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_renderBase = new rendererBase_t(*m_pixFrame);
|
||||||
|
if (NULL == m_renderBase) {
|
||||||
|
SVG_ERROR("Allocation of the m_renderBase for SVG drawing error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_renderArea = new rendererSolid_t(*m_renderBase);
|
||||||
|
if (NULL == m_renderArea) {
|
||||||
|
SVG_ERROR("Allocation of the m_renderArea for SVG drawing error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//m_basicMatrix *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2);
|
||||||
|
//m_basicMatrix *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
|
||||||
|
//m_basicMatrix *= agg::trans_affine_rotation(g_angle);// + agg::pi);
|
||||||
|
//m_basicMatrix *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
|
||||||
|
m_basicMatrix *= agg::trans_affine_translation(m_size.x*0.7, m_size.y/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
svg::Renderer::~Renderer(void)
|
||||||
|
{
|
||||||
|
if (NULL != m_buffer) {
|
||||||
|
ETK_FREE(m_buffer);
|
||||||
|
m_buffer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writing the buffer to a .PPM file, assuming it has
|
||||||
|
// RGB-structure, one byte per color component
|
||||||
|
//--------------------------------------------------
|
||||||
|
void svg::Renderer::WritePpm(etk::UString fileName)
|
||||||
|
{
|
||||||
|
if (NULL == m_buffer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FILE* fd = fopen(fileName.Utf8Data(), "wb");
|
||||||
|
if(NULL != fd) {
|
||||||
|
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++) {
|
||||||
|
fwrite(m_buffer+iii*DATA_ALLOCATION_ELEMENT, 1, 3, fd);
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
|
}
|
109
Sources/libparsersvg/parserSVG/Renderer.h
Normal file
109
Sources/libparsersvg/parserSVG/Renderer.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
*******************************************************************************
|
||||||
|
* @file parserSVG/Renderer.h
|
||||||
|
* @brief Basic SVG renderer for the AGG librairy (Header)
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @date 23/03/2012
|
||||||
|
* @par Project
|
||||||
|
* parserSVG
|
||||||
|
*
|
||||||
|
* @par Copyright
|
||||||
|
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY.
|
||||||
|
*
|
||||||
|
* Licence summary :
|
||||||
|
* You can modify and redistribute the sources code and binaries.
|
||||||
|
* You can send me the bug-fix
|
||||||
|
*
|
||||||
|
* Term of the licence in in the file licence.txt.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SVG_RENDERER_H__
|
||||||
|
#define __SVG_RENDERER_H__
|
||||||
|
|
||||||
|
#include <etk/UString.h>
|
||||||
|
|
||||||
|
#include <agg-2.4/agg_basics.h>
|
||||||
|
#include <agg-2.4/agg_rendering_buffer.h>
|
||||||
|
#include <agg-2.4/agg_rasterizer_scanline_aa.h>
|
||||||
|
#include <agg-2.4/agg_scanline_p.h>
|
||||||
|
#include <agg-2.4/agg_renderer_scanline.h>
|
||||||
|
#include <agg-2.4/agg_path_storage.h>
|
||||||
|
#include <agg-2.4/agg_conv_transform.h>
|
||||||
|
#include <agg-2.4/agg_bounding_rect.h>
|
||||||
|
#include <agg-2.4/agg_color_rgba.h>
|
||||||
|
#include <agg-2.4/agg_pixfmt_rgba.h>
|
||||||
|
|
||||||
|
namespace svg
|
||||||
|
{
|
||||||
|
#define MATRIX_SIZE (6)
|
||||||
|
class PaintState {
|
||||||
|
public :
|
||||||
|
PaintState(void) {};
|
||||||
|
~PaintState(void) {};
|
||||||
|
color8_ts fill;
|
||||||
|
color8_ts stroke;
|
||||||
|
etkFloat_t strokeWidth;
|
||||||
|
coord2D_ts viewPort;
|
||||||
|
etkFloat_t matrix[MATRIX_SIZE];
|
||||||
|
etkFloat_t opacity; //!< opacity on the result drawing ...
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// basic definition type for the renderer
|
||||||
|
typedef agg::renderer_base<agg::pixfmt_rgba32> rendererBase_t;
|
||||||
|
typedef agg::renderer_scanline_aa_solid<rendererBase_t> rendererSolid_t;
|
||||||
|
|
||||||
|
class Renderer {
|
||||||
|
private:
|
||||||
|
uint8_t * m_buffer;
|
||||||
|
public:
|
||||||
|
Renderer(uint32_t width, uint32_t height);
|
||||||
|
~Renderer(void);
|
||||||
|
void WritePpm(etk::UString fileName);
|
||||||
|
coord2D_ts m_size;
|
||||||
|
agg::rendering_buffer * m_renderingBuffer;
|
||||||
|
agg::pixfmt_rgba32 * m_pixFrame;
|
||||||
|
rendererBase_t * m_renderBase;
|
||||||
|
rendererSolid_t * m_renderArea;
|
||||||
|
agg::rasterizer_scanline_aa<> m_rasterizer; //!< AGG renderer system
|
||||||
|
agg::scanline_p8 m_scanLine; //!<
|
||||||
|
agg::trans_affine m_basicMatrix; //!< specific render of the curent element
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -219,28 +219,6 @@ bool write_ppm(const unsigned char* buf,
|
|||||||
typedef agg::rgba8 color_type;
|
typedef agg::rgba8 color_type;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Start of AGG abstraction for SVG render ...
|
|
||||||
|
|
||||||
typedef agg::renderer_base<agg::pixfmt_rgba32> rendererBase_t;
|
|
||||||
typedef agg::renderer_scanline_aa_solid<renderer_base> rendererSolid_t;
|
|
||||||
class Renderer {
|
|
||||||
private:
|
|
||||||
char * m_buffer;
|
|
||||||
public:
|
|
||||||
Renderer(uint32_t width, uint32_t height);
|
|
||||||
~Renderer(void);
|
|
||||||
uint32_t m_sizeX;
|
|
||||||
uint32_t m_sizeY;
|
|
||||||
rendererSolid_t * m_renderArea;
|
|
||||||
agg::rasterizer_scanline_aa<> m_rasterizer; //!< AGG renderer system
|
|
||||||
agg::scanline_p8 m_scanLine; //!<
|
|
||||||
agg::trans_affine m_basicMatrix; //!< specific render of the curent element
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
agg::rasterizer_scanline_aa<> g_rasterizer;
|
agg::rasterizer_scanline_aa<> g_rasterizer;
|
||||||
agg::scanline_p8 g_scanline;
|
agg::scanline_p8 g_scanline;
|
||||||
agg::path_storage g_path;
|
agg::path_storage g_path;
|
||||||
@ -479,94 +457,30 @@ uint32_t parse_lion(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors
|
|||||||
return pathIdx.Size();
|
return pathIdx.Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void svg::Parser::AggDraw(svg::Renderer& myRenderer, svg::PaintState &curentPaintProp)
|
||||||
void svg::Parser::AggDraw(agg::path_storage& path, etk::VectorType<agg::rgba8> &colors, etk::VectorType<uint32_t> &pathIdx, PaintState &curentPaintProp)
|
|
||||||
{
|
{
|
||||||
SVG_ERROR("printed color X = " << m_paint.fill);
|
curentPaintProp = m_paint;
|
||||||
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);
|
|
||||||
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, curentPaintProp);
|
m_subElementList[iii]->AggDraw(myRenderer, 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);
|
|
||||||
agg::pod_array_adaptor<unsigned> path_idx(&g_pathLdxList[0], g_npaths);
|
|
||||||
agg::bounding_rect(g_path, path_idx, 0, g_npaths, &g_x1, &g_y1, &g_x2, &g_y2);
|
|
||||||
g_base_dx = (g_x2 - g_x1) / 2.0;
|
|
||||||
g_base_dy = (g_y2 - g_y1) / 2.0;
|
|
||||||
|
|
||||||
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::bounding_rect(g_path2, path_idx2, 0, g_pathLdxList2.Size(), &g_x12, &g_y12, &g_x22, &g_y22);
|
|
||||||
g_base_dx2 = (g_x22 - g_x12) / 2.0;
|
|
||||||
g_base_dy2 = (g_y22 - g_y12) / 2.0;
|
|
||||||
|
|
||||||
float coefmult = 2;
|
float coefmult = 2;
|
||||||
int width = 800*coefmult;
|
int width = 800*coefmult;
|
||||||
int height = 600*coefmult;
|
int height = 600*coefmult;
|
||||||
|
|
||||||
unsigned char* buffer = new unsigned char[width * height * 4];
|
svg::Renderer * myRenderer = new svg::Renderer(width,height);
|
||||||
memset(buffer, 255, width * height * 4);
|
AggDraw(*myRenderer, m_paint);
|
||||||
|
etk::UString tmpFileOut = "yyy_out_";
|
||||||
agg::rendering_buffer rbuf(buffer, width, height, width * 4);
|
tmpFileOut += m_fileName.GetShortFilename();
|
||||||
agg::pixfmt_rgba32 pixf(rbuf);
|
tmpFileOut += ".ppm";
|
||||||
renderer_base rb(pixf);
|
myRenderer->WritePpm(tmpFileOut);
|
||||||
renderer_solid r(rb);
|
|
||||||
|
|
||||||
agg::trans_affine mtx;
|
|
||||||
mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
|
|
||||||
mtx *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
|
|
||||||
mtx *= agg::trans_affine_rotation(g_angle);// + agg::pi);
|
|
||||||
mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
|
|
||||||
mtx *= agg::trans_affine_translation(width*0.3, height/2);
|
|
||||||
|
|
||||||
// This code renders the lion:
|
|
||||||
agg::conv_transform<agg::path_storage, agg::trans_affine> trans(g_path, mtx);
|
|
||||||
agg::render_all_paths(g_rasterizer, g_scanline, r, trans, &g_colorsList[0], &g_pathLdxList[0], g_npaths);
|
|
||||||
// This code renders a second svg syctem ...:
|
|
||||||
|
|
||||||
agg::trans_affine mtx2;
|
|
||||||
mtx2 *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2);
|
|
||||||
mtx2 *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
|
|
||||||
mtx2 *= agg::trans_affine_rotation(g_angle);// + agg::pi);
|
|
||||||
mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
|
|
||||||
mtx2 *= agg::trans_affine_translation(width*0.7, height/2);
|
|
||||||
|
|
||||||
agg::conv_transform<agg::path_storage, agg::trans_affine> trans2(g_path2, mtx2);
|
|
||||||
agg::render_all_paths(g_rasterizer, g_scanline, r, trans2, &g_colorsList2[0], &g_pathLdxList2[0], g_pathLdxList2.Size());
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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, PaintState &curentPaintProp);
|
virtual void AggDraw(svg::Renderer& myRenderer, PaintState &curentPaintProp);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user