Example #1
0
string
Color::postscript() const
{
  char buffer[255];
  secured_sprintf( buffer, 255, "%.4f %.4f %.4f", _red/255.0, _green/255.0, _blue/255.0 );
  return buffer;
}
Example #2
0
string
Color::svgAlpha( const char * prefix ) const
{
  char buffer[255];
  if ( _alpha == 255 || *this == Color::Null ) return "";
  secured_sprintf( buffer, 255, " %s-opacity=\"%f\"", prefix, _alpha/255.0f );
  return buffer;
}
Example #3
0
string
Color::svg() const
{
  char buffer[255];
  if ( *this == Color::Null ) return "none";
  secured_sprintf( buffer, 255, "rgb(%d,%d,%d)", _red, _green, _blue );
  return buffer;
}
Example #4
0
string
Color::tikz() const
{
  // see tex/generic/pgf/utilities/pgfutil-plain.def for color definitions
  char buffer[255];
  if ( *this == Color::Null ) return "none";
  if ( *this == Color::Black ) return "black";
  if ( *this == Color::Gray ) return "gray";
  if ( *this == Color::White ) return "white";
  if ( *this == Color::Red ) return "red";
  if ( *this == Color::Green ) return "green!50!black";
  if ( *this == Color::Lime ) return "green";
  if ( *this == Color::Blue ) return "blue";
  if ( *this == Color::Silver ) return "white!75!black";
  if ( *this == Color::Purple ) return "{rgb,255:red,160;green,32;blue,240}";
  if ( *this == Color::Navy ) return "blue!50!black";
  secured_sprintf( buffer, 255, "{rgb,255:red,%d;green,%d;blue,%d}", _red, _green, _blue );
  return buffer;
}
Example #5
0
void
Board::saveFIG( const char * filename, double pageWidth, double pageHeight, double margin ) const
{
  std::ofstream file( filename );
  TransformFIG transform;
  Rect bbox = boundingBox();
  transform.setBoundingBox( bbox, pageWidth, pageHeight, margin  );
  transform.setDepthRange( *this );
  
  file << "#FIG 3.2  Produced by the Board library (Copyleft)2007 Sebastien Fourey\n";
  file << "Portrait\n";
  file << "Center\n";
  file << "Metric\n";
  file << "A4\n";
  file << "100.00\n";
  file << "Single\n";
  file << "-2\n";
  file << "1200 2\n";

  std::map<Color,int> colormap;
  int maxColor = 32;


  colormap[Color(0,0,0)] = 0; 
  colormap[Color(0,0,255)] = 1; 
  colormap[Color(0,255,0)] = 2; 
  colormap[Color(0,255,255)] = 0; 
  colormap[Color(255,0,0)] = 4; 
  colormap[Color(255,0,255)] = 0; 
  colormap[Color(255,255,0)] = 6; 
  colormap[Color(255,255,255)] = 7;


  std::vector< Shape* > shapes = _shapes;
  stable_sort( shapes.begin(), shapes.end(), shapeGreaterDepth );
  std::vector< Shape* >::const_iterator i = shapes.begin();
  std::vector< Shape* >::const_iterator end = shapes.end();
  while ( i != end ) { 
    if ( colormap.find( (*i)->penColor() ) == colormap.end() 
	 && (*i)->penColor().valid() )
      colormap[ (*i)->penColor() ] = maxColor++;
    if ( colormap.find( (*i)->fillColor() ) == colormap.end()
	 && (*i)->fillColor().valid() )
      colormap[ (*i)->fillColor() ] = maxColor++;
    ++i;
  }

  if ( colormap.find( _backgroundColor ) == colormap.end()
       && _backgroundColor.valid() )
    colormap[ _backgroundColor ] = maxColor++;
  
  // Write the colormap
  std::map<Color,int>::const_iterator iColormap = colormap.begin();
  std::map<Color,int>::const_iterator endColormap = colormap.end();
  char colorString[255];
  while ( iColormap != endColormap ) {
    secured_sprintf( colorString, 255,
		             "0 %d #%02x%02x%02x\n",
		             iColormap->second,
	                 iColormap->first.red(),
	                 iColormap->first.green(),
	                 iColormap->first.blue() );
    if ( iColormap->second >= 32 ) file << colorString;
    ++iColormap;
  }

  // Draw the background color if needed.
  if ( _backgroundColor != Color::None ) { 
    Rectangle r( bbox, Color::None, _backgroundColor, 0.0f );
    r.depth( std::numeric_limits<int>::max() );
    r.flushFIG( file, transform, colormap );
  }

  // Draw the shapes.
  i = shapes.begin();
  while ( i != end ) {
    // notice << (*i)->name() << " " << (*i)->depth() <<  '\n';
    (*i)->flushFIG( file, transform, colormap );
    ++i;
  }  
  file.close();
}