~ubuntu-branches/ubuntu/feisty/faust/feisty

« back to all changes in this revision

Viewing changes to compiler/draw/SVGDev.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mario Lang
  • Date: 2006-10-09 11:05:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 edgy)
  • Revision ID: james.westby@ubuntu.com-20061009110530-zvktdvpq5zewdxso
Tags: 0.9.8-1
* New upstream release.
* Upgrade Standards-Version to 3.7.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/************************************************************************
2
 
 ************************************************************************
3
 
    FAUST compiler
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.
10
 
 
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.
15
 
 
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
 
 ************************************************************************/
21
 
 
22
 
 
23
 
 
24
 
// SVGDev.cpp
25
 
 
26
 
#include "SVGDev.h"
27
 
#include "stdio.h"
28
 
#include <iostream>
29
 
using namespace std;
30
 
 
31
 
SVGDev::SVGDev(const char* ficName,float largeur, float hauteur)
32
 
{
33
 
        if((fic_repr = fopen(ficName,"w+")) == NULL) { cout<<"Impossible de creer ou d'ouvrir "<<ficName<<endl; }
34
 
 
35
 
        // representation file:
36
 
        fprintf(fic_repr,"<?xml version=\"1.0\"?>\n");
37
 
        // + DTD ...
38
 
        // viewBox:
39
 
        fprintf(fic_repr,"<svg preserveAspectRatio=\"xMidYMid meet\" viewBox=\"0 0 %f %f\" width=\"200mm\" height=\"150mm\" >\n",largeur,hauteur);
40
 
}
41
 
 
42
 
SVGDev::~SVGDev()
43
 
{
44
 
        fprintf(fic_repr,"</svg>\n");
45
 
        fclose(fic_repr);
46
 
}
47
 
 
48
 
 
49
 
 
50
 
void SVGDev::rect(float x,float y,float l,float h)
51
 
{
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);
53
 
}
54
 
 
55
 
void SVGDev::rond(float x,float y,float rayon)
56
 
{
57
 
        fprintf(fic_repr,"<circle cx=\"%f\" cy=\"%f\" r=\"%f\"/>\n",x,y,rayon);
58
 
}
59
 
 
60
 
void SVGDev::fleche(float x,float y,float rotation,int sens)
61
 
{
62
 
        if(sens == 1)
63
 
        {
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);
66
 
        }
67
 
        else //for recursion
68
 
        {
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);
71
 
        }
72
 
}
73
 
 
74
 
void SVGDev::carre(float x,float y,float cote)
75
 
{
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);
77
 
}
78
 
 
79
 
void SVGDev::trait(float x1,float y1,float x2,float y2)
80
 
{
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);
82
 
}
83
 
 
84
 
void SVGDev::dasharray(float x1,float y1,float x2,float y2)
85
 
{
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);
87
 
}
88
 
 
89
 
void SVGDev::text(float x,float y,const char* name)
90
 
{
91
 
        int     i,j;
92
 
 
93
 
        // SUBSTITUTION DES CARACTeRES INTERDITS EN XML
94
 
        char name2[256];
95
 
 
96
 
        for (i=0, j=0; (name[i] != 0) && (j < 250); i++) {
97
 
                switch (name[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]; 
104
 
                }
105
 
        }
106
 
        name2[j] = 0;
107
 
        
108
 
        cout << "text : " << name << " -> " << name2 << endl;;
109
 
        
110
 
        fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" style=\"text-anchor:middle\">%s</text>\n",x,y+5,name2);
111
 
}
112
 
 
113
 
void SVGDev::label(float x,float y,const char* name)
114
 
{
115
 
        int     i,j;
116
 
 
117
 
        // SUBSTITUTION DES CARACTeRES INTERDITS EN XML
118
 
        char name2[256];
119
 
 
120
 
        for (i=0, j=0; (name[i] != 0) && (j < 250); i++) {
121
 
                switch (name[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]; 
128
 
                }
129
 
        }
130
 
        name2[j] = 0;
131
 
        
132
 
        cout << "label : " << name << " -> " << name2 << endl;
133
 
        
134
 
        fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" style=\"font-size:7\">%s</text>\n",x,y+2,name2);
135
 
}
136
 
 
137
 
void SVGDev::markSens(float x,float y,int sens)
138
 
{       
139
 
        if (sens==1)
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);
141
 
        else
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);
143
 
 
144
 
}
145
 
 
146
 
void SVGDev::Error(const char* message, const char* reason,int nb_error,float x,float y,float largeur)
147
 
{
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);
150
 
}
151
 
 
152
 
 
153