1
/************************************************************************
2
************************************************************************
4
Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5
---------------------------------------------------------------------
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
************************************************************************
20
************************************************************************/
31
SVGDev::SVGDev(const char* ficName,float largeur, float hauteur)
33
if((fic_repr = fopen(ficName,"w+")) == NULL) { cout<<"Impossible de creer ou d'ouvrir "<<ficName<<endl; }
35
// representation file:
36
fprintf(fic_repr,"<?xml version=\"1.0\"?>\n");
39
fprintf(fic_repr,"<svg preserveAspectRatio=\"xMidYMid meet\" viewBox=\"0 0 %f %f\" width=\"200mm\" height=\"150mm\" >\n",largeur,hauteur);
44
fprintf(fic_repr,"</svg>\n");
50
void SVGDev::rect(float x,float y,float l,float h)
52
fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"2\" ry=\"2\" style=\"stroke: black;stroke-width:0.5;fill:none;\"/>\n",x,y,l,h);
55
void SVGDev::rond(float x,float y,float rayon)
57
fprintf(fic_repr,"<circle cx=\"%f\" cy=\"%f\" r=\"%f\"/>\n",x,y,rayon);
60
void SVGDev::fleche(float x,float y,float rotation,int sens)
64
fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.5;\"/>\n",x-4,y-2,x,y,rotation,x,y);
65
fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.5;\"/>\n",x-4,y+2,x,y,rotation,x,y);
69
fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.5;\"/>\n",x+4,y-2,x,y,rotation,x,y);
70
fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.5;\"/>\n",x+4,y+2,x,y,rotation,x,y);
74
void SVGDev::carre(float x,float y,float cote)
76
fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" style=\"stroke: black;stroke-width:0.5;fill:none;\"/>\n",x-0.5*cote,y-cote,cote,cote);
79
void SVGDev::trait(float x1,float y1,float x2,float y2)
81
fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: black; stroke-linecap:round; stroke-width:1;\"/>\n",x1,y1,x2,y2);
84
void SVGDev::dasharray(float x1,float y1,float x2,float y2)
86
fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: black; stroke-linecap:round; stroke-width:1; stroke-dasharray:3,3;\"/>\n",x1,y1,x2,y2);
89
void SVGDev::text(float x,float y,const char* name)
93
// SUBSTITUTION DES CARACTeRES INTERDITS EN XML
96
for (i=0, j=0; (name[i] != 0) && (j < 250); i++) {
98
case '<' : name2[j++] = '&'; name2[j++] = 'l'; name2[j++] = 't'; name2[j++] = ';'; break;
99
case '>' : name2[j++] = '&'; name2[j++] = 'g'; name2[j++] = 't'; name2[j++] = ';'; break;
100
case '\'' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'p'; name2[j++] = 'o'; name2[j++] = 's'; name2[j++] = ';'; break;
101
case '"' : name2[j++] = '&'; name2[j++] = 'q'; name2[j++] = 'u'; name2[j++] = 'o'; name2[j++] = 't'; name2[j++] = ';'; break;
102
case '&' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'm'; name2[j++] = 'p'; name2[j++] = ';'; break;
103
default : name2[j++] = name[i];
108
cout << "text : " << name << " -> " << name2 << endl;;
110
fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" style=\"text-anchor:middle\">%s</text>\n",x,y+5,name2);
113
void SVGDev::label(float x,float y,const char* name)
117
// SUBSTITUTION DES CARACTeRES INTERDITS EN XML
120
for (i=0, j=0; (name[i] != 0) && (j < 250); i++) {
122
case '<' : name2[j++] = '&'; name2[j++] = 'l'; name2[j++] = 't'; name2[j++] = ';'; break;
123
case '>' : name2[j++] = '&'; name2[j++] = 'g'; name2[j++] = 't'; name2[j++] = ';'; break;
124
case '\'' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'p'; name2[j++] = 'o'; name2[j++] = 's'; name2[j++] = ';'; break;
125
case '"' : name2[j++] = '&'; name2[j++] = 'q'; name2[j++] = 'u'; name2[j++] = 'o'; name2[j++] = 't'; name2[j++] = ';'; break;
126
case '&' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'm'; name2[j++] = 'p'; name2[j++] = ';'; break;
127
default : name2[j++] = name[i];
132
cout << "label : " << name << " -> " << name2 << endl;
134
fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" style=\"font-size:7\">%s</text>\n",x,y+2,name2);
137
void SVGDev::markSens(float x,float y,int sens)
140
fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"4\" height=\"4\" rx=\"2\" ry=\"1\" style=\"stroke: black;stroke-width:0.5;fill:none;\"/>\n",x,y);
142
fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"4\" height=\"4\" rx=\"2\" ry=\"1\" style=\"stroke: black;stroke-width:0.5;fill:none;\"/>\n",x-4,y-4);
146
void SVGDev::Error(const char* message, const char* reason,int nb_error,float x,float y,float largeur)
148
fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" textLength=\"%f\" lengthAdjust=\"spacingAndGlyphs\" style=\"stroke: red; stroke-width:0.3; fill:red; text-anchor:middle;\">%d : %s</text>\n",x,y-7,largeur,nb_error,message);
149
fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" textLength=\"%f\" lengthAdjust=\"spacingAndGlyphs\" style=\"stroke: red; stroke-width:0.3; fill:none; text-anchor:middle;\">%s</text>\n",x,y+7,largeur,reason);