Exemple #1
0
  void
  SVGStylable::glTraverseMarker(svgl::Context* svglContext, svgl::GLInfo* glinfo, float shapeStrokeWidth)
  {
    SVGElement * meAsElement = dynamic_cast<SVGElement*>(this);
    dom::Document * currentDoc = meAsElement->getOwnerDocument();
    SVGMarkerElement* marker = getSVGMarkerElement(svglContext->externalEntityManager, currentDoc);
    SVGMarkerElement *marker_start=marker, *marker_end=marker, *marker_mid=marker;
    marker_start = getSVGMarkerStartElement(svglContext->externalEntityManager, currentDoc);
    marker_end = getSVGMarkerEndElement(svglContext->externalEntityManager, currentDoc);
    marker_mid = getSVGMarkerMidElement(svglContext->externalEntityManager, currentDoc);

    if( !(marker || marker_start || marker_end || marker_mid) )
      return;

    BezierPath bezierpath;
    asBezier(svglContext, glinfo, &bezierpath);

#if 0
    SVGStylable* stylable = dynamic_cast<SVGStylable*>(shape);
    if(!stylable) {
      std::cerr << "unstylable referring shape for marker " __FL__;
      return;
    }
#endif
    
    SVGStylable* stylable = this;

    if(!marker_start) {
      marker_start=marker;
    } else {
      css::CSSStyleDeclaration& style = marker_start->getStyle().getValue();
      style.setParent(stylable->getStyle().getValue().getParent());
    }

    if(!marker_end) {
      marker_end=marker;
    } else {
      css::CSSStyleDeclaration& style = marker_end->getStyle().getValue();
      style.setParent(stylable->getStyle().getValue().getParent());
    }

    if(!marker_mid) {
      marker_mid=marker;
    } else {
      css::CSSStyleDeclaration& style = marker_mid->getStyle().getValue();
      style.setParent(stylable->getStyle().getValue().getParent());
    }

    if(marker) {
      css::CSSStyleDeclaration& style = marker->getStyle().getValue();
      style.setParent(stylable->getStyle().getValue().getParent());
    }
    
    marker=0;


    glPushMatrix();
    for (BezierPath::const_iterator i = bezierpath.begin();
	 i!=bezierpath.end();
	 ++i) {

      if(marker)
	marker->glTraverseFromUse(svglContext, glinfo, shapeStrokeWidth, 0);

      switch ( (*i).type() ) {

      case BezierPath::move: {
	const BezierPath::Point& p0 = (*i)[0];
	glTranslatef(p0.x(), p0.y(), 0);
	marker = marker_start;
      }
      break;

      case BezierPath::line: {
	const BezierPath::Point& p0 = (*i)[0];
	const BezierPath::Point& p1 = (*i)[1];
	BezierPath::Coord dx = p1.x()-p0.x();
	BezierPath::Coord dy = p1.y()-p0.y();
	glTranslatef(dx, dy, 0);
	marker = marker_mid;
      }
      break;
      
      case BezierPath::close: {
	const BezierPath::Point& p0 = (*i)[0];
	const BezierPath::Point& p1 = (*i)[1];
	BezierPath::Coord dx = p1.x()-p0.x();
	BezierPath::Coord dy = p1.y()-p0.y();
	glTranslatef(dx, dy, 0);
	marker = marker_end;
      }
      break;
      default:
	STDDBG;
	break;
      }
    }

    marker=marker_end;
    if(marker)
      marker->glTraverseFromUse(svglContext, glinfo, shapeStrokeWidth, 0);

    glPopMatrix();
  }