mathematical 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -10
  3. data/Rakefile +42 -3
  4. data/lib/mathematical.rb +5 -4
  5. data/lib/mathematical/mathematical.bundle +0 -0
  6. data/lib/mathematical/render.rb +6 -5
  7. data/lib/mathematical/version.rb +1 -1
  8. data/mathematical.gemspec +5 -5
  9. metadata +14 -296
  10. data/.gitignore +0 -24
  11. data/.gitmodules +0 -0
  12. data/Gemfile +0 -4
  13. data/ext/mathematical/README.itex2MML.md +0 -11
  14. data/ext/mathematical/README.lasem.md +0 -11
  15. data/ext/mathematical/extconf.rb +0 -51
  16. data/ext/mathematical/itex2MML.h +0 -63
  17. data/ext/mathematical/lasemrender.c +0 -257
  18. data/ext/mathematical/lex.yy.c +0 -6548
  19. data/ext/mathematical/lsm.c +0 -30
  20. data/ext/mathematical/lsm.h +0 -36
  21. data/ext/mathematical/lsmattributes.c +0 -279
  22. data/ext/mathematical/lsmattributes.h +0 -75
  23. data/ext/mathematical/lsmcairo.c +0 -598
  24. data/ext/mathematical/lsmcairo.h +0 -51
  25. data/ext/mathematical/lsmdebug.c +0 -179
  26. data/ext/mathematical/lsmdebug.h +0 -76
  27. data/ext/mathematical/lsmdom.h +0 -43
  28. data/ext/mathematical/lsmdomcharacterdata.c +0 -114
  29. data/ext/mathematical/lsmdomcharacterdata.h +0 -59
  30. data/ext/mathematical/lsmdomdocument.c +0 -292
  31. data/ext/mathematical/lsmdomdocument.h +0 -82
  32. data/ext/mathematical/lsmdomdocumentfragment.c +0 -81
  33. data/ext/mathematical/lsmdomdocumentfragment.h +0 -55
  34. data/ext/mathematical/lsmdomelement.c +0 -148
  35. data/ext/mathematical/lsmdomelement.h +0 -62
  36. data/ext/mathematical/lsmdomentities.c +0 -2155
  37. data/ext/mathematical/lsmdomentities.h +0 -35
  38. data/ext/mathematical/lsmdomenumtypes.c +0 -99
  39. data/ext/mathematical/lsmdomenumtypes.c.template +0 -39
  40. data/ext/mathematical/lsmdomenumtypes.h +0 -26
  41. data/ext/mathematical/lsmdomenumtypes.h.template +0 -26
  42. data/ext/mathematical/lsmdomimplementation.c +0 -82
  43. data/ext/mathematical/lsmdomimplementation.h +0 -41
  44. data/ext/mathematical/lsmdomnamednodemap.c +0 -118
  45. data/ext/mathematical/lsmdomnamednodemap.h +0 -64
  46. data/ext/mathematical/lsmdomnode.c +0 -725
  47. data/ext/mathematical/lsmdomnode.h +0 -120
  48. data/ext/mathematical/lsmdomnodelist.c +0 -70
  49. data/ext/mathematical/lsmdomnodelist.h +0 -58
  50. data/ext/mathematical/lsmdomparser.c +0 -461
  51. data/ext/mathematical/lsmdomparser.h +0 -54
  52. data/ext/mathematical/lsmdomtext.c +0 -82
  53. data/ext/mathematical/lsmdomtext.h +0 -55
  54. data/ext/mathematical/lsmdomtypes.h +0 -44
  55. data/ext/mathematical/lsmdomview.c +0 -422
  56. data/ext/mathematical/lsmdomview.h +0 -94
  57. data/ext/mathematical/lsmmathml.h +0 -66
  58. data/ext/mathematical/lsmmathmlactionelement.c +0 -93
  59. data/ext/mathematical/lsmmathmlactionelement.h +0 -57
  60. data/ext/mathematical/lsmmathmlaligngroupelement.c +0 -102
  61. data/ext/mathematical/lsmmathmlaligngroupelement.h +0 -56
  62. data/ext/mathematical/lsmmathmlalignmarkelement.c +0 -102
  63. data/ext/mathematical/lsmmathmlalignmarkelement.h +0 -56
  64. data/ext/mathematical/lsmmathmlattributes.c +0 -197
  65. data/ext/mathematical/lsmmathmlattributes.h +0 -126
  66. data/ext/mathematical/lsmmathmldocument.c +0 -306
  67. data/ext/mathematical/lsmmathmldocument.h +0 -61
  68. data/ext/mathematical/lsmmathmlelement.c +0 -491
  69. data/ext/mathematical/lsmmathmlelement.h +0 -107
  70. data/ext/mathematical/lsmmathmlenums.c +0 -429
  71. data/ext/mathematical/lsmmathmlenums.h +0 -182
  72. data/ext/mathematical/lsmmathmlenumtypes.c +0 -666
  73. data/ext/mathematical/lsmmathmlenumtypes.c.template +0 -39
  74. data/ext/mathematical/lsmmathmlenumtypes.h +0 -90
  75. data/ext/mathematical/lsmmathmlenumtypes.h.template +0 -26
  76. data/ext/mathematical/lsmmathmlerrorelement.c +0 -58
  77. data/ext/mathematical/lsmmathmlerrorelement.h +0 -56
  78. data/ext/mathematical/lsmmathmlfencedelement.c +0 -178
  79. data/ext/mathematical/lsmmathmlfencedelement.h +0 -65
  80. data/ext/mathematical/lsmmathmlfractionelement.c +0 -253
  81. data/ext/mathematical/lsmmathmlfractionelement.h +0 -62
  82. data/ext/mathematical/lsmmathmlglyphtableams.c +0 -597
  83. data/ext/mathematical/lsmmathmlglyphtableams.h +0 -45
  84. data/ext/mathematical/lsmmathmlitexelement.c +0 -187
  85. data/ext/mathematical/lsmmathmlitexelement.h +0 -60
  86. data/ext/mathematical/lsmmathmllayoututils.c +0 -191
  87. data/ext/mathematical/lsmmathmllayoututils.h +0 -58
  88. data/ext/mathematical/lsmmathmlmathelement.c +0 -204
  89. data/ext/mathematical/lsmmathmlmathelement.h +0 -81
  90. data/ext/mathematical/lsmmathmloperatordictionary.c +0 -3332
  91. data/ext/mathematical/lsmmathmloperatordictionary.h +0 -54
  92. data/ext/mathematical/lsmmathmloperatorelement.c +0 -307
  93. data/ext/mathematical/lsmmathmloperatorelement.h +0 -73
  94. data/ext/mathematical/lsmmathmlpaddedelement.c +0 -58
  95. data/ext/mathematical/lsmmathmlpaddedelement.h +0 -56
  96. data/ext/mathematical/lsmmathmlphantomelement.c +0 -71
  97. data/ext/mathematical/lsmmathmlphantomelement.h +0 -56
  98. data/ext/mathematical/lsmmathmlpresentationcontainer.c +0 -43
  99. data/ext/mathematical/lsmmathmlpresentationcontainer.h +0 -54
  100. data/ext/mathematical/lsmmathmlpresentationtoken.c +0 -303
  101. data/ext/mathematical/lsmmathmlpresentationtoken.h +0 -83
  102. data/ext/mathematical/lsmmathmlradicalelement.c +0 -266
  103. data/ext/mathematical/lsmmathmlradicalelement.h +0 -71
  104. data/ext/mathematical/lsmmathmlrowelement.c +0 -58
  105. data/ext/mathematical/lsmmathmlrowelement.h +0 -56
  106. data/ext/mathematical/lsmmathmlscriptelement.c +0 -282
  107. data/ext/mathematical/lsmmathmlscriptelement.h +0 -78
  108. data/ext/mathematical/lsmmathmlsemanticselement.c +0 -82
  109. data/ext/mathematical/lsmmathmlsemanticselement.h +0 -56
  110. data/ext/mathematical/lsmmathmlspaceelement.c +0 -142
  111. data/ext/mathematical/lsmmathmlspaceelement.h +0 -60
  112. data/ext/mathematical/lsmmathmlstringelement.c +0 -123
  113. data/ext/mathematical/lsmmathmlstringelement.h +0 -58
  114. data/ext/mathematical/lsmmathmlstyle.c +0 -130
  115. data/ext/mathematical/lsmmathmlstyle.h +0 -81
  116. data/ext/mathematical/lsmmathmlstyleelement.c +0 -307
  117. data/ext/mathematical/lsmmathmlstyleelement.h +0 -87
  118. data/ext/mathematical/lsmmathmltablecellelement.c +0 -122
  119. data/ext/mathematical/lsmmathmltablecellelement.h +0 -62
  120. data/ext/mathematical/lsmmathmltableelement.c +0 -545
  121. data/ext/mathematical/lsmmathmltableelement.h +0 -78
  122. data/ext/mathematical/lsmmathmltablerowelement.c +0 -120
  123. data/ext/mathematical/lsmmathmltablerowelement.h +0 -64
  124. data/ext/mathematical/lsmmathmltraits.c +0 -819
  125. data/ext/mathematical/lsmmathmltraits.h +0 -119
  126. data/ext/mathematical/lsmmathmltypes.h +0 -66
  127. data/ext/mathematical/lsmmathmlunderoverelement.c +0 -485
  128. data/ext/mathematical/lsmmathmlunderoverelement.h +0 -82
  129. data/ext/mathematical/lsmmathmlutils.c +0 -170
  130. data/ext/mathematical/lsmmathmlutils.h +0 -50
  131. data/ext/mathematical/lsmmathmlview.c +0 -1048
  132. data/ext/mathematical/lsmmathmlview.h +0 -164
  133. data/ext/mathematical/lsmproperties.c +0 -418
  134. data/ext/mathematical/lsmproperties.h +0 -85
  135. data/ext/mathematical/lsmstr.c +0 -231
  136. data/ext/mathematical/lsmstr.h +0 -114
  137. data/ext/mathematical/lsmsvg.h +0 -67
  138. data/ext/mathematical/lsmsvgaelement.c +0 -73
  139. data/ext/mathematical/lsmsvgaelement.h +0 -55
  140. data/ext/mathematical/lsmsvgattributes.h +0 -113
  141. data/ext/mathematical/lsmsvgcircleelement.c +0 -153
  142. data/ext/mathematical/lsmsvgcircleelement.h +0 -59
  143. data/ext/mathematical/lsmsvgclippathelement.c +0 -134
  144. data/ext/mathematical/lsmsvgclippathelement.h +0 -59
  145. data/ext/mathematical/lsmsvgcolors.c +0 -212
  146. data/ext/mathematical/lsmsvgcolors.h +0 -39
  147. data/ext/mathematical/lsmsvgdefselement.c +0 -74
  148. data/ext/mathematical/lsmsvgdefselement.h +0 -55
  149. data/ext/mathematical/lsmsvgdocument.c +0 -230
  150. data/ext/mathematical/lsmsvgdocument.h +0 -58
  151. data/ext/mathematical/lsmsvgelement.c +0 -367
  152. data/ext/mathematical/lsmsvgelement.h +0 -81
  153. data/ext/mathematical/lsmsvgellipseelement.c +0 -158
  154. data/ext/mathematical/lsmsvgellipseelement.h +0 -60
  155. data/ext/mathematical/lsmsvgenums.c +0 -544
  156. data/ext/mathematical/lsmsvgenums.h +0 -357
  157. data/ext/mathematical/lsmsvgenumtypes.c +0 -1083
  158. data/ext/mathematical/lsmsvgenumtypes.c.template +0 -39
  159. data/ext/mathematical/lsmsvgenumtypes.h +0 -111
  160. data/ext/mathematical/lsmsvgenumtypes.h.template +0 -26
  161. data/ext/mathematical/lsmsvgfilterblend.c +0 -105
  162. data/ext/mathematical/lsmsvgfilterblend.h +0 -58
  163. data/ext/mathematical/lsmsvgfiltercomposite.c +0 -109
  164. data/ext/mathematical/lsmsvgfiltercomposite.h +0 -58
  165. data/ext/mathematical/lsmsvgfilterelement.c +0 -266
  166. data/ext/mathematical/lsmsvgfilterelement.h +0 -66
  167. data/ext/mathematical/lsmsvgfilterflood.c +0 -86
  168. data/ext/mathematical/lsmsvgfilterflood.h +0 -55
  169. data/ext/mathematical/lsmsvgfiltergaussianblur.c +0 -114
  170. data/ext/mathematical/lsmsvgfiltergaussianblur.h +0 -57
  171. data/ext/mathematical/lsmsvgfiltermerge.c +0 -98
  172. data/ext/mathematical/lsmsvgfiltermerge.h +0 -55
  173. data/ext/mathematical/lsmsvgfiltermergenode.c +0 -87
  174. data/ext/mathematical/lsmsvgfiltermergenode.h +0 -57
  175. data/ext/mathematical/lsmsvgfilteroffset.c +0 -112
  176. data/ext/mathematical/lsmsvgfilteroffset.h +0 -58
  177. data/ext/mathematical/lsmsvgfilterprimitive.c +0 -168
  178. data/ext/mathematical/lsmsvgfilterprimitive.h +0 -66
  179. data/ext/mathematical/lsmsvgfilterspecularlighting.c +0 -127
  180. data/ext/mathematical/lsmsvgfilterspecularlighting.h +0 -60
  181. data/ext/mathematical/lsmsvgfiltersurface.c +0 -455
  182. data/ext/mathematical/lsmsvgfiltersurface.h +0 -66
  183. data/ext/mathematical/lsmsvgfiltertile.c +0 -102
  184. data/ext/mathematical/lsmsvgfiltertile.h +0 -57
  185. data/ext/mathematical/lsmsvggelement.c +0 -73
  186. data/ext/mathematical/lsmsvggelement.h +0 -55
  187. data/ext/mathematical/lsmsvggradientelement.c +0 -151
  188. data/ext/mathematical/lsmsvggradientelement.h +0 -68
  189. data/ext/mathematical/lsmsvgimageelement.c +0 -261
  190. data/ext/mathematical/lsmsvgimageelement.h +0 -67
  191. data/ext/mathematical/lsmsvglength.c +0 -93
  192. data/ext/mathematical/lsmsvglength.h +0 -59
  193. data/ext/mathematical/lsmsvglineargradientelement.c +0 -271
  194. data/ext/mathematical/lsmsvglineargradientelement.h +0 -60
  195. data/ext/mathematical/lsmsvglineelement.c +0 -153
  196. data/ext/mathematical/lsmsvglineelement.h +0 -60
  197. data/ext/mathematical/lsmsvgmarkerelement.c +0 -266
  198. data/ext/mathematical/lsmsvgmarkerelement.h +0 -74
  199. data/ext/mathematical/lsmsvgmaskelement.c +0 -232
  200. data/ext/mathematical/lsmsvgmaskelement.h +0 -64
  201. data/ext/mathematical/lsmsvgmatrix.c +0 -205
  202. data/ext/mathematical/lsmsvgmatrix.h +0 -59
  203. data/ext/mathematical/lsmsvgpathelement.c +0 -115
  204. data/ext/mathematical/lsmsvgpathelement.h +0 -59
  205. data/ext/mathematical/lsmsvgpatternelement.c +0 -398
  206. data/ext/mathematical/lsmsvgpatternelement.h +0 -69
  207. data/ext/mathematical/lsmsvgpolygonelement.c +0 -106
  208. data/ext/mathematical/lsmsvgpolygonelement.h +0 -57
  209. data/ext/mathematical/lsmsvgpolylineelement.c +0 -106
  210. data/ext/mathematical/lsmsvgpolylineelement.h +0 -57
  211. data/ext/mathematical/lsmsvgradialgradientelement.c +0 -323
  212. data/ext/mathematical/lsmsvgradialgradientelement.h +0 -61
  213. data/ext/mathematical/lsmsvgrectelement.c +0 -184
  214. data/ext/mathematical/lsmsvgrectelement.h +0 -62
  215. data/ext/mathematical/lsmsvgstopelement.c +0 -106
  216. data/ext/mathematical/lsmsvgstopelement.h +0 -57
  217. data/ext/mathematical/lsmsvgstyle.c +0 -558
  218. data/ext/mathematical/lsmsvgstyle.h +0 -217
  219. data/ext/mathematical/lsmsvgsvgelement.c +0 -260
  220. data/ext/mathematical/lsmsvgsvgelement.h +0 -71
  221. data/ext/mathematical/lsmsvgswitchelement.c +0 -103
  222. data/ext/mathematical/lsmsvgswitchelement.h +0 -55
  223. data/ext/mathematical/lsmsvgsymbolelement.c +0 -74
  224. data/ext/mathematical/lsmsvgsymbolelement.h +0 -55
  225. data/ext/mathematical/lsmsvgtextelement.c +0 -170
  226. data/ext/mathematical/lsmsvgtextelement.h +0 -58
  227. data/ext/mathematical/lsmsvgtraits.c +0 -1158
  228. data/ext/mathematical/lsmsvgtraits.h +0 -103
  229. data/ext/mathematical/lsmsvgtransformable.c +0 -106
  230. data/ext/mathematical/lsmsvgtransformable.h +0 -54
  231. data/ext/mathematical/lsmsvgtspanelement.c +0 -143
  232. data/ext/mathematical/lsmsvgtspanelement.h +0 -58
  233. data/ext/mathematical/lsmsvgtypes.h +0 -77
  234. data/ext/mathematical/lsmsvguseelement.c +0 -237
  235. data/ext/mathematical/lsmsvguseelement.h +0 -69
  236. data/ext/mathematical/lsmsvgview.c +0 -2400
  237. data/ext/mathematical/lsmsvgview.h +0 -168
  238. data/ext/mathematical/lsmtraits.c +0 -119
  239. data/ext/mathematical/lsmtraits.h +0 -49
  240. data/ext/mathematical/lsmtypes.h +0 -36
  241. data/ext/mathematical/lsmutils.c +0 -54
  242. data/ext/mathematical/lsmutils.h +0 -56
  243. data/ext/mathematical/mathematical.c +0 -122
  244. data/ext/mathematical/y.tab.c +0 -6179
  245. data/ext/mathematical/y.tab.h +0 -389
  246. data/script/bench +0 -21
  247. data/script/bootstrap +0 -9
  248. data/script/single_test +0 -7
  249. data/test/mathematical/basic_test.rb +0 -38
  250. data/test/mathematical/fixtures/after/brackets_display.html +0 -1
  251. data/test/mathematical/fixtures/after/dollar_sign_inline.html +0 -1
  252. data/test/mathematical/fixtures/after/equation_display.html +0 -1
  253. data/test/mathematical/fixtures/after/multiple_dollar_inline.html +0 -1
  254. data/test/mathematical/fixtures/after/parens_inline.html +0 -1
  255. data/test/mathematical/fixtures/before/brackets_display.text +0 -1
  256. data/test/mathematical/fixtures/before/dollar_sign_inline.text +0 -1
  257. data/test/mathematical/fixtures/before/equation_display.text +0 -1
  258. data/test/mathematical/fixtures/before/multiple_dollar_inline.text +0 -1
  259. data/test/mathematical/fixtures/before/parens_inline.text +0 -1
  260. data/test/mathematical/fixtures/performance/big_file.text +0 -1767
  261. data/test/mathematical/fixtures_test.rb +0 -31
  262. data/test/mathematical/performance_test.rb +0 -13
  263. data/test/test_helper.rb +0 -4
