Class: Plurimath::Math::Function::FontStyle
- Inherits:
-
BinaryFunction
show all
- Defined in:
- lib/plurimath/math/function/font_style.rb,
lib/plurimath/math/function/font_style/bold.rb,
lib/plurimath/math/function/font_style/italic.rb,
lib/plurimath/math/function/font_style/normal.rb,
lib/plurimath/math/function/font_style/script.rb,
lib/plurimath/math/function/font_style/fraktur.rb,
lib/plurimath/math/function/font_style/monospace.rb,
lib/plurimath/math/function/font_style/sans-serif.rb,
lib/plurimath/math/function/font_style/bold-italic.rb,
lib/plurimath/math/function/font_style/bold-script.rb,
lib/plurimath/math/function/font_style/bold-fraktur.rb,
lib/plurimath/math/function/font_style/double_struck.rb,
lib/plurimath/math/function/font_style/bold-sans-serif.rb,
lib/plurimath/math/function/font_style/sans-serif-italic.rb,
lib/plurimath/math/function/font_style/sans-serif-bold-italic.rb
Direct Known Subclasses
Bold, BoldFraktur, BoldItalic, BoldSansSerif, BoldScript, DoubleStruck, Fraktur, Italic, Monospace, Normal, SansSerif, SansSerifBoldItalic, SansSerifItalic, Script
Defined Under Namespace
Classes: Bold, BoldFraktur, BoldItalic, BoldSansSerif, BoldScript, DoubleStruck, Fraktur, Italic, Monospace, Normal, SansSerif, SansSerifBoldItalic, SansSerifItalic, Script
Constant Summary
Constants inherited
from Core
Core::ALL_PARAMETERS, Core::REPLACABLES
Instance Attribute Summary
#hide_function_name, #parameter_one, #parameter_two
Instance Method Summary
collapse
-
#==(object) ⇒ Object
-
#empty_font_style_r_tag(sty, scr) ⇒ Object
-
#extract_class_name_from_text ⇒ Object
-
#extractable? ⇒ Boolean
-
#flatten_omml_nodes(nodes) ⇒ Object
-
#font_family(unicode: false, omml: false, mathml: false) ⇒ Object
-
#font_styles(display_style, options:, sty: "p", scr: nil) ⇒ Object
-
#inject_font_style_recursive(node, sty, scr) ⇒ Object
-
#inject_font_style_rpr(r_node, sty, scr) ⇒ Object
-
#line_breaking(obj) ⇒ Object
-
#r_tag_node?(node) ⇒ Boolean
-
#supported_fonts(fonts_array = [], unicode: false, omml: false, mathml: false) ⇒ Object
-
#t_tag_node?(node) ⇒ Boolean
-
#to_asciimath(options:) ⇒ Object
-
#to_asciimath_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#to_html(options:) ⇒ Object
-
#to_latex(options:) ⇒ Object
-
#to_latex_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#to_mathml_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#to_mathml_without_math_tag(intent, options:) ⇒ Object
-
#to_omml_math_zone(spacing, last = false, _, display_style:, options:) ⇒ Object
-
#to_omml_without_math_tag(display_style, options:) ⇒ Object
-
#to_unicodemath(options:) ⇒ Object
-
#to_unicodemath_math_zone(spacing, last = false, _, options:) ⇒ Object
-
#validate_function_formula ⇒ Object
#all_values_exist?, #any_value_exist?, #initialize
Methods inherited from Core
#ascii_fields_to_print, #class_name, #cloned_objects, #common_math_zone_conversion, descendants, #dump_mathml, #dump_nodes, #dump_omml, #dump_ox_nodes, #empty_tag, #filtered_values, #font_style_t_tag, #get, #gsub_spacing, inherited, #insert_t_tag, #invert_unicode_symbols, #is_binary_function?, #is_mrow?, #is_mstyle?, #is_nary_function?, #is_nary_symbol?, #is_ternary_function?, #is_unary?, #latex_fields_to_print, #linebreak?, #mathml_fields_to_print, #mathml_nodes, #mini_sized?, #msty_tag_with_attrs, #nary_attr_value, #nary_intent_name, #omml_fields_to_print, #omml_nodes, #omml_parameter, #omml_tag_name, #ox_element, #paren?, #pretty_print_instance_variables, #prime_unicode?, #r_element, #replacable_values, #result, #separate_table, #set, #symbol?, #tag_name, #to_ms_value, #unicodemath_fields_to_print, #unicodemath_parens, #updated_object_values, #validate_mathml_fields, #variable_value, #variables
Instance Method Details
#==(object) ⇒ Object
27
28
29
30
31
|
# File 'lib/plurimath/math/function/font_style.rb', line 27
def ==(object)
object.class == self.class &&
object.parameter_one == parameter_one &&
comparable_font_family(object.parameter_two) == comparable_font_family(parameter_two)
end
|
#empty_font_style_r_tag(sty, scr) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/plurimath/math/function/font_style.rb', line 120
def empty_font_style_r_tag(sty, scr)
r_tag = Utility.ox_element("r", namespace: "m")
rpr_tag = Utility.ox_element("rPr", namespace: "m")
if scr
rpr_tag << Utility.ox_element("scr", namespace: "m",
attributes: { "m:val": scr })
end
if sty
rpr_tag << Utility.ox_element("sty", namespace: "m",
attributes: { "m:val": sty })
end
r_tag << rpr_tag
r_tag
end
|
65
66
67
68
|
# File 'lib/plurimath/math/function/font_style.rb', line 65
def
parameter_one.parameter_one if parameter_one.is_a?(Text)
parameter_one.class_name
end
|
70
71
72
|
# File 'lib/plurimath/math/function/font_style.rb', line 70
def
parameter_one.is_a?(Text)
end
|
#flatten_omml_nodes(nodes) ⇒ Object
102
103
104
105
106
107
108
109
110
|
# File 'lib/plurimath/math/function/font_style.rb', line 102
def flatten_omml_nodes(nodes)
nodes.each_with_object([]) do |node, result|
if node.is_a?(Array)
result.concat(flatten_omml_nodes(node))
elsif !node.nil?
result << node
end
end
end
|
#font_family(unicode: false, omml: false, mathml: false) ⇒ Object
215
216
217
218
219
|
# File 'lib/plurimath/math/function/font_style.rb', line 215
def font_family(unicode: false, omml: false, mathml: false)
fonts = font_classes
fonts = font_classes(parameter_to_class) if fonts.empty?
supported_fonts(fonts, unicode: unicode, omml: omml, mathml: mathml)
end
|
#font_styles(display_style, options:, sty: "p", scr: nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/plurimath/math/function/font_style.rb', line 74
def font_styles(display_style, options:, sty: "p", scr: nil)
children = flatten_omml_nodes(
Array(parameter_one&.font_style_t_tag(display_style,
options: options)),
)
return [empty_font_style_r_tag(sty, scr)] if children.empty?
if children.all? { |node| node.is_a?(String) || t_tag_node?(node) }
r_tag = empty_font_style_r_tag(sty, scr)
Utility.update_nodes(r_tag, children)
return [r_tag]
end
children.flat_map do |node|
if r_tag_node?(node)
inject_font_style_rpr(node, sty, scr)
[node]
elsif t_tag_node?(node)
r_tag = empty_font_style_r_tag(sty, scr)
r_tag << node
[r_tag]
else
inject_font_style_recursive(node, sty, scr)
[node]
end
end
end
|
#inject_font_style_recursive(node, sty, scr) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/plurimath/math/function/font_style.rb', line 152
def inject_font_style_recursive(node, sty, scr)
return unless node.respond_to?(:nodes)
node.nodes.each do |child|
if r_tag_node?(child)
inject_font_style_rpr(child, sty, scr)
elsif child.respond_to?(:nodes)
inject_font_style_recursive(child, sty, scr)
end
end
end
|
#inject_font_style_rpr(r_node, sty, scr) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/plurimath/math/function/font_style.rb', line 135
def inject_font_style_rpr(r_node, sty, scr)
return if r_node.nodes.any? do |n|
n.respond_to?(:name) && n.name == "m:rPr"
end
rpr_tag = Utility.ox_element("rPr", namespace: "m")
if scr
rpr_tag << Utility.ox_element("scr", namespace: "m",
attributes: { "m:val": scr })
end
if sty
rpr_tag << Utility.ox_element("sty", namespace: "m",
attributes: { "m:val": sty })
end
r_node.insert_in_nodes(0, rpr_tag)
end
|
#line_breaking(obj) ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/plurimath/math/function/font_style.rb', line 255
def line_breaking(obj)
parameter_one&.line_breaking(obj)
return unless obj.value_exist?
obj.update(
self.class.new(
Utility.filter_values(obj.value),
parameter_two,
),
)
end
|
#r_tag_node?(node) ⇒ Boolean
116
117
118
|
# File 'lib/plurimath/math/function/font_style.rb', line 116
def r_tag_node?(node)
node.respond_to?(:name) && node.name == "m:r"
end
|
#supported_fonts(fonts_array = [], unicode: false, omml: false, mathml: false) ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/plurimath/math/function/font_style.rb', line 221
def supported_fonts(fonts_array = [], unicode: false, omml: false,
mathml: false)
if unicode
font = UnicodeMath::Constants::FONTS_CLASSES.find { |value| fonts_array.include?(value) }
return "\\#{font}" if font
end
if omml
return Omml::Parser::SUPPORTED_FONTS.values.find do |value|
fonts_array.include?(value)
end
end
if mathml
Mathml::Constants::SUPPORTED_FONT_STYLES.find do |string, _object|
fonts_array.include?(string.to_s)
end&.first ||
parameter_two
end
end
|
#t_tag_node?(node) ⇒ Boolean
112
113
114
|
# File 'lib/plurimath/math/function/font_style.rb', line 112
def t_tag_node?(node)
node.respond_to?(:name) && node.name == "m:t"
end
|
#to_asciimath(options:) ⇒ Object
23
24
25
|
# File 'lib/plurimath/math/function/font_style.rb', line 23
def to_asciimath(options:)
parameter_one&.to_asciimath(options: options)
end
|
#to_asciimath_math_zone(spacing, last = false, _, options:) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/plurimath/math/function/font_style.rb', line 164
def to_asciimath_math_zone(spacing, last = false, _, options:)
new_spacing = gsub_spacing(spacing, last)
new_arr = [
"#{spacing}\"#{to_asciimath(options: options)}\" function apply\n",
"#{new_spacing}|_ \"#{parameter_two}\" font family\n",
]
ascii_fields_to_print(parameter_one,
{ spacing: new_spacing, field_name: "argument", additional_space: "| |_ ",
array: new_arr, options: options })
new_arr
end
|
#to_html(options:) ⇒ Object
49
50
51
|
# File 'lib/plurimath/math/function/font_style.rb', line 49
def to_html(options:)
parameter_one&.to_html(options: options)
end
|
#to_latex(options:) ⇒ Object
53
54
55
|
# File 'lib/plurimath/math/function/font_style.rb', line 53
def to_latex(options:)
parameter_one&.to_latex(options: options)
end
|
#to_latex_math_zone(spacing, last = false, _, options:) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/plurimath/math/function/font_style.rb', line 176
def to_latex_math_zone(spacing, last = false, _, options:)
new_spacing = gsub_spacing(spacing, last)
new_arr = [
"#{spacing}\"#{to_latex(options: options)}\" function apply\n",
"#{new_spacing}|_ \"#{parameter_two}\" font family\n",
]
latex_fields_to_print(parameter_one,
{ spacing: new_spacing, field_name: "argument", additional_space: "| |_ ",
array: new_arr, options: options })
new_arr
end
|
#to_mathml_math_zone(spacing, last = false, _, options:) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/plurimath/math/function/font_style.rb', line 188
def to_mathml_math_zone(spacing, last = false, _, options:)
new_spacing = gsub_spacing(spacing, last)
new_arr = [
"#{spacing}\"#{dump_mathml(self,
options: options)}\" function apply\n",
"#{new_spacing}|_ \"#{font_family(mathml: true)}\" font family\n",
]
mathml_fields_to_print(parameter_one,
{ spacing: new_spacing, field_name: "argument", additional_space: "| |_ ",
array: new_arr, options: options })
new_arr
end
|
#to_mathml_without_math_tag(intent, options:) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/plurimath/math/function/font_style.rb', line 33
def to_mathml_without_math_tag(intent, options:)
first_value = parameter_one&.to_mathml_without_math_tag(intent,
options: options)
Utility.update_nodes(
Utility.ox_element(
"mstyle",
attributes: { mathvariant: font_family(mathml: true) },
),
[first_value],
)
end
|
#to_omml_math_zone(spacing, last = false, _, display_style:, options:) ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/plurimath/math/function/font_style.rb', line 201
def to_omml_math_zone(spacing, last = false, _, display_style:,
options:)
new_spacing = gsub_spacing(spacing, last)
new_arr = [
"#{spacing}\"#{dump_omml(self, display_style,
options: options)}\" function apply\n",
"#{new_spacing}|_ \"#{font_family(omml: true)}\" font family\n",
]
omml_fields_to_print(parameter_one,
{ spacing: new_spacing, field_name: "argument", additional_space: "| |_ ",
array: new_arr, display_style: display_style, options: options })
new_arr
end
|
#to_omml_without_math_tag(display_style, options:) ⇒ Object
45
46
47
|
# File 'lib/plurimath/math/function/font_style.rb', line 45
def to_omml_without_math_tag(display_style, options:)
font_styles(display_style, options: options)
end
|
#to_unicodemath(options:) ⇒ Object
57
58
59
|
# File 'lib/plurimath/math/function/font_style.rb', line 57
def to_unicodemath(options:)
"#{font_family(unicode: true)}#{parameter_one&.to_unicodemath(options: options)}"
end
|
#to_unicodemath_math_zone(spacing, last = false, _, options:) ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/plurimath/math/function/font_style.rb', line 241
def to_unicodemath_math_zone(spacing, last = false, _, options:)
new_spacing = gsub_spacing(spacing, last)
new_arr = [
"#{spacing}\"#{dump_unicodemath(self,
options: options)}\" function apply\n",
"#{new_spacing}|_ \"#{font_family(unicode: true,
options: options)}\" font family\n",
]
unicodemath_fields_to_print(parameter_one,
{ spacing: new_spacing, field_name: "argument", additional_space: "| |_ ",
array: new_arr, options: options })
new_arr
end
|
61
62
63
|
# File 'lib/plurimath/math/function/font_style.rb', line 61
def validate_function_formula
true
end
|