Line data Source code
1 : /* File: document_css_writer.c; Copyright and License: see below */
2 :
3 : #include "document/document_css_writer.h"
4 : #include "utf8stringbuf/utf8string.h"
5 : #include "u8/u8_trace.h"
6 : #include "u8/u8_log.h"
7 : #include <stdbool.h>
8 : #include <assert.h>
9 :
10 : /* IO_FILE_FORMAT_CSS */
11 :
12 : static const char CSS_GENERAL[]
13 : ="body {\n"
14 : " background-color: rgb(255,255,255);\n"
15 : " font-family: Helvetica,Arial,sans-serif;\n"
16 : "}\n"
17 : "article {\n"
18 : " margin-left: 200px;\n"
19 : " padding-top: 8px;\n"
20 : " padding-right: 8px;\n"
21 : " padding-bottom: 8px;\n"
22 : " padding-left: 24px;\n"
23 : "}\n"
24 : "nav {\n"
25 : " background-color: rgb(240,248,255);\n"
26 : " left: 0px;\n"
27 : " top: 0px;\n"
28 : " width: 200px;\n"
29 : " height: 100%;\n"
30 : " position: fixed;\n"
31 : " overflow: auto;\n"
32 : " padding: 2px;\n"
33 : " margin: 0px;\n"
34 : "}\n";
35 :
36 : static const char CSS_TOC[]
37 : ="a:hover {\n"
38 : " background-color: rgb(255,255,255);\n"
39 : "}\n"
40 : ".toc {\n"
41 : " list-style-type: none;\n"
42 : " list-style-position: inside;\n"
43 : " padding: 0px;\n"
44 : " margin: 0px;\n"
45 : "}\n"
46 : ".toc1 {\n"
47 : " padding-left: 0px;\n"
48 : " padding-top: 3px;\n"
49 : " padding-right: 0px;\n"
50 : " padding-bottom: 3px;\n"
51 : " color: rgb(192,128,0);\n"
52 : " font-size: small;\n"
53 : " counter-reset: cnt-head-two;\n"
54 : "}\n"
55 : ".toc2::before {\n"
56 : " counter-increment: cnt-head-two;\n"
57 : " content: counter(cnt-head-two) \"\\0000a0 \";\n"
58 : "}\n"
59 : ".toc2 {\n"
60 : " padding-left: 8px;\n"
61 : " padding-top: 2px;\n"
62 : " padding-right: 0px;\n"
63 : " padding-bottom: 2px;\n"
64 : " color: rgb(192,128,0);\n"
65 : " font-size: small;\n"
66 : " counter-reset: cnt-head-three;\n"
67 : "}\n"
68 : ".toc3::before {\n"
69 : " counter-increment: cnt-head-three;\n"
70 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \"\\0000a0 \";\n"
71 : "}\n"
72 : ".toc3 {\n"
73 : " padding-left: 8px;\n"
74 : " padding-top: 2px;\n"
75 : " padding-right: 0px;\n"
76 : " padding-bottom: 1px;\n"
77 : " color: rgb(192,128,0);\n"
78 : " font-size: x-small;\n"
79 : " counter-reset: cnt-head-four;\n"
80 : "}\n"
81 : ".toc4::before {\n"
82 : " counter-increment: cnt-head-four;\n"
83 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \".\" counter(cnt-head-four) \"\\0000a0 \";\n"
84 : "}\n"
85 : ".toc4 {\n"
86 : " padding-left: 8px;\n"
87 : " padding-top: 1px;\n"
88 : " padding-right: 0px;\n"
89 : " padding-bottom: 1px;\n"
90 : " border-left: 2px solid #FFFFFF;\n"
91 : " color: rgb(192,128,0);\n"
92 : " font-size: xx-small;\n"
93 : " counter-reset: cnt-head-five;\n"
94 : "}\n"
95 : ".toc5::before {\n"
96 : " counter-increment: cnt-head-five;\n"
97 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \".\" counter(cnt-head-four) \".\" counter(cnt-head-five) \"\\0000a0 \";\n"
98 : "}\n"
99 : ".toc5 {\n"
100 : " padding-left: 8px;\n"
101 : " padding-top: 1px;\n"
102 : " padding-right: 0px;\n"
103 : " padding-bottom: 0px;\n"
104 : " color: rgb(192,128,0);\n"
105 : " font-size: xx-small;\n"
106 : " counter-reset: cnt-head-six;\n"
107 : "}\n"
108 : ".toc6::before {\n"
109 : " counter-increment: cnt-head-six;\n"
110 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \".\" counter(cnt-head-four) \".\" counter(cnt-head-five) \".\" counter(cnt-head-six) \"\\0000a0 \";\n"
111 : "}\n"
112 : ".toc6 {\n"
113 : " padding-left: 8px;\n"
114 : " color: rgb(192,128,0);\n"
115 : " font-size: xx-small;\n"
116 : "}\n";
117 :
118 : static const char CSS_DATA_LAYOUT[]
119 : =".diag-title {\n"
120 : " color: rgb(192,128,0);\n"
121 : "}\n"
122 : ".diag-stereo::before {\n"
123 : " content:\"\\0000a0 \\0000ab\";\n"
124 : "}\n"
125 : ".diag-stereo {\n"
126 : " color: rgb(80,80,80);\n"
127 : "}\n"
128 : ".diag-stereo::after {\n"
129 : " content: \"\\0000bb\";\n"
130 : "}\n"
131 : ".diag-name {\n"
132 : " color: rgb(128,128,128);\n"
133 : "}\n"
134 : ".diag-type::before {\n"
135 : " content:\"\\0000a0 \\0000a0 {type=\";\n"
136 : "}\n"
137 : ".diag-type {\n"
138 : " color: rgb(160,160,160);\n"
139 : "}\n"
140 : ".diag-type::after {\n"
141 : " content: \"}\";\n"
142 : "}\n"
143 : ".diag-id::before {\n"
144 : " content:\"\\0000a0 \\0000a0 {id=\";\n"
145 : "}\n"
146 : ".diag-id {\n"
147 : " color: rgb(160,160,160);\n"
148 : "}\n"
149 : ".diag-id::after {\n"
150 : " content: \"}\";\n"
151 : "}\n"
152 : ".diag-descr {\n"
153 : " padding: 16px 8px;\n"
154 : " margin-left: 2px;\n"
155 : " margin-right: 2px;\n"
156 : " margin-top: 2px;\n"
157 : " margin-bottom: 12px;\n"
158 : " border: 1px solid #DDAA88;\n"
159 : "}\n"
160 : ".clas {\n"
161 : " margin-top: 8px;\n"
162 : " border-top: 1px solid #CCCCCC;\n"
163 : " border-right: 1px solid #CCCCCC;\n"
164 : " border-bottom: 1px solid #CCCCCC;\n"
165 : "}\n"
166 : ".clas-stereo::before {\n"
167 : " content:\"\\0000a0 \\0000ab\";\n"
168 : "}\n"
169 : ".clas-stereo {\n"
170 : " color: rgb(80,80,80);\n"
171 : "}\n"
172 : ".clas-stereo::after {\n"
173 : " content: \"\\0000bb\";\n"
174 : "}\n"
175 : ".clas-name {\n"
176 : " color: rgb(192,128,0);\n"
177 : "}\n"
178 : ".clas-type::before {\n"
179 : " content:\"\\0000a0 \\0000a0 {type=\";\n"
180 : "}\n"
181 : ".clas-type {\n"
182 : " color: rgb(160,160,160);\n"
183 : "}\n"
184 : ".clas-type::after {\n"
185 : " content: \"}\";\n"
186 : "}\n"
187 : ".clas-id::before {\n"
188 : " content:\"\\0000a0 \\0000a0 {id=\";\n"
189 : "}\n"
190 : ".clas-id {\n"
191 : " color: rgb(160,160,160);\n"
192 : "}\n"
193 : ".clas-id::after {\n"
194 : " content: \"}\";\n"
195 : "}\n"
196 : ".clas-see::before {\n"
197 : " content:\"appears in \";\n"
198 : "}\n"
199 : ".clas-see {\n"
200 : " background-color: rgb(240,240,240);\n"
201 : " text-align: right;\n"
202 : " font-size: x-small;\n"
203 : " color: rgb(160,160,160);\n"
204 : "}\n"
205 : ".clas-descr {\n"
206 : " padding: 16px 8px;\n"
207 : " margin: 2px;\n"
208 : " border: 1px solid #CCCCCC;\n"
209 : "}\n"
210 : ".feat {\n"
211 : " font-size: small;\n"
212 : " margin-left: 32px;\n"
213 : " margin-right: 0px;\n"
214 : "}\n"
215 : ".feat-stereo::before {\n"
216 : " content:\"\\0000a0 \\0000ab\";\n"
217 : "}\n"
218 : ".feat-stereo {\n"
219 : " color: rgb(80,80,80);\n"
220 : "}\n"
221 : ".feat-stereo::after {\n"
222 : " content: \"\\0000bb\";\n"
223 : "}\n"
224 : /* ".feat-name {\n" */
225 : /* " color: rgb(0,0,0);\n" */
226 : /* "}\n" */
227 : ".feat-type::before {\n"
228 : " content:\"\\0000a0 \\0000a0 {type=\";\n"
229 : "}\n"
230 : ".feat-type {\n"
231 : " color: rgb(160,160,160);\n"
232 : "}\n"
233 : ".feat-type::after {\n"
234 : " content: \"}\";\n"
235 : "}\n"
236 : ".feat-id::before {\n"
237 : " content: \"\\0000a0 \\0000a0 {id=\";\n"
238 : "}\n"
239 : ".feat-id {\n"
240 : " color: rgb(160,160,160);\n"
241 : "}\n"
242 : ".feat-id::after {\n"
243 : " content :\"}\";\n"
244 : "}\n"
245 : ".feat-descr {\n"
246 : " padding: 8px 8px;\n"
247 : " margin: 2px;\n"
248 : " border: 1px solid #CCCCCC;\n"
249 : "}\n"
250 : ".rel {\n"
251 : " font-size: small;\n"
252 : " margin-left: 32px;\n"
253 : " margin-right: 0px;\n"
254 : "}\n"
255 : ".rel-stereo::before {\n"
256 : " content:\"\\0000a0 \\0000ab\";\n"
257 : "}\n"
258 : ".rel-stereo {\n"
259 : " color: rgb(80,80,80);\n"
260 : "}\n"
261 : ".rel-stereo::after {\n"
262 : " content: \"\\0000bb\";\n"
263 : "}\n"
264 : /* ".rel-name {\n" */
265 : /* " color: rgb(0,0,0);\n" */
266 : /* "}\n" */
267 : /* ".rel-dest {\n" */
268 : /* " color: rgb(0,0,0);\n" */
269 : /* "}\n" */
270 : ".rel-type::before {\n"
271 : " content:\"\\0000a0 \\0000a0 {type=\";\n"
272 : "}\n"
273 : ".rel-type {\n"
274 : " color: rgb(160,160,160);\n"
275 : "}\n"
276 : ".rel-type::after {\n"
277 : " content: \"}\";\n"
278 : "}\n"
279 : ".rel-id::before {\n"
280 : " content: \"\\0000a0 \\0000a0 {id=\";\n"
281 : "}\n"
282 : ".rel-id {\n"
283 : " color: rgb(160,160,160);\n"
284 : "}\n"
285 : ".rel-id::after {\n"
286 : " content: \"}\";\n"
287 : "}\n"
288 : ".rel-descr {\n"
289 : " padding: 8px 8px;\n"
290 : " margin: 2px;\n"
291 : " border: 1px solid #CCCCCC;\n"
292 : "}\n";
293 :
294 : static const char CSS_SECTIONS[]
295 : ="h1 {\n"
296 : " counter-reset: cnt-head-two;\n"
297 : "}\n"
298 : "h2::before {\n"
299 : " counter-increment: cnt-head-two;\n"
300 : " content: counter(cnt-head-two) \"\\0000a0 \";\n"
301 : "}\n"
302 : "h2 {\n"
303 : " counter-reset: cnt-head-three;\n"
304 : "}\n"
305 : "h3::before {\n"
306 : " counter-increment: cnt-head-three;\n"
307 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \"\\0000a0 \";\n"
308 : "}\n"
309 : "h3 {\n"
310 : " counter-reset: cnt-head-four;\n"
311 : "}\n"
312 : "h4::before {\n"
313 : " counter-increment: cnt-head-four;\n"
314 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \".\" counter(cnt-head-four) \"\\0000a0 \";\n"
315 : "}\n"
316 : "h4 {\n"
317 : " counter-reset: cnt-head-five;\n"
318 : "}\n"
319 : "h5::before {\n"
320 : " counter-increment: cnt-head-five;\n"
321 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \".\" counter(cnt-head-four) \".\" counter(cnt-head-five) \"\\0000a0 \";\n"
322 : "}\n"
323 : "h5 {\n"
324 : " counter-reset: cnt-head-six;\n"
325 : "}\n"
326 : "h6::before {\n"
327 : " counter-increment: cnt-head-six;\n"
328 : " content: counter(cnt-head-two) \".\" counter(cnt-head-three) \".\" counter(cnt-head-four) \".\" counter(cnt-head-five) \".\" counter(cnt-head-six) \"\\0000a0 \";\n"
329 : "}\n"
330 : "p {\n"
331 : " padding: 2px;\n"
332 : " margin: 0px;\n"
333 : "}\n";
334 :
335 0 : void document_css_writer_init ( document_css_writer_t *this_,
336 : universal_output_stream_t *output )
337 : {
338 0 : U8_TRACE_BEGIN();
339 0 : assert( NULL != output );
340 :
341 0 : (*this_).output = output;
342 :
343 0 : U8_TRACE_END();
344 0 : }
345 :
346 0 : void document_css_writer_destroy( document_css_writer_t *this_ )
347 : {
348 0 : U8_TRACE_BEGIN();
349 :
350 0 : (*this_).output = NULL;
351 :
352 0 : U8_TRACE_END();
353 0 : }
354 :
355 0 : u8_error_t document_css_writer_write_stylesheet( document_css_writer_t *this_ )
356 : {
357 0 : U8_TRACE_BEGIN();
358 0 : u8_error_t export_err = U8_ERROR_NONE;
359 :
360 0 : utf8string_t *text_1 = CSS_GENERAL;
361 0 : const size_t text_1_len = utf8string_get_length(text_1);
362 0 : export_err |= universal_output_stream_write( (*this_).output, text_1, text_1_len );
363 :
364 0 : utf8string_t *text_2 = CSS_TOC;
365 0 : const size_t text_2_len = utf8string_get_length(text_2);
366 0 : export_err |= universal_output_stream_write( (*this_).output, text_2, text_2_len );
367 :
368 0 : utf8string_t *text_3 = CSS_DATA_LAYOUT;
369 0 : const size_t text_3_len = utf8string_get_length(text_3);
370 0 : export_err |= universal_output_stream_write( (*this_).output, text_3, text_3_len );
371 :
372 0 : utf8string_t *text_4 = CSS_SECTIONS;
373 0 : const size_t text_4_len = utf8string_get_length(text_4);
374 0 : export_err |= universal_output_stream_write( (*this_).output, text_4, text_4_len );
375 :
376 0 : U8_TRACE_END_ERR( export_err );
377 0 : return export_err;
378 : }
379 :
380 :
381 : /*
382 : Copyright 2017-2025 Andreas Warnke
383 :
384 : Licensed under the Apache License, Version 2.0 (the "License");
385 : you may not use this file except in compliance with the License.
386 : You may obtain a copy of the License at
387 :
388 : http://www.apache.org/licenses/LICENSE-2.0
389 :
390 : Unless required by applicable law or agreed to in writing, software
391 : distributed under the License is distributed on an "AS IS" BASIS,
392 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
393 : See the License for the specific language governing permissions and
394 : limitations under the License.
395 : */
|