KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
kjb::qd::SvgWrap Class Reference

class used to render a PixPath as an SVG polygonal path picture More...

#include <svgwrap.h>

Public Member Functions

 SvgWrap (const PixPath &pp=PixPath::reserve())
 ctor take a path and sets fields to sensible default values More...
 
SvgWrapset_segs (bool seg=true)
 can opt in/out of showing line segments between points of path More...
 
SvgWrapset_xml (bool xml=true)
 can opt in/out of emitting XML tag at start of output More...
 
SvgWrapset_svg (bool svg=true)
 can opt in/out of emitting opening SVG tag at start of output More...
 
SvgWrapset_svg (bool svg_open, bool svg_close)
 can opt in/out of emitting SVG open, close tags (you pick which) More...
 
SvgWrapset_text (bool txt=true)
 can opt in/out of showing point sequence index More...
 
SvgWrapset_color (const std::string &color)
 set the color of the path and text More...
 
SvgWrapset_color (const kjb_c::Pixel &color)
 see overload of same name, but this takes a struct kjb_c::Pixel. More...
 
SvgWrapset_fill (bool fill=false)
 can opt in/out of making this a filled polygon More...
 
SvgWrapset_fill_color (const std::string &color)
 set the color used for filling the polygon interior (if any). More...
 
SvgWrapset_fill_color (const kjb_c::Pixel &color)
 see overload of same name, but this takes a struct kjb_c::Pixel. More...
 
SvgWrapset_id (const std::string &)
 try to set the id string for the path More...
 
const std::string & get_id () const
 retrieve the identifier for this rendering More...
 
SvgWrapset_path_extra (const std::string &)
 set an extra attribute to add to each path node in SVG More...
 
const std::string & get_path_extra () const
 retrieve the optional extra-path-attribute string. More...
 
std::string operator() () const
 render the path in a rectangular box using SVG 1.1 More...
 

Static Public Member Functions

static std::string xml_header ()
 string for top of a standalone XML file More...
 

Public Attributes

bool m_show_segments
 show line segments between points? More...
 
bool m_show_text
 show numbered sequence of points? More...
 
bool m_gen_xml_header
 print the special XML header tag? More...
 
bool m_open_svg
 print an opening SVG tag? More...
 
bool m_close_svg
 print the close tag of the SVG node? More...
 
bool m_fill_path
 should the path be filled? More...
 
unsigned m_width
 width in world units of the SVG image More...
 
unsigned m_height
 height in world units of SVG image More...
 
unsigned m_magnify
 magnification from world to image More...
 
std::string m_color
 color, as text string, of objects More...
 
std::string m_fill_color
 color of fill, can override default More...
 
bool m_totally_omit_stroke_attribute
 no mention of stroke at all More...
 
bool m_totally_omit_fill_attribute
 no mention of fill at all More...
 

Detailed Description

class used to render a PixPath as an SVG polygonal path picture

The many "set_xxx" functions all return a reference to *this, so that they can be chained.

Expert users might want to avoid the automated logic that controls how the stroke and fill attributes are computed, perhaps because the path will be placed within a group tag. The "m_totally_omit_*" booleans will turn off those attributes, irrespective of any other flags. Under some circumstances that is the only way to get the desired output; however, because they are specialty settings and they trump other state settings, we don't provide set functions for them and the user has to write out their deliberately long and clumsy names, to make clear that they are for experts only.

Constructor & Destructor Documentation

kjb::qd::SvgWrap::SvgWrap ( const PixPath pp = PixPath::reserve())
inline

ctor take a path and sets fields to sensible default values

Member Function Documentation

const std::string& kjb::qd::SvgWrap::get_id ( ) const
inline

retrieve the identifier for this rendering

See Also
set_id
const std::string& kjb::qd::SvgWrap::get_path_extra ( ) const
inline

retrieve the optional extra-path-attribute string.

See Also
set_path_extra
std::string kjb::qd::SvgWrap::operator() ( ) const

render the path in a rectangular box using SVG 1.1

SvgWrap& kjb::qd::SvgWrap::set_color ( const std::string &  color)
inline

set the color of the path and text

Parameters
coloris a string specifying output color. See http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#colors for a presentation of valid color. In brief, you can use standard named colors like "red," hex values like "#cbacca," or other things.
Returns
reference to self for easy chaining of setters.

We call this the "default color" because it controls the color of lines, text, and polygon fill unless the user provides an overriding value for polygon fill color.

SvgWrap& kjb::qd::SvgWrap::set_color ( const kjb_c::Pixel &  color)
inline

see overload of same name, but this takes a struct kjb_c::Pixel.

