1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  *  SPDX-FileCopyrightText: 2005 Takuro Ashie
4  *  SPDX-FileCopyrightText: 2012 CSSlayer <wengxt@gmail.com>
5  *
6  *  SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #ifndef __FCITX_ANTHY_READING_H__
10 #define __FCITX_ANTHY_READING_H__
11 
12 #include "engine.h"
13 #include "kana.h"
14 #include "key2kana.h"
15 #include "nicola.h"
16 
17 class AnthyState;
18 
19 typedef enum {
20     FCITX_ANTHY_STRING_LATIN,
21     FCITX_ANTHY_STRING_WIDE_LATIN,
22     FCITX_ANTHY_STRING_HIRAGANA,
23     FCITX_ANTHY_STRING_KATAKANA,
24     FCITX_ANTHY_STRING_HALF_KATAKANA,
25 } StringType;
26 
27 class Reading;
28 class ReadingSegment;
29 typedef std::vector<ReadingSegment> ReadingSegments;
30 
31 class ReadingSegment {
32     friend class Reading;
33 
34 public:
35     ReadingSegment();
36     virtual ~ReadingSegment();
37 
get()38     const std::string &get() { return kana; }
get_raw()39     const std::string &get_raw() { return raw; }
40 
41     void split(ReadingSegments &segments);
42 
43 private:
44     std::string raw;
45     std::string kana;
46 };
47 
48 class Reading {
49 public:
50     Reading(AnthyState &anthy);
51     virtual ~Reading();
52 
53     bool canProcesKeyEvent(const fcitx::KeyEvent &key);
54     bool processKeyEvent(const fcitx::KeyEvent &key);
55     void finish();
56     void clear();
57 
58     std::string getByChar(unsigned int start = 0, int length = -1,
59                           StringType type = FCITX_ANTHY_STRING_HIRAGANA);
60     std::string getRawByChar(unsigned int start = 0, int length = -1);
61     bool append(const fcitx::KeyEvent &key, const std::string &string);
62     void erase(unsigned int start = 0, int length = -1,
63                bool allow_split = false);
64 
65     unsigned int length();
66     unsigned int utf8Length();
67     unsigned int caretPos();
68     unsigned int caretPosByChar();
69     void setCaretPosByChar(unsigned int pos);
70     void moveCaret(int step, bool allow_split = false);
71 
72     void setTypingMethod(TypingMethod method);
73     TypingMethod typingMethod();
74     void setPeriodStyle(PeriodStyle style);
75     PeriodStyle periodStyle();
76     void setCommaStyle(CommaStyle style);
77     CommaStyle commaStyle();
78     void setBracketStyle(BracketStyle style);
79     BracketStyle bracketStyle();
80     void setSlashStyle(SlashStyle style);
81     SlashStyle slashStyle();
82     void setSymbolHalf(bool half);
83     bool isSymbolHalf();
84     void setNumberHalf(bool half);
85     bool isNumberHalf();
86     void setPseudoAsciiMode(int mode);
87     bool isPseudoAsciiMode();
88     void resetPseudoAsciiMode();
89 
90 private:
91     void resetPending();
92     void splitSegment(unsigned int seg_id);
93 
94 private:
95     AnthyState &state_;
96 
97     // tables
98     Key2KanaTableSet key2kanaTables_;
99     Key2KanaTableSet nicolaTables_;
100 
101     // convertors
102     Key2KanaConvertor key2kanaNormal_;
103     KanaConvertor kana_;
104     NicolaConvertor nicola_;
105     Key2KanaConvertorBase *key2kana_;
106 
107     // state
108     ReadingSegments segments_;
109     unsigned int segmentPos_;
110     unsigned int caretOffset_;
111 };
112 
113 #endif /* __FCITX_ANTHY_READING_H__ */
114 /*
115 vi:ts=4:nowrap:ai:expandtab
116 */
117