TPCCLIB
Loading...
Searching...
No Matches
svg_title.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpcsvg.h"
7/*****************************************************************************/
9extern int SVG_INLINE;
10/*****************************************************************************/
11
12/*****************************************************************************/
19 FILE *fp,
21 const char *main_title_text,
23 const char *sub_title_text,
25 struct svg_viewports *vp,
28 char *errmsg,
30 int verbose
31) {
32 char tmp[1024], line[128], ilc[9];
33 double main_pos, sub_pos;
34
35 if(verbose>0) printf("%s(fp, mtt, stt, vp, errmsg, %d)\n", __func__, verbose);
36 if(verbose>1) {
37 printf("main_title_text := '%s'\n", main_title_text);
38 printf("sub_title_text := '%s'\n", sub_title_text);
39 }
40
41 /* Check the input */
42 if(vp->main_title_viewport.is==0) return(0);
43 if(fp==NULL) {
44 if(errmsg!=NULL) sprintf(errmsg, "file was closed too early");
45 return(1);
46 }
47
48 if(SVG_INLINE) strcpy(ilc, "svg:"); else strcpy(ilc, "");
49
50 /* Set title of the SVG document */
51 sprintf(tmp, "\n <%stitle>%s</%stitle>\n", ilc, main_title_text, ilc);
52 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(4);}
53
54 /* Create a new viewport for main title */
55 strcpy(tmp, "\n <!-- Main title viewport -->\n");
56 sprintf(line, " <%ssvg x=\"%dpx\" y=\"%dpx\" width=\"%dpx\" height=\"%d\"",
58 vp->main_title_viewport.w, vp->main_title_viewport.h); strcat(tmp, line);
59 sprintf(line, "\n viewBox=\"0 0 %d %d\"",
60 vp->main_title_viewport.w, vp->main_title_viewport.h); strcat(tmp, line);
61 strcat(tmp, "\n preserveAspectRatio=\"xMidYMid meet\"");
62 strcat(tmp, ">\n");
63 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(4);}
64
65
66#if(0)
67 sprintf(tmp, " <rect width=\"%dpx\" height=\"%dpx\" stroke=\"none\" fill=\"lime\" fill-opacity=\"0.3\" />\n",
69 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(99);}
70#endif
71
72 /* Determine the y positions for titles */
73 if(strlen(main_title_text)>0) { /* main title exists */
74 if(strlen(sub_title_text)==0) { /* no subtitle */
75 main_pos=0.75*(double)vp->main_title_viewport.h;
76 sub_pos=vp->main_title_viewport.h;
77 } else { /* also subtitle */
78 main_pos=0.52*(double)vp->main_title_viewport.h;
79 sub_pos=0.9*(double)vp->main_title_viewport.h;
80 }
81 } else { /* no main title */
82 if(strlen(sub_title_text)==0) { /* no subtitle either */
83 main_pos=0.5*(double)vp->main_title_viewport.h;
84 sub_pos=vp->main_title_viewport.h;
85 } else { /* only subtitle */
86 main_pos=0.0;
87 sub_pos=0.4*(double)vp->main_title_viewport.h;
88 }
89 }
90
91 /* Set main title text */
92 sprintf(tmp, " <%stext x=\"%d\" y=\"%g\"\n", ilc, vp->main_title_viewport.w/2, main_pos);
93 sprintf(line, " font-family=\"Sans-serif\""); strcat(tmp, line);
94 sprintf(line, " text-anchor=\"middle\""); strcat(tmp, line);
95 sprintf(line, " font-size=\"%d\"", vp->main_title_viewport.chr_size); strcat(tmp, line);
96 sprintf(line, " fill=\"black\""); strcat(tmp, line);
97 sprintf(line, ">\n"); strcat(tmp, line);
98 sprintf(line, " %s\n", main_title_text); strcat(tmp, line);
99 sprintf(line, " </%stext>\n", ilc); strcat(tmp, line);
100 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(6);}
101
102 /* Set sub title text */
103 sprintf(tmp, " <%stext x=\"%d\" y=\"%g\"\n", ilc, vp->main_title_viewport.w/2, sub_pos);
104 sprintf(line, " font-family=\"Sans-serif\""); strcat(tmp, line);
105 sprintf(line, " text-anchor=\"middle\""); strcat(tmp, line);
106 sprintf(line, " font-size=\"%d\"", 2*vp->main_title_viewport.chr_size/3); strcat(tmp, line);
107 sprintf(line, " fill=\"black\""); strcat(tmp, line);
108 sprintf(line, ">\n"); strcat(tmp, line);
109 sprintf(line, " %s\n", sub_title_text); strcat(tmp, line);
110 sprintf(line, " </%stext>\n", ilc); strcat(tmp, line);
111 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(8);}
112
113 /* Close the view port */
114 sprintf(tmp, " </%ssvg>\n", ilc);
115 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(9);}
116
117 return(0);
118}
119/*****************************************************************************/
120
121/*****************************************************************************/
128 FILE *fp,
130 const char *title_text,
132 struct svg_viewports *vp,
135 char *errmsg,
137 int verbose
138) {
139 char tmp[1024], line[128], ilc[9];
140
141 if(verbose>0) printf("%s(fp, tt, vp, errmsg, %d)\n", __func__, verbose);
142 if(verbose>1) printf("title_text := '%s'\n", title_text);
143
144 /* Check the input */
145 if(vp->xaxis_title_viewport.is==0) return(0);
146 if(fp==NULL) {
147 if(errmsg!=NULL) sprintf(errmsg, "file was closed too early");
148 return(1);
149 }
150
151 if(SVG_INLINE) strcpy(ilc, "svg:"); else strcpy(ilc, "");
152
153 /* Create a new viewport for x axis title */
154 strcpy(tmp, "\n <!-- X axis title viewport -->\n");
155 sprintf(line, " <%ssvg x=\"%dpx\" y=\"%dpx\" width=\"%dpx\" height=\"%d\"",
157 vp->xaxis_title_viewport.w, vp->xaxis_title_viewport.h); strcat(tmp, line);
158 sprintf(line, "\n viewBox=\"0 0 %d %d\"",
159 vp->xaxis_title_viewport.w, vp->xaxis_title_viewport.h); strcat(tmp, line);
160 strcat(tmp, "\n preserveAspectRatio=\"xMidYMid meet\"");
161 strcat(tmp, ">\n");
162 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(4);}
163
164
165#if(0)
166 sprintf(tmp, " <rect width=\"%dpx\" height=\"%dpx\" stroke=\"none\" fill=\"green\" fill-opacity=\"0.3\" />\n",
168 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(99);}
169#endif
170
171
172 /* Set the text contents */
173 sprintf(tmp, " <%stext x=\"%d\" y=\"%g\"\n",
174 ilc, vp->xaxis_title_viewport.w/2, 0.75*(double)vp->xaxis_title_viewport.h);
175 sprintf(line, " font-family=\"Sans-serif\""); strcat(tmp, line);
176 sprintf(line, " text-anchor=\"middle\""); strcat(tmp, line);
177 sprintf(line, " font-size=\"%d\"", vp->xaxis_title_viewport.chr_size); strcat(tmp, line);
178 sprintf(line, " fill=\"black\""); strcat(tmp, line);
179 sprintf(line, ">\n"); strcat(tmp, line);
180 sprintf(line, " %s\n", title_text); strcat(tmp, line);
181 sprintf(line, " </%stext>\n", ilc); strcat(tmp, line);
182 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(6);}
183
184 /* Close the view port */
185 sprintf(tmp, " </%ssvg>\n", ilc);
186 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(9);}
187
188 return(0);
189}
190/*****************************************************************************/
191
192/*****************************************************************************/
199 FILE *fp,
201 const char *title_text,
203 struct svg_viewports *vp,
206 char *errmsg,
208 int verbose
209) {
210 char tmp[1024], line[128], ilc[9];
211 double xpos, ypos;
212
213 if(verbose>0) printf("%s(fp, tt, vp, errmsg, %d)\n", __func__, verbose);
214 if(verbose>1) printf("title_text := '%s'\n", title_text);
215
216 /* Check the input */
217 if(vp->yaxis_title_viewport.is==0) return(0);
218 if(fp==NULL) {
219 if(errmsg!=NULL) sprintf(errmsg, "file was closed too early");
220 return(1);
221 }
222
223 if(SVG_INLINE) strcpy(ilc, "svg:"); else strcpy(ilc, "");
224
225 /* Create a new viewport for y axis title */
226 strcpy(tmp, "\n <!-- Y axis title viewport -->\n");
227 sprintf(line, " <%ssvg x=\"%dpx\" y=\"%dpx\" width=\"%dpx\" height=\"%d\"",
229 vp->yaxis_title_viewport.w, vp->yaxis_title_viewport.h); strcat(tmp, line);
230 sprintf(line, "\n viewBox=\"0 0 %d %d\"",
231 vp->yaxis_title_viewport.w, vp->yaxis_title_viewport.h); strcat(tmp, line);
232 strcat(tmp, "\n preserveAspectRatio=\"xMidYMid meet\"");
233 strcat(tmp, ">\n");
234 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(4);}
235
236
237#if(0)
238 sprintf(tmp, " <rect width=\"%dpx\" height=\"%dpx\" stroke=\"none\" fill=\"red\" fill-opacity=\"0.3\" />\n",
240 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(99);}
241#endif
242
243 /* Set the text contents */
244 xpos=0.75*(double)vp->yaxis_title_viewport.w;
245 ypos=0.5*(double)vp->yaxis_title_viewport.h;
246 sprintf(tmp, " <%stext x=\"%g\" y=\"%g\"\n", ilc, xpos, ypos);
247 sprintf(line, " font-family=\"Sans-serif\""); strcat(tmp, line);
248 sprintf(line, " text-anchor=\"middle\""); strcat(tmp, line);
249 sprintf(line, " font-size=\"%d\"", vp->yaxis_title_viewport.chr_size); strcat(tmp, line);
250 sprintf(line, " fill=\"black\""); strcat(tmp, line);
251 sprintf(line, " transform=\"rotate(270,%g,%g)\"", xpos, ypos); strcat(tmp, line);
252 sprintf(line, ">\n"); strcat(tmp, line);
253 sprintf(line, " %s\n", title_text); strcat(tmp, line);
254 sprintf(line, " </%stext>\n", ilc); strcat(tmp, line);
255 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(6);}
256
257 /* Close the view port */
258 sprintf(tmp, " </%ssvg>\n", ilc);
259 if(svg_write(fp, tmp, errmsg, verbose-5)!=0) {return(9);}
260
261 return(0);
262}
263/*****************************************************************************/
264
265/*****************************************************************************/
Header file for libtpcsvg.
int svg_write(FILE *fp, const char *svg_string, char *errmsg, int verbose)
Definition svg_file.c:304
struct svg_viewport_pos main_title_viewport
Definition libtpcsvg.h:106
struct svg_viewport_pos yaxis_title_viewport
Definition libtpcsvg.h:108
struct svg_viewport_pos xaxis_title_viewport
Definition libtpcsvg.h:110
int SVG_INLINE
Definition svg_file.c:12
int svg_create_xaxis_title(FILE *fp, const char *title_text, struct svg_viewports *vp, char *errmsg, int verbose)
Definition svg_title.c:126
int svg_create_main_title(FILE *fp, const char *main_title_text, const char *sub_title_text, struct svg_viewports *vp, char *errmsg, int verbose)
Definition svg_title.c:17
int svg_create_yaxis_title(FILE *fp, const char *title_text, struct svg_viewports *vp, char *errmsg, int verbose)
Definition svg_title.c:197