1 /* Lasem
2  *
3  * Copyright © 2007-2008 Emmanuel Pacaud
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author:
21  * 	Emmanuel Pacaud <emmanuel@gnome.org>
22  */
23 
24 #include <lsmmathmlenums.h>
25 #include <lsmtraits.h>
26 #include <string.h>
27 
28 static const char *lsm_mathml_mode_strings[] = {
29 	"display",
30 	"inline"
31 };
32 
33 const char *
lsm_mathml_mode_to_string(LsmMathmlMode mode)34 lsm_mathml_mode_to_string (LsmMathmlMode mode)
35 {
36 	if (mode < 0 || mode > LSM_MATHML_MODE_INLINE)
37 		return NULL;
38 
39 	return lsm_mathml_mode_strings[mode];
40 }
41 
42 LsmMathmlMode
lsm_mathml_mode_from_string(const char * string)43 lsm_mathml_mode_from_string (const char *string)
44 {
45 	return lsm_enum_value_from_string (string, lsm_mathml_mode_strings,
46 					   G_N_ELEMENTS (lsm_mathml_mode_strings));
47 }
48 
49 static const char *lsm_mathml_display_strings[] = {
50 	"block",
51 	"inline"
52 };
53 
54 const char *
lsm_mathml_display_to_string(LsmMathmlDisplay display)55 lsm_mathml_display_to_string (LsmMathmlDisplay display)
56 {
57 	if (display < 0 || display > LSM_MATHML_DISPLAY_INLINE)
58 		return NULL;
59 
60 	return lsm_mathml_display_strings[display];
61 }
62 
63 LsmMathmlDisplay
lsm_mathml_display_from_string(const char * string)64 lsm_mathml_display_from_string (const char *string)
65 {
66 	return lsm_enum_value_from_string (string, lsm_mathml_display_strings,
67 					   G_N_ELEMENTS (lsm_mathml_display_strings));
68 }
69 
70 static const char *lsm_mathml_space_name_strings[] = {
71 	"negativeveryverythinmathspace",
72 	"negativeverythinmathspace",
73 	"negativethinmathspace",
74 	"negativemediummathspace",
75 	"negativethickmathspace",
76 	"negativeverythickmathspace",
77 	"negativeveryverythickmathspace",
78 
79 	"veryverythinmathspace",
80 	"verythinmathspace",
81 	"thinmathspace",
82 	"mediummathspace",
83 	"thickmathspace",
84 	"verythickmathspace",
85 	"veryverythickmathspace",
86 	"infinity"
87 };
88 
89 const char *
lsm_mathml_space_name_to_string(LsmMathmlSpaceName space_name)90 lsm_mathml_space_name_to_string (LsmMathmlSpaceName space_name)
91 {
92 	if (space_name < 0 || space_name > LSM_MATHML_SPACE_NAME_INFINITY)
93 		return NULL;
94 
95 	return lsm_mathml_space_name_strings[space_name];
96 }
97 
98 LsmMathmlSpaceName
lsm_mathml_space_name_from_string(const char * string)99 lsm_mathml_space_name_from_string (const char *string)
100 {
101 	return lsm_enum_value_from_string (string, lsm_mathml_space_name_strings,
102 					   G_N_ELEMENTS (lsm_mathml_space_name_strings));
103 }
104 
105 static const char *lsm_mathml_unit_strings[] = {
106 	"",
107 	"em",
108 	"ex",
109 	"in",
110 	"cm",
111 	"mm",
112 	"pt",
113 	"px",
114 	"pc",
115 	"%"
116 };
117 
118 const char *
lsm_mathml_unit_to_string(LsmMathmlUnit unit)119 lsm_mathml_unit_to_string (LsmMathmlUnit unit)
120 {
121 	if (unit < 0 || unit > LSM_MATHML_UNIT_PERCENT)
122 		return NULL;
123 
124 	return lsm_mathml_unit_strings[unit];
125 }
126 
127 LsmMathmlUnit
lsm_mathml_unit_from_string(const char * string)128 lsm_mathml_unit_from_string (const char *string)
129 {
130 	return lsm_enum_value_from_string (string, lsm_mathml_unit_strings,
131 					   G_N_ELEMENTS (lsm_mathml_unit_strings));
132 }
133 
134 static const char *lsm_mathml_font_style_strings[] = {
135 	"normal",
136 	"italic"
137 };
138 
139 const char *
lsm_mathml_font_style_to_string(LsmMathmlFontStyle font_style)140 lsm_mathml_font_style_to_string (LsmMathmlFontStyle font_style)
141 {
142 	if (font_style < 0 || font_style > LSM_MATHML_FONT_STYLE_ITALIC)
143 		return NULL;
144 
145 	return lsm_mathml_font_style_strings[font_style];
146 }
147 
148 LsmMathmlFontStyle
lsm_mathml_font_style_from_string(const char * string)149 lsm_mathml_font_style_from_string (const char *string)
150 {
151 	return lsm_enum_value_from_string (string, lsm_mathml_font_style_strings,
152 					   G_N_ELEMENTS (lsm_mathml_font_style_strings));
153 }
154 
155 static const char *lsm_mathml_font_weight_strings[] = {
156 	"normal",
157 	"bold"
158 };
159 
160 const char *
lsm_mathml_font_weight_to_string(LsmMathmlFontWeight font_weight)161 lsm_mathml_font_weight_to_string (LsmMathmlFontWeight font_weight)
162 {
163 	if (font_weight < 0 || font_weight > LSM_MATHML_FONT_WEIGHT_BOLD)
164 		return NULL;
165 
166 	return lsm_mathml_font_weight_strings[font_weight];
167 }
168 
169 LsmMathmlFontWeight
lsm_mathml_font_weight_from_string(const char * string)170 lsm_mathml_font_weight_from_string (const char *string)
171 {
172 	return lsm_enum_value_from_string (string, lsm_mathml_font_weight_strings,
173 					   G_N_ELEMENTS (lsm_mathml_font_weight_strings));
174 }
175 
176 static const char *lsm_mathml_variant_strings[] = {
177 	"normal",
178 	"bold",
179 	"italic",
180 	"bold-italic",
181 	"double-struck",
182 	"bold-fraktur",
183 	"script",
184 	"bold-script",
185 	"fraktur",
186 	"sans-serif",
187 	"bold-sans-serif",
188 	"sans-serif-italic",
189 	"sans-serif-bold-italic",
190 	"monospace"
191 };
192 
193 const char *
lsm_mathml_variant_to_string(LsmMathmlVariant variant)194 lsm_mathml_variant_to_string (LsmMathmlVariant variant)
195 {
196 	if (variant < 0 || variant > LSM_MATHML_VARIANT_MONOSPACE)
197 		return NULL;
198 
199 	return lsm_mathml_variant_strings[variant];
200 }
201 
202 LsmMathmlVariant
lsm_mathml_variant_from_string(const char * string)203 lsm_mathml_variant_from_string (const char *string)
204 {
205 	return lsm_enum_value_from_string (string, lsm_mathml_variant_strings,
206 					   G_N_ELEMENTS (lsm_mathml_variant_strings));
207 }
208 
209 void
lsm_mathml_variant_set_font_style(LsmMathmlVariant * variant,LsmMathmlFontStyle style)210 lsm_mathml_variant_set_font_style (LsmMathmlVariant *variant, LsmMathmlFontStyle style)
211 {
212 	if (variant == NULL)
213 		return;
214 
215 	switch (style) {
216 		case LSM_MATHML_FONT_STYLE_ITALIC:
217 			switch (*variant) {
218 				case LSM_MATHML_VARIANT_NORMAL:
219 					*variant = LSM_MATHML_VARIANT_ITALIC;
220 					return;
221 				case LSM_MATHML_VARIANT_BOLD:
222 					*variant = LSM_MATHML_VARIANT_BOLD_ITALIC;
223 					return;
224 				case LSM_MATHML_VARIANT_SANS_SERIF:
225 					*variant = LSM_MATHML_VARIANT_SANS_SERIF_ITALIC;
226 					return;
227 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD:
228 					*variant = LSM_MATHML_VARIANT_SANS_SERIF_BOLD_ITALIC;
229 					return;
230 				case LSM_MATHML_VARIANT_ITALIC:
231 				case LSM_MATHML_VARIANT_BOLD_ITALIC:
232 				case LSM_MATHML_VARIANT_DOUBLE_STRUCK:
233 				case LSM_MATHML_VARIANT_FRAKTUR_BOLD:
234 				case LSM_MATHML_VARIANT_SCRIPT:
235 				case LSM_MATHML_VARIANT_SCRIPT_BOLD:
236 				case LSM_MATHML_VARIANT_FRAKTUR:
237 				case LSM_MATHML_VARIANT_SANS_SERIF_ITALIC:
238 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD_ITALIC:
239 				case LSM_MATHML_VARIANT_MONOSPACE:
240 				case LSM_MATHML_VARIANT_ERROR:
241 					return;
242 			}
243 			break;
244 		case LSM_MATHML_FONT_WEIGHT_NORMAL:
245 			switch (*variant) {
246 				case LSM_MATHML_VARIANT_ITALIC:
247 					*variant = LSM_MATHML_VARIANT_NORMAL;
248 					return;
249 				case LSM_MATHML_VARIANT_BOLD_ITALIC:
250 					*variant = LSM_MATHML_VARIANT_BOLD;
251 					return;
252 				case LSM_MATHML_VARIANT_SANS_SERIF_ITALIC:
253 					*variant = LSM_MATHML_VARIANT_SANS_SERIF;
254 					return;
255 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD_ITALIC:
256 					*variant = LSM_MATHML_VARIANT_SANS_SERIF_BOLD;
257 					return;
258 				case LSM_MATHML_VARIANT_BOLD:
259 				case LSM_MATHML_VARIANT_NORMAL:
260 				case LSM_MATHML_VARIANT_SANS_SERIF:
261 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD:
262 				case LSM_MATHML_VARIANT_DOUBLE_STRUCK:
263 				case LSM_MATHML_VARIANT_FRAKTUR_BOLD:
264 				case LSM_MATHML_VARIANT_SCRIPT:
265 				case LSM_MATHML_VARIANT_SCRIPT_BOLD:
266 				case LSM_MATHML_VARIANT_FRAKTUR:
267 				case LSM_MATHML_VARIANT_MONOSPACE:
268 				case LSM_MATHML_VARIANT_ERROR:
269 					return;
270 			}
271 			break;
272 		default:
273 			return;
274 	}
275 }
276 
277 void
lsm_mathml_variant_set_font_weight(LsmMathmlVariant * variant,LsmMathmlFontWeight weight)278 lsm_mathml_variant_set_font_weight (LsmMathmlVariant *variant, LsmMathmlFontWeight weight)
279 {
280 	if (variant == NULL)
281 		return;
282 
283 	switch (weight) {
284 		case LSM_MATHML_FONT_WEIGHT_BOLD:
285 			switch (*variant) {
286 				case LSM_MATHML_VARIANT_NORMAL:
287 					*variant = LSM_MATHML_VARIANT_BOLD;
288 					return;
289 				case LSM_MATHML_VARIANT_ITALIC:
290 					*variant = LSM_MATHML_VARIANT_BOLD_ITALIC;
291 					return;
292 				case LSM_MATHML_VARIANT_SANS_SERIF:
293 					*variant = LSM_MATHML_VARIANT_SANS_SERIF_BOLD;
294 					return;
295 				case LSM_MATHML_VARIANT_SANS_SERIF_ITALIC:
296 					*variant = LSM_MATHML_VARIANT_SANS_SERIF_BOLD_ITALIC;
297 					return;
298 				case LSM_MATHML_VARIANT_SCRIPT:
299 					*variant = LSM_MATHML_VARIANT_SCRIPT_BOLD;
300 					return;
301 				case LSM_MATHML_VARIANT_FRAKTUR:
302 					*variant = LSM_MATHML_VARIANT_FRAKTUR_BOLD;
303 					return;
304 				case LSM_MATHML_VARIANT_BOLD:
305 				case LSM_MATHML_VARIANT_BOLD_ITALIC:
306 				case LSM_MATHML_VARIANT_DOUBLE_STRUCK:
307 				case LSM_MATHML_VARIANT_FRAKTUR_BOLD:
308 				case LSM_MATHML_VARIANT_SCRIPT_BOLD:
309 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD:
310 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD_ITALIC:
311 				case LSM_MATHML_VARIANT_MONOSPACE:
312 				case LSM_MATHML_VARIANT_ERROR:
313 					return;
314 			}
315 			break;
316 		case LSM_MATHML_FONT_WEIGHT_NORMAL:
317 			switch (*variant) {
318 				case LSM_MATHML_VARIANT_BOLD:
319 					*variant = LSM_MATHML_VARIANT_NORMAL;
320 					return;
321 				case LSM_MATHML_VARIANT_BOLD_ITALIC:
322 					*variant = LSM_MATHML_VARIANT_ITALIC;
323 					return;
324 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD:
325 					*variant = LSM_MATHML_VARIANT_SANS_SERIF;
326 					return;
327 				case LSM_MATHML_VARIANT_SANS_SERIF_BOLD_ITALIC:
328 					*variant = LSM_MATHML_VARIANT_SANS_SERIF_ITALIC;
329 					return;
330 				case LSM_MATHML_VARIANT_FRAKTUR_BOLD:
331 					*variant = LSM_MATHML_VARIANT_FRAKTUR;
332 					return;
333 				case LSM_MATHML_VARIANT_SCRIPT_BOLD:
334 					*variant = LSM_MATHML_VARIANT_SCRIPT;
335 					return;
336 				case LSM_MATHML_VARIANT_ITALIC:
337 				case LSM_MATHML_VARIANT_NORMAL:
338 				case LSM_MATHML_VARIANT_SANS_SERIF:
339 				case LSM_MATHML_VARIANT_SANS_SERIF_ITALIC:
340 				case LSM_MATHML_VARIANT_DOUBLE_STRUCK:
341 				case LSM_MATHML_VARIANT_SCRIPT:
342 				case LSM_MATHML_VARIANT_FRAKTUR:
343 				case LSM_MATHML_VARIANT_MONOSPACE:
344 				case LSM_MATHML_VARIANT_ERROR:
345 					return;
346 			}
347 			break;
348 		default:
349 			return;
350 	}
351 }
352 
353 static const char *lsm_mathml_form_strings[] = {
354 	"prefix",
355 	"postfix",
356 	"infix"
357 };
358 
359 const char *
lsm_mathml_form_to_string(LsmMathmlForm form)360 lsm_mathml_form_to_string (LsmMathmlForm form)
361 {
362 	if (form < 0 || form > LSM_MATHML_FORM_INFIX)
363 		return NULL;
364 
365 	return lsm_mathml_form_strings[form];
366 }
367 
368 LsmMathmlForm
lsm_mathml_form_from_string(const char * string)369 lsm_mathml_form_from_string (const char *string)
370 {
371 	return lsm_enum_value_from_string (string, lsm_mathml_form_strings,
372 					   G_N_ELEMENTS (lsm_mathml_form_strings));
373 }
374 
375 static const char *lsm_mathml_row_align_strings[] = {
376 	"baseline",
377 	"top",
378 	"bottom",
379 	"center",
380 	"axis"
381 };
382 
383 const char *
lsm_mathml_row_align_to_string(LsmMathmlRowAlign row_align)384 lsm_mathml_row_align_to_string (LsmMathmlRowAlign row_align)
385 {
386 	if (row_align < 0 || row_align > LSM_MATHML_ROW_ALIGN_AXIS)
387 		return NULL;
388 
389 	return lsm_mathml_row_align_strings[row_align];
390 }
391 
392 LsmMathmlRowAlign
lsm_mathml_row_align_from_string(const char * string)393 lsm_mathml_row_align_from_string (const char *string)
394 {
395 	return lsm_enum_value_from_string (string, lsm_mathml_row_align_strings,
396 					   G_N_ELEMENTS (lsm_mathml_row_align_strings));
397 }
398 
399 static const char *lsm_mathml_column_align_strings[] = {
400 	"center",
401 	"left",
402 	"right"
403 };
404 
405 const char *
lsm_mathml_column_align_to_string(LsmMathmlColumnAlign column_align)406 lsm_mathml_column_align_to_string (LsmMathmlColumnAlign column_align)
407 {
408 	if (column_align < 0 || column_align > LSM_MATHML_COLUMN_ALIGN_RIGHT)
409 		return NULL;
410 
411 	return lsm_mathml_column_align_strings[column_align];
412 }
413 
414 LsmMathmlColumnAlign
lsm_mathml_column_align_from_string(const char * string)415 lsm_mathml_column_align_from_string (const char *string)
416 {
417 	return lsm_enum_value_from_string (string, lsm_mathml_column_align_strings,
418 					   G_N_ELEMENTS (lsm_mathml_column_align_strings));
419 }
420 
421 static const char *lsm_mathml_line_strings[] = {
422 	"none",
423 	"solid",
424 	"dashed"
425 };
426 
427 const char *
lsm_mathml_line_to_string(LsmMathmlLine line)428 lsm_mathml_line_to_string (LsmMathmlLine line)
429 {
430 	if (line < 0 || line > LSM_MATHML_LINE_DASHED)
431 		return NULL;
432 
433 	return lsm_mathml_line_strings [line];
434 }
435 
436 LsmMathmlLine
lsm_mathml_line_from_string(const char * string)437 lsm_mathml_line_from_string (const char *string)
438 {
439 	return lsm_enum_value_from_string (string, lsm_mathml_line_strings,
440 					   G_N_ELEMENTS (lsm_mathml_line_strings));
441 }
442 
443 static const char *lsm_mathml_notation_strings[] = {
444 	"longdiv",
445 	"actuarial",
446 	"radical",
447 	"box",
448 	"roundedbox",
449 	"circle",
450 	"left",
451 	"right",
452 	"top",
453 	"bottom",
454 	"updiagonalstrike",
455 	"downdiagonalstrike",
456 	"verticalstrike",
457 	"horizontalstrike",
458 	"madruwb",
459 	"updiagonalarrow"
460 };
461 
462 const char *
lsm_mathml_notation_to_string(LsmMathmlNotation notation)463 lsm_mathml_notation_to_string (LsmMathmlNotation notation)
464 {
465 	if (notation < 0 || notation > LSM_MATHML_NOTATION_UP_DIAGONAL_ARROW)
466 		return NULL;
467 
468 	return lsm_mathml_notation_strings [notation];
469 }
470 
471 LsmMathmlNotation
lsm_mathml_notation_from_string(const char * string)472 lsm_mathml_notation_from_string	 (const char *string)
473 {
474 	return lsm_enum_value_from_string (string, lsm_mathml_notation_strings,
475 					   G_N_ELEMENTS (lsm_mathml_notation_strings));
476 }
477 
478 static const char *lsm_mathml_linebreak_strings[] = {
479 	"auto",
480 	"newline",
481 	"nobreak",
482 	"goodbreak",
483 	"badbreak"
484 };
485 
486 const char *
lsm_mathml_linebreak_to_string(LsmMathmlLinebreak linebreak)487 lsm_mathml_linebreak_to_string (LsmMathmlLinebreak linebreak)
488 {
489 	if (linebreak < 0 || linebreak > LSM_MATHML_LINEBREAK_BADBREAK)
490 		return NULL;
491 
492 	return lsm_mathml_linebreak_strings[linebreak];
493 }
494 
495 LsmMathmlLinebreak
lsm_mathml_linebreak_from_string(const char * string)496 lsm_mathml_linebreak_from_string (const char *string)
497 {
498 	return lsm_enum_value_from_string (string, lsm_mathml_linebreak_strings,
499 					   G_N_ELEMENTS (lsm_mathml_linebreak_strings));
500 }
501