summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/Alphabet.cpp
Unidiff
Diffstat (limited to 'inputmethods/dasher/Alphabet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/dasher/Alphabet.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/inputmethods/dasher/Alphabet.cpp b/inputmethods/dasher/Alphabet.cpp
new file mode 100644
index 0000000..dc58b35
--- a/dev/null
+++ b/inputmethods/dasher/Alphabet.cpp
@@ -0,0 +1,140 @@
1// Alphabet.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include "Alphabet.h"
10#include "AlphabetMap.h"
11
12//#include <iostream>
13//WinCE doesn't have iostream!
14
15using namespace Dasher;
16using namespace std;
17
18
19CAlphabet::CAlphabet() : m_Groups(0), m_DefaultEncoding(Opts::Western), m_Orientation(Opts::LeftToRight)
20{
21 m_Characters.push_back("");
22 m_Display.push_back("");
23 m_Colours.push_back("");
24 m_Foreground.push_back("");
25 m_Group.push_back(0);
26}
27
28
29void CAlphabet::GetSymbols(vector<symbol>* Symbols, string* Input, bool IsMore)
30{
31 string Tmp;
32 symbol CurSymbol=0, TmpSymbol=0;
33 bool KeyIsPrefix;
34 int z= Input->size();
35 int extras;
36 unsigned int bit;
37
38 for (unsigned int i=0; i<Input->size(); i++) {
39
40 Tmp = (*Input)[i];
41
42 /* The string we've been given is in UTF-8. The symbols are
43 also in UTF-8, so we need to pass the entire UTF-8 character
44 which may be several bytes long. RFC 2279 describes this
45 encoding */
46
47 if ((*Input)[i] & 0x80) { // Character is more than 1 byte long
48 extras = 1;
49 for (bit = 0x20; ((*Input)[i] & bit) != 0; bit >>= 1)
50 extras++;
51 if (extras > 5) {
52 } // Malformed character
53 while (extras-->0) {
54 Tmp += (*Input)[++i];
55 }
56 }
57
58 CurSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
59
60 if (KeyIsPrefix) {
61 CurSymbol = 0;
62 for (; i<Input->size(); i++) {
63
64 Tmp += (*Input)[i];
65
66 TmpSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
67 if (TmpSymbol>0) {
68 CurSymbol = TmpSymbol;
69 }
70 if (!KeyIsPrefix) {
71 if (CurSymbol!=0) {
72 Symbols->push_back(CurSymbol);
73 } else {
74 i -= Tmp.size()-1;
75 //Tmp.erase(Tmp.begin(), Tmp.end());
76 Tmp = "";
77 }
78 break;
79 }
80 }
81 } else {
82 if (CurSymbol!=0)
83 Symbols->push_back(CurSymbol);
84 }
85 }
86
87 if (IsMore)
88 if (KeyIsPrefix)
89 *Input = Tmp;
90 else
91 *Input = "";
92 else
93 if (KeyIsPrefix)
94 Symbols->push_back(CurSymbol);
95}
96
97
98// add single char to the character set
99void CAlphabet::AddChar(const string NewCharacter, const string Display, const string Colour, const string Foreground)
100{
101 m_Characters.push_back(NewCharacter);
102 m_Display.push_back(Display);
103 m_Colours.push_back(Colour);
104 m_Foreground.push_back(Foreground);
105 m_Group.push_back(m_Groups);
106
107 symbol ThisSymbol = m_Characters.size()-1;
108 TextMap.Add(NewCharacter, ThisSymbol);
109}
110
111
112void CAlphabet::StartNewGroup()
113{
114 m_Groups++;
115}
116
117
118// diagnostic dump of character set
119void CAlphabet::dump() const {
120// TODO
121/*
122 dchar deb[256];
123 unsigned int i;
124 for (i=1;i<m_vtCharacters.size();i++) {
125 //wsprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]); // Windows specific
126 Usprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]);
127 DebugOutput(deb);
128 }
129*/
130}
131
132int CAlphabet::GetTextColour(symbol Symbol)
133{
134 std::string TextColour=m_Foreground[Symbol];
135 if (TextColour != "") {
136 return atoi(TextColour.c_str());
137 } else {
138 return 0;
139 }
140}