Class: Wx::SF::Printout

Inherits:
PRT::Printout
  • Object
show all
Defined in:
lib/wx/shapes/printout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, canvas) ⇒ Printout

Constructor.

Parameters:

  • title (String)
  • canvas (ShapeCanvas)

    canvas to print



11
12
13
14
# File 'lib/wx/shapes/printout.rb', line 11

def initialize(title, canvas)
  super(title)
  @canvas = canvas
end

Instance Attribute Details

#canvasObject

Access (set/get) canvas (to be) printed.



17
18
19
# File 'lib/wx/shapes/printout.rb', line 17

def canvas
  @canvas
end

Instance Method Details

#get_page_infoObject

Called by printing framework. Supply information about printed pages. This function can be overridden if necessary.



117
118
119
# File 'lib/wx/shapes/printout.rb', line 117

def get_page_info
  [1,1,1,1]
end

#has_page(page) ⇒ Object

Called by printing framework. Functions TRUE if a page of given index already exists in printed document. This function can be overridden if necessary.



21
22
23
# File 'lib/wx/shapes/printout.rb', line 21

def has_page(page)
  page == 1
end

#on_begin_document(start_page, end_page) ⇒ Object

Called by printing framework. Initialize print job. This function can be overridden if necessary.



26
27
28
29
# File 'lib/wx/shapes/printout.rb', line 26

def on_begin_document(start_page, end_page)
  # HINT: perform custom actions...
  super
end

#on_end_documentObject

Called by printing framework. Deinitialize the print job. This function can be overridden if necessary.



32
33
34
35
# File 'lib/wx/shapes/printout.rb', line 32

def on_end_document
  # HINT: perform custom actions...
  super
end

#on_print_page(page) ⇒ Object

Called by printing framework. It does the print job. This function can be overridden if necessary.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/wx/shapes/printout.rb', line 38

def on_print_page(page)
  dc = get_dc
  if dc && @canvas
    # get drawing size
    total_bb = @canvas.get_total_bounding_box
    max_x = total_bb.right
    max_y = total_bb.bottom
  
    # set printing mode
    case @canvas.get_print_mode
    when ShapeCanvas::PRINTMODE::FIT_TO_PAGE
      fit_this_size_to_page([max_x, max_y])
      fit_rect = get_logical_page_rect

    when ShapeCanvas::PRINTMODE::FIT_TO_PAPER
      fit_this_size_to_paper([max_x, max_y])
      fit_rect = get_logical_paper_rect

    when ShapeCanvas::PRINTMODE::FIT_TO_MARGINS
      fit_this_size_to_page_margins([max_x, max_y], ShapeCanvas.page_setup_data)
      fit_rect = get_logical_page_margins_rect(ShapeCanvas.page_setup_data)

    when ShapeCanvas::PRINTMODE::MAP_TO_PAGE
      map_screen_size_to_page
      fit_rect = get_logical_page_rect

    when ShapeCanvas::PRINTMODE::MAP_TO_PAPER
      map_screen_size_to_paper
      fit_rect = get_logical_paper_rect

    when ShapeCanvas::PRINTMODE::MAP_TO_MARGINS
      map_screen_size_to_page
      fit_rect = get_logical_page_margins_rect(ShapeCanvas.page_setup_data)

    when ShapeCanvas::PRINTMODE::MAP_TO_DEVICE
      map_screen_size_to_device
      fit_rect = get_logical_page_rect

    else
      fit_rect = Wx::Rect.new
    end

    # This offsets the image so that it is centered within the reference
    # rectangle defined above.
    xoff = ((fit_rect.width - max_x - total_bb.left) / 2) - fit_rect.x
    yoff = ((fit_rect.height - max_y - total_bb.top) / 2) - fit_rect.y
  
    case @canvas.get_print_h_align
    when ShapeCanvas::HALIGN::LEFT
      xoff = 0
    when ShapeCanvas::HALIGN::RIGHT
      xoff = fit_rect.width - total_bb.width
    end
  
    case @canvas.get_print_v_align
    when ShapeCanvas::VALIGN::TOP
      yoff = 0
    when ShapeCanvas::VALIGN::BOTTOM
      yoff = fit_rect.height - total_bb.height
    end
  
    offset_logical_origin(xoff, yoff)
  
    # store current canvas properties
    prev_scale = @canvas.get_scale

    # draw the canvas content without any scale (dc is scaled by the printing framework)
    @canvas.set_scale(1.0)
    @canvas.draw_background(dc, NOT_FROM_PAINT) if @canvas.has_style?(ShapeCanvas::STYLE::PRINT_BACKGROUND)
    @canvas.draw_content(dc, NOT_FROM_PAINT)
    @canvas.draw_foreground(dc, NOT_FROM_PAINT)
    @canvas.set_scale(prev_scale)
  
    return true
  end
  false
end