2012-03-20 22:41:35 +01:00
/**
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* @ file parserSVG / Polygon . cpp
* @ brief basic poligon parsing ( Sources )
* @ author Edouard DUPIN
* @ date 20 / 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/Polygon.h>
2012-03-26 18:18:52 +02:00
# include <agg-2.4/agg_conv_stroke.h>
# include <agg-2.4/agg_path_storage.h>
2012-03-20 22:41:35 +01:00
2012-03-22 17:45:05 +01:00
svg : : Polygon : : Polygon ( PaintState parentPaintState ) : svg : : Base ( parentPaintState )
2012-03-20 22:41:35 +01:00
{
}
svg : : Polygon : : ~ Polygon ( void )
{
}
2012-03-27 18:32:44 +02:00
bool svg : : Polygon : : Parse ( TiXmlNode * node , agg : : trans_affine & parentTrans , coord2D_ts & sizeMax )
2012-03-20 22:41:35 +01:00
{
2012-03-21 18:01:50 +01:00
ParseTransform ( node ) ;
ParsePaintAttr ( node ) ;
2012-03-26 18:18:52 +02:00
SVG_VERBOSE ( " parsed P1. trans : ( " < < m_transformMatrix . sx < < " , " < < m_transformMatrix . shy < < " , " < < m_transformMatrix . shx < < " , " < < m_transformMatrix . sy < < " , " < < m_transformMatrix . tx < < " , " < < m_transformMatrix . ty < < " ) " ) ;
// add the property of the parrent modifications ...
m_transformMatrix * = parentTrans ;
SVG_VERBOSE ( " parsed P2. trans : ( " < < m_transformMatrix . sx < < " , " < < m_transformMatrix . shy < < " , " < < m_transformMatrix . shx < < " , " < < m_transformMatrix . sy < < " , " < < m_transformMatrix . tx < < " , " < < m_transformMatrix . ty < < " ) " ) ;
2012-03-21 18:01:50 +01:00
const char * sss = node - > ToElement ( ) - > Attribute ( " points " ) ;
if ( NULL = = sss ) {
SVG_ERROR ( " (l " < < node - > Row ( ) < < " ) polygon: missing points attribute " ) ;
return false ;
}
2012-03-27 18:32:44 +02:00
sizeMax . x = 0 ;
sizeMax . y = 0 ;
2012-03-21 18:01:50 +01:00
SVG_VERBOSE ( " Parse polygon : \" " < < sss < < " \" " ) ;
while ( ' \0 ' ! = sss [ 0 ] ) {
coord2D_ts pos ;
int32_t n ;
if ( sscanf ( sss , " %f,%f %n " , & pos . x , & pos . y , & n ) = = 2 ) {
m_listPoint . PushBack ( pos ) ;
sss + = n ;
2012-03-27 18:32:44 +02:00
sizeMax . x = etk_max ( sizeMax . x , pos . x ) ;
sizeMax . y = etk_max ( sizeMax . y , pos . y ) ;
2012-03-21 18:01:50 +01:00
} else {
break ;
}
}
return true ;
}
void svg : : Polygon : : Display ( int32_t spacing )
{
SVG_DEBUG ( SpacingDist ( spacing ) < < " Polygon nbPoint= " < < m_listPoint . Size ( ) ) ;
}
2012-03-26 18:18:52 +02:00
void svg : : Polygon : : AggDraw ( svg : : Renderer & myRenderer , agg : : trans_affine & basicTrans )
2012-03-21 18:01:50 +01:00
{
2012-03-26 18:18:52 +02:00
myRenderer . m_renderArea - > color ( agg : : rgba8 ( m_paint . fill . red , m_paint . fill . green , m_paint . fill . blue , m_paint . fill . alpha ) ) ;
2012-03-23 17:57:27 +01:00
2012-03-26 18:18:52 +02:00
agg : : path_storage path ;
path . start_new_path ( ) ;
2012-03-23 17:57:27 +01:00
2012-03-21 18:01:50 +01:00
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 . close_polygon ( ) ;
2012-03-27 18:32:44 +02:00
/*
// configure the end of the line :
switch ( m_paint . lineCap ) {
case svg : : LINECAP_SQUARE :
path . line_cap ( agg : : square_cap ) ;
break ;
case svg : : LINECAP_ROUND :
path . line_cap ( agg : : round_cap ) ;
break ;
default : // svg::LINECAP_BUTT
path . line_cap ( agg : : butt_cap ) ;
break ;
}
switch ( m_paint . lineJoin ) {
case svg : : LINEJOIN_BEVEL :
path . line_join ( agg : : bevel_join ) ;
break ;
case svg : : LINEJOIN_ROUND :
path . line_join ( agg : : round_join ) ;
break ;
default : // svg::LINEJOIN_MITER
path . line_join ( agg : : miter_join ) ;
break ;
}
*/
2012-03-23 17:57:27 +01:00
2012-03-26 18:18:52 +02:00
agg : : trans_affine mtx = m_transformMatrix ;
mtx * = basicTrans ;
2012-03-23 17:57:27 +01:00
2012-03-27 18:32:44 +02:00
if ( m_paint . fill . alpha ! = 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 ) ;
myRenderer . m_rasterizer . add_path ( trans ) ;
agg : : render_scanlines ( myRenderer . m_rasterizer , myRenderer . m_scanLine , * myRenderer . m_renderArea ) ;
}
2012-03-26 18:18:52 +02:00
2012-03-27 18:32:44 +02:00
if ( m_paint . strokeWidth > 0 & & m_paint . stroke . alpha ! = 0x00 ) {
2012-03-26 18:18:52 +02:00
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 : : path_storage > myPolygonStroke ( path ) ;
myPolygonStroke . width ( m_paint . strokeWidth ) ;
agg : : conv_transform < agg : : conv_stroke < agg : : path_storage > , agg : : trans_affine > transStroke ( myPolygonStroke , mtx ) ;
// set the filling mode :
myRenderer . m_rasterizer . filling_rule ( agg : : fill_non_zero ) ;
myRenderer . m_rasterizer . add_path ( transStroke ) ;
agg : : render_scanlines ( myRenderer . m_rasterizer , myRenderer . m_scanLine , * myRenderer . m_renderArea ) ;
}
2012-03-20 22:41:35 +01:00
}
2012-03-21 18:01:50 +01:00