class Glimmer::SWT::FontProxy

Proxy for org.eclipse.swt.graphics.Font

This class can be optionally used with WidgetProxy to manipulate an SWT widget font (reusing its FontData but building a new Font)

Otherwise, if no WidgetProxy is passed to constructor, it builds new FontData

Invoking `#swt_font` returns the SWT Font object wrapped by this proxy

Follows the Proxy Design Pattern

Constants

ERROR_INVALID_FONT_STYLE
FONT_STYLES

Attributes

font_properties[R]
widget_proxy[R]

Public Class Methods

new(widget_proxy = nil, font_properties) click to toggle source

Builds a new font proxy from passed in widget_proxy and font_properties hash,

It begins with existing SWT widget font and amends it with font properties.

Font properties consist of: :name, :height, and :style (one needed minimum)

Style (:style value) can only be one of FontProxy::FONT_STYLES values: that is :normal, :bold, or :italic

# File lib/glimmer/swt/font_proxy.rb, line 50
def initialize(widget_proxy = nil, font_properties)
  @widget_proxy = widget_proxy
  @font_properties = font_properties.symbolize_keys
  detect_invalid_font_property(font_properties)
end

Public Instance Methods

height() click to toggle source
# File lib/glimmer/swt/font_proxy.rb, line 60
def height
  font_properties[:height]
end
name() click to toggle source
# File lib/glimmer/swt/font_proxy.rb, line 56
def name
  font_properties[:name]
end
style() click to toggle source
# File lib/glimmer/swt/font_proxy.rb, line 64
def style
  font_properties[:style]
end

Private Instance Methods

detect_invalid_font_property(font_properties) click to toggle source
# File lib/glimmer/swt/font_proxy.rb, line 70
def detect_invalid_font_property(font_properties)
  font_properties[:style].to_collection(false).select do |style|
    style.is_a?(Symbol) || style.is_a?(String)
  end.each do |style|
    raise Error, style.to_s + ERROR_INVALID_FONT_STYLE if !FONT_STYLES.include?(style.to_sym)
  end
end