00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "SVGDev.h"
00027 #include "stdio.h"
00028 #include <iostream>
00029 using namespace std;
00030
00031 extern bool gShadowBlur;
00032
00033 static char* xmlcode(const char* name, char* name2)
00034 {
00035 int i,j;
00036
00037
00038
00039 for (i=0, j=0; (name[i] != 0) && (j < 250); i++) {
00040 switch (name[i]) {
00041 case '<' : name2[j++] = '&'; name2[j++] = 'l'; name2[j++] = 't'; name2[j++] = ';'; break;
00042 case '>' : name2[j++] = '&'; name2[j++] = 'g'; name2[j++] = 't'; name2[j++] = ';'; break;
00043 case '\'' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'p'; name2[j++] = 'o'; name2[j++] = 's'; name2[j++] = ';'; break;
00044 case '"' : name2[j++] = '&'; name2[j++] = 'q'; name2[j++] = 'u'; name2[j++] = 'o'; name2[j++] = 't'; name2[j++] = ';'; break;
00045 case '&' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'm'; name2[j++] = 'p'; name2[j++] = ';'; break;
00046 default : name2[j++] = name[i];
00047 }
00048 }
00049 name2[j] = 0;
00050
00051 return name2;
00052 }
00053
00054 SVGDev::SVGDev(const char* ficName,double largeur, double hauteur)
00055 {
00056 double gScale = 0.5;
00057
00058 if ((fic_repr = fopen(ficName,"w+")) == NULL) {
00059
00060 cout<<"Impossible de creer ou d'ouvrir "<<ficName<<endl;
00061 }
00062
00063
00064 fprintf(fic_repr,"<?xml version=\"1.0\"?>\n");
00065
00066
00067
00068 fprintf(fic_repr,"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 %f %f\" width=\"%fmm\" height=\"%fmm\" version=\"1.1\">\n", largeur, hauteur, largeur*gScale, hauteur*gScale);
00069
00070 if (gShadowBlur) {
00071 fprintf(fic_repr,
00072 "<defs>\n"
00073 " <filter id=\"filter\" filterRes=\"50\" x=\"0\" y=\"0\">\n"
00074 " <feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"1.5\"/>\n"
00075 " <feOffset dx=\"1\" dy=\"1\"/>\n"
00076 " </filter>\n"
00077 "</defs>\n"
00078 );
00079 }
00080
00081 }
00082
00083 SVGDev::~SVGDev()
00084 {
00085 fprintf(fic_repr,"</svg>\n");
00086 fclose(fic_repr);
00087 }
00088
00089 void SVGDev::rect(double x,double y,double l,double h, const char* color, const char* link)
00090 {
00091 char buf[512];
00092 if (link != 0 && link[0]!=0) {
00093
00094 fprintf(fic_repr,"<a xlink:href=\"%s\">\n", xmlcode(link, buf));
00095 }
00096
00097 if (gShadowBlur) {
00098 fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"0\" ry=\"0\" style=\"stroke:none;fill:#888888;;filter:url(#filter);\"/>\n",x+1,y+1,l,h);
00099 } else {
00100 fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"0\" ry=\"0\" style=\"stroke:none;fill:#cccccc;\"/>\n",x+1,y+1,l,h);
00101 }
00102
00103
00104
00105
00106 fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"0\" ry=\"0\" style=\"stroke:none;fill:%s;\"/>\n", x, y, l, h, color);
00107 if (link != 0 && link[0]!=0) {
00108
00109 fprintf(fic_repr,"</a>\n");
00110 }
00111
00112 }
00113
00114 void SVGDev::rond(double x,double y,double rayon)
00115 {
00116 fprintf(fic_repr,"<circle cx=\"%f\" cy=\"%f\" r=\"%f\"/>\n",x,y,rayon);
00117 }
00118
00119 void SVGDev::fleche(double x,double y,double rotation,int sens)
00120 {
00121 double dx = 3;
00122 double dy = 1;
00123
00124 if(sens == 1)
00125 {
00126 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x-dx,y-dy,x,y,rotation,x,y);
00127 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x-dx,y+dy,x,y,rotation,x,y);
00128 }
00129 else
00130 {
00131 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x+dx,y-dy,x,y,rotation,x,y);
00132 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x+dx,y+dy,x,y,rotation,x,y);
00133 }
00134 }
00135
00136 void SVGDev::carre(double x,double y,double cote)
00137 {
00138 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);
00139 }
00140
00141 void SVGDev::trait(double x1,double y1,double x2,double y2)
00142 {
00143
00144 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:black; stroke-linecap:round; stroke-width:0.25;\"/>\n",x1,y1,x2,y2);
00145 }
00146
00147 void SVGDev::dasharray(double x1,double y1,double x2,double y2)
00148 {
00149 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: black; stroke-linecap:round; stroke-width:0.25; stroke-dasharray:3,3;\"/>\n",x1,y1,x2,y2);
00150 }
00151
00152 void SVGDev::text(double x,double y,const char* name)
00153 {
00154 char name2[256];
00155
00156 fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" font-family=\"Arial\" font-size=\"7\" text-anchor=\"middle\" fill=\"#FFFFFF\">%s</text>\n",x,y+2,xmlcode(name,name2));
00157 }
00158
00159 void SVGDev::label(double x,double y,const char* name)
00160 {
00161 char name2[256];
00162
00163 fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" font-family=\"Arial\" font-size=\"7\">%s</text>\n",x,y+2,xmlcode(name,name2));
00164
00165 }
00166
00167 void SVGDev::markSens(double x,double y,int sens)
00168 {
00169 int offset = (sens == 1) ? 2 : -2;
00170 fprintf(fic_repr,"<circle cx=\"%f\" cy=\"%f\" r=\"1\"/>\n", x+offset, y+offset);
00171 }
00172
00173 void SVGDev::Error(const char* message, const char* reason,int nb_error,double x,double y,double largeur)
00174 {
00175 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);
00176 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);
00177 }
00178
00179
00180