mathematical 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/ext/mathematical/extconf.rb +14 -0
  3. data/ext/mathematical/itex2MML.h +63 -0
  4. data/ext/mathematical/lasemrender.c +257 -0
  5. data/ext/mathematical/lex.yy.c +6548 -0
  6. data/ext/mathematical/lsm.c +31 -0
  7. data/ext/mathematical/lsm.h +39 -0
  8. data/ext/mathematical/lsmattributes.c +279 -0
  9. data/ext/mathematical/lsmattributes.h +75 -0
  10. data/ext/mathematical/lsmcairo.c +598 -0
  11. data/ext/mathematical/lsmcairo.h +51 -0
  12. data/ext/mathematical/lsmdebug.c +183 -0
  13. data/ext/mathematical/lsmdebug.h +73 -0
  14. data/ext/mathematical/lsmdom.h +43 -0
  15. data/ext/mathematical/lsmdomcharacterdata.c +114 -0
  16. data/ext/mathematical/lsmdomcharacterdata.h +59 -0
  17. data/ext/mathematical/lsmdomdocument.c +255 -0
  18. data/ext/mathematical/lsmdomdocument.h +75 -0
  19. data/ext/mathematical/lsmdomdocumentfragment.c +81 -0
  20. data/ext/mathematical/lsmdomdocumentfragment.h +55 -0
  21. data/ext/mathematical/lsmdomelement.c +148 -0
  22. data/ext/mathematical/lsmdomelement.h +62 -0
  23. data/ext/mathematical/lsmdomentities.c +2166 -0
  24. data/ext/mathematical/lsmdomentities.h +35 -0
  25. data/ext/mathematical/lsmdomenumtypes.c +99 -0
  26. data/ext/mathematical/lsmdomenumtypes.h +26 -0
  27. data/ext/mathematical/lsmdomimplementation.c +82 -0
  28. data/ext/mathematical/lsmdomimplementation.h +41 -0
  29. data/ext/mathematical/lsmdomnamednodemap.c +118 -0
  30. data/ext/mathematical/lsmdomnamednodemap.h +64 -0
  31. data/ext/mathematical/lsmdomnode.c +737 -0
  32. data/ext/mathematical/lsmdomnode.h +122 -0
  33. data/ext/mathematical/lsmdomnodelist.c +70 -0
  34. data/ext/mathematical/lsmdomnodelist.h +58 -0
  35. data/ext/mathematical/lsmdomparser.c +461 -0
  36. data/ext/mathematical/lsmdomparser.h +54 -0
  37. data/ext/mathematical/lsmdomtext.c +82 -0
  38. data/ext/mathematical/lsmdomtext.h +55 -0
  39. data/ext/mathematical/lsmdomtypes.h +44 -0
  40. data/ext/mathematical/lsmdomview.c +422 -0
  41. data/ext/mathematical/lsmdomview.h +94 -0
  42. data/ext/mathematical/lsmitex.c +76 -0
  43. data/ext/mathematical/lsmitex.h +36 -0
  44. data/ext/mathematical/lsmmathml.h +66 -0
  45. data/ext/mathematical/lsmmathmlactionelement.c +93 -0
  46. data/ext/mathematical/lsmmathmlactionelement.h +57 -0
  47. data/ext/mathematical/lsmmathmlaligngroupelement.c +102 -0
  48. data/ext/mathematical/lsmmathmlaligngroupelement.h +56 -0
  49. data/ext/mathematical/lsmmathmlalignmarkelement.c +102 -0
  50. data/ext/mathematical/lsmmathmlalignmarkelement.h +56 -0
  51. data/ext/mathematical/lsmmathmlattributes.c +197 -0
  52. data/ext/mathematical/lsmmathmlattributes.h +126 -0
  53. data/ext/mathematical/lsmmathmldocument.c +304 -0
  54. data/ext/mathematical/lsmmathmldocument.h +61 -0
  55. data/ext/mathematical/lsmmathmlelement.c +491 -0
  56. data/ext/mathematical/lsmmathmlelement.h +107 -0
  57. data/ext/mathematical/lsmmathmlenums.c +429 -0
  58. data/ext/mathematical/lsmmathmlenums.h +182 -0
  59. data/ext/mathematical/lsmmathmlenumtypes.c +666 -0
  60. data/ext/mathematical/lsmmathmlenumtypes.h +90 -0
  61. data/ext/mathematical/lsmmathmlerrorelement.c +58 -0
  62. data/ext/mathematical/lsmmathmlerrorelement.h +56 -0
  63. data/ext/mathematical/lsmmathmlfencedelement.c +178 -0
  64. data/ext/mathematical/lsmmathmlfencedelement.h +65 -0
  65. data/ext/mathematical/lsmmathmlfractionelement.c +253 -0
  66. data/ext/mathematical/lsmmathmlfractionelement.h +62 -0
  67. data/ext/mathematical/lsmmathmlglyphtableams.c +597 -0
  68. data/ext/mathematical/lsmmathmlglyphtableams.h +45 -0
  69. data/ext/mathematical/lsmmathmlitexelement.c +187 -0
  70. data/ext/mathematical/lsmmathmlitexelement.h +60 -0
  71. data/ext/mathematical/lsmmathmllayoututils.c +191 -0
  72. data/ext/mathematical/lsmmathmllayoututils.h +58 -0
  73. data/ext/mathematical/lsmmathmlmathelement.c +204 -0
  74. data/ext/mathematical/lsmmathmlmathelement.h +81 -0
  75. data/ext/mathematical/lsmmathmloperatordictionary.c +3332 -0
  76. data/ext/mathematical/lsmmathmloperatordictionary.h +54 -0
  77. data/ext/mathematical/lsmmathmloperatorelement.c +307 -0
  78. data/ext/mathematical/lsmmathmloperatorelement.h +73 -0
  79. data/ext/mathematical/lsmmathmlpaddedelement.c +58 -0
  80. data/ext/mathematical/lsmmathmlpaddedelement.h +56 -0
  81. data/ext/mathematical/lsmmathmlphantomelement.c +71 -0
  82. data/ext/mathematical/lsmmathmlphantomelement.h +56 -0
  83. data/ext/mathematical/lsmmathmlpresentationcontainer.c +43 -0
  84. data/ext/mathematical/lsmmathmlpresentationcontainer.h +54 -0
  85. data/ext/mathematical/lsmmathmlpresentationtoken.c +303 -0
  86. data/ext/mathematical/lsmmathmlpresentationtoken.h +83 -0
  87. data/ext/mathematical/lsmmathmlradicalelement.c +266 -0
  88. data/ext/mathematical/lsmmathmlradicalelement.h +71 -0
  89. data/ext/mathematical/lsmmathmlrowelement.c +58 -0
  90. data/ext/mathematical/lsmmathmlrowelement.h +56 -0
  91. data/ext/mathematical/lsmmathmlscriptelement.c +282 -0
  92. data/ext/mathematical/lsmmathmlscriptelement.h +78 -0
  93. data/ext/mathematical/lsmmathmlsemanticselement.c +84 -0
  94. data/ext/mathematical/lsmmathmlsemanticselement.h +56 -0
  95. data/ext/mathematical/lsmmathmlspaceelement.c +142 -0
  96. data/ext/mathematical/lsmmathmlspaceelement.h +60 -0
  97. data/ext/mathematical/lsmmathmlstringelement.c +123 -0
  98. data/ext/mathematical/lsmmathmlstringelement.h +58 -0
  99. data/ext/mathematical/lsmmathmlstyle.c +130 -0
  100. data/ext/mathematical/lsmmathmlstyle.h +81 -0
  101. data/ext/mathematical/lsmmathmlstyleelement.c +307 -0
  102. data/ext/mathematical/lsmmathmlstyleelement.h +87 -0
  103. data/ext/mathematical/lsmmathmltablecellelement.c +122 -0
  104. data/ext/mathematical/lsmmathmltablecellelement.h +62 -0
  105. data/ext/mathematical/lsmmathmltableelement.c +545 -0
  106. data/ext/mathematical/lsmmathmltableelement.h +78 -0
  107. data/ext/mathematical/lsmmathmltablerowelement.c +120 -0
  108. data/ext/mathematical/lsmmathmltablerowelement.h +64 -0
  109. data/ext/mathematical/lsmmathmltraits.c +819 -0
  110. data/ext/mathematical/lsmmathmltraits.h +119 -0
  111. data/ext/mathematical/lsmmathmltypes.h +66 -0
  112. data/ext/mathematical/lsmmathmlunderoverelement.c +485 -0
  113. data/ext/mathematical/lsmmathmlunderoverelement.h +82 -0
  114. data/ext/mathematical/lsmmathmlutils.c +170 -0
  115. data/ext/mathematical/lsmmathmlutils.h +50 -0
  116. data/ext/mathematical/lsmmathmlview.c +1048 -0
  117. data/ext/mathematical/lsmmathmlview.h +164 -0
  118. data/ext/mathematical/lsmproperties.c +418 -0
  119. data/ext/mathematical/lsmproperties.h +85 -0
  120. data/ext/mathematical/lsmstr.c +231 -0
  121. data/ext/mathematical/lsmstr.h +114 -0
  122. data/ext/mathematical/lsmsvg.h +67 -0
  123. data/ext/mathematical/lsmsvgaelement.c +73 -0
  124. data/ext/mathematical/lsmsvgaelement.h +55 -0
  125. data/ext/mathematical/lsmsvgattributes.h +118 -0
  126. data/ext/mathematical/lsmsvgcircleelement.c +153 -0
  127. data/ext/mathematical/lsmsvgcircleelement.h +59 -0
  128. data/ext/mathematical/lsmsvgclippathelement.c +134 -0
  129. data/ext/mathematical/lsmsvgclippathelement.h +59 -0
  130. data/ext/mathematical/lsmsvgcolors.c +212 -0
  131. data/ext/mathematical/lsmsvgcolors.h +39 -0
  132. data/ext/mathematical/lsmsvgdefselement.c +74 -0
  133. data/ext/mathematical/lsmsvgdefselement.h +55 -0
  134. data/ext/mathematical/lsmsvgdocument.c +288 -0
  135. data/ext/mathematical/lsmsvgdocument.h +64 -0
  136. data/ext/mathematical/lsmsvgelement.c +373 -0
  137. data/ext/mathematical/lsmsvgelement.h +81 -0
  138. data/ext/mathematical/lsmsvgellipseelement.c +158 -0
  139. data/ext/mathematical/lsmsvgellipseelement.h +60 -0
  140. data/ext/mathematical/lsmsvgenums.c +544 -0
  141. data/ext/mathematical/lsmsvgenums.h +357 -0
  142. data/ext/mathematical/lsmsvgenumtypes.c +1083 -0
  143. data/ext/mathematical/lsmsvgenumtypes.h +111 -0
  144. data/ext/mathematical/lsmsvgfilterblend.c +105 -0
  145. data/ext/mathematical/lsmsvgfilterblend.h +58 -0
  146. data/ext/mathematical/lsmsvgfiltercomposite.c +109 -0
  147. data/ext/mathematical/lsmsvgfiltercomposite.h +58 -0
  148. data/ext/mathematical/lsmsvgfilterelement.c +266 -0
  149. data/ext/mathematical/lsmsvgfilterelement.h +66 -0
  150. data/ext/mathematical/lsmsvgfilterflood.c +86 -0
  151. data/ext/mathematical/lsmsvgfilterflood.h +55 -0
  152. data/ext/mathematical/lsmsvgfiltergaussianblur.c +114 -0
  153. data/ext/mathematical/lsmsvgfiltergaussianblur.h +57 -0
  154. data/ext/mathematical/lsmsvgfiltermerge.c +98 -0
  155. data/ext/mathematical/lsmsvgfiltermerge.h +55 -0
  156. data/ext/mathematical/lsmsvgfiltermergenode.c +87 -0
  157. data/ext/mathematical/lsmsvgfiltermergenode.h +57 -0
  158. data/ext/mathematical/lsmsvgfilteroffset.c +112 -0
  159. data/ext/mathematical/lsmsvgfilteroffset.h +58 -0
  160. data/ext/mathematical/lsmsvgfilterprimitive.c +168 -0
  161. data/ext/mathematical/lsmsvgfilterprimitive.h +66 -0
  162. data/ext/mathematical/lsmsvgfilterspecularlighting.c +127 -0
  163. data/ext/mathematical/lsmsvgfilterspecularlighting.h +60 -0
  164. data/ext/mathematical/lsmsvgfiltersurface.c +455 -0
  165. data/ext/mathematical/lsmsvgfiltersurface.h +66 -0
  166. data/ext/mathematical/lsmsvgfiltertile.c +102 -0
  167. data/ext/mathematical/lsmsvgfiltertile.h +57 -0
  168. data/ext/mathematical/lsmsvggelement.c +73 -0
  169. data/ext/mathematical/lsmsvggelement.h +55 -0
  170. data/ext/mathematical/lsmsvggradientelement.c +151 -0
  171. data/ext/mathematical/lsmsvggradientelement.h +68 -0
  172. data/ext/mathematical/lsmsvgimageelement.c +261 -0
  173. data/ext/mathematical/lsmsvgimageelement.h +67 -0
  174. data/ext/mathematical/lsmsvglength.c +152 -0
  175. data/ext/mathematical/lsmsvglength.h +65 -0
  176. data/ext/mathematical/lsmsvglineargradientelement.c +271 -0
  177. data/ext/mathematical/lsmsvglineargradientelement.h +60 -0
  178. data/ext/mathematical/lsmsvglineelement.c +153 -0
  179. data/ext/mathematical/lsmsvglineelement.h +60 -0
  180. data/ext/mathematical/lsmsvgmarkerelement.c +266 -0
  181. data/ext/mathematical/lsmsvgmarkerelement.h +74 -0
  182. data/ext/mathematical/lsmsvgmaskelement.c +232 -0
  183. data/ext/mathematical/lsmsvgmaskelement.h +64 -0
  184. data/ext/mathematical/lsmsvgmatrix.c +205 -0
  185. data/ext/mathematical/lsmsvgmatrix.h +59 -0
  186. data/ext/mathematical/lsmsvgpathelement.c +115 -0
  187. data/ext/mathematical/lsmsvgpathelement.h +59 -0
  188. data/ext/mathematical/lsmsvgpatternelement.c +398 -0
  189. data/ext/mathematical/lsmsvgpatternelement.h +69 -0
  190. data/ext/mathematical/lsmsvgpolygonelement.c +106 -0
  191. data/ext/mathematical/lsmsvgpolygonelement.h +57 -0
  192. data/ext/mathematical/lsmsvgpolylineelement.c +106 -0
  193. data/ext/mathematical/lsmsvgpolylineelement.h +57 -0
  194. data/ext/mathematical/lsmsvgradialgradientelement.c +323 -0
  195. data/ext/mathematical/lsmsvgradialgradientelement.h +61 -0
  196. data/ext/mathematical/lsmsvgrectelement.c +184 -0
  197. data/ext/mathematical/lsmsvgrectelement.h +62 -0
  198. data/ext/mathematical/lsmsvgstopelement.c +106 -0
  199. data/ext/mathematical/lsmsvgstopelement.h +57 -0
  200. data/ext/mathematical/lsmsvgstyle.c +560 -0
  201. data/ext/mathematical/lsmsvgstyle.h +217 -0
  202. data/ext/mathematical/lsmsvgsvgelement.c +260 -0
  203. data/ext/mathematical/lsmsvgsvgelement.h +71 -0
  204. data/ext/mathematical/lsmsvgswitchelement.c +103 -0
  205. data/ext/mathematical/lsmsvgswitchelement.h +55 -0
  206. data/ext/mathematical/lsmsvgsymbolelement.c +74 -0
  207. data/ext/mathematical/lsmsvgsymbolelement.h +55 -0
  208. data/ext/mathematical/lsmsvgtextelement.c +203 -0
  209. data/ext/mathematical/lsmsvgtextelement.h +60 -0
  210. data/ext/mathematical/lsmsvgtraits.c +1232 -0
  211. data/ext/mathematical/lsmsvgtraits.h +104 -0
  212. data/ext/mathematical/lsmsvgtransformable.c +106 -0
  213. data/ext/mathematical/lsmsvgtransformable.h +54 -0
  214. data/ext/mathematical/lsmsvgtspanelement.c +174 -0
  215. data/ext/mathematical/lsmsvgtspanelement.h +60 -0
  216. data/ext/mathematical/lsmsvgtypes.h +77 -0
  217. data/ext/mathematical/lsmsvguseelement.c +237 -0
  218. data/ext/mathematical/lsmsvguseelement.h +69 -0
  219. data/ext/mathematical/lsmsvgview.c +2583 -0
  220. data/ext/mathematical/lsmsvgview.h +179 -0
  221. data/ext/mathematical/lsmtraits.c +119 -0
  222. data/ext/mathematical/lsmtraits.h +49 -0
  223. data/ext/mathematical/lsmtypes.h +36 -0
  224. data/ext/mathematical/lsmutils.c +54 -0
  225. data/ext/mathematical/lsmutils.h +56 -0
  226. data/ext/mathematical/mathematical.c +145 -0
  227. data/ext/mathematical/y.tab.c +6179 -0
  228. data/ext/mathematical/y.tab.h +389 -0
  229. data/lib/mathematical/version.rb +1 -1
  230. data/mathematical.gemspec +8 -6
  231. data/test/mathematical/basic_test.rb +9 -0
  232. data/test/mathematical/fixtures/after/brackets_display.html +1 -0
  233. data/test/mathematical/fixtures/after/compliance_accents.html +17 -0
  234. data/test/mathematical/fixtures/after/compliance_arrows.html +71 -0
  235. data/test/mathematical/fixtures/after/compliance_colors.html +4 -0
  236. data/test/mathematical/fixtures/after/compliance_greek_letters.html +42 -0
  237. data/test/mathematical/fixtures/after/compliance_large_math.html +19 -0
  238. data/test/mathematical/fixtures/after/compliance_log_symbols.html +34 -0
  239. data/test/mathematical/fixtures/after/compliance_operators.html +262 -0
  240. data/test/mathematical/fixtures/after/dollar_sign_inline.html +1 -0
  241. data/test/mathematical/fixtures/after/equation_display.html +1 -0
  242. data/test/mathematical/fixtures/after/multiple_dollar_inline.html +1 -0
  243. data/test/mathematical/fixtures/after/parens_inline.html +1 -0
  244. data/test/mathematical/fixtures/before/brackets_display.text +1 -0
  245. data/test/mathematical/fixtures/before/compliance_accents.text +17 -0
  246. data/test/mathematical/fixtures/before/compliance_arrows.text +71 -0
  247. data/test/mathematical/fixtures/before/compliance_colors.text +4 -0
  248. data/test/mathematical/fixtures/before/compliance_greek_letters.text +42 -0
  249. data/test/mathematical/fixtures/before/compliance_large_math.text +19 -0
  250. data/test/mathematical/fixtures/before/compliance_log_symbols.text +34 -0
  251. data/test/mathematical/fixtures/before/compliance_operators.text +262 -0
  252. data/test/mathematical/fixtures/before/dollar_sign_inline.text +1 -0
  253. data/test/mathematical/fixtures/before/equation_display.text +1 -0
  254. data/test/mathematical/fixtures/before/multiple_dollar_inline.text +1 -0
  255. data/test/mathematical/fixtures/before/parens_inline.text +1 -0
  256. data/test/mathematical/fixtures/performance/big_file.text +1767 -0
  257. data/test/mathematical/fixtures_test.rb +45 -0
  258. data/test/mathematical/maliciousness_test.rb +45 -0
  259. data/test/mathematical/performance_test.rb +15 -0
  260. data/test/test_helper.rb +5 -0
  261. metadata +301 -14
  262. data/lib/mathematical.bundle +0 -0
  263. data/lib/mathematical/mathematical.bundle +0 -0
