Class: RTF::Font
- Inherits:
-
Object
- Object
- RTF::Font
- Defined in:
- lib/rtf/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.
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.
39 40 41 42 43 44 45 46 |
# File 'lib/rtf/font.rb', line 39 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.
26 27 28 |
# File 'lib/rtf/font.rb', line 26 def family @family end |
#name ⇒ Object (readonly)
Attribute accessor.
26 27 28 |
# File 'lib/rtf/font.rb', line 26 def name @name 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.
53 54 55 56 57 |
# File 'lib/rtf/font.rb', line 53 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.
75 76 77 78 |
# File 'lib/rtf/font.rb', line 75 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.
64 65 66 67 |
# File 'lib/rtf/font.rb', line 64 def to_s(indent=0) prefix = indent > 0 ? ' ' * indent : '' "#{prefix}Family: #{@family.id2name}, Name: #{@name}" end |