Method: HexaPDF::Content::Canvas#text_cursor

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

#text_cursorObject

:call-seq:

canvas.text_cursor     -> [x, y]

Returns the position of the text cursor, i.e. the origin of text space. This is where the first glyph of the next drawn text will be placed.

Note that this method can only be called while the current graphic object is a text object since the text matrix is otherwise undefined.

Examples:

#>pdf
canvas.font("Helvetica", size: 10)
canvas.text("Some sample text", at: [30, 150])
tx, ty = canvas.text_cursor                    # Cursor is directly after the text
canvas.stroke_color("hp-blue").
  circle(tx, ty, 0.5).
  circle(tx, ty, 5).stroke
canvas.text("Last cursor: (#{tx.round(2)}, #{ty.round(2)})", at: [30, 100])

See: #move_text_cursor



2212
2213
2214
2215
# File 'lib/hexapdf/content/canvas.rb', line 2212

def text_cursor
  raise_unless_in_text
  graphics_state.tm.evaluate(0, 0)
end