Module: Rabbit::Element::TextRenderer

Includes:
Base
Included in:
TextContainerElement, TextElement
Defined in:
lib/rabbit/element/text-renderer.rb

Instance Attribute Summary collapse

Attributes included from Base

#base_h, #base_w, #base_x, #base_y, #default_margin_bottom, #default_margin_left, #default_margin_right, #default_margin_top, #default_padding_bottom, #default_padding_left, #default_padding_right, #default_padding_top, #default_visible, #h, #horizontal_centering, #margin_bottom, #margin_left, #margin_right, #margin_top, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #ph, #pw, #px, #py, #real_simulation, #user_property, #vertical_centering, #w, #x, #y

Instance Method Summary collapse

Methods included from Base

#[], #[]=, #add_default_prop, #adjust_x_centering, #adjust_y_margin, #adjust_y_padding, #available_w, #centering_adjusted_height, #centering_adjusted_width, #clear_margin, #clear_padding, #clone, #compile_for_horizontal_centering, #compile_horizontal, #default_prop, #do_vertical_centering?, #draw, #font, #have_wait_tag?, #hide, #if_dirty, #init_default_margin, #init_default_padding, #init_default_visible, #inline_element?, #inspect, #margin_set, #margin_with, #match?, #next_element, #padding_set, #padding_with, #previous_element, #prop_delete, #prop_get, #prop_set, #prop_value, #restore_x_margin, #restore_x_padding, #setup_margin, #setup_padding, #show, #slide, #substitute_newline, #substitute_text, #visible?, #wait

Methods included from Base::DrawHook

#clear_draw_procs, def_draw_hook, def_draw_hooks

Methods included from Utils

arg_list, collect_classes_under_module, collect_modules_under_module, collect_under_module, combination, compute_bottom_y, compute_left_x, compute_right_x, compute_top_y, corresponding_class_under_module, corresponding_module_under_module, corresponding_objects, drawable_to_pixbuf, ensure_time, events_pending_available?, extract_four_way, find_path_in_load_path, init_by_constants_as_default_value, move_to, move_to_bottom_left, move_to_bottom_right, move_to_top_left, move_to_top_right, parse_four_way, process_pending_events, process_pending_events_proc, quartz?, require_files_under_directory_in_load_path, require_safe, split_number_to_minute_and_second, stringify_hash_key, support_console_input?, support_console_output?, syntax_highlighting_debug?, time, to_class_name, unescape_title, windows?

Instance Attribute Details

#first_line_heightObject (readonly)

Returns the value of attribute first_line_height.



10
11
12
# File 'lib/rabbit/element/text-renderer.rb', line 10

def first_line_height
  @first_line_height
end

#first_line_widthObject (readonly)

Returns the value of attribute first_line_width.



10
11
12
# File 'lib/rabbit/element/text-renderer.rb', line 10

def first_line_width
  @first_line_width
end

#indent=(value) ⇒ Object (writeonly)

Sets the attribute indent

Parameters:

  • value

    the value to set the attribute indent to.



12
13
14
# File 'lib/rabbit/element/text-renderer.rb', line 12

def indent=(value)
  @indent = value
end

#layoutObject (readonly)

Returns the value of attribute layout.



8
9
10
# File 'lib/rabbit/element/text-renderer.rb', line 8

def layout
  @layout
end

#original_heightObject (readonly)

Returns the value of attribute original_height.



9
10
11
# File 'lib/rabbit/element/text-renderer.rb', line 9

def original_height
  @original_height
end

#original_widthObject (readonly)

Returns the value of attribute original_width.



9
10
11
# File 'lib/rabbit/element/text-renderer.rb', line 9

def original_width
  @original_width
end

#spacing=(value) ⇒ Object (writeonly)

Sets the attribute spacing

Parameters:

  • value

    the value to set the attribute spacing to.



12
13
14
# File 'lib/rabbit/element/text-renderer.rb', line 12

def spacing=(value)
  @spacing = value
end

#wrap_mode=(value) ⇒ Object (writeonly)

Sets the attribute wrap_mode

Parameters:

  • value

    the value to set the attribute wrap_mode to.



12
13
14
# File 'lib/rabbit/element/text-renderer.rb', line 12

def wrap_mode=(value)
  @wrap_mode = value
end

Instance Method Details

#align=(new_value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/rabbit/element/text-renderer.rb', line 23

def align=(new_value)
  if new_value.is_a?(String)
    new_value = Pango::Layout.const_get("ALIGN_#{new_value.to_s.upcase}")
  end
  dirty! if @align != new_value
  @align = new_value
end

#as_large_as_possible(proc_name = nil, &compute_max_size) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/rabbit/element/text-renderer.rb', line 153

def as_large_as_possible(proc_name=nil, &compute_max_size)
  proc_name ||= "as-large-as-possible"
  make_params = Proc.new do |canvas, x, y, w, h,
                             initial_width, initial_height,
                             max_width, max_height|
    if (max_width and initial_width > max_width) or
        (max_height and initial_height > max_height)
      scale = 0.95
      compare = Proc.new do |_width, _height|
        (max_width.nil? or _width < max_width) and
          (max_height.nil? or _height < max_height)
      end
    else
      scale = 1.05
      compare = Proc.new do |_width, _height|
        (max_width and _width > max_width) or
          (max_height and _height > max_height)
      end
    end
    [scale, compare]
  end
  dynamic_font_size_computation(proc_name, compute_max_size, &make_params)
