Module: Rabbit::Element::TextRenderer

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

Constant Summary

Constants included from GetText

GetText::DOMAIN

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_element, #compile_for_horizontal_centering, #compile_horizontal, #default_prop, #do_vertical_centering?, #draw, #font, #have_tag?, #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, 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?

Methods included from GetText

included

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

#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



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/rabbit/element/text-renderer.rb', line 167

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



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

def clear_theme
  super
  text_clear_theme
end

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



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

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

#dirty!Object



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

def dirty!
  super
  @layout = nil
end

#dirty?Boolean

Returns:

  • (Boolean)


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

def dirty?
  super or text_dirty?
end

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



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

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

#do_horizontal_centering?Boolean

Returns:

  • (Boolean)


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

def do_horizontal_centering?
  @horizontal_centering
end

#font_sizeObject



127
128
129
# File 'lib/rabbit/element/text-renderer.rb', line 127

def font_size
  text_props["size"]
end

#have_numerical_font_size?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/rabbit/element/text-renderer.rb', line 140

def have_numerical_font_size?
  font_size.is_a?(Numeric)
end

#heightObject



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

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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rabbit/element/text-renderer.rb', line 144

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 = lambda do |_width, _height|
        candidates = [0.95]
        candidates << (max_width.to_f) / _width if max_width
        candidates << (max_height.to_f) / _height if max_height
        candidates.min
      end
      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



88
89
90
# File 'lib/rabbit/element/text-renderer.rb', line 88

def markuped_text
  markup(text)
end

#pixel_font_sizeObject



131
132
133
134
135
136
137
138
# File 'lib/rabbit/element/text-renderer.rb', line 131

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

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



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

def reset_horizontal_centering(canvas, x, y, w, h)
  self.align = default_align if @align == Pango::Layout::ALIGN_CENTER
end

#spacing=(new_spacing) ⇒ Object



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

def spacing=(new_spacing)
  dirty! if @spacing != new_spacing
  @spacing = new_spacing
end

#text_clear_themeObject



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

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



63
64
65
66
67
68
69
70
# File 'lib/rabbit/element/text-renderer.rb', line 63

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)


115
116
117
# File 'lib/rabbit/element/text-renderer.rb', line 115

def text_dirty?
  @layout.nil?
end

#text_propsObject



119
120
121
122
123
124
125
# File 'lib/rabbit/element/text-renderer.rb', line 119

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



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

def text_to_html(generator)
  markup_as_html(text)
end

#widthObject



42
43
44
45
46
47
48
# File 'lib/rabbit/element/text-renderer.rb', line 42

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