mathematical 0.6.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -12
- data/Rakefile +3 -2
- data/ext/mathematical/cairo_callbacks.c +25 -0
- data/ext/mathematical/cairo_callbacks.h +7 -0
- data/ext/mathematical/extconf.rb +11 -11
- data/ext/mathematical/lasem/src/lsmmathmldocument.c +3 -0
- data/ext/mathematical/lasem/src/lsmmathmlencloseelement.c +142 -0
- data/ext/mathematical/lasem/src/lsmmathmlencloseelement.h +64 -0
- data/ext/mathematical/lasem/src/lsmmathmlenums.c +35 -0
- data/ext/mathematical/lasem/src/lsmmathmlenums.h +25 -1
- data/ext/mathematical/lasem/src/lsmmathmlpaddedelement.c +79 -0
- data/ext/mathematical/lasem/src/lsmmathmlpaddedelement.h +5 -0
- data/ext/mathematical/lasem/src/lsmmathmlstyleelement.c +6 -0
- data/ext/mathematical/lasem/src/lsmmathmltableelement.c +5 -5
- data/ext/mathematical/lasem/src/lsmmathmltraits.c +24 -0
- data/ext/mathematical/lasem/src/lsmmathmltraits.h +1 -0
- data/ext/mathematical/lasem/src/lsmmathmltypes.h +1 -0
- data/ext/mathematical/lasem/src/lsmmathmlutils.h +9 -2
- data/ext/mathematical/lasem/src/lsmmathmlview.c +283 -11
- data/ext/mathematical/lasem/src/lsmmathmlview.h +13 -0
- data/ext/mathematical/lasem_overrides.c +40 -0
- data/ext/mathematical/lasem_overrides.h +23 -0
- data/ext/mathematical/mathematical.c +119 -127
- data/ext/mathematical/mathematical.h +24 -0
- data/ext/mathematical/mtex2MML/ext/extconf.rb +1 -1
- data/ext/mathematical/mtex2MML/src/lex.yy.c +4488 -4032
- data/ext/mathematical/mtex2MML/src/mtex2MML.h +3 -0
- data/ext/mathematical/mtex2MML/src/parse_extras.c +14 -5
- data/ext/mathematical/mtex2MML/src/parse_extras.h +3 -1
- data/ext/mathematical/mtex2MML/src/string_extras.c +39 -0
- data/ext/mathematical/mtex2MML/src/string_extras.h +7 -0
- data/ext/mathematical/mtex2MML/src/y.tab.c +4408 -3175
- data/ext/mathematical/mtex2MML/src/y.tab.h +500 -422
- data/lib/mathematical.rb +112 -2
- data/lib/mathematical/corrections.rb +2 -2
- data/lib/mathematical/version.rb +2 -2
- data/mathematical.gemspec +4 -4
- data/test/mathematical/basic_test.rb +1 -1
- data/test/mathematical/corrections_test.rb +1 -1
- data/test/mathematical/fixtures/png/numeric_test_1.png +0 -0
- data/test/mathematical/fixtures/png/numeric_test_2.png +0 -0
- data/test/mathematical/fixtures/png/numeric_test_3.png +0 -0
- data/test/mathematical/fixtures_test.rb +7 -7
- data/test/mathematical/maliciousness_test.rb +44 -17
- data/test/mathematical/mathjax_test.rb +5 -13
- data/test/mathematical/mathml_test.rb +3 -3
- data/test/mathematical/multiples_test.rb +68 -0
- data/test/mathematical/performance_test.rb +2 -2
- data/test/mathematical/png_test.rb +5 -5
- data/test/test_helper.rb +36 -1
- metadata +26 -11
- data/lib/mathematical/render.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020b6daf960edb5a9e5436aef6fa8c406188896c
|
4
|
+
data.tar.gz: ac15939f237b1086ed76ab8cd36fd55b7cb261e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f73b02d173514430ff94664fa28e2b2d7cdfd863556796b399c3ee590a97a1904ab9f119b13ea617a677a47bde1351d7c5a4bbcd069d8732ffa097b46a418f9
|
7
|
+
data.tar.gz: 773a25ece459f013a69554c33018f2be6530ffc0e31d6b821a89690d5a652d84286e51697037b69887c09a682c50669927ff0ee4252cbf29fda3dad301a939df
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ The simplest way to do this is
|
|
27
27
|
``` ruby
|
28
28
|
require 'mathematical'
|
29
29
|
|
30
|
-
Mathematical
|
30
|
+
Mathematical.new.render(string_with_math)
|
31
31
|
```
|
32
32
|
|
33
33
|
`string_with_math` should just be a string of math TeX inline (`$..$`) or display (`$$..$$`) style math.
|
@@ -45,21 +45,55 @@ The output will be a hash, with keys that depend on the format you want:
|
|
45
45
|
* If you asked for MathML, you'll get:
|
46
46
|
* `mathml`: the MathML data
|
47
47
|
|
48
|
+
**Note**: If you pass in invalid LaTeX, an error is not raised, but a message *is* printed to STDERR, and the original string is returned (not a hash).
|
49
|
+
|
50
|
+
### Array of equations
|
51
|
+
|
52
|
+
Rather than just a string, you can also provide an array of math inputs:
|
53
|
+
|
54
|
+
``` ruby
|
55
|
+
inputs = []
|
56
|
+
inputs << '$a$'
|
57
|
+
inputs << '$b$'
|
58
|
+
inputs << '$c$'
|
59
|
+
|
60
|
+
Mathematical.new.render(inputs)
|
61
|
+
```
|
62
|
+
|
63
|
+
This returns an array of hashes, possessing the same keys as above.
|
64
|
+
|
65
|
+
**Note**: With an array, it is possible to receive elements that are not hashes. For example, given the following input:
|
66
|
+
|
67
|
+
```
|
68
|
+
array = ['$foof$', '$not__thisisnotreal$', '$poof$']
|
69
|
+
```
|
70
|
+
|
71
|
+
You will receive the following output:
|
72
|
+
|
73
|
+
```
|
74
|
+
Mathematical.new.render(array)
|
75
|
+
[ {:svg => "...", :width => ... }, '$not__thisisnotreal$', {:svg => "...", :width => ... }]
|
76
|
+
```
|
77
|
+
|
78
|
+
That is, while the first and last elements are valid LaTeX math, the middle one is not, so the same string is returned. As with a single string, a message is also printed to STDERR.
|
79
|
+
|
48
80
|
### Options
|
49
81
|
|
50
|
-
`Mathematical
|
82
|
+
`Mathematical.new` takes an optional hash to define a few options:
|
51
83
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
84
|
+
| Name | Description | Default
|
85
|
+
|------|-------------|--------
|
86
|
+
| `:ppi` | A double determining the pixels per inch of the resulting SVG | `72.0`
|
87
|
+
| `:zoom` | A double determining the zoom level of the resulting SVG | `1.0`
|
88
|
+
| `:base64` | A boolean determining whether Mathematical's output should be a base64-encoded SVG string | `false`
|
89
|
+
| `:maxsize` | A numeral indicating the `MAXSIZE` the output string can be. | `unsigned long`
|
90
|
+
| `:format` | A symbol indicating whether you want an `:svg`, `:png`, or `:mathml` output. | `:svg`
|
57
91
|
|
58
92
|
Pass these in like this:
|
59
93
|
|
60
94
|
``` ruby
|
61
95
|
opts = { :ppi => 200.0, :zoom => 5.0, :base64 => true }
|
62
|
-
renderer = Mathematical
|
96
|
+
renderer = Mathematical.new(opts)
|
63
97
|
renderer.render('$a \ne b$')
|
64
98
|
```
|
65
99
|
|
@@ -67,7 +101,7 @@ renderer.render('$a \ne b$')
|
|
67
101
|
|
68
102
|
Check out [SUPPORTED.md on the mtex2MML website](https://github.com/gjtorikian/mtex2MML/blob/master/SUPPORTED.md).
|
69
103
|
|
70
|
-
**Note**: This library makes a few assumptions about the strings that you pass in. It assumes that `$..$` is inline math
|
104
|
+
**Note**: This library makes a few assumptions about the strings that you pass in. It assumes that `$..$` is inline math and `$$..$$` is display math.
|
71
105
|
|
72
106
|
## Building
|
73
107
|
|
@@ -122,10 +156,12 @@ On a Windows machine, I have no idea. Pull requests welcome!
|
|
122
156
|
|
123
157
|
```
|
124
158
|
Benchmarking....
|
125
|
-
Size:
|
159
|
+
Size: 1164 kilobytes
|
126
160
|
Iterations: 10
|
127
161
|
user system total real
|
128
|
-
Rendering...
|
162
|
+
Rendering... 18.070000 0.290000 18.360000 ( 23.003883)
|
163
|
+
|
164
|
+
19340 items converted!
|
129
165
|
```
|
130
166
|
|
131
167
|
## Hacking
|
@@ -217,7 +253,7 @@ With it, you could do something fun like:
|
|
217
253
|
|
218
254
|
``` ruby
|
219
255
|
MathToItex(string).convert do |eq, type|
|
220
|
-
svg_content = Mathematical
|
256
|
+
svg_content = Mathematical.new(:base64 => true).render(eq)
|
221
257
|
|
222
258
|
# create image tags of math with base64-encoded SVGs
|
223
259
|
%|<img class="#{type.to_s}-math" data-math-type="#{type.to_s}-math" src="#{svg_content}"/>|
|
data/Rakefile
CHANGED
@@ -40,9 +40,10 @@ task :copy_samples do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
task :destroy_copies do
|
43
|
+
safe_files = [/extconf.rb/, /mathematical\.(?:c|h)/, /lasem_overrides/, /cairo_callbacks/]
|
43
44
|
ext_dir = File.join(File.dirname(__FILE__), 'ext', 'mathematical')
|
44
45
|
Dir.glob("#{ext_dir}/*").select { |f| File.file?(f) }.each do |f|
|
45
|
-
next if
|
46
|
+
next if safe_files.any? { |s| f =~ s }
|
46
47
|
File.delete(f)
|
47
48
|
end
|
48
49
|
Dir.glob("#{ext_dir}/{lib,src,test,ext,deps,uthash}").select { |d| FileUtils.rm_rf d }
|
@@ -51,5 +52,5 @@ end
|
|
51
52
|
desc 'Pretty format C code'
|
52
53
|
task :format do
|
53
54
|
puts `astyle --indent=spaces=2 --style=1tbs --keep-one-line-blocks \
|
54
|
-
$(ack -f --type=cpp --type=cc ext/mathematical/
|
55
|
+
$(ack -n -f --type=cpp --type=cc ext/mathematical/)`
|
55
56
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#include <cairo_callbacks.h>
|
2
|
+
|
3
|
+
cairo_status_t cairoSvgSurfaceCallback (void *closure, const unsigned char *data, unsigned int length)
|
4
|
+
{
|
5
|
+
VALUE self = (VALUE) closure;
|
6
|
+
if (rb_iv_get(self, "@svg") == Qnil) {
|
7
|
+
rb_iv_set(self, "@svg", rb_str_new2(""));
|
8
|
+
}
|
9
|
+
|
10
|
+
rb_str_cat(rb_iv_get(self, "@svg"), data, length);
|
11
|
+
|
12
|
+
return CAIRO_STATUS_SUCCESS;
|
13
|
+
}
|
14
|
+
|
15
|
+
cairo_status_t cairoPngSurfaceCallback (void *closure, const unsigned char *data, unsigned int length)
|
16
|
+
{
|
17
|
+
VALUE self = (VALUE) closure;
|
18
|
+
if (rb_iv_get(self, "@png") == Qnil) {
|
19
|
+
rb_iv_set(self, "@png", rb_str_new2(""));
|
20
|
+
}
|
21
|
+
|
22
|
+
rb_str_cat(rb_iv_get(self, "@png"), data, length);
|
23
|
+
|
24
|
+
return CAIRO_STATUS_SUCCESS;
|
25
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
#include <cairo-svg.h>
|
4
|
+
|
5
|
+
extern cairo_status_t cairoSvgSurfaceCallback (void *closure, const unsigned char *data, unsigned int length);
|
6
|
+
|
7
|
+
extern cairo_status_t cairoPngSurfaceCallback (void *closure, const unsigned char *data, unsigned int length);
|
data/ext/mathematical/extconf.rb
CHANGED
@@ -2,36 +2,36 @@ require 'mkmf'
|
|
2
2
|
require 'rbconfig'
|
3
3
|
host_os = RbConfig::CONFIG['host_os']
|
4
4
|
|
5
|
-
LASEM_DIR = File.join(File.dirname(__FILE__),
|
6
|
-
MTEX_DIR = File.join(File.dirname(__FILE__),
|
5
|
+
LASEM_DIR = File.join(File.dirname(__FILE__), 'lasem', 'src')
|
6
|
+
MTEX_DIR = File.join(File.dirname(__FILE__), 'mtex2MML', 'src')
|
7
7
|
|
8
8
|
if host_os =~ /darwin|mac os/
|
9
9
|
ENV['PKG_CONFIG_PATH'] = "/opt/X11/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
|
10
10
|
end
|
11
11
|
|
12
|
-
have_library(
|
13
|
-
find_header(
|
14
|
-
find_header(
|
15
|
-
find_header(
|
16
|
-
find_header(
|
12
|
+
have_library('xml2')
|
13
|
+
find_header('libxml/tree.h', '/include/libxml2', '/usr/include/libxml2', '/usr/local/include/libxml2')
|
14
|
+
find_header('libxml/parser.h', '/include/libxml2', '/usr/include/libxml2', '/usr/local/include/libxml2')
|
15
|
+
find_header('libxml/xpath.h', '/include/libxml2', '/usr/include/libxml2', '/usr/local/include/libxml2')
|
16
|
+
find_header('libxml/xpathInternals.h', '/include/libxml2', '/usr/include/libxml2', '/usr/local/include/libxml2')
|
17
17
|
|
18
18
|
# TODO: this is so frakkin' stupid. but I can't seem to get subdirs to compile any other way
|
19
19
|
# the `destroy_copies` task, immediately after `compile`, will destroy these files
|
20
20
|
FileUtils.cp_r(Dir.glob("#{LASEM_DIR}/*"), File.dirname(__FILE__))
|
21
|
-
File.delete(File.join(File.dirname(__FILE__),
|
21
|
+
File.delete(File.join(File.dirname(__FILE__), 'lasemrender.c'))
|
22
22
|
|
23
23
|
# build mtex2MML Bison files
|
24
24
|
Dir.chdir(MTEX_DIR) do
|
25
|
-
system
|
25
|
+
system 'make'
|
26
26
|
end
|
27
27
|
|
28
28
|
FileUtils.cp_r(Dir.glob("#{MTEX_DIR}/*.{c,h,cc}"), File.dirname(__FILE__))
|
29
29
|
FileUtils.cp_r("#{MTEX_DIR}/deps/.", File.dirname(__FILE__))
|
30
30
|
FileUtils.cp_r(Dir.glob("#{MTEX_DIR}/deps/**/*"), File.dirname(__FILE__))
|
31
31
|
|
32
|
-
have_library(
|
32
|
+
have_library('pangocairo-1.0')
|
33
33
|
|
34
34
|
$LDFLAGS += " #{`pkg-config --static --libs glib-2.0 gdk-pixbuf-2.0 cairo pango`.chomp}"
|
35
35
|
$CFLAGS += " #{`pkg-config --cflags glib-2.0 gdk-pixbuf-2.0 cairo pango`.chomp} -I#{LASEM_DIR} -I#{MTEX_DIR}"
|
36
36
|
|
37
|
-
create_makefile(
|
37
|
+
create_makefile('mathematical/mathematical')
|
@@ -36,6 +36,7 @@
|
|
36
36
|
#include <lsmmathmloperatorelement.h>
|
37
37
|
#include <lsmmathmlstringelement.h>
|
38
38
|
#include <lsmmathmlrowelement.h>
|
39
|
+
#include <lsmmathmlencloseelement.h>
|
39
40
|
#include <lsmmathmlpaddedelement.h>
|
40
41
|
#include <lsmmathmlfencedelement.h>
|
41
42
|
#include <lsmmathmlerrorelement.h>
|
@@ -102,6 +103,8 @@ _create_element (LsmDomDocument *document, const char *tag_name)
|
|
102
103
|
node = lsm_mathml_operator_element_new ();
|
103
104
|
else if (strcmp (tag_name, "mrow") == 0)
|
104
105
|
node = lsm_mathml_row_element_new ();
|
106
|
+
else if (strcmp (tag_name, "menclose") == 0)
|
107
|
+
node = lsm_mathml_enclose_element_new ();
|
105
108
|
else if (strcmp (tag_name, "mn") == 0)
|
106
109
|
node = lsm_mathml_number_element_new ();
|
107
110
|
else if (strcmp (tag_name, "mi") == 0)
|
@@ -0,0 +1,142 @@
|
|
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 <lsmmathmlencloseelement.h>
|
25
|
+
#include <lsmmathmlview.h>
|
26
|
+
|
27
|
+
static GObjectClass *parent_class;
|
28
|
+
|
29
|
+
/* LsmDomNode implementation */
|
30
|
+
|
31
|
+
static const char *
|
32
|
+
_get_node_name (LsmDomNode *node)
|
33
|
+
{
|
34
|
+
return "menclose";
|
35
|
+
}
|
36
|
+
|
37
|
+
/* LsmMathmlElement implementation */
|
38
|
+
|
39
|
+
static void
|
40
|
+
_update (LsmMathmlElement *self, LsmMathmlStyle *style)
|
41
|
+
{
|
42
|
+
LsmMathmlEncloseElement *enclose = LSM_MATHML_ENCLOSE_ELEMENT (self);
|
43
|
+
|
44
|
+
style->math_color = lsm_mathml_color_attribute_inherit (&enclose->math_color, style->math_color);
|
45
|
+
style->math_background = lsm_mathml_color_attribute_inherit (&enclose->math_background, style->math_background);
|
46
|
+
}
|
47
|
+
|
48
|
+
static const LsmMathmlBbox *
|
49
|
+
_measure (LsmMathmlElement *self, LsmMathmlView *view, const LsmMathmlBbox *bbox)
|
50
|
+
{
|
51
|
+
LsmMathmlEncloseElement *enclose = LSM_MATHML_ENCLOSE_ELEMENT (self);
|
52
|
+
LsmMathmlBbox stretch_bbox;
|
53
|
+
|
54
|
+
LSM_MATHML_ELEMENT_CLASS (parent_class)->measure (self, view, bbox);
|
55
|
+
|
56
|
+
stretch_bbox = self->bbox;
|
57
|
+
|
58
|
+
lsm_mathml_view_measure_notation (view, &self->style, enclose->notation.value, &stretch_bbox,
|
59
|
+
&self->bbox, &enclose->x_child_offset);
|
60
|
+
|
61
|
+
return &self->bbox;
|
62
|
+
}
|
63
|
+
|
64
|
+
static void
|
65
|
+
_layout (LsmMathmlElement *self, LsmMathmlView *view,
|
66
|
+
double x, double y, const LsmMathmlBbox *bbox)
|
67
|
+
{
|
68
|
+
LsmMathmlEncloseElement *enclose = LSM_MATHML_ENCLOSE_ELEMENT (self);
|
69
|
+
|
70
|
+
LSM_MATHML_ELEMENT_CLASS (parent_class)->layout (self, view, x + enclose->x_child_offset, y, bbox);
|
71
|
+
}
|
72
|
+
|
73
|
+
static void
|
74
|
+
_render (LsmMathmlElement *self, LsmMathmlView *view)
|
75
|
+
{
|
76
|
+
LsmMathmlEncloseElement *enclose = LSM_MATHML_ENCLOSE_ELEMENT (self);
|
77
|
+
|
78
|
+
LSM_MATHML_ELEMENT_CLASS (parent_class)->render (self, view);
|
79
|
+
|
80
|
+
lsm_mathml_view_show_notation (view, &self->style, enclose->notation.value, self->x, self->y, &self->bbox,
|
81
|
+
enclose->x_child_offset);
|
82
|
+
}
|
83
|
+
|
84
|
+
/* LsmMathmlEncloseElement implementation */
|
85
|
+
|
86
|
+
LsmDomNode *
|
87
|
+
lsm_mathml_enclose_element_new (void)
|
88
|
+
{
|
89
|
+
return g_object_new (LSM_TYPE_MATHML_ENCLOSE_ELEMENT, NULL);
|
90
|
+
}
|
91
|
+
|
92
|
+
static const LsmMathmlNotation notation_default = LSM_MATHML_NOTATION_LONGDIV;
|
93
|
+
|
94
|
+
static void
|
95
|
+
lsm_mathml_enclose_element_init (LsmMathmlEncloseElement *element)
|
96
|
+
{
|
97
|
+
}
|
98
|
+
|
99
|
+
/* LsmMathmlEncloseElement class */
|
100
|
+
|
101
|
+
static const LsmAttributeInfos _attribute_infos[] = {
|
102
|
+
{
|
103
|
+
.name = "notation",
|
104
|
+
.attribute_offset = offsetof (LsmMathmlEncloseElement, notation),
|
105
|
+
.trait_class = &lsm_mathml_notation_trait_class,
|
106
|
+
.trait_default = ¬ation_default
|
107
|
+
},
|
108
|
+
{
|
109
|
+
.name = "mathcolor",
|
110
|
+
.attribute_offset = offsetof (LsmMathmlEncloseElement, math_color),
|
111
|
+
.trait_class = &lsm_mathml_color_trait_class,
|
112
|
+
},
|
113
|
+
{
|
114
|
+
.name = "mathbackground",
|
115
|
+
.attribute_offset = offsetof (LsmMathmlEncloseElement, math_background),
|
116
|
+
.trait_class = &lsm_mathml_color_trait_class,
|
117
|
+
}
|
118
|
+
};
|
119
|
+
|
120
|
+
static void
|
121
|
+
lsm_mathml_enclose_element_class_init (LsmMathmlEncloseElementClass *klass)
|
122
|
+
{
|
123
|
+
LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (klass);
|
124
|
+
LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_CLASS (klass);
|
125
|
+
|
126
|
+
parent_class = g_type_class_peek_parent (klass);
|
127
|
+
|
128
|
+
d_node_class->get_node_name = _get_node_name;
|
129
|
+
|
130
|
+
m_element_class->update = _update;
|
131
|
+
m_element_class->measure = _measure;
|
132
|
+
m_element_class->layout = _layout;
|
133
|
+
m_element_class->render = _render;
|
134
|
+
m_element_class->attribute_manager = lsm_attribute_manager_duplicate (m_element_class->attribute_manager);
|
135
|
+
|
136
|
+
lsm_attribute_manager_add_attributes (m_element_class->attribute_manager,
|
137
|
+
G_N_ELEMENTS (_attribute_infos),
|
138
|
+
_attribute_infos);
|
139
|
+
}
|
140
|
+
|
141
|
+
G_DEFINE_TYPE (LsmMathmlEncloseElement, lsm_mathml_enclose_element, LSM_TYPE_MATHML_PRESENTATION_CONTAINER)
|
142
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/* Lasem
|
2
|
+
*
|
3
|
+
* Copyright © 2007-2011 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_ENCLOSE_ELEMENT_H
|
25
|
+
#define LSM_MATHML_ENCLOSE_ELEMENT_H
|
26
|
+
|
27
|
+
#include <lsmmathmltypes.h>
|
28
|
+
#include <lsmmathmlpresentationcontainer.h>
|
29
|
+
|
30
|
+
G_BEGIN_DECLS
|
31
|
+
|
32
|
+
#define LSM_TYPE_MATHML_ENCLOSE_ELEMENT (lsm_mathml_enclose_element_get_type ())
|
33
|
+
#define LSM_MATHML_ENCLOSE_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_MATHML_ENCLOSE_ELEMENT, LsmMathmlEncloseElement))
|
34
|
+
#define LSM_MATHML_ENCLOSE_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_MATHML_ENCLOSE_ELEMENT, LsmMathmlEncloseElementClass))
|
35
|
+
#define LSM_IS_MATHML_ENCLOSE_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_MATHML_ENCLOSE_ELEMENT))
|
36
|
+
#define LSM_IS_MATHML_ENCLOSE_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_MATHML_ENCLOSE_ELEMENT))
|
37
|
+
#define LSM_MATHML_ENCLOSE_ELEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_MATHML_ENCLOSE_ELEMENT, LsmMathmlEncloseElementClass))
|
38
|
+
|
39
|
+
typedef struct _LsmMathmlEncloseElementClass LsmMathmlEncloseElementClass;
|
40
|
+
|
41
|
+
struct _LsmMathmlEncloseElement {
|
42
|
+
LsmMathmlPresentationContainer presentation_container;
|
43
|
+
|
44
|
+
LsmMathmlEnumAttribute notation;
|
45
|
+
LsmMathmlColorAttribute math_color;
|
46
|
+
LsmMathmlColorAttribute math_background;
|
47
|
+
|
48
|
+
/* View data */
|
49
|
+
|
50
|
+
double x_child_offset;
|
51
|
+
};
|
52
|
+
|
53
|
+
struct _LsmMathmlEncloseElementClass {
|
54
|
+
LsmMathmlPresentationContainerClass parent_class;
|
55
|
+
};
|
56
|
+
|
57
|
+
GType lsm_mathml_enclose_element_get_type (void);
|
58
|
+
|
59
|
+
LsmDomNode *lsm_mathml_enclose_element_new (void);
|
60
|
+
|
61
|
+
G_END_DECLS
|
62
|
+
|
63
|
+
#endif
|
64
|
+
|
@@ -427,3 +427,38 @@ lsm_mathml_line_from_string (const char *string)
|
|
427
427
|
return lsm_enum_value_from_string (string, lsm_mathml_line_strings,
|
428
428
|
G_N_ELEMENTS (lsm_mathml_line_strings));
|
429
429
|
}
|
430
|
+
|
431
|
+
static const char *lsm_mathml_notation_strings[] = {
|
432
|
+
"longdiv",
|
433
|
+
"actuarial",
|
434
|
+
"radical",
|
435
|
+
"box",
|
436
|
+
"roundedbox",
|
437
|
+
"circle",
|
438
|
+
"left",
|
439
|
+
"right",
|
440
|
+
"top",
|
441
|
+
"bottom",
|
442
|
+
"updiagonalstrike",
|
443
|
+
"downdiagonalstrike",
|
444
|
+
"verticalstrike",
|
445
|
+
"horizontalstrike",
|
446
|
+
"madruwb",
|
447
|
+
"updiagonalarrow"
|
448
|
+
};
|
449
|
+
|
450
|
+
const char *
|
451
|
+
lsm_mathml_notation_to_string (LsmMathmlNotation notation)
|
452
|
+
{
|
453
|
+
if (notation < 0 || notation > LSM_MATHML_NOTATION_UP_DIAGONAL_ARROW)
|
454
|
+
return NULL;
|
455
|
+
|
456
|
+
return lsm_mathml_notation_strings [notation];
|
457
|
+
}
|
458
|
+
|
459
|
+
LsmMathmlNotation
|
460
|
+
lsm_mathml_notation_from_string (const char *string)
|
461
|
+
{
|
462
|
+
return lsm_enum_value_from_string (string, lsm_mathml_notation_strings,
|
463
|
+
G_N_ELEMENTS (lsm_mathml_notation_strings));
|
464
|
+
}
|