예제 #1
0
svgtiny_code svgtiny_parse_line(Poco::XML::Element *line,
		struct svgtiny_parse_state state)
{
	float x1 = 0, y1 = 0, x2 = 0, y2 = 0;
	float *p;
	//xmlAttr *attr;
    Poco::XML::Attr *attr;

	//for (attr = line->properties; attr; attr = attr->next) {
    //for( attr = line->FirstAttribute(); attr; attr = attr->Next() ) {
    
    Poco::XML::NamedNodeMap *map = line->attributes();
    for( int i = 0; i < map->length(); i++ ) {
    
		//const char *name = (const char *) attr->name;
		//const char *content = (const char *) attr->children->content;
        
        //const char *name = (const char *) attr->Name();
		//const char *content = (const char *) attr->Value();
        
        const char *name = (const char *) map->item(i)->localName().c_str();
		const char *content = (const char *) map->item(i)->getNodeValue().c_str();
        
		if (strcmp(name, "x1") == 0)
			x1 = svgtiny_parse_length(content,
					state.viewport_width, state);
		else if (strcmp(name, "y1") == 0)
			y1 = svgtiny_parse_length(content,
					state.viewport_height, state);
		else if (strcmp(name, "x2") == 0)
			x2 = svgtiny_parse_length(content,
					state.viewport_width, state);
		else if (strcmp(name, "y2") == 0)
			y2 = svgtiny_parse_length(content,
					state.viewport_height, state);
        }
	svgtiny_parse_paint_attributes(line, &state);
	svgtiny_parse_transform_attributes(line, &state);

//    p = (float*) malloc(7 * sizeof p[0]);
    p = (float*) malloc(6 * sizeof p[0]);
	if (!p)
		return svgtiny_OUT_OF_MEMORY;

