[Scim-imengine-dev 1039] pseudo ASCII input (was: Re: scim-anthy-1.0.0)

Back to archive index

Akira TAGOH at****@gclab*****
2006年 4月 10日 (月) 22:18:21 JST


たごうです。

>>>>> On Sat, 1 Apr 2006 00:52:16 +0900,
>>>>> "ahie" == ashie****@homa***** wrote:

>> 1.0がリリースされた直後で、ちょっと恐縮なので、時間がとれた
>> ときにでもみてみたいと思ってますが、英大文字による強制ASCII
>> 入力ができないかという要望を頂きました。
>> 
>> # これもMS-IME由来?なんですかね、よく分かりませんが

ahie> これは私もやりたいと思っていて、日記かこのMLに「1.0までには
ahie> やりたいけど、時間が無いから無理かな〜」と書いた記憶があり
ahie> ます。

ahie> これをやると操作性が大きく向上するので、やって頂けると非常
ahie> にうれしいです:)

ahie> # あたしゃしばらくバグフィックス以外は無理です

ちょっと見てみる時間ができたので、パッチを書いてみました。
さっとテストした感じでは問題なさそうに動いてますが、何かしら
の問題はあるかもしれません。
どなたかレビューして頂けると助かります。

--
Akira TAGOH
-------------- next part --------------
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_factory.cpp scim-anthy-1.0.0/src/scim_anthy_factory.cpp
--- scim-anthy-1.0.0.orig/src/scim_anthy_factory.cpp	2006-02-13 19:18:19.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_factory.cpp	2006-04-10 16:12:41.000000000 +0900
@@ -121,6 +121,7 @@
       m_romaji_half_symbol          (SCIM_ANTHY_CONFIG_ROMAJI_HALF_SYMBOL_DEFAULT),
       m_romaji_half_number          (SCIM_ANTHY_CONFIG_ROMAJI_HALF_NUMBER_DEFAULT),
       m_romaji_allow_split          (SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT_DEFAULT),
+      m_romaji_pseudo_ascii_mode    (SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE_DEFAULT),
       m_nicola_time                 (SCIM_ANTHY_CONFIG_NICOLA_TIME_DEFAULT),
       m_dict_admin_command          (SCIM_ANTHY_CONFIG_DICT_ADMIN_COMMAND_DEFAULT),
       m_add_word_command            (SCIM_ANTHY_CONFIG_ADD_WORD_COMMAND_DEFAULT),
@@ -490,6 +491,10 @@
             = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT),
                             SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT_DEFAULT);
 
+        m_romaji_pseudo_ascii_mode
+            = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE),
+                            SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE_DEFAULT);
+
         m_nicola_time
             = config->read (String (SCIM_ANTHY_CONFIG_NICOLA_TIME),
                             SCIM_ANTHY_CONFIG_NICOLA_TIME_DEFAULT);
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_factory.h scim-anthy-1.0.0/src/scim_anthy_factory.h
--- scim-anthy-1.0.0.orig/src/scim_anthy_factory.h	2006-02-13 19:17:02.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_factory.h	2006-04-10 16:12:59.000000000 +0900
@@ -91,6 +91,7 @@
     bool           m_romaji_half_symbol;
     bool           m_romaji_half_number;
     bool           m_romaji_allow_split;
+    bool           m_romaji_pseudo_ascii_mode;
     int            m_nicola_time;
     KeyEventList   m_left_thumb_keys;
     KeyEventList   m_right_thumb_keys;
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_imengine.cpp scim-anthy-1.0.0/src/scim_anthy_imengine.cpp
--- scim-anthy-1.0.0.orig/src/scim_anthy_imengine.cpp	2006-03-29 14:18:59.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_imengine.cpp	2006-04-10 21:54:34.000000000 +0900
@@ -819,11 +819,16 @@
 
     if (method != get_typing_method ()) {
         Key2KanaTable *fundamental_table = NULL;
-        if (method == SCIM_ANTHY_TYPING_METHOD_ROMAJI)
+        bool pseudo_ascii = false;
+
+        if (method == SCIM_ANTHY_TYPING_METHOD_ROMAJI) {
             fundamental_table = m_factory->m_custom_romaji_table;
-        else if (method == SCIM_ANTHY_TYPING_METHOD_KANA)
+            pseudo_ascii = m_factory->m_romaji_pseudo_ascii_mode;
+        } else if (method == SCIM_ANTHY_TYPING_METHOD_KANA) {
             fundamental_table = m_factory->m_custom_kana_table;
+        }
         m_preedit.set_typing_method (method);
+        m_preedit.use_pseudo_ascii_mode (pseudo_ascii);
     }
 }
 
