]> git.lyx.org Git - lyx.git/blob - src/tex-accent.C
Fix loop when opening TOC widget in an empty document, basically by Richard Heck.
[lyx.git] / src / tex-accent.C
1 /**
2  * \file tex-accent.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Matthias Ettrich
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "tex-accent.h"
15 #include "debug.h"
16
17 #include "support/convert.h"
18 #include "support/docstream.h"
19
20
21 namespace lyx {
22
23 // FIXME This file has nothing to do with TeX anymore
24
25 /* the names used by TeX and XWindows for deadkeys/accents are not the same
26    so here follows a table to clearify the differences. Please correct this
27    if I got it wrong
28
29    |------------------|------------------|------------------|--------------|
30    |      TeX         |     XWindows     |   \bind/LFUN     | used by intl |
31    |------------------|------------------|------------------|--------------|
32    |    grave         |    grave         |LFUN_ACCENT_GRAVE        | grave
33    |    acute         |    acute         |LFUN_ACCENT_ACUTE        | acute
34    |    circumflex    |    circumflex    |LFUN_ACCENT_CIRCUMFLEX   | circumflex
35    | umlaut/dieresis  |    diaeresis     |LFUN_ACCENT_UMLAUT       | umlaut
36    |    tilde         |    tilde         |LFUN_ACCENT_TILDE        | tilde
37    |    macron        |    maron         |LFUN_ACCENT_MACRON       | macron
38    |    dot           |    abovedot      |LFUN_ACCENT_DOT          | dot
39    |    cedilla       |    cedilla       |LFUN_ACCENT_CEDILLA      | cedilla
40    |    underdot      |                  |LFUN_ACCENT_UNDERDOT     | underdot
41    |    underbar      |                  |LFUN_ACCENT_UNDERBAR     | underbar
42    |    hácek         |    caron         |LFUN_ACCENT_CARON        | caron
43    |    breve         |    breve         |LFUN_ACCENT_BREVE        | breve
44    |    tie           |                  |LFUN_ACCENT_TIE          | tie
45    | Hungarian umlaut |    doubleacute   |LFUN_ACCENT_HUNGARIAN_UMLAUT  | hungarian umlaut
46    |    circle        |    abovering     |LFUN_ACCENT_CIRCLE       | circle
47    |                  |    ogonek        |                  |
48    |                  |    iota          |                  |
49    |                  |    voiced_sound  |                  |
50    |                  | semivoiced_sound |                  |
51    |                  |                  |LFUN_ACCENT_SPECIAL_CARON| special caron
52    */
53 // I am not sure how some of the XWindows names coresponds to the TeX ones.
54
55 tex_accent_struct lyx_accent_table[] = {
56         {TEX_NOACCENT,   0,      "",                LFUN_NOACTION},
57         {TEX_ACUTE,      0x0301, "acute",           LFUN_ACCENT_ACUTE},
58         {TEX_GRAVE,      0x0300, "grave",           LFUN_ACCENT_GRAVE},
59         {TEX_MACRON,     0x0304, "macron",          LFUN_ACCENT_MACRON},
60         {TEX_TILDE,      0x0303, "tilde",           LFUN_ACCENT_TILDE},
61         {TEX_UNDERBAR,   0x0320, "underbar",        LFUN_ACCENT_UNDERBAR},
62         {TEX_CEDILLA,    0x0327, "cedilla",         LFUN_ACCENT_CEDILLA},
63         {TEX_UNDERDOT,   0x0323, "underdot",        LFUN_ACCENT_UNDERDOT},
64         {TEX_CIRCUMFLEX, 0x0302, "circumflex",      LFUN_ACCENT_CIRCUMFLEX},
65         {TEX_CIRCLE,     0x030a, "circle",          LFUN_ACCENT_CIRCLE},
66         {TEX_TIE,        0x0361, "tie",             LFUN_ACCENT_TIE},
67         {TEX_BREVE,      0x0306, "breve",           LFUN_ACCENT_BREVE},
68         {TEX_CARON,      0x030c, "caron",           LFUN_ACCENT_CARON},
69 //      {TEX_SPECIAL_CARON, 0x030c, "ooo",          LFUN_ACCENT_SPECIAL_CARON},
70         // Don't fix this typo for compatibility reasons!
71         {TEX_HUNGUML,    0x030b, "hugarian_umlaut", LFUN_ACCENT_HUNGARIAN_UMLAUT},
72         {TEX_UMLAUT,     0x0308, "umlaut",          LFUN_ACCENT_UMLAUT},
73         {TEX_DOT,        0x0307, "dot",             LFUN_ACCENT_DOT},
74         {TEX_OGONEK,     0x0328, "ogonek",          LFUN_ACCENT_OGONEK}
75 };
76
77
78 tex_accent_struct get_accent(kb_action action)
79 {
80         int i = 0;
81         while (i <= TEX_MAX_ACCENT) {
82                 if (lyx_accent_table[i].action == action)
83                         return lyx_accent_table[i];
84                 ++i;
85         }
86         struct tex_accent_struct temp = { static_cast<tex_accent>(0), 0,
87                                           0, static_cast<kb_action>(0)};
88         return temp;
89 }
90
91
92 docstring const DoAccent(docstring const & s, tex_accent accent)
93 {
94         if (s.empty())
95                 return docstring(1, lyx_accent_table[accent].ucs4);
96
97         odocstringstream os;
98         os.put(s[0]);
99         os.put(lyx_accent_table[accent].ucs4);
100         if (s.length() > 1) {
101                 if (accent != TEX_TIE || s.length() > 2)
102                         lyxerr << "Warning: Too many characters given for accent "
103                                << lyx_accent_table[accent].name << '.' << std::endl;
104                 os << s.substr(1);
105         }
106         return normalize_kc(os.str());
107 }
108
109
110 docstring const DoAccent(char_type c, tex_accent accent)
111 {
112         return DoAccent(docstring(1, c), accent);
113 }
114
115
116 } // namespace lyx