This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortie_eps.c
96 lines (73 loc) · 2.6 KB
/
sortie_eps.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "geom2d.h"
#include "sortie.h"
FichierSortie sortie_open(char* path, int w, int h, SortieMode mode) {
FILE* out = fopen(path, "w");
fprintf(out, "%%!PS-Adobe-3.0 EPSF-3.0\n");
fprintf(out, "%%%%BoundingBox: 0 0 %d %d\n", w, h);
fprintf(out, "\n%% Fichier généré automatiquement, ne pas modifier. (%s)\n\n", path);
if (mode == MODE_STROKED_POINTS) {
fprintf(out, "%% Macro pour dessiner des points\n/circle {0.2 0 360 arc closepath 0 0 1 setrgbcolor fill} def\n\n");
}
return (FichierSortie) {
.out = out,
.mode = mode,
.h = h,
};
}
void sortie_ecrire_contour(FichierSortie self, TableauPoints contour) {
FILE* out = self.out;
SortieMode mode = self.mode;
Point p;
if (contour.len > 0) {
p = contour.inner[0];
fprintf(out, "%f %f moveto\n", p.x, self.h - p.y);
for (int i = 1; i < contour.len; i++) {
p = contour.inner[i];
fprintf(out, "%f %f lineto\n", p.x, self.h - p.y);
}
if (mode != MODE_FILLED) {
fprintf(out, "0.1 setlinewidth stroke\n");
}
}
if (mode == MODE_STROKED_POINTS) {
// On commence à 1, le premier point et le dernier points sont les mêmes
for (int i = 1; i < contour.len; i++) {
p = contour.inner[i];
fprintf(out, "%f %f circle\n", p.x, self.h - p.y);
}
}
}
void sortie_ecrire_contour_bezier(FichierSortie self, ListeBezier3* contour) {
FILE* out = self.out;
SortieMode mode = self.mode;
Point p;
if (contour->len > 0) {
ListeBezier3Noeud* noeud = contour->first;
p = noeud->value.c0;
fprintf(out, "%f %f moveto\n", p.x, self.h - p.y);
while (noeud) {
Point c1 = noeud->value.c1, c2 = noeud->value.c2;
p = noeud->value.c3;
fprintf(out, "%f %f %f %f %f %f curveto\n", c1.x, self.h - c1.y, c2.x, self.h - c2.y, p.x, self.h - p.y);
noeud = noeud->next;
}
if (mode != MODE_FILLED) {
fprintf(out, "0.1 setlinewidth stroke\n");
}
}
if (mode == MODE_STROKED_POINTS) {
// On commence à 1, le premier point et le dernier points sont les mêmes
for (ListeBezier3Noeud* noeud = contour->first; noeud; noeud = noeud->next) {
Point p = noeud->value.c1;
fprintf(out, "%f %f circle\n", p.x, self.h - p.y);
}
}
}
void sortie_close(FichierSortie self) {
FILE* out = self.out;
if (self.mode == MODE_FILLED) {
fprintf(out, "fill\n");
}
fprintf(out, "showpage\n");
fclose(out);
}