Class: Acrofill::Appearance
- Inherits:
-
Object
- Object
- Acrofill::Appearance
- Defined in:
- lib/acrofill/appearance.rb
Overview
Builds the /AP /N appearance stream (a Form XObject) for a filled text-field widget, honouring the field's /DA string and /Q alignment.
Defined Under Namespace
Classes: Box
Constant Summary collapse
- PADDING =
2.0- TOP_OFFSET =
pdftk offsets the first multiline row by 1pt from the box top.
1.0- DEFAULT_SIZE =
12.0- MIN_SIZE =
2.0- MAX_SIZE =
144.0- COLOR_OP_ARITY =
Colour-setting operators allowed in a /DA string, and their operand counts.
{ 'g' => 1, 'rg' => 3, 'k' => 4 }.freeze
- NUMERIC_OPERAND =
A plain PDF real; exponent notation is not valid PDF number syntax.
/\A-?\d*\.?\d+\z/
Instance Method Summary collapse
-
#build(field_node, widget, value, multiline: false, comb: nil) ⇒ Object
Returns a Reference to the new appearance XObject, or nil when the widget geometry is unusable.
-
#initialize(doc, acroform) ⇒ Appearance
constructor
A new instance of Appearance.
Constructor Details
#initialize(doc, acroform) ⇒ Appearance
Returns a new instance of Appearance.
21 22 23 24 25 |
# File 'lib/acrofill/appearance.rb', line 21 def initialize(doc, acroform) @doc = doc @acroform = acroform @fonts = Fonts.new(doc, acroform) end |
Instance Method Details
#build(field_node, widget, value, multiline: false, comb: nil) ⇒ Object
Returns a Reference to the new appearance XObject, or nil when the widget geometry is unusable.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/acrofill/appearance.rb', line 29 def build(field_node, , value, multiline: false, comb: nil) rect = @doc.normalized_box([:Rect] || @doc.inherited_value(field_node, :Rect)) return nil unless rect box = Box.new(rect[2] - rect[0], rect[3] - rect[1], alignment(field_node)) return nil if box.width <= 0 || box.height <= 0 font_name, size, color_ops = parse_da(field_node) font = @fonts.metrics(font_name) size, body = draw(value, font, size, box, multiline: multiline, comb: comb) @doc.add(StreamObject.new(appearance_dict(font_name, box), content(font_name, size, color_ops, body).b)) end |