	p[0] = svgtiny_PATH_MOVE;
	p[1] = x1;
	p[2] = y1;
	p[3] = svgtiny_PATH_LINE;
	p[4] = x2;
	p[5] = y2;
//	p[6] = svgtiny_PATH_CLOSE;

//    return svgtiny_add_path(p, 7, &state);
    return svgtiny_add_path(p, 6, &state);    
}
예제 #2
0
bool ofXml::removeAttribute(const string& path) 
{

    string attributeName, pathToAttribute;

    Poco::XML::Element *e;
    if(element) {
        
        bool hasPath = false;

        // you can pass either /node[@attr] or just attr
        if(path.find("[@") != string::npos)
        {
            int attrBegin = path.find("[@");
            int start = attrBegin + 2;
            int end = path.find("]", start);
            attributeName = path.substr( start, end - start );
            pathToAttribute = path.substr(0, attrBegin);
            hasPath = true;
        }
        else
        {
            attributeName = path;
        }
        
        if(hasPath) {
            e = (Poco::XML::Element*) element->getNodeByPath(pathToAttribute);
        } else {
            e = element;
        }

    } else {
        ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
        return false;
    }
    
    if(e) {
        Poco::XML::NamedNodeMap *map = e->attributes();
        
		for(unsigned long i = 0; i < map->length(); i++) {
            if(map->item(i)->nodeName() == attributeName) {
                e->removeAttribute(map->item(i)->nodeName());
            }
        }
        
        map->release();
        return true;
    }
    return false;
}
예제 #3
0
bool ofXml::removeAttributes(const string& path) 
{
    Poco::XML::Element *e;
    if(element) {
        if(path.find("[@") == string::npos) {
            // we need to create a proper path
            string attributePath = "[@" + path + "]";
            e = (Poco::XML::Element*) element->getNodeByPath(attributePath);
        } else {
            e = (Poco::XML::Element*) element->getNodeByPath(path);
        }

    } else {
        ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
        return false;
    }
    
    if(e) {
        Poco::XML::NamedNodeMap *map = e->attributes();
        
        for(unsigned long i = 0; i < map->length(); i++) {
            e->removeAttribute(map->item(i)->nodeName());
        }
        
        map->release();
        return true;
    }
    return false;
}
예제 #4
0
void svgtiny_parse_position_attributes(const Poco::XML::Element *node,
		const struct svgtiny_parse_state state,
		float *x, float *y, float *width, float *height)
{
	//xmlAttr *attr;
    const Poco::XML::Attr *attr;

	*x = 0;
	*y = 0;
	*width = state.viewport_width;
	*height = state.viewport_height;

	//for (attr = node->properties; attr; attr = attr->next) {
    //for( attr = node->FirstAttribute(); attr; attr = attr->Next() ) {
    Poco::XML::NamedNodeMap *map = node->attributes();
    //for( attr = node->FirstAttribute(); attr; attr = attr->Next() ) {
    for( int i = 0; i < map->length(); i++ ) {
    
    
		//const char *name = (const char *) attr->name;
		//const char *content = (const char *) attr->children->content;
        
        // good god this is ugly
        const char *name = (const char *) map->item(i)->localName().c_str();
		const char *content = (const char *) map->item(i)->getNodeValue().c_str();
        const string content_str = map->item(i)->getNodeValue();
        
		if (strcmp(name, "x") == 0)
			*x = svgtiny_parse_length(content,
					state.viewport_width, state);
		else if (strcmp(name, "y") == 0)
			*y = svgtiny_parse_length(content,
					state.viewport_height, state);
		else if (strcmp(name, "width") == 0)
			*width = svgtiny_parse_length(content,
					state.viewport_width, state);
		else if (strcmp(name, "height") == 0)
			*height = svgtiny_parse_length(content,
					state.viewport_height, state);
	}
}
예제 #5
0
std::map<std::string, std::string>
XmlHandler::get_attributes_from_tag(const std::string &xpath) {
  std::map<std::string, std::string> attributes_map;
  Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
  Poco::XML::Node *pNode = it.nextNode();
  Poco::XML::Node *detectorNode = pNode->getNodeByPath(xpath);
  if (detectorNode) {
    Poco::XML::NamedNodeMap *attributes = detectorNode->attributes();
    for (unsigned int i = 0; i < attributes->length(); i++) {
      Poco::XML::Node *attribute = attributes->item(i);
      attributes_map.emplace(attribute->nodeName(), attribute->nodeValue());
    }
  }
  return attributes_map;
}
예제 #6
0
bool ofXml::removeAttributes()
{

    if(element) {
        Poco::XML::NamedNodeMap *map = element->attributes();
        
        for(unsigned long i = 0; i < map->length(); i++) {
            element->removeAttribute(map->item(i)->nodeName());
        }
        
        map->release();
        return true;
    }
    ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
    return false;

}
예제 #7
0
/** Create the dimension as a MDHistogram dimension.
*/
Mantid::Geometry::MDHistoDimension* IMDDimensionFactory::doCreate() const
{
  using namespace Mantid::Geometry;

  if(m_dimensionXML == NULL)
  {
    throw std::runtime_error("Must provide dimension xml before creation");
  }

  Poco::XML::NamedNodeMap* attributes = m_dimensionXML->attributes();

  //First and only attribute is the dimension id.
  Poco::XML::Node* dimensionId = attributes->item(0);
  std::string id = dimensionId->innerText();

  std::string name = m_dimensionXML->getChildElement("Name")->innerText();
  Poco::XML::Element* unitsElement = m_dimensionXML->getChildElement("Units");
  std::string units = "None";
  if(NULL != unitsElement)
  {
   //Set units if they exist.
   units = unitsElement->innerText();
  }
  double upperBounds = atof(m_dimensionXML->getChildElement("UpperBounds")->innerText().c_str());
  double lowerBounds = atof(m_dimensionXML->getChildElement("LowerBounds")->innerText().c_str());
  unsigned int nBins = atoi(m_dimensionXML->getChildElement("NumberOfBins")->innerText().c_str());
  Poco::XML::Element* integrationXML = m_dimensionXML->getChildElement("Integrated");

  if (NULL != integrationXML)
  {
    double upperLimit = atof(integrationXML->getChildElement("UpperLimit")->innerText().c_str());
    double lowerLimit = atof(integrationXML->getChildElement("LowerLimit")->innerText().c_str());

    //As it is not currently possible to set integration ranges on a MDDimension or MDGeometryDescription, boundaries become integration ranges.
    upperBounds = upperLimit;
    lowerBounds = lowerLimit;
  }

  return new MDHistoDimension(name, id, units, lowerBounds, upperBounds, nBins);
}
예제 #8
0
svgtiny_code svgtiny_parse_ellipse(Poco::XML::Element *ellipse,
		struct svgtiny_parse_state state)
{
	float x = 0, y = 0, rx = -1, ry = -1;
	float *p;
	Poco::XML::Attr *attr;

	//for (attr = ellipse->properties; attr; attr = attr->next) {
    //for( attr = ellipse->FirstAttribute(); attr; attr = attr->Next() ) {
    
    Poco::XML::NamedNodeMap *map = ellipse->attributes();
    for( int i = 0; i < map->length(); i++ ) {
    
		//const char *name = (const char *) attr->name;
		//const char *content = (const char *) attr->children->content;
        
        //const char *name = (const char *) attr->Name();
		//const char *content = (const char *) attr->Value();
        
        const char *name = (const char *) map->item(i)->localName().c_str();
		const char *content = (const char *) map->item(i)->getNodeValue().c_str();
        
		if (strcmp(name, "cx") == 0)
			x = svgtiny_parse_length(content,
					state.viewport_width, state);
		else if (strcmp(name, "cy") == 0)
			y = svgtiny_parse_length(content,
					state.viewport_height, state);
		else if (strcmp(name, "rx") == 0)
			rx = svgtiny_parse_length(content,
					state.viewport_width, state);
		else if (strcmp(name, "ry") == 0)
			ry = svgtiny_parse_length(content,
					state.viewport_width, state);
        }
	svgtiny_parse_paint_attributes(ellipse, &state);
	svgtiny_parse_transform_attributes(ellipse, &state);

