mathtype 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +7 -0
  4. data/Rakefile +8 -0
  5. data/lib/file_parser/ole.rb +15 -0
  6. data/lib/file_parser/parser.rb +19 -0
  7. data/lib/file_parser/wmf.rb +28 -0
  8. data/lib/mathtype.rb +30 -7
  9. data/lib/mathtype/version.rb +1 -1
  10. data/lib/records/bintypes.rb +18 -0
  11. data/lib/records/mtef.rb +8 -114
  12. data/lib/records/nudge.rb +9 -5
  13. data/lib/records/ruler.rb +1 -1
  14. data/lib/records/typesizes.rb +5 -10
  15. data/lib/records3/char.rb +53 -0
  16. data/lib/records3/embell.rb +109 -0
  17. data/lib/records3/font.rb +27 -0
  18. data/lib/records3/line.rb +47 -0
  19. data/lib/records3/matrix.rb +80 -0
  20. data/lib/records3/mtef.rb +97 -0
  21. data/lib/records3/options.rb +5 -0
  22. data/lib/records3/pile.rb +43 -0
  23. data/lib/records3/size.rb +75 -0
  24. data/lib/records3/snapshot.rb +19 -0
  25. data/lib/records3/tmpl.rb +751 -0
  26. data/lib/{records → records5}/char.rb +6 -12
  27. data/lib/{records → records5}/color.rb +1 -1
  28. data/lib/{records → records5}/color_def.rb +8 -8
  29. data/lib/{records → records5}/embell.rb +2 -2
  30. data/lib/{records → records5}/encoding_def.rb +1 -1
  31. data/lib/{records → records5}/eqn_prefs.rb +2 -2
  32. data/lib/{records → records5}/font_def.rb +1 -1
  33. data/lib/{records → records5}/font_style_def.rb +1 -1
  34. data/lib/{records → records5}/future.rb +1 -1
  35. data/lib/{records → records5}/line.rb +3 -3
  36. data/lib/{records → records5}/matrix.rb +11 -3
  37. data/lib/records5/mtef.rb +129 -0
  38. data/lib/{records → records5}/pile.rb +2 -2
  39. data/lib/{records → records5}/size.rb +9 -7
  40. data/lib/records5/snapshot.rb +19 -0
  41. data/lib/{records → records5}/tmpl.rb +2 -2
  42. data/spec/fixtures/expected/mathtype3/ceil.xml +38 -0
  43. data/spec/fixtures/expected/mathtype3/fence.xml +77 -0
  44. data/spec/fixtures/expected/mathtype3/floor.xml +38 -0
  45. data/spec/fixtures/expected/mathtype3/frac.xml +136 -0
  46. data/spec/fixtures/expected/mathtype3/large_nudge.xml +135 -0
  47. data/spec/fixtures/expected/mathtype3/lim_embell.xml +247 -0
  48. data/spec/fixtures/expected/mathtype3/matrix_2x1.xml +500 -0
  49. data/spec/fixtures/expected/mathtype3/pile.xml +188 -0
  50. data/spec/fixtures/expected/mathtype3/sigma_subsup.xml +46 -0
  51. data/spec/fixtures/expected/mathtype3/small_nudge.xml +90 -0
  52. data/spec/fixtures/expected/mathtype3/sqrt.xml +132 -0
  53. data/spec/fixtures/expected/{299.xml → mathtype5/299.xml} +30 -15
  54. data/spec/fixtures/expected/{arrows.xml → mathtype5/arrows.xml} +30 -15
  55. data/spec/fixtures/expected/{embedded.xml → mathtype5/embedded.xml} +29 -14
  56. data/spec/fixtures/expected/{embellishments.xml → mathtype5/embellishments.xml} +30 -15
  57. data/spec/fixtures/expected/{equation1.xml → mathtype5/equation1.xml} +30 -15
  58. data/spec/fixtures/expected/{equation10.xml → mathtype5/equation10.xml} +30 -15
  59. data/spec/fixtures/expected/{equation11.xml → mathtype5/equation11.xml} +30 -15
  60. data/spec/fixtures/expected/{equation12.xml → mathtype5/equation12.xml} +30 -15
  61. data/spec/fixtures/expected/{equation13.xml → mathtype5/equation13.xml} +30 -15
  62. data/spec/fixtures/expected/{equation2.xml → mathtype5/equation2.xml} +30 -15
  63. data/spec/fixtures/expected/{equation3.xml → mathtype5/equation3.xml} +30 -15
  64. data/spec/fixtures/expected/{equation4.xml → mathtype5/equation4.xml} +30 -15
  65. data/spec/fixtures/expected/{equation5.xml → mathtype5/equation5.xml} +30 -15
  66. data/spec/fixtures/expected/{equation6.xml → mathtype5/equation6.xml} +30 -15
  67. data/spec/fixtures/expected/{equation7.xml → mathtype5/equation7.xml} +30 -15
  68. data/spec/fixtures/expected/{equation8.xml → mathtype5/equation8.xml} +30 -15
  69. data/spec/fixtures/expected/{equation9.xml → mathtype5/equation9.xml} +30 -15
  70. data/spec/fixtures/expected/{fences.xml → mathtype5/fences.xml} +30 -15
  71. data/spec/fixtures/expected/{integrals.xml → mathtype5/integrals.xml} +30 -15
  72. data/spec/fixtures/expected/mathtype5/matrix-border.xml +365 -0
  73. data/spec/fixtures/expected/mathtype5/matrix.xml +382 -0
  74. data/spec/fixtures/expected/{sizes.xml → mathtype5/sizes.xml} +30 -15
  75. data/spec/fixtures/input/mathtype3/ceil.bin +0 -0
  76. data/spec/fixtures/input/mathtype3/fence.bin +0 -0
  77. data/spec/fixtures/input/mathtype3/floor.bin +0 -0
  78. data/spec/fixtures/input/mathtype3/frac.bin +0 -0
  79. data/spec/fixtures/input/mathtype3/large_nudge.bin +0 -0
  80. data/spec/fixtures/input/mathtype3/lim_embell.bin +0 -0
  81. data/spec/fixtures/input/mathtype3/matrix_2x1.bin +0 -0
  82. data/spec/fixtures/input/mathtype3/pile.bin +0 -0
  83. data/spec/fixtures/input/mathtype3/sigma_subsup.bin +0 -0
  84. data/spec/fixtures/input/mathtype3/small_nudge.bin +0 -0
  85. data/spec/fixtures/input/mathtype3/sqrt.bin +0 -0
  86. data/spec/fixtures/input/{299.bin → mathtype5/299.bin} +0 -0
  87. data/spec/fixtures/input/{arrows.bin → mathtype5/arrows.bin} +0 -0
  88. data/spec/fixtures/input/{embedded.bin → mathtype5/embedded.bin} +0 -0
  89. data/spec/fixtures/input/{embellishments.bin → mathtype5/embellishments.bin} +0 -0
  90. data/spec/fixtures/input/{equation1.bin → mathtype5/equation1.bin} +0 -0
  91. data/spec/fixtures/input/{equation10.bin → mathtype5/equation10.bin} +0 -0
  92. data/spec/fixtures/input/{equation11.bin → mathtype5/equation11.bin} +0 -0
  93. data/spec/fixtures/input/{equation12.bin → mathtype5/equation12.bin} +0 -0
  94. data/spec/fixtures/input/{equation13.bin → mathtype5/equation13.bin} +0 -0
  95. data/spec/fixtures/input/{equation2.bin → mathtype5/equation2.bin} +0 -0
  96. data/spec/fixtures/input/{equation3.bin → mathtype5/equation3.bin} +0 -0
  97. data/spec/fixtures/input/{equation4.bin → mathtype5/equation4.bin} +0 -0
  98. data/spec/fixtures/input/{equation5.bin → mathtype5/equation5.bin} +0 -0
  99. data/spec/fixtures/input/{equation6.bin → mathtype5/equation6.bin} +0 -0
  100. data/spec/fixtures/input/{equation7.bin → mathtype5/equation7.bin} +0 -0
  101. data/spec/fixtures/input/{equation8.bin → mathtype5/equation8.bin} +0 -0
  102. data/spec/fixtures/input/{equation9.bin → mathtype5/equation9.bin} +0 -0
  103. data/spec/fixtures/input/{fences.bin → mathtype5/fences.bin} +0 -0
  104. data/spec/fixtures/input/{integrals.bin → mathtype5/integrals.bin} +0 -0
  105. data/spec/fixtures/input/mathtype5/matrix-border.bin +0 -0
  106. data/spec/fixtures/input/mathtype5/matrix.bin +0 -0
  107. data/spec/fixtures/input/{sizes.bin → mathtype5/sizes.bin} +0 -0
  108. data/spec/mathtype_spec.rb +11 -9
  109. data/test-mathtype.rb +2 -0
  110. metadata +168 -97
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 693d2bb86526597c9c9f40fd3eac1e639509a920
4
- data.tar.gz: ff96dd06f680570c21ba2372f6d4668ba4d61d87
3
+ metadata.gz: ff3d156bf0f845c0888bb780e84edc9150bbc0cd
4
+ data.tar.gz: a2de68f80bcd9c83217a3b58f29aeb388520f91e
5
5
  SHA512:
