2003-05-22 10:40:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetspace.C
|
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
#include "insetspace.h"
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
#include "LColor.h"
|
2003-05-22 10:40:57 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-05-30 06:48:24 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "outputparams.h"
|
2003-05-22 10:40:57 +00:00
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
using std::max;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
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_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
2003-06-02 10:03:27 +00:00
|
|
|
|
LyXFont & font = mi.base.font;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.asc = font_metrics::maxAscent(font);
|
|
|
|
|
dim.des = font_metrics::maxDescent(font);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
|
|
|
|
|
switch (kind_) {
|
|
|
|
|
case THIN:
|
|
|
|
|
case NEGTHIN:
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.wid = font_metrics::width("x", font) / 3;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROTECTED:
|
|
|
|
|
case NORMAL:
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.wid = font_metrics::width("x", font);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case QUAD:
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.wid = 20;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case QQUAD:
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.wid = 40;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case ENSPACE:
|
|
|
|
|
case ENSKIP:
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.wid = 10;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = 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
|
|
|
|
{
|
2003-07-18 07:47:07 +00:00
|
|
|
|
int const w = width();
|
2003-05-30 06:48:24 +00:00
|
|
|
|
int const h = font_metrics::ascent('x', pi.base.font);
|
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);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
if (kind_ == NORMAL) {
|
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)
|
2003-05-30 06:48:24 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 4, LColor::latex);
|
2003-05-22 10:40:57 +00:00
|
|
|
|
else
|
2003-05-30 06:48:24 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 4, LColor::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:
|
|
|
|
|
command = "\\space";
|
|
|
|
|
break;
|
|
|
|
|
case PROTECTED:
|
|
|
|
|
command = "~";
|
|
|
|
|
break;
|
|
|
|
|
case THIN:
|
|
|
|
|
command = "\\,";
|
|
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This function will not be necessary when lyx3
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetSpace::read(Buffer const &, LyXLex & lex)
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
string const command = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (command == "\\space")
|
|
|
|
|
kind_ = NORMAL;
|
|
|
|
|
else if (command == "~")
|
|
|
|
|
kind_ = PROTECTED;
|
|
|
|
|
else if (command == "\\,")
|
|
|
|
|
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'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetSpace::latex(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
int InsetSpace::plaintext(Buffer const &, ostream & os,
|
|
|
|
|
OutputParams const &) const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
|
|
|
|
switch (kind_) {
|
|
|
|
|
case NORMAL:
|
|
|
|
|
case PROTECTED:
|
|
|
|
|
case THIN:
|
|
|
|
|
case QUAD:
|
|
|
|
|
case QQUAD:
|
|
|
|
|
case ENSPACE:
|
|
|
|
|
case ENSKIP:
|
|
|
|
|
case NEGTHIN:
|
|
|
|
|
os << ' ';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetSpace::linuxdoc(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetSpace::docbook(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetSpace::clone() const
|
2003-05-22 10:40:57 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(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;
|
|
|
|
|
}
|