Class: Tabula::ObjectExtractor::RulingReceiver
- Inherits:
-
Object
- Object
- Tabula::ObjectExtractor::RulingReceiver
- Defined in:
- lib/tabula/pdf/object_extractor.rb
Overview
Receiver for extracting ruling lines from PDF graphics
Instance Attribute Summary collapse
-
#rulings ⇒ Object
readonly
Returns the value of attribute rulings.
Instance Method Summary collapse
- #append_line(x, y) ⇒ Object
- #append_rectangle(x, y, width, height) ⇒ Object
-
#begin_new_subpath(x, y) ⇒ Object
Path construction.
- #close_and_stroke_path ⇒ Object
- #close_fill_stroke ⇒ Object
- #close_path ⇒ Object
-
#concatenate_matrix(a, b, c, d, e, f) ⇒ Object
CTM operations.
- #end_path ⇒ Object
- #fill_path_with_even_odd ⇒ Object
- #fill_path_with_nonzero ⇒ Object
-
#initialize(page_height, y_inverted: false) ⇒ RulingReceiver
constructor
A new instance of RulingReceiver.
- #restore_graphics_state ⇒ Object
- #save_graphics_state ⇒ Object
-
#stroke_path ⇒ Object
Path painting.
Constructor Details
#initialize(page_height, y_inverted: false) ⇒ RulingReceiver
Returns a new instance of RulingReceiver.
199 200 201 202 203 204 205 206 207 |
# File 'lib/tabula/pdf/object_extractor.rb', line 199 def initialize(page_height, y_inverted: false) @page_height = page_height @y_inverted = y_inverted @rulings = [] @current_path = [] @subpaths = [] # Collect all subpaths for filling @ctm = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] @graphics_state_stack = [] end |
Instance Attribute Details
#rulings ⇒ Object (readonly)
Returns the value of attribute rulings.
197 198 199 |
# File 'lib/tabula/pdf/object_extractor.rb', line 197 def rulings @rulings end |
Instance Method Details
#append_line(x, y) ⇒ Object
216 217 218 |
# File 'lib/tabula/pdf/object_extractor.rb', line 216 def append_line(x, y) @current_path << [transform_point(x, y), :line] end |
#append_rectangle(x, y, width, height) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/tabula/pdf/object_extractor.rb', line 220 def append_rectangle(x, y, width, height) # Convert rectangle to four lines p1 = transform_point(x, y) p2 = transform_point(x + width, y) p3 = transform_point(x + width, y + height) p4 = transform_point(x, y + height) @current_path = [ [p1, :move], [p2, :line], [p3, :line], [p4, :line], [p1, :line] ] end |
#begin_new_subpath(x, y) ⇒ Object
Path construction
210 211 212 213 214 |
# File 'lib/tabula/pdf/object_extractor.rb', line 210 def begin_new_subpath(x, y) # Save current subpath if it has content @subpaths << @current_path.dup if @current_path.any? @current_path = [[transform_point(x, y), :move]] end |
#close_and_stroke_path ⇒ Object
270 271 272 273 |
# File 'lib/tabula/pdf/object_extractor.rb', line 270 def close_and_stroke_path close_path stroke_path end |
#close_fill_stroke ⇒ Object
275 276 277 278 |
# File 'lib/tabula/pdf/object_extractor.rb', line 275 def close_fill_stroke close_path stroke_path end |
#close_path ⇒ Object
284 285 286 287 288 289 |
# File 'lib/tabula/pdf/object_extractor.rb', line 284 def close_path return if @current_path.empty? first_point = @current_path.first[0] @current_path << [first_point, :line] end |
#concatenate_matrix(a, b, c, d, e, f) ⇒ Object
CTM operations
292 293 294 295 |
# File 'lib/tabula/pdf/object_extractor.rb', line 292 def concatenate_matrix(a, b, c, d, e, f) matrix = [[a, b, 0], [c, d, 0], [e, f, 1]] @ctm = matrix_multiply(matrix, @ctm) end |
#end_path ⇒ Object
280 281 282 |
# File 'lib/tabula/pdf/object_extractor.rb', line 280 def end_path @current_path = [] end |
#fill_path_with_even_odd ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/tabula/pdf/object_extractor.rb', line 256 def fill_path_with_even_odd # Include current path @subpaths << @current_path.dup if @current_path.any? # Process all subpaths @subpaths.each do |subpath| @current_path = subpath extract_rulings_from_filled_path end @current_path = [] @subpaths = [] end |
#fill_path_with_nonzero ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/tabula/pdf/object_extractor.rb', line 242 def fill_path_with_nonzero # Include current path @subpaths << @current_path.dup if @current_path.any? # Process all subpaths @subpaths.each do |subpath| @current_path = subpath extract_rulings_from_filled_path end @current_path = [] @subpaths = [] end |
#restore_graphics_state ⇒ Object
301 302 303 |
# File 'lib/tabula/pdf/object_extractor.rb', line 301 def restore_graphics_state @ctm = @graphics_state_stack.pop || [[1, 0, 0], [0, 1, 0], [0, 0, 1]] end |
#save_graphics_state ⇒ Object
297 298 299 |
# File 'lib/tabula/pdf/object_extractor.rb', line 297 def save_graphics_state @graphics_state_stack.push(@ctm.map(&:dup)) end |
#stroke_path ⇒ Object
Path painting
237 238 239 240 |
# File 'lib/tabula/pdf/object_extractor.rb', line 237 def stroke_path extract_lines_from_path @current_path = [] end |