-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtexto.c
More file actions
125 lines (101 loc) · 2.88 KB
/
texto.c
File metadata and controls
125 lines (101 loc) · 2.88 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "texto.h"
#include "point.h"
typedef struct{
char id[100];
int size;
Point point;
char* txt;
char cb[220], cp[220];
}TextoStruct;
//Create
Texto criaTexto(char* id, int size, float x, float y, char* txt, char* cb, char* cp){
TextoStruct* tex = (TextoStruct*)malloc(sizeof(TextoStruct));
Point point = criaPoint(x, y);
tex->point = point;
strcpy(tex->id, id);
strcpy(tex->cb, cb);
strcpy(tex->cp, cp);
tex->txt = (char*) malloc(sizeof(char) * (size + 1));
strcpy(tex->txt, txt);
return tex;
}
//Setters
void textoSetId(Texto texto, char* id){
TextoStruct* tex = (TextoStruct*)texto;
strcpy(tex->id, id);
}
void textoSetX(Texto texto, float x){
TextoStruct* tex = (TextoStruct*)texto;
setPointX(tex->point, x);
}
void textoSetY(Texto texto, float y){
TextoStruct* tex = (TextoStruct*)texto;
setPointY(tex->point, y);
}
void textoSetTexto(Texto texto, char* txt, int size){
TextoStruct* tex = (TextoStruct*) texto;
free(tex->txt);
tex->txt = (char*) malloc(sizeof(char) * size);
strcpy(tex->txt, txt);
}
void textoSetCorBorda(Texto texto, char* cb){
TextoStruct* tex = (TextoStruct*)texto;
strcpy(tex->cb, cb);
}
void textoSetCorPreenchimento(Texto texto, char* cp){
TextoStruct* tex = (TextoStruct*)texto;
strcpy(tex->cp, cp);
}
void textoSetPoint(Texto texto, Point point){
TextoStruct* tex = (TextoStruct*)texto;
free(tex->point);
tex->point = point;
}
//Getters
char* textoGetId(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
return tex->id;
}
float textoGetX(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
return getPointX(tex->point);
}
float textoGetY(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
return getPointY(tex->point);
}
char* textoGetTexto(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
return tex->txt;
}
char* textoGetCorBorda(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
return tex->cb;
}
char* textoGetCorPreenchimento(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
return tex->cp;
}
Point textoGetPoint(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
return tex->point;
}
//Desaloca texto
void textoDeletaTxt(Texto texto){
TextoStruct* tex = (TextoStruct*)texto;
free(tex->txt);
}
void textoSwap(Texto t1, Texto t2){
TextoStruct* a = (TextoStruct*) t1;
TextoStruct* b = (TextoStruct*) t2;
TextoStruct temp = *a;
*a = *b;
*b = temp;
}
void textoDesenhaSvgGeo(Texto texto, void* fileSvg){
fprintf((FILE*)fileSvg, "\n\t<text x=\"%f\" y=\"%f\" stroke=\"%s\" fill=\"%s\" stroke-width=\"0.5\">%s</text>", textoGetX(texto), textoGetY(texto), textoGetCorBorda(texto), textoGetCorPreenchimento(texto), textoGetTexto(texto));
//stroke-width não devia estar em cores padrao?
}