Class: Rpdfium::Form::Field
- Inherits:
-
Object
- Object
- Rpdfium::Form::Field
- Defined in:
- lib/rpdfium/form/form.rb
Overview
Wrapper per un widget di form. Si costruisce a partire da un’annotazione di tipo :widget e l’env del documento.
Constant Summary collapse
- TYPES =
{ Raw::FPDF_FORMFIELD_UNKNOWN => :unknown, Raw::FPDF_FORMFIELD_PUSHBUTTON => :pushbutton, Raw::FPDF_FORMFIELD_CHECKBOX => :checkbox, Raw::FPDF_FORMFIELD_RADIOBUTTON => :radiobutton, Raw::FPDF_FORMFIELD_COMBOBOX => :combobox, Raw::FPDF_FORMFIELD_LISTBOX => :listbox, Raw::FPDF_FORMFIELD_TEXTFIELD => :textfield, Raw::FPDF_FORMFIELD_SIGNATURE => :signature }.freeze
Instance Attribute Summary collapse
-
#annotation ⇒ Object
readonly
Returns the value of attribute annotation.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#checked? ⇒ Boolean
Per checkbox e radio.
- #flags ⇒ Object
-
#initialize(env, annotation) ⇒ Field
constructor
A new instance of Field.
- #name ⇒ Object
-
#options ⇒ Object
Per combobox/listbox.
-
#readonly? ⇒ Boolean
PDF spec §12.7.4.1: bit 1=read-only, bit 2=required, bit 3=no-export.
- #required? ⇒ Boolean
- #to_h ⇒ Object
- #type ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(env, annotation) ⇒ Field
Returns a new instance of Field.
67 68 69 70 |
# File 'lib/rpdfium/form/form.rb', line 67 def initialize(env, annotation) @env = env @annotation = annotation end |
Instance Attribute Details
#annotation ⇒ Object (readonly)
Returns the value of attribute annotation.
65 66 67 |
# File 'lib/rpdfium/form/form.rb', line 65 def annotation @annotation end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
65 66 67 |
# File 'lib/rpdfium/form/form.rb', line 65 def env @env end |
Instance Method Details
#checked? ⇒ Boolean
Per checkbox e radio
93 94 95 96 97 |
# File 'lib/rpdfium/form/form.rb', line 93 def checked? return false unless %i[checkbox radiobutton].include?(type) Raw.FPDFAnnot_IsChecked(@env.handle, @annotation.handle) == 1 end |
#flags ⇒ Object
84 85 86 |
# File 'lib/rpdfium/form/form.rb', line 84 def flags Raw.FPDFAnnot_GetFormFieldFlags(@env.handle, @annotation.handle) end |
#name ⇒ Object
76 77 78 |
# File 'lib/rpdfium/form/form.rb', line 76 def name Raw.read_utf16_string(:FPDFAnnot_GetFormFieldName, @env.handle, @annotation.handle) end |
#options ⇒ Object
Per combobox/listbox
100 101 102 103 104 105 106 107 108 |
# File 'lib/rpdfium/form/form.rb', line 100 def n = Raw.FPDFAnnot_GetOptionCount(@env.handle, @annotation.handle) return [] if n <= 0 Array.new(n) do |i| Raw.read_utf16_string(:FPDFAnnot_GetOptionLabel, @env.handle, @annotation.handle, i) end end |
#readonly? ⇒ Boolean
PDF spec §12.7.4.1: bit 1=read-only, bit 2=required, bit 3=no-export
89 |
# File 'lib/rpdfium/form/form.rb', line 89 def readonly?; (flags & (1 << 0)).positive?; end |
#required? ⇒ Boolean
90 |
# File 'lib/rpdfium/form/form.rb', line 90 def required?; (flags & (1 << 1)).positive?; end |
#to_h ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/rpdfium/form/form.rb', line 110 def to_h { name: name, type: type, value: value, readonly: readonly?, required: required?, checked: (%i[checkbox radiobutton].include?(type) ? checked? : nil), options: (%i[combobox listbox].include?(type) ? : nil), bbox: @annotation.bbox }.compact end |
#type ⇒ Object
72 73 74 |
# File 'lib/rpdfium/form/form.rb', line 72 def type TYPES[Raw.FPDFAnnot_GetFormFieldType(@env.handle, @annotation.handle)] || :unknown end |
#value ⇒ Object
80 81 82 |
# File 'lib/rpdfium/form/form.rb', line 80 def value Raw.read_utf16_string(:FPDFAnnot_GetFormFieldValue, @env.handle, @annotation.handle) end |