Class: FXSection
- Defined in:
- lib/IFMapper/MapPrinting.rb,
lib/IFMapper/FXSection.rb,
lib/IFMapper/PDFMapExporter.rb,
lib/IFMapper/SVGMapExporter.rb,
lib/IFMapper/PDFMapExporter_prawn.rb,
lib/IFMapper/PDFMapExporter_pdfwriter.rb
Overview
Common printing add-ons
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#pxlen ⇒ Object
Returns the value of attribute pxlen.
-
#pylen ⇒ Object
Returns the value of attribute pylen.
-
#rotate ⇒ Object
Returns the value of attribute rotate.
-
#xoff ⇒ Object
Returns the value of attribute xoff.
-
#yoff ⇒ Object
Returns the value of attribute yoff.
Attributes inherited from Section
#comments, #connections, #name, #rooms
Instance Method Summary collapse
-
#initialize ⇒ FXSection
constructor
A new instance of FXSection.
- #new_connection(roomA, exitA, roomB, exitB = nil) ⇒ Object
- #new_room(x, y) ⇒ Object
- #pdf_draw(pdf, opts, mapname, pdflocationnos) ⇒ Object
- #pdf_draw_grid(pdf, opts, w, h) ⇒ Object
- #pdf_draw_section_name(pdf, opts, px, py) ⇒ Object
- #properties(map) ⇒ Object
- #svg_draw(svg, opts, x, y, mapname, section_idx) ⇒ Object
- #svg_draw_grid(pdf, opts, w, h) ⇒ Object
- #svg_draw_section_name(svg, opts, x, y) ⇒ Object
- #svg_draw_separate(opts, svgfile, section_idx, mapname, mapcreator) ⇒ Object
- #svg_height(opts) ⇒ Object
- #svg_width(opts) ⇒ Object
Methods inherited from Section
#delete_connection, #delete_connection_at, #delete_room, #delete_room_at, #delete_room_only, #free?, #marshal_dump, #marshal_load, #min_max_rooms, #rooms_width_height, #shift
Constructor Details
#initialize ⇒ FXSection
Returns a new instance of FXSection.
34 35 36 37 |
# File 'lib/IFMapper/FXSection.rb', line 34 def initialize() super @win = nil end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
4 5 6 |
# File 'lib/IFMapper/MapPrinting.rb', line 4 def page @page end |
#pxlen ⇒ Object
Returns the value of attribute pxlen.
4 5 6 |
# File 'lib/IFMapper/MapPrinting.rb', line 4 def pxlen @pxlen end |
#pylen ⇒ Object
Returns the value of attribute pylen.
4 5 6 |
# File 'lib/IFMapper/MapPrinting.rb', line 4 def pylen @pylen end |
#rotate ⇒ Object
Returns the value of attribute rotate.
4 5 6 |
# File 'lib/IFMapper/MapPrinting.rb', line 4 def rotate @rotate end |
#xoff ⇒ Object
Returns the value of attribute xoff.
4 5 6 |
# File 'lib/IFMapper/MapPrinting.rb', line 4 def xoff @xoff end |
#yoff ⇒ Object
Returns the value of attribute yoff.
4 5 6 |
# File 'lib/IFMapper/MapPrinting.rb', line 4 def yoff @yoff end |
Instance Method Details
#new_connection(roomA, exitA, roomB, exitB = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/IFMapper/FXSection.rb', line 7 def new_connection( roomA, exitA, roomB, exitB = nil ) # Verify rooms exist in section (ie. don't allow links across # sections) if not @rooms.include?(roomA) raise ConnectionError, "Room #{roomA} not in section #{self}" end if roomB and not @rooms.include?(roomB) raise ConnectionError, "Room #{roomB} not in section #{self}" end c = FXConnection.new( roomA, roomB ) return _new_connection(c, roomA, exitA, roomB, exitB) end |
#new_room(x, y) ⇒ Object
21 22 23 24 |
# File 'lib/IFMapper/FXSection.rb', line 21 def new_room(x, y) r = FXRoom.new( x, y, MSG_NEW_LOCATION ) return _new_room(r, x, y) end |
#pdf_draw(pdf, opts, mapname, pdflocationnos) ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 349 def pdf_draw(pdf, opts, mapname, pdflocationnos ) w, h = rooms_width_height x, y = [0, 0] loop do if rotate pdf.rotate_axis(90.0) pdf.translate_axis( 0, -pdf.page_height ) end # Move section to its position in page tx1, ty1 = [@xoff * opts['ww'], @yoff * -opts['hh']] pdf.translate_axis( tx1, ty1 ) # Use times-roman as font pdf.select_font 'Times-Roman' pdf.stroke_color(Color::RGB::Black) pdf.fill_color(Color::RGB::Black) pdf_draw_section_name( pdf, opts, x, y ) xymin, = min_max_rooms # Move rooms, so that we don't print empty areas tx2 = -(xymin[0]) * opts['ww'] - x * opts['ww'] ty2 = (xymin[1]) * opts['hh'] - 60 + (y - (y > 0? 1 : 0)) * opts['hh'] pdf.translate_axis( tx2, ty2 ) # For testing purposes only, draw grid of boxes # pdf_draw_grid( pdf, opts, w, h ) @connections.each { |c| a = c.roomA b = c.roomB next if a.y < y and b and b.y < y c.pdf_draw( pdf, opts ) } @rooms.each_with_index { |r, idx| next if r.y < y r.pdf_draw( pdf, opts, idx, pdflocationnos) } # Reset axis pdf.translate_axis(-tx2, -ty2) pdf.translate_axis(-tx1, -ty1) xi = opts['width'] yi = opts['height'] if rotate xi = (pdf.page_height / opts['ww']).to_i - 1 yi = (pdf.page_width / opts['hh']).to_i - 1 end x += xi if x >= w x = 0 y += yi break if y >= h end if rotate pdf.rotate_axis(-90.0) pdf.translate_axis( 0, pdf.page_height ) end # We could not fit all rooms in page. Start new page pdf.start_new_page end end |
#pdf_draw_grid(pdf, opts, w, h) ⇒ Object
324 325 326 327 328 329 330 331 332 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 324 def pdf_draw_grid(pdf, opts, w, h ) (0...w).each { |xx| (0...h).each { |yy| x = xx * opts['ww'] + opts['ws_2'] + opts['margin_2'] y = yy * opts['hh'] + opts['hs_2'] + opts['margin_2'] pdf.rectangle(x, y, opts['w'], opts['h']).stroke } } end |
#pdf_draw_section_name(pdf, opts, px, py) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/IFMapper/PDFMapExporter.rb', line 335 def pdf_draw_section_name( pdf, opts, px, py ) return if not @name or @name == '' xymin, xymax = min_max_rooms text = @name text += " (#{px}, #{py})" if px > 0 or py > 0 y = (opts['height']) * opts['hh'] + 16 w = xymax[0] w = opts['width'] if w > opts['width'] x = (w + 2) * opts['ww'] / 2 - text.size / 2 * 16 x = 0 if x < 0 pdf.add_text( x, y, text, 16 ) end |
#properties(map) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/IFMapper/FXSection.rb', line 26 def properties(map) if not @win @win = FXSectionDialogBox.new(map) end @win.copy_from(self) @win.show end |
#svg_draw(svg, opts, x, y, mapname, section_idx) ⇒ Object
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 794 def svg_draw(svg, opts, x, y, mapname, section_idx ) if DEBUG_OUTPUT; puts "svg::FXSection::svg_draw" end x, y = svg_draw_section_name( svg, opts, x, y ) origx = x origy = y @connections.each { |c| a = c.roomA b = c.roomB next if a.y < 0 and b and b.y < 0 c.svg_draw( svg, opts, x, y ) } @rooms.each_with_index { |r, idx| next if r.y < 0 r.svg_draw( svg, opts, idx, x, y) } # Add the compass displaying code in here so that it # is displayed beneath the interactive display items when # they are switched on. compass_scale_factor = opts['compass_size']; if(compass_scale_factor > 0) compassx = (x + opts['margin'] + (opts['w'] / 2))/compass_scale_factor compassy = ((y + svg_height(opts)) - opts['h'])/compass_scale_factor svg.root.add_element "use", { "x" => compassx, "y" => compassy, "xlink:href" => "#compass", "transform" => "scale(" + compass_scale_factor.to_s() + ")" } y = y + (64 * compass_scale_factor) end # # Iterate through the list of rooms a second time to # add the interactive elements (list of objects/tasks). # We do this as a second pass so that these objects a displayed # on top of the basic room objects. # if opts['draw_interactive'] == true if DEBUG_OUTPUT; puts "svg::FXSection::svg_draw::draw_interactive == true" end @rooms.each_with_index { |r, idx| if (!((opts['draw_connections'] == false) && (r.name =~ /Shortcut to.*/i))) r.svg_draw_interactive( svg, opts, idx, origx, origy, section_idx) end } end y = y + svg_height( opts ) return [x,y] end |
#svg_draw_grid(pdf, opts, w, h) ⇒ Object
728 729 730 731 732 733 734 735 736 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 728 def svg_draw_grid(pdf, opts, w, h ) if DEBUG_OUTPUT; puts "svg::FXSection::svg_draw_grid" end (0...w).each { |xx| (0...h).each { |yy| x = xx * opts['ww'] + opts['ws_2'] + opts['margin_2'] y = yy * opts['hh'] + opts['hs_2'] + opts['margin_2'] } } end |
#svg_draw_section_name(svg, opts, x, y) ⇒ Object
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 739 def svg_draw_section_name( svg, opts, x, y ) return [x,y] if not @name or @name == '' font_size = opts['name_font_size'] if opts['print_section_names'] == true svg, x, y = SVGUtilities::add_text( svg, x, y, font_size, @name, opts, '2F4F4F' ) y = y + opts['name_line_spacing'] end if opts['draw_sectioncomments'] == true if not @comments or @comments == '' if DEBUG_OUTPUT; puts "svg::FXSection::svg_draw_section_name:section comments is empty, not printing" end else num_chars_per_line = svg.root.attributes["width"].to_i() / (font_size*0.75) brokenlines = @comments.split(/\r?\n/); brokenlines.each {|brokenline| lines = SVGUtilities::break_text_lines(brokenline, num_chars_per_line); lines.each {|line| svg, x, y = SVGUtilities::add_text( svg, x, y, font_size*0.75, line, opts, '000000' ) y = y + (opts['name_line_spacing']) } y = y + (opts['name_line_spacing']) } end end y = y + (opts['name_line_spacing'] * 8) return [x,y] end |
#svg_draw_separate(opts, svgfile, section_idx, mapname, mapcreator) ⇒ Object
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 860 def svg_draw_separate(opts, svgfile, section_idx, mapname, mapcreator) if DEBUG_OUTPUT; puts "svg::FXSection::svg_draw_separate" end svg = SVGUtilities::new_svg_doc(svg_width(opts), svg_height(opts)) svg = SVGUtilities::add_compass(svg) if DEBUG_OUTPUT; printf("svg_draw_separate: section_idx = %s\r\n", section_idx.to_s()) end if opts['draw_interactive'] == true svg = SVGUtilities::svg_add_script(svg, opts) end x = opts['name_x'] + opts['margin'] y = opts['name_y'] + opts['margin'] font_size = opts['name_font_size'] svg, x, y = SVGUtilities::add_titles(svg, opts, x, y, font_size, mapname, mapcreator) x, y = svg_draw(svg, opts, x, y, svgfile, section_idx) svg.root.attributes["height"] = y formatter = REXML::Formatters::Pretty.new(2) formatter.compact = true file = File.open(svgfile, "w") file.puts formatter.write(svg, "") file.close if DEBUG_OUTPUT; printf("\r\n") end end |
#svg_height(opts) ⇒ Object
786 787 788 789 790 791 792 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 786 def svg_height( opts ) minmaxxy = min_max_rooms maxy = minmaxxy[1][1] sect_height = (maxy+2) * opts['hh'] return sect_height end |
#svg_width(opts) ⇒ Object
778 779 780 781 782 783 784 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 778 def svg_width( opts ) minmaxxy = min_max_rooms maxx = minmaxxy[1][0] sect_width = (maxx+4) * opts['ww'] return sect_width end |