Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Svg.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, The Cinder Project
3  All rights reserved.
4 
5  This code is designed for use with the Cinder C++ library, http://libcinder.org
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8  the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and
11  the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13  the following disclaimer in the documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22  POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #pragma once
26 
27 #include "cinder/Cinder.h"
28 #include "cinder/Xml.h"
29 #include "cinder/Vector.h"
30 #include "cinder/Color.h"
31 #include "cinder/Shape2d.h"
32 #include "cinder/PolyLine.h"
33 #include "cinder/Exception.h"
34 #include "cinder/MatrixAffine2.h"
35 #include "cinder/Surface.h"
36 #include "cinder/Font.h"
37 #include "cinder/Function.h"
38 
39 #include <map>
40 #include <boost/noncopyable.hpp>
41 
42 namespace cinder { namespace svg {
43 
48 
49 class Node;
50 class Group;
51 class Rect;
52 class Circle;
53 class Path;
54 class TextSpan;
55 class Style;
56 class Line;
57 class Ellipse;
58 class Polyline;
59 class Polygon;
60 class Image;
62 
63 typedef std::function<bool(const Node&, svg::Style *)> RenderVisitor;
64 
66 class Renderer {
67  public:
68  Renderer() {}
69 
70  virtual ~Renderer() {}
71 
72  void setVisitor( const std::function<bool(const Node&, svg::Style *)> &visitor );
73 
74  virtual void pushGroup( const Group &group, float opacity ) {}
75  virtual void popGroup() {}
76  virtual void drawPath( const svg::Path &path ) {}
77  virtual void drawPolyline( const svg::Polyline &polyline ) {}
78  virtual void drawPolygon( const svg::Polygon &polygon ) {}
79  virtual void drawLine( const svg::Line &line ) {}
80  virtual void drawRect( const svg::Rect &rect ) {}
81  virtual void drawCircle( const svg::Circle &circle ) {}
82  virtual void drawEllipse( const svg::Ellipse &ellipse ) {}
83  virtual void drawImage( const svg::Image &image ) {}
84  virtual void drawTextSpan( const svg::TextSpan &span ) {}
85 
86  virtual void pushMatrix( const MatrixAffine2f &m ) {}
87  virtual void popMatrix() {}
88  virtual void pushStyle( const svg::Style &style ) {}
89  virtual void popStyle( const svg::Style &style ) {}
90  virtual void pushFill( const class Paint &paint ) {}
91  virtual void popFill() {}
92  virtual void pushStroke( const class Paint &paint ) {}
93  virtual void popStroke() {}
94  virtual void pushFillOpacity( float opacity ) {}
95  virtual void popFillOpacity() {}
96  virtual void pushStrokeOpacity( float opacity ) {}
97  virtual void popStrokeOpacity() {}
98  virtual void pushStrokeWidth( float width ) {}
99  virtual void popStrokeWidth() {}
100  virtual void pushFillRule( FillRule rule ) {}
101  virtual void popFillRule() {}
102  virtual void pushLineCap( LineCap lineCap ) {}
103  virtual void popLineCap() {}
104  virtual void pushLineJoin( LineJoin lineJoin ) {}
105  virtual void popLineJoin() {}
106  virtual void pushTextPen( const Vec2f &penPos ) {}
107  virtual void popTextPen() {}
108  virtual void pushTextRotation( float rotation ) {}
109  virtual void popTextRotation() {}
110 
111  bool visit( const Node &node, svg::Style *style ) const {
112  if( mVisitor )
113  return (*mVisitor)( node, style );
114  else
115  return true;
116  }
117 
118  protected:
119  // this is a shared_ptr to work around a bug in Clang 4.0
120  std::shared_ptr<std::function<bool(const Node&, svg::Style *)> > mVisitor;
121 
122  friend class svg::Node;
123 };
124 
126 class Value {
127  public:
128  enum Unit { USER, PX, PERCENT, PT, PC, MM, CM, INCH, EM, EX };
129 
130  Value() : mValue( 0 ), mUnit( USER ) {}
131  Value( float value, Unit unit = USER ) : mValue( value ), mUnit( unit ) {}
132 
133  float asUser( float percentOf = 100, float dpi = 72, float fontSize = 12, float fontXHeight = 7 ) const;
134 
135  bool isUser() const { return mUnit == USER; }
136  bool isPercent() const { return mUnit == PERCENT; }
137  bool isPixels() const { return mUnit == PX; }
138 
139  static Value parse( const char **sInOut );
140  static Value parse( const std::string &s );
141 
143  float mValue;
144 };
145 
147 class Paint {
148  public:
150 
151  Paint();
152  Paint( uint8_t type );
153  Paint( const ColorA8u &color );
154 
155  static Paint parse( const char *value, bool *specified, const Node *parentNode );
156 
157  bool isNone() const { return mType == NONE; }
158  bool isLinearGradient() const { return mType == LINEAR_GRADIENT; }
159  bool isRadialGradient() const { return mType == RADIAL_GRADIENT; }
160  const ColorA8u& getColor( size_t idx = 0 ) const { return mStops[idx].second; }
161  float getOffset( size_t idx ) const { return mStops[idx].first; }
162  size_t getNumColors() const { return mStops.size(); }
163 
164  // only apply to gradients
165  Vec2f getCoords0() const { return mCoords0; } // (x1,y1) on linear, (cx,cy) on radial
166  Vec2f getCoords1() const { return mCoords1; } // (x2,y2) on linear, (fx,fy) on radial
167  float getRadius() const { return mRadius; } // radial-only
169  bool specifiesTransform() const { return mSpecifiesTransform; }
171 
172  uint8_t mType;
173  std::vector<std::pair<float,ColorA8u> > mStops;
174 
176  float mRadius;
180 };
181 
183 class Style {
184  public:
185  Style();
186  Style( const XmlTree &xml, const Node *parent );
187 
189  static Style makeGlobalDefaults();
191  void clear();
192 
193  bool specifiesFill() const { return mSpecifiesFill; }
194  void unspecifyFill() { mSpecifiesFill = false; }
195  const Paint& getFill() const { return mFill; }
196  void setFill( const Paint &fill ) { mSpecifiesFill = true; mFill = fill; }
197  static const Paint& getFillDefault() { return sPaintBlack; }
198 
199  bool specifiesStroke() const { return mSpecifiesStroke; }
200  void unspecifyStroke() { mSpecifiesStroke = false; }
201  const Paint& getStroke() const { return mStroke; }
202  void setStroke( const Paint &stroke ) { mSpecifiesStroke = true; mStroke = stroke; }
203  static const Paint& getStrokeDefault() { return sPaintNone; }
204 
205  bool specifiesOpacity() const { return mSpecifiesOpacity; }
207  float getOpacity() const { return mOpacity; }
208  void setOpacity( float opacity ) { mSpecifiesOpacity = true; mOpacity = opacity; }
209  static float getOpacityDefault() { return 1.0f; }
210 
213  float getStrokeOpacity() const { return mStrokeOpacity; }
214  void setStrokeOpacity( float strokeOpacity ) { mSpecifiesStrokeOpacity = true; mStrokeOpacity = strokeOpacity; }
215  static float getStrokeOpacityDefault() { return 1.0f; }
216 
219  float getFillOpacity() const { return mFillOpacity; }
220  void setFillOpacity( float fillOpacity ) { mSpecifiesFillOpacity = true; mFillOpacity = fillOpacity; }
221  static float getFillOpacityDefault() { return 1.0f; }
222 
225  float getStrokeWidth() const { return mStrokeWidth; }
226  void setStrokeWidth( float strokeWidth ) { mSpecifiesStrokeWidth = true; mStrokeWidth = strokeWidth; }
227  static float getStrokeWidthDefault() { return 1.0f; }
228 
229  bool specifiesFillRule() const { return mSpecifiesFillRule; }
231  FillRule getFillRule() const { return mFillRule; }
232  void setFillRule( FillRule fillRule ) { mSpecifiesFillRule = true; mFillRule = fillRule; }
234 
235  bool specifiesLineCap() const { return mSpecifiesLineCap; }
237  LineCap getLineCap() const { return mLineCap; }
238  void setLineCap( LineCap lineCap ) { mSpecifiesLineCap = true; mLineCap = lineCap; }
240 
241  bool specifiesLineJoin() const { return mSpecifiesLineJoin; }
243  LineJoin getLineJoin() const { return mLineJoin; }
244  void setLineJoin( LineJoin lineJoin ) { mSpecifiesLineJoin = true; mLineJoin = lineJoin; }
246 
247  // fonts
250  const std::vector<std::string>& getFontFamilies() const { return mFontFamilies; }
251  std::vector<std::string>& getFontFamilies() { return mFontFamilies; }
252  void setFontFamily( const std::string &family ) { mSpecifiesFontFamilies = true; mFontFamilies.clear(); mFontFamilies.push_back( family ); }
253  void setFontFamilies( const std::vector<std::string> &families ) { mSpecifiesFontFamilies = true; mFontFamilies = families; }
254  static const std::vector<std::string>& getFontFamiliesDefault();
255 
256  bool specifiesFontSize() const { return mSpecifiesFontSize; }
258  Value getFontSize() const { return mFontSize; }
259  void setFontSize( const Value &fontSize ) { mSpecifiesFontSize = true; mFontSize = fontSize; }
260  static Value getFontSizeDefault() { return Value( 12 ); }
261 
262  bool specifiesFontWeight() const { return mSpecifiesFontWeight; }
265  void setFontWeight( FontWeight weight ) { mSpecifiesFontWeight = true; mFontWeight = weight; }
267 
268  bool specifiesVisible() const { return mSpecifiesVisible; }
269  bool isVisible() const { return mVisible; }
270  void setVisible( bool visible ) { mSpecifiesVisible = true; mVisible = visible; }
272 
273  bool isDisplayNone() const { return mDisplayNone; }
274  void setDisplayNone( bool displayNone ) { mDisplayNone = displayNone; }
275 
276  void startRender( Renderer &renderer, bool isNodeDrawable ) const;
277  void finishRender( Renderer &renderer, bool isNodeDrawable ) const;
278 
279  void parseStyleAttribute( const std::string &stylePropertyString, const Node *parent );
280  bool parseProperty( const std::string &key, const std::string &value, const Node *parent );
281 
282  protected:
284  float mOpacity;
287 
291  float mStrokeWidth;
298 
299  // fonts
301  std::vector<std::string> mFontFamilies;
304 
305  // visibility
307 
308  private:
309  static Paint sPaintNone, sPaintBlack;
310 };
311 
313 class Node {
314  public:
315  Node( const Node *parent ) : mParent( parent ), mSpecifiesTransform( false ), mBoundingBoxCached( false ) {}
316  virtual ~Node() {}
317 
319  class Doc* getDoc() const;
321  const Node* getParent() const { return mParent; }
323  const std::string& getId() const { return mId; }
325  std::string getDomPath() const;
327  const Style& getStyle() const { return mStyle; }
329  void setStyle( const Style &style ) { mStyle = style; }
331  Style calcInheritedStyle() const;
332 
334  virtual bool containsPoint( const Vec2f &pt ) const { return false; }
335 
337  void render( Renderer &renderer ) const;
338 
340  virtual const Node* findInAncestors( const std::string &elementId ) const;
342  Paint findPaintInAncestors( const std::string &paintName ) const;
343 
345  bool specifiesTransform() const { return mSpecifiesTransform; }
358 
363 
365  virtual Shape2d getShape() const { return Shape2d(); }
368 
370  const Paint& getFill() const;
372  const Paint& getStroke() const;
374  float getOpacity() const;
376  float getFillOpacity() const;
378  float getStrokeOpacity() const;
380  FillRule getFillRule() const;
382  LineCap getLineCap() const;
384  LineJoin getLineJoin() const;
386  float getStrokeWidth() const;
388  const std::vector<std::string>& getFontFamilies() const;
390  Value getFontSize() const;
392  bool isVisible() const;
394  bool isDisplayNone() const { return mStyle.isDisplayNone(); }
395 
396 
397  protected:
398  Node( const Node *parent, const XmlTree &xml );
399  // returns whether this type of node directly renders anything. Everything but groups.
400  virtual bool isDrawable() const { return true; }
401 
402  void startRender( Renderer &renderer, const Style &style ) const;
403  void finishRender( Renderer &renderer, const Style &style ) const;
404  virtual void renderSelf( Renderer &renderer ) const = 0;
405 
406  virtual Rectf calcBoundingBox() const { return Rectf( 0, 0, 0, 0 ); }
407 
408  static Paint parsePaint( const char *value, bool *specified, const Node *parentNode );
410  static bool parseTransformComponent( const char **c, MatrixAffine2f *result );
411 
412  static std::string findStyleValue( const std::string &styleString, const std::string &key );
413  void parseStyle( const std::string &value );
414 
415  protected:
416  const Node *mParent;
421  mutable bool mBoundingBoxCached;
423 
424  private:
425  void firstStartRender( Renderer &renderer ) const;
426 
427  friend class Group;
428  friend class Use;
429 };
430 
432 class Gradient : public Node {
433  public:
434  Gradient( const Node *parent, const XmlTree &xml );
435 
436  class Stop {
437  public:
438  Stop( const Node *parent, const XmlTree &xml );
439 
440  float mOffset; // normalized 0-1
442  float mOpacity;
444  };
445 
447  bool specifiesTransform() const { return mSpecifiesTransform; }
448 
449  protected:
450  virtual void renderSelf( Renderer &renderer ) const {}
451 
452  void parse( const Node *parent, const XmlTree &xml );
453  void copyAttributesFrom( const Gradient &rhs );
454  Paint asPaint() const;
455 
456  std::vector<Stop> mStops;
461 };
462 
464 class LinearGradient : public Gradient {
465  public:
466  LinearGradient( const Node *parent, const XmlTree &xml );
467 
468  Paint asPaint() const;
469 
470  protected:
471  void parse( const XmlTree &xml );
472 
473  virtual bool isDrawable() const { return false; }
474 };
475 
477 class RadialGradient : public Gradient {
478  public:
479  RadialGradient( const Node *parent, const XmlTree &xml );
480 
481  Paint asPaint() const;
482 
483  protected:
484  void parse( const XmlTree &xml );
485 
486  virtual bool isDrawable() const { return false; }
487  float mRadius;
488 };
489 
491 class Circle : public Node {
492  public:
493  Circle( const Node *parent ) : Node( parent ) {}
494  Circle( const Node *parent, const XmlTree &xml );
495 
496  Vec2f getCenter() const { return mCenter; }
497  float getRadius() const { return mRadius; }
498 
499  virtual bool containsPoint( const Vec2f &pt ) const { return pt.distanceSquared( mCenter ) < mRadius * mRadius; }
500 
501  virtual Shape2d getShape() const;
502 
503  protected:
504  virtual void renderSelf( Renderer &renderer ) const;
506 
508  float mRadius;
509 };
510 
512 class Ellipse : public Node {
513  public:
514  Ellipse( const Node *parent ) : Node( parent ) {}
515  Ellipse( const Node *parent, const XmlTree &xml );
516 
517  Vec2f getCenter() const { return mCenter; }
518  float getRadiusX() const { return mRadiusX; }
519  float getRadiusY() const { return mRadiusY; }
520 
521  bool containsPoint( const Vec2f &pt ) const;
522 
523  virtual Shape2d getShape() const;
524 
525  protected:
526  virtual void renderSelf( Renderer &renderer ) const;
528 
531 };
532 
534 class Path : public Node {
535  public:
536  Path( const Node *parent ) : Node( parent ) {}
537  Path( const Node *parent, const XmlTree &xml );
538 
539  const Shape2d& getShape2d() const { return mPath; }
540  void appendShape2d( Shape2d *appendTo ) const;
541 
542  virtual bool containsPoint( const Vec2f &pt ) const { return mPath.contains( pt ); }
543 
544  virtual Shape2d getShape() const { return mPath; }
545 
546  protected:
547  virtual void renderSelf( Renderer &renderer ) const;
548  virtual Rectf calcBoundingBox() const { return mPath.calcPreciseBoundingBox(); }
549 
551 };
552 
554 class Line : public Node {
555  public:
556  Line( const Node *parent ) : Node( parent ) {}
557  Line( const Node *parent, const XmlTree &xml );
558 
559  const Vec2f& getPoint1() const { return mPoint1; }
560  const Vec2f& getPoint2() const { return mPoint2; }
561 
562  virtual Shape2d getShape() const;
563 
564  protected:
565  virtual void renderSelf( Renderer &renderer ) const;
566  virtual Rectf calcBoundingBox() const { return Rectf( mPoint1, mPoint2 ); }
567 
569 };
570 
572 class Rect : public Node {
573  public:
574  Rect( const Node *parent ) : Node( parent ) {}
575  Rect( const Node *parent, const XmlTree &xml );
576 
577  const Rectf& getRect() const { return mRect; }
578 
579  virtual bool containsPoint( const Vec2f &pt ) const { return mRect.contains( pt ); }
580 
581  virtual Shape2d getShape() const;
582 
583  protected:
584  virtual void renderSelf( Renderer &renderer ) const;
585  virtual Rectf calcBoundingBox() const { return mRect; }
586 
588 };
589 
591 class Polygon : public Node {
592  public:
593  Polygon( const Node *parent ) : Node( parent ) {}
594  Polygon( const Node *parent, const XmlTree &xml );
595 
596  const PolyLine2f& getPolyLine() const { return mPolyLine; }
598 
599  virtual bool containsPoint( const Vec2f &pt ) const { return mPolyLine.contains( pt ); }
600 
601  virtual Shape2d getShape() const;
602 
603  protected:
604  virtual void renderSelf( Renderer &renderer ) const;
605  virtual Rectf calcBoundingBox() const { return Rectf( mPolyLine.getPoints() ); }
606 
608 };
609 
611 class Polyline : public Node {
612  public:
613  Polyline( const Node *parent ) : Node( parent ) {}
614  Polyline( const Node *parent, const XmlTree &xml );
615 
616  const PolyLine2f& getPolyLine() const { return mPolyLine; }
618 
619  virtual bool containsPoint( const Vec2f &pt ) const { return mPolyLine.contains( pt ); }
620 
621  virtual Shape2d getShape() const;
622 
623  protected:
624  virtual void renderSelf( Renderer &renderer ) const;
625  virtual Rectf calcBoundingBox() const { return Rectf( mPolyLine.getPoints() ); }
626 
628 };
629 
631 class Use : public Node {
632  public:
633  Use( const Node *parent, const XmlTree &xml );
634 
635  virtual bool isDrawable() const { return false; }
636 
637  virtual Shape2d getShape() const{ if( mReferenced ) return mReferenced->getShape(); else return Shape2d(); }
638 
639  protected:
640  virtual void renderSelf( Renderer &renderer ) const;
641  virtual Rectf calcBoundingBox() const { if( mReferenced ) return mReferenced->getBoundingBox(); else return Rectf(0,0,0,0); }
642 
643  void parse( const XmlTree &xml );
644 
646 };
647 
649 class Image : public Node {
650  public:
651  Image( const Node *parent, const XmlTree &xml );
652 
653  const Rectf& getRect() const { return mRect; }
654  const std::shared_ptr<Surface8u> getSurface() const { return mImage; }
655 
656  virtual bool containsPoint( const Vec2f &pt ) const { return mRect.contains( pt ); }
657 
658  protected:
659  virtual void renderSelf( Renderer &renderer ) const;
660  virtual Rectf calcBoundingBox() const { return mRect; }
661 
662  static std::shared_ptr<Surface8u> parseDataImage( const std::string &data );
663 
665  fs::path mFilePath;
666  std::shared_ptr<Surface8u> mImage;
667 };
668 
669 typedef std::shared_ptr<TextSpan> TextSpanRef;
670 
672 class TextSpan : public Node {
673  public:
674  class Attributes {
675  public:
677  Attributes( const XmlTree &xml );
678 
679  void startRender( Renderer &renderer ) const;
680  void finishRender( Renderer &renderer ) const;
681 
682  std::vector<Value> mX, mY;
683  float mDx, mDy;
684  std::vector<Value> mRotate;
685  float mTextLength;
687  };
688 
689  TextSpan( const Node *parent, const XmlTree &xml );
690  TextSpan( const Node *parent, const std::string &spanString );
691 
692  const std::string& getString() const { return mString; }
693  const std::shared_ptr<Font> getFont() const;
695  std::vector<std::pair<uint16_t,Vec2f> > getGlyphMeasures() const;
696  Vec2f getTextPen() const;
697  float getRotation() const;
698 
699  protected:
700  virtual void renderSelf( Renderer &renderer ) const;
701 
702  bool mIgnoreAttributes; // TextSpans that are actually the contents of Text's attributes should be ignored
705  mutable std::shared_ptr<Font> mFont;
706  mutable std::shared_ptr<std::vector<std::pair<uint16_t,Vec2f> > > mGlyphMeasures;
707  mutable std::shared_ptr<Shape2d> mShape;
708 
709  std::vector<TextSpanRef> mSpans;
710 
711  friend class Text;
712 };
713 
715 class Text : public Node {
716  public:
717  Text( const Node *parent, const XmlTree &xml );
718 
719  Vec2f getTextPen() const;
720  float getRotation() const;
721 
722  protected:
723  virtual void renderSelf( Renderer &renderer ) const;
724 
726 
727  std::vector<TextSpanRef> mSpans;
728 };
729 
731 class Group : public Node, private boost::noncopyable {
732  public:
733  Group( const Node *parent ) : Node( parent ) {}
734  Group( const Node *parent, const XmlTree &xml );
735  ~Group();
736 
738  template<typename T>
739  const T* find( const std::string &id ) { return dynamic_cast<const T*>( findNode( id ) ); }
741  const Node* findNode( const std::string &id, bool recurse = true ) const;
743  template<typename T>
744  const T* findByIdContains( const std::string &idPartial ) { return dynamic_cast<const T*>( findNodeByIdContains( idPartial ) ); }
746  const Node* findNodeByIdContains( const std::string &idPartial, bool recurse = true ) const;
747  virtual const Node* findInAncestors( const std::string &elementId ) const;
749  const Node& getChild( const std::string &id ) const;
751  const Node& operator/( const std::string &id ) const { return getChild( id ); }
752 
754  virtual Shape2d getShape() const { return getMergedShape2d(); }
755 
757  void appendMergedShape2d( Shape2d *appendTo ) const;
758 
760  const std::list<Node*>& getChildren() const { return mChildren; }
762  std::list<Node*>& getChildren() { return mChildren; }
763 
764  protected:
765  Node* nodeUnderPoint( const Vec2f &absolutePoint, const MatrixAffine2f &parentInverseMatrix ) const;
766  Shape2d getMergedShape2d() const;
767 
768  virtual void renderSelf( Renderer &renderer ) const;
769  virtual Rectf calcBoundingBox() const;
770 
771  virtual bool isDrawable() const { return false; }
772  void parse( const XmlTree &xml );
773 
774  std::list<Node*> mChildren;
775  std::shared_ptr<Group> mDefs;
776 };
777 
778 
779 typedef std::shared_ptr<Doc> DocRef;
781 class Doc : public Group {
782  public:
783  Doc() : Group( 0 ), mWidth( 0 ), mHeight( 0 ) {}
784  Doc( const fs::path &filePath );
785  Doc( DataSourceRef dataSource, const fs::path &filePath = fs::path() );
786 
787  static DocRef create( const fs::path &filePath );
788  static DocRef create( DataSourceRef dataSource, const fs::path &filePath = fs::path() );
789  static DocRef createFromSvgz( DataSourceRef dataSource, const fs::path &filePath = fs::path() );
790 
792  int32_t getWidth() const { return mWidth; }
794  int32_t getHeight() const { return mHeight; }
796  Vec2i getSize() const { return Vec2i( getWidth(), getHeight() ); }
798  float getAspectRatio() const { return getWidth() / (float)getHeight(); }
800  Area getBounds() const { return Area( 0, 0, mWidth, mHeight ); }
801 
803  float getDpi() const { return 72.0f; }
804 
806  Node* nodeUnderPoint( const Vec2f &pt );
807 
809  std::shared_ptr<Surface8u> loadImage( fs::path relativePath );
810  private:
811  void loadDoc( DataSourceRef source, fs::path filePath );
812 
813  virtual void renderSelf( Renderer &renderer ) const;
814 
815  std::shared_ptr<XmlTree> mXmlTree;
816  std::map<fs::path,std::shared_ptr<Surface8u> > mImageCache;
817 
818  fs::path mFilePath;
819  Area mViewBox;
820  int32_t mWidth, mHeight;
821 };
822 
824 class Exc : public Exception
825 {};
826 
827 class ValueExc : public Exc
828 {};
829 
830 class FloatParseExc : public Exc
831 {};
832 
833 class PathParseExc : public Exc
834 {};
835 
836 class TransformParseExc : public Exc
837 {};
838 
839 class ExcChildNotFound : public Exc {
840  public:
841  ExcChildNotFound( const std::string &child ) throw();
842 
843  virtual const char* what() const throw() { return mMessage; }
844 
845  private:
846  char mMessage[2048];
847 };
848 
849 
850 } } // namespace cinder::svg
Paint mStroke
Definition: Svg.h:289
static bool parseTransformComponent(const char **c, MatrixAffine2f *result)
Definition: Svg.cpp:800
Line(const Node *parent)
Definition: Svg.h:556
bool mUseObjectBoundingBox
Definition: Svg.h:177
Circle(const Node *parent)
Definition: Svg.h:493
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.h:365
void setFontWeight(FontWeight weight)
Definition: Svg.h:265
SVG Style for a node. Corresponds to SVG Styling: http://www.w3.org/TR/SVG/styling.html.
Definition: Svg.h:183
float mOpacity
Definition: Svg.h:442
bool mSpecifiesTransform
Definition: Svg.h:459
const Rectf & getRect() const
Definition: Svg.h:653
bool mSpecifiesFillOpacity
Definition: Svg.h:285
virtual ~Node()
Definition: Svg.h:316
Represents a group of SVG elements. http://www.w3.org/TR/SVG/struct.html#Groups.
Definition: Svg.h:731
SVG Text element. http://www.w3.org/TR/SVG/text.html#TextElement.
Definition: Svg.h:715
std::vector< Value > mRotate
Definition: Svg.h:684
Group(const Node *parent)
Definition: Svg.h:733
GLsizei GLsizei GLchar * source
Definition: GLee.h:2361
void appendShape2d(Shape2d *appendTo) const
Definition: Svg.cpp:1486
SVG Circle element: http://www.w3.org/TR/SVG/shapes.html#CircleElement.
Definition: Svg.h:491
Paint findPaintInAncestors(const std::string &paintName) const
Finds the svg::Paint node with ID elementId amongst this Node's ancestors. Returns a default svg::Pai...
Definition: Svg.cpp:958
virtual void popFillOpacity()
Definition: Svg.h:95
SVG Value/Unit pair.
Definition: Svg.h:126
float mStrokeWidth
Definition: Svg.h:291
bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.cpp:1166
std::shared_ptr< Surface8u > loadImage(fs::path relativePath)
Utility function to load an image relative to the document. Caches results.
Definition: Svg.cpp:2244
bool mSpecifiesStrokeOpacity
Definition: Svg.h:285
float getOpacity() const
Definition: Svg.h:207
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.cpp:1143
const Node * findNode(const std::string &id, bool recurse=true) const
Recursively searches for a child element named id. Returns NULL on failure.
Definition: Svg.cpp:1717
virtual bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.h:619
virtual ~Renderer()
Definition: Svg.h:70
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1623
virtual void popGroup()
Definition: Svg.h:75
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1493
virtual const Node * findInAncestors(const std::string &elementId) const
Finds the node with ID elementId amongst this Node's ancestors. Returns NULL on failure.
Definition: Svg.cpp:1775
virtual Shape2d getShape() const
Returns the merged Shape2d for all children of the group.
Definition: Svg.h:754
Definition: Svg.h:47
bool mUseObjectBoundingBox
Definition: Svg.h:458
virtual Rectf calcBoundingBox() const
Definition: Svg.h:641
Polyline(const Node *parent)
Definition: Svg.h:613
Shape2d transformCopy(const MatrixAffine2f &matrix) const
Returns a copy transformed by matrix.
Definition: Shape2d.cpp:87
bool mSpecifiesFontWeight
Definition: Svg.h:300
void unspecifyStrokeWidth()
Definition: Svg.h:224
void setStrokeWidth(float strokeWidth)
Definition: Svg.h:226
void unspecifyFill()
Definition: Svg.h:194
bool mSpecifiesOpacity
Definition: Svg.h:283
std::shared_ptr< Doc > DocRef
Definition: Svg.h:779
bool mSpecifiesStrokeWidth
Definition: Svg.h:290
Definition: Area.h:37
virtual bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.h:542
bool mSpecifiesVisible
Definition: Svg.h:306
virtual void pushTextRotation(float rotation)
Definition: Svg.h:108
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1546
virtual void pushTextPen(const Vec2f &penPos)
Definition: Svg.h:106
GLsizei const GLchar ** string
Definition: GLee.h:2427
Node(const Node *parent)
Definition: Svg.h:315
Style calcInheritedStyle() const
Returns the node's Style, including attributes inherited from its ancestors for attributes it does no...
Definition: Svg.cpp:899
bool mIgnoreAttributes
Definition: Svg.h:702
Vec2f getCoords0() const
Definition: Svg.h:165
Definition: Svg.h:149
float getOffset(size_t idx) const
Definition: Svg.h:161
float mRadius
Definition: Svg.h:487
std::vector< Value > mY
Definition: Svg.h:682
virtual void pushMatrix(const MatrixAffine2f &m)
Definition: Svg.h:86
Vec2f mPoint1
Definition: Svg.h:568
Node * nodeUnderPoint(const Vec2f &pt)
Returns the top-most Node which contains pt. Returns NULL if no Node contains the point...
Definition: Svg.cpp:2267
void setFillOpacity(float fillOpacity)
Definition: Svg.h:220
bool specifiesFontFamilies() const
Definition: Svg.h:248
virtual bool isDrawable() const
Definition: Svg.h:473
bool mBoundingBoxCached
Definition: Svg.h:421
std::vector< std::string > & getFontFamilies()
Definition: Svg.h:251
Doc()
Definition: Svg.h:783
Ellipse(const Node *parent)
Definition: Svg.h:514
virtual void drawEllipse(const svg::Ellipse &ellipse)
Definition: Svg.h:82
const Node & operator/(const std::string &id) const
Returns a reference to the child named id. Throws svg::ExcChildNotFound if not found.
Definition: Svg.h:751
static Style makeGlobalDefaults()
Returns a Style set appropriately for global defaults.
Definition: Svg.cpp:288
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1814
GLenum GLsizei width
Definition: GLee.h:969
virtual void popStrokeOpacity()
Definition: Svg.h:97
virtual void renderSelf(Renderer &renderer) const =0
FillRule getFillRule() const
Definition: Svg.h:231
void setStyle(const Style &style)
Sets the style defined on this Node but not inherited from ancestors.
Definition: Svg.h:329
static const Paint & getStrokeDefault()
Definition: Svg.h:203
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.cpp:1514
virtual bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.h:334
std::vector< std::pair< float, ColorA8u > > mStops
Definition: Svg.h:173
const Node * mParent
Definition: Svg.h:416
float getRotation() const
Definition: Svg.cpp:1970
virtual void drawPolyline(const svg::Polyline &polyline)
Definition: Svg.h:77
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1929
Definition: Svg.h:149
PolyLine2f & getPolyLine()
Definition: Svg.h:617
MatrixAffine2f getTransform() const
Definition: Svg.h:170
LineJoin getLineJoin() const
Returns node's line join, or the first among its ancestors when it has none.
Definition: Svg.cpp:694
Shape2d getMergedShape2d() const
Definition: Svg.cpp:1797
virtual void pushFillOpacity(float opacity)
Definition: Svg.h:94
FontWeight mFontWeight
Definition: Svg.h:303
void appendMergedShape2d(Shape2d *appendTo) const
Appends the merged Shape2d for the group to appentTo.
Definition: Svg.cpp:1804
RectT transformCopy(const class MatrixAffine2< T > &matrix) const
Returns a copy of the Rect transformed by matrix. Represents the bounding box of the transformed Rect...
Definition: Rect.cpp:202
std::vector< TextSpanRef > mSpans
Definition: Svg.h:727
std::shared_ptr< Font > mFont
Definition: Svg.h:705
void parse(const XmlTree &xml)
Definition: Svg.cpp:1111
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.h:450
void clear()
Marks all styles as unspecified.
Definition: Svg.cpp:312
Definition: Svg.h:839
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:1011
float getStrokeOpacity() const
Returns node's stroke opacity, or the first among its ancestors when it has none. ...
Definition: Svg.cpp:673
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.cpp:1173
float getRotation() const
Definition: Svg.cpp:2123
void setDisplayNone(bool displayNone)
Definition: Svg.h:274
std::vector< std::pair< uint16_t, Vec2f > > getGlyphMeasures() const
Returns a vector of glyph IDs and positions for the string, ignoring rotation. Cached and lazily calc...
Definition: Svg.cpp:2037
T x
Definition: Vector.h:71
static Paint parse(const char *value, bool *specified, const Node *parentNode)
Definition: Svg.cpp:203
bool mSpecifiesTransform
Definition: Svg.h:179
SVG Polyline Element: http://www.w3.org/TR/SVG/shapes.html#PolylineElement.
Definition: Svg.h:611
Definition: Svg.h:128
MatrixAffine2f getTransformAbsolute() const
Returns the absolute transformation of this node, which includes inherited transformations.
Definition: Svg.cpp:976
Vec2f getCenter() const
Definition: Svg.h:517
void unspecifyStrokeOpacity()
Definition: Svg.h:212
float mStrokeOpacity
Definition: Svg.h:286
LineCap getLineCap() const
Returns node's line cap, or the first among its ancestors when it has none.
Definition: Svg.cpp:687
virtual Rectf calcBoundingBox() const
Definition: Svg.h:660
void parse(const XmlTree &xml)
Definition: Svg.cpp:1656
LineJoin
Definition: Svg.h:46
void parse(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1002
void unspecifyVisible()
Definition: Svg.h:271
Definition: Svg.h:47
SVG Ellipse element: http://www.w3.org/TR/SVG/shapes.html#EllipseElement.
Definition: Svg.h:512
Paint asPaint() const
Definition: Svg.cpp:1120
virtual void pushGroup(const Group &group, float opacity)
Definition: Svg.h:74
bool mDisplayNone
Definition: Svg.h:306
static Value getFontSizeDefault()
Definition: Svg.h:260
float getFillOpacity() const
Definition: Svg.h:219
bool isLinearGradient() const
Definition: Svg.h:158
std::shared_ptr< TextSpan > TextSpanRef
Definition: Svg.h:669
float getStrokeWidth() const
Returns node's stroke width, or the first among its ancestors when it has none.
Definition: Svg.cpp:652
virtual bool isDrawable() const
Definition: Svg.h:486
bool isDisplayNone() const
Returns whether the Display property of this Node is set to 'None', preventing rendering of the node ...
Definition: Svg.h:394
FontWeight getFontWeight() const
Definition: Svg.h:264
void setFontFamilies(const std::vector< std::string > &families)
Definition: Svg.h:253
bool specifiesFillOpacity() const
Definition: Svg.h:217
bool mSpecifiesTransform
Definition: Svg.h:419
Definition: Xml.h:46
Vec2f getCoords1() const
Definition: Svg.h:166
static float getStrokeWidthDefault()
Definition: Svg.h:227
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: GLee.h:1023
float mDx
Definition: Svg.h:683
static float getFillOpacityDefault()
Definition: Svg.h:221
static LineJoin getLineJoinDefault()
Definition: Svg.h:245
std::shared_ptr< Group > mDefs
Definition: Svg.h:775
std::vector< Stop > mStops
Definition: Svg.h:456
virtual void drawPath(const svg::Path &path)
Definition: Svg.h:76
Definition: Svg.h:46
SVG tspan Element. Generally owned by a svg::Text Node. http://www.w3.org/TR/SVG/text.html#TSpanElement.
Definition: Svg.h:672
RadialGradient(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1105
virtual void popLineJoin()
Definition: Svg.h:105
bool isDisplayNone() const
Definition: Svg.h:273
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.h:637
Definition: Svg.h:47
bool specifiesOpacity() const
Definition: Svg.h:205
virtual bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.h:656
PolyLine2f mPolyLine
Definition: Svg.h:627
Definition: Svg.h:128
SVG Rect element: http://www.w3.org/TR/SVG/shapes.html#RectElement.
Definition: Svg.h:572
Vec2f mPoint2
Definition: Svg.h:568
virtual void pushLineJoin(LineJoin lineJoin)
Definition: Svg.h:104
virtual void popStroke()
Definition: Svg.h:93
bool specifiesStroke() const
Definition: Svg.h:199
virtual Rectf calcBoundingBox() const
Definition: Svg.h:605
SVG Radial gradient.
Definition: Svg.h:477
virtual Rectf calcBoundingBox() const
Definition: Svg.h:505
bool contains(const Vec2< Y > &pt) const
Is a point pt inside the rectangle.
Definition: Rect.h:80
void unspecifyFontWeight()
Definition: Svg.h:263
Gradient(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:996
void setVisitor(const std::function< bool(const Node &, svg::Style *)> &visitor)
Definition: Svg.cpp:172
Image(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1887
const T * find(const std::string &id)
Recursively searches for a child element of type svg::T named id. Returns NULL on failure to find the...
Definition: Svg.h:739
virtual void drawLine(const svg::Line &line)
Definition: Svg.h:79
bool mSpecifiesLineCap
Definition: Svg.h:294
const Node & getChild(const std::string &id) const
Returns a reference to the child named id. Throws svg::ExcChildNotFound if not found.
Definition: Svg.cpp:1789
std::vector< Value > mX
Definition: Svg.h:682
void unspecifyTransform()
Removes the local transformation of this node, effectively making it the identity matrix...
Definition: Svg.h:351
bool specifiesLineCap() const
Definition: Svg.h:235
FillRule mFillRule
Definition: Svg.h:293
void startRender(Renderer &renderer, const Style &style) const
Definition: Svg.cpp:932
static FontWeight getFontWeightDefault()
Definition: Svg.h:266
void setFontFamily(const std::string &family)
Definition: Svg.h:252
Vec2f getTextPen() const
Definition: Svg.cpp:1961
std::vector< TextSpanRef > mSpans
Definition: Svg.h:709
PolyLine2f & getPolyLine()
Definition: Svg.h:597
MatrixAffine2f mTransform
Definition: Svg.h:460
Definition: Svg.h:833
Unit
Definition: Svg.h:128
Definition: Svg.h:128
SVG Paint specification for fill or stroke, including solids and gradients.
Definition: Svg.h:147
Shape2d mPath
Definition: Svg.h:550
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1161
float getStrokeWidth() const
Definition: Svg.h:225
MatrixAffine2f mTransform
Definition: Svg.h:420
const Node * findNodeByIdContains(const std::string &idPartial, bool recurse=true) const
Recursively searches for a child element whose name contains idPartial. Returns NULL on failure...
Definition: Svg.cpp:1690
float asUser(float percentOf=100, float dpi=72, float fontSize=12, float fontXHeight=7) const
Definition: Svg.cpp:524
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1980
Rectf calcPreciseBoundingBox() const
Returns the precise bounding box of the Shape's curves. Slower to calculate than calcBoundingBox().
Definition: Shape2d.cpp:115
float mRadius
Definition: Svg.h:176
bool isVisible() const
Definition: Svg.h:269
virtual void popFill()
Definition: Svg.h:91
virtual void pushStrokeOpacity(float opacity)
Definition: Svg.h:96
MatrixAffine2< T > invertCopy(T epsilon=EPSILON) const
Returns a copy of the matrix inverted. epsilon specifies the tolerance for testing for singularity...
Definition: MatrixAffine2.h:577
LinearGradient(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1082
Definition: Svg.h:128
virtual bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.h:579
float mRadius
Definition: Svg.h:508
void startRender(Renderer &renderer, bool isNodeDrawable) const
Definition: Svg.cpp:473
Use(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1854
Definition: Svg.h:128
Definition: Svg.h:45
Value getFontSize() const
Returns node's font size, or the first among its ancestors when it has none.
Definition: Svg.cpp:708
static FillRule getFillRuleDefault()
Definition: Svg.h:233
const Paint & getFill() const
Definition: Svg.h:195
float mValue
Definition: Svg.h:143
FontWeight
Definition: Svg.h:47
Rect(const Node *parent)
Definition: Svg.h:574
Definition: Svg.h:47
Vec2f getTextPen() const
Definition: Svg.cpp:2111
static DocRef create(const fs::path &filePath)
Definition: Svg.cpp:2169
SVG Line element: http://www.w3.org/TR/SVG/shapes.html#LineElement.
Definition: Svg.h:554
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.h:544
Paint mFill
Definition: Svg.h:289
~Group()
Definition: Svg.cpp:1650
bool specifiesTransform() const
Returns whether this Node specifies a transformation.
Definition: Svg.h:345
void setFillRule(FillRule fillRule)
Definition: Svg.h:232
Style()
Definition: Svg.cpp:271
void setStrokeOpacity(float strokeOpacity)
Definition: Svg.h:214
bool visit(const Node &node, svg::Style *style) const
Definition: Svg.h:111
Vec2f mCenter
Definition: Svg.h:529
bool specifiesTransform() const
Definition: Svg.h:169
Definition: Svg.h:47
float getRadiusY() const
Definition: Svg.h:519
float getDpi() const
Returns the document's dots-per-inch. Currently hardcoded to 72.
Definition: Svg.h:803
GLuint GLenum GLenum transform
Definition: GLee.h:10032
size_t getNumColors() const
Definition: Svg.h:162
static float getOpacityDefault()
Definition: Svg.h:209
void unspecifyLineJoin()
Definition: Svg.h:242
Vec2i getSize() const
Returns the size of the document in pixels.
Definition: Svg.h:796
bool contains(const Vec2f &pt) const
Returns whether the point pt is contained within the boundaries of the shape.
Definition: Shape2d.cpp:135
static MatrixAffine2f parseTransform(const std::string &value)
Definition: Svg.cpp:788
const std::shared_ptr< Font > getFont() const
Definition: Svg.cpp:2092
const Paint & getStroke() const
Returns node's stroke, or the first among its ancestors when it has none.
Definition: Svg.cpp:645
Shape2d getShapeAbsolute() const
Returns a Shape2d representing the node in absolute coordinates. Not supported for Text...
Definition: Svg.h:367
Definition: Svg.h:436
virtual void pushStyle(const svg::Style &style)
Definition: Svg.h:88
static DocRef createFromSvgz(DataSourceRef dataSource, const fs::path &filePath=fs::path())
Definition: Svg.cpp:2179
virtual void pushLineCap(LineCap lineCap)
Definition: Svg.h:102
virtual const Node * findInAncestors(const std::string &elementId) const
Finds the node with ID elementId amongst this Node's ancestors. Returns NULL on failure.
Definition: Svg.cpp:948
void render(Renderer &renderer) const
Renders the node and its descendants.
Definition: Svg.cpp:916
float getFillOpacity() const
Returns node's fill opacity, or the first among its ancestors when it has none.
Definition: Svg.cpp:666
Definition: Svg.h:47
bool mVisible
Definition: Svg.h:306
float getRadiusX() const
Definition: Svg.h:518
const ColorA8u & getColor(size_t idx=0) const
Definition: Svg.h:160
class Doc * getDoc() const
Returns the svg::Doc this Node is an element of.
Definition: Svg.cpp:614
Definition: Svg.h:830
bool specifiesFill() const
Definition: Svg.h:193
const PolyLine2f & getPolyLine() const
Definition: Svg.h:596
MatrixAffine2f mTransform
Definition: Svg.h:178
Paint asPaint() const
Definition: Svg.cpp:1061
SVG Use Element, which instantiates a different element: http://www.w3.org/TR/SVG/struct.html#UseElement.
Definition: Svg.h:631
virtual void pushStroke(const class Paint &paint)
Definition: Svg.h:92
bool mSpecifiesOpacity
Definition: Svg.h:443
void setLineCap(LineCap lineCap)
Definition: Svg.h:238
virtual void pushFillRule(FillRule rule)
Definition: Svg.h:100
std::vector< std::string > mFontFamilies
Definition: Svg.h:301
Attributes()
Definition: Svg.h:676
Definition: Svg.h:128
std::shared_ptr< std::vector< std::pair< uint16_t, Vec2f > > > mGlyphMeasures
Definition: Svg.h:706
FillRule getFillRule() const
Returns node's fill rule, or the first among its ancestors when it has none.
Definition: Svg.cpp:680
Definition: Svg.h:47
Base class for SVG Gradients. See SVG Gradients: http://www.w3.org/TR/SVG/pservers.html#Gradients.
Definition: Svg.h:432
bool useObjectBoundingBox() const
Definition: Svg.h:168
Rectf getBoundingBoxAbsolute() const
Returns the absolute bounding box of the Node. Calculated and cached the first time it is requested...
Definition: Svg.h:362
virtual Rectf calcBoundingBox() const
Definition: Svg.h:548
const std::string & getString() const
Definition: Svg.h:692
Style mStyle
Definition: Svg.h:418
bool useObjectBoundingBox() const
Definition: Svg.h:446
bool contains(const Vec2f &pt) const
Returns whether the point pt is contained within the boundaries of the PolyLine.
Definition: PolyLine.cpp:92
const Shape2d & getShape2d() const
Definition: Svg.h:539
Value mFontSize
Definition: Svg.h:302
const Rectf & getRect() const
Definition: Svg.h:577
void setFontSize(const Value &fontSize)
Definition: Svg.h:259
LineJoin getLineJoin() const
Definition: Svg.h:243
float mOpacity
Definition: Svg.h:284
Path(const Node *parent)
Definition: Svg.h:536
void setTransform(const MatrixAffine2f &transform)
Sets the local transformation of this node.
Definition: Svg.h:349
Vec2f mCenter
Definition: Svg.h:507
std::shared_ptr< std::function< bool(const Node &, svg::Style *)> > mVisitor
Definition: Svg.h:120
virtual void pushFill(const class Paint &paint)
Definition: Svg.h:90
virtual bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.h:499
TextSpan(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1993
std::string mString
Definition: Svg.h:704
virtual bool isDrawable() const
Definition: Svg.h:635
Vec2f mCoords0
Definition: Svg.h:175
Definition: Svg.h:47
Base class for an element of an SVG Document.
Definition: Svg.h:313
bool mSpecifiesFill
Definition: Svg.h:288
bool specifiesVisible() const
Definition: Svg.h:268
virtual void popStyle(const svg::Style &style)
Definition: Svg.h:89
virtual void drawImage(const svg::Image &image)
Definition: Svg.h:83
const Vec2f & getPoint1() const
Definition: Svg.h:559
void setVisible(bool visible)
Definition: Svg.h:270
virtual bool containsPoint(const Vec2f &pt) const
Returns whether the point pt is inside of the Node's shape.
Definition: Svg.h:599
MatrixAffine2f getTransformInverse() const
Returns the inverse of the local transformation of this node. Returns identity if the Node's transfor...
Definition: Svg.h:353
Definition: Svg.h:46
void setLineJoin(LineJoin lineJoin)
Definition: Svg.h:244
void unspecifyFontSize()
Definition: Svg.h:257
bool mSpecifiesColor
Definition: Svg.h:443
Definition: Svg.h:44
void fill(float value, float *array, size_t length)
fills array with value value
Definition: Dsp.cpp:169
TextSpan::Attributes mAttributes
Definition: Svg.h:725
virtual bool isDrawable() const
Definition: Svg.h:771
SVG Polygon Element: http://www.w3.org/TR/SVG/shapes.html#PolygonElement.
Definition: Svg.h:591
Rectf mRect
Definition: Svg.h:664
boost::geometry::model::polygon< boost::geometry::model::d2::point_xy< double > > polygon
Definition: ConvexHull.cpp:32
Definition: Svg.h:45
bool specifiesFontWeight() const
Definition: Svg.h:262
T y
Definition: Vector.h:71
void parse(const XmlTree &xml)
Definition: Svg.cpp:1088
Node * nodeUnderPoint(const Vec2f &absolutePoint, const MatrixAffine2f &parentInverseMatrix) const
Definition: Svg.cpp:1748
GLsizei const GLfloat * value
Definition: GLee.h:2487
SVG Image Element. Represents an unpremultiplied bitmap. http://www.w3.org/TR/SVG/struct.html#ImageElement.
Definition: Svg.h:649
Vec2f getCenter() const
Definition: Svg.h:496
Definition: Svg.h:128
float mFillOpacity
Definition: Svg.h:286
SVG Exception base-class.
Definition: Svg.h:824
void startRender(Renderer &renderer) const
Definition: Svg.cpp:2135
static Paint parsePaint(const char *value, bool *specified, const Node *parentNode)
Definition: Svg.cpp:722
bool isVisible() const
Returns whether this Node is visible, or the first among its ancestors when unspecified.
Definition: Svg.cpp:715
Unit mUnit
Definition: Svg.h:142
virtual Rectf calcBoundingBox() const
Definition: Svg.h:527
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:963
bool specifiesStrokeOpacity() const
Definition: Svg.h:211
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1873
void unspecifyFillOpacity()
Definition: Svg.h:218
bool mSpecifiesFillRule
Definition: Svg.h:292
ColorA8u mColor
Definition: Svg.h:441
const GLubyte * c
Definition: GLee.h:8491
Rectf mBoundingBox
Definition: Svg.h:422
Renderer()
Definition: Svg.h:68
fs::path mFilePath
Definition: Svg.h:665
float getAspectRatio() const
Returns the aspect ratio of the Doc (width / height)
Definition: Svg.h:798
virtual Rectf calcBoundingBox() const
Definition: Svg.h:566
FillRule
Definition: Svg.h:44
void finishRender(Renderer &renderer, bool isNodeDrawable) const
Definition: Svg.cpp:502
float mDy
Definition: Svg.h:683
virtual void drawCircle(const svg::Circle &circle)
Definition: Svg.h:81
LineJoin mLineJoin
Definition: Svg.h:297
Value getFontSize() const
Definition: Svg.h:258
virtual void popTextRotation()
Definition: Svg.h:109
void finishRender(Renderer &renderer) const
Definition: Svg.cpp:2145
bool mSpecifiesFontFamilies
Definition: Svg.h:300
Definition: Svg.h:47
const std::vector< T > & getPoints() const
Definition: PolyLine.h:36
void setStroke(const Paint &stroke)
Definition: Svg.h:202
void unspecifyStroke()
Definition: Svg.h:200
bool isUser() const
Definition: Svg.h:135
virtual void drawPolygon(const svg::Polygon &polygon)
Definition: Svg.h:78
const std::shared_ptr< Surface8u > getSurface() const
Definition: Svg.h:654
bool specifiesStrokeWidth() const
Definition: Svg.h:223
bool isNone() const
Definition: Svg.h:157
Definition: Svg.h:45
int32_t getWidth() const
Returns the width of the document in pixels.
Definition: Svg.h:792
uint8_t mType
Definition: Svg.h:172
void unspecifyFillRule()
Definition: Svg.h:230
RectT< float > Rectf
Definition: Rect.h:139
std::shared_ptr< Shape2d > mShape
Definition: Svg.h:707
float mOffset
Definition: Svg.h:440
virtual Rectf calcBoundingBox() const
Definition: Svg.h:625
float mRadiusX
Definition: Svg.h:530
const PolyLine2f & getPolyLine() const
Definition: Svg.h:616
static const std::vector< std::string > & getFontFamiliesDefault()
Definition: Svg.cpp:326
const Paint & getFill() const
Returns node's fill, or the first among its ancestors when it has none.
Definition: Svg.cpp:638
const std::string & getId() const
Returns the ID of this Node when present.
Definition: Svg.h:323
Vec2f mCoords0
Definition: Svg.h:457
Definition: Svg.h:44
void setOpacity(float opacity)
Definition: Svg.h:208
virtual void popLineCap()
Definition: Svg.h:103
Value()
Definition: Svg.h:130
const std::list< Node * > & getChildren() const
Returns a reference to the list of the Group's children.
Definition: Svg.h:760
Definition: Svg.h:47
bool mSpecifiesLineJoin
Definition: Svg.h:296
static float getStrokeOpacityDefault()
Definition: Svg.h:215
Definition: Svg.h:836
float mTextLength
Definition: Svg.h:685
virtual void popTextPen()
Definition: Svg.h:107
bool specifiesLineJoin() const
Definition: Svg.h:241
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.cpp:1551
static const Paint & getFillDefault()
Definition: Svg.h:197
bool isRadialGradient() const
Definition: Svg.h:159
Vec2f mCoords1
Definition: Svg.h:457
void parseStyleAttribute(const std::string &stylePropertyString, const Node *parent)
Definition: Svg.cpp:337
virtual Rectf calcBoundingBox() const
Definition: Svg.h:585
SVG Path element: http://www.w3.org/TR/SVG/paths.html#PathElement.
Definition: Svg.h:534
Vec2f mCoords1
Definition: Svg.h:175
float getRadius() const
Definition: Svg.h:497
Definition: Svg.h:47
Represents an SVG Document. See SVG Document Structure http://www.w3.org/TR/SVG/struct.html.
Definition: Svg.h:781
const Node * mReferenced
Definition: Svg.h:645
void parse(const XmlTree &xml)
Definition: Svg.cpp:1860
bool specifiesFontSize() const
Definition: Svg.h:256
Definition: Exception.h:32
Stop(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1039
std::list< Node * > & getChildren()
Returns a reference to the list of the Group's children.
Definition: Svg.h:762
Paint()
Definition: Svg.cpp:184
static MatrixAffine2< float > identity()
Definition: MatrixAffine2.h:182
static Value parse(const char **sInOut)
Definition: Svg.cpp:550
virtual void popFillRule()
Definition: Svg.h:101
virtual Rectf calcBoundingBox() const
Definition: Svg.h:406
std::string getDomPath() const
Returns a DOM-style path to this node.
Definition: Svg.cpp:626
void parseStyle(const std::string &value)
Base class from which Renderers are derived.
Definition: Svg.h:66
virtual bool isDrawable() const
Definition: Svg.h:400
bool specifiesTransform() const
Definition: Svg.h:447
virtual void drawTextSpan(const svg::TextSpan &span)
Definition: Svg.h:84
const std::vector< std::string > & getFontFamilies() const
Definition: Svg.h:250
GLenum GLenum GLvoid GLvoid GLvoid * span
Definition: GLee.h:1089
Attributes mAttributes
Definition: Svg.h:703
float mLengthAdjust
Definition: Svg.h:686
LineCap mLineCap
Definition: Svg.h:295
Definition: Svg.h:128
const GLfloat * m
Definition: GLee.h:13493
void copyAttributesFrom(const Gradient &rhs)
Definition: Svg.cpp:1027
std::function< bool(const Node &, svg::Style *)> RenderVisitor
Definition: Svg.h:61
bool mSpecifiesFontSize
Definition: Svg.h:300
void unspecifyLineCap()
Definition: Svg.h:236
void unspecifyOpacity()
Definition: Svg.h:206
void finishRender(Renderer &renderer, const Style &style) const
Definition: Svg.cpp:940
static std::shared_ptr< Surface8u > parseDataImage(const std::string &data)
Definition: Svg.cpp:1909
MatrixAffine2f getTransformAbsoluteInverse() const
Returns the inverse of the absolute transformation of this node, which includes inherited transformat...
Definition: Svg.h:357
static std::string findStyleValue(const std::string &styleString, const std::string &key)
Definition: Svg.cpp:886
Polygon(const Node *parent)
Definition: Svg.h:593
virtual void pushStrokeWidth(float width)
Definition: Svg.h:98
static LineCap getLineCapDefault()
Definition: Svg.h:239
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1593
std::shared_ptr< class DataSource > DataSourceRef
Definition: DataSource.h:35
const Node * getParent() const
Returns the immediate parent of this node.
Definition: Svg.h:321
GLdouble s
Definition: GLee.h:1378
bool specifiesFillRule() const
Definition: Svg.h:229
const Style & getStyle() const
Returns the style elements defined on this Node but not inherited from ancestors. ...
Definition: Svg.h:327
Paint asPaint() const
Definition: Svg.cpp:1096
bool mSpecifiesStroke
Definition: Svg.h:288
LineCap getLineCap() const
Definition: Svg.h:237
Text(const Node *parent, const XmlTree &xml)
Definition: Svg.cpp:1937
std::list< Node * > mChildren
Definition: Svg.h:774
SVG Linear gradient.
Definition: Svg.h:464
virtual const char * what() const
Definition: Svg.h:843
Definition: Shape2d.h:34
const Vec2f & getPoint2() const
Definition: Svg.h:560
void unspecifyFontFamilies()
Definition: Svg.h:249
float getOpacity() const
Returns node's opacity, or the first among its ancestors when it has none.
Definition: Svg.cpp:659
bool isPercent() const
Definition: Svg.h:136
MatrixAffine2f getTransform() const
Returns the local transformation of this node. Returns identity if the Node's transform isn't specifi...
Definition: Svg.h:347
float mRadiusY
Definition: Svg.h:530
Rectf getBoundingBox() const
Returns the local bounding box of the Node. Calculated and cached the first time it is requested...
Definition: Svg.h:360
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1138
std::string mId
Definition: Svg.h:417
virtual void popStrokeWidth()
Definition: Svg.h:99
const std::vector< std::string > & getFontFamilies() const
Returns node's font families, or the first among its ancestors when it has none.
Definition: Svg.cpp:701
virtual Rectf calcBoundingBox() const
Definition: Svg.cpp:1832
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.cpp:1598
void setFill(const Paint &fill)
Definition: Svg.h:196
T distanceSquared(const Vec2< T > &rhs) const
Definition: Vector.h:170
Definition: Svg.h:128
Value(float value, Unit unit=USER)
Definition: Svg.h:131
bool parseProperty(const std::string &key, const std::string &value, const Node *parent)
Definition: Svg.cpp:349
bool isPixels() const
Definition: Svg.h:137
float getRadius() const
Definition: Svg.h:167
const T * findByIdContains(const std::string &idPartial)
Recursively searches for a child element of type svg::T whose name contains idPartial. Returns NULL on failure to find the object or if it is not of type T.
Definition: Svg.h:744
int32_t getHeight() const
Returns the height of the document in pixels.
Definition: Svg.h:794
PolyLine2f mPolyLine
Definition: Svg.h:607
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:2018
LineCap
Definition: Svg.h:45
Definition: Svg.h:827
virtual void drawRect(const svg::Rect &rect)
Definition: Svg.h:80
virtual void popMatrix()
Definition: Svg.h:87
Vec2< int > Vec2i
Definition: Vector.h:1313
Rectf mRect
Definition: Svg.h:587
virtual void renderSelf(Renderer &renderer) const
Definition: Svg.cpp:1509
float getStrokeOpacity() const
Definition: Svg.h:213
Definition: Svg.h:128
std::shared_ptr< Surface8u > mImage
Definition: Svg.h:666
ExcChildNotFound(const std::string &child)
Definition: Svg.cpp:2277
virtual Shape2d getShape() const
Returns a Shape2d representing the node in local coordinates. Not supported for Text.
Definition: Svg.cpp:1628
Area getBounds() const
Returns the bounds of the Doc (0,0,width,height)
Definition: Svg.h:800
const Paint & getStroke() const
Definition: Svg.h:201
Definition: Svg.h:46
GLuint color
Definition: GLee.h:3198