Method: HexaPDF::Content::Canvas#initialize

Defined in:
lib/hexapdf/content/canvas.rb

#initialize(context) ⇒ Canvas

Creates a new Canvas object for the given context object (either a HexaPDF::Type::Page or a HexaPDF::Type::Form).

This method is usually not invoked directly but through HexaPDF::Type::Page#canvas or HexaPDF::Type::Form#canvas to make sure the contents of the canvas is properly assigned to the context object.

Examples:

doc = HexaPDF::Document.new
canvas = doc.pages.add.canvas


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/hexapdf/content/canvas.rb', line 292

def initialize(context)
  @context = context
  @operators = Operator::DEFAULT_OPERATORS.dup
  @graphics_state = GraphicsState.new
  @graphics_object = :none
  @font = nil
  @font_stack = []
  @serializer = HexaPDF::Serializer.new
  @current_point = [0, 0]
  @start_point = [0, 0]
  @contents = ''.b
  source = HexaPDF::Filter.source_from_proc do
    case graphics_object
    when :path, :clipping_path then end_path
    when :text then end_text
    end
    restore_graphics_state while graphics_state.saved_states?
    @contents
  end
  @stream_data = HexaPDF::StreamData.new(source)
end