Class: PDF::Reader::ValidatingReceiver
- Inherits:
-
Object
- Object
- PDF::Reader::ValidatingReceiver
- Defined in:
- lib/pdf/reader/validating_receiver.rb
Overview
Page#walk will execute the content stream of a page, calling methods on a receiver class provided by the user. Each operator has a specific set of parameters it expects, and we wrap the users receiver class in this one to verify the PDF uses valid parameters.
Without these checks, users can’t be confident about the number of parameters they’ll receive for an operator, or what the type of those parameters will be. Everyone ends up building their own type safety guard clauses and it’s tedious.
Not all operators have type safety implemented yet, but we can expand the number over time.
Instance Method Summary collapse
-
#begin_inline_image(*args) ⇒ Object
: (*untyped) -> void.
-
#begin_inline_image_data(*args) ⇒ Object
: (*untyped) -> void.
-
#begin_text_object(*args) ⇒ Object
: (*untyped) -> void.
-
#concatenate_matrix(*args) ⇒ Object
: (*untyped) -> void.
-
#end_inline_image(*args) ⇒ Object
: (*untyped) -> void.
-
#end_text_object(*args) ⇒ Object
: (*untyped) -> void.
-
#initialize(wrapped) ⇒ ValidatingReceiver
constructor
: (untyped) -> void.
-
#invoke_xobject(*args) ⇒ Object
: (*untyped) -> void.
-
#method_missing(methodname, *args) ⇒ Object
: (Symbol, *untyped) -> void.
-
#move_text_position(*args) ⇒ Object
: (*untyped) -> void.
-
#move_text_position_and_set_leading(*args) ⇒ Object
: (*untyped) -> void.
-
#move_to_next_line_and_show_text(*args) ⇒ Object
: (*untyped) -> void.
-
#move_to_start_of_next_line(*args) ⇒ Object
: (*untyped) -> void.
-
#page=(page) ⇒ Object
: (PDF::Reader::Page) -> void.
-
#respond_to?(meth) ⇒ Boolean
: (untyped) -> bool.
-
#restore_graphics_state(*args) ⇒ Object
: (*untyped) -> void.
-
#save_graphics_state(*args) ⇒ Object
Graphics State Operators.
-
#set_character_spacing(*args) ⇒ Object
Text State Operators.
-
#set_horizontal_text_scaling(*args) ⇒ Object
: (*untyped) -> void.
-
#set_spacing_next_line_show_text(*args) ⇒ Object
: (*untyped) -> void.
-
#set_text_font_and_size(*args) ⇒ Object
: (*untyped) -> void.
-
#set_text_leading(*args) ⇒ Object
: (*untyped) -> void.
-
#set_text_matrix_and_text_line_matrix(*args) ⇒ Object
: (*untyped) -> void.
-
#set_text_rendering_mode(*args) ⇒ Object
: (*untyped) -> void.
-
#set_text_rise(*args) ⇒ Object
: (*untyped) -> void.
-
#set_word_spacing(*args) ⇒ Object
: (*untyped) -> void.
-
#show_text(*args) ⇒ Object
Text Showing Operators.
-
#show_text_with_positioning(*args) ⇒ Object
: (*untyped) -> void.
Constructor Details
#initialize(wrapped) ⇒ ValidatingReceiver
: (untyped) -> void
20 21 22 |
# File 'lib/pdf/reader/validating_receiver.rb', line 20 def initialize(wrapped) @wrapped = wrapped end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodname, *args) ⇒ Object
: (Symbol, *untyped) -> void
279 280 281 |
# File 'lib/pdf/reader/validating_receiver.rb', line 279 def method_missing(methodname, *args) @wrapped.send(methodname, *args) end |
Instance Method Details
#begin_inline_image(*args) ⇒ Object
: (*untyped) -> void
248 249 250 |
# File 'lib/pdf/reader/validating_receiver.rb', line 248 def begin_inline_image(*args) call_wrapped(:begin_inline_image) end |
#begin_inline_image_data(*args) ⇒ Object
: (*untyped) -> void
253 254 255 256 257 |
# File 'lib/pdf/reader/validating_receiver.rb', line 253 def begin_inline_image_data(*args) # We can't use call_wrapped() here because sorbet won't allow splat args with a dynamic # number of elements @wrapped.begin_inline_image_data(*args) if @wrapped.respond_to?(:begin_inline_image_data) end |
#begin_text_object(*args) ⇒ Object
: (*untyped) -> void
65 66 67 |
# File 'lib/pdf/reader/validating_receiver.rb', line 65 def begin_text_object(*args) call_wrapped(:begin_text_object) end |
#concatenate_matrix(*args) ⇒ Object
: (*untyped) -> void
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pdf/reader/validating_receiver.rb', line 47 def concatenate_matrix(*args) a, b, c, d, e, f = *args call_wrapped( :concatenate_matrix, TypeCheck.cast_to_numeric!(a), TypeCheck.cast_to_numeric!(b), TypeCheck.cast_to_numeric!(c), TypeCheck.cast_to_numeric!(d), TypeCheck.cast_to_numeric!(e), TypeCheck.cast_to_numeric!(f), ) end |
#end_inline_image(*args) ⇒ Object
: (*untyped) -> void
260 261 262 263 264 265 266 267 |
# File 'lib/pdf/reader/validating_receiver.rb', line 260 def end_inline_image(*args) data, _ = *args call_wrapped( :end_inline_image, TypeCheck.cast_to_string!(data) ) end |
#end_text_object(*args) ⇒ Object
: (*untyped) -> void
70 71 72 |
# File 'lib/pdf/reader/validating_receiver.rb', line 70 def end_text_object(*args) call_wrapped(:end_text_object) end |
#invoke_xobject(*args) ⇒ Object
: (*untyped) -> void
234 235 236 237 238 239 240 241 |
# File 'lib/pdf/reader/validating_receiver.rb', line 234 def invoke_xobject(*args) label, _ = *args call_wrapped( :invoke_xobject, TypeCheck.cast_to_symbol(label) ) end |
#move_text_position(*args) ⇒ Object
: (*untyped) -> void
146 147 148 149 150 151 152 153 |
# File 'lib/pdf/reader/validating_receiver.rb', line 146 def move_text_position(*args) # Td x, y, _ = *args call_wrapped( :move_text_position, TypeCheck.cast_to_numeric!(x), TypeCheck.cast_to_numeric!(y) ) end |
#move_text_position_and_set_leading(*args) ⇒ Object
: (*untyped) -> void
156 157 158 159 160 161 162 163 |
# File 'lib/pdf/reader/validating_receiver.rb', line 156 def move_text_position_and_set_leading(*args) # TD x, y, _ = *args call_wrapped( :move_text_position_and_set_leading, TypeCheck.cast_to_numeric!(x), TypeCheck.cast_to_numeric!(y) ) end |
#move_to_next_line_and_show_text(*args) ⇒ Object
: (*untyped) -> void
210 211 212 213 214 215 216 |
# File 'lib/pdf/reader/validating_receiver.rb', line 210 def move_to_next_line_and_show_text(*args) # ' string, _ = *args call_wrapped( :move_to_next_line_and_show_text, TypeCheck.cast_to_string!(string) ) end |
#move_to_start_of_next_line(*args) ⇒ Object
: (*untyped) -> void
180 181 182 |
# File 'lib/pdf/reader/validating_receiver.rb', line 180 def move_to_start_of_next_line(*args) # T* call_wrapped(:move_to_start_of_next_line) end |
#page=(page) ⇒ Object
: (PDF::Reader::Page) -> void
25 26 27 |
# File 'lib/pdf/reader/validating_receiver.rb', line 25 def page=(page) call_wrapped(:page=, page) end |
#respond_to?(meth) ⇒ Boolean
: (untyped) -> bool
274 275 276 |
# File 'lib/pdf/reader/validating_receiver.rb', line 274 def respond_to?(meth) @wrapped.respond_to?(meth) end |
#restore_graphics_state(*args) ⇒ Object
: (*untyped) -> void
38 39 40 |
# File 'lib/pdf/reader/validating_receiver.rb', line 38 def restore_graphics_state(*args) call_wrapped(:restore_graphics_state) end |
#save_graphics_state(*args) ⇒ Object
Graphics State Operators
: (*untyped) -> void
33 34 35 |
# File 'lib/pdf/reader/validating_receiver.rb', line 33 def save_graphics_state(*args) call_wrapped(:save_graphics_state) end |
#set_character_spacing(*args) ⇒ Object
Text State Operators
: (*untyped) -> void
78 79 80 81 82 83 84 |
# File 'lib/pdf/reader/validating_receiver.rb', line 78 def set_character_spacing(*args) char_spacing, _ = *args call_wrapped( :set_character_spacing, TypeCheck.cast_to_numeric!(char_spacing) ) end |
#set_horizontal_text_scaling(*args) ⇒ Object
: (*untyped) -> void
87 88 89 90 91 92 93 |
# File 'lib/pdf/reader/validating_receiver.rb', line 87 def set_horizontal_text_scaling(*args) h_scaling, _ = *args call_wrapped( :set_horizontal_text_scaling, TypeCheck.cast_to_numeric!(h_scaling) ) end |
#set_spacing_next_line_show_text(*args) ⇒ Object
: (*untyped) -> void
219 220 221 222 223 224 225 226 227 |
# File 'lib/pdf/reader/validating_receiver.rb', line 219 def set_spacing_next_line_show_text(*args) # " aw, ac, string = *args call_wrapped( :set_spacing_next_line_show_text, TypeCheck.cast_to_numeric!(aw), TypeCheck.cast_to_numeric!(ac), TypeCheck.cast_to_string!(string) ) end |
#set_text_font_and_size(*args) ⇒ Object
: (*untyped) -> void
96 97 98 99 100 101 102 103 |
# File 'lib/pdf/reader/validating_receiver.rb', line 96 def set_text_font_and_size(*args) label, size, _ = *args call_wrapped( :set_text_font_and_size, TypeCheck.cast_to_symbol(label), TypeCheck.cast_to_numeric!(size) ) end |
#set_text_leading(*args) ⇒ Object
: (*untyped) -> void
106 107 108 109 110 111 112 |
# File 'lib/pdf/reader/validating_receiver.rb', line 106 def set_text_leading(*args) leading, _ = *args call_wrapped( :set_text_leading, TypeCheck.cast_to_numeric!(leading) ) end |
#set_text_matrix_and_text_line_matrix(*args) ⇒ Object
: (*untyped) -> void
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/pdf/reader/validating_receiver.rb', line 166 def set_text_matrix_and_text_line_matrix(*args) # Tm a, b, c, d, e, f = *args call_wrapped( :set_text_matrix_and_text_line_matrix, TypeCheck.cast_to_numeric!(a), TypeCheck.cast_to_numeric!(b), TypeCheck.cast_to_numeric!(c), TypeCheck.cast_to_numeric!(d), TypeCheck.cast_to_numeric!(e), TypeCheck.cast_to_numeric!(f), ) end |
#set_text_rendering_mode(*args) ⇒ Object
: (*untyped) -> void
115 116 117 118 119 120 121 |
# File 'lib/pdf/reader/validating_receiver.rb', line 115 def set_text_rendering_mode(*args) mode, _ = *args call_wrapped( :set_text_rendering_mode, TypeCheck.cast_to_numeric!(mode) ) end |
#set_text_rise(*args) ⇒ Object
: (*untyped) -> void
124 125 126 127 128 129 130 |
# File 'lib/pdf/reader/validating_receiver.rb', line 124 def set_text_rise(*args) rise, _ = *args call_wrapped( :set_text_rise, TypeCheck.cast_to_numeric!(rise) ) end |
#set_word_spacing(*args) ⇒ Object
: (*untyped) -> void
133 134 135 136 137 138 139 |
# File 'lib/pdf/reader/validating_receiver.rb', line 133 def set_word_spacing(*args) word_spacing, _ = *args call_wrapped( :set_word_spacing, TypeCheck.cast_to_numeric!(word_spacing) ) end |
#show_text(*args) ⇒ Object
Text Showing Operators
: (*untyped) -> void
188 189 190 191 192 193 194 |
# File 'lib/pdf/reader/validating_receiver.rb', line 188 def show_text(*args) # Tj (AWAY) string, _ = *args call_wrapped( :show_text, TypeCheck.cast_to_string!(string) ) end |
#show_text_with_positioning(*args) ⇒ Object
: (*untyped) -> void
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/pdf/reader/validating_receiver.rb', line 197 def show_text_with_positioning(*args) # TJ [(A) 120 (WA) 20 (Y)] params, _ = *args unless params.is_a?(Array) raise MalformedPDFError, "TJ operator expects a single Array argument" end call_wrapped( :show_text_with_positioning, params ) end |