Class: FXSection
- Defined in:
- lib/IFMapper/MapPrinting.rb,
lib/IFMapper/FXSection.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, available_width) ⇒ Object
- #svg_draw_separate(opts, svgfile, section_idx, mapname, mapcreator, maxwidth) ⇒ 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.
8 9 10 |
# File 'lib/IFMapper/MapPrinting.rb', line 8 def page @page end |
#pxlen ⇒ Object
Returns the value of attribute pxlen.
8 9 10 |
# File 'lib/IFMapper/MapPrinting.rb', line 8 def pxlen @pxlen end |
#pylen ⇒ Object
Returns the value of attribute pylen.
8 9 10 |
# File 'lib/IFMapper/MapPrinting.rb', line 8 def pylen @pylen end |
#rotate ⇒ Object
Returns the value of attribute rotate.
8 9 10 |
# File 'lib/IFMapper/MapPrinting.rb', line 8 def rotate @rotate end |
#xoff ⇒ Object
Returns the value of attribute xoff.
8 9 10 |
# File 'lib/IFMapper/MapPrinting.rb', line 8 def xoff @xoff end |
#yoff ⇒ Object
Returns the value of attribute yoff.
8 9 10 |
# File 'lib/IFMapper/MapPrinting.rb', line 8 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
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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 369 def pdf_draw(pdf, opts, mapname, pdflocationnos ) w, h = rooms_width_height x, y = [0, 0] loop do pdf.save_graphics_state if rotate pdf.rotate 90.0 pdf.translate( 0, -pdf.margin_box.height ) end # Move section to its position in page tx1, ty1 = [@xoff * opts['ww'], @yoff * -opts['hh']] pdf.translate( tx1, ty1 ) # Use times-roman as font pdf.font 'Times-Roman' pdf.stroke_color '000000' 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( 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(-tx2, -ty2) pdf.translate(-tx1, -ty1) xi = opts['width'] yi = opts['height'] if rotate xi = (pdf.margin_box.height / opts['ww']).to_i - 1 yi = (pdf.margin_box.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(-90.0) pdf.translate( 0, pdf.page_height ) end pdf.restore_graphics_state # 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
344 345 346 347 348 349 350 351 352 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 344 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']) } } end |
#pdf_draw_section_name(pdf, opts, px, py) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/IFMapper/PDFMapExporter_prawn.rb', line 355 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.draw_text text, :at => [x,y], :font_size => 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
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 913 def svg_draw(svg, opts, x, y, mapname, section_idx ) if DEBUG_OUTPUT; puts "svg::FXSection::svg_draw" end if DEBUG_OUTPUT; printf(" current section: x=%f, y=%f\r\n", x, y) end sectionid = "section" + (section_idx + 1).to_s() if svg.root.elements["defs"] == nil svg.root.add_element "defs" end defs = svg.root.elements["defs"] defs << REXML::Comment.new(" #{MSG_SVG_MAP_SECT_BEGINS} (#{sectionid}) ") sectiongroup = REXML::Element.new "g" sectiongroup.attributes["id"] = sectionid sectionx = x; sectiony = y; x, y = svg_draw_section_name( sectiongroup, opts, 0, 0, svg.root.attributes["width"] ) origx = x origy = y @connections.each { |c| a = c.roomA b = c.roomB next if a.y < 0 and b and b.y < 0 if opts['current_section_only'] && (opts['selected_elements_only'] || opts['text_for_selected_only']) if c.selected c.svg_draw( sectiongroup, opts, x, y ) end else c.svg_draw( sectiongroup, opts, x, y ) end } @rooms.each_with_index { |r, idx| next if r.y < 0 if opts['current_section_only'] && opts['selected_elements_only'] if r.selected or idx == 0 r.svg_draw( sectiongroup, opts, idx, x, y) end else r.svg_draw( sectiongroup, opts, idx, x, y) end } # 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 sectiongroup.add_element "use", { "x" => compassx, "y" => compassy, "xlink:href" => "#compass", "transform" => "scale(" + compass_scale_factor.to_s() + ")" } y = y + (72 * 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 SVGUtilities::should_draw_interactive(opts) == 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 =~ /#{MSG_SVG_SHORTCUT_TO}.*/i))) if opts['current_section_only'] && opts['selected_elements_only'] if r.selected r.svg_draw_interactive( sectiongroup, opts, idx, origx, origy, section_idx) end else r.svg_draw_interactive( sectiongroup, opts, idx, origx, origy, section_idx) end end } end y = y + svg_height( opts ) svg.root.elements["defs"] << sectiongroup defs << REXML::Comment.new(" #{MSG_SVG_MAP_SECT_ENDS} (#{sectionid}) ") svg.root.add_element "use", { "x" => sectionx, "y" => sectiony, "xlink:href" => "#section" + (section_idx + 1).to_s() } return [x,y] end |
#svg_draw_grid(pdf, opts, w, h) ⇒ Object
847 848 849 850 851 852 853 854 855 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 847 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, available_width) ⇒ Object
858 859 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 892 893 894 895 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 858 def svg_draw_section_name( svg, opts, x, y, available_width ) 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 = (available_width.to_i / font_size*0.75).floor 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).to_i, 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, maxwidth) ⇒ Object
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 1022 def svg_draw_separate(opts, svgfile, section_idx, mapname, mapcreator, maxwidth) # Called from both: # Draw current section only to individual file # Draw all sections into individual files if DEBUG_OUTPUT; puts "svg::FXSection::svg_draw_separate" end svg = SVGUtilities::new_svg_doc(maxwidth, svg_height(opts)) if opts['compass_size'] > 0 svg = SVGUtilities::add_compass(svg) end if DEBUG_OUTPUT; printf("svg_draw_separate: section_idx = %s\r\n", section_idx.to_s()) end if SVGUtilities::should_draw_interactive(opts) == 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) outx, outy = svg_draw(svg, opts, x, y, svgfile, section_idx) y = y + outy; svg.root.attributes["height"] = y svg = SVGUtilities::add_background(svg, svg_width(opts).to_s, y.to_s, File.basename(svgfile, ".*")) formatter = REXML::Formatters::Pretty.new(2) formatter.compact = true file = File.open(svgfile, "w") formatter.write(svg, file) file.close if DEBUG_OUTPUT; printf("\r\n") end end |
#svg_height(opts) ⇒ Object
905 906 907 908 909 910 911 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 905 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
897 898 899 900 901 902 903 |
# File 'lib/IFMapper/SVGMapExporter.rb', line 897 def svg_width( opts ) minmaxxy = min_max_rooms maxx = minmaxxy[1][0] sect_width = (maxx+4) * opts['ww'] return sect_width end |