]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
fix the smallcaps drawing, move xfont metrics functions out from LyXFont, move non...
[lyx.git] / src / insets / insetlabel.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetlabel.h"
18
19 using std::ostream;
20
21 /* Label. Used to insert a label automatically */
22
23
24 InsetLabel::InsetLabel(string const & cmd)
25 {
26         scanCommand(cmd);
27 }
28
29
30 Inset * InsetLabel::Clone() const
31 {
32         return new InsetLabel(getCommand());
33 }
34
35
36 int InsetLabel::GetNumberOfLabels() const
37 {
38         return 1;
39 }
40
41
42 string InsetLabel::getLabel(int) const
43 {
44         return contents;
45 }
46
47
48 int InsetLabel::Latex(ostream & os,
49                       signed char /*fragile*/, bool /*fs*/) const
50 {
51         os << escape(getCommand());
52         return 0;
53 }
54
55
56 int InsetLabel::Linuxdoc(ostream & os) const
57 {
58         os << "<label id=\"" << getContents() << "\" >";
59         return 0;
60 }
61
62
63 int InsetLabel::DocBook(ostream & os) const
64 {
65         os << "<anchor id=\"" << getContents() << "\" >";
66         return 0;
67 }
68
69
70 // This function escapes 8-bit characters and other problematic characters
71 // It's exactly the same code as in insetref.C.
72 string InsetLabel::escape(string const & lab) const {
73         char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
74                               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
75         string enc;
76         for (string::size_type i= 0; i < lab.length(); ++i) {
77                 unsigned char c = lab[i];
78                 if (c >= 128 || c == '=' || c == '%') {
79                         enc += '=';
80                         enc += hexdigit[c >> 4];
81                         enc += hexdigit[c & 15];
82                 } else {
83                         enc += c;
84                 }
85         }
86         return enc;
87 }