Class: HexaPDF::Layout::Frame::FitResult
- Inherits:
-
Object
- Object
- HexaPDF::Layout::Frame::FitResult
- Defined in:
- lib/hexapdf/layout/frame.rb
Overview
Stores the result of fitting a box in a Frame.
Instance Attribute Summary collapse
-
#available_height ⇒ Object
The available height in the frame for this particular box.
-
#available_width ⇒ Object
The available width in the frame for this particular box.
-
#box ⇒ Object
The box that was fitted into the frame.
-
#frame ⇒ Object
The frame into which the box was fitted.
-
#mask ⇒ Object
The rectangle (a Geom2D::Rectangle object) that will be removed from the frame when drawing the box.
-
#x ⇒ Object
The horizontal position where the box will be drawn.
-
#y ⇒ Object
The vertical position where the box will be drawn.
Instance Method Summary collapse
-
#draw(canvas, dx: 0, dy: 0) ⇒ Object
Draws the #box onto the canvas at (#x + dx, #y + dy).
-
#initialize(frame, box) ⇒ FitResult
constructor
Initialize the result object for the given frame and box.
-
#success! ⇒ Object
Marks the fitting status as success.
-
#success? ⇒ Boolean
Returns
trueif fitting was successful.
Constructor Details
#initialize(frame, box) ⇒ FitResult
Initialize the result object for the given frame and box.
117 118 119 120 121 122 123 |
# File 'lib/hexapdf/layout/frame.rb', line 117 def initialize(frame, box) @frame = frame @box = box @available_width = 0 @available_height = 0 @success = false end |
Instance Attribute Details
#available_height ⇒ Object
The available height in the frame for this particular box.
110 111 112 |
# File 'lib/hexapdf/layout/frame.rb', line 110 def available_height @available_height end |
#available_width ⇒ Object
The available width in the frame for this particular box.
107 108 109 |
# File 'lib/hexapdf/layout/frame.rb', line 107 def available_width @available_width end |
#box ⇒ Object
The box that was fitted into the frame.
98 99 100 |
# File 'lib/hexapdf/layout/frame.rb', line 98 def box @box end |
#frame ⇒ Object
The frame into which the box was fitted.
95 96 97 |
# File 'lib/hexapdf/layout/frame.rb', line 95 def frame @frame end |
#mask ⇒ Object
The rectangle (a Geom2D::Rectangle object) that will be removed from the frame when drawing the box.
114 115 116 |
# File 'lib/hexapdf/layout/frame.rb', line 114 def mask @mask end |
#x ⇒ Object
The horizontal position where the box will be drawn.
101 102 103 |
# File 'lib/hexapdf/layout/frame.rb', line 101 def x @x end |
#y ⇒ Object
The vertical position where the box will be drawn.
104 105 106 |
# File 'lib/hexapdf/layout/frame.rb', line 104 def y @y end |
Instance Method Details
#draw(canvas, dx: 0, dy: 0) ⇒ Object
Draws the #box onto the canvas at (#x + dx, #y + dy).
The relative offset (dx, dy) is useful when rendering results that were accumulated and then need to be moved because the container holding them changes its position.
The configuration option “debug” can be used to add visual debug output with respect to box placement.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/hexapdf/layout/frame.rb', line 142 def draw(canvas, dx: 0, dy: 0) doc = canvas.context.document if doc.config['debug'] name = (frame.parent_boxes + [box]).map do |box| box.class.to_s.sub(/.*::/, '') end.join('-') << "##{box.object_id}" name = "#{name} (#{(x + dx).to_i},#{(y + dy).to_i}-#{mask.width.to_i}x#{mask.height.to_i})" ocg = doc.optional_content.ocg(name) canvas.optional_content(ocg) do canvas.translate(dx, dy) do canvas.fill_color("green").stroke_color("darkgreen"). opacity(fill_alpha: 0.1, stroke_alpha: 0.2). draw(:geom2d, object: mask, path_only: true).fill_stroke end end page = "Page #{canvas.context.index + 1}" rescue "XObject" doc.optional_content.default_configuration.add_ocg_to_ui(ocg, path: ['Debug', page]) end box.draw(canvas, x + dx, y + dy) end |
#success! ⇒ Object
Marks the fitting status as success.
126 127 128 |
# File 'lib/hexapdf/layout/frame.rb', line 126 def success! @success = true end |
#success? ⇒ Boolean
Returns true if fitting was successful.
131 132 133 |
# File 'lib/hexapdf/layout/frame.rb', line 131 def success? @success end |