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
|
|
|
|
* Copyright 1995-1999 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"
|
|
|
|
|
|
|
|
/* 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-02-18 22:22:42 +00:00
|
|
|
int InsetLabel::Latex(ostream & os, signed char /*fragile*/) 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-02 02:19:43 +00:00
|
|
|
#ifndef USE_OSTREAM_ONLY
|
2000-02-18 22:22:42 +00:00
|
|
|
int InsetLabel::Latex(string & file, signed char /*fragile*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
file += escape(getCommand());
|
|
|
|
return 0;
|
|
|
|
}
|
2000-03-02 02:19:43 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-02-18 22:22:42 +00:00
|
|
|
int InsetLabel::Linuxdoc(string & file) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
file += "<label id=\"" + getContents() +"\" >";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-18 22:22:42 +00:00
|
|
|
int InsetLabel::DocBook(string & file) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
file += "<anchor id=\"" + getContents() +"\" >";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|