示例#1
0
svgtiny_code svgtiny_add_path(float *p, unsigned int n,
		struct svgtiny_parse_state *state)
{
	struct svgtiny_shape *shape;

	if (state->fill == svgtiny_LINEAR_GRADIENT)
		return svgtiny_add_path_linear_gradient(p, n, state);

	svgtiny_transform_path(p, n, state);

	shape = svgtiny_add_shape(state);
	if (!shape) {
		free(p);
		return svgtiny_OUT_OF_MEMORY;
	}
	shape->path = p;
	shape->path_length = n;
	state->diagram->shape_count++;
    
    if(state->currNode){
       // ofLog()<<"svgtiny_add_path "<<state->info->flatlist.size()<<" state->currNode->type "<<state->currNode->type<<endl;
        state->info->flatlist.push_back(state->currNode);

    }else{
        ofLog()<<"WARNING svgtiny_add_path lost pointer. Make sure the svg node is represented in SVG_TYPE_... "<<endl;

    }

	return svgtiny_OK;
}
示例#2
0
svgtiny_code svgtiny_parse_text(xmlNode *text,
		struct svgtiny_parse_state state)
{
	float x, y, width, height;
	float px, py;
	xmlNode *child;

	svgtiny_parse_position_attributes(text, state,
			&x, &y, &width, &height);
	svgtiny_parse_font_attributes(text, &state);
	svgtiny_parse_transform_attributes(text, &state);

	px = state.ctm.a * x + state.ctm.c * y + state.ctm.e;
	py = state.ctm.b * x + state.ctm.d * y + state.ctm.f;
/* 	state.ctm.e = px - state.origin_x; */
/* 	state.ctm.f = py - state.origin_y; */

	/*struct css_style style = state.style;
	style.font_size.value.length.value *= state.ctm.a;*/

	for (child = text->children; child; child = child->next) {
		svgtiny_code code = svgtiny_OK;

		if (child->type == XML_TEXT_NODE) {
			struct svgtiny_shape *shape = svgtiny_add_shape(&state);
			if (!shape)
				return svgtiny_OUT_OF_MEMORY;
			shape->text = strdup((const char *) child->content);
			shape->text_x = px;
			shape->text_y = py;
			state.diagram->shape_count++;

		} else if (child->type == XML_ELEMENT_NODE &&
				strcmp((const char *) child->name,
					"tspan") == 0) {
			code = svgtiny_parse_text(child, state);
		}

		if (!code != svgtiny_OK)
			return code;
	}

	return svgtiny_OK;
}
示例#3
0
svgtiny_code svgtiny_add_path(float *p, unsigned int n,
		struct svgtiny_parse_state *state)
{
	struct svgtiny_shape *shape;

	if (state->fill == svgtiny_LINEAR_GRADIENT)
		return svgtiny_add_path_linear_gradient(p, n, state);

	svgtiny_transform_path(p, n, state);

	shape = svgtiny_add_shape(state);
	if (!shape) {
		free(p);
		return svgtiny_OUT_OF_MEMORY;
	}
	shape->path = p;
	shape->path_length = n;
	state->diagram->shape_count++;

	return svgtiny_OK;
}
示例#4
0
svgtiny_code svgtiny_parse_text(dom_element *text,
		struct svgtiny_parse_state state)
{
	float x, y, width, height;
	float px, py;
	dom_node *child;
	dom_exception exc;

	svgtiny_setup_state_local(&state);

	svgtiny_parse_position_attributes(text, state,
			&x, &y, &width, &height);
	svgtiny_parse_font_attributes(text, &state);
	svgtiny_parse_transform_attributes(text, &state);

	px = state.ctm.a * x + state.ctm.c * y + state.ctm.e;
	py = state.ctm.b * x + state.ctm.d * y + state.ctm.f;
/* 	state.ctm.e = px - state.origin_x; */
/* 	state.ctm.f = py - state.origin_y; */

	/*struct css_style style = state.style;
	style.font_size.value.length.value *= state.ctm.a;*/
	
