3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup Nielsen
7 * \author Jean-Marc Lasgouttes
8 * \author Lars Gullik Bjønnes
9 * \author Jürgen Spitzmüller
11 * Full author contact details are available in file CREDITS.
16 #include "InsetSpace.h"
18 #include "BufferView.h"
20 #include "Dimension.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
24 #include "LaTeXFeatures.h"
26 #include "MetricsInfo.h"
27 #include "texstream.h"
30 #include "support/debug.h"
31 #include "support/docstream.h"
32 #include "support/gettext.h"
33 #include "support/lassert.h"
34 #include "support/Length.h"
35 #include "support/lstrings.h"
36 #include "support/qstring_helpers.h"
38 #include "frontends/Application.h"
39 #include "frontends/FontMetrics.h"
40 #include "frontends/Painter.h"
47 InsetSpace::InsetSpace(InsetSpaceParams const & params)
48 : Inset(nullptr), params_(params)
52 InsetSpaceParams::Kind InsetSpace::kind() const
58 GlueLength InsetSpace::length() const
60 return params_.length;
64 docstring InsetSpace::toolTip(BufferView const &, int, int) const
67 switch (params_.kind) {
68 case InsetSpaceParams::NORMAL:
69 message = _("Normal Space");
71 case InsetSpaceParams::PROTECTED:
72 message = _("Non-Breaking Normal Space");
74 case InsetSpaceParams::VISIBLE:
75 message = _("Non-Breaking Visible Normal Space");
77 case InsetSpaceParams::THIN:
78 message = _("Non-Breaking Thin Space (1/6 em)");
80 case InsetSpaceParams::MEDIUM:
81 message = _("Non-Breaking Medium Space (2/9 em)");
83 case InsetSpaceParams::THICK:
84 message = _("Non-Breaking Thick Space (5/18 em)");
86 case InsetSpaceParams::QUAD:
87 message = _("Quad Space (1 em)");
89 case InsetSpaceParams::QQUAD:
90 message = _("Double Quad Space (2 em)");
92 case InsetSpaceParams::ENSPACE:
93 message = _("Non-Breaking Half Quad Space (1/2 em)");
95 case InsetSpaceParams::ENSKIP:
96 message = _("Half Quad Space (1/2 em)");
98 case InsetSpaceParams::NEGTHIN:
99 message = _("Non-Breaking Negative Thin Space (-1/6 em)");
101 case InsetSpaceParams::NEGMEDIUM:
102 message = _("Non-Breaking Negative Medium Space (-2/9 em)");
104 case InsetSpaceParams::NEGTHICK:
105 message = _("Non-Breaking Negative Thick Space (-5/18 em)");
107 case InsetSpaceParams::HFILL:
108 message = _("Horizontal Fill");
110 case InsetSpaceParams::HFILL_PROTECTED:
111 message = _("Non-Breaking Horizontal Fill");
113 case InsetSpaceParams::DOTFILL:
114 message = _("Non-Breaking Horizontal Fill (Dots)");
116 case InsetSpaceParams::HRULEFILL:
117 message = _("Non-Breaking Horizontal Fill (Rule)");
119 case InsetSpaceParams::LEFTARROWFILL:
120 message = _("Non-Breaking Horizontal Fill (Left Arrow)");
122 case InsetSpaceParams::RIGHTARROWFILL:
123 message = _("Non-Breaking Horizontal Fill (Right Arrow)");
125 case InsetSpaceParams::UPBRACEFILL:
126 message = _("Non-Breaking Horizontal Fill (Up Brace)");
128 case InsetSpaceParams::DOWNBRACEFILL:
129 message = _("Non-Breaking Horizontal Fill (Down Brace)");
131 case InsetSpaceParams::CUSTOM:
133 message = support::bformat(_("Horizontal Space (%1$s)"),
134 locLengthDocString(from_ascii(params_.length.asString())));
136 case InsetSpaceParams::CUSTOM_PROTECTED:
138 message = support::bformat(_("Non-Breaking Horizontal Space (%1$s)"),
139 locLengthDocString(from_ascii(params_.length.asString())));
146 void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
148 switch (cmd.action()) {
150 case LFUN_INSET_MODIFY: {
152 string arg = to_utf8(cmd.argument());
153 if (arg == "space \\hspace{}")
154 arg += params_.length.len().empty()
155 ? " \\length 1" + string(stringFromUnit(Length::defaultUnit()))
156 : " \\length " + params_.length.asString();
157 string2params(arg, params_);
161 case LFUN_INSET_DIALOG_UPDATE:
162 cur.bv().updateDialog("space", params2string(params()));
166 Inset::doDispatch(cur, cmd);
172 bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
173 FuncStatus & status) const
175 switch (cmd.action()) {
177 case LFUN_INSET_MODIFY:
178 if (cmd.getArg(0) == "space") {
179 InsetSpaceParams params;
180 string2params(to_utf8(cmd.argument()), params);
181 status.setOnOff(params_.kind == params.kind);
182 status.setEnabled(true);
184 status.setEnabled(false);
187 case LFUN_INSET_DIALOG_UPDATE:
188 status.setEnabled(true);
191 return Inset::getStatus(cur, cmd, status);
196 int InsetSpace::rowFlags() const
198 switch (params_.kind) {
199 case InsetSpaceParams::PROTECTED:
200 case InsetSpaceParams::CUSTOM_PROTECTED:
201 case InsetSpaceParams::HFILL_PROTECTED:
202 case InsetSpaceParams::THIN:
203 case InsetSpaceParams::NEGTHIN:
204 case InsetSpaceParams::MEDIUM:
205 case InsetSpaceParams::NEGMEDIUM:
206 case InsetSpaceParams::THICK:
207 case InsetSpaceParams::NEGTHICK:
208 case InsetSpaceParams::ENSPACE:
209 case InsetSpaceParams::VISIBLE:
210 // no break after these
212 case InsetSpaceParams::NORMAL:
213 case InsetSpaceParams::QUAD:
214 case InsetSpaceParams::QQUAD:
215 case InsetSpaceParams::ENSKIP:
216 case InsetSpaceParams::CUSTOM:
217 case InsetSpaceParams::HFILL:
218 case InsetSpaceParams::DOTFILL:
219 case InsetSpaceParams::HRULEFILL:
220 case InsetSpaceParams::LEFTARROWFILL:
221 case InsetSpaceParams::RIGHTARROWFILL:
222 case InsetSpaceParams::UPBRACEFILL:
223 case InsetSpaceParams::DOWNBRACEFILL:
224 // these allow line breaking
227 return CanBreakAfter;
232 int const arrow_size = 8;
236 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
239 // The width for hfills is calculated externally in
240 // TextMetrics::setRowAlignment. The value of 5 is the
241 // minimal value when the hfill is not active.
242 dim = Dimension(5, 10, 10);
246 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
247 dim.asc = fm.maxAscent();
248 dim.des = fm.maxDescent();
249 int const em = fm.em();
251 switch (params_.kind) {
252 case InsetSpaceParams::THIN:
253 case InsetSpaceParams::NEGTHIN:
256 case InsetSpaceParams::MEDIUM:
257 case InsetSpaceParams::NEGMEDIUM:
260 case InsetSpaceParams::THICK:
261 case InsetSpaceParams::NEGTHICK:
264 case InsetSpaceParams::PROTECTED:
265 case InsetSpaceParams::VISIBLE:
266 case InsetSpaceParams::NORMAL:
267 dim.wid = fm.width(char_type(' '));
269 case InsetSpaceParams::QUAD:
272 case InsetSpaceParams::QQUAD:
275 case InsetSpaceParams::ENSPACE:
276 case InsetSpaceParams::ENSKIP:
277 dim.wid = int(0.5 * em);
279 case InsetSpaceParams::CUSTOM:
280 case InsetSpaceParams::CUSTOM_PROTECTED: {
281 int const w = mi.base.inPixels(params_.length.len());
282 int const minw = (w < 0) ? 3 * arrow_size : 4;
283 dim.wid = max(minw, abs(w));
286 case InsetSpaceParams::HFILL:
287 case InsetSpaceParams::HFILL_PROTECTED:
288 case InsetSpaceParams::DOTFILL:
289 case InsetSpaceParams::HRULEFILL:
290 case InsetSpaceParams::LEFTARROWFILL:
291 case InsetSpaceParams::RIGHTARROWFILL:
292 case InsetSpaceParams::UPBRACEFILL:
293 case InsetSpaceParams::DOWNBRACEFILL:
300 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
302 Dimension const dim = dimension(*pi.base.bv);
304 if (isHfill() || params_.length.len().value() < 0) {
305 int const asc = theFontMetrics(pi.base.font).ascent('M');
306 int const desc = theFontMetrics(pi.base.font).descent('M');
307 // Pixel height divisible by 2 for prettier fill graphics:
308 int const oddheight = (asc ^ desc) & 1;
309 int const x0 = x + 1;
310 int const x1 = x + dim.wid - 2;
311 int const y0 = y + desc - 1;
312 int const y1 = y - asc + oddheight - 1;
313 int const y2 = (y0 + y1) / 2;
314 int xoffset = (y0 - y1) / 2;
316 // Two tests for very narrow insets
317 if (xoffset > x1 - x0
318 && (params_.kind == InsetSpaceParams::LEFTARROWFILL
319 || params_.kind == InsetSpaceParams::RIGHTARROWFILL))
321 if (xoffset * 6 > (x1 - x0)
322 && (params_.kind == InsetSpaceParams::UPBRACEFILL
323 || params_.kind == InsetSpaceParams::DOWNBRACEFILL))
324 xoffset = (x1 - x0) / 6;
326 int const x2 = x0 + xoffset;
327 int const x3 = x1 - xoffset;
328 int const xm = (x0 + x1) / 2;
329 int const xml = xm - xoffset;
330 int const xmr = xm + xoffset;
332 if (params_.kind == InsetSpaceParams::HFILL) {
333 pi.pain.line(x0, y1, x0, y0, Color_added_space);
334 pi.pain.line(x0, y2, x1, y2, Color_added_space,
335 frontend::Painter::line_onoffdash);
336 pi.pain.line(x1, y1, x1, y0, Color_added_space);
337 } else if (params_.kind == InsetSpaceParams::HFILL_PROTECTED) {
338 pi.pain.line(x0, y1, x0, y0, Color_latex);
339 pi.pain.line(x0, y2, x1, y2, Color_latex,
340 frontend::Painter::line_onoffdash);
341 pi.pain.line(x1, y1, x1, y0, Color_latex);
342 } else if (params_.kind == InsetSpaceParams::DOTFILL) {
343 pi.pain.line(x0, y1, x0, y0, Color_special);
344 pi.pain.line(x0, y0, x1, y0, Color_special,
345 frontend::Painter::line_onoffdash);
346 pi.pain.line(x1, y1, x1, y0, Color_special);
347 } else if (params_.kind == InsetSpaceParams::HRULEFILL) {
348 pi.pain.line(x0, y1, x0, y0, Color_special);
349 pi.pain.line(x0, y0, x1, y0, Color_special);
350 pi.pain.line(x1, y1, x1, y0, Color_special);
351 } else if (params_.kind == InsetSpaceParams::LEFTARROWFILL) {
352 pi.pain.line(x2, y1 + 1 , x0 + 1, y2, Color_special);
353 pi.pain.line(x0 + 1, y2 + 1 , x2, y0, Color_special);
354 pi.pain.line(x0, y2 , x1, y2, Color_special);
355 } else if (params_.kind == InsetSpaceParams::RIGHTARROWFILL) {
356 pi.pain.line(x3 + 1, y1 + 1 , x1, y2, Color_special);
357 pi.pain.line(x1, y2 + 1 , x3 + 1, y0, Color_special);
358 pi.pain.line(x0, y2 , x1, y2, Color_special);
359 } else if (params_.kind == InsetSpaceParams::UPBRACEFILL) {
360 pi.pain.line(x0 + 1, y1 + 1 , x2, y2, Color_special);
361 pi.pain.line(x2, y2 , xml, y2, Color_special);
362 pi.pain.line(xml + 1, y2 + 1 , xm, y0, Color_special);
363 pi.pain.line(xm + 1, y0 , xmr, y2 + 1, Color_special);
364 pi.pain.line(xmr, y2 , x3, y2, Color_special);
365 pi.pain.line(x3 + 1, y2 , x1, y1 + 1, Color_special);
366 } else if (params_.kind == InsetSpaceParams::DOWNBRACEFILL) {
367 pi.pain.line(x0 + 1, y0 , x2, y2 + 1, Color_special);
368 pi.pain.line(x2, y2 , xml, y2, Color_special);
369 pi.pain.line(xml + 1, y2 , xm, y1 + 1, Color_special);
370 pi.pain.line(xm + 1, y1 + 1 , xmr, y2, Color_special);
371 pi.pain.line(xmr, y2 , x3, y2, Color_special);
372 pi.pain.line(x3 + 1, y2 + 1 , x1, y0, Color_special);
373 } else if (params_.kind == InsetSpaceParams::CUSTOM) {
374 pi.pain.line(x0, y1 + 1 , x2 + 1, y2, Color_special);
375 pi.pain.line(x2 + 1, y2 + 1 , x0, y0, Color_special);
376 pi.pain.line(x1 + 1, y1 + 1 , x3, y2, Color_special);
377 pi.pain.line(x3, y2 + 1 , x1 + 1, y0, Color_special);
378 pi.pain.line(x2, y2 , x3, y2, Color_special);
379 } else if (params_.kind == InsetSpaceParams::CUSTOM_PROTECTED) {
380 pi.pain.line(x0, y1 + 1 , x2 + 1, y2, Color_latex);
381 pi.pain.line(x2 + 1, y2 + 1 , x0, y0, Color_latex);
382 pi.pain.line(x1 + 1, y1 + 1 , x3, y2, Color_latex);
383 pi.pain.line(x3, y2 + 1 , x1 + 1, y0, Color_latex);
384 pi.pain.line(x2, y2 , x3, y2, Color_latex);
389 int const w = dim.wid;
390 int const h = theFontMetrics(pi.base.font).xHeight();
394 yp[0] = y - max(h / 4, 1);
395 if (params_.kind == InsetSpaceParams::NORMAL ||
396 params_.kind == InsetSpaceParams::PROTECTED ||
397 params_.kind == InsetSpaceParams::VISIBLE) {
398 xp[1] = x; yp[1] = y;
399 xp[2] = x + w - 1; yp[2] = y;
401 xp[1] = x; yp[1] = y + max(h / 4, 1);
402 xp[2] = x + w - 1; yp[2] = y + max(h / 4, 1);
405 yp[3] = y - max(h / 4, 1);
407 Color col = Color_special;
408 if (params_.kind == InsetSpaceParams::PROTECTED ||
409 params_.kind == InsetSpaceParams::ENSPACE ||
410 params_.kind == InsetSpaceParams::THIN ||
411 params_.kind == InsetSpaceParams::NEGTHIN ||
412 params_.kind == InsetSpaceParams::MEDIUM ||
413 params_.kind == InsetSpaceParams::NEGMEDIUM ||
414 params_.kind == InsetSpaceParams::THICK ||
415 params_.kind == InsetSpaceParams::NEGTHICK ||
416 params_.kind == InsetSpaceParams::CUSTOM_PROTECTED)
418 else if (params_.kind == InsetSpaceParams::VISIBLE)
419 col = Color_foreground;
421 pi.pain.lines(xp, yp, 4, col);
425 void InsetSpaceParams::write(ostream & os) const
428 case InsetSpaceParams::NORMAL:
431 case InsetSpaceParams::PROTECTED:
434 case InsetSpaceParams::VISIBLE:
435 os << "\\textvisiblespace{}";
437 case InsetSpaceParams::THIN:
438 os << "\\thinspace{}";
440 case InsetSpaceParams::MEDIUM:
441 os << "\\medspace{}";
443 case InsetSpaceParams::THICK:
444 os << "\\thickspace{}";
446 case InsetSpaceParams::QUAD:
449 case InsetSpaceParams::QQUAD:
452 case InsetSpaceParams::ENSPACE:
455 case InsetSpaceParams::ENSKIP:
458 case InsetSpaceParams::NEGTHIN:
459 os << "\\negthinspace{}";
461 case InsetSpaceParams::NEGMEDIUM:
462 os << "\\negmedspace{}";
464 case InsetSpaceParams::NEGTHICK:
465 os << "\\negthickspace{}";
467 case InsetSpaceParams::HFILL:
470 case InsetSpaceParams::HFILL_PROTECTED:
471 os << "\\hspace*{\\fill}";
473 case InsetSpaceParams::DOTFILL:
476 case InsetSpaceParams::HRULEFILL:
477 os << "\\hrulefill{}";
479 case InsetSpaceParams::LEFTARROWFILL:
480 os << "\\leftarrowfill{}";
482 case InsetSpaceParams::RIGHTARROWFILL:
483 os << "\\rightarrowfill{}";
485 case InsetSpaceParams::UPBRACEFILL:
486 os << "\\upbracefill{}";
488 case InsetSpaceParams::DOWNBRACEFILL:
489 os << "\\downbracefill{}";
491 case InsetSpaceParams::CUSTOM:
494 case InsetSpaceParams::CUSTOM_PROTECTED:
499 if (!length.len().empty())
500 os << "\n\\length " << length.asString();
504 void InsetSpaceParams::read(Lexer & lex)
506 lex.setContext("InsetSpaceParams::read");
510 // The tests for math might be disabled after a file format change
511 if (command == "\\space{}")
512 kind = InsetSpaceParams::NORMAL;
513 else if (command == "~")
514 kind = InsetSpaceParams::PROTECTED;
515 else if (command == "\\textvisiblespace{}")
516 kind = InsetSpaceParams::VISIBLE;
517 else if (command == "\\thinspace{}")
518 kind = InsetSpaceParams::THIN;
519 else if (command == "\\medspace{}")
520 kind = InsetSpaceParams::MEDIUM;
521 else if (command == "\\thickspace{}")
522 kind = InsetSpaceParams::THICK;
523 else if (command == "\\quad{}")
524 kind = InsetSpaceParams::QUAD;
525 else if (command == "\\qquad{}")
526 kind = InsetSpaceParams::QQUAD;
527 else if (command == "\\enspace{}")
528 kind = InsetSpaceParams::ENSPACE;
529 else if (command == "\\enskip{}")
530 kind = InsetSpaceParams::ENSKIP;
531 else if (command == "\\negthinspace{}")
532 kind = InsetSpaceParams::NEGTHIN;
533 else if (command == "\\negmedspace{}")
534 kind = InsetSpaceParams::NEGMEDIUM;
535 else if (command == "\\negthickspace{}")
536 kind = InsetSpaceParams::NEGTHICK;
537 else if (command == "\\hfill{}")
538 kind = InsetSpaceParams::HFILL;
539 else if (command == "\\hspace*{\\fill}")
540 kind = InsetSpaceParams::HFILL_PROTECTED;
541 else if (command == "\\dotfill{}")
542 kind = InsetSpaceParams::DOTFILL;
543 else if (command == "\\hrulefill{}")
544 kind = InsetSpaceParams::HRULEFILL;
545 else if (command == "\\hspace{}")
546 kind = InsetSpaceParams::CUSTOM;
547 else if (command == "\\leftarrowfill{}")
548 kind = InsetSpaceParams::LEFTARROWFILL;
549 else if (command == "\\rightarrowfill{}")
550 kind = InsetSpaceParams::RIGHTARROWFILL;
551 else if (command == "\\upbracefill{}")
552 kind = InsetSpaceParams::UPBRACEFILL;
553 else if (command == "\\downbracefill{}")
554 kind = InsetSpaceParams::DOWNBRACEFILL;
555 else if (command == "\\hspace*{}")
556 kind = InsetSpaceParams::CUSTOM_PROTECTED;
558 lex.printError("InsetSpace: Unknown kind: `$$Token'");
560 if (lex.checkFor("\\length"))
565 void InsetSpace::write(ostream & os) const
572 void InsetSpace::read(Lexer & lex)
575 lex >> "\\end_inset";
579 void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
581 switch (params_.kind) {
582 case InsetSpaceParams::NORMAL:
583 if (runparams.find_effective())
586 os << (runparams.free_spacing ? " " : "\\ ");
588 case InsetSpaceParams::PROTECTED:
589 if (runparams.find_effective())
591 else if (runparams.local_font &&
592 runparams.local_font->language()->lang() == "polutonikogreek")
593 // in babel's polutonikogreek, ~ is active
594 os << (runparams.free_spacing ? " " : "\\nobreakspace{}");
596 os << (runparams.free_spacing ? ' ' : '~');
598 case InsetSpaceParams::VISIBLE:
599 if (runparams.find_effective())
602 os << (runparams.free_spacing ? " " : "\\textvisiblespace{}");
604 case InsetSpaceParams::THIN:
605 if (runparams.find_effective())
608 os << (runparams.free_spacing ? " " : "\\,");
610 case InsetSpaceParams::MEDIUM:
611 if (runparams.find_effective())
613 else if (params_.math)
614 os << (runparams.free_spacing ? " " : "\\:");
616 os << (runparams.free_spacing ? " " : "\\medspace{}");
618 case InsetSpaceParams::THICK:
619 if (runparams.find_effective())
621 else if (params_.math)
622 os << (runparams.free_spacing ? " " : "\\;");
624 os << (runparams.free_spacing ? " " : "\\thickspace{}");
626 case InsetSpaceParams::QUAD:
627 if (runparams.find_effective())
630 os << (runparams.free_spacing ? " " : "\\quad{}");
632 case InsetSpaceParams::QQUAD:
633 if (runparams.find_effective()) {
638 os << (runparams.free_spacing ? " " : "\\qquad{}");
640 case InsetSpaceParams::ENSPACE:
641 if (runparams.find_effective())
644 os << (runparams.free_spacing ? " " : "\\enspace{}");
646 case InsetSpaceParams::ENSKIP:
647 if (runparams.find_effective())
650 os << (runparams.free_spacing ? " " : "\\enskip{}");
652 case InsetSpaceParams::NEGTHIN:
653 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\negthinspace{}");
655 case InsetSpaceParams::NEGMEDIUM:
656 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\negmedspace{}");
658 case InsetSpaceParams::NEGTHICK:
659 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\negthickspace{}");
661 case InsetSpaceParams::HFILL:
662 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\hfill{}");
664 case InsetSpaceParams::HFILL_PROTECTED:
665 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\hspace*{\\fill}");
667 case InsetSpaceParams::DOTFILL:
668 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\dotfill{}");
670 case InsetSpaceParams::HRULEFILL:
671 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\hrulefill{}");
673 case InsetSpaceParams::LEFTARROWFILL:
674 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\leftarrowfill{}");
676 case InsetSpaceParams::RIGHTARROWFILL:
677 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\rightarrowfill{}");
679 case InsetSpaceParams::UPBRACEFILL:
680 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\upbracefill{}");
682 case InsetSpaceParams::DOWNBRACEFILL:
683 os << (runparams.free_spacing && runparams.find_effective() ? " " : "\\downbracefill{}");
685 case InsetSpaceParams::CUSTOM:
686 if (runparams.find_effective())
688 else if (runparams.free_spacing)
691 os << "\\hspace{" << from_ascii(params_.length.asLatexString()) << "}";
693 case InsetSpaceParams::CUSTOM_PROTECTED:
694 if (runparams.find_effective())
696 else if (runparams.free_spacing)
699 os << "\\hspace*{" << from_ascii(params_.length.asLatexString()) << "}";
705 int InsetSpace::plaintext(odocstringstream & os,
706 OutputParams const &, size_t) const
708 switch (params_.kind) {
709 case InsetSpaceParams::HFILL:
710 case InsetSpaceParams::HFILL_PROTECTED:
713 case InsetSpaceParams::DOTFILL:
716 case InsetSpaceParams::HRULEFILL:
719 case InsetSpaceParams::LEFTARROWFILL:
722 case InsetSpaceParams::RIGHTARROWFILL:
725 case InsetSpaceParams::UPBRACEFILL:
728 case InsetSpaceParams::DOWNBRACEFILL:
731 case InsetSpaceParams::VISIBLE:
734 case InsetSpaceParams::ENSKIP:
737 case InsetSpaceParams::ENSPACE:
738 os.put(0x2060); // WORD JOINER, makes the breakable en space unbreakable
740 os.put(0x2060); // WORD JOINER, makes the breakable en space unbreakable
742 case InsetSpaceParams::QUAD:
745 case InsetSpaceParams::QQUAD:
749 case InsetSpaceParams::THIN:
752 case InsetSpaceParams::MEDIUM:
753 os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable medium space breakable
755 os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable medium space breakable
757 case InsetSpaceParams::THICK:
758 os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable thick space breakable
760 os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable thick space breakable
762 case InsetSpaceParams::PROTECTED:
763 case InsetSpaceParams::CUSTOM_PROTECTED:
766 case InsetSpaceParams::NEGTHIN:
767 case InsetSpaceParams::NEGMEDIUM:
768 case InsetSpaceParams::NEGTHICK:
777 void InsetSpace::docbook(XMLStream & xs, OutputParams const &) const
779 switch (params_.kind) {
780 case InsetSpaceParams::NORMAL:
781 xs << XMLStream::ESCAPE_NONE << " ";
783 case InsetSpaceParams::QUAD:
784 xs << XMLStream::ESCAPE_NONE << " "; // HTML:  
786 case InsetSpaceParams::QQUAD:
787 xs << XMLStream::ESCAPE_NONE << "  "; // HTML:   
789 case InsetSpaceParams::ENSKIP:
790 xs << XMLStream::ESCAPE_NONE << " "; // HTML:  
792 case InsetSpaceParams::PROTECTED:
793 xs << XMLStream::ESCAPE_NONE << " "; // HTML:
795 case InsetSpaceParams::VISIBLE:
796 xs << XMLStream::ESCAPE_NONE << "␣";
798 case InsetSpaceParams::ENSPACE: // HTML: ⁠ ⁠ (word joiners)
799 xs << XMLStream::ESCAPE_NONE << "⁠ ⁠";
801 case InsetSpaceParams::THIN:
802 xs << XMLStream::ESCAPE_NONE << " "; // HTML: &thinspace;
804 case InsetSpaceParams::MEDIUM:
805 xs << XMLStream::ESCAPE_NONE << " "; // HTML:  
807 case InsetSpaceParams::THICK:
808 xs << XMLStream::ESCAPE_NONE << " "; // HTML:  
810 case InsetSpaceParams::NEGTHIN:
811 case InsetSpaceParams::NEGMEDIUM:
812 case InsetSpaceParams::NEGTHICK:
813 xs << XMLStream::ESCAPE_NONE << " "; // HTML:
815 case InsetSpaceParams::HFILL:
816 case InsetSpaceParams::HFILL_PROTECTED:
817 case InsetSpaceParams::DOTFILL:
818 case InsetSpaceParams::HRULEFILL:
819 case InsetSpaceParams::LEFTARROWFILL:
820 case InsetSpaceParams::RIGHTARROWFILL:
821 case InsetSpaceParams::UPBRACEFILL:
822 case InsetSpaceParams::DOWNBRACEFILL:
823 case InsetSpaceParams::CUSTOM:
824 case InsetSpaceParams::CUSTOM_PROTECTED:
831 docstring InsetSpace::xhtml(XMLStream & xs, OutputParams const &) const
834 switch (params_.kind) {
835 case InsetSpaceParams::NORMAL:
838 case InsetSpaceParams::ENSKIP:
841 case InsetSpaceParams::ENSPACE:
842 output ="⁠ ⁠";
844 case InsetSpaceParams::QQUAD:
845 output ="  ";
847 case InsetSpaceParams::THICK:
850 case InsetSpaceParams::QUAD:
853 case InsetSpaceParams::MEDIUM:
856 case InsetSpaceParams::THIN:
859 case InsetSpaceParams::PROTECTED:
860 case InsetSpaceParams::NEGTHIN:
861 case InsetSpaceParams::NEGMEDIUM:
862 case InsetSpaceParams::NEGTHICK:
865 // no XHTML entity, only unicode code for space character exists
866 case InsetSpaceParams::VISIBLE:
869 case InsetSpaceParams::HFILL:
870 case InsetSpaceParams::HFILL_PROTECTED:
871 case InsetSpaceParams::DOTFILL:
872 case InsetSpaceParams::HRULEFILL:
873 case InsetSpaceParams::LEFTARROWFILL:
874 case InsetSpaceParams::RIGHTARROWFILL:
875 case InsetSpaceParams::UPBRACEFILL:
876 case InsetSpaceParams::DOWNBRACEFILL:
878 // Can we do anything with those in HTML?
880 case InsetSpaceParams::CUSTOM:
882 // Probably we could do some sort of blank span?
884 case InsetSpaceParams::CUSTOM_PROTECTED:
886 // Probably we could do some sort of blank span?
890 // don't escape the entities!
891 xs << XMLStream::ESCAPE_NONE << from_ascii(output);
896 void InsetSpace::validate(LaTeXFeatures & features) const
898 if (features.isAvailable("LaTeX-2020/10/01"))
899 // As of this version, the LaTeX kernel
900 // includes all spaces.
903 // In earlier versions, we require amsmath
904 // for some text and math spaces
905 if ((params_.kind == InsetSpaceParams::NEGMEDIUM
906 || params_.kind == InsetSpaceParams::NEGTHICK)
908 && (params_.kind == InsetSpaceParams::MEDIUM
909 || params_.kind == InsetSpaceParams::THICK)))
910 features.require("amsmath");
914 void InsetSpace::toString(odocstream & os) const
916 odocstringstream ods;
917 plaintext(ods, OutputParams(0));
922 void InsetSpace::forOutliner(docstring & os, size_t const, bool const) const
924 // There's no need to be cute here.
929 bool InsetSpace::isHfill() const
931 return params_.kind == InsetSpaceParams::HFILL
932 || params_.kind == InsetSpaceParams::HFILL_PROTECTED
933 || params_.kind == InsetSpaceParams::DOTFILL
934 || params_.kind == InsetSpaceParams::HRULEFILL
935 || params_.kind == InsetSpaceParams::LEFTARROWFILL
936 || params_.kind == InsetSpaceParams::RIGHTARROWFILL
937 || params_.kind == InsetSpaceParams::UPBRACEFILL
938 || params_.kind == InsetSpaceParams::DOWNBRACEFILL;
942 string InsetSpace::contextMenuName() const
944 return "context-space";
948 void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
950 params = InsetSpaceParams();
954 istringstream data(in);
957 lex.setContext("InsetSpace::string2params");
959 string const name = lex.getString();
960 if (name == "mathspace")
964 // we can try to read this even if the name is wrong
965 LATTEST(name == "space");
968 // There are cases, such as when we are called via getStatus() from
969 // Dialog::canApply(), where we are just called with "space" rather
970 // than a full "space \type{}\n\\end_inset".
976 string InsetSpace::params2string(InsetSpaceParams const & params)
981 data << "space" << ' ';