@@ -0,0 +1,78 @@
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
+ #ifndef LSM_MATHML_TABLE_ELEMENT_H
25
+ #define LSM_MATHML_TABLE_ELEMENT_H
26
+
27
+ #include <lsmmathmltypes.h>
28
+ #include <lsmmathmlelement.h>
29
+
30
+ G_BEGIN_DECLS
31
+
32
+ #define LSM_TYPE_MATHML_TABLE_ELEMENT (lsm_mathml_table_element_get_type ())
33
+ #define LSM_MATHML_TABLE_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_MATHML_TABLE_ELEMENT, LsmMathmlTableElement))
34
+ #define LSM_MATHML_TABLE_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_MATHML_TABLE_ELEMENT, LsmMathmlTableElementClass))
35
+ #define LSM_IS_MATHML_TABLE_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_MATHML_TABLE_ELEMENT))
36
+ #define LSM_IS_MATHML_TABLE_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_MATHML_TABLE_ELEMENT))
37
+ #define LSM_MATHML_TABLE_ELEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_MATHML_TABLE_ELEMENT, LsmMathmlTableElementClass))
38
+
39
+ typedef struct _LsmMathmlTableElementClass LsmMathmlTableElementClass;
40
+
41
+ struct _LsmMathmlTableElement {
42
+ LsmMathmlElement element;
43
+
44
+ LsmMathmlEnumListAttribute row_align;
45
+ LsmMathmlEnumListAttribute column_align;
46
+ LsmMathmlSpaceListAttribute row_spacing;
47
+ LsmMathmlSpaceListAttribute column_spacing;
48
+ LsmMathmlEnumListAttribute row_lines;
49
+ LsmMathmlEnumListAttribute column_lines;
50
+ LsmMathmlEnumAttribute frame;
51
+ LsmMathmlSpaceListAttribute frame_spacing;
52
+
53
+ LsmMathmlBooleanAttribute equal_rows;
54
+ LsmMathmlBooleanAttribute equal_columns;
55
+ LsmMathmlBooleanAttribute display_style;
56
+
57
+ /* View data */
58
+
59
+ unsigned int n_columns;
60
+ unsigned int n_rows;
61
+ double *widths;
62
+ double *heights;
63
+ double *depths;
64
+ double line_width;
65
+ };
66
+
67
+ struct _LsmMathmlTableElementClass {
68
+ LsmMathmlElementClass parent_class;
69
+ };
70
+
71
+ GType lsm_mathml_table_element_get_type (void);
72
+
73
+ LsmDomNode * lsm_mathml_table_element_new (void);
74
+
75
+ G_END_DECLS
76
+
77
+ #endif
78
+
@@ -0,0 +1,120 @@
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 <lsmmathmltablerowelement.h>
25
+ #include <lsmmathmltablecellelement.h>
26
+
27
+ static GObjectClass *parent_class;
28
+
29
+ /* GdomNode implementation */
30
+
31
+ static const char *
32
+ lsm_mathml_table_row_get_node_name (LsmDomNode *node)
33
+ {
34
+ LsmMathmlTableRowElement *row = LSM_MATHML_TABLE_ROW_ELEMENT (node);
35
+
36
+ switch (row->type) {
37
+ case LSM_MATHML_TABLE_ROW_ELEMENT_TYPE_LABELED_ROW:
38
+ return "mtr";
39
+ break;
40
+ default:
41
+ return "mlabeledtr";
42
+ break;
43
+ }
44
+ }
45
+
46
+ static gboolean
47
+ lsm_mathml_table_row_can_append_child (LsmDomNode *self, LsmDomNode *child)
48
+ {
49
+ return LSM_IS_MATHML_ELEMENT (child);
50
+ }
51
+
52
+ /* LsmMathmlElement implementation */
53
+
54
+ static const LsmMathmlBbox *
55
+ lsm_mathml_table_row_element_measure (LsmMathmlElement *self, LsmMathmlView *view, const LsmMathmlBbox *bbox)
56
+ {
57
+ LSM_MATHML_ELEMENT_CLASS (parent_class)->measure (self, view, bbox);
58
+
59
+ return &self->bbox;
60
+ }
61
+
62
+ static void
63
+ lsm_mathml_table_row_element_layout (LsmMathmlElement *self, LsmMathmlView *view,
64
+ double x, double y, const LsmMathmlBbox *bbox)
65
+ {
66
+ LSM_MATHML_ELEMENT_CLASS (parent_class)->layout (self, view, x, y, bbox);
67
+ }
68
+
69
+ /* LsmMathmlTableRowElement implementation */
70
+
71
+ LsmDomNode *
72
+ lsm_mathml_table_row_element_new (void)
73
+ {
74
+ LsmDomNode *node;
75
+
76
+ node = g_object_new (LSM_TYPE_MATHML_TABLE_ROW_ELEMENT, NULL);
77
+ g_return_val_if_fail (node != NULL, NULL);
78
+
79
+ LSM_MATHML_TABLE_ROW_ELEMENT (node)->type = LSM_MATHML_TABLE_ROW_ELEMENT_TYPE_ROW;
80
+
81
+ return node;
82
+ }
83
+
84
+ LsmDomNode *
85
+ lsm_mathml_labeled_table_row_element_new (void)
86
+ {
87
+ LsmDomNode *node;
88
+
89
+ node = g_object_new (LSM_TYPE_MATHML_TABLE_ROW_ELEMENT, NULL);
90
+ g_return_val_if_fail (node != NULL, NULL);
91
+
92
+ LSM_MATHML_TABLE_ROW_ELEMENT (node)->type = LSM_MATHML_TABLE_ROW_ELEMENT_TYPE_LABELED_ROW;
93
+
94
+ return node;
95
+ }
96
+
97
+ static void
98
+ lsm_mathml_table_row_element_init (LsmMathmlTableRowElement *self)
99
+ {
100
+ }
101
+
102
+ /* LsmMathmlTableRowElement class */
103
+
104
+ static void
105
+ lsm_mathml_table_row_element_class_init (LsmMathmlTableRowElementClass *table_row_class)
106
+ {
107
+ LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (table_row_class);
108
+ LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_CLASS (table_row_class);
109
+
110
+ parent_class = g_type_class_peek_parent (table_row_class);
111
+
112
+ d_node_class->get_node_name = lsm_mathml_table_row_get_node_name;
113
+ d_node_class->can_append_child = lsm_mathml_table_row_can_append_child;
114
+
115
+ m_element_class->measure = lsm_mathml_table_row_element_measure;
116
+ m_element_class->layout = lsm_mathml_table_row_element_layout;
117
+ m_element_class->is_inferred_row = NULL;
118
+ }
119
+
120
+ G_DEFINE_TYPE (LsmMathmlTableRowElement, lsm_mathml_table_row_element, LSM_TYPE_MATHML_ELEMENT)
@@ -0,0 +1,64 @@
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
+ #ifndef LSM_MATHML_TABLE_ROW_ELEMENT_H
25
+ #define LSM_MATHML_TABLE_ROW_ELEMENT_H
26
+
27
+ #include <lsmmathmltypes.h>
28
+ #include <lsmmathmlelement.h>
29
+
30
+ G_BEGIN_DECLS
31
+
32
+ typedef enum {
33
+ LSM_MATHML_TABLE_ROW_ELEMENT_TYPE_ROW,
34
+ LSM_MATHML_TABLE_ROW_ELEMENT_TYPE_LABELED_ROW
35
+ } LsmMathmlTableRowElementType;
36
+
37
+ #define LSM_TYPE_MATHML_TABLE_ROW_ELEMENT (lsm_mathml_table_row_element_get_type ())
38
+ #define LSM_MATHML_TABLE_ROW_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_MATHML_TABLE_ROW_ELEMENT, LsmMathmlTableRowElement))
39
+ #define LSM_MATHML_TABLE_ROW_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_MATHML_TABLE_ROW_ELEMENT, LsmMathmlTableRowElementClass))
40
+ #define LSM_IS_MATHML_TABLE_ROW_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_MATHML_TABLE_ROW_ELEMENT))
41
+ #define LSM_IS_MATHML_TABLE_ROW_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_MATHML_TABLE_ROW_ELEMENT))
42
+ #define LSM_MATHML_TABLE_ROW_ELEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_MATHML_TABLE_ROW_ELEMENT, LsmMathmlTableRowElementClass))
43
+
44
+ typedef struct _LsmMathmlTableRowElementClass LsmMathmlTableRowElementClass;
45
+
46
+ struct _LsmMathmlTableRowElement {
47
+ LsmMathmlElement element;
48
+
49
+ LsmMathmlTableRowElementType type;
50
+ };
51
+
52
+ struct _LsmMathmlTableRowElementClass {
53
+ LsmMathmlElementClass parent_class;
54
+ };
55
+
56
+ GType lsm_mathml_table_row_element_get_type (void);
57
+
58
+ LsmDomNode * lsm_mathml_table_row_element_new (void);
59
+ LsmDomNode * lsm_mathml_labeled_table_row_element_new (void);
60
+
61
+ G_END_DECLS
62
+
63
+ #endif
64
+
@@ -0,0 +1,819 @@
1
+ /* Lasem
2
+ *
3
+ * Copyright © 2009 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 <pango/pango-attributes.h>
25
+ #include <lsmmathmltraits.h>
26
+ #include <math.h>
27
+ #include <string.h>
28
+ #include <stdlib.h>
29
+
30
+ static gboolean
31
+ lsm_mathml_boolean_trait_from_string (LsmTrait *abstract_trait, char *string)
32
+ {
33
+ gboolean *value = (gboolean *) abstract_trait;
34
+
35
+ if (g_strcmp0 (string, "true") == 0) {
36
+ *value = TRUE;
37
+ return TRUE;
38
+ } else if (g_strcmp0 (string, "false") == 0) {
39
+ *value = FALSE;
40
+ return TRUE;
41
+ }
42
+
43
+ *value = FALSE;
44
+ return FALSE;
45
+ }
46
+
47
+ static char *
48
+ lsm_mathml_boolean_trait_to_string (LsmTrait *abstract_trait)
49
+ {
50
+ gboolean *value = (gboolean *) abstract_trait;
51
+
52
+ return g_strdup_printf ("%s", *value ? "true" : "false");
53
+ }
54
+
55
+ const LsmTraitClass lsm_mathml_boolean_trait_class = {
56
+ .size = sizeof (gboolean),
57
+ .from_string = lsm_mathml_boolean_trait_from_string,
58
+ .to_string = lsm_mathml_boolean_trait_to_string
59
+ };
60
+
61
+ static gboolean
62
+ lsm_mathml_unsigned_trait_from_string (LsmTrait *abstract_trait, char *string)
63
+ {
64
+ unsigned int *value = (unsigned int *) abstract_trait;
65
+ char *end_ptr;
66
+
67
+ *value = strtol (string, &end_ptr, 10);
68
+
69
+ return end_ptr != string;
70
+ }
71
+
72
+ static char *
73
+ lsm_mathml_unsigned_trait_to_string (LsmTrait *abstract_trait)
74
+ {
75
+ unsigned int *value = (unsigned int *) abstract_trait;
76
+
77
+ return g_strdup_printf ("%u", *value);
78
+ }
79
+
80
+ const LsmTraitClass lsm_mathml_unsigned_trait_class = {
81
+ .size = sizeof (unsigned),
82
+ .from_string = lsm_mathml_unsigned_trait_from_string,
83
+ .to_string = lsm_mathml_unsigned_trait_to_string
84
+ };
85
+
86
+ static gboolean
87
+ lsm_mathml_display_trait_from_string (LsmTrait *abstract_trait, char *string)
88
+ {
89
+ LsmMathmlDisplay *value = (LsmMathmlDisplay *) abstract_trait;
90
+
91
+ *value = lsm_mathml_display_from_string (string);
92
+
93
+ return *value >= 0;
94
+ }
95
+
96
+ static char *
97
+ lsm_mathml_display_trait_to_string (LsmTrait *abstract_trait)
98
+ {
99
+ LsmMathmlDisplay *value = (LsmMathmlDisplay *) abstract_trait;
100
+
101
+ return g_strdup (lsm_mathml_display_to_string (*value));
102
+ }
103
+
104
+ const LsmTraitClass lsm_mathml_display_trait_class = {
105
+ .size = sizeof (int),
106
+ .from_string = lsm_mathml_display_trait_from_string,
107
+ .to_string = lsm_mathml_display_trait_to_string
108
+ };
109
+
110
+ static gboolean
111
+ lsm_mathml_mode_trait_from_string (LsmTrait *abstract_trait, char *string)
112
+ {
113
+ LsmMathmlMode *value = (LsmMathmlMode *) abstract_trait;
114
+
115
+ *value = lsm_mathml_mode_from_string (string);
116
+
117
+ return *value >= 0;
118
+ }
119
+
120
+ static char *
121
+ lsm_mathml_mode_trait_to_string (LsmTrait *abstract_trait)
122
+ {
123
+ LsmMathmlMode *value = (LsmMathmlMode *) abstract_trait;
124
+
125
+ return g_strdup (lsm_mathml_mode_to_string (*value));
126
+ }
127
+
128
+ const LsmTraitClass lsm_mathml_mode_trait_class = {
129
+ .size = sizeof (int),
130
+ .from_string = lsm_mathml_mode_trait_from_string,
131
+ .to_string = lsm_mathml_mode_trait_to_string
132
+ };
133
+
134
+ static gboolean
135
+ lsm_mathml_line_trait_from_string (LsmTrait *abstract_trait, char *string)
136
+ {
137
+ LsmMathmlLine *value = (LsmMathmlLine *) abstract_trait;
138
+
139
+ *value = lsm_mathml_line_from_string (string);
140
+
141
+ return *value >= 0;
142
+ }
143
+
144
+ static char *
145
+ lsm_mathml_line_trait_to_string (LsmTrait *abstract_trait)
146
+ {
147
+ LsmMathmlLine *value = (LsmMathmlLine *) abstract_trait;
148
+
149
+ return g_strdup (lsm_mathml_line_to_string (*value));
150
+ }
151
+
152
+ const LsmTraitClass lsm_mathml_line_trait_class = {
153
+ .size = sizeof (int),
154
+ .from_string = lsm_mathml_line_trait_from_string,
155
+ .to_string = lsm_mathml_line_trait_to_string
156
+ };
157
+
158
+ static gboolean
159
+ lsm_mathml_font_style_trait_from_string (LsmTrait *abstract_trait, char *string)
160
+ {
161
+ LsmMathmlFontStyle *value = (LsmMathmlFontStyle *) abstract_trait;
162
+
163
+ *value = lsm_mathml_font_style_from_string (string);
164
+
165
+ return *value >= 0;
166
+ }
167
+
168
+ static char *
169
+ lsm_mathml_font_style_trait_to_string (LsmTrait *abstract_trait)
170
+ {
171
+ LsmMathmlFontStyle *value = (LsmMathmlFontStyle *) abstract_trait;
172
+
173
+ return g_strdup (lsm_mathml_font_style_to_string (*value));
174
+ }
175
+
176
+ const LsmTraitClass lsm_mathml_font_style_trait_class = {
177
+ .size = sizeof (int),
178
+ .from_string = lsm_mathml_font_style_trait_from_string,
179
+ .to_string = lsm_mathml_font_style_trait_to_string
180
+ };
181
+
182
+ static gboolean
183
+ lsm_mathml_font_weight_trait_from_string (LsmTrait *abstract_trait, char *string)
184
+ {
185
+ LsmMathmlFontWeight *value = (LsmMathmlFontWeight *) abstract_trait;
186
+
187
+ *value = lsm_mathml_font_weight_from_string (string);
188
+
189
+ return *value >= 0;
190
+ }
191
+
192
+ static char *
193
+ lsm_mathml_font_weight_trait_to_string (LsmTrait *abstract_trait)
194
+ {
195
+ LsmMathmlFontWeight *value = (LsmMathmlFontWeight *) abstract_trait;
196
+
197
+ return g_strdup (lsm_mathml_font_weight_to_string (*value));
198
+ }
199
+
200
+ const LsmTraitClass lsm_mathml_font_weight_trait_class = {
201
+ .size = sizeof (int),
202
+ .from_string = lsm_mathml_font_weight_trait_from_string,
203
+ .to_string = lsm_mathml_font_weight_trait_to_string
204
+ };
205
+
206
+ static gboolean
207
+ lsm_mathml_variant_trait_from_string (LsmTrait *abstract_trait, char *string)
208
+ {
209
+ LsmMathmlVariant *value = (LsmMathmlVariant *) abstract_trait;
210
+
211
+ *value = lsm_mathml_variant_from_string (string);
212
+
213
+ return *value >= 0;
214
+ }
215
+
216
+ static char *
217
+ lsm_mathml_variant_trait_to_string (LsmTrait *abstract_trait)
218
+ {
219
+ LsmMathmlVariant *value = (LsmMathmlVariant *) abstract_trait;
220
+
221
+ return g_strdup (lsm_mathml_variant_to_string (*value));
222
+ }
223
+
224
+ const LsmTraitClass lsm_mathml_variant_trait_class = {
225
+ .size = sizeof (int),
226
+ .from_string = lsm_mathml_variant_trait_from_string,
227
+ .to_string = lsm_mathml_variant_trait_to_string
228
+ };
229
+
230
+ static gboolean
231
+ lsm_mathml_form_trait_from_string (LsmTrait *abstract_trait, char *string)
232
+ {
233
+ LsmMathmlForm *value = (LsmMathmlForm *) abstract_trait;
234
+
235
+ *value = lsm_mathml_form_from_string (string);
236
+
237
+ return *value >= 0;
238
+ }
239
+
240
+ static char *
241
+ lsm_mathml_form_trait_to_string (LsmTrait *abstract_trait)
242
+ {
243
+ LsmMathmlForm *value = (LsmMathmlForm *) abstract_trait;
244
+
245
+ return g_strdup (lsm_mathml_form_to_string (*value));
246
+ }
247
+
248
+ const LsmTraitClass lsm_mathml_form_trait_class = {
249
+ .size = sizeof (int),
250
+ .from_string = lsm_mathml_form_trait_from_string,
251
+ .to_string = lsm_mathml_form_trait_to_string
252
+ };
253
+
254
+ typedef int (*LsmMathmlEnumFromString) (const char *string);
255
+ typedef char * (*LsmMathmlEnumToString) (unsigned int value);
256
+
257
+ static gboolean
258
+ lsm_mathml_enum_list_trait_from_string (LsmMathmlEnumList *enum_list,
259
+ LsmMathmlEnumFromString from_string,
260
+ char *string)
261
+ {
262
+ char **items;
263
+ unsigned int i;
264
+ int enum_value;
265
+
266
+ g_free (enum_list->values);
267
+
268
+ items = g_strsplit_set (string, " ", -1);
269
+ enum_list->n_values = g_strv_length (items);
270
+
271
+ enum_list->values = g_new (int, enum_list->n_values);
272
+ for (i = 0; i < enum_list->n_values; i++) {
273
+ enum_value = from_string (items[i]);
274
+ if (enum_value < 0) {
275
+ g_free (enum_list->values);
276
+ enum_list->values = NULL;
277
+ enum_list->n_values = 0;
278
+ g_strfreev (items);
279
+
280
+ return FALSE;
281
+ }
282
+ enum_list->values[i] = enum_value;
283
+ }
284
+
285
+ g_strfreev (items);
286
+
287
+ return TRUE;
288
+ }
289
+
290
+ static char *
291
+ lsm_mathml_enum_list_trait_to_string (LsmMathmlEnumList *enum_list,
292
+ LsmMathmlEnumToString to_string)
293
+ {
294
+ return g_strdup ("FIXME");
295
+ }
296
+
297
+ static void
298
+ lsm_mathml_enum_list_trait_init (LsmTrait *abstract_trait,
299
+ const LsmTrait *abstract_default)
300
+ {
301
+ LsmMathmlEnumList *enum_list = (LsmMathmlEnumList *) abstract_trait;
302
+ LsmMathmlEnumList *enum_list_defaut = (LsmMathmlEnumList *) abstract_default;
303
+
304
+ enum_list->n_values = enum_list_defaut->n_values;
305
+ if (enum_list->n_values == 0)
306
+ enum_list->values = NULL;
307
+ else {
308
+ enum_list->values = g_new (int, enum_list->n_values);
309
+ memcpy (enum_list->values, enum_list_defaut->values, sizeof (int) * enum_list->n_values);
310
+ }
311
+ }
312
+
313
+ void
314
+ lsm_mathml_enum_list_init (LsmMathmlEnumList *enum_list, const LsmMathmlEnumList *enum_list_default)
315
+ {
316
+ g_return_if_fail (enum_list != NULL);
317
+ g_return_if_fail (enum_list_default != NULL);
318
+
319
+ lsm_mathml_enum_list_trait_init (enum_list, enum_list_default);
320
+ }
321
+
322
+ static void
323
+ lsm_mathml_enum_list_trait_finalize (LsmTrait *abstract_trait)
324
+ {
325
+ LsmMathmlEnumList *enum_list = (LsmMathmlEnumList *) abstract_trait;
326
+
327
+ g_free (enum_list->values);
328
+ enum_list->values = NULL;
329
+ enum_list->n_values = 0;
330
+ }
331
+
332
+ static gboolean
333
+ lsm_mathml_row_align_list_trait_from_string (LsmTrait *abstract_trait,
334
+ char *string)
335
+ {
336
+ return lsm_mathml_enum_list_trait_from_string ((LsmMathmlEnumList *) abstract_trait,
337
+ (LsmMathmlEnumFromString) lsm_mathml_row_align_from_string,
338
+ string);
339
+ }
340
+
341
+ static char *
342
+ lsm_mathml_row_align_list_trait_to_string (LsmTrait *abstract_trait)
343
+ {
344
+ return lsm_mathml_enum_list_trait_to_string ((LsmMathmlEnumList *) abstract_trait,
345
+ (LsmMathmlEnumToString) lsm_mathml_row_align_to_string);
346
+ }
347
+
348
+ const LsmTraitClass lsm_mathml_row_align_list_trait_class = {
349
+ .size = sizeof (LsmMathmlEnumList),
350
+ .from_string = lsm_mathml_row_align_list_trait_from_string,
351
+ .to_string = lsm_mathml_row_align_list_trait_to_string,
352
+ .init = lsm_mathml_enum_list_trait_init,
353
+ .finalize = lsm_mathml_enum_list_trait_finalize
354
+ };
355
+
356
+ static gboolean
357
+ lsm_mathml_column_align_list_trait_from_string (LsmTrait *abstract_trait,
358
+ char *string)
359
+ {
360
+ return lsm_mathml_enum_list_trait_from_string ((LsmMathmlEnumList *) abstract_trait,
361
+ (LsmMathmlEnumFromString) lsm_mathml_column_align_from_string,
362
+ string);
363
+ }
364
+
365
+ static char *
366
+ lsm_mathml_column_align_list_trait_to_string (LsmTrait *abstract_trait)
367
+ {
368
+ return lsm_mathml_enum_list_trait_to_string ((LsmMathmlEnumList *) abstract_trait,
369
+ (LsmMathmlEnumToString) lsm_mathml_column_align_to_string);
370
+ }
371
+
372
+ const LsmTraitClass lsm_mathml_column_align_list_trait_class = {
373
+ .size = sizeof (LsmMathmlEnumList),
374
+ .from_string = lsm_mathml_column_align_list_trait_from_string,
375
+ .to_string = lsm_mathml_column_align_list_trait_to_string,
376
+ .init = lsm_mathml_enum_list_trait_init,
377
+ .finalize = lsm_mathml_enum_list_trait_finalize
378
+ };
379
+
380
+ static gboolean
381
+ lsm_mathml_line_list_trait_from_string (LsmTrait *abstract_trait,
382
+ char *string)
383
+ {
384
+ return lsm_mathml_enum_list_trait_from_string ((LsmMathmlEnumList *) abstract_trait,
385
+ (LsmMathmlEnumFromString) lsm_mathml_line_from_string,
386
+ string);
387
+ }
388
+
389
+ static char *
390
+ lsm_mathml_line_list_trait_to_string (LsmTrait *abstract_trait)
391
+ {
392
+ return lsm_mathml_enum_list_trait_to_string ((LsmMathmlEnumList *) abstract_trait,
393
+ (LsmMathmlEnumToString) lsm_mathml_line_to_string);
394
+ }
395
+
396
+ const LsmTraitClass lsm_mathml_line_list_trait_class = {
397
+ .size = sizeof (LsmMathmlEnumList),
398
+ .from_string = lsm_mathml_line_list_trait_from_string,
399
+ .to_string = lsm_mathml_line_list_trait_to_string,
400
+ .init = lsm_mathml_enum_list_trait_init,
401
+ .finalize = lsm_mathml_enum_list_trait_finalize
402
+ };
403
+
404
+ static gboolean
405
+ lsm_mathml_script_level_trait_from_string (LsmTrait *abstract_trait, char *string)
406
+ {
407
+ LsmMathmlScriptLevel *value = (LsmMathmlScriptLevel *) abstract_trait;
408
+ char *end_ptr;
409
+
410
+ value->level = strtol (string, &end_ptr, 10);
411
+
412
+ if (string[0] == '+')
413
+ value->sign = LSM_MATHML_SCRIPT_LEVEL_SIGN_PLUS;
414
+ else if (string[0] == '-')
415
+ value->sign = LSM_MATHML_SCRIPT_LEVEL_SIGN_MINUS;
416
+ else
417
+ value->sign = LSM_MATHML_SCRIPT_LEVEL_SIGN_NONE;
418
+
419
+ return end_ptr != string;
420
+ }
421
+
422
+ static char *
423
+ lsm_mathml_script_level_trait_to_string (LsmTrait *abstract_trait)
424
+ {
425
+ LsmMathmlScriptLevel *value = (LsmMathmlScriptLevel *) abstract_trait;
426
+
427
+ if (value->sign == LSM_MATHML_SCRIPT_LEVEL_SIGN_PLUS)
428
+ return g_strdup_printf ("+%d", value->level);
429
+
430
+ return g_strdup_printf ("%d", value->level);
431
+ }
432
+
433
+ const LsmTraitClass lsm_mathml_script_level_trait_class = {
434
+ .size = sizeof (int),
435
+ .from_string = lsm_mathml_script_level_trait_from_string,
436
+ .to_string = lsm_mathml_script_level_trait_to_string
437
+ };
438
+
439
+ static gboolean
440
+ lsm_mathml_double_trait_from_string (LsmTrait *abstract_trait, char *string)
441
+ {
442
+ double *value = (double *) abstract_trait;
443
+ char *end_ptr;
444
+
445
+ *value = g_ascii_strtod (string, &end_ptr);
446
+
447
+ return end_ptr != string;
448
+ }
449
+
450
+ static char *
451
+ lsm_mathml_double_trait_to_string (LsmTrait *abstract_trait)
452
+ {
453
+ double *value = (double *) abstract_trait;
454
+
455
+ return g_strdup_printf ("%g", *value);
456
+ }
457
+
458
+ const LsmTraitClass lsm_mathml_double_trait_class = {
459
+ .size = sizeof (double),
460
+ .from_string = lsm_mathml_double_trait_from_string,
461
+ .to_string = lsm_mathml_double_trait_to_string
462
+ };
463
+
464
+ static LsmMathmlColor *
465
+ lsm_mathml_color_copy (LsmMathmlColor *color)
466
+ {
467
+ LsmMathmlColor *copy;
468
+
469
+ copy = g_new (LsmMathmlColor, 1);
470
+ memcpy (copy, color, sizeof (LsmMathmlColor));
471
+
472
+ return copy;
473
+ }
474
+
475
+ GType
476
+ lsm_mathml_color_get_type (void)
477
+ {
478
+ static GType our_type = 0;
479
+ if (our_type == 0)
480
+ our_type = g_boxed_type_register_static
481
+ ("LsmMathmlColor",
482
+ (GBoxedCopyFunc) lsm_mathml_color_copy,
483
+ (GBoxedFreeFunc) g_free);
484
+ return our_type;
485
+ }
486
+
487
+ static gboolean
488
+ lsm_mathml_color_trait_from_string (LsmTrait *abstract_trait, char *string)
489
+ {
490
+ LsmMathmlColor *color = (LsmMathmlColor *) abstract_trait;
491
+ PangoColor pango_color;
492
+ gboolean result;
493
+
494
+ if (strcmp (string, "transparent") == 0) {
495
+ color->red = 0.0;
496
+ color->green = 0.0;
497
+ color->blue = 0.0;
498
+ color->alpha = 0.0;
499
+
500
+ return TRUE;
501
+ }
502
+
503
+ result = pango_color_parse (&pango_color, string);
504
+ color->alpha = 1.0;
505
+ color->red = pango_color.red / 65535.0;
506
+ color->green = pango_color.green / 65535.0;
507
+ color->blue = pango_color.blue / 65535.0;
508
+
509
+ return result;
510
+ }
511
+
512
+ static char *
513
+ lsm_mathml_color_trait_to_string (LsmTrait *abstract_trait)
514
+ {
515
+ LsmMathmlColor *color = (LsmMathmlColor *) abstract_trait;
516
+ PangoColor pango_color;
517
+
518
+ if (color->alpha <= 0.0)
519
+ return g_strdup ("transparent");
520
+
521
+ pango_color.red = ((int) ((double) 0.5 + 65535.0 * color->red));
522
+ pango_color.blue = ((int) ((double) 0.5 + 65535.0 * color->blue));
523
+ pango_color.green = ((int) ((double) 0.5 + 65535.0 * color->green));
524
+
525
+ return pango_color_to_string (&pango_color);
526
+ }
527
+
528
+ const LsmTraitClass lsm_mathml_color_trait_class = {
529
+ .size = sizeof (LsmMathmlColor),
530
+ .from_string = lsm_mathml_color_trait_from_string,
531
+ .to_string = lsm_mathml_color_trait_to_string
532
+ };
533
+
534
+ static gboolean
535
+ lsm_mathml_string_trait_from_string (LsmTrait *abstract_trait, char *string)
536
+ {
537
+ char **value = (char **) abstract_trait;
538
+
539
+ g_free (*value);
540
+ *value = g_strdup (string);
541
+
542
+ return TRUE;
543
+ }
544
+
545
+ static char *
546
+ lsm_mathml_string_trait_to_string (LsmTrait *abstract_trait)
547
+ {
548
+ char **value = (char **) abstract_trait;
549
+
550
+ return g_strdup (*value);
551
+ }
552
+
553
+ static void
554
+ lsm_mathml_string_trait_init (LsmTrait *abstract_trait,
555
+ const LsmTrait *abstract_default)
556
+ {
557
+ char **value = (char **) abstract_trait;
558
+ char **default_value = (char **) abstract_default;
559
+
560
+ *value = g_strdup (*default_value);
561
+ }
562
+
563
+ static void
564
+ lsm_mathml_string_trait_finalize (LsmTrait *abstract_trait)
565
+ {
566
+ char **value = (char **) abstract_trait;
567
+
568
+ g_free (*value);
569
+ *value = NULL;
570
+ }
571
+
572
+ const LsmTraitClass lsm_mathml_string_trait_class = {
573
+ .size = sizeof (char *),
574
+ .from_string = lsm_mathml_string_trait_from_string,
575
+ .to_string = lsm_mathml_string_trait_to_string,
576
+ .init = lsm_mathml_string_trait_init,
577
+ .finalize = lsm_mathml_string_trait_finalize
578
+ };
579
+
580
+ static LsmMathmlLength *
581
+ lsm_mathml_length_copy (LsmMathmlLength *length)
582
+ {
583
+ LsmMathmlLength *copy;
584
+
585
+ copy = g_new (LsmMathmlLength, 1);
586
+ memcpy (copy, length, sizeof (LsmMathmlLength));
587
+
588
+ return copy;
589
+ }
590
+
591
+ GType
592
+ lsm_mathml_length_get_type (void)
593
+ {
594
+ static GType our_type = 0;
595
+
596
+ if (our_type == 0)
597
+ our_type = g_boxed_type_register_static
598
+ ("LsmMathmlLength",
599
+ (GBoxedCopyFunc) lsm_mathml_length_copy,
600
+ (GBoxedFreeFunc) g_free);
601
+ return our_type;
602
+ }
603
+
604
+ static gboolean
605
+ lsm_mathml_length_trait_from_string (LsmTrait *abstract_trait, char *string)
606
+ {
607
+ LsmMathmlLength *length = (LsmMathmlLength *) abstract_trait;
608
+ char *unit_str;
609
+
610
+ length->value = g_ascii_strtod (string, &unit_str);
611
+ length->unit = lsm_mathml_unit_from_string (unit_str);
612
+
613
+ /* TODO Handle "big", "small", normal" sizes */
614
+
615
+ return unit_str != string && length->unit >= 0;
616
+ }
617
+
618
+ static char *
619
+ lsm_mathml_length_trait_to_string (LsmTrait *abstract_trait)
620
+ {
621
+ LsmMathmlLength *length = (LsmMathmlLength *) abstract_trait;
622
+
623
+ return g_strdup_printf ("%g %s", length->value,
624
+ lsm_mathml_unit_to_string (length->unit));
625
+ }
626
+
627
+ const LsmTraitClass lsm_mathml_length_trait_class = {
628
+ .size = sizeof (char *),
629
+ .from_string = lsm_mathml_length_trait_from_string,
630
+ .to_string = lsm_mathml_length_trait_to_string
631
+ };
632
+
633
+ double
634
+ lsm_mathml_length_normalize (const LsmMathmlLength *length,
635
+ double base,
636
+ double font_size)
637
+ {
638
+ double value;
639
+
640
+ g_return_val_if_fail (length != NULL, 0.0);
641
+
642
+ switch (length->unit) {
643
+ case LSM_MATHML_UNIT_PX:
644
+ case LSM_MATHML_UNIT_PT:
645
+ value = length->value;
646
+ break;
647
+ case LSM_MATHML_UNIT_PC:
648
+ value = length->value * 72.0 / 6.0;
649
+ break;
650
+ case LSM_MATHML_UNIT_CM:
651
+ value = length->value * 72.0 / 2.54;
652
+ break;
653
+ case LSM_MATHML_UNIT_MM:
654
+ value = length->value * 72.0 / 25.4;
655
+ break;
656
+ case LSM_MATHML_UNIT_IN:
657
+ value = length->value * 72.0;
658
+ break;
659
+ case LSM_MATHML_UNIT_EM:
660
+ value = length->value * font_size;
661
+ break;
662
+ case LSM_MATHML_UNIT_EX:
663
+ value = length->value * font_size * 0.5;
664
+ break;
665
+ case LSM_MATHML_UNIT_PERCENT:
666
+ value = length->value * base / 100.0;
667
+ break;
668
+ case LSM_MATHML_UNIT_NONE:
669
+ value = length->value * base;
670
+ break;
671
+ default:
672
+ value = 0;
673
+ }
674
+
675
+ return value;
676
+ }
677
+
678
+ static LsmMathmlSpace *
679
+ lsm_mathml_space_copy (LsmMathmlSpace *space)
680
+ {
681
+ LsmMathmlSpace *copy;
682
+
683
+ copy = g_new (LsmMathmlSpace, 1);
684
+ memcpy (copy, space, sizeof (LsmMathmlSpace));
685
+
686
+ return copy;
687
+ }
688
+
689
+ GType
690
+ lsm_mathml_space_get_type (void)
691
+ {
692
+ static GType our_type = 0;
693
+
694
+ if (our_type == 0)
695
+ our_type = g_boxed_type_register_static
696
+ ("LsmMathmlSpace",
697
+ (GBoxedCopyFunc) lsm_mathml_space_copy,
698
+ (GBoxedFreeFunc) g_free);
699
+ return our_type;
700
+ }
701
+
702
+ static gboolean
703
+ lsm_mathml_space_trait_from_string (LsmTrait *abstract_trait, char *string)
704
+ {
705
+ LsmMathmlSpace *space = (LsmMathmlSpace *) abstract_trait;
706
+ char *unit_str;
707
+
708
+ space->name = lsm_mathml_space_name_from_string (string);
709
+
710
+ if (space->name < 0) {
711
+ space->length.value = g_ascii_strtod (string, &unit_str);
712
+ space->length.unit = lsm_mathml_unit_from_string (unit_str);
713
+
714
+ return unit_str != string && space->length.unit >= 0;
715
+ }
716
+
717
+ space->length.value = 0.0;
718
+ space->length.unit = LSM_MATHML_UNIT_PX;
719
+
720
+ return TRUE;
721
+ }
722
+
723
+ static char *
724
+ lsm_mathml_space_trait_to_string (LsmTrait *abstract_trait)
725
+ {
726
+ LsmMathmlSpace *space = (LsmMathmlSpace *) abstract_trait;
727
+ const char *string;
728
+
729
+ string = lsm_mathml_space_name_to_string (space->name);
730
+ if (string != NULL)
731
+ return g_strdup (string);
732
+
733
+ return g_strdup_printf ("%g %s", space->length.value,
734
+ lsm_mathml_unit_to_string (space->length.unit));
735
+ }
736
+
737
+ const LsmTraitClass lsm_mathml_space_trait_class = {
738
+ .size = sizeof (char *),
739
+ .from_string = lsm_mathml_space_trait_from_string,
740
+ .to_string = lsm_mathml_space_trait_to_string
741
+ };
742
+
743
+ static gboolean
744
+ lsm_mathml_space_list_trait_from_string (LsmTrait *abstract_trait, char *string)
745
+ {
746
+ LsmMathmlSpaceList *space_list = (LsmMathmlSpaceList *) abstract_trait;
747
+ char **items;
748
+ unsigned int i;
749
+
750
+ g_free (space_list->spaces);
751
+
752
+ items = g_strsplit_set (string, " ", -1);
753
+ space_list->n_spaces = g_strv_length (items);
754
+
755
+ space_list->spaces = g_new (LsmMathmlSpace, space_list->n_spaces);
756
+ for (i = 0; i < space_list->n_spaces; i++) {
757
+ if (!lsm_mathml_space_trait_from_string (&space_list->spaces[i], items[i])) {
758
+ g_free (space_list->spaces);
759
+ space_list->spaces = NULL;
760
+ space_list->n_spaces = 0;
761
+ g_strfreev (items);
762
+
763
+ return FALSE;
764
+ }
765
+ }
766
+
767
+ g_strfreev (items);
768
+
769
+ return TRUE;
770
+ }
771
+
772
+ static char *
773
+ lsm_mathml_space_list_trait_to_string (LsmTrait *abstract_trait)
774
+ {
775
+ return g_strdup ("FIXME");
776
+ }
777
+
778
+ static void
779
+ lsm_mathml_space_list_trait_init (LsmTrait *abstract_trait,
780
+ const LsmTrait *abstract_default)
781
+ {
782
+ LsmMathmlSpaceList *space_list = (LsmMathmlSpaceList *) abstract_trait;
783
+ LsmMathmlSpaceList *space_list_defaut = (LsmMathmlSpaceList *) abstract_default;
784
+
785
+ space_list->n_spaces = space_list_defaut->n_spaces;
786
+ if (space_list->n_spaces == 0)
787
+ space_list->spaces = NULL;
788
+ else {
789
+ space_list->spaces = g_new (LsmMathmlSpace, space_list->n_spaces);
790
+ memcpy (space_list->spaces, space_list_defaut->spaces, sizeof (LsmMathmlSpace) * space_list->n_spaces);
791
+ }
792
+ }
793
+
794
+ static void
795
+ lsm_mathml_space_list_trait_finalize (LsmTrait *abstract_trait)
796
+ {
797
+ LsmMathmlSpaceList *space_list = (LsmMathmlSpaceList *) abstract_trait;
798
+
799
+ g_free (space_list->spaces);
800
+ space_list->spaces = NULL;
801
+ space_list->n_spaces = 0;
802
+ }
803
+
804
+ void
805
+ lsm_mathml_space_list_init (LsmMathmlSpaceList *space_list, const LsmMathmlSpaceList *space_list_default)
806
+ {
807
+ g_return_if_fail (space_list != NULL);
808
+ g_return_if_fail (space_list_default != NULL);
809
+
810
+ lsm_mathml_space_list_trait_init (space_list, space_list_default);
811
+ }
812
+
813
+ const LsmTraitClass lsm_mathml_space_list_trait_class = {
814
+ .size = sizeof (LsmMathmlSpaceList),
815
+ .from_string = lsm_mathml_space_list_trait_from_string,
816
+ .to_string = lsm_mathml_space_list_trait_to_string,
817
+ .init = lsm_mathml_space_list_trait_init,
818
+ .finalize = lsm_mathml_space_list_trait_finalize
819
+ };