Class: Prawn::Icon
- Inherits:
-
Object
- Object
- Prawn::Icon
- Defined in:
- lib/prawn/icon/interface.rb,
lib/prawn/icon/base.rb,
lib/prawn/icon/errors.rb,
lib/prawn/icon/parser.rb,
lib/prawn/icon/version.rb,
lib/prawn/icon/font_data.rb
Overview
Easy icon font usage within Prawn. Currently supported icon fonts include: FontAwesome, Zurb Foundicons and PaymentFont.
Icon Keys
Icon keys must be supplied to most Prawn::Icon
methods. Keys map directly to a unicode character within the font that produces a given icon. As a rule, included icon keys should match the keys from the font provider. The icon key mapping is specified in the font’s legend_file
, which is a YAML
file located in Prawn::Icon::Base::FONTDIR/font/font.yml.
- Prawn::Icon
-
Houses the methods and interfaces necessary for rendering icons to the Prawn::Document.
- Prawn::Icon::FontData
-
Used to store various information about an icon font, including the key-to-unicode mapping information. Also houses methods to cache and lazily load the requested font data on a document basis.
- Prawn::Icon::Parser
-
Used to initially parse icons that are used with the inline_format: true option. The input string is parsed once for <icon></icon> tags, then the output is provided to Prawn’s internal formatted text parser.
Defined Under Namespace
Modules: Base, Errors, Interface Classes: FontData, Parser
Constant Summary collapse
Instance Attribute Summary collapse
-
#set ⇒ Object
readonly
Returns the value of attribute set.
-
#unicode ⇒ Object
readonly
Returns the value of attribute unicode.
Instance Method Summary collapse
- #format_hash ⇒ Object
-
#initialize(key, document, opts = {}) ⇒ Icon
constructor
A new instance of Icon.
- #render ⇒ Object
Constructor Details
#initialize(key, document, opts = {}) ⇒ Icon
Returns a new instance of Icon.
177 178 179 180 181 182 183 184 185 |
# File 'lib/prawn/icon/interface.rb', line 177 def initialize(key, document, opts = {}) @pdf = document @set = opts[:set] || FontData.specifier_from_key(key) @data = FontData.load(document, @set) @key = strip_specifier_from_key(key) @unicode = @data.unicode(@key) @options = opts end |
Instance Attribute Details
#set ⇒ Object (readonly)
Returns the value of attribute set.
175 176 177 |
# File 'lib/prawn/icon/interface.rb', line 175 def set @set end |
#unicode ⇒ Object (readonly)
Returns the value of attribute unicode.
175 176 177 |
# File 'lib/prawn/icon/interface.rb', line 175 def unicode @unicode end |
Instance Method Details
#format_hash ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/prawn/icon/interface.rb', line 187 def format_hash base = { font: @set.to_s, content: @unicode } opts = @options.dup # Prawn::Table renames :color to :text_color opts[:text_color] = opts.delete(:color) base.merge(opts) end |
#render ⇒ Object
195 196 197 198 199 |
# File 'lib/prawn/icon/interface.rb', line 195 def render @pdf.font(@data.path) do @pdf.text @unicode, @options end end |