lib/rsyntaxtree/svg_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= "overline"
    elsif /\A\-(.+)\-\z/ =~ main
      main = $1
      main_decoration= "underline"
    elsif /\A\=(.+)\=\z/ =~ main
      main = $1
      main_decoration= "line-through"
    else
      main_decoration= ""
    end
    if /\A\*\*\*(.+)\*\*\*\z/ =~ main
      main = $1
      main_style = "font-style: italic"
      main_weight = "font-weight: bold"
    elsif /\A\*\*(.+)\*\*\z/ =~ main
      main = $1
      main_style = ""
      main_weight = "font-weight: bold"
    elsif /\A\*(.+)\*\z/ =~ main
      main = $1
      main_style = "font-style: italic"
      main_weight = ""
    else
      main_style = ""
      main_weight = ""
    end
    main_width = img_get_txt_width(main, @font, @font_size)
    if sub != ""
      if /\A\+(.+)\+\z/ =~ sub
        sub = $1
        sub_decoration= "overline"
      elsif /\A\-(.+)\-\z/ =~ sub
        sub = $1
        sub_decoration= "underline"
      elsif /\A\=(.+)\=\z/ =~ sub
        sub = $1
        sub_decoration= "line-through"
      else
        sub_decoration= ""
      end
      if /\A\*\*\*(.+)\*\*\*\z/ =~ sub
        sub = $1
        sub_style = "font-style: italic"
        sub_weight = "font-weight: bold"
      elsif /\A\*\*(.+)\*\*\z/ =~ sub
        sub = $1
        sub_style = ""
        sub_weight = "font-weight: bold"
      elsif /\A\*(.+)\*\z/ =~ sub
        sub = $1
        sub_style = "font-style: italic"
        sub_weight = ""
      else
        sub_style = ""
        sub_weight = ""
      end
      sub_width  = img_get_txt_width(sub.to_s,  @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
    main_data  = @text_styles.sub(/COLOR/, col)
    main_data  = main_data.sub(/FONT_SIZE/, @font_size.to_s)
    main_x = txt_pos
    main_y = top + @e_height - @m[:e_padd] * 1.5
    main_data  = main_data.sub(/X_VALUE/, main_x.to_s)
    main_data  = main_data.sub(/Y_VALUE/, main_y.to_s)
    @tree_data += main_data.sub(/TD/, "text-decoration='#{main_decoration}'")
      .sub(/ST/, main_style)
      .sub(/WA/, main_weight)
      .sub(/CONTENT/, main)
    sub_data  = @text_styles.sub(/COLOR/, col)
    sub_data  = sub_data.sub(/FONT_SIZE/, @sub_size.to_s)
    sub_x = main_x + main_width
    sub_y = top + (@e_height - @m[:e_padd] + @sub_size / 10)
    if (sub.length > 0 )
      sub_data   = sub_data.sub(/X_VALUE/, sub_x.ceil.to_s)
      sub_data   = sub_data.sub(/Y_VALUE/, sub_y.ceil.to_s)
      @tree_data += sub_data.sub(/TD/, "text-decoration='#{sub_decoration}'")
        .sub(/ST/, sub_style)
        .sub(/WA/, sub_weight)
        .sub(/CONTENT/, 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 = "overline" elsif / \A \- (.+) \- \z / =~ main main = $1 main_decoration = "underline" elsif / \A \= (.+) \= \z / =~ main main = $1 main_decoration = "line-through" else main_decoration = "" end if / \A \* \* \* (.+) \* \* \* \z / =~ main main = $1 main_style = "font-style: italic" main_weight = "font-weight: bold" elsif / \A \* \* (.+) \* \* \z / =~ main main = $1 main_style = "" main_weight = "font-weight: bold" elsif / \A \* (.+) \* \z / =~ main main = $1 main_style = "font-style: italic" main_weight = "" else main_style = "" main_weight = "" end main_width = img_get_txt_width ( main , @font , @font_size ) if sub != "" if / \A \+ (.+) \+ \z / =~ sub sub = $1 sub_decoration = "overline" elsif / \A \- (.+) \- \z / =~ sub sub = $1 sub_decoration = "underline" elsif / \A \= (.+) \= \z / =~ sub sub = $1 sub_decoration = "line-through" else sub_decoration = "" end if / \A \* \* \* (.+) \* \* \* \z / =~ sub sub = $1 sub_style = "font-style: italic" sub_weight = "font-weight: bold" elsif / \A \* \* (.+) \* \* \z / =~ sub sub = $1 sub_style = "" sub_weight = "font-weight: bold" elsif / \A \* (.+) \* \z / =~ sub sub = $1 sub_style = "font-style: italic" sub_weight = "" else sub_style = "" sub_weight = "" end sub_width = img_get_txt_width ( sub . to_s , @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 main_data = @text_styles . sub ( / COLOR / , col ) main_data = main_data . sub ( / FONT_SIZE / , @font_size . to_s ) main_x = txt_pos main_y = top + @e_height - @m [ :e_padd ] * 1.5 main_data = main_data . sub ( / X_VALUE / , main_x . to_s ) main_data = main_data . sub ( / Y_VALUE / , main_y . to_s ) @tree_data += main_data . sub ( / TD / , "text-decoration='#{main_decoration}'" ) . sub ( / ST / , main_style ) . sub ( / WA / , main_weight ) . sub ( / CONTENT / , main ) sub_data = @text_styles . sub ( / COLOR / , col ) sub_data = sub_data . sub ( / FONT_SIZE / , @sub_size . to_s ) sub_x = main_x + main_width sub_y = top + ( @e_height - @m [ :e_padd ] + @sub_size / 10 ) if ( sub . length > 0 ) sub_data = sub_data . sub ( / X_VALUE / , sub_x . ceil . to_s ) sub_data = sub_data . sub ( / Y_VALUE / , sub_y . ceil . to_s ) @tree_data += sub_data . sub ( / TD / , "text-decoration='#{sub_decoration}'" ) . sub ( / ST / , sub_style ) . sub ( / WA / , sub_weight ) . sub ( / CONTENT / , 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>