]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
the freespacing patch from Kayvan, draw the math empty delim with onoffdash, asure...
[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-1999 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 /* Label. Used to insert a label automatically */
20
21
22 InsetLabel::InsetLabel(string const & cmd)
23 {
24         scanCommand(cmd);
25 }
26
27
28 Inset * InsetLabel::Clone() const
29 {
30         return new InsetLabel(getCommand());
31 }
32
33
34 int InsetLabel::GetNumberOfLabels() const
35 {
36         return 1;
37 }
38
39
40 string InsetLabel::getLabel(int) const
41 {
42         return contents;
43 }
44
45
46 int InsetLabel::Latex(ostream & os, signed char /*fragile*/, bool /*fs*/) const
47 {
48         os << escape(getCommand());
49         return 0;
50 }
51
52
53 #ifndef USE_OSTREAM_ONLY
54 int InsetLabel::Latex(string & file, signed char /*fragile*/, bool /*fs*/) const
55 {
56         file += escape(getCommand());
57         return 0;
58 }
59
60
61 int InsetLabel::Linuxdoc(string & file) const
62 {
63         file += "<label id=\"" + getContents() +"\" >";
64         return 0;
65 }
66
67
68 int InsetLabel::DocBook(string & file) const
69 {
70         file += "<anchor id=\"" + getContents() +"\" >";
71         return 0;
72 }
73
74 #else
75
76 int InsetLabel::Linuxdoc(ostream & os) const
77 {
78         os << "<label id=\"" << getContents() << "\" >";
79         return 0;
80 }
81
82
83 int InsetLabel::DocBook(ostream & os) const
84 {
85         os << "<anchor id=\"" << getContents() << "\" >";
86         return 0;
87 }
88 #endif
89
90
91
92
93 // This function escapes 8-bit characters and other problematic characters
94 // It's exactly the same code as in insetref.C.
95 string InsetLabel::escape(string const & lab) const {
96         char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
97                               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
98         string enc;
99         for (string::size_type i= 0; i < lab.length(); ++i) {
100                 unsigned char c = lab[i];
101                 if (c >= 128 || c == '=' || c == '%') {
102                         enc += '=';
103                         enc += hexdigit[c >> 4];
104                         enc += hexdigit[c & 15];
105                 } else {
106                         enc += c;
107                 }
108         }
109         return enc;
110 }