        exc = dom_node_get_first_child(text, &child);
	if (exc != DOM_NO_ERR) {
		return svgtiny_LIBDOM_ERROR;
		svgtiny_cleanup_state_local(&state);
	}
	while (child != NULL) {
		dom_node *next;
		dom_node_type nodetype;
		svgtiny_code code = svgtiny_OK;

		exc = dom_node_get_node_type(child, &nodetype);
		if (exc != DOM_NO_ERR) {
			dom_node_unref(child);
			svgtiny_cleanup_state_local(&state);
			return svgtiny_LIBDOM_ERROR;
		}
		if (nodetype == DOM_ELEMENT_NODE) {
			dom_string *nodename;
			exc = dom_node_get_node_name(child, &nodename);
			if (exc != DOM_NO_ERR) {
				dom_node_unref(child);
				svgtiny_cleanup_state_local(&state);
				return svgtiny_LIBDOM_ERROR;
			}
			if (dom_string_caseless_isequal(nodename,
							state.interned_tspan))
				code = svgtiny_parse_text((dom_element *)child,
							  state);
			dom_string_unref(nodename);
		} else if (nodetype == DOM_TEXT_NODE) {
			struct svgtiny_shape *shape = svgtiny_add_shape(&state);
			dom_string *content;
			if (shape == NULL) {
				dom_node_unref(child);
				svgtiny_cleanup_state_local(&state);
				return svgtiny_OUT_OF_MEMORY;
			}
			exc = dom_text_get_whole_text(child, &content);
			if (exc != DOM_NO_ERR) {
				dom_node_unref(child);
				svgtiny_cleanup_state_local(&state);
				return svgtiny_LIBDOM_ERROR;
			}
			if (content != NULL) {
				shape->text = strndup(dom_string_data(content),
						      dom_string_byte_length(content));
				dom_string_unref(content);
			} else {
				shape->text = strdup("");
			}
			shape->text_x = px;
			shape->text_y = py;
			state.diagram->shape_count++;
		}

		if (code != svgtiny_OK) {
			dom_node_unref(child);
			svgtiny_cleanup_state_local(&state);
			return code;
		}
		exc = dom_node_get_next_sibling(child, &next);
		dom_node_unref(child);
		if (exc != DOM_NO_ERR) {
			svgtiny_cleanup_state_local(&state);
			return svgtiny_LIBDOM_ERROR;
		}
		child = next;
	}

	svgtiny_cleanup_state_local(&state);

	return svgtiny_OK;
}
示例#5
0
svgtiny_code svgtiny_parse_text(Poco::XML::Element *text,
		struct svgtiny_parse_state state)
{
	float x, y, width, height;
	float px, py;
	Poco::XML::Element *child;

	svgtiny_parse_position_attributes(text, state,
			&x, &y, &width, &height);
	svgtiny_parse_font_attributes(text, &state);
	svgtiny_parse_transform_attributes(text, &state);

	px = state.ctm.a * x + state.ctm.c * y + state.ctm.e;
	py = state.ctm.b * x + state.ctm.d * y + state.ctm.f;
    
/* 	state.ctm.e = px - state.origin_x; */
/* 	state.ctm.f = py - state.origin_y; */

	/*struct css_style style = state.style;
	style.font_size.value.length.value *= state.ctm.a;*/

	//for (child = text->children; child; child = child->next) {
    //for( child = (Poco::XML::Element*) text->FirstChild( false ); child; child = (Poco::XML::Element*) child->NextSibling( false ) ) {
    
    
    Poco::XML::NodeIterator it(text, Poco::XML::NodeFilter::SHOW_ELEMENT | Poco::XML::NodeFilter::SHOW_TEXT);
    Poco::XML::Node* pNode = it.nextNode();
    while (pNode) {
    
		svgtiny_code code = svgtiny_OK;

		if (pNode->getNodeValue().compare("text") == 0) 
        {
			struct svgtiny_shape *shape = svgtiny_add_shape(&state);
			
            if (!shape)
				return svgtiny_OUT_OF_MEMORY;
            
			//shape->text = strdup((const char *) child->content);
            
            shape->text = strdup((const char *) pNode->getNodeValue().c_str());
            
			shape->text_x = px;
			shape->text_y = py;
			state.diagram->shape_count++;

		} 
        //else if (strcmp((const char *) child->Value(), "tspan") == 0) 
        else if (pNode->getNodeValue().compare("tspan") == 0) 
        {
			code = svgtiny_parse_text(child, state);
		}
    
        pNode = it.nextNode();

		if (!code != svgtiny_OK)
			return code;
	}

	return svgtiny_OK;
}