Class: Rpdfium::TextPage
- Inherits:
-
Object
- Object
- Rpdfium::TextPage
- Defined in:
- lib/rpdfium/page.rb
Overview
Wrapper for FPDF_TEXTPAGE
Class Method Summary collapse
Instance Method Summary collapse
- #char_count ⇒ Object
- #close ⇒ Object
- #handle ⇒ Object
-
#initialize(page) ⇒ TextPage
constructor
A new instance of TextPage.
Constructor Details
#initialize(page) ⇒ TextPage
Returns a new instance of TextPage.
1643 1644 1645 1646 1647 1648 1649 |
# File 'lib/rpdfium/page.rb', line 1643 def initialize(page) handle = Raw.FPDFText_LoadPage(page.handle) raise PageError, 'Could not load text page' if handle.null? @state = { handle: handle, closed: false } ObjectSpace.define_finalizer(self, self.class.finalizer(@state)) end |
Class Method Details
.finalizer(state) ⇒ Object
1651 1652 1653 1654 1655 1656 1657 1658 1659 |
# File 'lib/rpdfium/page.rb', line 1651 def self.finalizer(state) proc do next if state[:closed] next if state[:handle].null? Raw.FPDFText_ClosePage(state[:handle]) state[:closed] = true end end |
Instance Method Details
#char_count ⇒ Object
1665 1666 1667 |
# File 'lib/rpdfium/page.rb', line 1665 def char_count Raw.FPDFText_CountChars(@state[:handle]) end |
#close ⇒ Object
1669 1670 1671 1672 1673 1674 1675 1676 |
# File 'lib/rpdfium/page.rb', line 1669 def close return if @state[:closed] Raw.FPDFText_ClosePage(@state[:handle]) unless @state[:handle].null? @state[:handle] = FFI::Pointer::NULL @state[:closed] = true ObjectSpace.undefine_finalizer(self) end |
#handle ⇒ Object
1661 1662 1663 |
# File 'lib/rpdfium/page.rb', line 1661 def handle @state[:handle] end |