@@ -2173,16 +2178,26 @@
             m_preedit.set_input_mode (SCIM_ANTHY_MODE_WIDE_LATIN);
     }
 
-    // set typing method
+    // set typing method and pseudo ASCII mode
     if (m_on_init || !m_factory->m_show_typing_method_label) {
-        if (m_factory->m_typing_method == "NICOLA")
+        if (m_factory->m_typing_method == "NICOLA") {
             m_preedit.set_typing_method (SCIM_ANTHY_TYPING_METHOD_NICOLA);
-        else if (m_factory->m_typing_method == "Kana")
+            m_preedit.use_pseudo_ascii_mode(false);
+        } else if (m_factory->m_typing_method == "Kana") {
             m_preedit.set_typing_method (SCIM_ANTHY_TYPING_METHOD_KANA);
-        else
+            m_preedit.use_pseudo_ascii_mode(false);
+        } else {
             m_preedit.set_typing_method (SCIM_ANTHY_TYPING_METHOD_ROMAJI);
+            m_preedit.use_pseudo_ascii_mode(m_factory->m_romaji_pseudo_ascii_mode);
+        }
     } else {
-        m_preedit.set_typing_method (m_preedit.get_typing_method ());
+        TypingMethod m = m_preedit.get_typing_method ();
+
+        m_preedit.set_typing_method (m);
+        if (m == SCIM_ANTHY_TYPING_METHOD_ROMAJI)
+            m_preedit.use_pseudo_ascii_mode(m_factory->m_romaji_pseudo_ascii_mode);
+        else
+            m_preedit.use_pseudo_ascii_mode(false);
     }
 
     // set conversion mode
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_key2kana.cpp scim-anthy-1.0.0/src/scim_anthy_key2kana.cpp
--- scim-anthy-1.0.0.orig/src/scim_anthy_key2kana.cpp	2006-02-08 12:14:01.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_key2kana.cpp	2006-04-10 21:56:07.000000000 +0900
@@ -27,10 +27,12 @@
 
 Key2KanaConvertor::Key2KanaConvertor (AnthyInstance    & anthy,
                                       Key2KanaTableSet & tables)
-    : m_anthy          (anthy),
-      m_tables         (tables)
+    : m_anthy                   (anthy),
+      m_tables                  (tables),
+      m_is_in_pseudo_ascii_mode (false)
 {
     set_case_sensitive (false);
+    use_pseudo_ascii_mode (false);
 }
 
 Key2KanaConvertor::~Key2KanaConvertor ()
@@ -124,6 +126,13 @@
     bool has_partial_match = false;
     bool retval = false;
 
+    if (m_pseudo_ascii_mode)
+        compute_for_pseudo_ascii_mode(widestr);
+    if (m_is_in_pseudo_ascii_mode) {
+        m_pending += widestr;
+        pending = m_pending;
+        return false;
+    }
     if (!m_case_sensitive) {
         String half = utf8_wcstombs (matching_str);
         for (unsigned int i = 0; i < half.length (); i++)
@@ -213,6 +222,7 @@
 {
     m_pending.clear ();
     m_exact_match.clear ();
+    reset_pseudo_ascii_mode();
 }
 
 bool
@@ -257,6 +267,22 @@
         append (raw.substr(i, 1), res, pend);
     }
 }
+
+void
+Key2KanaConvertor::compute_for_pseudo_ascii_mode(const WideString & wstr)
+{
+    for (unsigned int i = 0; !m_is_in_pseudo_ascii_mode && i < wstr.length (); i++) {
+        if (wstr[i] >= 'A' && wstr[i] <= 'Z')
+            m_is_in_pseudo_ascii_mode = true;
+    }
+}
+
+void
+Key2KanaConvertor::reset_pseudo_ascii_mode (void)
+{
+    m_is_in_pseudo_ascii_mode = false;
+}
+
 /*
 vi:ts=4:nowrap:ai:expandtab
 */
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_key2kana.h scim-anthy-1.0.0/src/scim_anthy_key2kana.h
--- scim-anthy-1.0.0.orig/src/scim_anthy_key2kana.h	2006-02-08 12:14:01.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_key2kana.h	2006-04-10 22:00:32.000000000 +0900
@@ -37,22 +37,26 @@
 class Key2KanaConvertor : public Key2KanaConvertorBase
 {
 public:
-    Key2KanaConvertor             (AnthyInstance    & anthy,
-                                   Key2KanaTableSet & tables);
-    virtual ~Key2KanaConvertor    ();
-
-    bool       can_append         (const KeyEvent   & key);
-    bool       append             (const KeyEvent   & key,
-                                   WideString       & result,
-                                   WideString       & pending,
-                                   String           & raw);
-    void       clear              (void);
-
-    bool       is_pending         (void);
-    WideString get_pending        (void);
-    WideString flush_pending      (void);
-    void       reset_pending      (const WideString & result,
-                                   const String     & raw);
+    Key2KanaConvertor                        (AnthyInstance    & anthy,
+                                              Key2KanaTableSet & tables);
+    virtual ~Key2KanaConvertor               ();
+
+    bool       can_append                    (const KeyEvent   & key);
+    bool       append                        (const KeyEvent   & key,
+                                              WideString       & result,
+                                              WideString       & pending,
+                                              String           & raw);
+    void       clear                         (void);
+
+    bool       is_pending                    (void);
+    WideString get_pending                   (void);
+    WideString flush_pending                 (void);
+    void       reset_pending                 (const WideString & result,
+                                              const String     & raw);
+    void       use_pseudo_ascii_mode         (bool               flag)
+        { m_pseudo_ascii_mode = flag; }
+    void       compute_for_pseudo_ascii_mode (const WideString & wstr);
+    void       reset_pseudo_ascii_mode       (void);
 
 private:
     bool       append             (const String     & str,
@@ -66,6 +70,8 @@
     // state
     WideString         m_pending;
     Key2KanaRule       m_exact_match;
+    bool               m_pseudo_ascii_mode;
+    bool               m_is_in_pseudo_ascii_mode;
 };
 
 }
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_key2kana_base.h scim-anthy-1.0.0/src/scim_anthy_key2kana_base.h
--- scim-anthy-1.0.0.orig/src/scim_anthy_key2kana_base.h	2006-02-08 12:14:01.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_key2kana_base.h	2006-04-10 20:37:13.000000000 +0900
@@ -49,6 +49,11 @@
     virtual void       reset_pending      (const WideString & result,
                                            const String     & raw)       = 0;
 
+    virtual void       reset_pseudo_ascii_mode       (void)
+        {}
+    virtual void       compute_for_pseudo_ascii_mode (const WideString & wstr)
+        {}
+
     virtual void       set_case_sensitive (bool               sensitive)
         { m_case_sensitive = sensitive; }
     virtual bool       get_case_sensitive (void)
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_preedit.cpp scim-anthy-1.0.0/src/scim_anthy_preedit.cpp
--- scim-anthy-1.0.0.orig/src/scim_anthy_preedit.cpp	2006-02-13 17:00:41.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_preedit.cpp	2006-04-10 22:00:50.000000000 +0900
@@ -476,6 +476,12 @@
     return m_reading.get_number_width ();
 }
 
