Class: DYI::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/dyi/font.rb,
lib/ironruby.rb

Overview

Since:

  • 0.0.0

Constant Summary collapse

IMPLEMENT_ATTRIBUTES =

Since:

  • 0.0.0

[:font_family, :style, :variant, :weight, :size, :size_adjust, :stretch]
VALID_VALUES =

Since:

  • 0.0.0

{
  :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 =

Since:

  • 0.0.0

Length.new(16)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Font

Returns a new instance of Font.

Since:

  • 0.0.0



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dyi/font.rb', line 51

def initialize(options={})
  case options
  when Font
    IMPLEMENT_ATTRIBUTES.each do |attr|
      instance_variable_set("@#{attr}", options.__send__(attr))
    end
  when Hash
    options.each do |attr, value|
      __send__(attr.to_s + '=', value) if IMPLEMENT_ATTRIBUTES.include?(attr.to_sym)
    end
  else
    raise TypeError, "#{options.class} can't be coerced into #{self.class}"
  end
end

Class Method Details

.new(*args) ⇒ Object

Since:

  • 0.0.0



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

Since:

  • 0.0.0



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

Since:

  • 0.0.0



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

#attributesObject

Since:

  • 0.0.0



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_sizeObject

Since:

  • 0.0.0



104
105
106
# File 'lib/dyi/font.rb', line 104

def draw_size
  @size || DEFAULT_SIZE
end

#empty?Boolean

Returns:

  • (Boolean)

Since:

  • 0.0.0



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

Since:

  • 0.0.0



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

Since:

  • 0.0.0



96
97
98
# File 'lib/dyi/font.rb', line 96

def size=(value)
  @size = Length.new_or_nil(value)
end

#size_adjust=(value) ⇒ Object

Since:

  • 0.0.0



100
101
102
# File 'lib/dyi/font.rb', line 100

def size_adjust=(value)
  @size_adjust = value ? value.to_f : nil
end

#to_cls_fontObject

Since:

  • 0.0.0



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