Class: Prawn::Font
- Inherits:
-
Object
- Object
- Prawn::Font
- Defined in:
- lib/prawn/font.rb,
lib/prawn/font/afm.rb,
lib/prawn/font/ttf.rb,
lib/prawn/font/dfont.rb
Overview
Provides font information and helper functions.
Defined Under Namespace
Instance Attribute Summary collapse
-
#family ⇒ Object
readonly
The current font family.
-
#name ⇒ Object
readonly
The current font name.
-
#options ⇒ Object
readonly
The options hash used to initialize the font.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_to_current_page(subset) ⇒ Object
Registers the given subset of the current font with the current PDF page.
- #ascender ⇒ Object
- #descender ⇒ Object
-
#height ⇒ Object
Gets height of current font in PDF points at current font size.
- #height_at(size) ⇒ Object
- #identifier_for(subset) ⇒ Object
-
#initialize(document, name, options = {}) ⇒ Font
constructor
:nodoc:.
- #inspect ⇒ Object
- #line_gap ⇒ Object
-
#normalize_encoding(string) ⇒ Object
Normalizes the encoding of the string to an encoding supported by the font.
Constructor Details
#initialize(document, name, options = {}) ⇒ Font
:nodoc:
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/prawn/font.rb', line 220 def initialize(document,name,={}) #:nodoc: @document = document @name = name @options = @family = [:family] @document.proc_set :PDF, :Text @identifier = :"F#{@document.font_registry.size + 1}" @references = {} end |
Instance Attribute Details
#family ⇒ Object (readonly)
The current font family
206 207 208 |
# File 'lib/prawn/font.rb', line 206 def family @family end |
#name ⇒ Object (readonly)
The current font name
203 204 205 |
# File 'lib/prawn/font.rb', line 203 def name @name end |
#options ⇒ Object (readonly)
The options hash used to initialize the font
209 210 211 |
# File 'lib/prawn/font.rb', line 209 def @options end |
Class Method Details
.load(document, name, options = {}) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/prawn/font.rb', line 211 def self.load(document,name,={}) case name when /\.ttf$/ then TTF.new(document, name, ) when /\.dfont$/ then DFont.new(document, name, ) when /\.afm$/ then AFM.new(document, name, ) else AFM.new(document, name, ) end end |
Instance Method Details
#add_to_current_page(subset) ⇒ Object
Registers the given subset of the current font with the current PDF page. This is safe to call multiple times for a given font and subset, as it will only add the font the first time it is called.
275 276 277 278 |
# File 'lib/prawn/font.rb', line 275 def add_to_current_page(subset) @references[subset] ||= register(subset) @document.page_fonts.merge!(identifier_for(subset) => @references[subset]) end |
#ascender ⇒ Object
233 234 235 |
# File 'lib/prawn/font.rb', line 233 def ascender @ascender / 1000.0 * size end |
#descender ⇒ Object
237 238 239 |
# File 'lib/prawn/font.rb', line 237 def descender @descender / 1000.0 * size end |
#height ⇒ Object
Gets height of current font in PDF points at current font size
267 268 269 |
# File 'lib/prawn/font.rb', line 267 def height height_at(size) end |
#height_at(size) ⇒ Object
260 261 262 263 |
# File 'lib/prawn/font.rb', line 260 def height_at(size) @normalized_height ||= (@ascender - @descender + @line_gap) / 1000.0 @normalized_height * size end |
#identifier_for(subset) ⇒ Object
245 246 247 |
# File 'lib/prawn/font.rb', line 245 def identifier_for(subset) "#{@identifier}.#{subset}" end |
#inspect ⇒ Object
249 250 251 |
# File 'lib/prawn/font.rb', line 249 def inspect "#{self.class.name}< #{name}: #{size} >" end |
#line_gap ⇒ Object
241 242 243 |
# File 'lib/prawn/font.rb', line 241 def line_gap @line_gap / 1000.0 * size end |
#normalize_encoding(string) ⇒ Object
Normalizes the encoding of the string to an encoding supported by the font. The string is expected to be UTF-8 going in, and will be reencoded in-place (the argument will be modified directly). The return value is not defined.
256 257 258 |
# File 'lib/prawn/font.rb', line 256 def normalize_encoding(string) raise NotImplementedError, "subclasses of Prawn::Font must implement #normalize_encoding" end |