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, sty: "p", scr: nil, options:) ⇒ 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
26
27
28
29
30
|
# File 'lib/plurimath/math/function/font_style.rb', line 26
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
117
118
119
120
121
122
123
124
|
# File 'lib/plurimath/math/function/font_style.rb', line 117
def empty_font_style_r_tag(sty, scr)
r_tag = Utility.ox_element("r", namespace: "m")
rpr_tag = Utility.ox_element("rPr", namespace: "m")
rpr_tag << Utility.ox_element("scr", namespace: "m", attributes: { "m:val": scr }) if scr
rpr_tag << Utility.ox_element("sty", namespace: "m", attributes: { "m:val": sty }) if sty
r_tag << rpr_tag
r_tag
end
|
63
64
65
66
|
# File 'lib/plurimath/math/function/font_style.rb', line 63
def
parameter_one.parameter_one if parameter_one.is_a?(Text)
parameter_one.class_name
end
|
68
69
70
|
# File 'lib/plurimath/math/function/font_style.rb', line 68
def
parameter_one.is_a?(Text)
end
|
#flatten_omml_nodes(nodes) ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/plurimath/math/function/font_style.rb', line 99
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
187
188
189
190
191
|
# File 'lib/plurimath/math/function/font_style.rb', line 187
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, sty: "p", scr: nil, options:) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/plurimath/math/function/font_style.rb', line 72
def font_styles(display_style, sty: "p", scr: nil, options:)
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
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/plurimath/math/function/font_style.rb', line 135
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
126
127
128
129
130
131
132
133
|
# File 'lib/plurimath/math/function/font_style.rb', line 126
def inject_font_style_rpr(r_node, sty, scr)
return if r_node.nodes.any? { |n| n.respond_to?(:name) && n.name == "m:rPr" }
rpr_tag = Utility.ox_element("rPr", namespace: "m")
rpr_tag << Utility.ox_element("scr", namespace: "m", attributes: { "m:val": scr }) if scr
rpr_tag << Utility.ox_element("sty", namespace: "m", attributes: { "m:val": sty }) if sty
r_node.insert_in_nodes(0, rpr_tag)
end
|
#line_breaking(obj) ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/plurimath/math/function/font_style.rb', line 215
def line_breaking(obj)
parameter_one&.line_breaking(obj)
return unless obj.value_exist?
obj.update(
self.class.new(
Utility.filter_values(obj.value),
self.parameter_two,
)
)
end
|
#r_tag_node?(node) ⇒ Boolean
113
114
115
|
# File 'lib/plurimath/math/function/font_style.rb', line 113
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
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/plurimath/math/function/font_style.rb', line 193
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
return Omml::Parser::SUPPORTED_FONTS.values.find { |value| fonts_array.include?(value) } if omml
if mathml
Mathml::Constants::SUPPORTED_FONT_STYLES.find { |string, object| fonts_array.include?(string.to_s) }&.first ||
parameter_two
end
end
|
#t_tag_node?(node) ⇒ Boolean
109
110
111
|
# File 'lib/plurimath/math/function/font_style.rb', line 109
def t_tag_node?(node)
node.respond_to?(:name) && node.name == "m:t"
end
|
#to_asciimath(options:) ⇒ Object
22
23
24
|
# File 'lib/plurimath/math/function/font_style.rb', line 22
def to_asciimath(options:)
parameter_one&.to_asciimath(options: options)
end
|
#to_asciimath_math_zone(spacing, last = false, _, options:) ⇒ Object
147
148
149
150
151
152
153
154
155
|
# File 'lib/plurimath/math/function/font_style.rb', line 147
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
47
48
49
|
# File 'lib/plurimath/math/function/font_style.rb', line 47
def to_html(options:)
parameter_one&.to_html(options: options)
end
|
#to_latex(options:) ⇒ Object
51
52
53
|
# File 'lib/plurimath/math/function/font_style.rb', line 51
def to_latex(options:)
parameter_one&.to_latex(options: options)
end
|
#to_latex_math_zone(spacing, last = false, _, options:) ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'lib/plurimath/math/function/font_style.rb', line 157
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
167
168
169
170
171
172
173
174
175
|
# File 'lib/plurimath/math/function/font_style.rb', line 167
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
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/plurimath/math/function/font_style.rb', line 32
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
177
178
179
180
181
182
183
184
185
|
# File 'lib/plurimath/math/function/font_style.rb', line 177
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
43
44
45
|
# File 'lib/plurimath/math/function/font_style.rb', line 43
def to_omml_without_math_tag(display_style, options:)
font_styles(display_style, options: options)
end
|
#to_unicodemath(options:) ⇒ Object
55
56
57
|
# File 'lib/plurimath/math/function/font_style.rb', line 55
def to_unicodemath(options:)
"#{font_family(unicode: true)}#{parameter_one&.to_unicodemath(options: options)}"
end
|
#to_unicodemath_math_zone(spacing, last = false, _, options:) ⇒ Object
205
206
207
208
209
210
211
212
213
|
# File 'lib/plurimath/math/function/font_style.rb', line 205
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
|
59
60
61
|
# File 'lib/plurimath/math/function/font_style.rb', line 59
def validate_function_formula
true
end
|