Module: Rabbit::Element::TextRenderer
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
-
#align=(new_value) ⇒ Object
-
#as_large_as_possible(proc_name = nil, &compute_max_size) ⇒ Object
-
#clear_theme ⇒ Object
-
#compile(canvas, x, y, w, h) ⇒ Object
-
#dirty! ⇒ Object
-
#dirty? ⇒ Boolean
-
#do_horizontal_centering(canvas, x, y, w, h) ⇒ Object
-
#do_horizontal_centering? ⇒ Boolean
-
#font_size ⇒ Object
-
#have_numerical_font_size? ⇒ Boolean
-
#height ⇒ Object
-
#initialize(*args, &block) ⇒ Object
-
#justify=(new_value) ⇒ Object
-
#keep_in_size(proc_name = nil, &compute_max_size) ⇒ Object
-
#markuped_text ⇒ Object
-
#pixel_font_size ⇒ Object
-
#reset_horizontal_centering(canvas, x, y, w, h) ⇒ Object
-
#spacing=(new_spacing) ⇒ Object
-
#text_clear_theme ⇒ Object
-
#text_compile(canvas, x, y, w, h) ⇒ Object
-
#text_dirty? ⇒ Boolean
-
#text_props ⇒ Object
-
#text_renderer? ⇒ Boolean
-
#text_to_html(generator) ⇒ Object
-
#width ⇒ Object
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
#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_height ⇒ Object
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_width ⇒ Object
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
Sets the attribute indent
12
13
14
|
# File 'lib/rabbit/element/text-renderer.rb', line 12
def indent=(value)
@indent = value
end
|
#layout ⇒ Object
Returns the value of attribute layout.
8
9
10
|
# File 'lib/rabbit/element/text-renderer.rb', line 8
def layout
@layout
end
|
#original_height ⇒ Object
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_width ⇒ Object
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
Sets the attribute wrap_mode
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::Alignment.const_get(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_theme ⇒ Object
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
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::Alignment::CENTER
end
|
#do_horizontal_centering? ⇒ Boolean
76
77
78
|
# File 'lib/rabbit/element/text-renderer.rb', line 76
def do_horizontal_centering?
@horizontal_centering
end
|
#font_size ⇒ Object
127
128
129
|
# File 'lib/rabbit/element/text-renderer.rb', line 127
def font_size
text_props["size"]
end
|
#have_numerical_font_size? ⇒ Boolean
140
141
142
|
# File 'lib/rabbit/element/text-renderer.rb', line 140
def have_numerical_font_size?
font_size.is_a?(Numeric)
end
|
#height ⇒ Object
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_text ⇒ Object
88
89
90
|
# File 'lib/rabbit/element/text-renderer.rb', line 88
def markuped_text
markup(text)
end
|
#pixel_font_size ⇒ Object
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::Alignment::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_theme ⇒ Object
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
115
116
117
|
# File 'lib/rabbit/element/text-renderer.rb', line 115
def text_dirty?
@layout.nil?
end
|
#text_props ⇒ Object
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
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
|
#width ⇒ Object
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
|