196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/chem_scanner/chem_draw/node/base_value.rb', line 196
def cdx_text(data)
style_runs = read_int(data[0, 2], true)
text_pos = style_runs * 10 + 2
plain = data[text_pos, data.size - text_pos]
styles = cdx_styles(data[2..-1], style_runs)
if styles.empty?
return [{ text: plain, font: 3, face: 0, size: 8, color: 0 }]
end
plain_arr = plain.dup.split("")
styled_text = []
styles.each_with_index do |style, idx|
t_start = style.delete(:start)
t_end = (styles[idx + 1] || {}).fetch(:start, plain.length)
text = plain_arr[t_start..t_end - 1].join("")
style[:text] = text
style[:size] = style[:size] / 20
styled_text.push(style)
end
styled_text
end
|