mathtype 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff3d156bf0f845c0888bb780e84edc9150bbc0cd
|
4
|
+
data.tar.gz: a2de68f80bcd9c83217a3b58f29aeb388520f91e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27096fad9b7be819e96c584a1b79923aafc7f69ae51c34f0bc26b355908aaeedc1c39a7ba86534498e8db014dc31c8625d853d6d4932f542731b4c60a6c519c1
|
7
|
+
data.tar.gz: ae4a541eccaba74fed0b9809168edf56e078276f609cad9159747b40a13829379dd0559d6d2c4aa3a9bc2722f6c8d014789e04e2bca476c97480246b81ccca7c
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Rakefile
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bindata"
|
2
|
+
require "ole/storage"
|
3
|
+
|
4
|
+
module Mathtype
|
5
|
+
class OleFileParser < FileParser
|
6
|
+
def initialize(path)
|
7
|
+
read_from_file(path)
|
8
|
+
end
|
9
|
+
def read_from_file(path)
|
10
|
+
ole = Ole::Storage.open(path, "rb+")
|
11
|
+
@equation = ole.file.read("Equation Native")[28..-1]
|
12
|
+
ole.close
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mathtype
|
2
|
+
class FileParser
|
3
|
+
attr_reader :raw
|
4
|
+
attr_reader :equation
|
5
|
+
def initialize(path)
|
6
|
+
read_from_file(path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def read_from_file(path)
|
10
|
+
f = File.open(path, "rb")
|
11
|
+
@raw = f.read
|
12
|
+
f.close
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require_relative "wmf.rb"
|
18
|
+
require_relative "ole.rb"
|
19
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Mathtype
|
2
|
+
class WmfFileParser < FileParser
|
3
|
+
def initialize(path)
|
4
|
+
super(path)
|
5
|
+
extract_mtef_from_mfcomment(@raw)
|
6
|
+
end
|
7
|
+
|
8
|
+
def extract_mtef_from_mfcomment(comment)
|
9
|
+
match = comment.match("MathTypeUU")
|
10
|
+
if match
|
11
|
+
lenpos = match.end(0)
|
12
|
+
len = comment[lenpos..lenpos+1].unpack("H*")[0].to_i 16
|
13
|
+
start = lenpos + 2
|
14
|
+
else
|
15
|
+
match = comment.match("AppsMFCC\x01")
|
16
|
+
raise ::NotImplementedError, "No MathType Equation found in wmf" unless match
|
17
|
+
len_start = match.end(0)
|
18
|
+
totallen = comment[len_start..len_start + 3].reverse.chars.rotate(-1).join.unpack("H*")[0].to_i 16
|
19
|
+
datalen = comment[len_start + 4 .. len_start + 7].reverse.chars.rotate(-1).join.unpack("H*")[0].to_i 16
|
20
|
+
signature = comment[len_start + 8.. -1].match(/.+?\x00/)
|
21
|
+
raise ::NotImplementedError, "Equation split over multiple comments" unless totallen == datalen
|
22
|
+
start = len_start + 8 + signature.end(0)
|
23
|
+
len = datalen
|
24
|
+
end
|
25
|
+
@equation = comment[start..(start + len)]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/mathtype.rb
CHANGED
@@ -1,18 +1,28 @@
|
|
1
1
|
require "mathtype/version"
|
2
|
-
require "bindata"
|
3
|
-
require "ole/storage"
|
4
2
|
require "nokogiri"
|
3
|
+
require_relative "file_parser/parser.rb"
|
5
4
|
require_relative "records/mtef.rb"
|
5
|
+
require_relative "records3/mtef.rb"
|
6
|
+
require_relative "records5/mtef.rb"
|
7
|
+
|
6
8
|
|
7
9
|
module Mathtype
|
8
10
|
class Converter
|
11
|
+
attr_reader :parser
|
9
12
|
attr_reader :xml
|
10
13
|
attr_reader :builder
|
14
|
+
attr_reader :version
|
11
15
|
def initialize(equation)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
set_parser(equation)
|
17
|
+
raise ::NotImplementedError, "Only .wmf and .bin (OLE.-Object) currently supported, name supplied: #{equation}" unless @parser.equation
|
18
|
+
@version = @parser.equation[0].unpack('C')[0].to_i
|
19
|
+
raise ::NotImplementedError, "Only MTEF Version 3 and 5 currently supported, version is #{version}" unless (version==3 or version==5)
|
20
|
+
case @version
|
21
|
+
when 3
|
22
|
+
data = Mathtype3::Equation.read(@parser.equation).snapshot
|
23
|
+
when 5
|
24
|
+
data = Mathtype5::Equation.read(@parser.equation).snapshot
|
25
|
+
end
|
16
26
|
@builder = Nokogiri::XML::Builder.new do |xml|
|
17
27
|
@xml = xml
|
18
28
|
xml.root do
|
@@ -21,13 +31,26 @@ module Mathtype
|
|
21
31
|
end
|
22
32
|
end
|
23
33
|
|
34
|
+
def set_parser(equation)
|
35
|
+
if equation.end_with?(".bin")
|
36
|
+
@parser = Mathtype::OleFileParser.new equation
|
37
|
+
else equation.end_with?(".wmf")
|
38
|
+
@parser = Mathtype::WmfFileParser.new equation
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
24
42
|
def to_xml
|
25
43
|
@builder.to_xml
|
26
44
|
end
|
27
45
|
|
28
46
|
def process(element: "mtef", object:)
|
29
47
|
if object.is_a? Hash
|
30
|
-
|
48
|
+
case @version
|
49
|
+
when 3
|
50
|
+
name = Mathtype3::RECORD_NAMES[object[:record_type]]
|
51
|
+
else
|
52
|
+
name = Mathtype5::RECORD_NAMES[object[:record_type]]
|
53
|
+
end
|
31
54
|
if name
|
32
55
|
xml.send(name) do
|
33
56
|
(object[:payload] || {}).each do |k, v|
|
data/lib/mathtype/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Mathtype
|
2
|
+
class Mtef16 < BinData::Primitive
|
3
|
+
uint8 :low, :initial_value => 0
|
4
|
+
uint8 :high, :initial_value => 0
|
5
|
+
|
6
|
+
def get; (high << 8) + low end
|
7
|
+
def getlow
|
8
|
+
self.low
|
9
|
+
end
|
10
|
+
def gethigh
|
11
|
+
self.high
|
12
|
+
end
|
13
|
+
def set(v)
|
14
|
+
self.low = v & 0xFF
|
15
|
+
self.high = (v & 0xFF00) >> 8
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/records/mtef.rb
CHANGED
@@ -1,68 +1,11 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative "pile"
|
8
|
-
require_relative "tmpl"
|
9
|
-
require_relative "eqn_prefs"
|
10
|
-
require_relative "font_def"
|
11
|
-
require_relative "typesizes"
|
12
|
-
require_relative "font_style_def"
|
13
|
-
require_relative "matrix"
|
14
|
-
require_relative "encoding_def"
|
15
|
-
require_relative "embell"
|
16
|
-
require_relative "size"
|
17
|
-
require_relative "color"
|
18
|
-
require_relative "color_def"
|
19
|
-
require_relative "future"
|
1
|
+
require_relative 'snapshot'
|
2
|
+
require_relative 'bintypes'
|
3
|
+
require_relative 'end'
|
4
|
+
require_relative 'nudge'
|
5
|
+
require_relative 'ruler'
|
6
|
+
require_relative 'typesizes'
|
20
7
|
|
21
8
|
module Mathtype
|
22
|
-
RECORD_NAMES = {
|
23
|
-
0 => "end",
|
24
|
-
1 => "slot",
|
25
|
-
2 => "char",
|
26
|
-
3 => "tmpl",
|
27
|
-
4 => "pile",
|
28
|
-
5 => "matrix",
|
29
|
-
6 => "embell",
|
30
|
-
7 => "ruler",
|
31
|
-
8 => "font_style_def",
|
32
|
-
9 => "size",
|
33
|
-
10 => "full",
|
34
|
-
11 => "sub",
|
35
|
-
12 => "sub2",
|
36
|
-
13 => "sym",
|
37
|
-
14 => "subsym",
|
38
|
-
15 => "color",
|
39
|
-
16 => "color_def",
|
40
|
-
17 => "font_def",
|
41
|
-
18 => "eqn_prefs",
|
42
|
-
19 => "encoding_def",
|
43
|
-
100 => "future"
|
44
|
-
}
|
45
|
-
|
46
|
-
OPTIONS = {
|
47
|
-
# value => symbol # description
|
48
|
-
# Option flag values for all equation structure records:
|
49
|
-
"mtefOPT_NUDGE" => 0x08, # nudge values follow tag
|
50
|
-
# Option flag values for CHAR records:
|
51
|
-
"mtefOPT_CHAR_EMBELL" => 0x01, # character is followed by an embellishment list
|
52
|
-
"mtefOPT_CHAR_FUNC_START" => 0x02, # character starts a function (sin, cos, etc.)
|
53
|
-
"mtefOPT_CHAR_ENC_CHAR_8" => 0x04, # character is written with an 8-bit encoded value
|
54
|
-
"mtefOPT_CHAR_ENC_CHAR_16" => 0x10, # character is written with an 16-bit encoded value
|
55
|
-
"mtefOPT_CHAR_ENC_NO_MTCODE" => 0x20, # character is written without an 16-bit MTCode value
|
56
|
-
# Option flag values for LINE records:
|
57
|
-
"mtefOPT_LINE_NULL" => 0x01, # line is a placeholder only (i.e. not displayed)
|
58
|
-
"mtefOPT_LINE_LSPACE" => 0x04, # line spacing value follows tag
|
59
|
-
# Option flag values for LINE and PILE records:
|
60
|
-
"mtefOPT_LP_RULER" => 0x02, # RULER record follows LINE or PILE record
|
61
|
-
# Option flag values for COLOR_DEF records:
|
62
|
-
"mtefCOLOR_CMYK" => 0x01, # color model is CMYK, else RGB
|
63
|
-
"mtefCOLOR_SPOT" => 0x02, # color is a spot color, else a process color
|
64
|
-
"mtefCOLOR_NAME" => 0x04, # color has a name, else no name
|
65
|
-
}
|
66
9
|
|
67
10
|
HALIGN = {
|
68
11
|
1 => "left",
|
@@ -80,63 +23,14 @@ module Mathtype
|
|
80
23
|
4 => "axis" # math axis (center of +,-, brace points, etc.)
|
81
24
|
}
|
82
25
|
|
83
|
-
## Payload is the most important class to understand.
|
84
|
-
## This abstraction allows recursive formats.
|
85
|
-
## eg. lists can contain lists can contain lists.
|
86
|
-
|
87
|
-
class Payload < BinData::Choice
|
88
|
-
record_end 0 # end is a reserved keyword
|
89
|
-
record_line 1
|
90
|
-
record_char 2
|
91
|
-
record_tmpl 3
|
92
|
-
record_pile 4
|
93
|
-
record_matrix 5
|
94
|
-
record_embell 6
|
95
|
-
record_ruler 7
|
96
|
-
record_font_style_def 8
|
97
|
-
record_size 9
|
98
|
-
record_full 10
|
99
|
-
record_sub 11
|
100
|
-
record_sub2 12
|
101
|
-
record_sym 13
|
102
|
-
record_subsym 14
|
103
|
-
record_color 15
|
104
|
-
record_color_def 16
|
105
|
-
record_font_def 17
|
106
|
-
record_eqn_prefs 18
|
107
|
-
record_encoding_def 19
|
108
|
-
record_future 100
|
109
|
-
end
|
110
|
-
|
111
|
-
class NamedRecord < BinData::Record
|
112
|
-
int8 :record_type
|
113
|
-
payload :payload, :onlyif => :not_end_tag?, :selection => :record_type
|
114
|
-
|
115
|
-
def not_end_tag?
|
116
|
-
record_type != 0
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
26
|
class Equation < BinData::Record
|
121
|
-
include Snapshot
|
122
|
-
EXPOSED_IN_SNAPSHOT = %i(mtef_version platform product product_version
|
123
|
-
product_subversion application_key equation_options equation)
|
124
|
-
|
125
27
|
endian :little
|
126
28
|
uint8 :mtef_version
|
127
29
|
uint8 :platform
|
128
30
|
uint8 :product
|
129
31
|
uint8 :product_version
|
130
32
|
uint8 :product_subversion
|
131
|
-
|
132
|
-
uint8 :_equation_options
|
133
|
-
|
134
|
-
def equation_options
|
135
|
-
_equation_options == 1 ? "inline" : "block"
|
136
|
-
end
|
137
|
-
|
138
|
-
array :equation, read_until: lambda { element.record_type == 0 } do
|
139
|
-
named_record
|
140
|
-
end
|
33
|
+
include Snapshot
|
141
34
|
end
|
35
|
+
|
142
36
|
end
|
data/lib/records/nudge.rb
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
require_relative "snapshot"
|
13
13
|
|
14
14
|
module Mathtype
|
15
|
-
class
|
15
|
+
class RecordNudge < BinData::Record
|
16
16
|
include Snapshot
|
17
17
|
EXPOSED_IN_SNAPSHOT = %i(dx dy)
|
18
18
|
|
@@ -20,15 +20,19 @@ module Mathtype
|
|
20
20
|
|
21
21
|
int8 :_small_dx
|
22
22
|
int8 :_small_dy
|
23
|
-
|
24
|
-
|
23
|
+
mtef16 :_large_dx, :onlyif => lambda { has_large_offset }
|
24
|
+
mtef16 :_large_dy, :onlyif => lambda { has_large_offset }
|
25
25
|
|
26
26
|
def dx
|
27
|
-
|
27
|
+
has_large_offset ? _large_dx : (_small_dx - 128)
|
28
28
|
end
|
29
29
|
|
30
30
|
def dy
|
31
|
-
|
31
|
+
has_large_offset ? _large_dy : (_small_dy - 128)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_large_offset
|
35
|
+
_small_dx == -128 and _small_dy == -128
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
data/lib/records/ruler.rb
CHANGED
data/lib/records/typesizes.rb
CHANGED
@@ -7,18 +7,13 @@
|
|
7
7
|
# 11 means szSUB, and so on. See typesize.
|
8
8
|
|
9
9
|
module Mathtype
|
10
|
-
class RecordFull < BinData::Record
|
11
|
-
end
|
10
|
+
class RecordFull < BinData::Record; end
|
12
11
|
|
13
|
-
class RecordSub < BinData::Record
|
14
|
-
end
|
12
|
+
class RecordSub < BinData::Record; end
|
15
13
|
|
16
|
-
class RecordSub2 < BinData::Record
|
17
|
-
end
|
14
|
+
class RecordSub2 < BinData::Record; end
|
18
15
|
|
19
|
-
class RecordSym < BinData::Record
|
20
|
-
end
|
16
|
+
class RecordSym < BinData::Record; end
|
21
17
|
|
22
|
-
class RecordSubsym < BinData::Record
|
23
|
-
end
|
18
|
+
class RecordSubsym < BinData::Record; end
|
24
19
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# CHAR record (2):
|
2
|
+
# Consists of:
|
3
|
+
# record type (2)
|
4
|
+
# options
|
5
|
+
# [nudge] if mtefOPT_NUDGE is set
|
6
|
+
# [typeface] typeface value (signed integer; see FONT_STYLE_DEF record below)
|
7
|
+
# [character] character value (see below)
|
8
|
+
# [embellishment list] if mtefOPT_CHAR_EMBELL is set (embellishments)
|
9
|
+
# The character value itself is represented by one or more values. The presence or absence of these value is indicated by options and appear in this order:
|
10
|
+
# 16-bit integer MTCode value present unless the mtefOPT_CHAR_ENC_NO_MTCODE option is set
|
11
|
+
# 8-bit font position present if the mtefOPT_CHAR_ENC_CHAR_8 option is set
|
12
|
+
# 16-bit integer font position present if the mtefOPT_CHAR_ENC_CHAR_16 option is set
|
13
|
+
# The MTCode value defines the character independent of its font. MTCode is a superset of Unicode and is described in MTCode Encoding Tables. The 8-bit and 16-bit font positions are mutually exclusive but may both be absent. This is the position of the character within its font. Some of the common font encodings are given in Font Encoding Tables.
|
14
|
+
|
15
|
+
require_relative "snapshot"
|
16
|
+
|
17
|
+
module Mathtype3
|
18
|
+
class RecordEmbell < BinData::Record; end
|
19
|
+
class RecordChar < BinData::Record
|
20
|
+
include Snapshot
|
21
|
+
EXPOSED_IN_SNAPSHOT = %i(options nudge typeface mt_code_value embellishment_list)
|
22
|
+
|
23
|
+
endian :little
|
24
|
+
|
25
|
+
mandatory_parameter :_options
|
26
|
+
|
27
|
+
virtual :_tag_options, :value => lambda{ _options }
|
28
|
+
|
29
|
+
record_nudge :nudge, onlyif: lambda { _options & OPTIONS["xfLMOVE"] > 0 }
|
30
|
+
|
31
|
+
int8 :_typeface
|
32
|
+
|
33
|
+
mtef16 :_mt_code_value
|
34
|
+
|
35
|
+
array :embellishment_list,
|
36
|
+
onlyif: lambda { _options & OPTIONS["xfEMBELL"] > 0 },
|
37
|
+
read_until: lambda { element.record_type == 0 } do
|
38
|
+
named_record
|
39
|
+
end
|
40
|
+
|
41
|
+
def mt_code_value
|
42
|
+
sprintf("0x%04X", _mt_code_value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def typeface
|
46
|
+
_typeface + 128
|
47
|
+
end
|
48
|
+
|
49
|
+
def options
|
50
|
+
_tag_options
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|