@@ -1,30 +0,0 @@
1
- /* Lasem - SVG and Mathml library
2
- *
3
- * Copyright © 2010 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 <lsmdomimplementation.h>
25
-
26
- void
27
- lsm_shutdown (void)
28
- {
29
- lsm_dom_implementation_cleanup ();
30
- }
@@ -1,36 +0,0 @@
1
- /* Lasem - SVG and Mathml library
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
- #ifndef LSM_H
25
- #define LSM_H
26
-
27
- #include <lsmtypes.h>
28
-
29
- #include <lsmcairo.h>
30
- #include <lsmstr.h>
31
- #include <lsmdebug.h>
32
- #include <lsmtraits.h>
33
- #include <lsmattributes.h>
34
- #include <lsmproperties.h>
35
-
36
- #endif
@@ -1,279 +0,0 @@
1
- /* Lasem
2
- *
3
- * Copyright © 2007-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 <lsmattributes.h>
25
- #include <lsmdebug.h>
26
- #include <string.h>
27
- #include <stdlib.h>
28
- #include <math.h>
29
-
30
- gboolean
31
- lsm_attribute_is_defined (const LsmAttribute *attribute)
32
- {
33
- g_return_val_if_fail (attribute != NULL, FALSE);
34
-
35
- return attribute->value != NULL;
36
- }
37
-
38
- #define ATTRIBUTE_TRAIT(attribute) ((void *) (((void *) attribute) + sizeof (LsmAttribute)))
39
-
40
- struct _LsmAttributeManager {
41
- GHashTable * hash_by_name;
42
-
43
- gint ref_count;
44
- };
45
-
46
- G_DEFINE_BOXED_TYPE (LsmAttributeManager, lsm_attribute_manager, lsm_attribute_manager_ref, lsm_attribute_manager_unref)
47
-
48
- static LsmAttributeManager *
49
- lsm_attribute_manager_create (void)
50
- {
51
- LsmAttributeManager *manager;
52
-
53
- manager = g_new0 (LsmAttributeManager, 1);
54
- manager->hash_by_name = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
55
- manager->ref_count = 1;
56
-
57
- return manager;
58
- }
59
-
60
- LsmAttributeManager *
61
- lsm_attribute_manager_new (unsigned int n_attributes, const LsmAttributeInfos *attribute_infos)
62
- {
63
- LsmAttributeManager *manager;
64
-
65
- manager = lsm_attribute_manager_create ();
66
-
67
- lsm_attribute_manager_add_attributes (manager, n_attributes, attribute_infos);
68
-
69
- return manager;
70
- }
71
-
72
- LsmAttributeManager *
73
- lsm_attribute_manager_duplicate (const LsmAttributeManager *origin)
74
- {
75
- LsmAttributeManager *manager;
76
- GHashTableIter iter;
77
- gpointer key, value;
78
-
79
- g_return_val_if_fail (origin != NULL, NULL);
80
-
81
- manager = lsm_attribute_manager_create ();
82
-
83
- g_hash_table_iter_init (&iter, origin->hash_by_name);
84
- while (g_hash_table_iter_next (&iter, &key, &value))
85
- g_hash_table_insert (manager->hash_by_name, key, value);
86
-
87
- return manager;
88
- }
89
-
90
- void
91
- lsm_attribute_manager_add_attributes (LsmAttributeManager *manager,
92
- unsigned int n_attributes,
93
- const LsmAttributeInfos *attribute_infos)
94
- {
95
- unsigned int i;
96
-
97
- g_return_if_fail (n_attributes > 0);
98
- g_return_if_fail (attribute_infos != NULL);
99
-
100
- for (i = 0; i < n_attributes; i++) {
101
- g_assert (attribute_infos[i].name != NULL);
102
- g_assert (attribute_infos[i].attribute_offset >= 0);
103
- g_assert (attribute_infos[i].trait_class != NULL);
104
-
105
- g_hash_table_insert (manager->hash_by_name,
106
- (void *) attribute_infos[i].name,
107
- (void *) &attribute_infos[i]);
108
- }
109
-
110
- }
111
-
112
- LsmAttributeManager *
113
- lsm_attribute_manager_ref (LsmAttributeManager *manager)
114
- {
115
- g_return_val_if_fail (manager != NULL, NULL);
116
-
117
- g_atomic_int_inc (&manager->ref_count);
118
-
119
- return manager;
120
- }
121
-
122
- void
123
- lsm_attribute_manager_unref (LsmAttributeManager *manager)
124
- {
125
- g_return_if_fail (manager != NULL);
126
-
127
- if (g_atomic_int_dec_and_test (&manager->ref_count)) {
128
- g_hash_table_unref (manager->hash_by_name);
129
- g_free (manager);
130
- }
131
- }
132
-
133
- gboolean
134
- lsm_attribute_manager_set_attribute (LsmAttributeManager *manager,
135
- void *instance,
136
- const char *name,
137
- const char *value)
138
- {
139
- LsmAttribute *attribute;
140
- LsmAttributeInfos *attribute_infos;
141
- const LsmTraitClass *trait_class;
142
-
143
- g_return_val_if_fail (manager != NULL, FALSE);
144
-
145
- attribute_infos = g_hash_table_lookup (manager->hash_by_name, name);
146
- if (attribute_infos == NULL)
147
- return FALSE;
148
-
149
- attribute = (void *)(instance + attribute_infos->attribute_offset);
150
- g_return_val_if_fail (attribute != NULL, FALSE);
151
-
152
- trait_class = attribute_infos->trait_class;
153
-
154
- g_free (attribute->value);
155
- attribute->value = g_strdup (value);
156
-
157
- if (attribute->value != NULL) {
158
- if (trait_class->from_string) {
159
- gboolean success;
160
-
161
- success = trait_class->from_string (ATTRIBUTE_TRAIT (attribute), (char *) value);
162
- if (success)
163
- return TRUE;
164
-
165
- if (trait_class->finalize)
166
- trait_class->finalize (ATTRIBUTE_TRAIT (attribute));
167
- g_free (attribute->value);
168
- attribute->value = NULL;
169
-
170
- lsm_debug_dom ("[LsmAttributeManager::set_attribute] Invalid attribute value %s='%s'",
171
- name, value);
172
- } else
173
- return TRUE;
174
- }
175
-
176
- if (trait_class->init)
177
- trait_class->init (ATTRIBUTE_TRAIT (attribute), attribute_infos->trait_default);
178
- else
179
- /* Simple memcpy for default init implementation, discarded by a NULL default value. */
180
- if (attribute_infos->trait_default != NULL)
181
- memcpy (ATTRIBUTE_TRAIT (attribute),
182
- attribute_infos->trait_default,
183
- trait_class->size);
184
-
185
- return TRUE;
186
- }
187
-
188
- char const *
189
- lsm_attribute_manager_get_attribute (LsmAttributeManager *manager,
190
- void *instance,
191
- const char *name)
192
- {
193
- LsmAttributeInfos *attribute_infos;
194
- LsmAttribute *attribute;
195
-
196
- g_return_val_if_fail (manager != NULL, NULL);
197
-
198
- attribute_infos = g_hash_table_lookup (manager->hash_by_name, name);
199
- if (attribute_infos == NULL)
200
- return NULL;
201
-
202
- attribute = (void *)(instance + attribute_infos->attribute_offset);
203
- g_return_val_if_fail (attribute != NULL, NULL);
204
-
205
- return attribute->value;
206
- }
207
-
208
- void
209
- lsm_attribute_manager_clean_attributes (LsmAttributeManager *manager,
210
- void *instance)
211
- {
212
- LsmAttributeInfos *attribute_infos;
213
- LsmAttribute *attribute;
214
- const LsmTraitClass *trait_class;
215
- GHashTableIter iter;
216
- gpointer key, value;
217
-
218
- g_return_if_fail (manager != NULL);
219
-
220
- g_hash_table_iter_init (&iter, manager->hash_by_name);
221
- while (g_hash_table_iter_next (&iter, &key, &value)) {
222
- attribute_infos = value;
223
- trait_class = attribute_infos->trait_class;
224
-
225
- attribute = (void *)(instance + attribute_infos->attribute_offset);
226
- g_free (attribute->value);
227
- attribute->value = NULL;
228
-
229
- if (trait_class->finalize) {
230
- trait_class->finalize (ATTRIBUTE_TRAIT (attribute));
231
- }
232
- }
233
- }
234
-
235
- char *
236
- lsm_attribute_manager_serialize (LsmAttributeManager *manager,
237
- void *instance)
238
- {
239
- LsmAttributeInfos *attribute_infos;
240
- LsmAttribute *attribute;
241
- GString *string;
242
- GHashTableIter iter;
243
- char *c_string;
244
- gpointer key, value;
245
- gboolean attribute_found = FALSE;
246
-
247
- g_return_val_if_fail (manager != NULL, NULL);
248
-
249
- string = g_string_new ("");
250
-
251
- g_hash_table_iter_init (&iter, manager->hash_by_name);
252
- while (g_hash_table_iter_next (&iter, &key, &value)) {
253
- attribute_infos = value;
254
- attribute = (void *)(instance + attribute_infos->attribute_offset);
255
-
256
- if (attribute->value != NULL) {
257
- if (!attribute_found) {
258
- g_string_append_printf (string, "%s=\"%s\"",
259
- attribute_infos->name,
260
- attribute->value);
261
- attribute_found = TRUE;
262
- } else {
263
- g_string_append_printf (string, " %s=\"%s\"",
264
- attribute_infos->name,
265
- attribute->value);
266
- }
267
- }
268
- }
269
-
270
- if (!attribute_found) {
271
- g_string_free (string, TRUE);
272
- return NULL;
273
- }
274
-
275
- c_string = string->str;
276
- g_string_free (string, FALSE);
277
-
278
- return c_string;
279
- }
@@ -1,75 +0,0 @@
1
- /* Lasem
2
- *
3
- * Copyright © 2007-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
- #ifndef LSM_ATTRIBUTES_H
25
- #define LSM_ATTRIBUTES_H
26
-
27
- #include <lsmtypes.h>
28
- #include <lsmtraits.h>
29
-
30
- G_BEGIN_DECLS
31
-
32
- typedef struct {
33
- char *value;
34
- } LsmAttribute;
35
-
36
- gboolean lsm_attribute_is_defined (const LsmAttribute *attribute);
37
-
38
- typedef struct {
39
- char const * name;
40
- int attribute_offset;
41
- const LsmTraitClass * trait_class;
42
- const void * trait_default;
43
- } LsmAttributeInfos;
44
-
45
- typedef struct _LsmAttributeManager LsmAttributeManager;
46
-
47
- #define LSM_TYPE_ATTRIBUTE_MANAGER (lsm_attribute_manager_get_type())
48
-
49
- GType lsm_attribute_manager_get_type (void);
50
-
51
- LsmAttributeManager * lsm_attribute_manager_new (unsigned int n_attributes,
52
- const LsmAttributeInfos *attribute_infos);
53
- LsmAttributeManager * lsm_attribute_manager_duplicate (const LsmAttributeManager *origin);
54
- LsmAttributeManager * lsm_attribute_manager_ref (LsmAttributeManager *manager);
55
- void lsm_attribute_manager_unref (LsmAttributeManager *manager);
56
-
57
- void lsm_attribute_manager_add_attributes (LsmAttributeManager *manager,
58
- unsigned int n_attributes,
59
- const LsmAttributeInfos *attribute_infos);
60
-
61
- gboolean lsm_attribute_manager_set_attribute (LsmAttributeManager *manager,
62
- void *instance,
63
- char const *name,
64
- char const *value);
65
- char const * lsm_attribute_manager_get_attribute (LsmAttributeManager *manager,
66
- void *instance,
67
- char const *name);
68
- void lsm_attribute_manager_clean_attributes (LsmAttributeManager *manager,
69
- void *instance);
70
- char * lsm_attribute_manager_serialize (LsmAttributeManager *manager,
71
- void *instance);
72
-
73
- G_END_DECLS
74
-
75
- #endif
@@ -1,598 +0,0 @@
1
- /* Lasem
2
- *
3
- * Copyright © 2004 Caleb Moore
4
- * Copyright © 2012 Emmanuel Pacaud
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General
17
- * Public License along with this library; if not, write to the
18
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19
- * Boston, MA 02111-1307, USA.
20
- *
21
- * Authors:
22
- * Caleb Moore <c.moore@student.unsw.edu.au>
23
- * Emmanuel Pacaud <emmanuel@gnome.org>
24
- */
25
-
26
- #include <lsmcairo.h>
27
- #include <lsmsvgenums.h>
28
- #include <lsmutils.h>
29
- #include <lsmstr.h>
30
- #include <math.h>
31
- #include <string.h>
32
-
33
- typedef struct {
34
- cairo_t *cr;
35
- char *ptr;
36
- char last_command;
37
- double last_cp_x;
38
- double last_cp_y;
39
- double values[7];
40
- } LsmSvgPathContext;
41
-
42
- /*
43
- * Code for:
44
- *
45
- * _calc_angle
46
- * _cairo_elliptical_arc
47
- * _cairo_quadratic_curve_to
48
- * _emit_smooth_curve
49
- * _emit_smooth_quadratic_curve
50
- *
51
- * is adapted from the goocanvas library (goocanvasutils.c)
52
- *
53
- * GooCanvas. Copyright (C) 2005 Damon Chaplin.
54
- */
55
-
56
- void
57
- lsm_cairo_quadratic_curve_to (cairo_t *cr, double x1, double y1, double x, double y)
58
- {
59
- double x0, y0, xx1, yy1, xx2, yy2;
60
-
61
- cairo_get_current_point (cr, &x0, &y0);
62
-
63
- /* We need to convert the quadratic into a cubic bezier. */
64
-
65
- xx1 = x0 + (x1 - x0) * 2.0 / 3.0;
66
- yy1 = y0 + (y1 - y0) * 2.0 / 3.0;
67
-
68
- xx2 = xx1 + (x - x0) / 3.0;
69
- yy2 = yy1 + (y - y0) / 3.0;
70
-
71
- cairo_curve_to (cr, xx1, yy1, xx2, yy2, x, y);
72
- }
73
-
74
- void
75
- lsm_cairo_rel_quadratic_curve_to (cairo_t *cr, double dx1, double dy1, double dx, double dy)
76
- {
77
- double x0, y0;
78
-
79
- cairo_get_current_point (cr, &x0, &y0);
80
- lsm_cairo_quadratic_curve_to (cr, x0 + dx1, y0 + dy1, x0 + dx, y0 + dy);
81
- }
82
-
83
- static double
84
- _calc_angle (double ux, double uy, double vx, double vy)
85
- {
86
- double top, u_magnitude, v_magnitude, angle_cos, angle;
87
-
88
- top = ux * vx + uy * vy;
89
- u_magnitude = sqrt (ux * ux + uy * uy);
90
- v_magnitude = sqrt (vx * vx + vy * vy);
91
- angle_cos = top / (u_magnitude * v_magnitude);
92
-
93
- /* We check if the cosine is slightly out-of-bounds. */
94
- if (angle_cos >= 1.0)
95
- angle = 0.0;
96
- if (angle_cos <= -1.0)
97
- angle = M_PI;
98
- else
99
- angle = acos (angle_cos);
100
-
101
- if (ux * vy - uy * vx < 0)
102
- angle = - angle;
103
-
104
- return angle;
105
- }
106
-
107
- void
108
- lsm_cairo_elliptical_arc (cairo_t *cairo, double rx, double ry, double x_axis_rotation,
109
- gboolean large_arc_flag, gboolean sweep_flag, double x, double y)
110
- {
111
- double x1, y1, x2, y2, lambda;
112
- double v1, v2, angle, angle_sin, angle_cos, x11, y11;
113
- double rx_squared, ry_squared, x11_squared, y11_squared, top, bottom;
114
- double c, cx1, cy1, cx, cy, start_angle, angle_delta;
115
-
116
- cairo_get_current_point (cairo, &x1, &y1);
117
-
118
- x2 = x;
119
- y2 = y;
120
-
121
- /* If the endpoints are exactly the same, just return (see SVG spec). */
122
- if (x1 == x2 && y1 == y2)
123
- return;
124
-
125
- /* If either rx or ry is 0, do a simple lineto (see SVG spec). */
126
- if (rx == 0.0 || ry == 0.0)
127
- {
128
- cairo_line_to (cairo, x2, y2);
129
- return;
130
- }
131
-
132
- /* Calculate x1' and y1' (as per SVG implementation notes). */
133
- v1 = (x1 - x2) / 2.0;
134
- v2 = (y1 - y2) / 2.0;
135
-
136
- angle = x_axis_rotation * (M_PI / 180.0);
137
- angle_sin = sin (angle);
138
- angle_cos = cos (angle);
139
-
140
- x11 = (angle_cos * v1) + (angle_sin * v2);
141
- y11 = - (angle_sin * v1) + (angle_cos * v2);
142
-
143
- /* Ensure rx and ry are positive and large enough. */
144
- rx = rx > 0.0 ? rx : - rx;
145
- ry = ry > 0.0 ? ry : - ry;
146
- lambda = (x11 * x11) / (rx * rx) + (y11 * y11) / (ry * ry);
147
- if (lambda > 1.0)
148
- {
149
- gdouble square_root = sqrt (lambda);
150
- rx *= square_root;
151
- ry *= square_root;
152
- }
153
-
154
- /* Calculate cx' and cy'. */
155
- rx_squared = rx * rx;
156
- ry_squared = ry * ry;
157
- x11_squared = x11 * x11;
158
- y11_squared = y11 * y11;
159
-
160
- top = (rx_squared * ry_squared) - (rx_squared * y11_squared)
161
- - (ry_squared * x11_squared);
162
- if (top < 0.0)
163
- {
164
- c = 0.0;
165
- }
166
- else
167
- {
168
- bottom = (rx_squared * y11_squared) + (ry_squared * x11_squared);
169
- c = sqrt (top / bottom);
170
- }
171
-
172
- if (large_arc_flag == sweep_flag)
173
- c = - c;
174
-
175
- cx1 = c * ((rx * y11) / ry);
176
- cy1 = c * (- (ry * x11) / rx);
177
-
178
- /* Calculate cx and cy. */
179
- cx = (angle_cos * cx1) - (angle_sin * cy1) + (x1 + x2) / 2;
180
- cy = (angle_sin * cx1) + (angle_cos * cy1) + (y1 + y2) / 2;
181
-
182
- /* Calculate the start and end angles. */
183
- v1 = (x11 - cx1) / rx;
184
- v2 = (y11 - cy1) / ry;
185
-
186
- start_angle = _calc_angle (1, 0, v1, v2);
187
- angle_delta = _calc_angle (v1, v2, (-x11 - cx1) / rx, (-y11 - cy1) / ry);
188
-
189
- if (sweep_flag == 0 && angle_delta > 0.0)
190
- angle_delta -= 2 * M_PI;
191
- else if (sweep_flag == 1 && angle_delta < 0.0)
192
- angle_delta += 2 * M_PI;
193
-
194
- /* Now draw the arc. */
195
- cairo_save (cairo);
196
- cairo_translate (cairo, cx, cy);
197
- cairo_rotate (cairo, angle);
198
- cairo_scale (cairo, rx, ry);
199
-
200
- if (angle_delta > 0.0)
201
- cairo_arc (cairo, 0.0, 0.0, 1.0,
202
- start_angle, start_angle + angle_delta);
203
- else
204
- cairo_arc_negative (cairo, 0.0, 0.0, 1.0,
205
- start_angle, start_angle + angle_delta);
206
-
207
- cairo_restore (cairo);
208
- }
209
-
210
- void
211
- lsm_cairo_rel_elliptical_arc (cairo_t *cairo, double rx, double ry, double x_axis_rotation,
212
- gboolean large_arc_flag, gboolean sweep_flag, double dx, double dy)
213
- {
214
- double x, y;
215
-
216
- cairo_get_current_point (cairo, &x, &y);
217
-
218
- lsm_cairo_elliptical_arc (cairo, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x +dx ,y + dy);
219
- }
220
-
221
- void
222
- lsm_cairo_vertical (cairo_t *cairo, double y)
223
- {
224
- double x0, y0;
225
-
226
- cairo_get_current_point (cairo, &x0, &y0);
227
- cairo_line_to (cairo, x0, y);
228
- }
229
-
230
- void
231
- lsm_cairo_rel_vertical (cairo_t *cairo, double dy)
232
- {
233
- double x0, y0;
234
-
235
- cairo_get_current_point (cairo, &x0, &y0);
236
- cairo_line_to (cairo, x0, y0 + dy);
237
- }
238
-
239
- void
240
- lsm_cairo_horizontal (cairo_t *cairo, double x)
241
- {
242
- double x0, y0;
243
-
244
- cairo_get_current_point (cairo, &x0, &y0);
245
- cairo_line_to (cairo, x, y0);
246
- }
247
-
248
- void
249
- lsm_cairo_rel_horizontal (cairo_t *cairo, double dx)
250
- {
251
- double x0, y0;
252
-
253
- cairo_get_current_point (cairo, &x0, &y0);
254
- cairo_line_to (cairo, x0 + dx, y0);
255
- }
256
-
257
- static void
258
- _emit_function_1 (LsmSvgPathContext *ctxt,
259
- void (*cairo_func) (cairo_t *, double))
260
- {
261
- while (lsm_str_parse_double_list (&ctxt->ptr, 1, ctxt->values) == 1)
262
- cairo_func (ctxt->cr, ctxt->values[0]);
263
- }
264
-
265
- static void
266
- _emit_function_2 (LsmSvgPathContext *ctxt,
267
- void (*cairo_func_a) (cairo_t *, double, double),
268
- void (*cairo_func_b) (cairo_t *, double, double))
269
- {
270
-
271
- if (lsm_str_parse_double_list (&ctxt->ptr, 2, ctxt->values) == 2) {
272
- cairo_func_a (ctxt->cr, ctxt->values[0], ctxt->values[1]);
273
-
274
- /* Why oh why does the specification say Line is implied here ? */
275
-
276
- while (lsm_str_parse_double_list (&ctxt->ptr, 2, ctxt->values) == 2)
277
- cairo_func_b (ctxt->cr, ctxt->values[0], ctxt->values[1]);
278
- }
279
- }
280
-
281
- static void
282
- _emit_function_4 (LsmSvgPathContext *ctxt,
283
- void (*cairo_func) (cairo_t *, double, double, double, double))
284
- {
285
- while (lsm_str_parse_double_list (&ctxt->ptr, 4, ctxt->values) == 4)
286
- cairo_func (ctxt->cr, ctxt->values[0], ctxt->values[1], ctxt->values[2], ctxt->values[3]);
287
- }
288
-
289
- static void
290
- _emit_smooth_curve (LsmSvgPathContext *ctxt, gboolean relative)
291
- {
292
- double x, y;
293
- double x0, y0;
294
-
295
- cairo_get_current_point (ctxt->cr, &x0, &y0);
296
-
297
- switch (ctxt->last_command) {
298
- case 'C':
299
- x = 2 * x0 - ctxt->values[2];
300
- y = 2 * y0 - ctxt->values[3];
301
- break;
302
- case 'c':
303
- x = 2 * x0 - (ctxt->values[2] + x0 - ctxt->values[4]);
304
- y = 2 * y0 - (ctxt->values[3] + y0 - ctxt->values[5]);
305
- break;
306
- case 'S':
307
- x = 2 * x0 - ctxt->values[0];
308
- y = 2 * y0 - ctxt->values[1];
309
- break;
310
- case 's':
311
- x = 2 * x0 - (ctxt->values[0] + x0 - ctxt->values[2]);
312
- y = 2 * y0 - (ctxt->values[1] + y0 - ctxt->values[3]);
313
- break;
314
- default: x = x0; y = y0; break;
315
- }
316
-
317
- while (lsm_str_parse_double_list (&ctxt->ptr, 4, ctxt->values) == 4) {
318
- if (relative) {
319
- cairo_get_current_point (ctxt->cr, &x0, &y0);
320
- cairo_curve_to (ctxt->cr,
321
- x, y,
322
- x0 + ctxt->values[0], y0 + ctxt->values[1],
323
- x0 + ctxt->values[2], y0 + ctxt->values[3]);
324
- x = 2 * (x0 + ctxt->values[2]) - (x0 + ctxt->values[0]);
325
- y = 2 * (y0 + ctxt->values[3]) - (y0 + ctxt->values[1]);
326
- } else {
327
- cairo_curve_to (ctxt->cr, x, y,
328
- ctxt->values[0], ctxt->values[1], ctxt->values[2], ctxt->values[3]);
329
- x = 2 * ctxt->values[2] - ctxt->values[0];
330
- y = 2 * ctxt->values[3] - ctxt->values[1];
331
- }
332
- }
333
- }
334
-
335
- static void
336
- _emit_smooth_quadratic_curve (LsmSvgPathContext *ctxt, gboolean relative)
337
- {
338
- double x, y;
339
- double x0, y0;
340
-
341
- cairo_get_current_point (ctxt->cr, &x0, &y0);
342
-
343
- switch (ctxt->last_command) {
344
- case 'Q':
345
- ctxt->last_cp_x = ctxt->values[0];
346
- ctxt->last_cp_y = ctxt->values[1];
347
- break;
348
- case 'q':
349
- ctxt->last_cp_x = ctxt->values[0] + x0 - ctxt->values[2];
350
- ctxt->last_cp_y = ctxt->values[1] + y0 - ctxt->values[3];
351
- break;
352
- case 'T':
353
- case 't':
354
- break;
355
- default: ctxt->last_cp_x = x0; ctxt->last_cp_y = y0; break;
356
- }
357
-
358
- while (lsm_str_parse_double_list (&ctxt->ptr, 2, ctxt->values) == 2) {
359
- x = 2 * x0 - ctxt->last_cp_x;
360
- y = 2 * y0 - ctxt->last_cp_y;
361
- if (relative) {
362
- cairo_get_current_point (ctxt->cr, &x0, &y0);
363
- lsm_cairo_quadratic_curve_to (ctxt->cr, x, y, x0 + ctxt->values[0], y0 + ctxt->values[1]);
364
- } else {
365
- lsm_cairo_quadratic_curve_to (ctxt->cr, x, y, ctxt->values[0], ctxt->values[1]);
366
- }
367
- ctxt->last_cp_x = x;
368
- ctxt->last_cp_y = y;
369
- cairo_get_current_point (ctxt->cr, &x0, &y0);
370
- }
371
- }
372
-
373
- static void
374
- _emit_function_6 (LsmSvgPathContext *ctxt,
375
- void (*cairo_func) (cairo_t *, double, double, double ,double, double, double))
376
- {
377
- while (lsm_str_parse_double_list (&ctxt->ptr, 6, ctxt->values) == 6)
378
- cairo_func (ctxt->cr, ctxt->values[0], ctxt->values[1], ctxt->values[2],
379
- ctxt->values[3], ctxt->values[4], ctxt->values[5]);
380
- }
381
-
382
- static void
383
- _emit_function_7 (LsmSvgPathContext *ctxt,
384
- void (*cairo_func) (cairo_t *, double, double, double ,gboolean, gboolean, double, double))
385
- {
386
- while (lsm_str_parse_double_list (&ctxt->ptr, 7, ctxt->values) == 7)
387
- cairo_func (ctxt->cr, ctxt->values[0], ctxt->values[1], ctxt->values[2],
388
- ctxt->values[3], ctxt->values[4], ctxt->values[5],
389
- ctxt->values[6]);
390
- }
391
-
392
- void
393
- lsm_cairo_emit_svg_path (cairo_t *cr, char const *path)
394
- {
395
- LsmSvgPathContext ctxt;
396
-
397
- g_return_if_fail (cr != NULL);
398
-
399
- if (path == NULL)
400
- return;
401
-
402
- ctxt.cr = cr;
403
- ctxt.ptr = (char *) path;
404
- ctxt.last_command = '\0';
405
- cairo_get_current_point (cr,
406
- &ctxt.values[0],
407
- &ctxt.values[1]);
408
- ctxt.values[2] = ctxt.values[4] = ctxt.values[0];
409
- ctxt.values[3] = ctxt.values[5] = ctxt.values[1];
410
-
411
- lsm_str_skip_spaces (&ctxt.ptr);
412
-
413
- while (*ctxt.ptr != '\0') {
414
- char command;
415
-
416
- command = *ctxt.ptr;
417
- ctxt.ptr++;
418
- lsm_str_skip_spaces (&ctxt.ptr);
419
-
420
- if (!cairo_has_current_point (cr)) {
421
- cairo_move_to (cr, 0, 0);
422
- ctxt.values[2] = ctxt.values[4] = ctxt.values[0] = 0;
423
- ctxt.values[3] = ctxt.values[5] = ctxt.values[1] = 0;
424
- }
425
-
426
- switch (command) {
427
- case 'M': _emit_function_2 (&ctxt, cairo_move_to, cairo_line_to); break;
428
- case 'm': _emit_function_2 (&ctxt, cairo_rel_move_to, cairo_rel_line_to); break;
429
- case 'L': _emit_function_2 (&ctxt, cairo_line_to, cairo_line_to); break;
430
- case 'l': _emit_function_2 (&ctxt, cairo_rel_line_to, cairo_rel_line_to); break;
431
- case 'C': _emit_function_6 (&ctxt, cairo_curve_to); break;
432
- case 'c': _emit_function_6 (&ctxt, cairo_rel_curve_to); break;
433
- case 'S': _emit_smooth_curve (&ctxt, FALSE); break;
434
- case 's': _emit_smooth_curve (&ctxt, TRUE); break;
435
- case 'V': _emit_function_1 (&ctxt, lsm_cairo_vertical); break;
436
- case 'v': _emit_function_1 (&ctxt, lsm_cairo_rel_vertical); break;
437
- case 'H': _emit_function_1 (&ctxt, lsm_cairo_horizontal); break;
438
- case 'h': _emit_function_1 (&ctxt, lsm_cairo_rel_horizontal); break;
439
- case 'Q': _emit_function_4 (&ctxt, lsm_cairo_quadratic_curve_to); break;
440
- case 'q': _emit_function_4 (&ctxt, lsm_cairo_rel_quadratic_curve_to); break;
441
- case 'T': _emit_smooth_quadratic_curve (&ctxt, FALSE); break;
442
- case 't': _emit_smooth_quadratic_curve (&ctxt, TRUE); break;
443
- case 'A': _emit_function_7 (&ctxt, lsm_cairo_elliptical_arc); break;
444
- case 'a': _emit_function_7 (&ctxt, lsm_cairo_rel_elliptical_arc); break;
445
- case 'Z':
446
- case 'z': cairo_close_path (cr); break;
447
- default: break;
448
- }
449
-
450
- ctxt.last_command = command;
451
- }
452
- }
453
-
454
- void
455
- lsm_cairo_box_user_to_device (cairo_t *cairo, LsmBox *to, const LsmBox *from)
456
- {
457
- if (to == NULL)
458
- return;
459
-
460
- if (from == NULL || cairo == NULL) {
461
- to->x = 0;
462
- to->y = 0;
463
- to->width = 0;
464
- to->height = 0;
465
- }
466
-
467
- *to = *from;
468
-
469
- cairo_user_to_device (cairo, &to->x, &to->y);
470
- cairo_user_to_device_distance (cairo, &to->width, &to->height);
471
- }
472
-
473
- void
474
- lsm_cairo_box_device_to_user (cairo_t *cairo, LsmBox *to, const LsmBox *from)
475
- {
476
- if (to == NULL)
477
- return;
478
-
479
- if (from == NULL || cairo == NULL) {
480
- to->x = 0;
481
- to->y = 0;
482
- to->width = 0;
483
- to->height = 0;
484
- }
485
-
486
- *to = *from;
487
-
488
- cairo_device_to_user (cairo, &to->x, &to->y);
489
- cairo_device_to_user_distance (cairo, &to->width, &to->height);
490
- }
491
-
492
- /**
493
- * lsm_cairo_set_source_pixbuf:
494
- * @cairo: a cairo context
495
- * @pixbuf: a #GdkPixbuf
496
- * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf
497
- * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf
498
- *
499
- * Sets the given pixbuf as the source pattern for @cairo.
500
- *
501
- * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
502
- * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y.
503
- *
504
- * Since: 0.4
505
- */
506
-
507
- void
508
- lsm_cairo_set_source_pixbuf (cairo_t *cairo,
509
- const GdkPixbuf *pixbuf,
510
- double pixbuf_x,
511
- double pixbuf_y)
512
- {
513
- gint width = gdk_pixbuf_get_width (pixbuf);
514
- gint height = gdk_pixbuf_get_height (pixbuf);
515
- guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
516
- int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
517
- int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
518
- int cairo_stride;
519
- guchar *cairo_pixels;
520
- cairo_format_t format;
521
- cairo_surface_t *surface;
522
- static const cairo_user_data_key_t key;
523
- int j;
524
-
525
- if (n_channels == 3)
526
- format = CAIRO_FORMAT_RGB24;
527
- else
528
- format = CAIRO_FORMAT_ARGB32;
529
-
530
- cairo_stride = cairo_format_stride_for_width (format, width);
531
- cairo_pixels = g_malloc (height * cairo_stride);
532
- surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels,
533
- format,
534
- width, height, cairo_stride);
535
-
536
- cairo_surface_set_user_data (surface, &key,
537
- cairo_pixels, (cairo_destroy_func_t)g_free);
538
-
539
- for (j = height; j; j--)
540
- {
541
- guchar *p = gdk_pixels;
542
- guchar *q = cairo_pixels;
543
-
544
- if (n_channels == 3)
545
- {
546
- guchar *end = p + 3 * width;
547
-
548
- while (p < end)
549
- {
550
- #if G_BYTE_ORDER == G_LITTLE_ENDIAN
551
- q[0] = p[2];
552
- q[1] = p[1];
553
- q[2] = p[0];
554
- #else
555
- q[1] = p[0];
556
- q[2] = p[1];
557
- q[3] = p[2];
558
- #endif
559
- p += 3;
560
- q += 4;
561
- }
562
- }
563
- else
564
- {
565
- guchar *end = p + 4 * width;
566
- guint t1,t2,t3;
567
-
568
- #define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
569
-
570
- while (p < end)
571
- {
572
- #if G_BYTE_ORDER == G_LITTLE_ENDIAN
573
- MULT(q[0], p[2], p[3], t1);
574
- MULT(q[1], p[1], p[3], t2);
575
- MULT(q[2], p[0], p[3], t3);
576
- q[3] = p[3];
577
- #else
578
- q[0] = p[3];
579
- MULT(q[1], p[0], p[3], t1);
580
- MULT(q[2], p[1], p[3], t2);
581
- MULT(q[3], p[2], p[3], t3);
582
- #endif
583
-
584
- p += 4;
585
- q += 4;
586
- }
587
-
588
- #undef MULT
589
- }
590
-
591
- gdk_pixels += gdk_rowstride;
592
- cairo_pixels += cairo_stride;
593
- }
594
-
595
- cairo_set_source_surface (cairo, surface, pixbuf_x, pixbuf_y);
596
- cairo_surface_destroy (surface);
597
- }
598
-