Class: RRTF::Font
- Inherits:
-
Object
- Object
- RRTF::Font
- Defined in:
- lib/rrtf/font.rb
Overview
This class represents a font for use with some RTF content.
Constant Summary collapse
- MODERN =
A declaration for a font family. This family is used for monospaced fonts (e.g. Courier New).
:modern- ROMAN =
A declaration for a font family. This family is used for proportionally spaced serif fonts (e.g. Arial, Times New Roman).
:roman- SWISS =
A declaration for a font family. This family is used for proportionally spaced sans serif fonts (e.g. Tahoma, Lucida Sans).
:swiss- NIL =
A declaration for a font family. This family is used where none of the other families apply.
'nil'.intern
Instance Attribute Summary collapse
-
#family ⇒ Object
readonly
Attribute accessor.
-
#name ⇒ Object
readonly
Attribute accessor.
Class Method Summary collapse
-
.from_string(str) ⇒ Object
Format: “<FAMILY_CONSTANT>:<Name>”.
Instance Method Summary collapse
-
#==(object) ⇒ Object
This method overloads the equivalence test operator for the Font class to allow for Font comparisons.
-
#initialize(family, name) ⇒ Font
constructor
This is the constructor for the Font class.
-
#to_rtf(indent = 0) ⇒ Object
This method generates the RTF representation for a Font object as it would appear within a document font table.
-
#to_s(indent = 0) ⇒ Object
This method fetches a textual description for a Font object.
Constructor Details
#initialize(family, name) ⇒ Font
This is the constructor for the Font class.
Parameters
- family
-
The font family for the new font. This should be one of Font::MODERN, Font::ROMAN, Font::SWISS or Font::NIL.
- name
-
A string containing the font name.
Exceptions
- RTFError
-
Generated whenever an invalid font family is specified.
48 49 50 51 52 53 54 55 |
# File 'lib/rrtf/font.rb', line 48 def initialize(family, name) # Check that a valid family has been provided. if ![MODERN, ROMAN, SWISS, NIL].include?(family) RTFError::fire("Unknown font family specified for Font object.") end @family = family @name = name end |
Instance Attribute Details
#family ⇒ Object (readonly)
Attribute accessor.
24 25 26 |
# File 'lib/rrtf/font.rb', line 24 def family @family end |
#name ⇒ Object (readonly)
Attribute accessor.
24 25 26 |
# File 'lib/rrtf/font.rb', line 24 def name @name end |
Class Method Details
.from_string(str) ⇒ Object
Format: “<FAMILY_CONSTANT>:<Name>”
28 29 30 31 32 33 34 35 |
# File 'lib/rrtf/font.rb', line 28 def self.from_string(str) if str =~ /([a-z]+):(.+)/i parts = str.split(':') self.new(RRTF::Utilities.constantize("RRTF::Font::#{parts.first}"), parts.last) else RTFError.fire("Unreconized string font format '#{str}'.") end end |
Instance Method Details
#==(object) ⇒ Object
This method overloads the equivalence test operator for the Font class to allow for Font comparisons.
Parameters
- object
-
A reference to the object to be compared with.
62 63 64 65 66 |
# File 'lib/rrtf/font.rb', line 62 def ==(object) object.instance_of?(Font) && object.family == @family && object.name == @name end |
#to_rtf(indent = 0) ⇒ Object
This method generates the RTF representation for a Font object as it would appear within a document font table.
Parameters
- indent
-
The number of spaces to prefix to the lines generated by the method. Defaults to zero.
84 85 86 87 |
# File 'lib/rrtf/font.rb', line 84 def to_rtf(indent=0) prefix = indent > 0 ? ' ' * indent : '' "#{prefix}\\f#{@family.id2name} #{@name};" end |
#to_s(indent = 0) ⇒ Object
This method fetches a textual description for a Font object.
Parameters
- indent
-
The number of spaces to prefix to the lines generated by the method. Defaults to zero.
73 74 75 76 |
# File 'lib/rrtf/font.rb', line 73 def to_s(indent=0) prefix = indent > 0 ? ' ' * indent : '' "#{prefix}Family: #{@family.id2name}, Name: #{@name}" end |