Class: SVGUtilities
- Inherits:
-
Object
- Object
- SVGUtilities
- Defined in:
- lib/IFMapper/SVGMapExporter.rb
Class Method Summary collapse
- .add_compass(svg) ⇒ Object
- .add_text(svg, x, y, font_size, text, opts, fill_colour) ⇒ Object
- .add_titles(svg, opts, x, y, font_size, mapname, mapcreator) ⇒ Object
- .break_text_lines(text, maxlinelength) ⇒ Object
- .get_compass_svg_group ⇒ Object
- .new_svg_doc(width, height) ⇒ Object
- .num_text_lines(text, maxlinelength) ⇒ Object
- .svg_add_script(svg, opts) ⇒ Object
Class Method Details
.add_compass(svg) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 91 def self.add_compass(svg) compassgroup = SVGUtilities::get_compass_svg_group() defs = svg.root.add_element "defs" defs.add_element compassgroup return svg end |
.add_text(svg, x, y, font_size, text, opts, fill_colour) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 28 def self.add_text( svg, x, y, font_size, text, opts, fill_colour ) if DEBUG_OUTPUT; puts "svg::FXMap::svg_draw_name_text:" end y = y + font_size t = svg.root.add_element "text", { "x" => x, "y" => y, "style" => "font-size:" + font_size.to_s() + "pt;fill:#" + fill_colour.to_s()} t.text = text return [svg, x, y] end |
.add_titles(svg, opts, x, y, font_size, mapname, mapcreator) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 147 def self.add_titles( svg, opts, x, y, font_size, mapname, mapcreator ) if DEBUG_OUTPUT; puts "svg::SVGUtilities::add_titles" end if opts['print_title'] == true if not mapname or mapname == '' if DEBUG_OUTPUT; puts "svg::SVGUtilities::add_titles:name is empty, not printing" end else svg, x, y = SVGUtilities::add_text(svg, x, y, font_size*1.5, mapname, opts, '000000') y = y + (opts['name_line_spacing'] * 4) end end if opts['print_creator'] == true if not mapcreator or mapcreator == '' if DEBUG_OUTPUT; puts "svg::SVGUtilities::add_titles:creator is empty, not printing" end else svg, x, y = SVGUtilities::add_text(svg, x, y, font_size*0.85, 'Map ' + opts['creator_prefix'] + mapcreator, opts, '000000') y = y + (opts['name_line_spacing'] * 4) end end return [svg, x, y] end |
.break_text_lines(text, maxlinelength) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 50 def self.break_text_lines( text, maxlinelength ) if DEBUG_OUTPUT; printf("SVGUtilities::break_text_lines:text=%s\r\n", text) end out = Array.new max_chars = maxlinelength words = text.split(" ") cur_str = "" words.each { |word| new_len = cur_str.length + word.length if DEBUG_OUTPUT; printf("SVGUtilities::break_text_lines:current word: %s :: new_len: %d\r\n", word, new_len) end new_len = cur_str.length + word.length if new_len <= max_chars cur_str = cur_str + word + " " else out << cur_str cur_str = "" + word + " " end } out << cur_str return out end |
.get_compass_svg_group ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 75 def self.get_compass_svg_group() file = File.new( "icons/compass.svg" ) doc = REXML::Document.new file newgroup = REXML::Element.new "g" newgroup.attributes["id"] = "compass" doc.root.elements.each {|elem| newgroup.add_element(elem) } return newgroup end |
.new_svg_doc(width, height) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 14 def self.new_svg_doc ( width, height) svg = REXML::Document.new svg << REXML::XMLDecl.new svg.add_element "svg", { "width" => width, "height" => height, "version" => "1.1", "xmlns" => "http://www.w3.org/2000/svg", "xmlns:xlink" => "http://www.w3.org/1999/xlink"} return svg end |
.num_text_lines(text, maxlinelength) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 42 def self.num_text_lines ( text, maxlinelength ) if text and not text == '' return SVGUtilities::break_text_lines(text.chomp().strip(), maxlinelength).length else return 0 end end |
.svg_add_script(svg, opts) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 102 def self.svg_add_script( svg, opts ) svg.root.attributes["onload"] = "Init(evt)" script = svg.root.add_element "script", { "type" => "text/ecmascript" } script.add( REXML::CData.new(" var SVGDocument = null; var SVGRoot = null; function Init(evt) { SVGDocument = evt.target.ownerDocument; SVGRoot = SVGDocument.documentElement; } function ToggleOpacity(evt, targetId) { var newTarget = evt.target; if (targetId) { newTarget = SVGDocument.getElementById(targetId); } var newValue = newTarget.getAttributeNS(null, 'opacity') if ('0' != newValue) { newValue = '0'; } else { newValue = '1'; } newTarget.setAttributeNS(null, 'opacity', newValue); if (targetId) { SVGDocument.getElementById(targetId + 'Exception').setAttributeNS(null, 'opacity', '1'); } } ")) return svg; end |