1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 10:58:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetlabel.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
#include "support/LOstream.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* Label. Used to insert a label automatically */
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
InsetLabel::InsetLabel(string const & cmd)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
scanCommand(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
Inset * InsetLabel::Clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
return new InsetLabel(getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetLabel::GetNumberOfLabels() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string InsetLabel::getLabel(int) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return contents;
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
int InsetLabel::Latex(ostream & os,
|
|
|
|
signed char /*fragile*/, bool /*fs*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
os << escape(getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
int InsetLabel::Linuxdoc(ostream & os) const
|
|
|
|
{
|
|
|
|
os << "<label id=\"" << getContents() << "\" >";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetLabel::DocBook(ostream & os) const
|
|
|
|
{
|
|
|
|
os << "<anchor id=\"" << getContents() << "\" >";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// This function escapes 8-bit characters and other problematic characters
|
|
|
|
// It's exactly the same code as in insetref.C.
|
1999-10-02 16:21:10 +00:00
|
|
|
string InsetLabel::escape(string const & lab) const {
|
1999-09-27 18:44:28 +00:00
|
|
|
char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
1999-10-02 16:21:10 +00:00
|
|
|
string enc;
|
1999-11-15 10:58:38 +00:00
|
|
|
for (string::size_type i= 0; i < lab.length(); ++i) {
|
1999-11-04 01:40:20 +00:00
|
|
|
unsigned char c = lab[i];
|
|
|
|
if (c >= 128 || c == '=' || c == '%') {
|
1999-09-27 18:44:28 +00:00
|
|
|
enc += '=';
|
1999-11-04 01:40:20 +00:00
|
|
|
enc += hexdigit[c >> 4];
|
1999-09-27 18:44:28 +00:00
|
|
|
enc += hexdigit[c & 15];
|
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
enc += c;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return enc;
|
|
|
|
}
|