Class: ChemScanner::ChemDraw::Text
- Defined in:
- lib/chem_scanner/chem_draw/node/text.rb
Overview
Text parser
Constant Summary collapse
- GREEK_CHARS =
{ "A" => "Α", "a" => "α", "B" => "Β", "b" => "β", "G" => "Γ", "g" => "γ", "D" => "Δ", "d" => "δ", "E" => "Ε", "e" => "ε", "Z" => "Ζ", "z" => "ζ", "H" => "Η", "h" => "η", "Q" => "Θ", "q" => "θ", "I" => "Ι", "i" => "ι", "K" => "Κ", "k" => "κ", "L" => "Λ", "l" => "λ", "M" => "Μ", "m" => "μ", "N" => "Ν", "n" => "ν", "C" => "Ξ", "c" => "ξ", "O" => "Ο", "o" => "ο", "P" => "Π", "p" => "π", "R" => "Ρ", "r" => "ρ", "S" => "Σ", "s" => "σ", "T" => "Τ", "t" => "τ", "U" => "Υ", "u" => "υ", "F" => "Φ", "f" => "φ", "X" => "Χ", "x" => "χ", "Y" => "Ψ", "y" => "ψ", "W" => "Ω", "w" => "ω", }.freeze
- BOLD_VAL =
0x01
- FONT_KEY =
"face"
- COLOR_KEY =
"color"
Constants included from BaseValue
BaseValue::ARROW_NOGO_CROSS, BaseValue::CDXML_ARROW_TYPE, BaseValue::CDXML_ATOM_EXTERNAL_CONNECTION_TYPE, BaseValue::CDXML_CDX_POINT, BaseValue::CDXML_GRAPHIC_TYPE, BaseValue::CDXML_LINE_TYPE, BaseValue::CDXML_NODE_TYPE, BaseValue::CDXML_ORBITAL_TYPE, BaseValue::CDXML_OVAL_TYPE, BaseValue::TEXT_ATTRIBUTES
Instance Attribute Summary collapse
-
#bold_text ⇒ Object
Returns the value of attribute bold_text.
-
#center ⇒ Object
Returns the value of attribute center.
-
#non_bold_text ⇒ Object
Returns the value of attribute non_bold_text.
-
#polygon ⇒ Object
Returns the value of attribute polygon.
-
#styled_text ⇒ Object
Returns the value of attribute styled_text.
-
#value ⇒ Object
Returns the value of attribute value.
-
#warning ⇒ Object
Returns the value of attribute warning.
-
#warning_data ⇒ Object
Returns the value of attribute warning_data.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes inherited from BaseNode
Instance Method Summary collapse
- #bolded_styles ⇒ Object
-
#initialize(parser, parser_type, id, is_alias = false) ⇒ Text
constructor
A new instance of Text.
- #markdown ⇒ Object
- #parse_node(tag, _id, data) ⇒ Object
- #post_parse_node ⇒ Object
- #pre_parse_node ⇒ Object
- #remove_bold ⇒ Object
Methods inherited from BaseNode
#assign_center, #bounding_box, #cdx_read, #cdxml_read, #center_x, #center_y, #get_tempid, #read, #set_cdx, #set_cdxml
Methods included from BaseValue
#binary_chunks, #cdx_styles, #cdx_text, #cdxml_text, #do_unhandled, #point_2d, #point_3d, #polygon_from_bb, #read_bounding_box, #read_ids, #read_int, #read_type, #read_value
Constructor Details
#initialize(parser, parser_type, id, is_alias = false) ⇒ Text
Returns a new instance of Text.
66 67 68 69 70 71 72 73 74 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 66 def initialize(parser, parser_type, id, is_alias = false) super(parser, parser_type, id) @warning = false @is_alias = is_alias @bold_text = "" @value = "" end |
Instance Attribute Details
#bold_text ⇒ Object
Returns the value of attribute bold_text.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def bold_text @bold_text end |
#center ⇒ Object
Returns the value of attribute center.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def center @center end |
#non_bold_text ⇒ Object
Returns the value of attribute non_bold_text.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def non_bold_text @non_bold_text end |
#polygon ⇒ Object
Returns the value of attribute polygon.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def polygon @polygon end |
#styled_text ⇒ Object
Returns the value of attribute styled_text.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def styled_text @styled_text end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def value @value end |
#warning ⇒ Object
Returns the value of attribute warning.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def warning @warning end |
#warning_data ⇒ Object
Returns the value of attribute warning_data.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def warning_data @warning_data end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 8 def y @y end |
Instance Method Details
#bolded_styles ⇒ Object
115 116 117 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 115 def bolded_styles @styled_text.select { |s| s[:bold] } end |
#markdown ⇒ Object
108 109 110 111 112 113 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 108 def markdown @styled_text.reduce("") do |md, style| md += style[:bold] ? "**#{style[:text]}**" : style[:text] md end end |
#parse_node(tag, _id, data) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 76 def parse_node(tag, _id, data) # NOTE: CDXML text does not have tag # "Text" below only happens for CDX case @props_ref[tag] when "Text" then @styled_text = cdx_text(data) when "2DPosition" then @x, @y = read_value(tag, data) when "BoundingBox" then @polygon = read_value(tag, data) when "ChemicalWarning" @warning = true @warning_data = data else do_unhandled(tag) end end |
#post_parse_node ⇒ Object
96 97 98 99 100 101 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 96 def post_parse_node process_style retrieve_bold_text @center = Geometry::Point.new(@x, @y) end |
#pre_parse_node ⇒ Object
90 91 92 93 94 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 90 def pre_parse_node return if @parser_type == "cdx" @styled_text = cdxml_text(@parser.reader) end |
#remove_bold ⇒ Object
103 104 105 106 |
# File 'lib/chem_scanner/chem_draw/node/text.rb', line 103 def remove_bold @styled_text.delete_if { |s| (s[:face] & 1) == 1 } process_style end |