6
- metadata.gz: 08d635e3d187bcaf8fbb21b8be8be9b8fe21caf3e957cd026965d00fe48fb1e2a9442db99de1627767cf44b71dbb2f2bb922c377582cec48e1c9df8f966501e4
7
- data.tar.gz: cc098388343e636e9fb21777c1192d36dde9f9f7560503a1ab2a391a53dcab1367411bcfabecc243cf01209c4e9b0947871bd31b0200069ebd912920796c4730
6
+ metadata.gz: 27096fad9b7be819e96c584a1b79923aafc7f69ae51c34f0bc26b355908aaeedc1c39a7ba86534498e8db014dc31c8625d853d6d4932f542731b4c60a6c519c1
7
+ data.tar.gz: ae4a541eccaba74fed0b9809168edf56e078276f609cad9159747b40a13829379dd0559d6d2c4aa3a9bc2722f6c8d014789e04e2bca476c97480246b81ccca7c
data/.gitignore CHANGED
@@ -11,4 +11,7 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.gem
14
15
  mkmf.log
16
+ *~
17
+ #*#
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ task :default => :spec
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ rescue LoadError
9
+ end
10
+
@@ -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
@@ -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
- ole = Ole::Storage.open(equation, "rb+")
13
- eq = ole.file.read("Equation Native")[28..-1]
14
-
15
- data = Mathtype::Equation.read(eq).snapshot
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
- name = Mathtype::RECORD_NAMES[object[:record_type]]
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|
@@ -1,3 +1,3 @@
1
1
  module Mathtype
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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
@@ -1,68 +1,11 @@
1
- require_relative "end"
2
- require_relative "nudge"
3
- require_relative "ruler"
4
- require_relative "line"
5
- require_relative "embell"
6
- require_relative "char"
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
- stringz :application_key
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
@@ -12,7 +12,7 @@
12
12
  require_relative "snapshot"
13
13
 
14
14
  module Mathtype
15
- class Nudge < BinData::Record
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
- int16 :_large_dx, :onlyif => lambda { _small_dx == 128 }
24
- int16 :_large_dy, :onlyif => lambda { _small_dy == 128 }
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
- _small_dx == 128 ? _large_dx : (_small_dx - 128)
27
+ has_large_offset ? _large_dx : (_small_dx - 128)
28
28
  end
29
29
 
30
30
  def dy
31
- _small_dy == 128 ? _large_dy : (_small_dy - 128)
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
@@ -16,7 +16,7 @@ module Mathtype
16
16
 
17
17
  array :tab_stops, initial_length: :n_stops do
18
18
  int8 :tab_stop_type
19
- int16 :tab_stop
19
+ mtef16 :tab_stop
20
20
  end
21
21
  end
22
22
  end
@@ -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