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,304 @@
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 <lsmmathmldocument.h>
25
+ #include <lsmmathmlsemanticselement.h>
26
+ #include <lsmmathmlphantomelement.h>
27
+ #include <lsmmathmlmathelement.h>
28
+ #include <lsmmathmltableelement.h>
29
+ #include <lsmmathmltablerowelement.h>
30
+ #include <lsmmathmltablecellelement.h>
31
+ #include <lsmmathmlspaceelement.h>
32
+ #include <lsmmathmlradicalelement.h>
33
+ #include <lsmmathmlscriptelement.h>
34
+ #include <lsmmathmlfractionelement.h>
35
+ #include <lsmmathmlunderoverelement.h>
36
+ #include <lsmmathmloperatorelement.h>
37
+ #include <lsmmathmlstringelement.h>
38
+ #include <lsmmathmlrowelement.h>
39
+ #include <lsmmathmlpaddedelement.h>
40
+ #include <lsmmathmlfencedelement.h>
41
+ #include <lsmmathmlerrorelement.h>
42
+ #include <lsmmathmlactionelement.h>
43
+ #include <lsmmathmlstyleelement.h>
44
+ #include <lsmmathmlalignmarkelement.h>
45
+ #include <lsmmathmlaligngroupelement.h>
46
+ #include <lsmmathmlitexelement.h>
47
+ #include <lsmmathmlview.h>
48
+ #include <lsmdebug.h>
49
+ #include <gio/gio.h>
50
+ #include <string.h>
51
+
52
+ #include <lsmdomparser.h>
53
+
54
+ #include "itex2MML.h"
55
+
56
+ /* LsmDomNode implementation */
57
+
58
+ static gboolean
59
+ lsm_mathml_document_can_append_child (LsmDomNode *self, LsmDomNode *child)
60
+ {
61
+ return (LSM_IS_MATHML_MATH_ELEMENT (child));
62
+ }
63
+
64
+ /* LsmDomDocument implementation */
65
+
66
+ static LsmDomElement *
67
+ _create_element (LsmDomDocument *document, const char *tag_name)
68
+ {
69
+ LsmDomNode *node = NULL;
70
+
71
+ if (strcmp (tag_name, "math") == 0)
72
+ node = lsm_mathml_math_element_new ();
73
+ else if (strcmp (tag_name, "mtable") == 0)
74
+ node = lsm_mathml_table_element_new ();
75
+ else if (strcmp (tag_name, "mtr") == 0)
76
+ node = lsm_mathml_table_row_element_new ();
77
+ else if (strcmp (tag_name, "mlabeledtr") == 0)
78
+ node = lsm_mathml_labeled_table_row_element_new ();
79
+ else if (strcmp (tag_name, "mtd") == 0)
80
+ node = lsm_mathml_table_cell_element_new ();
81
+ else if (strcmp (tag_name, "mspace") == 0)
82
+ node = lsm_mathml_space_element_new ();
83
+ else if (strcmp (tag_name, "msqrt") == 0)
84
+ node = lsm_mathml_sqrt_element_new ();
85
+ else if (strcmp (tag_name, "mroot") == 0)
86
+ node = lsm_mathml_root_element_new ();
87
+ else if (strcmp (tag_name, "msub") == 0)
88
+ node = lsm_mathml_sub_element_new ();
89
+ else if (strcmp (tag_name, "msup") == 0)
90
+ node = lsm_mathml_sup_element_new ();
91
+ else if (strcmp (tag_name, "msubsup") == 0)
92
+ node = lsm_mathml_sub_sup_element_new ();
93
+ else if (strcmp (tag_name, "mfrac") == 0)
94
+ node = lsm_mathml_fraction_element_new ();
95
+ else if (strcmp (tag_name, "munder") == 0)
96
+ node = lsm_mathml_under_element_new ();
97
+ else if (strcmp (tag_name, "mover") == 0)
98
+ node = lsm_mathml_over_element_new ();
99
+ else if (strcmp (tag_name, "munderover") == 0)
100
+ node = lsm_mathml_under_over_element_new ();
101
+ else if (strcmp (tag_name, "mo") == 0)
102
+ node = lsm_mathml_operator_element_new ();
103
+ else if (strcmp (tag_name, "mrow") == 0)
104
+ node = lsm_mathml_row_element_new ();
105
+ else if (strcmp (tag_name, "mn") == 0)
106
+ node = lsm_mathml_number_element_new ();
107
+ else if (strcmp (tag_name, "mi") == 0)
108
+ node = lsm_mathml_identifier_element_new ();
109
+ else if (strcmp (tag_name, "mtext") == 0)
110
+ node = lsm_mathml_text_element_new ();
111
+ else if (strcmp (tag_name, "ms") == 0)
112
+ node = lsm_mathml_string_element_new ();
113
+ else if (strcmp (tag_name, "mstyle") == 0)
114
+ node = lsm_mathml_style_element_new ();
115
+ else if (strcmp (tag_name, "mphantom") == 0)
116
+ node = lsm_mathml_phantom_element_new ();
117
+ else if (strcmp (tag_name, "mpadded") == 0)
118
+ node = lsm_mathml_padded_element_new ();
119
+ else if (strcmp (tag_name, "mfenced") == 0)
120
+ node = lsm_mathml_fenced_element_new ();
121
+ else if (strcmp (tag_name, "merror") == 0)
122
+ node = lsm_mathml_error_element_new ();
123
+ else if (strcmp (tag_name, "maction") == 0)
124
+ node = lsm_mathml_action_element_new ();
125
+ else if (strcmp (tag_name, "malignmark") == 0)
126
+ node = lsm_mathml_align_mark_element_new ();
127
+ else if (strcmp (tag_name, "maligngroup") == 0)
128
+ node = lsm_mathml_align_group_element_new ();
129
+ else if (strcmp (tag_name, "semantics") == 0)
130
+ node = lsm_mathml_semantics_element_new ();
131
+ else if (strcmp (tag_name, "lasem:itex") == 0)
132
+ node = lsm_mathml_itex_element_new ();
133
+ else
134
+ lsm_debug_dom ("[MathmlDocument::create_element] Unknown tag (%s)", tag_name);
135
+
136
+ return LSM_DOM_ELEMENT (node);
137
+ }
138
+
139
+ static LsmDomElement *
140
+ lsm_mathml_document_create_element (LsmDomDocument *document, const char *tag_name)
141
+ {
142
+ LsmDomElement *element;
143
+
144
+ element = _create_element (document, tag_name);
145
+ if (element != NULL)
146
+ return element;
147
+
148
+ if (g_str_has_prefix (tag_name, "math:"))
149
+ return _create_element (document, &tag_name[4]);
150
+
151
+ return NULL;
152
+ }
153
+
154
+ static LsmDomView *
155
+ lsm_mathml_document_create_view (LsmDomDocument *document)
156
+ {
157
+ return LSM_DOM_VIEW (lsm_mathml_view_new (LSM_MATHML_DOCUMENT (document)));
158
+ }
159
+
160
+ /* LsmMathmlDocument implementation */
161
+
162
+ LsmDomDocument *
163
+ lsm_mathml_document_new (void)
164
+ {
165
+ return g_object_new (LSM_TYPE_MATHML_DOCUMENT, NULL);
166
+ }
167
+
168
+ static void
169
+ lsm_mathml_document_init (LsmMathmlDocument *document)
170
+ {
171
+ }
172
+
173
+ /* Additional methods */
174
+
175
+ LsmMathmlMathElement *
176
+ lsm_mathml_document_get_root_element (const LsmMathmlDocument *document)
177
+ {
178
+ return LSM_MATHML_MATH_ELEMENT (lsm_dom_document_get_document_element (LSM_DOM_DOCUMENT (document)));
179
+ }
180
+
181
+ /* LsmMathmlDocument class */
182
+
183
+ static void
184
+ lsm_mathml_document_class_init (LsmMathmlDocumentClass *m_document_class)
185
+ {
186
+ LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (m_document_class);
187
+ LsmDomDocumentClass *d_document_class = LSM_DOM_DOCUMENT_CLASS (m_document_class);
188
+
189
+ d_node_class->can_append_child = lsm_mathml_document_can_append_child;
190
+
191
+ d_document_class->create_element = lsm_mathml_document_create_element;
192
+ d_document_class->create_view = lsm_mathml_document_create_view;
193
+ }
194
+
195
+ G_DEFINE_TYPE (LsmMathmlDocument, lsm_mathml_document, LSM_TYPE_DOM_DOCUMENT)
196
+
197
+ static GQuark
198
+ lsm_mathml_document_error_quark (void)
199
+ {
200
+ static GQuark q = 0;
201
+
202
+ if (q == 0) {
203
+ q = g_quark_from_static_string ("lsm-mathml-error-quark");
204
+ }
205
+
206
+ return q;
207
+ }
208
+
209
+ #define LSM_MATHML_DOCUMENT_ERROR lsm_mathml_document_error_quark ()
210
+
211
+ typedef enum {
212
+ LSM_MATHML_DOCUMENT_ERROR_INVALID_ITEX
213
+ } LsmMathmlDocumentError;
214
+
215
+ LsmMathmlDocument *
216
+ lsm_mathml_document_new_from_itex (const char *itex, int size, GError **error)
217
+ {
218
+ LsmDomDocument *document;
219
+ char *mathml;
220
+
221
+ mathml = lsm_itex_to_mathml (itex, size);
222
+
223
+ if (mathml == NULL) {
224
+ lsm_debug_dom ("[LsmMathmlDocument::new_from_itex] Invalid document");
225
+
226
+ g_set_error (error,
227
+ LSM_MATHML_DOCUMENT_ERROR,
228
+ LSM_MATHML_DOCUMENT_ERROR_INVALID_ITEX,
229
+ "Invalid itex document.");
230
+
231
+ return NULL;
232
+ }
233
+
234
+ document = lsm_dom_document_new_from_memory (mathml, -1, error);
235
+
236
+ lsm_itex_free_mathml_buffer (mathml);
237
+
238
+ if (document == NULL)
239
+ return NULL;
240
+
241
+ if (!LSM_IS_MATHML_DOCUMENT (document)) {
242
+ g_object_unref (document);
243
+ return NULL;
244
+ }
245
+
246
+ return LSM_MATHML_DOCUMENT (document);
247
+ }
248
+
249
+ static LsmMathmlDocument *
250
+ lsm_mathml_document_new_from_itex_file (GFile *file, GError **error)
251
+ {
252
+ LsmMathmlDocument *document;
253
+ gsize size = 0;
254
+ char *contents = NULL;
255
+
256
+ if (!g_file_load_contents (file, NULL, &contents, &size, NULL, error))
257
+ return NULL;
258
+
259
+ document = lsm_mathml_document_new_from_itex (contents, size, error);
260
+
261
+ g_free (contents);
262
+
263
+ return document;
264
+ }
265
+
266
+ LsmMathmlDocument *
267
+ lsm_mathml_document_new_from_itex_path (const char *path, GError **error)
268
+ {
269
+ LsmMathmlDocument *document;
270
+ GFile *file;
271
+
272
+ g_return_val_if_fail (path != NULL, NULL);
273
+
274
+ file = g_file_new_for_path (path);
275
+
276
+ document = lsm_mathml_document_new_from_itex_file (file, error);
277
+
278
+ g_object_unref (file);
279
+
280
+ if (document != NULL)
281
+ lsm_dom_document_set_path (LSM_DOM_DOCUMENT (document), path);
282
+
283
+ return document;
284
+ }
285
+
286
+ LsmMathmlDocument *
287
+ lsm_mathml_document_new_from_itex_url (const char *url, GError **error)
288
+ {
289
+ LsmMathmlDocument *document;
290
+ GFile *file;
291
+
292
+ g_return_val_if_fail (url != NULL, NULL);
293
+
294
+ file = g_file_new_for_uri (url);
295
+
296
+ document = lsm_mathml_document_new_from_itex_file (file, error);
297
+
298
+ g_object_unref (file);
299
+
300
+ if (document != NULL)
301
+ lsm_dom_document_set_url (LSM_DOM_DOCUMENT (document), url);
302
+
303
+ return document;
304
+ }
@@ -0,0 +1,61 @@
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_DOCUMENT_H
25
+ #define LSM_MATHML_DOCUMENT_H
26
+
27
+ #include <lsmmathmltypes.h>
28
+ #include <lsmdomdocument.h>
29
+
30
+ G_BEGIN_DECLS
31
+
32
+ #define LSM_TYPE_MATHML_DOCUMENT (lsm_mathml_document_get_type ())
33
+ #define LSM_MATHML_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_MATHML_DOCUMENT, LsmMathmlDocument))
34
+ #define LSM_MATHML_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_MATHML_DOCUMENT, LsmMathmlDocumentClass))
35
+ #define LSM_IS_MATHML_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_MATHML_DOCUMENT))
36
+ #define LSM_IS_MATHML_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_MATHML_DOCUMENT))
37
+ #define LSM_MATHML_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_MATHML_DOCUMENT, LsmMathmlDocumentClass))
38
+
39
+ typedef struct _LsmMathmlDocumentClass LsmMathmlDocumentClass;
40
+
41
+ struct _LsmMathmlDocument {
42
+ LsmDomDocument document;
43
+ };
44
+
45
+ struct _LsmMathmlDocumentClass {
46
+ LsmDomDocumentClass parent_class;
47
+ };
48
+
49
+ GType lsm_mathml_document_get_type (void);
50
+
51
+ LsmDomDocument * lsm_mathml_document_new (void);
52
+ LsmMathmlMathElement * lsm_mathml_document_get_root_element (const LsmMathmlDocument *document);
53
+
54
+ LsmMathmlDocument * lsm_mathml_document_new_from_itex (const char *itex, int size, GError **error);
55
+ LsmMathmlDocument * lsm_mathml_document_new_from_itex_path (const char *url, GError **error);
56
+ LsmMathmlDocument * lsm_mathml_document_new_from_itex_url (const char *url, GError **error);
57
+
58
+ G_END_DECLS
59
+
60
+ #endif
61
+
@@ -0,0 +1,491 @@
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 <lsmmathmlelement.h>
25
+ #include <lsmmathmlspaceelement.h>
26
+ #include <lsmmathmloperatorelement.h>
27
+ #include <lsmmathmlview.h>
28
+ #include <lsmdebug.h>
29
+
30
+ static GObjectClass *parent_class;
31
+
32
+ static const LsmMathmlBbox null_bbox = {0.0,0.0,0.0, FALSE};
33
+
34
+ /* LsmDomNode implementation */
35
+
36
+ static gboolean
37
+ lsm_mathml_element_can_append_child (LsmDomNode *self, LsmDomNode *child)
38
+ {
39
+ return (LSM_IS_MATHML_ELEMENT (child));
40
+ }
41
+
42
+ static void
43
+ lsm_mathml_element_changed (LsmDomNode *self)
44
+ {
45
+ LsmMathmlElement *element = LSM_MATHML_ELEMENT (self);
46
+
47
+ element->need_update = TRUE;
48
+ element->need_measure = TRUE;
49
+ }
50
+
51
+ static gboolean
52
+ lsm_mathml_element_child_changed (LsmDomNode *parent, LsmDomNode *child)
53
+ {
54
+ LsmMathmlElement *element = LSM_MATHML_ELEMENT (parent);
55
+
56
+ if (element->need_children_update)
57
+ return FALSE;
58
+
59
+ element->need_children_update = TRUE;
60
+ element->need_measure = TRUE;
61
+
62
+ return TRUE;
63
+ }
64
+
65
+ /* LsmDomElement implementation */
66
+
67
+ static void
68
+ lsm_mathml_element_set_attribute (LsmDomElement *self, const char* name, const char *value)
69
+ {
70
+ LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_GET_CLASS(self);
71
+
72
+ lsm_attribute_manager_set_attribute (m_element_class->attribute_manager,
73
+ self, name, value);
74
+ }
75
+
76
+ static const char *
77
+ lsm_mathml_element_get_attribute (LsmDomElement *self, const char *name)
78
+ {
79
+ LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_GET_CLASS(self);
80
+
81
+ return lsm_attribute_manager_get_attribute (m_element_class->attribute_manager,
82
+ self, name);
83
+ }
84
+
85
+ static char *
86
+ lsm_mathml_element_get_serialized_attributes (LsmDomElement *self)
87
+ {
88
+ LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_GET_CLASS(self);
89
+
90
+ return lsm_attribute_manager_serialize (m_element_class->attribute_manager, self);
91
+ }
92
+
93
+ /* LsmMathmlElement implementation */
94
+
95
+ static gboolean
96
+ _update_children (LsmMathmlElement *self, LsmMathmlStyle *style)
97
+ {
98
+ LsmDomNode *node;
99
+ gboolean need_measure = FALSE;
100
+
101
+ for (node = LSM_DOM_NODE (self)->first_child; node != NULL; node = node->next_sibling)
102
+ if (LSM_IS_MATHML_ELEMENT (node))
103
+ if (lsm_mathml_element_update (LSM_MATHML_ELEMENT (node), style))
104
+ need_measure = TRUE;
105
+
106
+ return need_measure;
107
+ }
108
+
109
+ /**
110
+ * lsm_mathml_element_update:
111
+ * @self: a #LsmMathmlElement
112
+ * @parent_style: self parent style
113
+ *
114
+ * Update the actual property of an element and it's children. This function parses the element attributes and also make elements inherit style from their parents.
115
+ *
116
+ * Returns: TRUE if the size of the element has changed and needs to be recalculated.
117
+ */
118
+
119
+ gboolean
120
+ lsm_mathml_element_update (LsmMathmlElement *self, const LsmMathmlStyle *parent_style)
121
+ {
122
+ LsmMathmlElementClass *element_class;
123
+ LsmMathmlStyle *style;
124
+ gboolean need_measure;
125
+
126
+ g_return_val_if_fail (LSM_IS_MATHML_ELEMENT (self), FALSE);
127
+ g_return_val_if_fail (parent_style != NULL, FALSE);
128
+
129
+ if (!self->need_update && !self->need_children_update) {
130
+ lsm_debug_update ("[Element::update] %s already up to date",
131
+ lsm_dom_node_get_node_name (LSM_DOM_NODE (self)));
132
+ return FALSE;
133
+ }
134
+
135
+ element_class = LSM_MATHML_ELEMENT_GET_CLASS (self);
136
+
137
+ style = lsm_mathml_style_duplicate (parent_style);
138
+ g_return_val_if_fail (style != NULL, FALSE);
139
+
140
+ if (element_class->update != NULL)
141
+ element_class->update (self, style);
142
+
143
+ lsm_debug_update ("[Element::update] update %s (%s-%g)",
144
+ lsm_dom_node_get_node_name (LSM_DOM_NODE (self)),
145
+ style->math_family != NULL ? style->math_family : "undefined" ,
146
+ style->math_size);
147
+
148
+ g_free (self->style.math_family);
149
+ self->style.math_family = g_strdup (style->math_family);
150
+ self->style.math_variant = style->math_variant;
151
+ self->style.math_size = style->math_size;
152
+ self->style.math_color = style->math_color;
153
+ self->style.math_background = style->math_background;
154
+
155
+ if (self->need_update) {
156
+ LsmDomNode *node;
157
+
158
+ for (node = LSM_DOM_NODE (self)->first_child; node != NULL; node = node->next_sibling)
159
+ if (LSM_IS_MATHML_ELEMENT (node))
160
+ LSM_MATHML_ELEMENT (node)->need_update = TRUE;
161
+ }
162
+
163
+ if (element_class->update_children != NULL)
164
+ need_measure = element_class->update_children (self, style);
165
+ else
166
+ need_measure = FALSE;
167
+
168
+ lsm_mathml_style_free (style);
169
+
170
+ self->need_measure = need_measure || self->need_update;
171
+
172
+ self->need_update = FALSE;
173
+ self->need_children_update = FALSE;
174
+
175
+ return self->need_measure;
176
+ }
177
+
178
+ /* Inferred mrow implementation */
179
+
180
+ static const LsmMathmlBbox *
181
+ _measure (LsmMathmlElement *self, LsmMathmlView *view, const LsmMathmlBbox *bbox)
182
+ {
183
+ const LsmMathmlOperatorElement *operator;
184
+ LsmDomNode *node;
185
+ LsmMathmlBbox child_bbox;
186
+ LsmMathmlBbox stretch_bbox;
187
+ gboolean stretchy_found = FALSE;
188
+ unsigned int n_elements = 0;
189
+
190
+ self->bbox = lsm_mathml_bbox_null;
191
+
192
+ stretch_bbox = *bbox;
193
+
194
+ for (node = LSM_DOM_NODE (self)->first_child; node != NULL; node = node->next_sibling) {
195
+ if (LSM_IS_MATHML_ELEMENT (node)) {
196
+ operator = lsm_mathml_element_get_embellished_core (LSM_MATHML_ELEMENT (node));
197
+ if (operator != NULL && operator->stretchy.value) {
198
+ stretchy_found = TRUE;
199
+ child_bbox = *lsm_mathml_element_measure (LSM_MATHML_ELEMENT (operator), view,
200
+ &lsm_mathml_bbox_null);
201
+ lsm_mathml_bbox_stretch_vertically (&stretch_bbox, &child_bbox);
202
+ } else {
203
+ child_bbox = *lsm_mathml_element_measure (LSM_MATHML_ELEMENT (node), view,
204
+ &lsm_mathml_bbox_null);
205
+ if (operator != NULL)
206
+ child_bbox.width += operator->left_space.value + operator->right_space.value;
207
+ lsm_mathml_bbox_add_horizontally (&self->bbox, &child_bbox);
208
+ lsm_mathml_bbox_stretch_vertically (&stretch_bbox, &child_bbox);
209
+ }
210
+ n_elements++;
211
+ }
212
+ }
213
+
214
+ if (stretchy_found) {
215
+ lsm_debug_measure ("[Element::_measure] Stretchy found (width = %g, height = %g, depth = %g)",
216
+ stretch_bbox.width, stretch_bbox.height, stretch_bbox.depth);
217
+
218
+ for (node = LSM_DOM_NODE (self)->first_child; node != NULL; node = node->next_sibling) {
219
+ if (LSM_IS_MATHML_ELEMENT (node)) {
220
+ operator = lsm_mathml_element_get_embellished_core (LSM_MATHML_ELEMENT (node));
221
+ if (operator != NULL && operator->stretchy.value) {
222
+ child_bbox = *lsm_mathml_element_measure (LSM_MATHML_ELEMENT (node), view,
223
+ &stretch_bbox);
224
+ child_bbox.width += operator->left_space.value + operator->right_space.value;
225
+ lsm_mathml_bbox_add_horizontally (&self->bbox, &child_bbox);
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+ return &self->bbox;
232
+ }
233
+
234
+ const LsmMathmlBbox *
235
+ lsm_mathml_element_measure (LsmMathmlElement *element, LsmMathmlView *view, const LsmMathmlBbox *stretch_bbox)
236
+ {
237
+ LsmMathmlElementClass *element_class;
238
+
239
+ g_return_val_if_fail (LSM_IS_MATHML_ELEMENT (element), &null_bbox);
240
+
241
+ element_class = LSM_MATHML_ELEMENT_GET_CLASS (element);
242
+
243
+ g_return_val_if_fail (element_class != NULL, &null_bbox);
244
+
245
+ if (stretch_bbox == NULL)
246
+ stretch_bbox = &lsm_mathml_bbox_null;
247
+
248
+ if (element->need_measure || stretch_bbox->is_defined) {
249
+ if (element_class->measure) {
250
+ element->bbox = *(element_class->measure (element, view, stretch_bbox));
251
+
252
+ lsm_debug_measure ("[Element::measure] Bbox (%s) %g, %g, %g",
253
+ lsm_dom_node_get_node_name (LSM_DOM_NODE (element)),
254
+ element->bbox.width, element->bbox.height, element->bbox.depth);
255
+ } else {
256
+
257
+ lsm_debug_measure ("[Element::measure] method not defined");
258
+ element->bbox.width = 0.0;
259
+ element->bbox.height = 0.0;
260
+ element->bbox.depth = 0.0;
261
+ }
262
+
263
+ element->need_measure = FALSE;
264
+ element->need_layout = TRUE;
265
+ } else
266
+ lsm_debug_measure ("[Element::measure] %s already up to date",
267
+ lsm_dom_node_get_node_name (LSM_DOM_NODE (element)));
268
+
269
+ return &element->bbox;
270
+ }
271
+
272
+ /* Inferred mrow implementation */
273
+
274
+ static void
275
+ _layout (LsmMathmlElement *self, LsmMathmlView *view,
276
+ double x, double y, const LsmMathmlBbox *bbox)
277
+ {
278
+ const LsmMathmlOperatorElement *operator;
279
+ LsmDomNode *node;
280
+ LsmMathmlBbox child_bbox;
281
+ double offset;
282
+
283
+ for (node = LSM_DOM_NODE (self)->first_child; node != NULL; node = node->next_sibling)
284
+ if (LSM_IS_MATHML_ELEMENT (node)) {
285
+ child_bbox = *lsm_mathml_element_get_bbox (LSM_MATHML_ELEMENT (node));
286
+ operator = lsm_mathml_element_get_embellished_core (LSM_MATHML_ELEMENT (node));
287
+ if (operator != NULL)
288
+ offset = operator->left_space.value;
289
+ else
290
+ offset = 0.0;
291
+ lsm_mathml_element_layout (LSM_MATHML_ELEMENT (node), view, x + offset, y, &child_bbox);
292
+ if (operator != NULL)
293
+ child_bbox.width += offset + operator->right_space.value;
294
+ x += child_bbox.width;
295
+ }
296
+ }
297
+
298
+ void
299
+ lsm_mathml_element_layout (LsmMathmlElement *self, LsmMathmlView *view,
300
+ double x, double y, const LsmMathmlBbox *bbox)
301
+ {
302
+ LsmMathmlElementClass *element_class;
303
+
304
+ g_return_if_fail (LSM_IS_MATHML_ELEMENT (self));
305
+
306
+ element_class = LSM_MATHML_ELEMENT_GET_CLASS (self);
307
+
308
+ g_return_if_fail (element_class != NULL);
309
+
310
+ lsm_debug_measure ("[Element::layout] assigned bbox for %s = %g, %g, %g at %g, %g",
311
+ lsm_dom_node_get_node_name (LSM_DOM_NODE (self)), bbox->width, bbox->height, bbox->depth, x , y);
312
+
313
+ self->x = x;
314
+ self->y = y;
315
+
316
+ if (element_class->layout)
317
+ element_class->layout (self, view, x, y, bbox);
318
+
319
+ self->need_layout = FALSE;
320
+ }
321
+
322
+ /* Inferred mrow implementation */
323
+
324
+ static void
325
+ _render (LsmMathmlElement *element, LsmMathmlView *view)
326
+ {
327
+ LsmDomNode *node;
328
+
329
+ for (node = LSM_DOM_NODE (element)->first_child; node != NULL; node = node->next_sibling)
330
+ if (LSM_IS_MATHML_ELEMENT (node))
331
+ lsm_mathml_element_render (LSM_MATHML_ELEMENT (node), view);
332
+ }
333
+
334
+ void
335
+ lsm_mathml_element_render (LsmMathmlElement *element, LsmMathmlView *view)
336
+ {
337
+ LsmMathmlElementClass *element_class;
338
+
339
+ g_return_if_fail (LSM_IS_MATHML_ELEMENT (element));
340
+ element_class = LSM_MATHML_ELEMENT_GET_CLASS (element);
341
+ g_return_if_fail (element_class != NULL);
342
+
343
+ if (element_class->render) {
344
+ lsm_mathml_view_show_bbox (view, element->x, element->y, &element->bbox);
345
+ lsm_mathml_view_show_background (view, &element->style,
346
+ element->x, element->y,
347
+ &element->bbox);
348
+ element_class->render (element, view);
349
+ }
350
+ }
351
+
352
+ /* Inferred mrow implementation */
353
+
354
+ static LsmMathmlOperatorElement *
355
+ _get_embellished_core (const LsmMathmlElement *self)
356
+ {
357
+ LsmDomNode *node;
358
+ LsmMathmlOperatorElement *core = NULL;
359
+
360
+ g_assert (LSM_IS_MATHML_ELEMENT (self));
361
+
362
+ for (node = LSM_DOM_NODE (self)->first_child; node != NULL; node = node->next_sibling) {
363
+ if (LSM_IS_MATHML_ELEMENT (node)) {
364
+ if (!LSM_IS_MATHML_SPACE_ELEMENT (node)) {
365
+ if (core != NULL)
366
+ return NULL;
367
+ core = lsm_mathml_element_get_embellished_core (LSM_MATHML_ELEMENT (node));
368
+ }
369
+ } else
370
+ if (core != NULL)
371
+ return NULL;
372
+ }
373
+
374
+ return core;
375
+ }
376
+
377
+ LsmMathmlOperatorElement *
378
+ lsm_mathml_element_get_embellished_core (const LsmMathmlElement *self)
379
+ {
380
+ LsmMathmlElementClass *element_class;
381
+
382
+ g_return_val_if_fail (LSM_IS_MATHML_ELEMENT (self), NULL);
383
+
384
+ element_class = LSM_MATHML_ELEMENT_GET_CLASS (self);
385
+
386
+ if (element_class->get_embellished_core != NULL)
387
+ return element_class->get_embellished_core (self);
388
+
389
+ return NULL;
390
+ }
391
+
392
+ const LsmMathmlBbox *
393
+ lsm_mathml_element_get_bbox (const LsmMathmlElement *self)
394
+ {
395
+ g_return_val_if_fail (LSM_IS_MATHML_ELEMENT (self), &lsm_mathml_bbox_null);
396
+
397
+ return &self->bbox;
398
+ }
399
+
400
+ static gboolean
401
+ _is_inferred_row (const LsmMathmlElement *self)
402
+ {
403
+ return TRUE;
404
+ }
405
+
406
+ gboolean
407
+ lsm_mathml_element_is_inferred_row (const LsmMathmlElement *self)
408
+ {
409
+ LsmMathmlElementClass *element_class;
410
+
411
+ g_return_val_if_fail (LSM_IS_MATHML_ELEMENT (self), FALSE);
412
+
413
+ element_class = LSM_MATHML_ELEMENT_GET_CLASS (self);
414
+
415
+ if (element_class->is_inferred_row != NULL)
416
+ return element_class->is_inferred_row (self);
417
+
418
+ return FALSE;
419
+ }
420
+
421
+ static void
422
+ lsm_mathml_element_init (LsmMathmlElement *element)
423
+ {
424
+ element->need_update = TRUE;
425
+ element->need_measure = TRUE;
426
+ }
427
+
428
+ static void
429
+ lsm_mathml_element_finalize (GObject *object)
430
+ {
431
+ LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_GET_CLASS (object);
432
+ LsmMathmlElement *m_element = LSM_MATHML_ELEMENT (object);
433
+
434
+ g_free (m_element->style.math_family);
435
+
436
+ lsm_attribute_manager_clean_attributes (m_element_class->attribute_manager, m_element);
437
+
438
+ parent_class->finalize (object);
439
+ }
440
+
441
+ /* LsmMathmlElement class */
442
+
443
+ static const LsmAttributeInfos lsm_svg_attribute_infos[] = {
444
+ {
445
+ .name = "id",
446
+ .trait_class = &lsm_null_trait_class,
447
+ .attribute_offset = offsetof (LsmMathmlElement, id)
448
+ },
449
+ {
450
+ .name = "class",
451
+ .trait_class = &lsm_null_trait_class,
452
+ .attribute_offset = offsetof (LsmMathmlElement, class_name)
453
+ },
454
+ {
455
+ .name = "href",
456
+ .trait_class = &lsm_null_trait_class,
457
+ .attribute_offset = offsetof (LsmMathmlElement, href)
458
+ }
459
+ };
460
+
461
+ static void
462
+ lsm_mathml_element_class_init (LsmMathmlElementClass *m_element_class)
463
+ {
464
+ GObjectClass *object_class = G_OBJECT_CLASS (m_element_class);
465
+ LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (m_element_class);
466
+ LsmDomElementClass *d_element_class = LSM_DOM_ELEMENT_CLASS (m_element_class);
467
+
468
+ parent_class = g_type_class_peek_parent (m_element_class);
469
+
470
+ object_class->finalize = lsm_mathml_element_finalize;
471
+
472
+ d_node_class->can_append_child = lsm_mathml_element_can_append_child;
473
+ d_node_class->changed = lsm_mathml_element_changed;
474
+ d_node_class->child_changed = lsm_mathml_element_child_changed;
475
+
476
+ d_element_class->get_attribute = lsm_mathml_element_get_attribute;
477
+ d_element_class->set_attribute = lsm_mathml_element_set_attribute;
478
+ d_element_class->get_serialized_attributes = lsm_mathml_element_get_serialized_attributes;
479
+
480
+ m_element_class->update = NULL;
481
+ m_element_class->update_children = _update_children;
482
+ m_element_class->measure = _measure;
483
+ m_element_class->layout = _layout;
484
+ m_element_class->render = _render;
485
+ m_element_class->get_embellished_core = _get_embellished_core;
486
+ m_element_class->is_inferred_row = _is_inferred_row;
487
+ m_element_class->attribute_manager = lsm_attribute_manager_new (G_N_ELEMENTS (lsm_svg_attribute_infos),
488
+ lsm_svg_attribute_infos);
489
+ }
490
+
491
+ G_DEFINE_ABSTRACT_TYPE (LsmMathmlElement, lsm_mathml_element, LSM_TYPE_DOM_ELEMENT)