hex::svg Namespace Reference


Detailed Description

Output hex:: objects as Scalable Vector Graphics (SVG) - which you can easily convert to PNG or JPG.


Classes

class  Identity
 Parent class for objects that can have an id, SVG style & SVG class name. More...
class  Document

Typedefs

typedef std::map< std::string,
std::string > 
Style

Functions

std::string style_str (const Style &st)
 Render a style dictionary to SVG.
Style style_dict (const std::string &s) throw (hex::invalid_argument)
 Construct a style dictionary from an SVG string.
std::ostream & operator<< (std::ostream &os, hex::Point p)
std::string strip (const std::string &s)
 Helper function - strip whitespace from the start & end of a string.
std::string path_append (char &cmd, Point &p, char cmd1, const Point &p1)
 Helper function - append a new relative point to a path.
template<class InputIterator>
std::ostream & output_path_data (const Document &doc, std::ostream &os, InputIterator first, InputIterator last)
 Helper function.


Typedef Documentation

typedef std::map<std::string,std::string> hex::svg::Style

Definition at line 39 of file hexsvg.h.


Function Documentation

std::ostream& hex::svg::operator<< ( std::ostream &  os,
hex::Point  p 
) [inline]

Definition at line 50 of file hexsvg.h.

References hex::Point::x, and hex::Point::y.

00051 {
00052   os<<p.x<<","<<p.y;
00053   return os;
00054 }

template<class InputIterator>
std::ostream& hex::svg::output_path_data ( const Document &  doc,
std::ostream &  os,
InputIterator  first,
InputIterator  last 
)

Helper function.

Definition at line 108 of file svg.cc.

References hex::svg::Document::T().

Referenced by hex::svg::Document::draw_complex_area().

00114 {
00115   assert(first!=last);
00116   --last;
00117   os<<"M "<<doc.T(*first)<<" L";
00118   for(InputIterator p =++first; p!=last; ++p)
00119       os<<" "<<doc.T(*p);
00120   os<<" Z";
00121   return os;
00122 }

std::string hex::svg::path_append ( char &  cmd,
Point &  p,
char  cmd1,
const Point &  p1 
)

Helper function - append a new relative point to a path.

Parameters:
cmd in/out current command letter
p in/out current path point
cmd1 desired command letter
p1 desired point

Definition at line 88 of file svg.cc.

References hex::Point::str().

Referenced by hex::svg::Document::draw_skeleton().

00089 {
00090   std::ostringstream ss;
00091   if(p != p1)
00092   {
00093     if(cmd != cmd1)
00094     {
00095       ss<<" "<<cmd1;
00096       cmd=cmd1;
00097     }
00098     ss<<" "<<(p1-p);
00099     p=p1;
00100   }
00101   return ss.str();
00102 }

std::string hex::svg::strip ( const std::string &  s  ) 

Helper function - strip whitespace from the start & end of a string.

Definition at line 37 of file svg.cc.

Referenced by style_dict().

00038 {
00039   std::string::size_type p0 =s.find_first_not_of(" \t\n");
00040   std::string::size_type p1 =s.find_last_of(" \t\n");
00041   return s.substr(p0,p1-p0);
00042 }

Style hex::svg::style_dict ( const std::string &  s  )  throw (hex::invalid_argument)

Construct a style dictionary from an SVG string.

Definition at line 60 of file svg.cc.

References strip().

00061 {
00062   Style result;
00063   std::string::size_type pos =0;
00064   while(true)
00065   {
00066     pos=s.find_first_not_of(";",pos);
00067     if(pos==std::string::npos)
00068         break;
00069     std::string::size_type semi =s.find(";",pos);
00070     std::string clause =s.substr(pos,semi-pos);
00071     std::string::size_type colon =clause.find(":");
00072     if(colon==std::string::npos || colon==0 || (colon+1)>=clause.size())
00073         throw hex::invalid_argument(s);
00074     result[ strip(s.substr(0,colon)) ] = strip(s.substr(colon+1));
00075     pos=semi;
00076   }
00077   return result;
00078 }

std::string hex::svg::style_str ( const Style &  st  ) 

Render a style dictionary to SVG.

Definition at line 46 of file svg.cc.

00047 {
00048   std::string result ="";
00049   for(Style::const_iterator it=st.begin(); it!=st.end(); ++it)
00050   {
00051     if(!result.empty())
00052         result += ';';
00053     result += it->first + ":" + it->second;
00054   }
00055   return result;
00056 }


Generated on Thu Feb 21 00:00:55 2008 for libhex by  doxygen 1.5.1