Commit 498a277c authored by Pascal Noisette's avatar Pascal Noisette

a voir avec firefox...

parent 2d1320b5
......@@ -4,42 +4,60 @@
void Svg::rectangle()
{
sprintf(_conteneur,"<rect title='container' width='%ld' height='%ld' x='%ld' y='%ld' fill='rgb(%d,%d,%d)' />",_w, _h, _x,_y,_r,_g,_b);
afficher(_conteneur);
_buffer << "<rect title='container' width='" << _w
<<"' height='"<< _h
<<"' x='" << _x
<<"' y='" << _y
<<"' fill='rgb("<<_r<<","<<_g<<","<<_b
<<")'/>";
afficher();
}
void Svg::afficher(char* s)
void Svg::afficher()
{
printf(s);
if (_buffer.str().size()>BUFFER_SIZE){
svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
}
}
void Svg::init()
void Svg::init(char * path)
{
char * entete = "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>\n<svg xmlns='http://www.w3.org/2000/svg' x='0' y='0' width='1280' height='728' id='svg2'>\n\t<style type='text/css' id='stylecss' >\n\t\trect:hover\n\t\t\t{\n\t\t\t\tfill:#8fbbd0;\n\t\t\t}\n\t</style>\n\t<desc>Rectangles</desc>\n";
afficher(entete);
}
svg_file.open(path , ofstream::out | ofstream::trunc);
if (svg_file.is_open()==false){
std::cerr<<"unable to open file";
}
_buffer << "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>\n<svg xmlns='http://www.w3.org/2000/svg' x='0' y='0' width='1280' height='728' id='svg2'>\n\t<style type='text/css' id='stylecss' >\n\t\trect:hover\n\t\t\t{\n\t\t\t\tfill:#8fbbd0;\n\t\t\t}\n\t</style>\n\t<desc>Rectangles</desc>\n";
afficher();
}
void Svg::end()
{
char* end_of_document = "</svg>";
afficher(end_of_document);
_buffer << "</svg>";
svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
svg_file.close();
}
void Svg::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h)
{
_r=47;
_g=54;
_b=153;
_r=0xff;
_g=0x44;
_b=0xcc;
_w=(unsigned long)w;
_h=(unsigned long)h;
_x=(unsigned long)x;
_y=(unsigned long)y;
rectangle();
}
void Svg::draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b)
{
......@@ -48,10 +66,11 @@
_g=(unsigned char)g;
_b=(unsigned char)b;
_w=(unsigned long)(end-start);
_h=(unsigned long)100;
_h=(unsigned long)LEVEL - 10;
_x=(unsigned long)start;
_y=(unsigned long)50;
_y=(unsigned long)level*LEVEL;
rectangle();
}
#ifndef RENDER_SGV
#define RENDER_SVG
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream>
#define BUFFER_SIZE 2048
#define LEVEL 110
using namespace std;
typedef long Element_count ;
typedef unsigned long Element_count ;
typedef double Element_pos;
typedef double Element_col;
typedef unsigned int Element_col;
class Svg{
private:
char _conteneur[2048];
unsigned char _r,_g,_b;
ostringstream _buffer;
ofstream svg_file;
unsigned int _r,_g,_b;
unsigned long _x,_y,_w,_h;
void afficher(char*s);
void afficher();
void rectangle();
public:
/*!
* \brief SVG header buiding
*/
void init();
void init(char *path);
/*!
* \brief SVG bottom file buiding
......
#include <iostream>
#include "../src/render_svg.hpp"
using namespace std;
......@@ -7,10 +7,16 @@ int main()
Svg s;
s.init();
s.draw_container(0,100,100,100);
s.draw_state(0 , 150, 0, 50,50,50);
s.draw_state(400, 750, 0, 0xff,0xcc,33);
s.init("./out.svg");
s.draw_container(0,LEVEL*1,50,100);
s.draw_container(0,LEVEL*2,50,100);
s.draw_container(0,LEVEL*3,50,100);
s.draw_state(100, 750, 1, 0xff,0xcc,33);
s.draw_state(400, 750, 2, 0xff,0xcc,33);
s.draw_state(70, 300, 3, 0xff,0xcc,33);
s.end();
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment