diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2018-05-27 12:12:06 +0300 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2018-08-06 08:20:01 +0000 |
commit | 59208edaaf40be982904a6c8cad4eab2d14f938e (patch) | |
tree | a613276e1f785e6cd82d019f01dbe478c7cebc5d /src/virtualkeyboard/3rdparty/tcime/zhuyintable.cpp | |
parent | 263a16009e8d08004a546954cd7b2671c26fab9e (diff) |
Modularize virtual keyboard and add an extension interface
With the extension interface it is possible to add new input
method and/or languages without recompiling the Qt Virtual
Keyboard plugin itself.
The existing input methods are now isolated into plugins.
So installing a new input method is a matter of copying the
corresponding extension plugin to the plugins/virtualkeyboard
directory (and any collateral required by the extension plugin
itself).
This change also renames the HunspellInputMethod to
DefaultInputMethod. This change is necessary because some other
extension plugin may want to provide the default input method
instead.
Implementation plan
===================
[x] Create virtualkeyboard-private module
[x] Create plugin library
[x] Define interface for input method plugin
[x] Define interface for keyboard layouts
[x] Move existing input methods and layouts to plugins
[x] HangulInputMethod
[x] HunspellInputMethod
[x] Maybe create a private library for sharing
between HunspellInputMethod and LipiInputMethod
[x] LipiInputMethod
[x] OpenWnnInputMethod
[x] PinyinInputMethod
[x] T9WriteInputMethod
[x] TCInputMethod
[o] Rename some C++ classes (too generic name?)
[x] Think again replacing the QtVirtualKeyboard namespace
[x] Update documentation
[x] General instructions for creating a plugin
[x] For the C++ interfaces too (previously removed)
[ChangeLog][Important Behavior Changes] Introduce an extension
interface for the virtual keyboard. All the current input methods and
some special keyboard layouts (e.g. Hunspell, OpenWnn, etc.) have been
moved to extensions. The extension interface allows third party to
create a new input method without having to modify or rebuild the
virtual keyboard. In addition, this change makes it possible to add
features and languages independently by copying the desired extension
to the system.
[ChangeLog][Important Behavior Changes] Introduce a virtualkeyboard
module, which can be linked against an extension plugin. This module
provides the C++ API necessary for creating an input method.
[ChangeLog][Important Behavior Changes] Wrap the entire virtual
keyboard API into Qt namespace (e.g. QT_BEGIN_NAMESPACE/QT_END_NAMESPACE).
Task-number: QTBUG-57602
Change-Id: I449f4429109f596a7a1df7517c81f97d4aada27c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/virtualkeyboard/3rdparty/tcime/zhuyintable.cpp')
-rw-r--r-- | src/virtualkeyboard/3rdparty/tcime/zhuyintable.cpp | 161 |
1 files changed, 0 insertions, 161 deletions
diff --git a/src/virtualkeyboard/3rdparty/tcime/zhuyintable.cpp b/src/virtualkeyboard/3rdparty/tcime/zhuyintable.cpp deleted file mode 100644 index c405b1e3..00000000 --- a/src/virtualkeyboard/3rdparty/tcime/zhuyintable.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Qt implementation of TCIME library - * This file is part of the Qt Virtual Keyboard module. - * Contact: http://www.qt.io/licensing/ - * - * Copyright (C) 2015 The Qt Company - * Copyright 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "zhuyintable.h" -#include <QStringList> - -using namespace tcime; - -const int ZhuyinTable::INITIALS_SIZE = 22; -const QList<QChar> ZhuyinTable::yiEndingFinals = QList<QChar>() - << 0x311a << 0x311b << 0x311d << 0x311e << 0x3120 << 0x3121 << 0x3122 - << 0x3123 << 0x3124 << 0x3125; -const QList<QChar> ZhuyinTable::wuEndingFinals = QList<QChar>() - << 0x311a << 0x311b << 0x311e << 0x311f << 0x3122 << 0x3123 << 0x3124 - << 0x3125; -const QList<QChar> ZhuyinTable::yuEndingFinals = QList<QChar>() - << 0x311d << 0x3122 << 0x3123 << 0x3125; -const int ZhuyinTable::YI_FINALS_INDEX = 14; -const int ZhuyinTable::WU_FINALS_INDEX = 25; -const int ZhuyinTable::YU_FINALS_INDEX = 34; -const QChar ZhuyinTable::YI_FINALS = 0x3127; -const QChar ZhuyinTable::WU_FINALS = 0x3128; -const QChar ZhuyinTable::YU_FINALS = 0x3129; -const QList<QChar> ZhuyinTable::tones = QList<QChar>() - << ZhuyinTable::DEFAULT_TONE << 0x02d9 << 0x02ca << 0x02c7 << 0x02cb; -const QChar ZhuyinTable::DEFAULT_TONE = QChar(' '); - -int ZhuyinTable::getInitials(const QChar &initials) -{ - // Calculate the index by its distance to the first initials 'ㄅ' (b). - int index = initials.unicode() - 0x3105 + 1; - if (index >= ZhuyinTable::INITIALS_SIZE) - // Syllables starting with finals can still be valid. - return 0; - - return (index >= 0) ? index : -1; -} - -int ZhuyinTable::getFinals(const QString &finals) -{ - if (finals.length() == 0) - // Syllables ending with no finals can still be valid. - return 0; - - if (finals.length() > 2) - return -1; - - // Compute the index instead of direct lookup the whole array to save - // traversing time. First calculate the distance to the first finals - // 'ㄚ' (a). - const QChar firstFinal = finals.at(0); - int index = firstFinal.unicode() - 0x311a + 1; - if (index < YI_FINALS_INDEX) - return index; - - // Check 'ㄧ' (yi), 'ㄨ' (wu) , and 'ㄩ' (yu) group finals. - QList<QChar> endingFinals; - if (firstFinal == YI_FINALS) { - index = YI_FINALS_INDEX; - endingFinals = yiEndingFinals; - } else if (firstFinal == WU_FINALS) { - index = WU_FINALS_INDEX; - endingFinals = wuEndingFinals; - } else if (firstFinal == YU_FINALS) { - index = YU_FINALS_INDEX; - endingFinals = yuEndingFinals; - } else { - return -1; - } - - if (finals.length() == 1) - return index; - - for (int i = 0; i < endingFinals.size(); ++i) { - if (finals.at(1) == endingFinals[i]) - return index + i + 1; - } - return -1; -} - -int ZhuyinTable::getSyllablesIndex(const QString &syllables) -{ - if (syllables.isEmpty()) - return -1; - - int initials = getInitials(syllables.at(0)); - if (initials < 0) - return -1; - - // Strip out initials before getting finals column-index. - int finals = getFinals((initials != 0) ? syllables.mid(1) : syllables); - if (finals < 0) - return -1; - - return (finals * INITIALS_SIZE + initials); -} - -int ZhuyinTable::getTones(const QChar &c) -{ - for (int i = 0; i < tones.size(); ++i) { - if (tones[i] == c) - return i; - } - // Treat all other characters as the default tone with the index 0. - return 0; -} - -int ZhuyinTable::getTonesCount() -{ - return tones.size(); -} - -bool ZhuyinTable::isTone(const QChar &c) -{ - for (int i = 0; i < tones.size(); ++i) { - if (tones[i] == c) - return true; - } - return false; -} - -bool ZhuyinTable::isYiWuYuFinals(const QChar &c) -{ - ushort unicode = c.unicode(); - return unicode == YI_FINALS || unicode == WU_FINALS || unicode == YU_FINALS; -} - -QStringList ZhuyinTable::stripTones(const QString &input) -{ - const int last = input.length() - 1; - if (last < 0) - return QStringList(); - - QChar tone = input.at(last); - if (isTone(tone)) { - QString syllables = input.left(last); - if (syllables.length() <= 0) - return QStringList(); - return QStringList() << syllables << QString(tone); - } - // Treat the tone-less input as the default tone (tone-0). - return QStringList() << input << QString(DEFAULT_TONE); -} |