end

#clear_themeObject



83
84
85
86
# File 'lib/rabbit/element/text-renderer.rb', line 83

def clear_theme
  super
  text_clear_theme
end

#compile(canvas, x, y, w, h) ⇒ Object



53
54
55
56
# File 'lib/rabbit/element/text-renderer.rb', line 53

def compile(canvas, x, y, w, h)
  super
  text_compile(canvas, x, y, w, h)
end

#dirty!Object



97
98
99
100
# File 'lib/rabbit/element/text-renderer.rb', line 97

def dirty!
  super
  @layout = nil
end

#dirty?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/rabbit/element/text-renderer.rb', line 102

def dirty?
  super or text_dirty?
end

#do_horizontal_centering(canvas, x, y, w, h) ⇒ Object



75
76
77
# File 'lib/rabbit/element/text-renderer.rb', line 75

def do_horizontal_centering(canvas, x, y, w, h)
  self.align = Pango::Layout::ALIGN_CENTER
end

#do_horizontal_centering?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/rabbit/element/text-renderer.rb', line 71

def do_horizontal_centering?
  @horizontal_centering
end

#font_sizeObject



118
119
120
# File 'lib/rabbit/element/text-renderer.rb', line 118

def font_size
  text_props["size"]
end

#have_numerical_font_size?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/rabbit/element/text-renderer.rb', line 131

def have_numerical_font_size?
  font_size.is_a?(Numeric)
end

#heightObject



45
46
47
48
49
50
51
# File 'lib/rabbit/element/text-renderer.rb', line 45

def height
  if @height
    @height + @padding_top + @padding_bottom
  else
    nil
  end
end

#initialize(*args, &block) ⇒ Object



14
15
16
17
# File 'lib/rabbit/element/text-renderer.rb', line 14

def initialize(*args, &block)
  super
  text_clear_theme
end

#justify=(new_value) ⇒ Object



31
32
33
34
35
# File 'lib/rabbit/element/text-renderer.rb', line 31

def justify=(new_value)
  new_value = true if new_value
  dirty! if @justify != new_value
  @justify = new_value
end

#keep_in_size(proc_name = nil, &compute_max_size) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/rabbit/element/text-renderer.rb', line 135

def keep_in_size(proc_name=nil, &compute_max_size)
  proc_name ||= "keep-in-size"
  make_params = Proc.new do |canvas, x, y, w, h,
                             initial_width, initial_height,
                             max_width, max_height|
    if (max_width and initial_width > max_width) or
        (max_height and initial_height > max_height)
      scale = 0.95
      compare = Proc.new do |_width, _height|
        (max_width.nil? or _width < max_width) and
          (max_height.nil? or _height < max_height)
      end
      [scale, compare]
    end
  end
  dynamic_font_size_computation(proc_name, compute_max_size, &make_params)
end

#markuped_textObject



79
80
81
# File 'lib/rabbit/element/text-renderer.rb', line 79

def markuped_text
  markup(text)
end

#pixel_font_sizeObject



122
123
124
125
126
127
128
129
# File 'lib/rabbit/element/text-renderer.rb', line 122

def pixel_font_size
  _font_size = font_size
  if _font_size
    _font_size / Pango::SCALE
  else
    original_height
  end
end

#text_clear_themeObject



88
89
90
91
92
93
94
95
# File 'lib/rabbit/element/text-renderer.rb', line 88

def text_clear_theme
  @layout = nil
  @indent = 0
  @spacing = 0
  @wrap_mode = default_wrap_mode
  @align = default_align
  @justify = default_justify
end

#text_compile(canvas, x, y, w, h) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/rabbit/element/text-renderer.rb', line 58

def text_compile(canvas, x, y, w, h)
  if (@width and @width > @w) or (@height and @height > @h)
    dirty!
  end
  if_dirty do
    setup_draw_info(markuped_text, canvas, w)
  end
end

#text_dirty?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/rabbit/element/text-renderer.rb', line 106

def text_dirty?
  @layout.nil?
end

#text_propsObject



110
111
112
113
114
115
116
# File 'lib/rabbit/element/text-renderer.rb', line 110

def text_props
  props = {}
  @prop.each do |name, formatter|
    props[name] = formatter.value
  end
  props
end

#text_renderer?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rabbit/element/text-renderer.rb', line 19

def text_renderer?
  true
end

#text_to_html(generator) ⇒ Object



67
68
69
# File 'lib/rabbit/element/text-renderer.rb', line 67

def text_to_html(generator)
  markup_as_html(text)
end

#widthObject



37
38
39
40
41
42
43
# File 'lib/rabbit/element/text-renderer.rb', line 37

def width
  if @width
    @width + @padding_left + @padding_right
  else
    nil
  end
end