mathtype 0.0.8 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +7 -0
- data/Rakefile +8 -0
- data/lib/file_parser/ole.rb +15 -0
- data/lib/file_parser/parser.rb +19 -0
- data/lib/file_parser/wmf.rb +28 -0
- data/lib/mathtype.rb +30 -7
- data/lib/mathtype/version.rb +1 -1
- data/lib/records/bintypes.rb +18 -0
- data/lib/records/mtef.rb +8 -114
- data/lib/records/nudge.rb +9 -5
- data/lib/records/ruler.rb +1 -1
- data/lib/records/typesizes.rb +5 -10
- data/lib/records3/char.rb +53 -0
- data/lib/records3/embell.rb +109 -0
- data/lib/records3/font.rb +27 -0
- data/lib/records3/line.rb +47 -0
- data/lib/records3/matrix.rb +80 -0
- data/lib/records3/mtef.rb +97 -0
- data/lib/records3/options.rb +5 -0
- data/lib/records3/pile.rb +43 -0
- data/lib/records3/size.rb +75 -0
- data/lib/records3/snapshot.rb +19 -0
- data/lib/records3/tmpl.rb +751 -0
- data/lib/{records → records5}/char.rb +6 -12
- data/lib/{records → records5}/color.rb +1 -1
- data/lib/{records → records5}/color_def.rb +8 -8
- data/lib/{records → records5}/embell.rb +2 -2
- data/lib/{records → records5}/encoding_def.rb +1 -1
- data/lib/{records → records5}/eqn_prefs.rb +2 -2
- data/lib/{records → records5}/font_def.rb +1 -1
- data/lib/{records → records5}/font_style_def.rb +1 -1
- data/lib/{records → records5}/future.rb +1 -1
- data/lib/{records → records5}/line.rb +3 -3
- data/lib/{records → records5}/matrix.rb +11 -3
- data/lib/records5/mtef.rb +129 -0
- data/lib/{records → records5}/pile.rb +2 -2
- data/lib/{records → records5}/size.rb +9 -7
- data/lib/records5/snapshot.rb +19 -0
- data/lib/{records → records5}/tmpl.rb +2 -2
- data/spec/fixtures/expected/mathtype3/ceil.xml +38 -0
- data/spec/fixtures/expected/mathtype3/fence.xml +77 -0
- data/spec/fixtures/expected/mathtype3/floor.xml +38 -0
- data/spec/fixtures/expected/mathtype3/frac.xml +136 -0
- data/spec/fixtures/expected/mathtype3/large_nudge.xml +135 -0
- data/spec/fixtures/expected/mathtype3/lim_embell.xml +247 -0
- data/spec/fixtures/expected/mathtype3/matrix_2x1.xml +500 -0
- data/spec/fixtures/expected/mathtype3/pile.xml +188 -0
- data/spec/fixtures/expected/mathtype3/sigma_subsup.xml +46 -0
- data/spec/fixtures/expected/mathtype3/small_nudge.xml +90 -0
- data/spec/fixtures/expected/mathtype3/sqrt.xml +132 -0
- data/spec/fixtures/expected/{299.xml → mathtype5/299.xml} +30 -15
- data/spec/fixtures/expected/{arrows.xml → mathtype5/arrows.xml} +30 -15
- data/spec/fixtures/expected/{embedded.xml → mathtype5/embedded.xml} +29 -14
- data/spec/fixtures/expected/{embellishments.xml → mathtype5/embellishments.xml} +30 -15
- data/spec/fixtures/expected/{equation1.xml → mathtype5/equation1.xml} +30 -15
- data/spec/fixtures/expected/{equation10.xml → mathtype5/equation10.xml} +30 -15
- data/spec/fixtures/expected/{equation11.xml → mathtype5/equation11.xml} +30 -15
- data/spec/fixtures/expected/{equation12.xml → mathtype5/equation12.xml} +30 -15
- data/spec/fixtures/expected/{equation13.xml → mathtype5/equation13.xml} +30 -15
- data/spec/fixtures/expected/{equation2.xml → mathtype5/equation2.xml} +30 -15
- data/spec/fixtures/expected/{equation3.xml → mathtype5/equation3.xml} +30 -15
- data/spec/fixtures/expected/{equation4.xml → mathtype5/equation4.xml} +30 -15
- data/spec/fixtures/expected/{equation5.xml → mathtype5/equation5.xml} +30 -15
- data/spec/fixtures/expected/{equation6.xml → mathtype5/equation6.xml} +30 -15
- data/spec/fixtures/expected/{equation7.xml → mathtype5/equation7.xml} +30 -15
- data/spec/fixtures/expected/{equation8.xml → mathtype5/equation8.xml} +30 -15
- data/spec/fixtures/expected/{equation9.xml → mathtype5/equation9.xml} +30 -15
- data/spec/fixtures/expected/{fences.xml → mathtype5/fences.xml} +30 -15
- data/spec/fixtures/expected/{integrals.xml → mathtype5/integrals.xml} +30 -15
- data/spec/fixtures/expected/mathtype5/matrix-border.xml +365 -0
- data/spec/fixtures/expected/mathtype5/matrix.xml +382 -0
- data/spec/fixtures/expected/{sizes.xml → mathtype5/sizes.xml} +30 -15
- data/spec/fixtures/input/mathtype3/ceil.bin +0 -0
- data/spec/fixtures/input/mathtype3/fence.bin +0 -0
- data/spec/fixtures/input/mathtype3/floor.bin +0 -0
- data/spec/fixtures/input/mathtype3/frac.bin +0 -0
- data/spec/fixtures/input/mathtype3/large_nudge.bin +0 -0
- data/spec/fixtures/input/mathtype3/lim_embell.bin +0 -0
- data/spec/fixtures/input/mathtype3/matrix_2x1.bin +0 -0
- data/spec/fixtures/input/mathtype3/pile.bin +0 -0
- data/spec/fixtures/input/mathtype3/sigma_subsup.bin +0 -0
- data/spec/fixtures/input/mathtype3/small_nudge.bin +0 -0
- data/spec/fixtures/input/mathtype3/sqrt.bin +0 -0
- data/spec/fixtures/input/{299.bin → mathtype5/299.bin} +0 -0
- data/spec/fixtures/input/{arrows.bin → mathtype5/arrows.bin} +0 -0
- data/spec/fixtures/input/{embedded.bin → mathtype5/embedded.bin} +0 -0
- data/spec/fixtures/input/{embellishments.bin → mathtype5/embellishments.bin} +0 -0
- data/spec/fixtures/input/{equation1.bin → mathtype5/equation1.bin} +0 -0
- data/spec/fixtures/input/{equation10.bin → mathtype5/equation10.bin} +0 -0
- data/spec/fixtures/input/{equation11.bin → mathtype5/equation11.bin} +0 -0
- data/spec/fixtures/input/{equation12.bin → mathtype5/equation12.bin} +0 -0
- data/spec/fixtures/input/{equation13.bin → mathtype5/equation13.bin} +0 -0
- data/spec/fixtures/input/{equation2.bin → mathtype5/equation2.bin} +0 -0
- data/spec/fixtures/input/{equation3.bin → mathtype5/equation3.bin} +0 -0
- data/spec/fixtures/input/{equation4.bin → mathtype5/equation4.bin} +0 -0
- data/spec/fixtures/input/{equation5.bin → mathtype5/equation5.bin} +0 -0
- data/spec/fixtures/input/{equation6.bin → mathtype5/equation6.bin} +0 -0
- data/spec/fixtures/input/{equation7.bin → mathtype5/equation7.bin} +0 -0
- data/spec/fixtures/input/{equation8.bin → mathtype5/equation8.bin} +0 -0
- data/spec/fixtures/input/{equation9.bin → mathtype5/equation9.bin} +0 -0
- data/spec/fixtures/input/{fences.bin → mathtype5/fences.bin} +0 -0
- data/spec/fixtures/input/{integrals.bin → mathtype5/integrals.bin} +0 -0
- data/spec/fixtures/input/mathtype5/matrix-border.bin +0 -0
- data/spec/fixtures/input/mathtype5/matrix.bin +0 -0
- data/spec/fixtures/input/{sizes.bin → mathtype5/sizes.bin} +0 -0
- data/spec/mathtype_spec.rb +11 -9
- data/test-mathtype.rb +2 -0
- metadata +168 -97
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require_relative "snapshot"
|
|
2
|
+
|
|
3
|
+
# EMBELL record (6):
|
|
4
|
+
# Consists of:
|
|
5
|
+
# record type (6)
|
|
6
|
+
# options
|
|
7
|
+
# [nudge] if mtefOPT_NUDGE is set
|
|
8
|
+
# [embell] embellishment type
|
|
9
|
+
# The embellishment types are:
|
|
10
|
+
|
|
11
|
+
# value symbol description
|
|
12
|
+
# 2 emb1DOT over single dot
|
|
13
|
+
# 3 emb2DOT over double dot
|
|
14
|
+
# 4 emb3DOT over triple dot
|
|
15
|
+
# 5 emb1PRIME single prime
|
|
16
|
+
# 6 emb2PRIME double prime
|
|
17
|
+
# 7 embBPRIME backwards prime (left of character)
|
|
18
|
+
# 8 embTILDE tilde
|
|
19
|
+
# 9 embHAT hat (circumflex)
|
|
20
|
+
# 10 embNOT diagonal slash through character
|
|
21
|
+
# 11 embRARROW over right arrow
|
|
22
|
+
# 12 embLARROW over left arrow
|
|
23
|
+
# 13 embBARROW over both arrow (left and right)
|
|
24
|
+
# 14 embR1ARROW over right single-barbed arrow
|
|
25
|
+
# 15 embL1ARROW over left single-barbed arrow
|
|
26
|
+
# 16 embMBAR mid-height horizontal bar
|
|
27
|
+
# 17 embOBAR over-bar
|
|
28
|
+
# 18 emb3PRIME triple prime
|
|
29
|
+
# 19 embFROWN over-arc, concave downward
|
|
30
|
+
# 20 embSMILE over-arc, concave upward
|
|
31
|
+
# 21 embX_BARS double diagonal bars
|
|
32
|
+
# 22 embUP_BAR bottom-left to top-right diagonal bar
|
|
33
|
+
# 23 embDOWN_BAR top-left to bottom-right diagonal bar
|
|
34
|
+
# 24 emb4DOT over quad dot
|
|
35
|
+
# 25 embU_1DOT under single dot
|
|
36
|
+
# 26 embU_2DOT under double dot
|
|
37
|
+
# 27 embU_3DOT under triple dot
|
|
38
|
+
# 28 embU_4DOT under quad dot
|
|
39
|
+
# 29 embU_BAR under bar
|
|
40
|
+
# 30 embU_TILDE under tilde (~)
|
|
41
|
+
# 31 embU_FROWN under arc (ends point down)
|
|
42
|
+
# 32 embU_SMILE under arc (ends point up)
|
|
43
|
+
# 33 embU_RARROW under right arrow
|
|
44
|
+
# 34 embU_LARROW under left arrow
|
|
45
|
+
# 35 embU_BARROW under both arrow (left and right)
|
|
46
|
+
# 36 embU_R1ARROW under right arrow (1 barb)
|
|
47
|
+
# 37 embU_L1ARROW under left arrow (1 barb)
|
|
48
|
+
|
|
49
|
+
module Mathtype3
|
|
50
|
+
class RecordEmbell < BinData::Record
|
|
51
|
+
include Snapshot
|
|
52
|
+
EXPOSED_IN_SNAPSHOT = %i(options nudge embell)
|
|
53
|
+
|
|
54
|
+
EMBELL = {
|
|
55
|
+
2 => "emb1DOT", # over single dot
|
|
56
|
+
3 => "emb2DOT", # over double dot
|
|
57
|
+
4 => "emb3DOT", # over triple dot
|
|
58
|
+
5 => "emb1PRIME", # single prime
|
|
59
|
+
6 => "emb2PRIME", # double prime
|
|
60
|
+
7 => "embBPRIME", # backwards prime (left of character)
|
|
61
|
+
8 => "embTILDE", # tilde
|
|
62
|
+
9 => "embHAT", # hat (circumflex)
|
|
63
|
+
10 => "embNOT", # diagonal slash through character
|
|
64
|
+
11 => "embRARROW", # over right arrow
|
|
65
|
+
12 => "embLARROW", # over left arrow
|
|
66
|
+
13 => "embBARROW", # over both arrow (left and right)
|
|
67
|
+
14 => "embR1ARROW", # over right single-barbed arrow
|
|
68
|
+
15 => "embL1ARROW", # over left single-barbed arrow
|
|
69
|
+
16 => "embMBAR", # mid-height horizontal bar
|
|
70
|
+
17 => "embOBAR", # over-bar
|
|
71
|
+
18 => "emb3PRIME", # triple prime
|
|
72
|
+
19 => "embFROWN", # over-arc, concave downward
|
|
73
|
+
20 => "embSMILE", # over-arc, concave upward
|
|
74
|
+
21 => "embX_BARS", # double diagonal bars
|
|
75
|
+
22 => "embUP_BAR", # bottom-left to top-right diagonal bar
|
|
76
|
+
23 => "embDOWN_BAR", # top-left to bottom-right diagonal bar
|
|
77
|
+
24 => "emb4DOT", # over quad dot
|
|
78
|
+
25 => "embU_1DOT", # under single dot
|
|
79
|
+
26 => "embU_2DOT", # under double dot
|
|
80
|
+
27 => "embU_3DOT", # under triple dot
|
|
81
|
+
28 => "embU_4DOT", # under quad dot
|
|
82
|
+
29 => "embU_BAR", # under bar
|
|
83
|
+
30 => "embU_TILDE", # under tilde (~)
|
|
84
|
+
31 => "embU_FROWN", # under arc (ends point down)
|
|
85
|
+
32 => "embU_SMILE", # under arc (ends point up)
|
|
86
|
+
33 => "embU_RARROW", # under right arrow
|
|
87
|
+
34 => "embU_LARROW", # under left arrow
|
|
88
|
+
35 => "embU_BARROW", # under both arrow (left and right)
|
|
89
|
+
36 => "embU_R1ARROW", # under right arrow (1 barb)
|
|
90
|
+
37 => "embU_L1ARROW", # under left arrow (1 barb)
|
|
91
|
+
}
|
|
92
|
+
mandatory_parameter :_options
|
|
93
|
+
|
|
94
|
+
virtual :_tag_options, :value => lambda{ _options }
|
|
95
|
+
|
|
96
|
+
record_nudge :nudge, onlyif: lambda { _options & OPTIONS["xfLMOVE"] > 0 }
|
|
97
|
+
|
|
98
|
+
int8 :_embell
|
|
99
|
+
int8 :_none
|
|
100
|
+
|
|
101
|
+
def embell
|
|
102
|
+
EMBELL[_embell]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def options
|
|
106
|
+
_tag_options
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative "snapshot"
|
|
2
|
+
|
|
3
|
+
module Mathtype3
|
|
4
|
+
class RecordFont < BinData::Record
|
|
5
|
+
include Snapshot
|
|
6
|
+
EXPOSED_IN_SNAPSHOT = %i(options name typeface style)
|
|
7
|
+
|
|
8
|
+
endian :little
|
|
9
|
+
|
|
10
|
+
mandatory_parameter :_options
|
|
11
|
+
|
|
12
|
+
virtual :_tag_options, :value => lambda{ _options }
|
|
13
|
+
|
|
14
|
+
int8 :_typeface
|
|
15
|
+
|
|
16
|
+
int8 :style
|
|
17
|
+
|
|
18
|
+
stringz :name
|
|
19
|
+
def typeface
|
|
20
|
+
_typeface + 128
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def options
|
|
24
|
+
_tag_options
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# LINE record (1):
|
|
2
|
+
# Consists of:
|
|
3
|
+
# record type (1)
|
|
4
|
+
# options
|
|
5
|
+
# [nudge] if mtefOPT_NUDGE is set
|
|
6
|
+
# [line spacing] if mtefOPT_LINE_LSPACE is set (16-bit integer)
|
|
7
|
+
# [RULER record] if mtefOPT_LP_RULER is set
|
|
8
|
+
# object list of line (single pile, characters and templates, or nothing)
|
|
9
|
+
# The line spacing value, if present, is the distance between the baseline of
|
|
10
|
+
# this line and the line above it.
|
|
11
|
+
|
|
12
|
+
require_relative "snapshot"
|
|
13
|
+
|
|
14
|
+
module Mathtype3
|
|
15
|
+
class NamedRecord < BinData::Record; end
|
|
16
|
+
class RecordLine < BinData::Record
|
|
17
|
+
include Snapshot
|
|
18
|
+
EXPOSED_IN_SNAPSHOT = %i(options nudge line_spacing ruler object_list)
|
|
19
|
+
endian :little
|
|
20
|
+
|
|
21
|
+
mandatory_parameter :_options
|
|
22
|
+
|
|
23
|
+
virtual :_tag_options, :value => lambda{ _options }
|
|
24
|
+
|
|
25
|
+
record_nudge :nudge, onlyif: lambda { _options & OPTIONS["xfLMOVE"] > 0 }
|
|
26
|
+
|
|
27
|
+
mtef16 :line_spacing, onlyif: (lambda do
|
|
28
|
+
_options & OPTIONS["xfLSPACE"] > 0
|
|
29
|
+
end)
|
|
30
|
+
|
|
31
|
+
record_ruler :ruler, onlyif: (lambda do
|
|
32
|
+
_options & OPTIONS["xfRULER"] > 0
|
|
33
|
+
end)
|
|
34
|
+
|
|
35
|
+
array :object_list,
|
|
36
|
+
onlyif: lambda { _options & OPTIONS["xfNULL"] == 0 },
|
|
37
|
+
read_until: lambda { element.record_type == 0 } do
|
|
38
|
+
named_record
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_formatted_s(indent = 0); to_s; end
|
|
42
|
+
|
|
43
|
+
def options
|
|
44
|
+
_tag_options
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require_relative "snapshot"
|
|
2
|
+
|
|
3
|
+
# MATRIX record (5):
|
|
4
|
+
# record type (5)
|
|
5
|
+
# options
|
|
6
|
+
# [nudge] if mtefOPT_NUDGE is set
|
|
7
|
+
# [valign] vertical alignment of matrix within container
|
|
8
|
+
# [h_just] horizontal alignment within columns
|
|
9
|
+
# [v_just] vertical alignment within columns
|
|
10
|
+
# [rows] number of rows
|
|
11
|
+
# [cols] number of columns
|
|
12
|
+
# [row_parts] row partition line types (see below)
|
|
13
|
+
# [col_parts] column partition line types (see below)
|
|
14
|
+
# [object list] list of lines, one for each element of the matrix, in order from
|
|
15
|
+
# left-to-right and top-to-bottom
|
|
16
|
+
# The values for valign, h_just, and v_just are described in PILE above.
|
|
17
|
+
|
|
18
|
+
# The row partition line type list consists of two-bit values for each possible
|
|
19
|
+
# partition line (one more than the number of rows), rounded out to the nearest
|
|
20
|
+
# byte. Each value determines the line style of the corresponding partition line
|
|
21
|
+
# (0 for none, 1 for solid, 2 for dashed, or 3 for dotted). Similarly for the
|
|
22
|
+
# column partition lines.
|
|
23
|
+
|
|
24
|
+
module Mathtype3
|
|
25
|
+
class RecordMatrix < BinData::Record
|
|
26
|
+
include Snapshot
|
|
27
|
+
EXPOSED_IN_SNAPSHOT = %i(options nudge valign h_just v_just rows cols
|
|
28
|
+
row_parts col_parts object_list)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
mandatory_parameter :_options
|
|
32
|
+
|
|
33
|
+
virtual :_tag_options, :value => lambda{ _options }
|
|
34
|
+
|
|
35
|
+
record_nudge :nudge, onlyif: lambda { _options & OPTIONS["xfLMOVE"] > 0 }
|
|
36
|
+
|
|
37
|
+
int8 :_valign
|
|
38
|
+
int8 :_h_just
|
|
39
|
+
int8 :_v_just
|
|
40
|
+
int8 :rows
|
|
41
|
+
int8 :cols
|
|
42
|
+
|
|
43
|
+
array :row_parts, initial_length: lambda { rows + 1 } do
|
|
44
|
+
bit nbits: 2
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
bit :_realign_rows, nbits: lambda { realign(rows) }
|
|
48
|
+
|
|
49
|
+
array :col_parts, initial_length: lambda { cols + 1 } do
|
|
50
|
+
bit nbits: 2
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
bit :_realign_cols, nbits: lambda { realign(cols) }
|
|
54
|
+
|
|
55
|
+
array :object_list, read_until: lambda { element.record_type == 0 } do
|
|
56
|
+
named_record
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def valign
|
|
60
|
+
VALIGN[_valign]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def h_just
|
|
64
|
+
HALIGN[_h_just]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def v_just
|
|
68
|
+
VALIGN[_v_just]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def options
|
|
72
|
+
_tag_options
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def realign (nparts)
|
|
76
|
+
offset = (((nparts + 1) * 2) % 8)
|
|
77
|
+
return offset == 0 ? 0 : (8 - offset)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require_relative "line"
|
|
2
|
+
require_relative "embell"
|
|
3
|
+
require_relative "char"
|
|
4
|
+
require_relative "pile"
|
|
5
|
+
require_relative "tmpl"
|
|
6
|
+
require_relative "font"
|
|
7
|
+
require_relative "matrix"
|
|
8
|
+
require_relative "size"
|
|
9
|
+
|
|
10
|
+
module Mathtype3
|
|
11
|
+
class RecordEnd < Mathtype::RecordEnd; end
|
|
12
|
+
class RecordNudge < Mathtype::RecordNudge; end
|
|
13
|
+
class RecordRuler < Mathtype::RecordRuler; end
|
|
14
|
+
class RecordNudge < Mathtype::RecordNudge; end
|
|
15
|
+
class RecordFull < Mathtype::RecordFull; end
|
|
16
|
+
class RecordSub < Mathtype::RecordSub; end
|
|
17
|
+
class RecordSub2 < Mathtype::RecordSub2; end
|
|
18
|
+
class RecordSym < Mathtype::RecordSym; end
|
|
19
|
+
class RecordSubsym < Mathtype::RecordSubsym; end
|
|
20
|
+
|
|
21
|
+
HALIGN = Mathtype::HALIGN
|
|
22
|
+
VALIGN = Mathtype::VALIGN
|
|
23
|
+
|
|
24
|
+
RECORD_NAMES = {
|
|
25
|
+
0 => "end",
|
|
26
|
+
1 => "slot",
|
|
27
|
+
2 => "char",
|
|
28
|
+
3 => "tmpl",
|
|
29
|
+
4 => "pile",
|
|
30
|
+
5 => "matrix",
|
|
31
|
+
6 => "embell",
|
|
32
|
+
7 => "ruler",
|
|
33
|
+
8 => "font",
|
|
34
|
+
9 => "size",
|
|
35
|
+
10 => "full",
|
|
36
|
+
11 => "sub",
|
|
37
|
+
12 => "sub2",
|
|
38
|
+
13 => "sym",
|
|
39
|
+
14 => "subsym",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
OPTIONS = {
|
|
43
|
+
# value => symbol # description
|
|
44
|
+
# Option flag values for all equation structure records:
|
|
45
|
+
"xfLMOVE" => 0x08, # nudge values follow tag
|
|
46
|
+
# Option flag values for CHAR records:
|
|
47
|
+
"xfLAUTO" => 0x01, # character is followed by an embellishment list
|
|
48
|
+
"xfEMBELL" => 0x02, # character starts a function (sin, cos, etc.)
|
|
49
|
+
# Option flag values for LINE records:
|
|
50
|
+
"xfNULL" => 0x01, # line is a placeholder only (i.e. not displayed)
|
|
51
|
+
"xfLSPACE" => 0x04, # line spacing value follows tag
|
|
52
|
+
# Option flag values for LINE and PILE records:
|
|
53
|
+
"xfRULER" => 0x02, # RULER record follows LINE or PILE record
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class Payload < BinData::Choice
|
|
57
|
+
opt = {:_options => :options}
|
|
58
|
+
record_end 0 # end is a reserved keyword
|
|
59
|
+
record_line 1, opt
|
|
60
|
+
record_char 2, opt
|
|
61
|
+
record_tmpl 3, opt
|
|
62
|
+
record_pile 4, opt
|
|
63
|
+
record_matrix 5, opt
|
|
64
|
+
record_embell 6, opt
|
|
65
|
+
record_ruler 7, opt
|
|
66
|
+
record_font 8, opt
|
|
67
|
+
record_size 9, opt
|
|
68
|
+
record_full 10, opt
|
|
69
|
+
record_sub 11, opt
|
|
70
|
+
record_sub2 12, opt
|
|
71
|
+
record_sym 13, opt
|
|
72
|
+
record_subsym 14, opt
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
## Payload is the most important class to understand.
|
|
76
|
+
## This abstraction allows recursive formats.
|
|
77
|
+
## eg. lists can contain lists can contain lists.
|
|
78
|
+
|
|
79
|
+
class NamedRecord < BinData::Record
|
|
80
|
+
bit4 :record_options
|
|
81
|
+
bit4 :record_type
|
|
82
|
+
payload :payload, :onlyif => :not_end_tag?, :selection => :record_type, :options => :record_options
|
|
83
|
+
|
|
84
|
+
def not_end_tag?
|
|
85
|
+
record_type != 0
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
class Equation < Mathtype::Equation
|
|
90
|
+
EXPOSED_IN_SNAPSHOT = %i(mtef_version platform product product_version
|
|
91
|
+
product_subversion equation)
|
|
92
|
+
|
|
93
|
+
array :equation, read_until: lambda { element.record_type == 0 } do
|
|
94
|
+
named_record
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_relative "snapshot"
|
|
2
|
+
|
|
3
|
+
# PILE record (4):
|
|
4
|
+
|
|
5
|
+
# Consists of:
|
|
6
|
+
|
|
7
|
+
# record type (4)
|
|
8
|
+
# options
|
|
9
|
+
# [nudge] if mtefOPT_NUDGE is set
|
|
10
|
+
# [halign] horizontal alignment
|
|
11
|
+
# [valign] vertical alignment
|
|
12
|
+
# [[RULER record]] if mtefOPT_LP_RULER is set
|
|
13
|
+
# [object list] list of lines contained by the pile
|
|
14
|
+
|
|
15
|
+
module Mathtype3
|
|
16
|
+
class RecordPile < BinData::Record
|
|
17
|
+
include Snapshot
|
|
18
|
+
EXPOSED_IN_SNAPSHOT = %i(options halign valign object_list)
|
|
19
|
+
|
|
20
|
+
mandatory_parameter :_options
|
|
21
|
+
|
|
22
|
+
virtual :options, :value => lambda{ _options }
|
|
23
|
+
|
|
24
|
+
record_nudge :nudge, onlyif: lambda { _options & OPTIONS["xfLMOVE"] > 0 }
|
|
25
|
+
|
|
26
|
+
int8 :_halign
|
|
27
|
+
int8 :_valign
|
|
28
|
+
|
|
29
|
+
record_ruler :ruler, onlyif: lambda { _options & OPTIONS["xfRULER"] > 0 }
|
|
30
|
+
|
|
31
|
+
array :object_list, read_until: lambda { element.record_type == 0 } do
|
|
32
|
+
named_record
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def halign
|
|
36
|
+
HALIGN[_halign]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def valign
|
|
40
|
+
VALIGN[_valign]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require_relative "snapshot"
|
|
2
|
+
|
|
3
|
+
# SIZE record (9):
|
|
4
|
+
# Consists of one of the following cases:
|
|
5
|
+
|
|
6
|
+
# if lsize < 0 (explicit point size):
|
|
7
|
+
# record type (9)
|
|
8
|
+
# 101
|
|
9
|
+
# -point size (16 bit integer)
|
|
10
|
+
# else if -128 < dsize < +128:
|
|
11
|
+
# record type (9)
|
|
12
|
+
# lsize (typesize)
|
|
13
|
+
# dsize + 128
|
|
14
|
+
# else: (large delta)
|
|
15
|
+
# record type (9)
|
|
16
|
+
# 100
|
|
17
|
+
# lsize (typesize)
|
|
18
|
+
# dsize (16 bit integer)
|
|
19
|
+
# Sizes in MathType are represented as a pair of values, lsize and dsize. Lsize
|
|
20
|
+
# stands for "logical size", dsize for "delta size". If it is negative, it is an
|
|
21
|
+
# explicit point size (in 32nds of a point) negated and dsize is ignored.
|
|
22
|
+
# Otherwise, lsize is a typesize value and dsize is a delta from that size:
|
|
23
|
+
# Simple typesizes, without a delta value, are written using the records
|
|
24
|
+
# described in the next section.
|
|
25
|
+
|
|
26
|
+
module Mathtype3
|
|
27
|
+
class RecordSize < BinData::Record
|
|
28
|
+
include Snapshot
|
|
29
|
+
EXPOSED_IN_SNAPSHOT = %i(options lsize dsize point_size)
|
|
30
|
+
|
|
31
|
+
endian :little
|
|
32
|
+
|
|
33
|
+
mandatory_parameter :_options
|
|
34
|
+
|
|
35
|
+
virtual :_tag_options, :value => lambda{ _options }
|
|
36
|
+
|
|
37
|
+
int8 :_size_select
|
|
38
|
+
|
|
39
|
+
mtef16 :_point_size, onlyif: lambda { _size_select == 101 }
|
|
40
|
+
uint8 :_lsize_large_delta, onlyif: lambda { _size_select == 100 }
|
|
41
|
+
|
|
42
|
+
uint8 :_dsize, onlyif: lambda { _size_select != 100 && _size_select != 101 }
|
|
43
|
+
mtef16 :_dsize_large, onlyif: lambda { _size_select == 100 }
|
|
44
|
+
|
|
45
|
+
def dsize
|
|
46
|
+
case _size_select
|
|
47
|
+
when 100
|
|
48
|
+
_dsize_large / 32
|
|
49
|
+
when 101
|
|
50
|
+
nil
|
|
51
|
+
else
|
|
52
|
+
(_dsize - 128) / 32 # in 32nds of a point
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def lsize
|
|
57
|
+
case _size_select
|
|
58
|
+
when 100
|
|
59
|
+
_lsize_large_delta
|
|
60
|
+
when 101
|
|
61
|
+
nil
|
|
62
|
+
else
|
|
63
|
+
_size_select
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def point_size
|
|
68
|
+
-_point_size if _point_size != 0
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def options
|
|
72
|
+
_tag_options
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|