2003-05-22 10:40:57 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetSpace.cpp
|
2003-05-22 10:40:57 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Asger Alstrup Nielsen
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-09-07 01:45:40 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
2003-05-22 10:40:57 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-05-22 10:40:57 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetSpace.h"
|
2003-05-22 10:40:57 +00:00
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
|
#include "Dimension.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
#include "OutputParams.h"
|
2003-05-22 10:40:57 +00:00
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
|
#include "frontends/FontMetrics.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
#include "support/docstream.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
namespace lyx {
|
2003-05-22 10:40:57 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-28 06:47:15 +00:00
|
|
|
|
InsetSpace::InsetSpace()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-05-22 10:40:57 +00:00
|
|
|
|
InsetSpace::InsetSpace(Kind k)
|
|
|
|
|
: kind_(k)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetSpace::Kind InsetSpace::kind() const
|
|
|
|
|
{
|
|
|
|
|
return kind_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
2007-11-01 22:17:22 +00:00
|
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.asc = fm.maxAscent();
|
|
|
|
|
dim.des = fm.maxDescent();
|
2003-05-22 10:40:57 +00:00
|
|
|
|
|
|
|
|
|
switch (kind_) {
|
|
|
|
|
case THIN:
|
|
|
|
|
case NEGTHIN:
|
2007-12-21 19:34:13 +00:00
|
|
|
|
dim.wid = fm.width(char_type('M')) / 6;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROTECTED:
|
|
|
|
|
case NORMAL:
|
2007-12-21 19:34:13 +00:00
|
|
|
|
dim.wid = fm.width(char_type(' '));
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case QUAD:
|
2007-12-21 19:34:13 +00:00
|
|
|
|
dim.wid = fm.width(char_type('M'));
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case QQUAD:
|
2007-12-21 19:34:13 +00:00
|
|
|
|
dim.wid = 2 * fm.width(char_type('M'));
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case ENSPACE:
|
|
|
|
|
case ENSKIP:
|
2007-12-25 18:49:55 +00:00
|
|
|
|
dim.wid = int(0.5 * fm.width(char_type('M')));
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-09-25 07:41:03 +00:00
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
void InsetSpace::draw(PainterInfo & pi, int x, int y) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
2007-09-25 07:41:03 +00:00
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
int const w = dim.wid;
|
2006-10-11 17:24:46 +00:00
|
|
|
|
int const h = theFontMetrics(pi.base.font)
|
2006-10-07 16:15:06 +00:00
|
|
|
|
.ascent('x');
|
2003-05-22 10:40:57 +00:00
|
|
|
|
int xp[4], yp[4];
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
xp[0] = x;
|
|
|
|
|
yp[0] = y - max(h / 4, 1);
|
2007-12-26 10:38:59 +00:00
|
|
|
|
if (kind_ == NORMAL || kind_ == PROTECTED) {
|
2003-05-30 06:48:24 +00:00
|
|
|
|
xp[1] = x; yp[1] = y;
|
|
|
|
|
xp[2] = x + w; yp[2] = y;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
} else {
|
2003-05-30 06:48:24 +00:00
|
|
|
|
xp[1] = x; yp[1] = y + max(h / 4, 1);
|
|
|
|
|
xp[2] = x + w; yp[2] = y + max(h / 4, 1);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
}
|
2003-05-30 06:48:24 +00:00
|
|
|
|
xp[3] = x + w;
|
|
|
|
|
yp[3] = y - max(h / 4, 1);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
|
|
|
|
|
if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
|
2007-10-25 12:41:02 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 4, Color_latex);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
else
|
2007-10-25 12:41:02 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 4, Color_special);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetSpace::write(Buffer const &, ostream & os) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
|
|
|
|
string command;
|
|
|
|
|
switch (kind_) {
|
|
|
|
|
case NORMAL:
|
2005-09-28 09:40:50 +00:00
|
|
|
|
command = "\\space{}";
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROTECTED:
|
|
|
|
|
command = "~";
|
|
|
|
|
break;
|
|
|
|
|
case THIN:
|
2005-09-28 09:40:50 +00:00
|
|
|
|
command = "\\thinspace{}";
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case QUAD:
|
|
|
|
|
command = "\\quad{}";
|
|
|
|
|
break;
|
|
|
|
|
case QQUAD:
|
|
|
|
|
command = "\\qquad{}";
|
|
|
|
|
break;
|
|
|
|
|
case ENSPACE:
|
|
|
|
|
command = "\\enspace{}";
|
|
|
|
|
break;
|
|
|
|
|
case ENSKIP:
|
|
|
|
|
command = "\\enskip{}";
|
|
|
|
|
break;
|
|
|
|
|
case NEGTHIN:
|
|
|
|
|
command = "\\negthinspace{}";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
os << "\\InsetSpace " << command << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetSpace::read(Buffer const &, Lexer & lex)
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
2004-10-05 12:56:22 +00:00
|
|
|
|
lex.next();
|
2003-05-22 10:40:57 +00:00
|
|
|
|
string const command = lex.getString();
|
|
|
|
|
|
2005-09-28 09:40:50 +00:00
|
|
|
|
if (command == "\\space{}")
|
2003-05-22 10:40:57 +00:00
|
|
|
|
kind_ = NORMAL;
|
|
|
|
|
else if (command == "~")
|
|
|
|
|
kind_ = PROTECTED;
|
2005-09-28 09:40:50 +00:00
|
|
|
|
else if (command == "\\thinspace{}")
|
2003-05-22 10:40:57 +00:00
|
|
|
|
kind_ = THIN;
|
|
|
|
|
else if (command == "\\quad{}")
|
|
|
|
|
kind_ = QUAD;
|
|
|
|
|
else if (command == "\\qquad{}")
|
|
|
|
|
kind_ = QQUAD;
|
|
|
|
|
else if (command == "\\enspace{}")
|
|
|
|
|
kind_ = ENSPACE;
|
|
|
|
|
else if (command == "\\enskip{}")
|
|
|
|
|
kind_ = ENSKIP;
|
|
|
|
|
else if (command == "\\negthinspace{}")
|
|
|
|
|
kind_ = NEGTHIN;
|
|
|
|
|
else
|
|
|
|
|
lex.printError("InsetSpace: Unknown kind: `$$Token'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetSpace::latex(Buffer const &, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
|
|
|
|
switch (kind_) {
|
|
|
|
|
case NORMAL:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? " " : "\\ ");
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROTECTED:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? ' ' : '~');
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case THIN:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? " " : "\\,");
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case QUAD:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? " " : "\\quad{}");
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case QQUAD:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? " " : "\\qquad{}");
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case ENSPACE:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? " " : "\\enspace{}");
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case ENSKIP:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? " " : "\\enskip{}");
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case NEGTHIN:
|
2003-05-23 08:59:47 +00:00
|
|
|
|
os << (runparams.free_spacing ? " " : "\\negthinspace{}");
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetSpace::plaintext(Buffer const &, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
2007-02-15 23:44:33 +00:00
|
|
|
|
os << ' ';
|
|
|
|
|
return 1;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetSpace::docbook(Buffer const &, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
|
|
|
|
switch (kind_) {
|
|
|
|
|
case NORMAL:
|
|
|
|
|
case QUAD:
|
|
|
|
|
case QQUAD:
|
|
|
|
|
case ENSKIP:
|
|
|
|
|
os << " ";
|
|
|
|
|
break;
|
|
|
|
|
case PROTECTED:
|
|
|
|
|
case ENSPACE:
|
|
|
|
|
case THIN:
|
|
|
|
|
case NEGTHIN:
|
|
|
|
|
os << " ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetSpace::textString(Buffer const & buf, odocstream & os,
|
2005-11-25 14:40:34 +00:00
|
|
|
|
OutputParams const & op) const
|
|
|
|
|
{
|
|
|
|
|
return plaintext(buf, os, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetSpace::clone() const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetSpace(kind_);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetSpace::isChar() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InsetSpace::isLetter() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InsetSpace::isSpace() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|