KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
svgwrap.h
Go to the documentation of this file.
1 
6 /*
7  * $Id: svgwrap.h 17555 2014-09-18 07:36:52Z predoehl $
8  */
9 
10 #ifndef SVGWRAP_H_UOFARIZONAVISION
11 #define SVGWRAP_H_UOFARIZONAVISION 1
12 
13 #include <i_cpp/i_pixel.h>
14 #include <qd_cpp/pixpath.h>
15 
16 #include <string>
17 #include <sstream>
18 
19 
20 namespace kjb
21 {
22 namespace qd
23 {
24 
25 
41 class SvgWrap
42 {
43  PixPath m_pixpath;
44  std::string m_id;
45  std::string m_extra;
46 
47 public:
48 
49  // public attributes the user may twiddle at will
51  m_show_text,
53  m_open_svg,
54  m_close_svg,
55  m_fill_path;
56  unsigned m_width,
57  m_height,
58  m_magnify;
59  std::string m_color,
60  m_fill_color;
61 
62  // "experts-only" booleans -- usually not indicated
65 
67  SvgWrap( const PixPath& pp = PixPath::reserve() )
68  : m_pixpath( pp ),
69  m_show_segments( true ),
70  m_show_text( true ),
71  m_gen_xml_header( true ),
72  m_open_svg( true ),
73  m_close_svg( true ),
74  m_fill_path( false ),
75  m_width( 2000 ),
76  m_height( 2000 ),
77  m_magnify( 1 ),
78  m_color( "black" ),
79  m_fill_color( "" ),
82  {}
83 
85  SvgWrap& set_segs( bool seg = true )
86  {
87  m_show_segments = seg;
88  return *this;
89  }
90 
92  SvgWrap& set_xml( bool xml = true )
93  {
94  m_gen_xml_header = xml;
95  return *this;
96  }
97 
99  SvgWrap& set_svg( bool svg = true )
100  {
101  m_open_svg = m_close_svg = svg;
102  return *this;
103  }
104 
106  SvgWrap& set_svg( bool svg_open, bool svg_close )
107  {
108  m_open_svg = svg_open;
109  m_close_svg = svg_close;
110  return *this;
111  }
112 
114  SvgWrap& set_text( bool txt = true )
115  {
116  m_show_text = txt;
117  return *this;
118  }
119 
132  SvgWrap& set_color( const std::string& color )
133  {
134  m_color = color;
135  return *this;
136  }
137 
139  SvgWrap& set_color( const kjb_c::Pixel& color )
140  {
141  return set_color( kjb::pixel_as_hex_triplet_string( color ) );
142  }
143 
145  SvgWrap& set_fill( bool fill = false )
146  {
147  m_fill_path = fill;
148  return *this;
149  }
150 
174  SvgWrap& set_fill_color( const std::string& color )
175  {
176  m_fill_color = color;
177  return *this;
178  }
179 
181  SvgWrap& set_fill_color( const kjb_c::Pixel& color )
182  {
184  }
185 
186  SvgWrap& set_id( const std::string& );
187 
190  const std::string& get_id() const
191  {
192  return m_id;
193  }
194 
195  SvgWrap& set_path_extra( const std::string& );
196 
199  const std::string& get_path_extra() const
200  {
201  return m_extra;
202  }
203 
205  static std::string xml_header()
206  {
207  return "<?xml version=\"1.0\" ?>\n"
208  "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"
209  "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
210  }
211 
212  std::string operator()() const;
213 
214 private:
216  std::string svg_open_tag() const
217  {
218  std::ostringstream tag;
219  tag << "<svg xmlns=\"http://www.w3.org/2000/svg\" "
220  "xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
221  "width=\"" << m_width * m_magnify << "px\" "
222  "height=\"" << m_height * m_magnify << "px\" "
223  "viewBox=\"0 0 " << m_width << ' ' << m_height << "\">\n";
224  return tag.str();
225  }
226 
227  std::string generate_fill_attr() const;
228  std::string generate_stroke_attr() const;
229 };
230 
231 
232 
233 
234 }
235 }
236 
237 
238 #endif
SvgWrap & set_path_extra(const std::string &)
set an extra attribute to add to each path node in SVG
Definition: svgwrap.cpp:192
bool m_fill_path
should the path be filled?
Definition: svgwrap.h:50
bool m_gen_xml_header
print the special XML header tag?
Definition: svgwrap.h:50
const std::string & get_id() const
retrieve the identifier for this rendering
Definition: svgwrap.h:190
SvgWrap & set_fill(bool fill=false)
can opt in/out of making this a filled polygon
Definition: svgwrap.h:145
bool m_open_svg
print an opening SVG tag?
Definition: svgwrap.h:50
SvgWrap & set_id(const std::string &)
try to set the id string for the path
Definition: svgwrap.cpp:159
SvgWrap & set_text(bool txt=true)
can opt in/out of showing point sequence index
Definition: svgwrap.h:114
std::string m_color
color, as text string, of objects
Definition: svgwrap.h:59
bool m_show_segments
show line segments between points?
Definition: svgwrap.h:50
SvgWrap & set_xml(bool xml=true)
can opt in/out of emitting XML tag at start of output
Definition: svgwrap.h:92
bool m_totally_omit_fill_attribute
no mention of fill at all
Definition: svgwrap.h:63
unsigned m_height
height in world units of SVG image
Definition: svgwrap.h:56
static PixPath reserve(size_t potential_size=0)
named ctor creates an empty path but reserves some memory for it
Definition: pixpath.h:244
SvgWrap(const PixPath &pp=PixPath::reserve())
ctor take a path and sets fields to sensible default values
Definition: svgwrap.h:67
SvgWrap & set_svg(bool svg_open, bool svg_close)
can opt in/out of emitting SVG open, close tags (you pick which)
Definition: svgwrap.h:106
unsigned m_magnify
magnification from world to image
Definition: svgwrap.h:56
SvgWrap & set_color(const std::string &color)
set the color of the path and text
Definition: svgwrap.h:132
std::string operator()() const
render the path in a rectangular box using SVG 1.1
Definition: svgwrap.cpp:81
const std::string & get_path_extra() const
retrieve the optional extra-path-attribute string.
Definition: svgwrap.h:199
Representation of a sequence of pixel coordinates.
Definition: pixpath.h:117
bool m_totally_omit_stroke_attribute
no mention of stroke at all
Definition: svgwrap.h:63
SvgWrap & set_color(const kjb_c::Pixel &color)
see overload of same name, but this takes a struct kjb_c::Pixel.
Definition: svgwrap.h:139
Code for a wrapper class around the C struct Pixel.
SvgWrap & set_fill_color(const kjb_c::Pixel &color)
see overload of same name, but this takes a struct kjb_c::Pixel.
Definition: svgwrap.h:181
bool m_show_text
show numbered sequence of points?
Definition: svgwrap.h:50
bool m_close_svg
print the close tag of the SVG node?
Definition: svgwrap.h:50
std::string pixel_as_hex_triplet_string(const kjb_c::Pixel *)
express color as HTML-style hex triplet, e.g., "#FFCC00," of pointer
Definition: i_pixel.h:366
static std::string xml_header()
string for top of a standalone XML file
Definition: svgwrap.h:205
SvgWrap & set_fill_color(const std::string &color)
set the color used for filling the polygon interior (if any).
Definition: svgwrap.h:174
std::string m_fill_color
color of fill, can override default
Definition: svgwrap.h:59
class used to render a PixPath as an SVG polygonal path picture
Definition: svgwrap.h:41
SvgWrap & set_svg(bool svg=true)
can opt in/out of emitting opening SVG tag at start of output
Definition: svgwrap.h:99
Contains definition for class PixPath.
unsigned m_width
width in world units of the SVG image
Definition: svgwrap.h:56
SvgWrap & set_segs(bool seg=true)
can opt in/out of showing line segments between points of path
Definition: svgwrap.h:85