+void
+Preedit::use_pseudo_ascii_mode (bool flag)
+{
+    m_reading.use_pseudo_ascii_mode (flag);
+}
+
 bool
 Preedit::is_comma_or_period (const String & str)
 {
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_preedit.h scim-anthy-1.0.0/src/scim_anthy_preedit.h
--- scim-anthy-1.0.0.orig/src/scim_anthy_preedit.h	2006-02-13 17:00:42.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_preedit.h	2006-04-10 21:59:31.000000000 +0900
@@ -121,6 +121,7 @@
     virtual bool          get_symbol_width       (void);
     virtual void          set_number_width       (bool           half);
     virtual bool          get_number_width       (void);
+    virtual void          use_pseudo_ascii_mode  (bool           flag);
 
 private:
     void                  get_reading_substr     (WideString   & substr,
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_prefs.cpp scim-anthy-1.0.0/src/scim_anthy_prefs.cpp
--- scim-anthy-1.0.0.orig/src/scim_anthy_prefs.cpp	2006-02-13 19:07:19.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_prefs.cpp	2006-04-10 22:18:00.000000000 +0900
@@ -97,6 +97,15 @@
         false,
     },
     {
+        SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE,
+        SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE_DEFAULT,
+        SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE_DEFAULT,
+        N_("_Entering the pseudo ASCII input mode with capital letters."),
+        NULL,
+        N_("If this check is enabled, capital letters will becomes a trigger to enter the pseudo ASCII input mode till capital letters are in preedit."),
+        false,
+    },
+    {
         SCIM_ANTHY_CONFIG_PREDICT_ON_INPUT,
         SCIM_ANTHY_CONFIG_PREDICT_ON_INPUT_DEFAULT,
         SCIM_ANTHY_CONFIG_PREDICT_ON_INPUT_DEFAULT,
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_prefs.h scim-anthy-1.0.0/src/scim_anthy_prefs.h
--- scim-anthy-1.0.0.orig/src/scim_anthy_prefs.h	2006-02-13 19:03:56.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_prefs.h	2006-04-10 16:09:21.000000000 +0900
@@ -35,6 +35,7 @@
 #define SCIM_ANTHY_CONFIG_ROMAJI_HALF_SYMBOL          "/IMEngine/Anthy/RomajiHalfSymbol"
 #define SCIM_ANTHY_CONFIG_ROMAJI_HALF_NUMBER          "/IMEngine/Anthy/RomajiHalfNumber"
 #define SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT          "/IMEngine/Anthy/RomajiAllowSplit"
+#define SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE    "/IMEngine/Anthy/RomajiPseudoAsciiMode"
 
 #define SCIM_ANTHY_CONFIG_KANA_LAYOUT_FILE            "/IMEngine/Anthy/KanaLayoutFile"
 
@@ -167,6 +168,7 @@
 #define SCIM_ANTHY_CONFIG_ROMAJI_HALF_SYMBOL_DEFAULT          false
 #define SCIM_ANTHY_CONFIG_ROMAJI_HALF_NUMBER_DEFAULT          false
 #define SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT_DEFAULT          true
+#define SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE_DEFAULT    true
 
 #define SCIM_ANTHY_CONFIG_KANA_LAYOUT_FILE_DEFAULT            ""
 
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_reading.cpp scim-anthy-1.0.0/src/scim_anthy_reading.cpp
--- scim-anthy-1.0.0.orig/src/scim_anthy_reading.cpp	2006-02-13 17:00:42.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_reading.cpp	2006-04-10 21:59:25.000000000 +0900
@@ -431,6 +431,9 @@
                                m_segments[m_segment_pos - 1].raw);
     m_kana.reset_pending (m_segments[m_segment_pos - 1].kana,
                           m_segments[m_segment_pos - 1].raw);
+    m_key2kana->reset_pseudo_ascii_mode();
+    for (unsigned int i = 0; i < m_segment_pos; i++)
+        m_key2kana->compute_for_pseudo_ascii_mode(m_segments[i].kana);
 }
 
 unsigned int
@@ -650,3 +653,9 @@
 {
     return m_key2kana_tables.number_is_half ();
 }
+
+void
+Reading::use_pseudo_ascii_mode (bool flag)
+{
+    m_key2kana_normal.use_pseudo_ascii_mode (flag);
+}
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_reading.h scim-anthy-1.0.0/src/scim_anthy_reading.h
--- scim-anthy-1.0.0.orig/src/scim_anthy_reading.h	2006-02-13 17:00:42.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_reading.h	2006-04-10 22:01:33.000000000 +0900
@@ -104,6 +104,7 @@
     bool         get_symbol_width      (void);
     void         set_number_width      (bool             half);
     bool         get_number_width      (void);
+    void         use_pseudo_ascii_mode (bool             flag);
 
 private:
     void         reset_pending         (void);
diff -ruN -x 'Makefile*' -x autom4te.cache -x 'config*' -x libtool -x po -x '*o' -x '*a' -x '*i' -x '*~' -x 'stamp*' scim-anthy-1.0.0.orig/src/scim_anthy_setup_romaji.cpp scim-anthy-1.0.0/src/scim_anthy_setup_romaji.cpp
--- scim-anthy-1.0.0.orig/src/scim_anthy_setup_romaji.cpp	2006-02-08 12:14:01.000000000 +0900
+++ scim-anthy-1.0.0/src/scim_anthy_setup_romaji.cpp	2006-04-10 16:11:08.000000000 +0900
@@ -93,6 +93,10 @@
     widget = create_check_button (SCIM_ANTHY_CONFIG_ROMAJI_HALF_NUMBER);
     gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 4);
 
+    /* pseudo ascii mode */
+    widget = create_check_button (SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE);
+    gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 4);
+
     /* romaji table */
     GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
     gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);


Scim-imengine-dev メーリングリストの案内
Back to archive index