Class: Prawn::Font Abstract
- Inherits:
-
Object
- Object
- Prawn::Font
- Defined in:
- lib/prawn/font.rb
Overview
Provides font information and helper functions.
Direct Known Subclasses
Experimental API collapse
- AFM =
Deprecated.
Prawn::Fonts::AFM
- TTF =
Deprecated.
Fonts::TTF
- DFont =
Deprecated.
Fonts::DFont
- TTC =
Deprecated.
Fonts::TTC
Experimental API collapse
-
#family ⇒ String
readonly
The font family.
-
#name ⇒ String
readonly
The font name.
-
#options ⇒ Hash
readonly
The options hash used to initialize the font.
Experimental API collapse
-
.load(document, src, options = {}) ⇒ Prawn::Fonts::Font
Shortcut interface for constructing a font object.
-
#add_to_current_page(subset) ⇒ void
Registers the given subset of the current font with the current PDF page.
-
#ascender ⇒ Number
The size of the font ascender in PDF points.
-
#descender ⇒ Number
The size of the font descender in PDF points.
-
#eql?(other) ⇒ Boolean
Compliments the #hash implementation.
-
#hash ⇒ Integer
Return a hash (as in
Object#hash
) for the font. -
#height ⇒ Number
Gets height of current font in PDF points at current font size.
-
#height_at(size) ⇒ Number
Gets height of font in PDF points at the given font size.
-
#inspect ⇒ String
Returns a string containing a human-readable representation of this font.
-
#line_gap ⇒ Number
The size of the recommended gap between lines of text in PDF points.
-
#normalize_encoding(string) ⇒ String
abstract
Normalizes the encoding of the string to an encoding supported by the font.
-
#normalize_encoding!(str) ⇒ String
deprecated
Deprecated.
Instance Attribute Details
#family ⇒ String (readonly)
The font family.
Source Code
359 | def family |
360 | @family
|
361 | end
|
#name ⇒ String (readonly)
The font name.
Source Code
355 | def name |
356 | @name
|
357 | end
|
#options ⇒ Hash (readonly)
The options hash used to initialize the font.
Source Code
363 | def options |
364 | @options
|
365 | end
|
Class Method Details
.load(document, src, options = {}) ⇒ Prawn::Fonts::Font
Source Code
377 | def self.load(document, src, options = {}) |
378 | case font_format(src, options) |
379 | when 'ttf' then TTF.new(document, src, options) |
380 | when 'otf' then Fonts::OTF.new(document, src, options) |
381 | when 'dfont' then DFont.new(document, src, options) |
382 | when 'ttc' then TTC.new(document, src, options) |
383 | else AFM.new(document, src, options) |
384 | end
|
385 | end
|
Instance Method Details
#add_to_current_page(subset) ⇒ void
This method returns an undefined value.
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.
Source Code
496 | def add_to_current_page(subset) |
497 | @references[subset] ||= register(subset) |
498 | @document.state.page.fonts[identifier_for(subset)] = @references[subset] |
499 | end
|
#ascender ⇒ Number
The size of the font ascender in PDF points.
Source Code
430 | def ascender |
431 | @ascender / 1000.0 * size |
432 | end
|
#descender ⇒ Number
The size of the font descender in PDF points.
Source Code
437 | def descender |
438 | -@descender / 1000.0 * size |
439 | end
|
#eql?(other) ⇒ Boolean
Compliments the #hash implementation.
Source Code
532 | def eql?(other) |
533 | self.class == other.class && name == other.name && |
534 | family == other.family && size == other.size |
535 | end
|
#hash ⇒ Integer
Return a hash (as in Object#hash
) for the font. This is required since
font objects are used as keys in hashes that cache certain values.
Source Code
524 | def hash |
525 | [self.class, name, family].hash |
526 | end
|
#height ⇒ Number
Gets height of current font in PDF points at current font size.
Source Code
486 | def height |
487 | height_at(size) |
488 | end
|
#height_at(size) ⇒ Number
Gets height of font in PDF points at the given font size.
Source Code
478 | def height_at(size) |
479 | @normalized_height ||= (@ascender - @descender + @line_gap) / 1000.0 |
480 | @normalized_height * size |
481 | end
|
#inspect ⇒ String
Returns a string containing a human-readable representation of this font.
Source Code
516 | def inspect |
517 | "#{self.class.name}< #{name}: #{size} >" |
518 | end
|
#line_gap ⇒ Number
The size of the recommended gap between lines of text in PDF points
Source Code
444 | def line_gap |
445 | @line_gap / 1000.0 * size |
446 | end
|
#normalize_encoding(string) ⇒ String
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.
Source Code
456 | def normalize_encoding(_string) |
457 | raise NotImplementedError, |
458 | 'subclasses of Prawn::Font must implement #normalize_encoding'
|
459 | end
|
#normalize_encoding!(str) ⇒ String
This method doesn’t mutate its argument any more.
Destructive version of #normalize_encoding; normalizes the encoding of a string in place.
Source Code
469 | def normalize_encoding!(str) |
470 | warn('Font#normalize_encoding! is deprecated. Please use non-mutating version Font#normalize_encoding instead.') |
471 | str.dup.replace(normalize_encoding(str)) |
472 | end
|