Class: HexaPDF::Extras::Layout::QRCodeBox
- Inherits:
-
Layout::Box
- Object
- Layout::Box
- HexaPDF::Extras::Layout::QRCodeBox
- Defined in:
- lib/hexapdf/extras/layout/qr_code_box.rb
Overview
A QRCodeBox object is used for displaying a QR code.
The size of the QR code is determined by the width and height of the box (to be exact: by the smaller of the two values). The QR code is always placed at the top left corner of the box.
Internally, HexaPDF::Extras::GraphicObject::QRCode is used, so any option except at
and size
supported there can be used here.
Example:
#>pdf-composer100
composer.box(:qrcode, height: 50, data: 'Test', style: {position: :float})
composer.box(:qrcode, width: 20, data: 'Test', dark_color: 'red', style: {position: :float})
composer.box(:qrcode, width: 30, height: 50, data: 'Test', dark_color: 'green',
style: {position: :float})
composer.box(:qrcode, data: 'Test', dark_color: 'blue')
Instance Attribute Summary collapse
-
#qr_code ⇒ Object
readonly
The HexaPDF::Extras::GraphicObject::QRCode object that will be drawn.
Instance Method Summary collapse
-
#fit(available_width, available_height, _frame) ⇒ Object
Fits the QRCode into the given area.
-
#initialize(dark_color: nil, light_color: nil, data: nil, code_size: nil, max_code_size: nil, level: nil, mode: nil, **kwargs) ⇒ QRCodeBox
constructor
Creates a new QRCodeBox object with the given arguments (see HexaPDF::Extras::GraphicObject::QRCode for details).
Constructor Details
#initialize(dark_color: nil, light_color: nil, data: nil, code_size: nil, max_code_size: nil, level: nil, mode: nil, **kwargs) ⇒ QRCodeBox
Creates a new QRCodeBox object with the given arguments (see HexaPDF::Extras::GraphicObject::QRCode for details).
At least data
needs to be specified.
35 36 37 38 39 40 41 42 |
# File 'lib/hexapdf/extras/layout/qr_code_box.rb', line 35 def initialize(dark_color: nil, light_color: nil, data: nil, code_size: nil, max_code_size: nil, level: nil, mode: nil, **kwargs) super(**kwargs) @qr_code = HexaPDF::Extras::GraphicObject::QRCode.configure( dark_color: dark_color, light_color: light_color, data: data, code_size: code_size, max_code_size: max_code_size, level: level, mode: mode ) end |
Instance Attribute Details
#qr_code ⇒ Object (readonly)
The HexaPDF::Extras::GraphicObject::QRCode object that will be drawn.
29 30 31 |
# File 'lib/hexapdf/extras/layout/qr_code_box.rb', line 29 def qr_code @qr_code end |
Instance Method Details
#fit(available_width, available_height, _frame) ⇒ Object
Fits the QRCode into the given area.
45 46 47 48 49 50 |
# File 'lib/hexapdf/extras/layout/qr_code_box.rb', line 45 def fit(available_width, available_height, _frame) super @width = @height = [@width, @height].min @qr_code.size = [content_width, content_height].min @fit_successful = (@width <= available_width && @height <= available_height) end |