lib/rsyntaxtree/tree_graph.rb
# Add the element into the tree (draw it)
Add the element into the tree (draw it)
Add the element into the tree ( draw it )
def draw_element(x, y, w, string, type)
    string = string.sub(/\^\z/){""}
    if (type == ETYPE_LEAF) and @leafstyle == "nothing"
      top = row2px(y - 1) + (@font_size * 1.5)
    else
      top   = row2px(y)
    end
    left   = x + @m[:b_side]
    bottom = top  + @e_height
    right  = left + w
    parts = string.split("_", 2)
    if(parts.length > 1 )
      main = parts[0].strip
      sub  = parts[1].gsub(/_/, " ").strip
    else
      main = parts[0].strip
      sub  = ""
    end
    if /\A\+(.+)\+\z/ =~ main
      main = $1
      main_decoration = OverlineDecoration
    elsif /\A\-(.+)\-\z/ =~ main
      main = $1
      main_decoration = UnderlineDecoration
    elsif /\A\=(.+)\=\z/ =~ main
      main = $1
      main_decoration = LineThroughDecoration
    else
      main_decoration = NoDecoration
    end
    if /\A\*\*\*(.+)\*\*\*\z/ =~ main
      main = $1
      if !@multibyte
        main_font = @font_itbd
      end
    elsif /\A\*\*(.+)\*\*\z/ =~ main
      main = $1
      if !@multibyte
        main_font = @font_bd
      end
    elsif /\A\*(.+)\*\z/ =~ main
      main = $1
      if !@multibyte
        main_font = @font_it
      end
    else
      main_font = @font
    end
    main_width = img_get_txt_width(main, main_font, @font_size)
    if /\A\+(.+)\+\z/ =~ sub
      sub = $1
      sub_decoration = OverlineDecoration
    elsif /\A\-(.+)\-\z/ =~ sub
      sub = $1
      @gc.decorate(UnderlineDecoration)
      sub_decoration = UnderlineDecoration
    elsif /\A\=(.+)\=\z/ =~ sub
      sub = $1
      sub_decoration = LineThroughDecoration
    else
      sub_decoration = NoDecoration
    end
    sub_font = @font
    if /\A\*\*\*(.+)\*\*\*\z/ =~ sub
      sub = $1
      if !@multibyte
        sub_font = @font_itbd
      end
    elsif /\A\*\*(.+)\*\*\z/ =~ sub
      sub = $1
      if !@multibyte
        sub_font = @font_bd
      end
    elsif /\A\*(.+)\*\z/ =~ sub
      sub = $1
      if !@multibyte
        sub_font = @font_it
      end
    else
      sub_font = @font
    end
    if sub != ""
      sub_width  = img_get_txt_width(sub.to_s, sub_font, @sub_size)
    else
      sub_width = 0
    end
    txt_width = main_width + sub_width
    txt_pos   = left + (right - left) / 2 - txt_width / 2
    if(type == ETYPE_LEAF)
      col = @col_leaf
    else
      col = @col_node
    end
    if(main[0].chr == "<" && main[-1].chr == ">")
      col = @col_trace
    end
    @gc.stroke("none")
    @gc.fill(col)
    @gc.pointsize(@font_size)
    main_x = txt_pos
    main_y = top + @e_height - @m[:e_padd]
    @gc.interline_spacing = -(@main_height / 3)
    @gc.font(main_font)
    @gc.decorate(main_decoration)
    @gc.text(main_x.ceil, main_y.ceil, main)
    if (sub.length > 0 )
      @gc.pointsize(@sub_size)
      sub_x = txt_pos + main_width + @sub_space_width
      sub_y = top + (@e_height - @m[:e_padd] + @sub_size / 2)
      @gc.font(sub_font)
      @gc.decorate(sub_decoration)
      @gc.text(sub_x.ceil, sub_y.ceil, sub)
    end
  end
def draw_element ( x , y , w , string , type ) string = string . sub ( / \^ \z / ) { "" } if ( type == ETYPE_LEAF ) and @leafstyle == "nothing" top = row2px ( y - 1 ) + ( @font_size * 1.5 ) else top = row2px ( y ) end left = x + @m [ :b_side ] bottom = top + @e_height right = left + w parts = string . split ( "_" , 2 ) if ( parts . length > 1 ) main = parts [ 0 ] . strip sub = parts [ 1 ] . gsub ( / _ / , " " ) . strip else main = parts [ 0 ] . strip sub = "" end if / \A \+ (.+) \+ \z / =~ main main = $1 main_decoration = OverlineDecoration elsif / \A \- (.+) \- \z / =~ main main = $1 main_decoration = UnderlineDecoration elsif / \A \= (.+) \= \z / =~ main main = $1 main_decoration = LineThroughDecoration else main_decoration = NoDecoration end if / \A \* \* \* (.+) \* \* \* \z / =~ main main = $1 if ! @multibyte main_font = @font_itbd end elsif / \A \* \* (.+) \* \* \z / =~ main main = $1 if ! @multibyte main_font = @font_bd end elsif / \A \* (.+) \* \z / =~ main main = $1 if ! @multibyte main_font = @font_it end else main_font = @font end main_width = img_get_txt_width ( main , main_font , @font_size ) if / \A \+ (.+) \+ \z / =~ sub sub = $1 sub_decoration = OverlineDecoration elsif / \A \- (.+) \- \z / =~ sub sub = $1 @gc . decorate ( UnderlineDecoration ) sub_decoration = UnderlineDecoration elsif / \A \= (.+) \= \z / =~ sub sub = $1 sub_decoration = LineThroughDecoration else sub_decoration = NoDecoration end sub_font = @font if / \A \* \* \* (.+) \* \* \* \z / =~ sub sub = $1 if ! @multibyte sub_font = @font_itbd end elsif / \A \* \* (.+) \* \* \z / =~ sub sub = $1 if ! @multibyte sub_font = @font_bd end elsif / \A \* (.+) \* \z / =~ sub sub = $1 if ! @multibyte sub_font = @font_it end else sub_font = @font end if sub != "" sub_width = img_get_txt_width ( sub . to_s , sub_font , @sub_size ) else sub_width = 0 end txt_width = main_width + sub_width txt_pos = left + ( right - left ) / 2 - txt_width / 2 if ( type == ETYPE_LEAF ) col = @col_leaf else col = @col_node end if ( main [ 0 ] . chr == "<" && main [ - 1 ] . chr == ">" ) col = @col_trace end @gc . stroke ( "none" ) @gc . fill ( col ) @gc . pointsize ( @font_size ) main_x = txt_pos main_y = top + @e_height - @m [ :e_padd ] @gc . interline_spacing = - ( @main_height / 3 ) @gc . font ( main_font ) @gc . decorate ( main_decoration ) @gc . text ( main_x . ceil , main_y . ceil , main ) if ( sub . length > 0 ) @gc . pointsize ( @sub_size ) sub_x = txt_pos + main_width + @sub_space_width sub_y = top + ( @e_height - @m [ :e_padd ] + @sub_size / 2 ) @gc . font ( sub_font ) @gc . decorate ( sub_decoration ) @gc . text ( sub_x . ceil , sub_y . ceil , sub ) end end
Add the element into the tree (draw it)
Add the element into the tree ( draw it )
# Calculate element dimensions and position # Split the string into the main part and the # subscript part of the element (if any) # Calculate text size for the main and the # subscript part of the element # symbols for underline/overline removed temporarily # Center text in the element # Select apropriate color # Draw main text # Draw subscript text
x
<not_specific>
y
<not_specific>
w
<not_specific>
string
<not_specific>
type
<not_specific>