Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 498a277c authored by Pascal Noisette's avatar Pascal Noisette
Browse files

a voir avec firefox...

parent 2d1320b5
No related branches found
No related tags found
No related merge requests found
...@@ -4,42 +4,60 @@ ...@@ -4,42 +4,60 @@
void Svg::rectangle() 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); _buffer << "<rect title='container' width='" << _w
afficher(_conteneur); <<"' 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() void Svg::end()
{ {
char* end_of_document = "</svg>"; _buffer << "</svg>";
afficher(end_of_document); 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) 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; _w=(unsigned long)w;
_h=(unsigned long)h; _h=(unsigned long)h;
_x=(unsigned long)x; _x=(unsigned long)x;
_y=(unsigned long)y; _y=(unsigned long)y;
rectangle(); 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) 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 @@ ...@@ -48,10 +66,11 @@
_g=(unsigned char)g; _g=(unsigned char)g;
_b=(unsigned char)b; _b=(unsigned char)b;
_w=(unsigned long)(end-start); _w=(unsigned long)(end-start);
_h=(unsigned long)100; _h=(unsigned long)LEVEL - 10;
_x=(unsigned long)start; _x=(unsigned long)start;
_y=(unsigned long)50; _y=(unsigned long)level*LEVEL;
rectangle(); rectangle();
} }
#ifndef RENDER_SGV #ifndef RENDER_SGV
#define RENDER_SVG #define RENDER_SVG
#include <stdio.h> #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_pos;
typedef double Element_col; typedef unsigned int Element_col;
class Svg{ class Svg{
private: private:
ostringstream _buffer;
char _conteneur[2048]; ofstream svg_file;
unsigned char _r,_g,_b; unsigned int _r,_g,_b;
unsigned long _x,_y,_w,_h; unsigned long _x,_y,_w,_h;
void afficher();
void afficher(char*s);
void rectangle(); void rectangle();
public: public:
/*! /*!
* \brief SVG header buiding * \brief SVG header buiding
*/ */
void init(); void init(char *path);
/*! /*!
* \brief SVG bottom file buiding * \brief SVG bottom file buiding
......
#include <iostream>
#include "../src/render_svg.hpp" #include "../src/render_svg.hpp"
using namespace std; using namespace std;
...@@ -7,10 +7,16 @@ int main() ...@@ -7,10 +7,16 @@ int main()
Svg s; Svg s;
s.init(); s.init("./out.svg");
s.draw_container(0,100,100,100);
s.draw_state(0 , 150, 0, 50,50,50); s.draw_container(0,LEVEL*1,50,100);
s.draw_state(400, 750, 0, 0xff,0xcc,33); 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(); s.end();
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment