make_composite.dart
3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import 'package:flutter/widgets.dart';
import '../../ast/nodes/over.dart';
import '../../ast/nodes/style.dart';
import '../../ast/nodes/symbol.dart';
import '../../ast/options.dart';
import '../../ast/size.dart';
import '../../ast/syntax_tree.dart';
import '../../ast/types.dart';
import '../../parser/tex/font.dart';
import '../../utils/unicode_literal.dart';
import '../layout/line.dart';
import '../layout/reset_dimension.dart';
import '../layout/shift_baseline.dart';
import 'make_symbol.dart';
BuildResult makeRlapCompositeSymbol(
String char1,
String char2,
AtomType type,
Mode mode,
MathOptions options,
) {
final res1 = makeBaseSymbol(
symbol: char1, atomType: type, mode: mode, options: options);
final res2 = makeBaseSymbol(
symbol: char2, atomType: type, mode: mode, options: options);
return BuildResult(
italic: res2.italic,
options: options,
widget: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ResetDimension(
width: 0,
horizontalAlignment: CrossAxisAlignment.start,
child: res1.widget,
),
res2.widget,
],
),
);
}
BuildResult makeCompactedCompositeSymbol(
String char1,
String char2,
Measurement spacing,
AtomType type,
Mode mode,
MathOptions options,
) {
final res1 = makeBaseSymbol(
symbol: char1, atomType: type, mode: mode, options: options);
final res2 = makeBaseSymbol(
symbol: char2, atomType: type, mode: mode, options: options);
final widget1 = char1 != ':'
? res1.widget
: ShiftBaseline(
relativePos: 0.5,
offset: options.fontMetrics.axisHeight.cssEm.toLpUnder(options),
child: res1.widget,
);
final widget2 = char2 != ':'
? res2.widget
: ShiftBaseline(
relativePos: 0.5,
offset: options.fontMetrics.axisHeight.cssEm.toLpUnder(options),
child: res2.widget,
);
return BuildResult(
italic: res2.italic,
options: options,
widget: Line(
children: <Widget>[
LineElement(
child: widget1,
trailingMargin: spacing.toLpUnder(options),
),
widget2,
],
),
);
}
BuildResult makeDecoratedEqualSymbol(
String symbol,
AtomType type,
Mode mode,
MathOptions options,
) {
List<String> decoratorSymbols;
FontOptions? decoratorFont;
MathSize decoratorSize;
switch (symbol) {
// case '\u2258':
// break;
case '\u2259':
decoratorSymbols = ['\u2227']; // \wedge
decoratorSize = MathSize.tiny;
break;
case '\u225A':
decoratorSymbols = ['\u2228']; // \vee
decoratorSize = MathSize.tiny;
break;
case '\u225B':
decoratorSymbols = ['\u22c6']; // \star
decoratorSize = MathSize.scriptsize;
break;
case '\u225D':
decoratorSymbols = ['d', 'e', 'f'];
decoratorSize = MathSize.tiny;
decoratorFont = texMathFontOptions['\\mathrm']!;
break;
case '\u225E':
decoratorSymbols = ['m'];
decoratorSize = MathSize.tiny;
decoratorFont = texMathFontOptions['\\mathrm']!;
break;
case '\u225F':
decoratorSymbols = ['?'];
decoratorSize = MathSize.tiny;
break;
default:
throw ArgumentError.value(
unicodeLiteral(symbol), 'symbol', 'Not a decorator character');
}
final decorator = StyleNode(
children: decoratorSymbols
.map((symbol) => SymbolNode(symbol: symbol, mode: mode))
.toList(growable: false),
optionsDiff: OptionsDiff(
size: decoratorSize,
mathFontOptions: decoratorFont,
),
);
final proxyNode = OverNode(
base: SymbolNode(symbol: '=', mode: mode, overrideAtomType: type)
.wrapWithEquationRow(),
above: decorator.wrapWithEquationRow(),
);
return SyntaxNode(parent: null, value: proxyNode, pos: 0)
.buildWidget(options);
}