Class: DYI::Font
- Inherits:
-
Object
- Object
- DYI::Font
- Defined in:
- lib/dyi/font.rb,
lib/ironruby.rb
Overview
Constant Summary collapse
- IMPLEMENT_ATTRIBUTES =
[:font_family, :style, :variant, :weight, :size, :size_adjust, :stretch]
- VALID_VALUES =
{ :style => ['normal','italic','oblique'], :variant => ['normal','small-caps'], :weight => ['normal','bold','bolder','lighter','100','200','300','400','500','600','700','800','900'], :stretch => ['normal','wider','narrower','ultra-condensed','extra-condensed','condensed','semi-condensed','semi-expanded','expanded','extra-expanded','ultra-expanded'] }
- DEFAULT_SIZE =
Length.new(16)
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #draw_size ⇒ Object
- #empty? ⇒ Boolean
- #font_family=(value) ⇒ Object
-
#initialize(options = {}) ⇒ Font
constructor
A new instance of Font.
- #size=(value) ⇒ Object
- #size_adjust=(value) ⇒ Object
- #to_cls_font ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Font
Returns a new instance of Font.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dyi/font.rb', line 51 def initialize(={}) case when Font IMPLEMENT_ATTRIBUTES.each do |attr| instance_variable_set("@#{attr}", .__send__(attr)) end when Hash .each do |attr, value| __send__(attr.to_s + '=', value) if IMPLEMENT_ATTRIBUTES.include?(attr.to_sym) end else raise TypeError, "#{.class} can't be coerced into #{self.class}" end end |
Class Method Details
.new(*args) ⇒ Object
124 125 126 127 |
# File 'lib/dyi/font.rb', line 124 def new(*args) return args.first if args.size == 1 && args.first.instance_of?(self) super end |
.new_or_nil(*args) ⇒ Object
129 130 131 |
# File 'lib/dyi/font.rb', line 129 def new_or_nil(*args) (args.size == 1 && args.first.nil?) ? nil : new(*args) end |
.to_cls_font(font) ⇒ Object
124 125 126 |
# File 'lib/ironruby.rb', line 124 def to_cls_font(font) font ? font.to_cls_font : System::Drawing::Font.new('', DEFAULT_SIZE.to_f('pt')) end |
Instance Method Details
#attributes ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/dyi/font.rb', line 108 def attributes IMPLEMENT_ATTRIBUTES.inject({}) do |hash, attr| value = instance_variable_get("@#{attr}") hash[/^font_/ =~ attr.to_s ? attr : "font_#{attr}".to_sym] = value.to_s unless value.nil? hash end end |
#draw_size ⇒ Object
104 105 106 |
# File 'lib/dyi/font.rb', line 104 def draw_size @size || DEFAULT_SIZE end |
#empty? ⇒ Boolean
116 117 118 119 120 |
# File 'lib/dyi/font.rb', line 116 def empty? IMPLEMENT_ATTRIBUTES.all? do |attr| not instance_variable_get("@#{attr}") end end |
#font_family=(value) ⇒ Object
92 93 94 |
# File 'lib/dyi/font.rb', line 92 def font_family=(value) @font_family = value.to_s.size != 0 ? value.to_s : nil end |
#size=(value) ⇒ Object
96 97 98 |
# File 'lib/dyi/font.rb', line 96 def size=(value) @size = Length.new_or_nil(value) end |
#size_adjust=(value) ⇒ Object
100 101 102 |
# File 'lib/dyi/font.rb', line 100 def size_adjust=(value) @size_adjust = value ? value.to_f : nil end |
#to_cls_font ⇒ Object
119 120 121 |
# File 'lib/ironruby.rb', line 119 def to_cls_font System::Drawing::Font.new(font_family || '', size ? size.to_f : DEFAULT_SIZE.to_f('pt')) end |