SvgWrap& kjb::qd::SvgWrap::set_fill ( bool  fill = false)
inline

can opt in/out of making this a filled polygon

SvgWrap& kjb::qd::SvgWrap::set_fill_color ( const std::string &  color)
inline

set the color used for filling the polygon interior (if any).

See Also
set_color() for string format; also "" and "none" are valid.

The ctor-time default value is the empty string, which has the semantics of "use the default color."

The value here controls the color used to fill the interior points of the polygon defined by the path vertices. It does not affect stroke color or text color, both of which are set by the default color. If you want the polygons filled, you must turn on the fill flag; if you also want the interior color different from the outline, you must also set the fill color to the name/description of your desired color.

Technical points:

  • If the segments flag or fill flag is off, the fill color is ignored.
  • Otherwise, if this string is set to the empty string, then the polygon will be filled with the default color.
  • If the fill and segments flags are on yet the fill color is "none" then the polygon will not be filled, i.e., "filled with nothing."
  • This color is not used for text fill, just polygon fill.
SvgWrap& kjb::qd::SvgWrap::set_fill_color ( const kjb_c::Pixel &  color)
inline

see overload of same name, but this takes a struct kjb_c::Pixel.

SvgWrap & kjb::qd::SvgWrap::set_id ( const std::string &  id)

try to set the id string for the path

Exceptions
kjb::Illegal_argumentif the ID string contains a bad character.
Returns
reference to self (for easy chaining of these setters).

Disallowed characters include nonprintable characters and the characters in the string "<&>" – no support (yet) for escape sequences like "&amp;" Also the double-quote character and backslash are disallowed.

SvgWrap & kjb::qd::SvgWrap::set_path_extra ( const std::string &  e)

set an extra attribute to add to each path node in SVG

Exceptions
kjb::Illegal_argumentif the string contains a bad character.

The purpose is to set one or more attributes to be applied to each path node to support the many SVG features that we don't want to explicitly add to the API. Use as many attributes as you like, just obey XML syntax. Some sample attributes that you might want to use are below.

  • stroke-width="17"
  • stroke-linecap="round" (also try "square" or "butt")
  • stroke-linejoin="round" (also try "miter" or "bevel")
  • fill-rule="evenodd"
  • opacity="0.5"

The attribute must not, accidentally or on purpose, close a tag or break XML syntax, so we do not allow the characters '<' '>' '\' or '&' which all require special treatment. The above restriction is neither totally necessary nor sufficient to preserve the XML rules, so, apologies for the crudeness but be careful anyway. You can mess up your XML easily with this method!

SvgWrap& kjb::qd::SvgWrap::set_segs ( bool  seg = true)
inline

can opt in/out of showing line segments between points of path

SvgWrap& kjb::qd::SvgWrap::set_svg ( bool  svg = true)
inline

can opt in/out of emitting opening SVG tag at start of output

SvgWrap& kjb::qd::SvgWrap::set_svg ( bool  svg_open,
bool  svg_close 
)
inline

can opt in/out of emitting SVG open, close tags (you pick which)

SvgWrap& kjb::qd::SvgWrap::set_text ( bool  txt = true)
inline

can opt in/out of showing point sequence index

SvgWrap& kjb::qd::SvgWrap::set_xml ( bool  xml = true)
inline

can opt in/out of emitting XML tag at start of output

static std::string kjb::qd::SvgWrap::xml_header ( )
inlinestatic

string for top of a standalone XML file

Member Data Documentation

bool kjb::qd::SvgWrap::m_close_svg

print the close tag of the SVG node?

std::string kjb::qd::SvgWrap::m_color

color, as text string, of objects

std::string kjb::qd::SvgWrap::m_fill_color

color of fill, can override default

bool kjb::qd::SvgWrap::m_fill_path

should the path be filled?

bool kjb::qd::SvgWrap::m_gen_xml_header

print the special XML header tag?

unsigned kjb::qd::SvgWrap::m_height

height in world units of SVG image

unsigned kjb::qd::SvgWrap::m_magnify

magnification from world to image

bool kjb::qd::SvgWrap::m_open_svg

print an opening SVG tag?

bool kjb::qd::SvgWrap::m_show_segments

show line segments between points?

bool kjb::qd::SvgWrap::m_show_text

show numbered sequence of points?

bool kjb::qd::SvgWrap::m_totally_omit_fill_attribute

no mention of fill at all

bool kjb::qd::SvgWrap::m_totally_omit_stroke_attribute

no mention of stroke at all

unsigned kjb::qd::SvgWrap::m_width

width in world units of the SVG image


The documentation for this class was generated from the following files: