Object
Provides font information and helper functions.
Shortcut interface for constructing a font object. Filenames of the form *.ttf will call Font::TTF.new, *.dfont Font::DFont.new, and anything else will be passed through to Font::AFM.new()
# File lib/prawn/font.rb, line 241
241: def self.load(document,name,options={})
242: case name
243: when /\.ttf$/ then TTF.new(document, name, options)
244: when /\.dfont$/ then DFont.new(document, name, options)
245: when /\.afm$/ then AFM.new(document, name, options)
246: else AFM.new(document, name, options)
247: end
248: end
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.
# File lib/prawn/font.rb, line 320
320: def add_to_current_page(subset)
321: @references[subset] ||= register(subset)
322: @document.state.page.fonts.merge!(identifier_for(subset) => @references[subset])
323: end
The size of the font ascender in PDF points
# File lib/prawn/font.rb, line 264
264: def ascender
265: @ascender / 1000.0 * size
266: end
The size of the font descender in PDF points
# File lib/prawn/font.rb, line 270
270: def descender
271: -@descender / 1000.0 * size
272: end
Gets height of current font in PDF points at current font size
# File lib/prawn/font.rb, line 312
312: def height
313: height_at(size)
314: end
Gets height of current font in PDF points at the given font size
# File lib/prawn/font.rb, line 305
305: def height_at(size)
306: @normalized_height ||= (@ascender - @descender + @line_gap) / 1000.0
307: @normalized_height * size
308: end
# File lib/prawn/font.rb, line 280
280: def identifier_for(subset)
281: "#{@identifier}.#{subset}".to_sym
282: end
# File lib/prawn/font.rb, line 284
284: def inspect
285: "#{self.class.name}< #{name}: #{size} >"
286: end
The size of the recommended gap between lines of text in PDF points
# File lib/prawn/font.rb, line 276
276: def line_gap
277: @line_gap / 1000.0 * size
278: end
Normalizes the encoding of the string to an encoding supported by the font. The string is expected to be UTF-8 going in. It will be re-encoded and the new string will be returned. For an in-place (destructive) version, see normalize_encoding!.
# File lib/prawn/font.rb, line 292
292: def normalize_encoding(string)
293: raise NotImplementedError, "subclasses of Prawn::Font must implement #normalize_encoding"
294: end
Destructive version of normalize_encoding; normalizes the encoding of a string in place.
# File lib/prawn/font.rb, line 299
299: def normalize_encoding!(str)
300: str.replace(normalize_encoding(str))
301: end
generate a font identifier that hasn’t been used on the curretn page yet
# File lib/prawn/font.rb, line 337
337: def generate_unique_id
338: offset, id = 0, nil
339:
340: while id.nil? || page_contains_font_id?(id)
341: offset += 1
342: id = :"F#{@document.font_registry.size + offset}"
343: end
344:
345: id
346: end
Returns true if the provided font identifier already exists in the document. This is used when adding new fonts to a document to ensure we don’t step on fonts imported from a template.
page_contains_font_id?("F1")
=> true
# File lib/prawn/font.rb, line 355
355: def page_contains_font_id?(id)
356: id = id.to_s
357: @document.state.page.fonts.keys.any? { |exist_id|
358: exist_id.to_s[0,id.size] == id
359: }
360: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.