MCPcopy Create free account
hub / github.com/NanoMichael/MicroTeX / getColumnSep

Method getColumnSep

src/atom/atom_impl.cpp:122–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122float* MatrixAtom::getColumnSep(_out_ TeXEnvironment& env, float width) {
123 const int cols = _matrix->cols();
124 float* arr = new float[cols + 1]();
125 sptr<Box> Align, AlignSep, Hsep;
126 float h, w = env.getTextWidth();
127 int i = 0;
128
129 if (_ttype == ALIGNED || _ttype == ALIGNEDAT) w = POS_INF;
130
131 switch (_ttype) {
132 case ARRAY: {
133 // Array: (hsep_col/2 or 0) elem hsep_col elem hsep_col ... hsep_col elem (hsep_col/2 or 0)
134 Hsep = _hsep.createBox(env);
135 for (int i = 0; i < cols; i++) {
136 if (_position[i] == ALIGN_NONE) {
137 arr[i] = arr[i + 1] = 0;
138 i++;
139 } else {
140 arr[i] = Hsep->_width;
141 }
142 }
143 if (_spaceAround) {
144 const auto half = Hsep->_width / 2;
145 if (_position.front() != ALIGN_NONE) arr[0] = half;
146 if (_position.back() != ALIGN_NONE) arr[cols] = half;
147 }
148 return arr;
149 }
150 case MATRIX:
151 case SMALLMATRIX: {
152 // Simple matrix: 0 elem hsep_col elem hsep_col ... hsep_col elem 0
153 arr[0] = 0;
154 arr[cols] = arr[0];
155 Hsep = _hsep.createBox(env);
156 for (i = 1; i < cols; i++) arr[i] = Hsep->_width;
157 return arr;
158 }
159 case ALIGNED:
160 case ALIGN: {
161 // Align env: hsep = (textwidth - matwidth) / (2n + 1)
162 // Spaces: hsep eq_left \medskip eq_right hsep ... hsep elem hsep
163 Align = _align.createBox(env);
164 if (w != POS_INF) {
165 h = max((w - width - cols / 2 * Align->_width) / floor((cols + 3) / 2.f), 0.f);
166 AlignSep = sptr<Box>(new StrutBox(h, 0, 0, 0));
167 } else {
168 AlignSep = _hsep.createBox(env);
169 }
170
171 arr[cols] = AlignSep->_width;
172 for (int i = 0; i < cols; i++) {
173 if (i % 2 == 0)
174 arr[i] = AlignSep->_width;
175 else
176 arr[i] = Align->_width;
177 }
178 } break;
179 case ALIGNEDAT:

Callers

nothing calls this directly

Calls 3

colsMethod · 0.80
getTextWidthMethod · 0.80
createBoxMethod · 0.45

Tested by

no test coverage detected