<commit_before>/*
 *  svg.cpp
 *  MonkVG--iOS-OpenGL
 *
 *  Created by <NAME> on 8/12/10.
 *  Copyright 2010 Zero Vision. All rights reserved.
 *
 */

#include "mkOpenVG_SVG.h"

namespace MonkSVG {
	
	OpenVG_SVGHandler::OpenVG_SVGHandler()
	:	ISVGHandler()
	,	_mode( kGroupParseMode )
	,	_current_group( &_root_group ) 
	,	_blackBackFill( 0 )
	,	_batch( 0 )
	{
		_blackBackFill = vgCreatePaint();
		VGfloat fcolor[4] = { 0,0,0,1 };
		vgSetParameterfv( _blackBackFill, VG_PAINT_COLOR, 4, &fcolor[0]);
		_use_transform.setIdentity();

		//_root_transform.setScale( 1, -1 );
		
	}
	
	OpenVG_SVGHandler::~OpenVG_SVGHandler() {
		vgDestroyPaint( _blackBackFill );
		_blackBackFill = 0;
		
		if( _batch ) {
			vgDestroyBatchMNK( _batch );
			_batch = 0;
		}

	}
	
	
	void OpenVG_SVGHandler::draw() {
		
		// clear out the transform stack
		_transform_stack.clear();
		
		float m[9];
		vgGetMatrix( m );
		// assume the current openvg matrix is like the camera matrix and should always be applied first
		Transform2d top;
		Transform2d::multiply( top, Transform2d(m), rootTransform() );	// multiply by the root transform
		pushTransform( top );
		
		// SVG is origin at the top, left (openvg is origin at the bottom, left)
		// so need to flip
//		Transform2d flip;
//		flip.setScale( 1, -1 );
//		pushTransform( flip );
		
		if( _batch ) {
			vgDrawBatchMNK( _batch );
		} else {
			draw_recursive( _root_group );
		}
		
		vgLoadMatrix( m );	// restore matrix
		_transform_stack.clear();
	}
	
	void OpenVG_SVGHandler::draw_recursive( group_t& group ) {
		
		// push the group matrix onto the stack
		pushTransform( group.transform ); vgLoadMatrix( topTransform().m );
		
		for ( list<path_object_t>::iterator it = group.path_objects.begin(); it != group.path_objects.end(); it++ ) {
			path_object_t& po = *it;
			uint32_t draw_params = 0;
			if ( po.fill ) {
				vgSetPaint( po.fill, VG_FILL_PATH );
				draw_params |= VG_FILL_PATH;
			}
			
			if ( po.stroke ) {
				vgSetPaint( po.stroke, VG_STROKE_PATH );
				vgSetf( VG_STROKE_LINE_WIDTH, po.stroke_width );
				draw_params |= VG_STROKE_PATH;
			}<commit_msg>integrated optimized monksvg/vg<commit_after>/*
 *  svg.cpp
 *  MonkVG--iOS-OpenGL
 *
 *  Created by <NAME> on 8/12/10.
 *  Copyright 2010 Zero Vision. All rights reserved.
 *
 */

#include "mkOpenVG_SVG.h"

namespace MonkSVG {
	
	OpenVG_SVGHandler::OpenVG_SVGHandler()
	:	ISVGHandler()
	,	_mode( kGroupParseMode )
	,	_current_group( &_root_group ) 
	,	_blackBackFill( 0 )
	,	_batch( 0 )
	{
		_blackBackFill = vgCreatePaint();
		VGfloat fcolor[4] = { 0,0,0,1 };
		vgSetParameterfv( _blackBackFill, VG_PAINT_COLOR, 4, &fcolor[0]);
		_use_transform.setIdentity();

		//_root_transform.setScale( 1, -1 );
		
	}
	
	OpenVG_SVGHandler::~OpenVG_SVGHandler() {
		vgDestroyPaint( _blackBackFill );
		_blackBackFill = 0;
		
		if( _batch ) {
			vgDestroyBatchMNK( _batch );
			_batch = 0;
		}

	}
	
	
	void OpenVG_SVGHandler::draw() {
		
		// clear out the transform stack
		_transform_stack.clear();
		
		float m[9];
		vgGetMatrix( m );
		// assume the current openvg matrix is like the camera matrix and should always be applied first
		Transform2d top;
		Transform2d::multiply( top, Transform2d(m), rootTransform() );	// multiply by the root transform
		pushTransform( top );
		
		// SVG is origin at the top, left (openvg is origin at the bottom, left)
		// so need to flip
//		Transform2d flip;
//		flip.setScale( 1, -1 );
//		pushTransform( flip );
		
		if( _batch ) {
			vgLoadMatrix( topTransform().m );
			vgDrawBatchMNK( _batch );
		} else {
			draw_recursive( _root_group );
		}
		
		vgLoadMatrix( m );	// restore matrix
		_transform_stack.clear();
	}
	
	void OpenVG_SVGHandler::draw_recursive( group_t& group ) {
		
		// push the group matrix onto the stack
		pushTransform( group.transform ); vgLoadMatrix( topTransform().m );
		
		for ( list<path_object_t>::iterator it = group.path_objects.begin(); it != group.path_objects.end(); it++ ) {
			path_object_t& po = *it;
			uint32_t draw_params = 0;
			if ( po.fill ) {
				vgSetPaint( po.fill, VG_FILL_PATH );
				draw_params |= VG_FILL_PATH;
			}
			
			if ( po.stroke ) {
				vgSetPaint( po.stroke, VG_STROKE_PATH );
				vgSetf( VG_STROKE_LINE_WIDTH, po.stroke_width );
				draw_params |= VG_STROKE_PATH;
			}
{'fraction_non_alphanumeric': 0.12573167876375557, 'fraction_numerical': 0.014984781081713885, 'mean_word_length': 3.337055837563452, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3800608', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1583, 'n_words': 358}