	if (rx < 0 || ry < 0) {
		//state.diagram->error_line = ellipse->line;
		state.diagram->error_message = "ellipse: rx or ry missing "
				"or negative";
		return svgtiny_SVG_ERROR;
	}
	if (rx == 0 || ry == 0)
		return svgtiny_OK;

	p = (float*) malloc(32 * sizeof p[0]);
	if (!p)
		return svgtiny_OUT_OF_MEMORY;

	p[0] = svgtiny_PATH_MOVE;
	p[1] = x + rx;
	p[2] = y;
	p[3] = svgtiny_PATH_BEZIER;
	p[4] = x + rx;
	p[5] = y + ry * KAPPA;
	p[6] = x + rx * KAPPA;
	p[7] = y + ry;
	p[8] = x;
	p[9] = y + ry;
	p[10] = svgtiny_PATH_BEZIER;
	p[11] = x - rx * KAPPA;
	p[12] = y + ry;
	p[13] = x - rx;
	p[14] = y + ry * KAPPA;
	p[15] = x - rx;
	p[16] = y;
	p[17] = svgtiny_PATH_BEZIER;
	p[18] = x - rx;
	p[19] = y - ry * KAPPA;
	p[20] = x - rx * KAPPA;
	p[21] = y - ry;
	p[22] = x;
	p[23] = y - ry;
	p[24] = svgtiny_PATH_BEZIER;
	p[25] = x + rx * KAPPA;
	p[26] = y - ry;
	p[27] = x + rx;
	p[28] = y - ry * KAPPA;
	p[29] = x + rx;
	p[30] = y;
	p[31] = svgtiny_PATH_CLOSE;
	
	return svgtiny_add_path(p, 32, &state);
}
예제 #9
0
void svgtiny_parse_paint_attributes(const Poco::XML::Element *node,
		struct svgtiny_parse_state *state)
{
	//const xmlAttr *attr;
    const Poco::XML::Attr *attr;

	//for (attr = node->properties; attr; attr = attr->next) {
    
    //for( attr = node->FirstAttribute(); attr; attr = attr->Next() ) {
    Poco::XML::NamedNodeMap *map = node->attributes();
    for( int i = 0; i < map->length(); i++ ) {
    
		//const char *name = (const char *) attr->name;
		//const char *content = (const char *) attr->children->content;
        
        //const char *name = (const char *) attr->Name();
		//const char *content = (const char *) attr->Value();
        attr = (Poco::XML::Attr*) map->item(i);
        const char *name = (const char *) attr->localName().c_str();
		const char *content = (const char *) attr->getNodeValue().c_str();
        
		if (strcmp(name, "fill") == 0)
			svgtiny_parse_color(content, &state->fill, state);
		else if (strcmp(name, "stroke") == 0)
			svgtiny_parse_color(content, &state->stroke, state);
		else if (strcmp(name, "stroke-width") == 0)
			state->stroke_width = svgtiny_parse_length(content,
					state->viewport_width, *state);
		else if (strcmp(name, "style") == 0) {
			//const char *style = (const char *) attr->children->content;
            
            const char *style = attr->getValue().c_str();
            
			const char *s;
			char *value;
			if ((s = strstr(style, "fill:"))) {
				s += 5;
				while (*s == ' ')
					s++;
				value = strndup(s, strcspn(s, "; "));
				svgtiny_parse_color(value, &state->fill, state);
				free(value);
			}
			if ((s = strstr(style, "stroke:"))) {
				s += 7;
				while (*s == ' ')
					s++;
				value = strndup(s, strcspn(s, "; "));
				svgtiny_parse_color(value, &state->stroke, state);
				free(value);
			}
			if ((s = strstr(style, "stroke-width:"))) {
				s += 13;
				while (*s == ' ')
					s++;
				value = strndup(s, strcspn(s, "; "));
				state->stroke_width = svgtiny_parse_length(value,
						state->viewport_width, *state);
				free(value);
			}
        } else if (strcmp(name, "stroke-linecap") == 0) {
            if (strcmp(content, "butt") == 0) {
                state->stroke_linecap = svgtiny_STROKE_LINECAP_BUTT;
            } else if (strcmp(content, "round") == 0) {
                state->stroke_linecap = svgtiny_STROKE_LINECAP_ROUND;
            } else if (strcmp(content, "square") == 0) {
                state->stroke_linecap = svgtiny_STROKE_LINECAP_SQUARE;
            }
        } else if (strcmp(name, "stroke-linejoin") == 0) {
            if (strcmp(content, "miter") == 0) {
                state->stroke_linejoin = svgtiny_STROKE_LINEJOIN_MITER;
            } else if (strcmp(content, "bevel") == 0) {
                state->stroke_linejoin = svgtiny_STROKE_LINEJOIN_BEVEL;
            } else if (strcmp(content, "round") == 0) {
                state->stroke_linejoin = svgtiny_STROKE_LINEJOIN_ROUND;
            }
        }
	}
}