pax_global_header00006660000000000000000000000064124111727060014513gustar00rootroot0000000000000052 comment=66ff3abb03cc82886e4523e6690b091226070e69 ibus-libzhuyin-1.6.99.20140929/000077500000000000000000000000001241117270600155075ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/AUTHORS000066400000000000000000000000431241117270600165540ustar00rootroot00000000000000Peng Wu 2013 ibus-libzhuyin-1.6.99.20140929/COPYING000066400000000000000000000431031241117270600165430ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. ibus-libzhuyin-1.6.99.20140929/ChangeLog000066400000000000000000000010551241117270600172620ustar00rootroot000000000000002014-01-26 gettextize * m4/gettext.m4: New file, from gettext-0.18.3. * m4/iconv.m4: New file, from gettext-0.18.3. * m4/lib-ld.m4: New file, from gettext-0.18.3. * m4/lib-link.m4: New file, from gettext-0.18.3. * m4/lib-prefix.m4: New file, from gettext-0.18.3. * m4/nls.m4: New file, from gettext-0.18.3. * m4/po.m4: New file, from gettext-0.18.3. * m4/progtest.m4: New file, from gettext-0.18.3. * Makefile.am (SUBDIRS): Add po. (EXTRA_DIST): New variable. * configure.ac (AC_CONFIG_FILES): Add po/Makefile.in. ibus-libzhuyin-1.6.99.20140929/Makefile.am000066400000000000000000000023021241117270600175400ustar00rootroot00000000000000# vim:set noet ts=4: # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. SUBDIRS = src setup data po dist_doc_DATA = \ README \ COPYING \ AUTHORS \ ChangeLog \ INSTALL \ NEWS ACLOCAL_AMFLAGS = -I m4 # Remove doc directory on uninstall uninstall-local: -rm -r $(docdir) EXTRA_DIST = \ autogen.sh \ ibus-libzhuyin.spec.in \ $(NULL) noinst_DIST = \ $(NULL) DISTCLEANFILES = \ po/stamp-it \ $(NULL) ibus-libzhuyin-1.6.99.20140929/NEWS000066400000000000000000000000001241117270600161740ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/README000066400000000000000000000002351241117270600163670ustar00rootroot00000000000000ibus-libzhuyin New Zhuyin engine based on libzhuyin for IBus Description It includes a Chinese Zhuyin (Bopomofo) input method based on libzhuyin for IBus. ibus-libzhuyin-1.6.99.20140929/autogen.sh000077500000000000000000000010301241117270600175020ustar00rootroot00000000000000#!/bin/sh # Run this to generate all the initial makefiles, etc. srcdir=`dirname $0` test -z "$srcdir" && srcdir=. PKG_NAME="ibus-libzhuyin" (test -f $srcdir/configure.ac \ && test -f $srcdir/README ) || { echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" echo " top-level $PKG_NAME directory" exit 1 } which gnome-autogen.sh || { echo "You need to install gnome-common from the GNOME CVS" exit 1 } ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.8 . gnome-autogen.sh "$@" ibus-libzhuyin-1.6.99.20140929/configure.ac000066400000000000000000000066721241117270600200100ustar00rootroot00000000000000# vim:set et ts=4: # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # if not 1, append datestamp to the version number. m4_define([ibus_released], [0]) m4_define([ibus_major_version], [1]) m4_define([ibus_minor_version], [6]) m4_define([ibus_micro_version], [99]) m4_define(ibus_maybe_datestamp, m4_esyscmd([if test x]ibus_released[ != x1; then date +.%Y%m%d | tr -d '\n\r'; fi])) m4_define([ibus_version], ibus_major_version.ibus_minor_version.ibus_micro_version[]ibus_maybe_datestamp) AC_INIT([ibus-libzhuyin], [ibus_version], [https://github.com/libzhuyin/ibus-libzhuyin/issues/new],[ibus-libzhuyin]) AM_INIT_AUTOMAKE([1.10]) AC_GNU_SOURCE AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) # define PACKAGE_VERSION_* variables AS_VERSION AS_NANO AM_SANITY_CHECK AM_MAINTAINER_MODE AM_DISABLE_STATIC AC_PROG_CC AC_PROG_CXX AM_PROG_CC_C_O AC_ISC_POSIX AC_HEADER_STDC IT_PROG_INTLTOOL([0.35.0]) LT_INIT AC_PROG_SED # check ibus PKG_CHECK_MODULES(IBUS, [ ibus-1.0 >= 1.4.0 ]) # check libzhuyin PKG_CHECK_MODULES(LIBZHUYIN, [ libzhuyin >= 0.9.93 ], [enable_libzhuyin=yes]) LIBZHUYIN_DATADIR=`$PKG_CONFIG --variable=pkgdatadir libzhuyin` AC_SUBST(LIBZHUYIN_DATADIR) # check opencc PKG_CHECK_MODULES(OPENCC, [opencc], [enable_opencc=yes]) # check if ibus_config_get_values, which is available in ibus-1.3.99+ (git master) save_CFLAGS="$CFLAGS" save_LIBS="$LIBS" CFLAGS="$CFLAGS $IBUS_CFLAGS" LIBS="$LIBS $IBUS_LIBS" AC_CHECK_FUNCS([ibus_config_get_values]) CFLAGS="$save_CFLAGS" LIBS="$save_LIBS" # check env AC_PATH_PROG(ENV, env) AC_SUBST(ENV) # check python AM_PATH_PYTHON([2.5]) # --enable-boost AC_ARG_ENABLE(boost, AC_HELP_STRING([--enable-boost], [Use boost to replace stdc++0x.]), [enable_boost=$enableval], [enable_boost=no] ) if test x"$enable_boost" = x"yes"; then # check boost BOOST_REQUIRE([1.39]) BOOST_FIND_HEADER([boost/bind.hpp]) BOOST_FIND_HEADER([boost/signals2.hpp]) fi AM_CONDITIONAL(HAVE_BOOST, test x"$enable_boost" = x"yes") # define GETTEXT_* variables GETTEXT_PACKAGE=ibus-libzhuyin AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package]) AM_GLIB_GNU_GETTEXT([external]) # OUTPUT files AC_CONFIG_FILES([ po/Makefile.in Makefile src/Makefile src/libzhuyin.xml.in setup/Makefile setup/config.py setup/ibus-setup-libzhuyin ibus-libzhuyin.spec data/Makefile data/icons/Makefile ]) AC_OUTPUT AC_MSG_RESULT([ Build options: Version $VERSION Install prefix $prefix Use boost $enable_boost Use opencc $enable_opencc Use libzhuyin $enable_libzhuyin ]) ibus-libzhuyin-1.6.99.20140929/data/000077500000000000000000000000001241117270600164205ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/data/Makefile.am000066400000000000000000000031301241117270600204510ustar00rootroot00000000000000# vim:set noet ts=4: # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. SUBDIRS = \ icons \ $(NULL) desktop_in_in_files = \ ibus-setup-libzhuyin.desktop.in.in \ $(NULL) desktop_in_files = $(desktop_in_in_files:.in.in=.in) $(desktop_in_files): %.desktop.in: %.desktop.in.in Makefile $(AM_V_GEN) sed \ -e "s|\@libexecdir\@|$(libexecdir)|" \ -e "s|\@pkgdatadir\@|$(pkgdatadir)|" \ $< > $@.tmp && mv $@.tmp $@ desktopdir=$(datadir)/applications desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ symbols_DATA = \ easysymbol.txt \ usersymbol.txt \ $(NULL) symbolsdir = $(pkgdatadir) EXTRA_DIST = \ $(desktop_in_in_files) \ $(symbols_DATA) \ $(NULL) DISTCLEANFILES = \ $(desktop_in_files) \ $(desktop_DATA) \ $(NULL) ibus-libzhuyin-1.6.99.20140929/data/easysymbol.txt000066400000000000000000000002321241117270600213450ustar00rootroot00000000000000Q 〔 W 〕 A 【 S 】 Z 《 X 》 E { R } D 「 F 」 C 『 V 』 T ‘ Y ’ G “ H ” B 〝 N 〞 U + I - O × P ÷ J ≠ K ≒ L Orz M … ibus-libzhuyin-1.6.99.20140929/data/ibus-setup-libzhuyin.desktop.in.in000066400000000000000000000007301241117270600251400ustar00rootroot00000000000000[Desktop Entry] Name=IBus LibZhuyin Setup Name[zh_CN]=IBus 新注音配置工具 Name[zh_TW]=IBus 新注音配置工具 Name[zh_HK]=IBus 新注音配置工具 Comment=Set ibus-libzhuyin Preferences Comment[zh_CN]=设置 IBus 新注音首选项 Comment[zh_TW]=設定 IBus 新注音個人偏好 Comment[zh_HK]=設定 IBus 新注音個人偏好 Exec=@libexecdir@/ibus-setup-libzhuyin Icon=@pkgdatadir@/icons/ibus-zhuyin.svg NoDisplay=true Type=Application StartupNotify=true ibus-libzhuyin-1.6.99.20140929/data/icons/000077500000000000000000000000001241117270600175335ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/data/icons/Makefile.am000066400000000000000000000022111241117270600215630ustar00rootroot00000000000000# vim:set noet ts=4: # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. icons_DATA = \ ibus-zhuyin.svg \ chinese.svg \ english.svg \ full.svg \ full-punct.svg \ half.svg \ half-punct.svg \ simp-chinese.svg \ trad-chinese.svg \ $(NULL) iconsdir = $(pkgdatadir)/icons EXTRA_DIST = \ $(icons_DATA) \ $(NULL) ibus-libzhuyin-1.6.99.20140929/data/icons/chinese.svg000066400000000000000000000204571241117270600217020ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/english.svg000066400000000000000000000271731241117270600217170ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/full-punct.svg000066400000000000000000000232351241117270600223520ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/full.svg000066400000000000000000000153451241117270600212260ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/half-punct.svg000066400000000000000000000204601241117270600223170ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/half.svg000066400000000000000000000103671241117270600211750ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/ibus-zhuyin.svg000066400000000000000000000256531241117270600225550ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/simp-chinese.svg000066400000000000000000000324511241117270600226450ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/icons/trad-chinese.svg000066400000000000000000000363001241117270600226240ustar00rootroot00000000000000 image/svg+xml ibus-libzhuyin-1.6.99.20140929/data/usersymbol.txt000066400000000000000000000017071241117270600213720ustar00rootroot00000000000000… ※ 常用符號=,、。.?!;︰‧‥﹐﹒˙·‘’“”〝〞‵′〃~$%@&#* 左右括號=()「」〔〕{}〈〉『』《》【】﹙﹚﹝﹞﹛﹜ 上下括號=︵︶﹁﹂︹︺︷︸︿﹀﹃﹄︽︾︻︼ 希臘字母=αβγδεζηθικλμνξοπρστυφχψωΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ 數學符號=+-×÷=≠≒∞±√<>﹤﹥≦≧∩∪ˇ⊥∠∟⊿㏒㏑∫∮∵∴╳﹢ 特殊圖形=↑↓←→↖↗↙↘㊣◎○●⊕⊙○●△▲☆★◇◆□■▽▼§¥〒¢£※♀♂ Unicode=♨☀☁☂☃♠♥♣♦♩♪♫♬☺☻ 單線框=├─┼┴┬┤┌┐╞═╪╡│▕└┘╭╮╰╯ 雙線框=╔╦╗╠═╬╣╓╥╖╒╤╕║╚╩╝╟╫╢╙╨╜╞╪╡╘╧╛ 填色方塊=_ˍ▁▂▃▄▅▆▇█▏▎▍▌▋▊▉◢◣◥◤ 線段=﹣﹦≡|∣∥–︱—︳╴¯ ̄﹉﹊﹍﹎﹋﹌﹏︴∕﹨╱╲/\ ibus-libzhuyin-1.6.99.20140929/ibus-libzhuyin.spec.in000066400000000000000000000026771241117270600217610ustar00rootroot00000000000000Name: @PACKAGE_NAME@ Version: @PACKAGE_VERSION@ Release: 1%{?dist} Summary: New Zhuyin engine based on libzhuyin for IBus License: GPLv2+ Group: System Environment/Libraries URL: https://github.com/libzhuyin/ibus-libzhuyin Source0: http://downloads.sourceforge.net/libzhuyin/ibus-libzhuyin/%{name}-%{version}.tar.gz BuildRequires: gettext-devel BuildRequires: intltool BuildRequires: libtool BuildRequires: pkgconfig BuildRequires: sqlite-devel BuildRequires: opencc-devel BuildRequires: ibus-devel >= 1.3 BuildRequires: libzhuyin-devel >= 0.9.93 # Requires(post): sqlite Requires: ibus >= 1.3.0 Requires: libzhuyin-data >= 0.9.93 %description It includes a Chinese Zhuyin (Bopomofo) input method based on libzhuyin for IBus. %prep %setup -q %build %configure --disable-static \ --enable-opencc \ --disable-boost # make -C po update-gmo make %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT make DESTDIR=${RPM_BUILD_ROOT} install %find_lang %{name} %clean rm -rf $RPM_BUILD_ROOT %files -f %{name}.lang %defattr(-,root,root,-) %doc AUTHORS COPYING README %{_libexecdir}/ibus-engine-libzhuyin %{_libexecdir}/ibus-setup-libzhuyin %{_datadir}/@PACKAGE@/phrases.txt %{_datadir}/@PACKAGE@/icons %{_datadir}/@PACKAGE@/setup %dir %{_datadir}/@PACKAGE@ %dir %{_datadir}/@PACKAGE@/db %{_datadir}/ibus/component/* %changelog * Fri Jun 01 2012 Peng Wu - @VERSION@-1 - The first version. ibus-libzhuyin-1.6.99.20140929/m4/000077500000000000000000000000001241117270600160275ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/m4/as-version.m4000066400000000000000000000037701241117270600203660ustar00rootroot00000000000000dnl as-version.m4 0.2.0 dnl autostars m4 macro for versioning dnl Thomas Vander Stichele dnl $Id: as-version.m4,v 1.4 2004/06/01 09:40:05 thomasvs Exp $ dnl AS_VERSION dnl example dnl AS_VERSION dnl this macro dnl - AC_SUBST's PACKAGE_VERSION_MAJOR, _MINOR, _MICRO dnl - AC_SUBST's PACKAGE_VERSION_RELEASE, dnl which can be used for rpm release fields dnl - doesn't call AM_INIT_AUTOMAKE anymore because it prevents dnl maintainer mode from running correctly dnl dnl don't forget to put #undef PACKAGE_VERSION_RELEASE in acconfig.h dnl if you use acconfig.h AC_DEFUN([AS_VERSION], [ PACKAGE_VERSION_MAJOR=$(echo AC_PACKAGE_VERSION | cut -d'.' -f1) PACKAGE_VERSION_MINOR=$(echo AC_PACKAGE_VERSION | cut -d'.' -f2) PACKAGE_VERSION_MICRO=$(echo AC_PACKAGE_VERSION | cut -d'.' -f3) AC_SUBST(PACKAGE_VERSION_MAJOR) AC_SUBST(PACKAGE_VERSION_MINOR) AC_SUBST(PACKAGE_VERSION_MICRO) ]) dnl AS_NANO(ACTION-IF-NO-NANO, [ACTION-IF-NANO]) dnl requires AC_INIT to be called before dnl For projects using a fourth or nano number in your versioning to indicate dnl development or prerelease snapshots, this macro allows the build to be dnl set up differently accordingly. dnl this macro: dnl - parses AC_PACKAGE_VERSION, set by AC_INIT, and extracts the nano number dnl - sets the variable PACKAGE_VERSION_NANO dnl - sets the variable PACKAGE_VERSION_RELEASE, which can be used dnl for rpm release fields dnl - executes ACTION-IF-NO-NANO or ACTION-IF-NANO dnl example: dnl AS_NANO(RELEASE="yes", RELEASE="no") AC_DEFUN([AS_NANO], [ AC_MSG_CHECKING(nano version) NANO=$(echo AC_PACKAGE_VERSION | cut -d'.' -f4) if test x"$NANO" = x || test "x$NANO" = "x0" ; then AC_MSG_RESULT([0 (release)]) NANO=0 PACKAGE_VERSION_RELEASE=1 ifelse([$1], , :, [$1]) else AC_MSG_RESULT($NANO) PACKAGE_VERSION_RELEASE=0.`date +%Y%m%d.%H%M%S` ifelse([$2], , :, [$2]) fi PACKAGE_VERSION_NANO=$NANO AC_SUBST(PACKAGE_VERSION_NANO) AC_SUBST(PACKAGE_VERSION_RELEASE) ]) ibus-libzhuyin-1.6.99.20140929/m4/boost.m4000066400000000000000000001150111241117270600174160ustar00rootroot00000000000000# boost.m4: Locate Boost headers and libraries for autoconf-based projects. # Copyright (C) 2007, 2008, 2009 Benoit Sigoure # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Additional permission under section 7 of the GNU General Public # License, version 3 ("GPLv3"): # # If you convey this file as part of a work that contains a # configuration script generated by Autoconf, you may do so under # terms of your choice. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . m4_define([_BOOST_SERIAL], [m4_translit([ # serial 12 ], [# ], [])]) # Original sources can be found at http://github.com/tsuna/boost.m4 # You can fetch the latest version of the script by doing: # wget http://github.com/tsuna/boost.m4/raw/master/build-aux/boost.m4 # ------ # # README # # ------ # # This file provides several macros to use the various Boost libraries. # The first macro is BOOST_REQUIRE. It will simply check if it's possible to # find the Boost headers of a given (optional) minimum version and it will # define BOOST_CPPFLAGS accordingly. It will add an option --with-boost to # your configure so that users can specify non standard locations. # If the user's environment contains BOOST_ROOT and --with-boost was not # specified, --with-boost=$BOOST_ROOT is implicitly used. # For more README and documentation, go to http://github.com/tsuna/boost.m4 # Note: THESE MACROS ASSUME THAT YOU USE LIBTOOL. If you don't, don't worry, # simply read the README, it will show you what to do step by step. m4_pattern_forbid([^_?BOOST_]) # _BOOST_SED_CPP(SED-PROGRAM, PROGRAM, # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) # -------------------------------------------------------- # Same as AC_EGREP_CPP, but leave the result in conftest.i. # PATTERN is *not* overquoted, as in AC_EGREP_CPP. It could be useful # to turn this into a macro which extracts the value of any macro. m4_define([_BOOST_SED_CPP], [AC_LANG_PREPROC_REQUIRE()dnl AC_REQUIRE([AC_PROG_SED])dnl AC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])]) AS_IF([dnl eval is necessary to expand ac_cpp. dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell. dnl Beware of Windows end-of-lines, for instance if we are running dnl some Windows programs under Wine. In that case, boost/version.hpp dnl is certainly using "\r\n", but the regular Unix shell will only dnl strip `\n' with backquotes, not the `\r'. This results in dnl boost_cv_lib_version='1_37\r' for instance, which breaks dnl everything else. dnl Cannot use 'dnl' after [$4] because a trailing dnl may break AC_CACHE_CHECK (eval "$ac_cpp $CXXFLAGS conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | tr -d '\r' | $SED -n -e "$1" >conftest.i 2>&1], [$3], [$4]) rm -rf conftest* ])# AC_EGREP_CPP # BOOST_REQUIRE([VERSION], [ACTION-IF-NOT-FOUND]) # ----------------------------------------------- # Look for Boost. If version is given, it must either be a literal of the form # "X.Y.Z" where X, Y and Z are integers (the ".Z" part being optional) or a # variable "$var". # Defines the value BOOST_CPPFLAGS. This macro only checks for headers with # the required version, it does not check for any of the Boost libraries. # On # success, defines HAVE_BOOST. On failure, calls the optional # ACTION-IF-NOT-FOUND action if one was supplied. # Otherwise aborts with an error message. AC_DEFUN([BOOST_REQUIRE], [AC_REQUIRE([AC_PROG_CXX])dnl AC_REQUIRE([AC_PROG_GREP])dnl echo "$as_me: this is boost.m4[]_BOOST_SERIAL" >&AS_MESSAGE_LOG_FD boost_save_IFS=$IFS boost_version_req=$1 IFS=. set x $boost_version_req 0 0 0 IFS=$boost_save_IFS shift boost_version_req=`expr "$[1]" '*' 100000 + "$[2]" '*' 100 + "$[3]"` AC_ARG_WITH([boost], [AS_HELP_STRING([--with-boost=DIR], [prefix of Boost $1 @<:@guess@:>@])])dnl AC_ARG_VAR([BOOST_ROOT],[Location of Boost installation])dnl # If BOOST_ROOT is set and the user has not provided a value to # --with-boost, then treat BOOST_ROOT as if it the user supplied it. if test x"$BOOST_ROOT" != x; then if test x"$with_boost" = x; then AC_MSG_NOTICE([Detected BOOST_ROOT; continuing with --with-boost=$BOOST_ROOT]) with_boost=$BOOST_ROOT else AC_MSG_NOTICE([Detected BOOST_ROOT=$BOOST_ROOT, but overridden by --with-boost=$with_boost]) fi fi AC_SUBST([DISTCHECK_CONFIGURE_FLAGS], ["$DISTCHECK_CONFIGURE_FLAGS '--with-boost=$with_boost'"]) boost_save_CPPFLAGS=$CPPFLAGS AC_CACHE_CHECK([for Boost headers version >= $boost_version_req], [boost_cv_inc_path], [boost_cv_inc_path=no AC_LANG_PUSH([C++])dnl m4_pattern_allow([^BOOST_VERSION$])dnl AC_LANG_CONFTEST([AC_LANG_PROGRAM([[#include #if !defined BOOST_VERSION # error BOOST_VERSION is not defined #elif BOOST_VERSION < $boost_version_req # error Boost headers version < $boost_version_req #endif ]])]) # If the user provided a value to --with-boost, use it and only it. case $with_boost in #( ''|yes) set x '' /opt/local/include /usr/local/include /opt/include \ /usr/include C:/Boost/include;; #( *) set x "$with_boost/include" "$with_boost";; esac shift for boost_dir do # Without --layout=system, Boost (or at least some versions) installs # itself in /include/boost-. This inner loop helps to # find headers in such directories. # # Any ${boost_dir}/boost-x_xx directories are searched in reverse version # order followed by ${boost_dir}. The final '.' is a sentinel for # searching $boost_dir" itself. Entries are whitespace separated. # # I didn't indent this loop on purpose (to avoid over-indented code) boost_layout_system_search_list=`cd "$boost_dir" 2>/dev/null \ && ls -1 | "${GREP}" '^boost-' | sort -rn -t- -k2 \ && echo .` for boost_inc in $boost_layout_system_search_list do if test x"$boost_inc" != x.; then boost_inc="$boost_dir/$boost_inc" else boost_inc="$boost_dir" # Uses sentinel in boost_layout_system_search_list fi if test x"$boost_inc" != x; then # We are going to check whether the version of Boost installed # in $boost_inc is usable by running a compilation that # #includes it. But if we pass a -I/some/path in which Boost # is not installed, the compiler will just skip this -I and # use other locations (either from CPPFLAGS, or from its list # of system include directories). As a result we would use # header installed on the machine instead of the /some/path # specified by the user. So in that precise case (trying # $boost_inc), make sure the version.hpp exists. # # Use test -e as there can be symlinks. test -e "$boost_inc/boost/version.hpp" || continue CPPFLAGS="$CPPFLAGS -I$boost_inc" fi AC_COMPILE_IFELSE([], [boost_cv_inc_path=yes], [boost_cv_version=no]) if test x"$boost_cv_inc_path" = xyes; then if test x"$boost_inc" != x; then boost_cv_inc_path=$boost_inc fi break 2 fi done done AC_LANG_POP([C++])dnl ]) case $boost_cv_inc_path in #( no) boost_errmsg="cannot find Boost headers version >= $boost_version_req" m4_if([$2], [], [AC_MSG_ERROR([$boost_errmsg])], [AC_MSG_NOTICE([$boost_errmsg])]) $2 ;;#( yes) BOOST_CPPFLAGS= ;;#( *) AC_SUBST([BOOST_CPPFLAGS], ["-I$boost_cv_inc_path"]) ;; esac if test x"$boost_cv_inc_path" != xno; then AC_DEFINE([HAVE_BOOST], [1], [Defined if the requested minimum BOOST version is satisfied]) AC_CACHE_CHECK([for Boost's header version], [boost_cv_lib_version], [m4_pattern_allow([^BOOST_LIB_VERSION$])dnl _BOOST_SED_CPP([/^boost-lib-version = /{s///;s/\"//g;p;g;}], [#include boost-lib-version = BOOST_LIB_VERSION], [boost_cv_lib_version=`cat conftest.i`])]) # e.g. "134" for 1_34_1 or "135" for 1_35 boost_major_version=`echo "$boost_cv_lib_version" | sed 's/_//;s/_.*//'` case $boost_major_version in #( '' | *[[!0-9]]*) AC_MSG_ERROR([invalid value: boost_major_version=$boost_major_version]) ;; esac fi CPPFLAGS=$boost_save_CPPFLAGS ])# BOOST_REQUIRE # BOOST_STATIC() # -------------- # Add the "--enable-static-boost" configure argument. If this argument is given # on the command line, static versions of the libraries will be looked up. AC_DEFUN([BOOST_STATIC], [AC_ARG_ENABLE([static-boost], [AC_HELP_STRING([--enable-static-boost], [Prefer the static boost libraries over the shared ones [no]])], [enable_static_boost=yes], [enable_static_boost=no])])# BOOST_STATIC # BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND]) # -------------------------------------------------------------------------- # Wrapper around AC_CHECK_HEADER for Boost headers. Useful to check for # some parts of the Boost library which are only made of headers and don't # require linking (such as Boost.Foreach). # # Default ACTION-IF-NOT-FOUND: Fail with a fatal error unless Boost couldn't be # found in the first place, in which case by default a notice is issued to the # user. Presumably if we haven't died already it's because it's OK to not have # Boost, which is why only a notice is issued instead of a hard error. # # Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_ in # case of success # (where HEADER-NAME is written LIKE_THIS, e.g., # HAVE_BOOST_FOREACH_HPP). AC_DEFUN([BOOST_FIND_HEADER], [AC_REQUIRE([BOOST_REQUIRE])dnl if test x"$boost_cv_inc_path" = xno; then m4_default([$2], [AC_MSG_NOTICE([Boost not available, not searching for $1])]) else AC_LANG_PUSH([C++])dnl boost_save_CPPFLAGS=$CPPFLAGS CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" AC_CHECK_HEADER([$1], [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1], [Define to 1 if you have <$1>])])], [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])]) CPPFLAGS=$boost_save_CPPFLAGS AC_LANG_POP([C++])dnl fi ])# BOOST_FIND_HEADER # BOOST_FIND_LIB([LIB-NAME], [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST], # [CXX-PROLOGUE]) # ------------------------------------------------------------------------- # Look for the Boost library LIB-NAME (e.g., LIB-NAME = `thread', for # libboost_thread). Check that HEADER-NAME works and check that # libboost_LIB-NAME can link with the code CXX-TEST. The optional argument # CXX-PROLOGUE can be used to include some C++ code before the `main' # function. # # Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above). # # Boost libraries typically come compiled with several flavors (with different # runtime options) so PREFERRED-RT-OPT is the preferred suffix. A suffix is one # or more of the following letters: sgdpn (in that order). s = static # runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build, # n = (unsure) STLPort build without iostreams from STLPort (it looks like `n' # must always be used along with `p'). Additionally, PREFERRED-RT-OPT can # start with `mt-' to indicate that there is a preference for multi-thread # builds. Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp # ... If you want to make sure you have a specific version of Boost # (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro. AC_DEFUN([BOOST_FIND_LIB], [AC_REQUIRE([BOOST_REQUIRE])dnl AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl AC_REQUIRE([BOOST_STATIC])dnl AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl if test x"$boost_cv_inc_path" = xno; then AC_MSG_NOTICE([Boost not available, not searching for the Boost $1 library]) else dnl The else branch is huge and wasn't intended on purpose. AC_LANG_PUSH([C++])dnl AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl BOOST_FIND_HEADER([$3]) boost_save_CPPFLAGS=$CPPFLAGS CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" # Now let's try to find the library. The algorithm is as follows: first look # for a given library name according to the user's PREFERRED-RT-OPT. For each # library name, we prefer to use the ones that carry the tag (toolset name). # Each library is searched through the various standard paths were Boost is # usually installed. If we can't find the standard variants, we try to # enforce -mt (for instance on MacOSX, libboost_threads.dylib doesn't exist # but there's -obviously- libboost_threads-mt.dylib). AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib], [Boost_lib=no case "$2" in #( mt | mt-) boost_mt=-mt; boost_rtopt=;; #( mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$2" : 'Xmt-*\(.*\)'`;; #( *) boost_mt=; boost_rtopt=$2;; esac if test $enable_static_boost = yes; then boost_rtopt="s$boost_rtopt" fi # Find the proper debug variant depending on what we've been asked to find. case $boost_rtopt in #( *d*) boost_rt_d=$boost_rtopt;; #( *[[sgpn]]*) # Insert the `d' at the right place (in between `sg' and `pn') boost_rt_d=`echo "$boost_rtopt" | sed 's/\(s*g*\)\(p*n*\)/\1\2/'`;; #( *) boost_rt_d='-d';; esac # If the PREFERRED-RT-OPT are not empty, prepend a `-'. test -n "$boost_rtopt" && boost_rtopt="-$boost_rtopt" $boost_guess_use_mt && boost_mt=-mt # Look for the abs path the static archive. # $libext is computed by Libtool but let's make sure it's non empty. test -z "$libext" && AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?]) boost_save_ac_objext=$ac_objext # Generate the test file. AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3> $5], [$4])]) dnl Optimization hacks: compiling C++ is slow, especially with Boost. What dnl we're trying to do here is guess the right combination of link flags dnl (LIBS / LDFLAGS) to use a given library. This can take several dnl iterations before it succeeds and is thus *very* slow. So what we do dnl instead is that we compile the code first (and thus get an object file, dnl typically conftest.o). Then we try various combinations of link flags dnl until we succeed to link conftest.o in an executable. The problem is dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always dnl remove all the temporary files including conftest.o. So the trick here dnl is to temporarily change the value of ac_objext so that conftest.o is dnl preserved accross tests. This is obviously fragile and I will burn in dnl hell for not respecting Autoconf's documented interfaces, but in the dnl mean time, it optimizes the macro by a factor of 5 to 30. dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left dnl empty because the test file is generated only once above (before we dnl start the for loops). AC_COMPILE_IFELSE([], [ac_objext=do_not_rm_me_plz], [AC_MSG_ERROR([cannot compile a test that uses Boost $1])]) ac_objext=$boost_save_ac_objext boost_failed_libs= # Don't bother to ident the 6 nested for loops, only the 2 innermost ones # matter. for boost_tag_ in -$boost_cv_lib_tag ''; do for boost_ver_ in -$boost_cv_lib_version ''; do for boost_mt_ in $boost_mt -mt ''; do for boost_rtopt_ in $boost_rtopt '' -d; do for boost_lib in \ boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \ boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \ boost_$1$boost_tag_$boost_mt_$boost_ver_ \ boost_$1$boost_tag_$boost_ver_ do # Avoid testing twice the same lib case $boost_failed_libs in #( *@$boost_lib@*) continue;; esac # If with_boost is empty, we'll search in /lib first, which is not quite # right so instead we'll try to a location based on where the headers are. boost_tmp_lib=$with_boost test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include} for boost_ldpath in "$boost_tmp_lib/lib" '' \ /opt/local/lib /usr/local/lib /opt/lib /usr/lib \ "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64 do test -e "$boost_ldpath" || continue boost_save_LDFLAGS=$LDFLAGS # Are we looking for a static library? case $boost_ldpath:$boost_rtopt_ in #( *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt) Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext" test -e "$Boost_lib_LIBS" || continue;; #( *) # No: use -lboost_foo to find the shared library. Boost_lib_LIBS="-l$boost_lib";; esac boost_save_LIBS=$LIBS LIBS="$Boost_lib_LIBS $LIBS" test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath" dnl First argument of AC_LINK_IFELSE left empty because the test file is dnl generated only once above (before we start the for loops). _BOOST_AC_LINK_IFELSE([], [Boost_lib=yes], [Boost_lib=no]) ac_objext=$boost_save_ac_objext LDFLAGS=$boost_save_LDFLAGS LIBS=$boost_save_LIBS if test x"$Boost_lib" = xyes; then Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath" break 6 else boost_failed_libs="$boost_failed_libs@$boost_lib@" fi done done done done done done rm -f conftest.$ac_objext ]) case $Boost_lib in #( no) _AC_MSG_LOG_CONFTEST AC_MSG_ERROR([cannot not find the flags to link with Boost $1]) ;; esac AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS]) AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS]) CPPFLAGS=$boost_save_CPPFLAGS AS_VAR_POPDEF([Boost_lib])dnl AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl AS_VAR_POPDEF([Boost_lib_LIBS])dnl AC_LANG_POP([C++])dnl fi ])# BOOST_FIND_LIB # --------------------------------------- # # Checks for the various Boost libraries. # # --------------------------------------- # # List of boost libraries: http://www.boost.org/libs/libraries.htm # The page http://beta.boost.org/doc/libs is useful: it gives the first release # version of each library (among other things). # BOOST_ARRAY() # ------------- # Look for Boost.Array AC_DEFUN([BOOST_ARRAY], [BOOST_FIND_HEADER([boost/array.hpp])]) # BOOST_ASIO() # ------------ # Look for Boost.Asio (new in Boost 1.35). AC_DEFUN([BOOST_ASIO], [AC_REQUIRE([BOOST_SYSTEM])dnl BOOST_FIND_HEADER([boost/asio.hpp])]) # BOOST_BIND() # ------------ # Look for Boost.Bind AC_DEFUN([BOOST_BIND], [BOOST_FIND_HEADER([boost/bind.hpp])]) # BOOST_CONVERSION() # ------------------ # Look for Boost.Conversion (cast / lexical_cast) AC_DEFUN([BOOST_CONVERSION], [BOOST_FIND_HEADER([boost/cast.hpp]) BOOST_FIND_HEADER([boost/lexical_cast.hpp]) ])# BOOST_CONVERSION # BOOST_DATE_TIME([PREFERRED-RT-OPT]) # ----------------------------------- # Look for Boost.Date_Time. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_DATE_TIME], [BOOST_FIND_LIB([date_time], [$1], [boost/date_time/posix_time/posix_time.hpp], [boost::posix_time::ptime t;]) ])# BOOST_DATE_TIME # BOOST_FILESYSTEM([PREFERRED-RT-OPT]) # ------------------------------------ # Look for Boost.Filesystem. For the documentation of PREFERRED-RT-OPT, see # the documentation of BOOST_FIND_LIB above. # Do not check for boost/filesystem.hpp because this file was introduced in # 1.34. AC_DEFUN([BOOST_FILESYSTEM], [# Do we have to check for Boost.System? This link-time dependency was # added as of 1.35.0. If we have a version <1.35, we must not attempt to # find Boost.System as it didn't exist by then. if test $boost_major_version -ge 135; then BOOST_SYSTEM([$1]) fi # end of the Boost.System check. boost_filesystem_save_LIBS=$LIBS boost_filesystem_save_LDFLAGS=$LDFLAGS m4_pattern_allow([^BOOST_SYSTEM_(LIBS|LDFLAGS)$])dnl LIBS="$LIBS $BOOST_SYSTEM_LIBS" LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS" BOOST_FIND_LIB([filesystem], [$1], [boost/filesystem/path.hpp], [boost::filesystem::path p;]) LIBS=$boost_filesystem_save_LIBS LDFLAGS=$boost_filesystem_save_LDFLAGS ])# BOOST_FILESYSTEM # BOOST_FOREACH() # --------------- # Look for Boost.Foreach AC_DEFUN([BOOST_FOREACH], [BOOST_FIND_HEADER([boost/foreach.hpp])]) # BOOST_FORMAT() # -------------- # Look for Boost.Format # Note: we can't check for boost/format/format_fwd.hpp because the header isn't # standalone. It can't be compiled because it triggers the following error: # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std' # does not name a type AC_DEFUN([BOOST_FORMAT], [BOOST_FIND_HEADER([boost/format.hpp])]) # BOOST_FUNCTION() # ---------------- # Look for Boost.Function AC_DEFUN([BOOST_FUNCTION], [BOOST_FIND_HEADER([boost/function.hpp])]) # BOOST_GRAPH([PREFERRED-RT-OPT]) # ------------------------------- # Look for Boost.Graphs. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_GRAPH], [BOOST_FIND_LIB([graph], [$1], [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;]) ])# BOOST_GRAPH # BOOST_IOSTREAMS([PREFERRED-RT-OPT]) # ------------------------------- # Look for Boost.IOStreams. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_IOSTREAMS], [BOOST_FIND_LIB([iostreams], [$1], [boost/iostreams/device/file_descriptor.hpp], [boost::iostreams::file_descriptor fd(0); fd.close();]) ])# BOOST_IOSTREAMS # BOOST_HASH() # ------------ # Look for Boost.Functional/Hash AC_DEFUN([BOOST_HASH], [BOOST_FIND_HEADER([boost/functional/hash.hpp])]) # BOOST_LAMBDA() # -------------- # Look for Boost.Lambda AC_DEFUN([BOOST_LAMBDA], [BOOST_FIND_HEADER([boost/lambda/lambda.hpp])]) # BOOST_MATH() # ------------ # Look for Boost.Math # TODO: This library isn't header-only but it comes in multiple different # flavors that don't play well with BOOST_FIND_LIB (e.g, libboost_math_c99, # libboost_math_c99f, libboost_math_c99l, libboost_math_tr1, # libboost_math_tr1f, libboost_math_tr1l). This macro must be fixed to do the # right thing anyway. AC_DEFUN([BOOST_MATH], [BOOST_FIND_HEADER([boost/math/special_functions.hpp])]) # BOOST_MULTIARRAY() # ------------------ # Look for Boost.MultiArray AC_DEFUN([BOOST_MULTIARRAY], [BOOST_FIND_HEADER([boost/multi_array.hpp])]) # BOOST_NUMERIC_CONVERSION() # -------------------------- # Look for Boost.NumericConversion (policy-based numeric conversion) AC_DEFUN([BOOST_NUMERIC_CONVERSION], [BOOST_FIND_HEADER([boost/numeric/conversion/converter.hpp]) ])# BOOST_NUMERIC_CONVERSION # BOOST_OPTIONAL() # ---------------- # Look for Boost.Optional AC_DEFUN([BOOST_OPTIONAL], [BOOST_FIND_HEADER([boost/optional.hpp])]) # BOOST_PREPROCESSOR() # -------------------- # Look for Boost.Preprocessor AC_DEFUN([BOOST_PREPROCESSOR], [BOOST_FIND_HEADER([boost/preprocessor/repeat.hpp])]) # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT]) # ----------------------------------------- # Look for Boost.Program_options. For the documentation of PREFERRED-RT-OPT, see # the documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_PROGRAM_OPTIONS], [BOOST_FIND_LIB([program_options], [$1], [boost/program_options.hpp], [boost::program_options::options_description d("test");]) ])# BOOST_PROGRAM_OPTIONS # BOOST_REF() # ----------- # Look for Boost.Ref AC_DEFUN([BOOST_REF], [BOOST_FIND_HEADER([boost/ref.hpp])]) # BOOST_REGEX([PREFERRED-RT-OPT]) # ------------------------------- # Look for Boost.Regex. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_REGEX], [BOOST_FIND_LIB([regex], [$1], [boost/regex.hpp], [boost::regex exp("*"); boost::regex_match("foo", exp);]) ])# BOOST_REGEX # BOOST_SERIALIZATION([PREFERRED-RT-OPT]) # --------------------------------------- # Look for Boost.Serialization. For the documentation of PREFERRED-RT-OPT, see # the documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_SERIALIZATION], [BOOST_FIND_LIB([serialization], [$1], [boost/archive/text_oarchive.hpp], [std::ostream* o = 0; // Cheap way to get an ostream... boost::archive::text_oarchive t(*o);]) ])# BOOST_SIGNALS # BOOST_SIGNALS([PREFERRED-RT-OPT]) # --------------------------------- # Look for Boost.Signals. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_SIGNALS], [BOOST_FIND_LIB([signals], [$1], [boost/signal.hpp], [boost::signal s;]) ])# BOOST_SIGNALS # BOOST_SMART_PTR() # ----------------- # Look for Boost.SmartPtr AC_DEFUN([BOOST_SMART_PTR], [BOOST_FIND_HEADER([boost/scoped_ptr.hpp]) BOOST_FIND_HEADER([boost/shared_ptr.hpp]) ]) # BOOST_STATICASSERT() # -------------------- # Look for Boost.StaticAssert AC_DEFUN([BOOST_STATICASSERT], [BOOST_FIND_HEADER([boost/static_assert.hpp])]) # BOOST_STRING_ALGO() # ------------------- # Look for Boost.StringAlgo AC_DEFUN([BOOST_STRING_ALGO], [BOOST_FIND_HEADER([boost/algorithm/string.hpp]) ]) # BOOST_SYSTEM([PREFERRED-RT-OPT]) # -------------------------------- # Look for Boost.System. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. This library was introduced in Boost # 1.35.0. AC_DEFUN([BOOST_SYSTEM], [BOOST_FIND_LIB([system], [$1], [boost/system/error_code.hpp], [boost::system::error_code e; e.clear();]) ])# BOOST_SYSTEM # BOOST_TEST([PREFERRED-RT-OPT]) # ------------------------------ # Look for Boost.Test. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_TEST], [m4_pattern_allow([^BOOST_CHECK$])dnl BOOST_FIND_LIB([unit_test_framework], [$1], [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);], [using boost::unit_test::test_suite; test_suite* init_unit_test_suite(int argc, char ** argv) { return NULL; }]) ])# BOOST_TEST # BOOST_THREADS([PREFERRED-RT-OPT]) # --------------------------------- # Look for Boost.Thread. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. # FIXME: Provide an alias "BOOST_THREAD". AC_DEFUN([BOOST_THREADS], [dnl Having the pthread flag is required at least on GCC3 where dnl boost/thread.hpp would complain if we try to compile without dnl -pthread on GNU/Linux. AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl boost_threads_save_LIBS=$LIBS boost_threads_save_CPPFLAGS=$CPPFLAGS LIBS="$LIBS $boost_cv_pthread_flag" # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3, # boost/thread.hpp will trigger a #error if -pthread isn't used: # boost/config/requires_threads.hpp:47:5: #error "Compiler threading support # is not turned on. Please set the correct command line options for # threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)" CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag" BOOST_FIND_LIB([thread], [$1], [boost/thread.hpp], [boost::thread t; boost::mutex m;]) BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag" BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag" LIBS=$boost_threads_save_LIBS CPPFLAGS=$boost_threads_save_CPPFLAGS ])# BOOST_THREADS # BOOST_TOKENIZER() # ----------------- # Look for Boost.Tokenizer AC_DEFUN([BOOST_TOKENIZER], [BOOST_FIND_HEADER([boost/tokenizer.hpp])]) # BOOST_TRIBOOL() # --------------- # Look for Boost.Tribool AC_DEFUN([BOOST_TRIBOOL], [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp]) BOOST_FIND_HEADER([boost/logic/tribool.hpp]) ]) # BOOST_TUPLE() # ------------- # Look for Boost.Tuple AC_DEFUN([BOOST_TUPLE], [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])]) # BOOST_TYPETRAITS() # -------------------- # Look for Boost.TypeTraits AC_DEFUN([BOOST_TYPETRAITS], [BOOST_FIND_HEADER([boost/type_traits.hpp])]) # BOOST_UTILITY() # --------------- # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom, # etc.) AC_DEFUN([BOOST_UTILITY], [BOOST_FIND_HEADER([boost/utility.hpp])]) # BOOST_VARIANT() # --------------- # Look for Boost.Variant. AC_DEFUN([BOOST_VARIANT], [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp]) BOOST_FIND_HEADER([boost/variant.hpp])]) # BOOST_WAVE([PREFERRED-RT-OPT]) # ------------------------------ # NOTE: If you intend to use Wave/Spirit with thread support, make sure you # call BOOST_THREADS first. # Look for Boost.Wave. For the documentation of PREFERRED-RT-OPT, see the # documentation of BOOST_FIND_LIB above. AC_DEFUN([BOOST_WAVE], [AC_REQUIRE([BOOST_FILESYSTEM])dnl AC_REQUIRE([BOOST_DATE_TIME])dnl boost_wave_save_LIBS=$LIBS boost_wave_save_LDFLAGS=$LDFLAGS m4_pattern_allow([^BOOST_((FILE)?SYSTEM|DATE_TIME|THREAD)_(LIBS|LDFLAGS)$])dnl LIBS="$LIBS $BOOST_SYSTEM_LIBS $BOOST_FILESYSTEM_LIBS $BOOST_DATE_TIME_LIBS\ $BOOST_THREAD_LIBS" LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS $BOOST_FILESYSTEM_LDFLAGS\ $BOOST_DATE_TIME_LDFLAGS $BOOST_THREAD_LDFLAGS" BOOST_FIND_LIB([wave], [$1], [boost/wave.hpp], [boost::wave::token_id id; get_token_name(id);]) LIBS=$boost_wave_save_LIBS LDFLAGS=$boost_wave_save_LDFLAGS ])# BOOST_WAVE # BOOST_XPRESSIVE() # ----------------- # Look for Boost.Xpressive (new since 1.36.0). AC_DEFUN([BOOST_XPRESSIVE], [BOOST_FIND_HEADER([boost/xpressive/xpressive.hpp])]) # ----------------- # # Internal helpers. # # ----------------- # # _BOOST_PTHREAD_FLAG() # --------------------- # Internal helper for BOOST_THREADS. Based on ACX_PTHREAD: # http://autoconf-archive.cryp.to/acx_pthread.html AC_DEFUN([_BOOST_PTHREAD_FLAG], [AC_REQUIRE([AC_PROG_CXX])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_LANG_PUSH([C++])dnl AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag], [ boost_cv_pthread_flag= # The ordering *is* (sometimes) important. Some notes on the # individual items follow: # (none): in case threads are in libc; should be tried before -Kthread and # other compiler flags to prevent continual compiler warnings # -lpthreads: AIX (must check this before -lpthread) # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread) # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads) # -pthreads: Solaris/GCC # -mthreads: MinGW32/GCC, Lynx/GCC # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it # doesn't hurt to check since this sometimes defines pthreads too; # also defines -D_REENTRANT) # ... -mt is also the pthreads flag for HP/aCC # -lpthread: GNU Linux, etc. # --thread-safe: KAI C++ case $host_os in #( *solaris*) # On Solaris (at least, for some versions), libc contains stubbed # (non-functional) versions of the pthreads routines, so link-based # tests will erroneously succeed. (We need to link with -pthreads/-mt/ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather # a function called by this macro, so we could check for that, but # who knows whether they'll stub that too in a future libc.) So, # we'll just look for -pthreads and -lpthread first: boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #( *) boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \ -pthreads -mthreads -lpthread --thread-safe -mt";; esac # Generate the test file. AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include ], [pthread_t th; pthread_join(th, 0); pthread_attr_init(0); pthread_cleanup_push(0, 0); pthread_create(0,0,0,0); pthread_cleanup_pop(0);])]) for boost_pthread_flag in '' $boost_pthread_flags; do boost_pthread_ok=false dnl Re-use the test file already generated. boost_pthreads__save_LIBS=$LIBS LIBS="$LIBS $boost_pthread_flag" AC_LINK_IFELSE([], [if grep ".*$boost_pthread_flag" conftest.err; then echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD else boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag fi]) LIBS=$boost_pthreads__save_LIBS $boost_pthread_ok && break done ]) AC_LANG_POP([C++])dnl ])# _BOOST_PTHREAD_FLAG # _BOOST_gcc_test(MAJOR, MINOR) # ----------------------------- # Internal helper for _BOOST_FIND_COMPILER_TAG. m4_define([_BOOST_gcc_test], ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl # _BOOST_FIND_COMPILER_TAG() # -------------------------- # Internal. When Boost is installed without --layout=system, each library # filename will hold a suffix that encodes the compiler used during the # build. The Boost build system seems to call this a `tag'. AC_DEFUN([_BOOST_FIND_COMPILER_TAG], [AC_REQUIRE([AC_PROG_CXX])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag], [boost_cv_lib_tag=unknown if test x$boost_cv_inc_path != xno; then AC_LANG_PUSH([C++])dnl # The following tests are mostly inspired by boost/config/auto_link.hpp # The list is sorted to most recent/common to oldest compiler (in order # to increase the likelihood of finding the right compiler with the # least number of compilation attempt). # Beware that some tests are sensible to the order (for instance, we must # look for MinGW before looking for GCC3). # I used one compilation test per compiler with a #error to recognize # each compiler so that it works even when cross-compiling (let me know # if you know a better approach). # Known missing tags (known from Boost's tools/build/v2/tools/common.jam): # como, edg, kcc, bck, mp, sw, tru, xlc # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines # the same defines as GCC's). # TODO: Move the test on GCC 4.4 up once it's released. for i in \ _BOOST_gcc_test(4, 3) \ _BOOST_gcc_test(4, 2) \ _BOOST_gcc_test(4, 1) \ _BOOST_gcc_test(4, 0) \ "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \ && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \ || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \ _BOOST_gcc_test(3, 4) \ _BOOST_gcc_test(3, 3) \ "defined _MSC_VER && _MSC_VER >= 1500 @ vc90" \ "defined _MSC_VER && _MSC_VER == 1400 @ vc80" \ _BOOST_gcc_test(3, 2) \ "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \ _BOOST_gcc_test(3, 1) \ _BOOST_gcc_test(3, 0) \ "defined __BORLANDC__ @ bcb" \ "defined __ICC && (defined __unix || defined __unix__) @ il" \ "defined __ICL @ iw" \ "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \ _BOOST_gcc_test(4, 4) \ _BOOST_gcc_test(2, 95) \ "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \ "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \ "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \ "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8" do boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '` boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'` AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #if $boost_tag_test /* OK */ #else # error $boost_tag_test #endif ]])], [boost_cv_lib_tag=$boost_tag; break], []) done AC_LANG_POP([C++])dnl case $boost_cv_lib_tag in #( # Some newer (>= 1.35?) versions of Boost seem to only use "gcc" as opposed # to "gcc41" for instance. *-gcc | *'-gcc ') :;; #( Don't re-add -gcc: it's already in there. gcc*) boost_tag_x= case $host_os in #( darwin*) if test $boost_major_version -ge 136; then # The `x' added in r46793 of Boost. boost_tag_x=x fi;; esac # We can specify multiple tags in this variable because it's used by # BOOST_FIND_LIB that does a `for tag in -$boost_cv_lib_tag' ... boost_cv_lib_tag="$boost_tag_x$boost_cv_lib_tag -${boost_tag_x}gcc" ;; #( unknown) AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]]) boost_cv_lib_tag= ;; esac fi])dnl end of AC_CACHE_CHECK ])# _BOOST_FIND_COMPILER_TAG # _BOOST_GUESS_WHETHER_TO_USE_MT() # -------------------------------- # Compile a small test to try to guess whether we should favor MT (Multi # Thread) flavors of Boost. Sets boost_guess_use_mt accordingly. AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT], [# Check whether we do better use `mt' even though we weren't ask to. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #if defined _REENTRANT || defined _MT || defined __MT__ /* use -mt */ #else # error MT not needed #endif ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false]) ]) # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) # ------------------------------------------------------------------- # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls. Fragile, # will break when Autoconf changes its internals. Requires that you manually # rm -f conftest.$ac_objext in between to really different tests, otherwise # you will try to link a conftest.o left behind by a previous test. # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this # macro). # # Don't use "break" in the actions, as it would short-circuit some code # this macro runs after the actions. m4_define([_BOOST_AC_LINK_IFELSE], [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl rm -f conftest$ac_exeext boost_save_ac_ext=$ac_ext boost_use_source=: # If we already have a .o, re-use it. We change $ac_ext so that $ac_link # tries to link the existing object file instead of compiling from source. test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false && _AS_ECHO_LOG([re-using the existing conftest.$ac_objext]) AS_IF([_AC_DO_STDERR($ac_link) && { test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || $as_executable_p conftest$ac_exeext dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough. }], [$2], [if $boost_use_source; then _AC_MSG_LOG_CONFTEST fi $3]) ac_objext=$boost_save_ac_objext ac_ext=$boost_save_ac_ext dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization) dnl information created by the PGI compiler (conftest_ipa8_conftest.oo), dnl as it would interfere with the next link command. rm -f core conftest.err conftest_ipa8_conftest.oo \ conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl ])# _BOOST_AC_LINK_IFELSE # Local Variables: # mode: autoconf # End: ibus-libzhuyin-1.6.99.20140929/po/000077500000000000000000000000001241117270600161255ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/po/POTFILES.in000066400000000000000000000002271241117270600177030ustar00rootroot00000000000000src/ZYZhuyinProperties.cc src/ZYMain.cc setup/main.py [type: gettext/glade]setup/ibus-libzhuyin-preferences.ui data/ibus-setup-libzhuyin.desktop.in.in ibus-libzhuyin-1.6.99.20140929/po/POTFILES.skip000066400000000000000000000000451241117270600202410ustar00rootroot00000000000000data/ibus-setup-libzhuyin.desktop.in ibus-libzhuyin-1.6.99.20140929/setup/000077500000000000000000000000001241117270600166475ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/setup/Makefile.am000066400000000000000000000025711241117270600207100ustar00rootroot00000000000000# vim:set noet ts=4: # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. setup_libzhuyin_PYTHON = \ main.py \ config.py \ ibus-libzhuyin-preferences.ui \ $(NULL) setup_libzhuyindir = $(datadir)/ibus-libzhuyin/setup libexec_SCRIPTS = \ ibus-setup-libzhuyin \ $(NULL) CLEANFILES = \ *.pyc \ $(NULL) EXTRA_DIST = \ config.py.in \ ibus-setup-libzhuyin.in \ $(NULL) test-libzhuyin: $(ENV) DBUS_DEBUG=true \ IBUS_LOCALEDIR=@localedir@ \ IBUS_PKGDATADIR=$(pkgdatadir) \ PYTHONPATH=$(abs_top_srcdir):$(pyexecdir) \ $(PYTHON) $(srcdir)/main.py ibus-libzhuyin-1.6.99.20140929/setup/config.py.in000066400000000000000000000015671241117270600211040ustar00rootroot00000000000000# vim:set et ts=4 sts=4: # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2013-2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. def get_version(): return "@VERSION@" ibus-libzhuyin-1.6.99.20140929/setup/ibus-libzhuyin-preferences.ui000066400000000000000000001227301241117270600244670ustar00rootroot00000000000000 1 10 10 1 10 Standard HSU IBM GinYieh Eten Eten26 Standard Dvorak HSU Dvorak DaChen CP26 Hanyu Pinyin Luoma Pinyin Secondary Bopomofo 1234567890 asdfghjkl; asdfzxcv89 asdfjkl789 aoeu;qjkix aoeuhtnsid aoeuidhtns 1234qweras False True True left True False vertical True Use Chinese Mode When Start-up True True False start center 10 0 True False True 0 Use Full Width English When Start-up True True False start center 10 0 True False True 1 Use Full Width Punctuation When Start-up True True False start center 10 0 True False True 2 Use Traditional Chinese When Start-up True True False start center 10 0 True False True 3 Always Input Numbers by Input Pad True True False start center 10 0 True False True 4 True False Inputting False True False 10 10 10 10 10 10 10 True True False start center 10 Keyboard Layout 0 0 1 1 True False start center 10 Candidate Choose Keys 0 1 1 1 True False center 10 liststoreKeyboardMapping 0 1 0 1 1 True False center 10 liststoreSelectionKeys True 0 False 1 1 1 1 True False start center 10 Candidates per Page 0 2 1 1 True True start center 10 number adjustmentCandidate True 1 2 1 1 1 True False Keyboard 1 False True False True True Enable Fuzzy Zhuyin True True False start center 10 0 True True 0 0 1 1 l <=> n True True False start center 10 0 True 0 1 1 1 f <=> h True True False start center 10 0 True 0 2 1 1 l <=> r True True False start center 10 0 True 0 3 1 1 g <=> k True True False start center 10 0 True 0 4 1 1 c <=> ch True True False start center 10 0 True 1 1 1 1 z <=> zh True True False start center 10 0 True 1 2 1 1 s <=> sh True True False start center 10 0 True 1 3 1 1 an <=> ang True True False start center 10 0 True 0 5 1 1 in <=> ing True True False start center 10 0 True 0 6 1 1 en <=> eng True True False start center 10 0 True 1 5 1 1 2 True False Fuzzy Zhuyin 2 False True False 10 10 vertical 10 True False 10 User Symbols True True False 0 True True False True 0 Edit True True True 10 False True end 1 False True 0 True False 10 Easy Symbols True True False 0 True True False True 0 Edit True True True 10 False True end 1 False True 1 True False 10 True False 10 User Phrases False True 0 Clear True True True 10 False True end 1 Import True True True False True end 2 False True 2 True False Clear All Data True True True center 10 False True end 1 False True 3 True True 10 10 True False <b>Dictionary File Format:</b> Each line contains the following: "phrase zhuyin" like "你好 ㄋㄧˇ ㄏㄠˇ". True True False Help False True 4 3 True False User Phrases 3 False True False center 10 10 10 10 True False center vertical True False 32 gtk-about False True 0 True False <big><b>IBus Zhuyin %s</b></big> True False True 1 True False New Zhuyin input method for IBus False True 2 True False <small>Copyright (c) 2013-2014 Peng Wu</small> True False True 3 https://github.com/libzhuyin/ibus-libzhuyin True True True none https://github.com/libzhuyin/ibus-libzhuyin False True 4 True False <small> <b>Authors:</b> Peng Wu Peng Huang ... <b>Contributors:</b> ... </small> True end False True 5 4 True False About 4 False ibus-libzhuyin-1.6.99.20140929/setup/ibus-setup-libzhuyin.in000066400000000000000000000021741241117270600233160ustar00rootroot00000000000000#!/bin/sh # vim:set noet ts=4: # # ibus-tmpl - The Input Bus template project # # Copyright (c) 2007-2008 Peng Huang # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. prefix=@prefix@ exec_prefix=@exec_prefix@ datarootdir=@datarootdir@ pkgdatadir=@prefix@/share/@PACKAGE@ export IBUS_PREFIX=@prefix@ export IBUS_DATAROOTDIR=@datarootdir@ export IBUS_LOCALEDIR=@localedir@ export IBUS_PKGDATADIR=@prefix@/share/@PACKAGE@ cd @prefix@/share/@PACKAGE@/setup/ exec python main.py $@ ibus-libzhuyin-1.6.99.20140929/setup/main.py000066400000000000000000000300061241117270600201440ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2013-2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import gettext import locale import os import sys from gi.repository import GLib from gi.repository import Gtk from gi.repository import IBus import config locale.setlocale(locale.LC_ALL, "") localedir = os.getenv("IBUS_LOCALEDIR") pkgdatadir = os.getenv("IBUS_PKGDATADIR") or "." gettext.install('ibus-libzhuyin', localedir) class PreferencesWindow: def __init__(self, engine, parent=None): self.__bus = IBus.Bus() self.__config = self.__bus.get_config() self.__builder = Gtk.Builder() self.__builder.set_translation_domain("ibus-libzhuyin") self.__builder.add_from_file("ibus-libzhuyin-preferences.ui") self.__window = self.__builder.get_object("window") self.__init_pages() if engine == "zhuyin": self.__config_namespace = "engine/zhuyin" self.__values = dict(self.__config.get_values(self.__config_namespace)) self.__init_inputting() self.__init_keyboard() self.__init_fuzzy_zhuyin() self.__init_user_phrases() self.__init_about() self.__update_fuzzy_zhuyin() else: print("Error: Unknown Engine") exit() self.__pages.set_current_page(0) self.__window.connect("delete-event", Gtk.main_quit) def __init_pages(self): self.__pages = self.__builder.get_object("pages") self.__page_inputting = self.__builder.get_object("pageInputting") self.__page_keyboard = self.__builder.get_object("pageKeyboard") self.__page_fuzzy_zhuyin = self.__builder.get_object("pageFuzzyZhuyin") self.__page_user_phrases = self.__builder.get_object("pageUserPhrases") self.__page_about = self.__builder.get_object("pageAbout") self.__page_inputting.hide() self.__page_keyboard.hide() self.__page_fuzzy_zhuyin.hide() self.__page_user_phrases.hide() self.__page_about.hide() def __init_inputting(self): # page Inputting self.__page_inputting.show() # init state self.__chinese_mode = self.__builder.get_object("chinesemode") self.__full_half_english = self.__builder.get_object("fullhalfenglish") self.__full_half_punct = self.__builder.get_object("fullhalfpunct") self.__traditional_chinese = self.__builder.get_object("traditionalchinese") self.__always_input_num = self.__builder.get_object("alwaysinputnum") # read values self.__chinese_mode.set_active(self.__get_value("chinesemode", True)) self.__full_half_english.set_active(self.__get_value("fullhalfenglish", False)) self.__full_half_punct.set_active(self.__get_value("fullhalfpunct", True)) self.__traditional_chinese.set_active(self.__get_value("traditionalchinese", True)) self.__always_input_num.set_active(self.__get_value("alwaysinputnum", False)) # connect signals self.__chinese_mode.connect("toggled", self.__toggled_cb, "chinesemode") self.__full_half_english.connect("toggled", self.__toggled_cb, "fullhalfenglish") self.__full_half_punct.connect("toggled", self.__toggled_cb, "fullhalfpunct") self.__traditional_chinese.connect("toggled", self.__toggled_cb, "traditionalchinese") self.__always_input_num.connect("toggled", self.__toggled_cb, "alwaysinputnum") def __init_keyboard(self): # page Keyboard self.__page_keyboard.show() # init state self.__keyboard_layout = self.__builder.get_object("keyboardlayout") self.__candidate_keys = self.__builder.get_object("candidatekeys") self.__candidate_keys_entry = self.__candidate_keys.get_child() self.__candidate_num = self.__builder.get_object("candidatenum") # read value self.__keyboard_layout.set_active(self.__get_value("keyboardlayout", 0)) self.__candidate_keys_entry.set_text(self.__get_value("candidatekeys", "1234567890")) self.__candidate_num.set_value(self.__get_value("candidatenum", 10)) # connect signals self.__keyboard_layout.connect("changed", self.__keyboard_layout_cb, "keyboardlayout") self.__candidate_keys_entry.connect("changed", self.__candidate_keys_entry_cb, "candidatekeys") self.__candidate_num.connect("value-changed", self.__candidate_num_cb, "candidatenum") def __keyboard_layout_cb(self, widget, name): self.__set_value(name, widget.get_active()) def __candidate_keys_entry_cb(self, widget, name): self.__set_value(name, widget.get_text()) def __candidate_num_cb(self, widget, name): self.__set_value(name, int(widget.get_value())) def __init_fuzzy_zhuyin(self): # page Fuzzy Zhuyin self.__page_fuzzy_zhuyin.show() # fuzzy zhuyin self.__fuzzy_zhuyin = self.__builder.get_object("fuzzyzhuyin") self.__fuzzy_zhuyin_widgets = [ ("fuzzyzhuyin_c_ch", True), ("fuzzyzhuyin_z_zh", True), ("fuzzyzhuyin_s_sh", True), ("fuzzyzhuyin_l_n", True), ("fuzzyzhuyin_f_h", True), ("fuzzyzhuyin_l_r", False), ("fuzzyzhuyin_g_k", False), ("fuzzyzhuyin_an_ang", True), ("fuzzyzhuyin_en_eng", True), ("fuzzyzhuyin_in_ing", True), ] def __fuzzy_zhuyin_toggled_cb(widget): val = widget.get_active() for name, defval in self.__fuzzy_zhuyin_widgets: widget = self.__builder.get_object(name) widget.set_sensitive(val) self.__fuzzy_zhuyin.connect("toggled", __fuzzy_zhuyin_toggled_cb) # init value self.__fuzzy_zhuyin.set_active(self.__get_value("fuzzyzhuyin", False)) for name, defval in self.__fuzzy_zhuyin_widgets: widget = self.__builder.get_object(name) widget.set_active(self.__get_value(name, defval)) self.__fuzzy_zhuyin.connect("toggled", self.__toggled_cb, "fuzzyzhuyin") for name, defval in self.__fuzzy_zhuyin_widgets: widget = self.__builder.get_object(name) widget.connect("toggled", self.__toggled_cb, name) def __init_user_phrases(self): # page User Phrases self.__page_user_phrases.show() # init state self.__box_user_symbol = self.__builder.get_object("boxUserSymbol") self.__user_symbol = self.__builder.get_object("usersymbol") self.__edit_user_symbol = self.__builder.get_object("editusersymbol") self.__box_easy_symbol = self.__builder.get_object("boxEasySymbol") self.__easy_symbol = self.__builder.get_object("easysymbol") self.__edit_easy_symbol = self.__builder.get_object("editeasysymbol") self.__import_dictionary = self.__builder.get_object("importdictionary") self.__clear_user_data = self.__builder.get_object("clearuserdata") self.__clear_all_data = self.__builder.get_object("clearalldata") # check file path = os.path.join(pkgdatadir, 'usersymbol.txt') if not os.access(path, os.R_OK): self.__box_user_symbol.hide() path = os.path.join(pkgdatadir, 'easysymbol.txt') if not os.access(path, os.R_OK): self.__box_easy_symbol.hide() # connect signals self.__user_symbol.connect("toggled", self.__enable_symbol_cb, "usersymbol", self.__edit_user_symbol) self.__edit_user_symbol.connect("clicked", self.__edit_symbol_cb, "usersymbol.txt") self.__easy_symbol.connect("toggled", self.__enable_symbol_cb, "easysymbol", self.__edit_easy_symbol) self.__edit_easy_symbol.connect("clicked", self.__edit_symbol_cb, "easysymbol.txt") self.__import_dictionary.connect("clicked", self.__import_dictionary_cb) self.__clear_user_data.connect("clicked", self.__clear_user_data_cb, "user") self.__clear_all_data.connect("clicked", self.__clear_user_data_cb, "all") # read value self.__user_symbol.set_active(self.__get_value("usersymbol", True)) self.__easy_symbol.set_active(self.__get_value("easysymbol", True)) def __enable_symbol_cb(self, widget, name, editbutton): editbutton.set_sensitive(widget.get_active ()) self.__set_value(name, widget.get_active ()) def __edit_symbol_cb(self, widget, filename): import shutil path = os.path.join(GLib.get_user_config_dir(), "ibus", "libzhuyin") os.path.exists(path) or os.makedirs(path) path = os.path.join(path, filename) if not os.path.exists(path): src = os.path.join(pkgdatadir, filename) shutil.copyfile(src, path) os.system("xdg-open %s" % path) def __import_dictionary_cb(self, widget): dialog = Gtk.FileChooserDialog \ (_("Please choose a file"), None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) filter_text = Gtk.FileFilter() filter_text.set_name("Text files") filter_text.add_mime_type("text/plain") dialog.add_filter(filter_text) response = dialog.run() if response == Gtk.ResponseType.OK: self.__set_value("importdictionary", dialog.get_filename()) dialog.destroy() def __clear_user_data_cb(self, widget, name): self.__set_value("clearuserdata", name) def __init_about(self): # page About self.__page_about.show() self.__name_version = self.__builder.get_object("nameversion") self.__name_version.set_markup(_("New Zhuyin %s") % config.get_version()) def __update_fuzzy_zhuyin(self): options = [ ("fuzzyzhuyin_c_ch", "ㄘ <=> ㄔ"), ("fuzzyzhuyin_z_zh", "ㄗ <=> ㄓ"), ("fuzzyzhuyin_s_sh", "ㄙ <=> ㄕ"), ("fuzzyzhuyin_l_n", "ㄌ <=> ㄋ"), ("fuzzyzhuyin_f_h", "ㄈ <=> ㄏ"), ("fuzzyzhuyin_l_r", "ㄌ <=> ㄖ"), ("fuzzyzhuyin_g_k", "ㄍ <=> ㄎ"), ("fuzzyzhuyin_an_ang", "ㄢ <=> ㄤ"), ("fuzzyzhuyin_en_eng", "ㄣ <=> ㄥ"), ("fuzzyzhuyin_in_ing", "ㄧㄣ <=> ㄧㄥ"), ] for name, label in options: self.__builder.get_object(name).set_label(label) def __toggled_cb(self, widget, name): self.__set_value(name, widget.get_active ()) def __get_value(self, name, defval): if name in self.__values: var = self.__values[name] if isinstance(defval, type(var)): return var self.__set_value(name, defval) return defval def __set_value(self, name, val): var = None if isinstance(val, bool): var = GLib.Variant.new_boolean(val) elif isinstance(val, int): var = GLib.Variant.new_int32(val) elif isinstance(val, str): var = GLib.Variant.new_string(val) else: print >> sys.stderr, "val(%s) is not in support type." % repr(val) return self.__values[name] = val self.__config.set_value(self.__config_namespace, name, var) def show(self): self.__window.show() def main(): name = "zhuyin" PreferencesWindow(name).show() Gtk.main() if __name__ == "__main__": main() ibus-libzhuyin-1.6.99.20140929/src/000077500000000000000000000000001241117270600162765ustar00rootroot00000000000000ibus-libzhuyin-1.6.99.20140929/src/Makefile.am000066400000000000000000000064651241117270600203450ustar00rootroot00000000000000# vim:set noet ts=4: # # ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus # # Copyright (c) 2014 Peng Wu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. libexec_PROGRAMS = ibus-engine-libzhuyin #ibus_engine_libzhuyin_built_c_sources = \ # $(NULL) #ibus_engine_libzhuyin_built_h_sources = \ # ZYPunctTable.h \ # ZYSimpTradConverterTable.h \ # $(NULL) ibus_engine_libzhuyin_c_sources = \ ZYConfig.cc \ ZYEditor.cc \ ZYLibZhuyin.cc \ ZYZConfig.cc \ ZYZhuyinProperties.cc \ ZYTradSimpConverter.cc \ ZYEnhancedText.cc \ ZYZEnhancedEditor.cc \ ZYZPhoneticEditor.cc \ ZYZZhuyinEditor.cc \ ZYZPinyinEditor.cc \ ZYSymbols.cc \ ZYSymbolLookup.cc \ ZYZBuiltinSymbolSection.cc \ ZYZPhoneticSection.cc \ ZYZBopomofoSymbolSection.cc \ ZYZUserSymbolListAllSection.cc \ ZYZUserSymbolShownSection.cc \ ZYFallbackEditor.cc \ ZYEngine.cc \ ZYZZhuyinEngine.cc \ ZYMain.cc \ $(NULL) ibus_engine_libzhuyin_h_sources = \ ZYBus.h \ ZYConfig.h \ ZYEditor.h \ ZYLookupTable.h \ ZYObject.h \ ZYLibZhuyin.h \ ZYZConfig.h \ ZYZhuyinProperties.h \ ZYTradSimpConverter.h \ ZYEnhancedText.h \ ZYZEnhancedEditor.h \ ZYZPhoneticEditor.h \ ZYZZhuyinEditor.h \ ZYZPinyinEditor.h \ ZYSymbols.h \ ZYSymbolLookup.h \ ZYZSymbolSection.h \ ZYZBuiltinSymbolSection.h \ ZYZPhoneticSection.h \ ZYZBopomofoSymbolSection.h \ ZYZUserSymbolListAllSection.h \ ZYZUserSymbolShownSection.h \ ZYPointer.h \ ZYProperty.h \ ZYRawEditor.h \ ZYFallbackEditor.h \ ZYSignal.h \ ZYString.h \ ZYText.h \ ZYTypes.h \ ZYUtil.h \ ZYEngine.h \ ZYZZhuyinEngine.h \ $(NULL) ibus_engine_libzhuyin_SOURCES = \ $(ibus_engine_libzhuyin_c_sources) \ $(ibus_engine_libzhuyin_h_sources) \ $(NULL) ibus_engine_libzhuyin_CXXFLAGS = \ @IBUS_CFLAGS@ \ @LIBZHUYIN_CFLAGS@ \ @OPENCC_CFLAGS@ \ -DGETTEXT_PACKAGE=\"@GETTEXT_PACKAGE@\" \ -DPKGDATADIR=\"$(pkgdatadir)\" \ -DLIBEXECDIR=\"$(libexecdir)\" \ -DLIBZHUYIN_DATADIR=\"@LIBZHUYIN_DATADIR@\/data\" \ $(NULL) if HAVE_BOOST ibus_engine_libzhuyin_CXXFLAGS += \ @BOOST_CPPFLAGS@ \ $(NULL) else ibus_engine_libzhuyin_CXXFLAGS += \ -std=c++0x \ $(NULL) endif ibus_engine_libzhuyin_LDADD = \ @IBUS_LIBS@ \ @LIBZHUYIN_LIBS@ \ @OPENCC_LIBS@ \ $(NULL) component_DATA = \ libzhuyin.xml \ $(NULL) componentdir = @datadir@/ibus/component EXTRA_DIST = \ libzhuyin.xml.in \ $(NULL) CLEANFILES = \ libzhuyin.xml \ $(NULL) libzhuyin.xml: libzhuyin.xml.in $(AM_V_GEN) \ ( \ libexecdir=${libexecdir}; \ pkgdatadir=${pkgdatadir}; \ s=`cat $<`; \ eval "echo \"$${s}\""; \ ) > $@ ibus-libzhuyin-1.6.99.20140929/src/ZYBus.h000066400000000000000000000023141241117270600174630ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_BUS_H_ #define __ZY_BUS_H_ #include #include "ZYObject.h" namespace ZY { class Bus : Object { public: Bus (void) : Object (ibus_bus_new ()) { } bool isConnected (void) { return ibus_bus_is_connected (*this); } operator IBusBus * (void) const { return get (); } }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYConfig.cc000066400000000000000000000072041241117270600203000ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYConfig.h" #include "ZYTypes.h" #include "ZYBus.h" namespace ZY { Config::Config (Bus & bus, const std::string & name) : Object (ibus_bus_get_config (bus)), m_section ("engine/" + name) { initDefaultValues (); g_signal_connect (get (), "value-changed", G_CALLBACK (valueChangedCallback), this); } Config::~Config (void) { } void Config::initDefaultValues (void) { m_page_size = 5; m_keyboard_layout = CHEWING_DEFAULT; m_init_chinese = TRUE; m_init_full_english = FALSE; m_init_full_punct = TRUE; m_init_trad_chinese = TRUE; m_always_input_numbers = FALSE; m_easy_symbol = TRUE; m_user_symbol = TRUE; } void Config::readDefaultValues (void) { } inline bool Config::read (const gchar * name, bool defval) { GVariant *value = NULL; if ((value = ibus_config_get_value (get (), m_section.c_str (), name)) != NULL) { if (g_variant_classify (value) == G_VARIANT_CLASS_BOOLEAN) return g_variant_get_boolean (value); } // write default value to config value = g_variant_new ("b", defval); ibus_config_set_value (get (), m_section.c_str (), name, value); return defval; } inline gint Config::read (const gchar * name, gint defval) { GVariant *value = NULL; if ((value = ibus_config_get_value (get (), m_section.c_str (), name)) != NULL) { if (g_variant_classify (value) == G_VARIANT_CLASS_INT32) return g_variant_get_int32 (value); } // write default value to config value = g_variant_new ("i", defval); ibus_config_set_value (get (), m_section.c_str (), name, value); return defval; } inline std::string Config::read (const gchar * name, const gchar * defval) { GVariant *value = NULL; if ((value = ibus_config_get_value (get (), m_section.c_str (), name)) != NULL) { if (g_variant_classify (value) == G_VARIANT_CLASS_STRING) return g_variant_get_string (value, NULL); } // write default value to config value = g_variant_new ("s", defval); ibus_config_set_value (get (), m_section.c_str (), name, value); return defval; } gboolean Config::valueChanged (const std::string §ion, const std::string &name, GVariant *value) { return FALSE; } void Config::valueChangedCallback (IBusConfig *config, const gchar *section, const gchar *name, GVariant *value, Config *self) { self->valueChanged (section, name, value); } }; ibus-libzhuyin-1.6.99.20140929/src/ZYConfig.h000066400000000000000000000077261241117270600201530ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_CONFIG_H_ #define __ZY_CONFIG_H_ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "ZYUtil.h" #include "ZYObject.h" namespace ZY { class Bus; class Config : public Object { protected: Config (Bus & bus, const std::string & name); virtual ~Config (void); public: zhuyin_option_t option (void) const { return m_option & m_option_mask; } guint orientation (void) const { return m_orientation; } guint pageSize (void) const { return m_page_size; } ZhuyinScheme keyboardLayout (void) const { return m_keyboard_layout; } gboolean initChinese (void) const { return m_init_chinese; } gboolean initFullEnglish (void) const { return m_init_full_english; } gboolean initFullPunct (void) const { return m_init_full_punct; } gboolean initTradChinese (void) const { return m_init_trad_chinese; } gboolean alwaysInputNumbers (void) const { return m_always_input_numbers; } std::string candidateKeys (void) const { return m_candidate_keys; } gboolean easySymbol (void) const { return m_easy_symbol; } gboolean userSymbol (void) const { return m_user_symbol; } protected: bool read (const gchar * name, bool defval); gint read (const gchar * name, gint defval); std::string read (const gchar * name, const gchar * defval); void initDefaultValues (void); virtual void readDefaultValues (void); virtual gboolean valueChanged (const std::string §ion, const std::string &name, GVariant *value); private: static void valueChangedCallback (IBusConfig *config, const gchar *section, const gchar *name, GVariant *value, Config *self); protected: std::string m_section; zhuyin_option_t m_option; zhuyin_option_t m_option_mask; gint m_orientation; guint m_page_size; ZhuyinScheme m_keyboard_layout; gboolean m_init_chinese; gboolean m_init_full_english; gboolean m_init_full_punct; gboolean m_init_trad_chinese; gboolean m_always_input_numbers; std::string m_candidate_keys; gboolean m_easy_symbol; gboolean m_user_symbol; }; static inline bool normalizeGVariant (GVariant *value, bool defval) { if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_BOOLEAN) return defval; return g_variant_get_boolean (value); } static inline gint normalizeGVariant (GVariant *value, gint defval) { if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_INT32) return defval; return g_variant_get_int32 (value); } static inline std::string normalizeGVariant (GVariant *value, const std::string &defval) { if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_STRING) return defval; return g_variant_get_string (value, NULL); } }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYEditor.cc000066400000000000000000000065021241117270600203210ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYText.h" #include "ZYEditor.h" namespace ZY { Editor::Editor (ZhuyinProperties & props, Config & config) : m_cursor (0), m_props (props), m_config (config) { } Editor::~Editor (void) { } gboolean Editor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { modifiers &= (IBUS_CONTROL_MASK | IBUS_MOD1_MASK | IBUS_SUPER_MASK | IBUS_HYPER_MASK | IBUS_META_MASK); /* ignore key events with some masks */ if (modifiers != 0) return TRUE; if (keyval >= IBUS_exclam && keyval <= IBUS_asciitilde) { /* char key */ m_text.insert (m_cursor++, keyval); update (); return TRUE; } else { /* control key */ if (!m_text) return FALSE; } switch (keyval) { case IBUS_BackSpace: if (m_cursor > 0) { m_text.erase (--m_cursor, 1); update (); } return TRUE; case IBUS_Delete: case IBUS_KP_Delete: if (m_cursor < m_text.length ()) { m_text.erase (m_cursor, 1); update (); } return TRUE; case IBUS_Left: case IBUS_KP_Left: if (!m_text) return FALSE; if (m_cursor > 0) { m_cursor --; update (); } return TRUE; case IBUS_Right: case IBUS_KP_Right: if (m_cursor < m_text.length ()) { m_cursor ++; update (); } return TRUE; case IBUS_space: case IBUS_Return: case IBUS_KP_Enter: { StaticText text (m_text); commitText (text); reset (); } return TRUE; case IBUS_Escape: reset (); return TRUE; default: return TRUE; } } void Editor::reset (void) { gboolean need_update = (m_cursor != 0 || !m_text.empty ()); m_cursor = 0; m_text = ""; if (need_update) update (); } void Editor::pageUp (void) { } void Editor::pageDown (void) { } void Editor::cursorUp (void) { } void Editor::cursorDown (void) { } void Editor::candidateClicked (guint index, guint button, guint state) { } void Editor::update (void) { if (m_text) { StaticText text (m_text); text.appendAttribute (IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1); updatePreeditText (text, m_cursor, TRUE); } else { hidePreeditText (); } } }; ibus-libzhuyin-1.6.99.20140929/src/ZYEditor.h000066400000000000000000000121621241117270600201620ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_EDITOR_H_ #define __ZY_EDITOR_H_ #include #include "ZYSignal.h" #include "ZYString.h" #include "ZYUtil.h" namespace ZY { class Text; class LookupTable; class ZhuyinProperties; class Config; class Editor; typedef std::shared_ptr EditorPtr; class Editor { public: Editor (ZhuyinProperties & prop, Config & config); virtual ~Editor (void); virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void pageUp (void); virtual void pageDown (void); virtual void cursorUp (void); virtual void cursorDown (void); virtual void update (void); virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); const String & text (void) const { return m_text; } void setText (const String & text, guint cursor) { m_text = text; m_cursor = cursor; } /* signals */ signal & signalCommitText (void) { return m_signal_commit_text; } signal & signalUpdatePreeditText (void) { return m_signal_update_preedit_text; } signal & signalShowPreeditText (void) { return m_signal_show_preedit_text; } signal & signalHidePreeditText (void) { return m_signal_hide_preedit_text; } signal & signalUpdateAuxiliaryText (void) { return m_signal_update_auxiliary_text; } signal & signalShowAuxiliaryText (void) { return m_signal_show_auxiliary_text; } signal & signalHideAuxiliaryText (void) { return m_signal_hide_auxiliary_text; } signal & signalUpdateLookupTable (void) { return m_signal_update_lookup_table; } signal & signalUpdateLookupTableFast (void) { return m_signal_update_lookup_table_fast; } signal & signalShowLookupTable (void) { return m_signal_show_lookup_table; } signal & signalHideLookupTable (void) { return m_signal_hide_lookup_table; } protected: /* methods */ void commitText (Text & text) const { m_signal_commit_text (text); } void updatePreeditText (Text & text, guint cursor, gboolean visible) const { m_signal_update_preedit_text (text, cursor, visible); } void showPreeditText (void) const { m_signal_show_preedit_text (); } void hidePreeditText (void) const { m_signal_hide_preedit_text (); } void updateAuxiliaryText (Text & text, gboolean visible) const { m_signal_update_auxiliary_text (text, visible); } void showAuxiliaryText (void) const { m_signal_show_auxiliary_text (); } void hideAuxiliaryText (void) const { m_signal_hide_auxiliary_text (); } void updateLookupTable (LookupTable & table, gboolean visible) const { m_signal_update_lookup_table (table, visible); } void updateLookupTableFast (LookupTable & table, gboolean visible) const { m_signal_update_lookup_table_fast (table, visible); } void showLookupTable (void) const { m_signal_show_lookup_table (); } void hideLookupTable (void) const { m_signal_hide_lookup_table (); } protected: /* signals */ signal m_signal_commit_text; signal m_signal_update_preedit_text; signal m_signal_show_preedit_text; signal m_signal_hide_preedit_text; signal m_signal_update_auxiliary_text; signal m_signal_show_auxiliary_text; signal m_signal_hide_auxiliary_text; signal m_signal_update_lookup_table; signal m_signal_update_lookup_table_fast; signal m_signal_show_lookup_table; signal m_signal_hide_lookup_table; protected: String m_text; guint m_cursor; ZhuyinProperties & m_props; Config & m_config; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYEngine.cc000066400000000000000000000255651241117270600203120ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "ZYEngine.h" #include "ZYZZhuyinEngine.h" namespace ZY { /* code of engine class of GObject */ #define IBUS_ZHUYIN_ENGINE(obj) \ (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_ZHUYIN_ENGINE, IBusZhuyinEngine)) #define IBUS_ZHUYIN_ENGINE_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_ZHUYIN_ENGINE, IBusZhuyinEngineClass)) #define IBUS_IS_ZHUYIN_ENGINE(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_ZHUYIN_ENGINE)) #define IBUS_IS_ZHUYIN_ENGINE_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_ZHUYIN_ENGINE)) #define IBUS_ZHUYIN_ENGINE_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_ZHUYIN_ENGINE, IBusZhuyinEngineClass)) typedef struct _IBusZhuyinEngine IBusZhuyinEngine; typedef struct _IBusZhuyinEngineClass IBusZhuyinEngineClass; struct _IBusZhuyinEngine { IBusEngine parent; /* members */ Engine *engine; }; struct _IBusZhuyinEngineClass { IBusEngineClass parent; }; /* functions prototype */ static void ibus_zhuyin_engine_class_init (IBusZhuyinEngineClass *klass); static void ibus_zhuyin_engine_init (IBusZhuyinEngine *zhuyin); static GObject* ibus_zhuyin_engine_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params); static void ibus_zhuyin_engine_destroy (IBusZhuyinEngine *zhuyin); static gboolean ibus_zhuyin_engine_process_key_event (IBusEngine *engine, guint keyval, guint keycode, guint modifiers); static void ibus_zhuyin_engine_focus_in (IBusEngine *engine); static void ibus_zhuyin_engine_focus_out (IBusEngine *engine); #if IBUS_CHECK_VERSION (1, 5, 4) static void ibus_zhuyin_engine_set_content_type (IBusEngine *engine, guint purpose, guint hints); #endif static void ibus_zhuyin_engine_reset (IBusEngine *engine); static void ibus_zhuyin_engine_enable (IBusEngine *engine); static void ibus_zhuyin_engine_disable (IBusEngine *engine); #if 0 static void ibus_engine_set_cursor_location (IBusEngine *engine, gint x, gint y, gint w, gint h); static void ibus_zhuyin_engine_set_capabilities (IBusEngine *engine, guint caps); #endif static void ibus_zhuyin_engine_page_up (IBusEngine *engine); static void ibus_zhuyin_engine_page_down (IBusEngine *engine); static void ibus_zhuyin_engine_cursor_up (IBusEngine *engine); static void ibus_zhuyin_engine_cursor_down (IBusEngine *engine); static void ibus_zhuyin_engine_property_activate (IBusEngine *engine, const gchar *prop_name, guint prop_state); static void ibus_zhuyin_engine_candidate_clicked (IBusEngine *engine, guint index, guint button, guint state); #if 0 static void ibus_zhuyin_engine_property_show (IBusEngine *engine, const gchar *prop_name); static void ibus_zhuyin_engine_property_hide (IBusEngine *engine, const gchar *prop_name); #endif G_DEFINE_TYPE (IBusZhuyinEngine, ibus_zhuyin_engine, IBUS_TYPE_ENGINE) static void ibus_zhuyin_engine_class_init (IBusZhuyinEngineClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); IBusEngineClass *engine_class = IBUS_ENGINE_CLASS (klass); object_class->constructor = ibus_zhuyin_engine_constructor; ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_zhuyin_engine_destroy; engine_class->process_key_event = ibus_zhuyin_engine_process_key_event; engine_class->reset = ibus_zhuyin_engine_reset; engine_class->enable = ibus_zhuyin_engine_enable; engine_class->disable = ibus_zhuyin_engine_disable; engine_class->focus_in = ibus_zhuyin_engine_focus_in; engine_class->focus_out = ibus_zhuyin_engine_focus_out; #if IBUS_CHECK_VERSION (1, 5, 4) engine_class->set_content_type = ibus_zhuyin_engine_set_content_type; #endif engine_class->page_up = ibus_zhuyin_engine_page_up; engine_class->page_down = ibus_zhuyin_engine_page_down; engine_class->cursor_up = ibus_zhuyin_engine_cursor_up; engine_class->cursor_down = ibus_zhuyin_engine_cursor_down; engine_class->property_activate = ibus_zhuyin_engine_property_activate; engine_class->candidate_clicked = ibus_zhuyin_engine_candidate_clicked; } static void ibus_zhuyin_engine_init (IBusZhuyinEngine *zhuyin) { if (g_object_is_floating (zhuyin)) g_object_ref_sink (zhuyin); // make engine sink } static GObject* ibus_zhuyin_engine_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { IBusZhuyinEngine *engine; const gchar *name; engine = (IBusZhuyinEngine *) G_OBJECT_CLASS (ibus_zhuyin_engine_parent_class)->constructor ( type, n_construct_params, construct_params); name = ibus_engine_get_name ((IBusEngine *) engine); if (name) { if (std::strcmp (name, "libzhuyin") == 0 || std::strcmp (name, "libzhuyin-debug") == 0) { engine->engine = new ZhuyinEngine (IBUS_ENGINE (engine)); } } else { engine->engine = new ZhuyinEngine (IBUS_ENGINE (engine)); } return (GObject *) engine; } static void ibus_zhuyin_engine_destroy (IBusZhuyinEngine *zhuyin) { delete zhuyin->engine; ((IBusObjectClass *) ibus_zhuyin_engine_parent_class)->destroy ((IBusObject *)zhuyin); } static gboolean ibus_zhuyin_engine_process_key_event (IBusEngine *engine, guint keyval, guint keycode, guint modifiers) { IBusZhuyinEngine *zhuyin = (IBusZhuyinEngine *) engine; return zhuyin->engine->processKeyEvent (keyval, keycode, modifiers); } #if IBUS_CHECK_VERSION (1, 5, 4) static void ibus_zhuyin_engine_set_content_type (IBusEngine *engine, guint purpose, guint hints) { IBusZhuyinEngine *zhuyin = (IBusZhuyinEngine *) engine; return zhuyin->engine->setContentType (purpose, hints); } #endif static void ibus_zhuyin_engine_property_activate (IBusEngine *engine, const gchar *prop_name, guint prop_state) { IBusZhuyinEngine *zhuyin = (IBusZhuyinEngine *) engine; zhuyin->engine->propertyActivate (prop_name, prop_state); } static void ibus_zhuyin_engine_candidate_clicked (IBusEngine *engine, guint index, guint button, guint state) { IBusZhuyinEngine *zhuyin = (IBusZhuyinEngine *) engine; zhuyin->engine->candidateClicked (index, button, state); } #define FUNCTION(name, Name) \ static void \ ibus_zhuyin_engine_##name (IBusEngine *engine) \ { \ IBusZhuyinEngine *zhuyin = (IBusZhuyinEngine *) engine; \ zhuyin->engine->Name (); \ ((IBusEngineClass *) ibus_zhuyin_engine_parent_class) \ ->name (engine); \ } FUNCTION(focus_in, focusIn) FUNCTION(focus_out, focusOut) FUNCTION(reset, reset) FUNCTION(enable, enable) FUNCTION(disable, disable) FUNCTION(page_up, pageUp) FUNCTION(page_down, pageDown) FUNCTION(cursor_up, cursorUp) FUNCTION(cursor_down, cursorDown) #undef FUNCTION Engine::Engine (IBusEngine *engine) : m_engine (engine) { #if IBUS_CHECK_VERSION (1, 5, 4) m_input_purpose = IBUS_INPUT_PURPOSE_FREE_FORM; #endif } gboolean Engine::contentIsPassword() { #if IBUS_CHECK_VERSION (1, 5, 4) return IBUS_INPUT_PURPOSE_PASSWORD == m_input_purpose; #else return FALSE; #endif } void Engine::focusOut (void) { #if IBUS_CHECK_VERSION (1, 5, 4) m_input_purpose = IBUS_INPUT_PURPOSE_FREE_FORM; #endif } #if IBUS_CHECK_VERSION(1, 5, 4) void Engine::setContentType (guint purpose, guint hints) { m_input_purpose = (IBusInputPurpose) purpose; } #endif Engine::~Engine (void) { } }; ibus-libzhuyin-1.6.99.20140929/src/ZYEngine.h000066400000000000000000000072711241117270600201460ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_ENGINE_H_ #define __ZY_ENGINE_H_ #include #include "ZYPointer.h" #include "ZYLookupTable.h" #include "ZYProperty.h" #include "ZYEditor.h" namespace ZY { #define IBUS_TYPE_ZHUYIN_ENGINE \ (ZY::ibus_zhuyin_engine_get_type ()) GType ibus_zhuyin_engine_get_type (void); class Engine { public: Engine (IBusEngine *engine); virtual ~Engine (void); gboolean contentIsPassword(); // virtual functions virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers) = 0; virtual void focusIn (void) = 0; virtual void focusOut (void); #if IBUS_CHECK_VERSION (1, 5, 4) virtual void setContentType (guint purpose, guint hints); #endif virtual void reset (void) = 0; virtual void enable (void) = 0; virtual void disable (void) = 0; virtual void pageUp (void) = 0; virtual void pageDown (void) = 0; virtual void cursorUp (void) = 0; virtual void cursorDown (void) = 0; virtual gboolean propertyActivate (const gchar *prop_name, guint prop_state) = 0; virtual void candidateClicked (guint index, guint button, guint state) = 0; protected: void commitText (Text & text) const { ibus_engine_commit_text (m_engine, text); } void updatePreeditText (Text & text, guint cursor, gboolean visible) const { ibus_engine_update_preedit_text (m_engine, text, cursor, visible); } void showPreeditText (void) const { ibus_engine_show_preedit_text (m_engine); } void hidePreeditText (void) const { ibus_engine_hide_preedit_text (m_engine); } void updateAuxiliaryText (Text & text, gboolean visible) const { ibus_engine_update_auxiliary_text (m_engine, text, visible); } void showAuxiliaryText (void) const { ibus_engine_show_auxiliary_text (m_engine); } void hideAuxiliaryText (void) const { ibus_engine_hide_auxiliary_text (m_engine); } void updateLookupTable (LookupTable &table, gboolean visible) const { ibus_engine_update_lookup_table (m_engine, table, visible); } void updateLookupTableFast (LookupTable &table, gboolean visible) const { ibus_engine_update_lookup_table_fast (m_engine, table, visible); } void showLookupTable (void) const { ibus_engine_show_lookup_table (m_engine); } void hideLookupTable (void) const { ibus_engine_hide_lookup_table (m_engine); } void registerProperties (PropList & props) const { ibus_engine_register_properties (m_engine, props); } void updateProperty (Property & prop) const { ibus_engine_update_property (m_engine, prop); } protected: Pointer m_engine; // engine pointer #if IBUS_CHECK_VERSION (1, 5, 4) IBusInputPurpose m_input_purpose; #endif }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYEnhancedText.cc000066400000000000000000000233131241117270600214440ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYEnhancedText.h" #include namespace ZY{ const char symbol_lead_char = '`'; const int symbol_parts_num = 3; typedef String::const_iterator iterator_t; #if 0 /* template method, to be moved to PhoneticEditor class. */ bool isPhonetic (const char key) { /* use zhuyin_in_chewing_keyboard here. */ return PHONETIC_SECTION; } #endif String escape_brace (const String & text) { String braced_text = "{"; iterator_t iter; for (iter = text.begin (); iter != text.end (); ++iter) { braced_text += *iter; if ('{' == *iter || '}' == *iter) { braced_text += *iter; } } braced_text += "}"; return braced_text; } String get_next_brace(const String & enhanced_text, size_t start_pos, size_t & end_pos) { String text; iterator_t iter = enhanced_text.begin () + start_pos; /* eat the first '{'. */ assert ('{' == *iter); ++iter; for (; iter != enhanced_text.end (); ++iter ) { switch(*iter) { case '{': ++iter; /* eat the next '{'. */ assert ('{' == *iter); text += *iter; break; case '}': ++iter; if ('}' == *iter) { text += *iter; } else { /* exit loop here. */ end_pos = iter - enhanced_text.begin (); return text; } break; default: text += *iter; break; } } /* can't reach the end, will end at the last '}'. */ assert(iter != enhanced_text.end ()); return text; } /* implementation */ size_t get_enhanced_text_length (const String & enhanced_text) { size_t length = 0; size_t start_pos = 0, end_pos = 0; iterator_t iter; for (iter = enhanced_text.begin (); iter != enhanced_text.end ();) { /* handle symbol section. */ if (symbol_lead_char == *iter) { ++iter; start_pos = iter - enhanced_text.begin (); /* eat 3 braces. */ for (int i = 0; i < symbol_parts_num; ++i) { get_next_brace (enhanced_text, start_pos, end_pos); start_pos = end_pos; } iter = enhanced_text.begin () + start_pos; ++length; continue; } /* only phonetic character allows here. */ /* assert(PHONETIC_SECTION == isPhonetic(*iter)); */ ++iter; ++length; } return length; } section_t probe_section (const String & enhanced_text, size_t offset, size_t & pos) { size_t start_pos = 0, end_pos = 0; /* loop from start to offset. */ iterator_t iter; for (iter = enhanced_text.begin (); iter != enhanced_text.end (); ) { /* only one character left. */ if (0 == offset) break; /* Note: some duplicated code here... */ /* handle symbol section. */ if (symbol_lead_char == *iter) { ++iter; start_pos = iter - enhanced_text.begin (); /* eat 3 braces. */ for (int i = 0; i < symbol_parts_num; ++i) { get_next_brace (enhanced_text, start_pos, end_pos); start_pos = end_pos; } iter = enhanced_text.begin () + start_pos; --offset; continue; } /* only phonetic character allows here. */ /* assert(PHONETIC_SECTION == isPhonetic(*iter)); */ ++iter; --offset; } pos = iter - enhanced_text.begin (); if (symbol_lead_char == *iter) return SYMBOL_SECTION; else return PHONETIC_SECTION; } section_t probe_section_quick (const String & enhanced_text, size_t pos) { iterator_t iter = enhanced_text.begin () + pos; if (symbol_lead_char == *iter) return SYMBOL_SECTION; else return PHONETIC_SECTION; } bool get_phonetic_section (const String & enhanced_text, size_t start_pos, size_t & end_pos, String & section) { section.clear(); iterator_t iter = enhanced_text.begin () + start_pos; /* safe check here. */ if (symbol_lead_char == *iter) return false; /* gather consecutive characters. */ for (; iter != enhanced_text.end (); ++iter) { if (symbol_lead_char == *iter) break; /* assert(PHONETIC_SECTION == isPhonetic(*iter)); */ section += *iter; } end_pos = iter - enhanced_text.begin (); return true; } bool get_symbol_section (const String & enhanced_text, size_t start_pos, size_t & end_pos, String & type, String & lookup, String & choice) { iterator_t iter = enhanced_text.begin () + start_pos; if (symbol_lead_char != *iter) return false; assert (symbol_lead_char == *iter); ++iter; /* eat the type. */ start_pos = iter - enhanced_text.begin (); type = get_next_brace (enhanced_text, start_pos, end_pos); start_pos = end_pos; /* eat the lookup. */ lookup = get_next_brace (enhanced_text, start_pos, end_pos); start_pos = end_pos; /* eat the choice. */ choice = get_next_brace (enhanced_text, start_pos, end_pos); start_pos = end_pos; return true; } bool probe_section_start(const String & enhanced_text, guint offset, guint & inner_offset, size_t & index, size_t & start_pos) { /* decrement the cursor variable to calculate the zhuyin cursor. */ guint cursor = offset; inner_offset = 0; index = 0; start_pos = 0; size_t end_pos = 0; while (end_pos != enhanced_text.size ()) { if (0 == cursor) break; start_pos = end_pos; section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); size_t section_len = end_pos - start_pos; if (cursor < section_len) break; cursor -= section_len; if (0 == cursor) { start_pos = end_pos; break; } ++index; } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); --cursor; } } inner_offset = cursor; return true; } bool insert_section (String & enhanced_text, size_t offset, const String & section) { size_t pos = 0; section_t section_type = probe_section (enhanced_text, offset, pos); enhanced_text = enhanced_text.substr (0, pos) + section + enhanced_text.substr (pos); return true; } bool insert_phonetic(String & enhanced_text, size_t offset, const char key) { String section; section += key; return insert_section(enhanced_text, offset, section); } bool insert_symbol(String & enhanced_text, size_t offset, const String & type, const String & lookup, const String & choice) { String section; section += symbol_lead_char; section += escape_brace (type) + escape_brace (lookup) + escape_brace(choice); return insert_section(enhanced_text, offset, section); } bool erase_input_sequence(String & enhanced_text, size_t offset, size_t length) { size_t pos = 0, start_pos = 0, end_pos = 0; section_t section_type = probe_section(enhanced_text, offset, pos); start_pos = pos; end_pos = pos; for (size_t i = 0; i < length; ++i) { switch (section_type) { case PHONETIC_SECTION: ++ end_pos; break; case SYMBOL_SECTION: { String type, lookup, choice; assert (get_symbol_section (enhanced_text, pos, end_pos, type, lookup, choice)); } break; } pos = end_pos; /* reach the end of the enhanced text. */ if (enhanced_text.length () == pos) break; section_type = probe_section_quick (enhanced_text, pos); } enhanced_text.erase (start_pos, end_pos - start_pos); return true; } size_t get_number_of_phonetic_sections (String & enhanced_text) { size_t num = 0; size_t start_pos = 0, end_pos = 0; while (end_pos != enhanced_text.size ()) { section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); ++num; } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); } start_pos = end_pos; } return num; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYEnhancedText.h000066400000000000000000000044471241117270600213150ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_ENHANCED_TEXT_H_ #define __ZY_ENHANCED_TEXT_H_ #include "ZYString.h" namespace ZY{ typedef enum { PHONETIC_SECTION, SYMBOL_SECTION } section_t; /* all enhanced text should loop from the start to get the correct position. */ size_t get_enhanced_text_length (const String & enhanced_text); /* offset is for the input offset, pos is for the actual position in enhanced text. */ section_t probe_section (const String & enhanced_text, size_t offset, size_t & pos); section_t probe_section_quick (const String & enhanced_text, size_t pos); bool get_phonetic_section (const String & enhanced_text, size_t start_pos, size_t & end_pos, String & section); /* only one input character here. */ bool get_symbol_section (const String & enhanced_text, size_t start_pos, size_t & end_pos, String & type, String & lookup, String & choice); bool probe_section_start(const String & enhanced_text, guint offset, guint & inner_offset, size_t & index, size_t & start_pos); bool insert_phonetic(String & enhanced_text, size_t offset, const char key); bool insert_symbol(String & enhanced_text, size_t offset, const String & type, const String & lookup, const String & choice); bool erase_input_sequence(String & enhanced_text, size_t offset, size_t length); size_t get_number_of_phonetic_sections (String & enhanced_text); }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYFallbackEditor.cc000066400000000000000000000115231241117270600217400ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYFallbackEditor.h" #include #include "ZYSymbols.h" #include "ZYZhuyinProperties.h" namespace ZY { inline gboolean FallbackEditor::processPunct (guint keyval, guint keycode, guint modifiers) { guint cmshm_modifiers = cmshm_filter (modifiers); if (G_UNLIKELY (keyval == IBUS_period && cmshm_modifiers == IBUS_CONTROL_MASK)) { m_props.toggleModeFullPunct (); return TRUE; } /* check ctrl, alt, hyper, supper masks */ if (cmshm_modifiers != 0) return FALSE; /* English mode */ if (!m_props.modeChinese ()) { /* Punctuation character */ if (is_half_punct (keyval)) { if (G_UNLIKELY (m_props.modeFullPunct ())) { String punct; half_punct_to_full_punct (keyval, punct); commit (punct); } else { commit (keyval); } return TRUE; } } else { /* Chinese mode, handled by ZhuyinEditor or PinyinEditor. */ return TRUE; } return FALSE; } inline gboolean FallbackEditor::processEnglish (guint keyval, guint keycode, guint modifiers) { guint cmshm_modifiers = cmshm_filter (modifiers); /* check ctrl, alt, hyper, supper masks */ if (cmshm_modifiers != 0) return FALSE; /* English mode */ if (!m_props.modeChinese ()) { /* English character */ if (is_half_english (keyval)) { if (G_UNLIKELY (m_props.modeFullEnglish ())) { String english; half_english_to_full_english (keyval, english); commit (english); } else { commit (keyval); } return TRUE; } } else { /* Chinese mode, handled by ZhuyinEditor or PinyinEditor. */ return TRUE; } return FALSE; } gboolean FallbackEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { gboolean retval = FALSE; modifiers &= (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK | IBUS_SUPER_MASK | IBUS_HYPER_MASK | IBUS_META_MASK); switch (keyval) { /* numbers */ case IBUS_KP_0 ... IBUS_KP_9: keyval = keyval - IBUS_KP_0 + IBUS_0; case IBUS_0 ... IBUS_9: /* letters */ case IBUS_a ... IBUS_z: case IBUS_A ... IBUS_Z: if (modifiers == 0) { retval = processEnglish (keyval, keycode, modifiers); } break; /* punct */ case IBUS_exclam ... IBUS_slash: case IBUS_colon ... IBUS_at: case IBUS_bracketleft ... IBUS_quoteleft: case IBUS_braceleft ... IBUS_asciitilde: retval = processPunct (keyval, keycode, modifiers); break; case IBUS_KP_Equal: retval = processPunct ('=', keycode, modifiers); break; case IBUS_KP_Multiply: retval = processPunct ('*', keycode, modifiers); break; case IBUS_KP_Add: retval = processPunct ('+', keycode, modifiers); break; #if 0 case IBUS_KP_Separator: retval = processPunct (IBUS_separator, keycode, modifiers); break; #endif case IBUS_KP_Subtract: retval = processPunct ('-', keycode, modifiers); break; case IBUS_KP_Decimal: retval = processPunct ('.', keycode, modifiers); break; case IBUS_KP_Divide: retval = processPunct ('/', keycode, modifiers); break; /* space */ case IBUS_KP_Space: keyval = IBUS_space; case IBUS_space: retval = processEnglish (keyval, keycode, modifiers); break; /* others */ default: break; } return retval; } void FallbackEditor::reset (void) { m_quote = TRUE; m_double_quote = TRUE; m_prev_committed_char = 0; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYFallbackEditor.h000066400000000000000000000041111241117270600215750ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_FALLBACK_EDITOR_ #define __ZY_FALLBACK_EDITOR_ #include "ZYText.h" #include "ZYEditor.h" namespace ZY { class FallbackEditor : public Editor { public: FallbackEditor (ZhuyinProperties &props, Config & config) : Editor (props, config), m_quote (TRUE), m_double_quote (TRUE), m_prev_committed_char (0) { } gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); void reset (void); void setPrevCommittedChar (gunichar ch) { m_prev_committed_char = ch; } private: void commit (gchar ch) { gchar str[2] = {ch, 0}; StaticText text (str); commitText (text); } void commit (gunichar ch) { Text text (ch); commitText (text); } void commit (const gchar *str) { StaticText text (str); commitText (text); } void commit (const String &str) { commit ((const gchar *)str); } gboolean processPunct (guint keyval, guint keycode, guint modifiers); gboolean processEnglish (guint keyval, guint keycode, guint modifiers); private: gboolean m_quote; gboolean m_double_quote; gunichar m_prev_committed_char; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYLibZhuyin.cc000066400000000000000000000134331241117270600210110ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYLibZhuyin.h" #include #include #include #include "ZYZConfig.h" #define LIBZHUYIN_SAVE_TIMEOUT (5 * 60) namespace ZY { std::unique_ptr LibZhuyinBackEnd::m_instance; static LibZhuyinBackEnd libzhuyin_backend; LibZhuyinBackEnd::LibZhuyinBackEnd () { m_timeout_id = 0; m_timer = g_timer_new (); m_zhuyin_context = NULL; } LibZhuyinBackEnd::~LibZhuyinBackEnd () { g_timer_destroy (m_timer); if (m_timeout_id != 0) { saveUserDB (); g_source_remove (m_timeout_id); } if (m_zhuyin_context) zhuyin_fini (m_zhuyin_context); m_zhuyin_context = NULL; } zhuyin_context_t * LibZhuyinBackEnd::initZhuyinContext (Config *config) { zhuyin_context_t * context = NULL; gchar * userdir = g_build_filename (g_get_user_cache_dir (), "ibus", "libzhuyin", NULL); int retval = g_mkdir_with_parents (userdir, 0700); if (retval) { g_free (userdir); userdir = NULL; } context = zhuyin_init (LIBZHUYIN_DATADIR, userdir); g_free (userdir); /* load user phrase library. */ zhuyin_load_phrase_library (context, USER_DICTIONARY); return context; } gboolean LibZhuyinBackEnd::setZhuyinOptions (Config *config) { if (NULL == m_zhuyin_context) return FALSE; ZhuyinScheme scheme = config->keyboardLayout (); switch (scheme) { case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: zhuyin_set_chewing_scheme (m_zhuyin_context, scheme); break; case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: zhuyin_set_full_pinyin_scheme (m_zhuyin_context, scheme); break; default: assert (FALSE); } zhuyin_option_t options = config->option (); zhuyin_set_options (m_zhuyin_context, options); return TRUE; } zhuyin_instance_t * LibZhuyinBackEnd::allocZhuyinInstance () { Config * config = &ZhuyinConfig::instance (); if (NULL == m_zhuyin_context) { m_zhuyin_context = initZhuyinContext (config); } setZhuyinOptions (config); return zhuyin_alloc_instance (m_zhuyin_context); } void LibZhuyinBackEnd::freeZhuyinInstance (zhuyin_instance_t *instance) { if (instance) zhuyin_free_instance (instance); } void LibZhuyinBackEnd::init (void) { g_assert (NULL == m_instance.get ()); LibZhuyinBackEnd * backend = new LibZhuyinBackEnd; m_instance.reset (backend); } void LibZhuyinBackEnd::finalize (void) { m_instance.reset (); } gboolean LibZhuyinBackEnd::saveUserDB (void) { if (m_zhuyin_context) zhuyin_save (m_zhuyin_context); return TRUE; } void LibZhuyinBackEnd::modified (void) { /* Restart the timer */ g_timer_start (m_timer); if (m_timeout_id != 0) return; m_timeout_id = g_timeout_add_seconds (LIBZHUYIN_SAVE_TIMEOUT, LibZhuyinBackEnd::timeoutCallback, static_cast (this)); } gboolean LibZhuyinBackEnd::importZhuyinDictionary (const char * filename) { /* user phrase library should be already loaded here. */ FILE * dictfile = fopen (filename, "r"); if (NULL == dictfile) return FALSE; import_iterator_t * iter = zhuyin_begin_add_phrases (m_zhuyin_context, USER_DICTIONARY); if (NULL == iter) return FALSE; char* linebuf = NULL; size_t size = 0; ssize_t read; while ((read = getline (&linebuf, &size, dictfile)) != -1) { if (0 == strlen (linebuf)) continue; if ( '\n' == linebuf[strlen (linebuf) - 1] ) { linebuf[strlen (linebuf) - 1] = '\0'; } gchar ** items = g_strsplit_set (linebuf, " \t", 2); guint len = g_strv_length (items); if (2 != len) continue; gchar * phrase = items[0]; gchar * zhuyin = items[1]; zhuyin_iterator_add_phrase (iter, phrase, zhuyin, -1); g_strfreev (items); } zhuyin_end_add_phrases (iter); fclose (dictfile); zhuyin_save (m_zhuyin_context); return TRUE; } gboolean LibZhuyinBackEnd::clearZhuyinUserData (const char * target) { if (0 == strcmp ("all", target)) zhuyin_mask_out (m_zhuyin_context, 0x0, 0x0); else if (0 == strcmp ("user", target)) zhuyin_mask_out (m_zhuyin_context, PHRASE_INDEX_LIBRARY_MASK, PHRASE_INDEX_MAKE_TOKEN (USER_DICTIONARY, null_token)); else g_warning ("unknown clear target: %s.\n", target); zhuyin_save (m_zhuyin_context); return TRUE; } gboolean LibZhuyinBackEnd::timeoutCallback (gpointer data) { LibZhuyinBackEnd *self = static_cast(data); /* Get the elapsed time since last modification of database. */ guint elapsed = (guint)g_timer_elapsed (self->m_timer, NULL); if (elapsed >= LIBZHUYIN_SAVE_TIMEOUT && self->saveUserDB ()) { self->m_timeout_id = 0; return FALSE; } return TRUE; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYLibZhuyin.h000066400000000000000000000037451241117270600206600ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_H_ #define __ZY_LIB_ZHUYIN_H_ #include #include typedef struct _zhuyin_context_t zhuyin_context_t; typedef struct _zhuyin_instance_t zhuyin_instance_t; namespace ZY { class Config; class LibZhuyinBackEnd { public: LibZhuyinBackEnd (); virtual ~LibZhuyinBackEnd (); gboolean setZhuyinOptions (Config *config); zhuyin_context_t * initZhuyinContext (Config *config); zhuyin_instance_t *allocZhuyinInstance (); void freeZhuyinInstance (zhuyin_instance_t *instance); void modified (void); gboolean importZhuyinDictionary (const char * filename); gboolean clearZhuyinUserData (const char * target); /* use static initializer in C++. */ static LibZhuyinBackEnd & instance (void) { return *m_instance; } static void init (void); static void finalize (void); private: gboolean saveUserDB (void); static gboolean timeoutCallback (gpointer data); private: /* libzhuyin context */ zhuyin_context_t *m_zhuyin_context; guint m_timeout_id; GTimer *m_timer; private: static std::unique_ptr m_instance; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYLookupTable.h000066400000000000000000000056261241117270600211640ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LOOKUP_TABLE_H_ #define __ZY_LOOKUP_TABLE_H_ #include #include "ZYObject.h" #include "ZYText.h" namespace ZY { class LookupTable : Object { public: LookupTable (guint page_size = 10, guint cursor_pos = 0, gboolean cursor_visible = TRUE, gboolean round = FALSE) : Object (ibus_lookup_table_new (page_size, cursor_pos, cursor_visible, round)) { } guint pageSize (void) { return ibus_lookup_table_get_page_size (*this); } guint orientation (void) { return ibus_lookup_table_get_orientation (*this); } guint cursorPos (void) { return ibus_lookup_table_get_cursor_pos (*this); } guint size (void) { return ibus_lookup_table_get_number_of_candidates (*this); } gboolean pageUp (void) { return ibus_lookup_table_page_up (*this); } gboolean pageDown (void) { return ibus_lookup_table_page_down (*this); } gboolean cursorUp (void) { return ibus_lookup_table_cursor_up (*this); } gboolean cursorDown (void) { return ibus_lookup_table_cursor_down (*this); } void setPageSize (guint size) { ibus_lookup_table_set_page_size (*this, size); } void setCursorPos (guint pos) { ibus_lookup_table_set_cursor_pos (*this, pos); } void setOrientation (gint orientation) { ibus_lookup_table_set_orientation (*this, orientation); } void clear (void) { ibus_lookup_table_clear (*this); } void setCursorVisable (gboolean visable){ ibus_lookup_table_set_cursor_visible (*this, visable); } void setLabel (guint index, IBusText *text) { ibus_lookup_table_set_label (*this, index, text); } void appendCandidate (IBusText *text) { ibus_lookup_table_append_candidate (*this, text); } void appendLabel (IBusText *text) { ibus_lookup_table_append_label (*this, text); } IBusText * getCandidate(guint index) { return ibus_lookup_table_get_candidate(*this, index); } operator IBusLookupTable * (void) const { return get (); } }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYMain.cc000066400000000000000000000115511241117270600177570ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include "ZYEngine.h" #include "ZYPointer.h" #include "ZYBus.h" #include "ZYConfig.h" #include "ZYZConfig.h" #include "ZYLibZhuyin.h" using namespace ZY; #define N_(text) text static Pointer factory; /* options */ static gboolean ibus = FALSE; static gboolean verbose = FALSE; static void show_version_and_quit (void) { g_print ("%s - Version %s\n", g_get_application_name (), VERSION); exit (EXIT_SUCCESS); } static const GOptionEntry entries[] = { { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) show_version_and_quit, "Show the application's version.", NULL }, { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL }, { NULL }, }; static void ibus_disconnected_cb (IBusBus *bus, gpointer user_data) { g_debug ("bus disconnected"); ibus_quit (); } static void start_component (void) { Pointer component; ibus_init (); Bus bus; if (!bus.isConnected ()) { g_warning ("Can not connect to ibus!"); exit (0); } if (!ibus_bus_get_config (bus)) { g_warning ("IBus config component is not ready!"); exit (0); } LibZhuyinBackEnd::init (); ZhuyinConfig::init (bus); g_signal_connect ((IBusBus *)bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL); component = ibus_component_new ("org.freedesktop.IBus.Libzhuyin", N_("Libzhuyin input method"), VERSION, "GPL", "Peng Wu ", "https://github.com/libzhuyin/ibus-libzhuyin", "", "ibus-libzhuyin"); ibus_component_add_engine (component, ibus_engine_desc_new ("libzhuyin-debug", N_("New Zhuyin (debug)"), N_("New Zhuyin input method (debug)"), "zh_TW", "GPL", "Peng Wu \n" "Peng Huang \n" "BYVoid ", PKGDATADIR "/icons/ibus-zhuyin.svg", "us")); factory = ibus_factory_new (ibus_bus_get_connection (bus)); if (ibus) { ibus_factory_add_engine (factory, "libzhuyin", IBUS_TYPE_ZHUYIN_ENGINE); ibus_bus_request_name (bus, "org.freedesktop.IBus.Libzhuyin", 0); } else { ibus_factory_add_engine (factory, "libzhuyin-debug", IBUS_TYPE_ZHUYIN_ENGINE); ibus_bus_register_component (bus, component); } ibus_main (); } #include static void sigterm_cb (int sig) { LibZhuyinBackEnd::finalize (); ::exit (EXIT_FAILURE); } static void atexit_cb (void) { LibZhuyinBackEnd::finalize (); } int main (gint argc, gchar **argv) { GError *error = NULL; GOptionContext *context; setlocale (LC_ALL, ""); context = g_option_context_new ("- ibus zhuyin engine component"); g_option_context_add_main_entries (context, entries, "ibus-libzhuyin"); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("Option parsing failed: %s\n", error->message); exit (-1); } ::signal (SIGTERM, sigterm_cb); ::signal (SIGINT, sigterm_cb); g_atexit (atexit_cb); start_component (); return 0; } ibus-libzhuyin-1.6.99.20140929/src/ZYObject.h000066400000000000000000000025141241117270600201420ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_OBJECT_H_ #define __ZY_OBJECT_H_ #include #include "ZYPointer.h" namespace ZY { class Object { protected: template Object (T *p) : m_p ((GObject *)p) { g_assert (get () != NULL); } operator GObject * (void) const { return m_p; } template T * get (void) const { return (T *) (GObject *) m_p; } private: Pointer m_p; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYPointer.h000066400000000000000000000035711241117270600203600ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_POINTER_H_ #define __ZY_POINTER_H_ #include namespace ZY { template struct Pointer { public: Pointer (T *p = NULL) : m_p (NULL) { set (p); } ~Pointer (void) { set (NULL); } void set (T * p) { if (m_p) { g_object_unref (m_p); } m_p = p; if (p) { #if 0 g_debug ("%s, floating = %d",G_OBJECT_TYPE_NAME (p), g_object_is_floating (p)); #endif g_object_ref_sink (p); } } Pointer &operator = (T *p) { set (p); return *this; } Pointer &operator = (const Pointer & p) { set (p.m_p); return *this; } const T * operator-> (void) const { return m_p; } T * operator-> (void) { return m_p; } operator T * (void) const { return m_p; } operator gboolean (void) const { return m_p != NULL; } private: T *m_p; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYProperty.h000066400000000000000000000053471241117270600205670ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_PROPERTY_H_ #define __ZY_PROPERTY_H_ #include #include "ZYObject.h" #include "ZYText.h" namespace ZY { class Property : public Object { public: Property (const gchar *key, IBusPropType type = PROP_TYPE_NORMAL, IBusText *label = NULL, const gchar *icon = NULL, IBusText *tooltip = NULL, gboolean sensitive = TRUE, gboolean visible = TRUE, IBusPropState state = PROP_STATE_UNCHECKED, IBusPropList *props = NULL) : Object (ibus_property_new (key, type, label, icon, tooltip, sensitive, visible, state, props)) { } void setLabel (IBusText *text) { ibus_property_set_label (get (), text); } void setLabel (const gchar *text) { setLabel (Text (text)); } void setIcon (const gchar *icon) { ibus_property_set_icon (get (), icon); } void setSymbol (IBusText *text) { ibus_property_set_symbol (get (), text); } void setSymbol (const gchar *text) { setSymbol (Text (text)); } void setSensitive (gboolean sensitive) { ibus_property_set_sensitive (get (), sensitive); } void setTooltip (IBusText *text) { ibus_property_set_tooltip (get (), text); } void setTooltip (const gchar *text) { setTooltip (Text (text)); } operator IBusProperty * (void) const { return get (); } }; class PropList : Object { public: PropList (void) : Object (ibus_prop_list_new ()) { } void append (Property &prop) { ibus_prop_list_append (get (), prop); } operator IBusPropList * (void) const { return get (); } }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYRawEditor.h000066400000000000000000000021311241117270600206270ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_RAW_EDITOR_ #define __ZY_RAW_EDITOR_ #include "ZYEditor.h" namespace ZY { class RawEditor : public Editor { public: RawEditor (ZhuyinProperties &props, Config & config) : Editor (props, config) { } }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYSignal.h000066400000000000000000000054571241117270600201620ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_SIGNAL_H_ #define __ZY_SIGNAL_H_ #ifdef HAVE_CONFIG_H # include #endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ # include namespace ZY { using namespace std::placeholders; // implement signal templates template struct signal { }; template struct signal< R(), T1, T2, T3> { typedef std::function func_type; void connect (func_type f) { m_func = f; } R operator ()() const { m_func (); } private: func_type m_func; }; template struct signal< R(T1), T2, T3> { typedef std::function func_type; void connect (func_type f) { m_func = f; } R operator ()(T1 a1) const { return m_func (a1); } private: func_type m_func; }; template struct signal< R(T1, T2), T3> { typedef std::function func_type; void connect (func_type f) { m_func = f; } R operator ()(T1 a1, T2 a2) const { return m_func (a1, a2); } private: func_type m_func; }; template struct signal< R(T1, T2, T3)> { typedef std::function func_type; void connect (func_type f) {m_func = f; } R operator ()(T1 a1, T2 a2, T3 a3) const { return m_func (a1, a2, a3); } private: func_type m_func; }; }; #else // __GXX_EXPERIMENTAL_CXX0X__ # include # include namespace std { // import boost::bind into std namespace using boost::bind; }; namespace ZY { // use boost::signal2 namespace bs2 = boost::signals2; template struct signal : public bs2::signal_type >::type { }; }; #endif // __GXX_EXPERIMENTAL_CXX0X__ #endif // __ZY_SIGNAL_H_ ibus-libzhuyin-1.6.99.20140929/src/ZYString.h000066400000000000000000000074241241117270600202070ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_STRING_H_ #define __ZY_STRING_H_ #include #include #include #include namespace ZY { class String : public std::string { public: String () : std::string () { } String (const gchar *str) : std::string (str) { } String (const std::string &str) : std::string (str) { } /* TODO: remove the following line later. */ G_DEPRECATED String (gint len) : std::string () { reserve (len); } String (const gchar ch) : std::string (1, ch) { } String & printf (const gchar *fmt, ...) { gchar *str; va_list args; va_start (args, fmt); str = g_strdup_vprintf (fmt, args); va_end (args); assign (str); g_free (str); return *this; } String & appendPrintf (const gchar *fmt, ...) { gchar *str; va_list args; va_start (args, fmt); str = g_strdup_vprintf (fmt, args); va_end (args); append (str); g_free (str); return *this; } String & appendUnichar (gunichar ch) { gchar str[12]; gint len; len = g_unichar_to_utf8 (ch, str); str[len] = 0; append (str); return *this; } String & insert (gint i, gchar ch) { std::string::insert (i, 1, ch); return *this; } String & truncate (guint len) { erase(len); return *this; } gsize utf8Length (void) const { return g_utf8_strlen (c_str(), -1); } String & operator<< (gint i) { return appendPrintf ("%d", i); } String & operator<< (guint i) { return appendPrintf ("%u", i); } String & operator<< (const gchar ch) { append (1, ch); return *this; } String & operator<< (const gchar *str) { append (str); return *this; } String & operator<< (const gunichar *wstr) { gchar *str; GError *error; str = g_ucs4_to_utf8 (wstr, -1, NULL, NULL, &error); if (str == NULL) { g_warning ("convert ucs4 to utf8 failed: %s", error->message); g_error_free (error); } else { append (str); g_free (str); } return *this; } gchar operator[] (gint i) { return std::string::operator[] (i); } String & operator<< (const std::string &str) { return operator<< (str.c_str ()); } String & operator<< (const String &str) { return operator<< ((const gchar *)str); } String & operator= (const gchar * str) { assign (str); return *this; } String & operator= (const gchar ch) { assign (1, ch); return *this; } operator const gchar *(void) const { return this->c_str (); } operator gboolean (void) const { return ! empty (); } }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYSymbolLookup.cc000066400000000000000000000044731241117270600215370ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYSymbolLookup.h" #include #include namespace ZY { gboolean SymbolLookup::loadFromFile(const char * filename) { FILE * symbolfile = fopen (filename, "r"); if (NULL == symbolfile) return FALSE; char* linebuf = NULL; size_t size = 0; ssize_t read; while ((read = getline (&linebuf, &size, symbolfile)) != -1) { if (0 == strlen (linebuf)) continue; if ( '\n' == linebuf[strlen (linebuf) - 1] ) { linebuf[strlen (linebuf) - 1] = '\0'; } gchar ** items = g_strsplit_set (linebuf, " =", 2); guint len = g_strv_length (items); if (0 == len) continue; String index = items[0]; /* for symbols.dat, copy display label from symbol. */ String symbol = index; if (2 == len) symbol = items[1]; /* just append. */ m_indexes.push_back (index); m_symbols.push_back (symbol); g_strfreev (items); } return TRUE; } String SymbolLookup::find (const String index) { gboolean found = FALSE; size_t i; for(i = 0; i < m_indexes.size (); ++i) { if (index == m_indexes[i]) { found = TRUE; break; } } if (found) return m_symbols[i]; return ""; } void SymbolLookup::dumpInfo () { size_t i; for (i = 0; i < m_indexes.size (); ++i) printf ("%s %s\n", m_indexes[i].c_str (), m_symbols[i].c_str ()); } }; ibus-libzhuyin-1.6.99.20140929/src/ZYSymbolLookup.h000066400000000000000000000025711241117270600213760ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_SYMBOL_LOOKUP_H_ #define __ZY_SYMBOL_LOOKUP_H_ #include "ZYString.h" #include #include namespace ZY { class SymbolLookup { private: typedef std::vector symbol_vec_t; public: SymbolLookup () {} virtual ~SymbolLookup () {} gboolean loadFromFile (const char * filename); String find(const String index); const std::vector & getIndexes() { return m_indexes; } void dumpInfo (); protected: symbol_vec_t m_indexes; symbol_vec_t m_symbols; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYSymbols.cc000066400000000000000000000346061241117270600205310ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYSymbols.h" #include namespace ZY { /* The following tables are copied from libchewing code. */ static const char G_EASY_SYMBOL_KEY[] = { #if 0 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #endif /* only capital letters are allowed here. */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; bool is_easy_symbol(const gint key) { for (size_t i = 0; i < G_N_ELEMENTS (G_EASY_SYMBOL_KEY); ++i) { if (key == G_EASY_SYMBOL_KEY[i]) return true; } return false; } static const char * const symbol_buf[][ 50 ] = { { "0", "\xC3\xB8", 0 }, /* "ø" */ { "[", "\xE3\x80\x8C", "\xE3\x80\x8E", "\xE3\x80\x8A", "\xE3\x80\x88", "\xE3\x80\x90", "\xE3\x80\x94", 0 }, /* "「", "『", "《", "〈", "【", "〔" */ { "]", "\xE3\x80\x8D", "\xE3\x80\x8F", "\xE3\x80\x8B", "\xE3\x80\x89", "\xE3\x80\x91", "\xE3\x80\x95", 0 }, /* "」", "』", "》", "〉", "】", "〕" */ { "{", "\xEF\xBD\x9B", 0 }, /* "{" */ { "}", "\xEF\xBD\x9D", 0 }, /* "}" */ { "<", "\xEF\xBC\x8C", "\xE2\x86\x90", 0 }, /* ",", "←" */ { ">", "\xE3\x80\x82", "\xE2\x86\x92", "\xEF\xBC\x8E", 0 }, /* "。", "→", "." */ { "?", "\xEF\xBC\x9F", "\xC2\xBF", 0 }, /* "?", "¿" */ { "!", "\xEF\xBC\x81", "\xE2\x85\xA0","\xC2\xA1", 0 }, /* "!", "Ⅰ","¡" */ { "@", "\xEF\xBC\xA0", "\xE2\x85\xA1", "\xE2\x8A\x95", "\xE2\x8A\x99", "\xE3\x8A\xA3", "\xEF\xB9\xAB", 0 }, /* "@", "Ⅱ", "⊕", "⊙", "㊣", "﹫" */ { "#", "\xEF\xBC\x83", "\xE2\x85\xA2", "\xEF\xB9\x9F", 0 }, /* "#", "Ⅲ", "﹟" */ { "$", "\xEF\xBC\x84", "\xE2\x85\xA3", "\xE2\x82\xAC", "\xEF\xB9\xA9", "\xEF\xBF\xA0", "\xE2\x88\xAE","\xEF\xBF\xA1", "\xEF\xBF\xA5", 0 }, /* "$", "Ⅳ", "€", "﹩", "¢", "∮","£", "¥" */ { "%", "\xEF\xBC\x85", "\xE2\x85\xA4", 0 }, /* "%", "Ⅴ" */ { "^", "\xEF\xB8\xBF", "\xE2\x85\xA5", "\xEF\xB9\x80", "\xEF\xB8\xBD", "\xEF\xB8\xBE", 0 }, /* "︿", "Ⅵ", "﹀", "︽", "︾" */ { "&", "\xEF\xBC\x86", "\xE2\x85\xA6", "\xEF\xB9\xA0", 0 }, /* "&", "Ⅶ", "﹠" */ { "*", "\xEF\xBC\x8A", "\xE2\x85\xA7", "\xC3\x97", "\xE2\x80\xBB", "\xE2\x95\xB3", "\xEF\xB9\xA1", "\xE2\x98\xAF", "\xE2\x98\x86", "\xE2\x98\x85", 0 }, /* "*", "Ⅷ", "×", "※", "╳", "﹡", "☯", "☆", "★" */ { "(", "\xEF\xBC\x88", "\xE2\x85\xA8", 0 }, /* "(", "Ⅸ" */ { ")", "\xEF\xBC\x89", "\xE2\x85\xA9", 0 }, /* ")", "Ⅹ" */ { "_", "\xEF\xBC\xBF", "\xE2\x80\xA6", "\xE2\x80\xA5", "\xE2\x86\x90", "\xE2\x86\x92", "\xEF\xB9\x8D", "\xEF\xB9\x89", "\xCB\x8D", "\xEF\xBF\xA3", "\xE2\x80\x93", "\xE2\x80\x94", "\xC2\xAF", "\xEF\xB9\x8A", "\xEF\xB9\x8E", "\xEF\xB9\x8F", "\xEF\xB9\xA3", "\xEF\xBC\x8D", 0 }, /* "_", "…", "‥", "←", "→", "﹍", "﹉", "ˍ", " ̄" * "–", "—", "¯", "﹊", "﹎", "﹏", "﹣", "-" */ { "+", "\xEF\xBC\x8B", "\xC2\xB1", "\xEF\xB9\xA2", 0 }, /* "+", "±", "﹢" */ { "=", "\xEF\xBC\x9D", "\xE2\x89\x92", "\xE2\x89\xA0", "\xE2\x89\xA1", "\xE2\x89\xA6", "\xE2\x89\xA7", "\xEF\xB9\xA6", 0 }, /* "=", "≒", "≠", "≡", "≦", "≧", "﹦" */ { "`", "\xE3\x80\x8F", "\xE3\x80\x8E", "\xE2\x80\xB2", "\xE2\x80\xB5", 0 }, /* "』", "『", "′", "‵" */ { "~", "\xEF\xBD\x9E", 0 }, /* "~" */ { ":", "\xEF\xBC\x9A", "\xEF\xBC\x9B", "\xEF\xB8\xB0", "\xEF\xB9\x95", 0 }, /* ":", ";", "︰", "﹕" */ { "\"", "\xEF\xBC\x9B", 0 }, /* ";" */ { "\'", "\xE3\x80\x81", "\xE2\x80\xA6", "\xE2\x80\xA5", 0 }, /* "、", "…", "‥" */ { "\\", "\xEF\xBC\xBC", "\xE2\x86\x96", "\xE2\x86\x98", "\xEF\xB9\xA8", 0 }, /* "\", "↖", "↘", "﹨" */ { "-", "\xEF\xBC\x8D", "\xEF\xBC\xBF", "\xEF\xBF\xA3", "\xC2\xAF", "\xCB\x8D", "\xE2\x80\x93", "\xE2\x80\x94", "\xE2\x80\xA5", "\xE2\x80\xA6", "\xE2\x86\x90", "\xE2\x86\x92", "\xE2\x95\xB4", "\xEF\xB9\x89", "\xEF\xB9\x8A", "\xEF\xB9\x8D", "\xEF\xB9\x8E", "\xEF\xB9\x8F", "\xEF\xB9\xA3", 0 }, /* "-", "_", " ̄", "¯", "ˍ", "–", "—", "‥", "…" * "←", "→", "╴", "﹉", "﹊", "﹍", "﹎", "﹏", "﹣" */ { "/", "\xEF\xBC\x8F", "\xC3\xB7", "\xE2\x86\x97", "\xE2\x86\x99", "\xE2\x88\x95", 0 }, /* "/","÷","↗","↙","∕" */ { "|", "\xE2\x86\x91", "\xE2\x86\x93", "\xE2\x88\xA3", "\xE2\x88\xA5", "\xEF\xB8\xB1", "\xEF\xB8\xB3", "\xEF\xB8\xB4" ,0 }, /* "↑", "↓", "∣", "∥", "︱", "︳", "︴" */ { "A", "\xC3\x85","\xCE\x91", "\xCE\xB1", "\xE2\x94\x9C", "\xE2\x95\xA0", "\xE2\x95\x9F", "\xE2\x95\x9E", 0 }, /* "Å","Α", "α", "├", "╠", "╟", "╞" */ { "B", "\xCE\x92", "\xCE\xB2","\xE2\x88\xB5", 0 }, /* "Β", "β","∵" */ { "C", "\xCE\xA7", "\xCF\x87", "\xE2\x94\x98", "\xE2\x95\xAF", "\xE2\x95\x9D", "\xE2\x95\x9C", "\xE2\x95\x9B", "\xE3\x8F\x84", "\xE2\x84\x83", "\xE3\x8E\x9D", "\xE2\x99\xA3", "\xC2\xA9", 0 }, /* "Χ", "χ", "┘", "╯", "╝", "╜", "╛" * "㏄", "℃", "㎝", "♣", "©" */ { "D", "\xCE\x94", "\xCE\xB4", "\xE2\x97\x87", "\xE2\x97\x86", "\xE2\x94\xA4", "\xE2\x95\xA3", "\xE2\x95\xA2", "\xE2\x95\xA1", "\xE2\x99\xA6", 0 }, /* "Δ", "δ", "◇", "◆", "┤", "╣", "╢", "╡","♦" */ { "E", "\xCE\x95", "\xCE\xB5", "\xE2\x94\x90", "\xE2\x95\xAE", "\xE2\x95\x97", "\xE2\x95\x93", "\xE2\x95\x95", 0 }, /* "Ε", "ε", "┐", "╮", "╗", "╓", "╕" */ { "F", "\xCE\xA6", "\xCF\x88", "\xE2\x94\x82", "\xE2\x95\x91", "\xE2\x99\x80", 0 }, /* "Φ", "ψ", "│", "║", "♀" */ { "G", "\xCE\x93", "\xCE\xB3", 0 }, /* "Γ", "γ" */ { "H", "\xCE\x97", "\xCE\xB7","\xE2\x99\xA5", 0 }, /* "Η", "η","♥" */ { "I", "\xCE\x99", "\xCE\xB9", 0 }, /* "Ι", "ι" */ { "J", "\xCF\x86", 0 }, /* "φ" */ { "K", "\xCE\x9A", "\xCE\xBA","\xE3\x8E\x9E", "\xE3\x8F\x8E", 0 }, /* "Κ", "κ","㎞", "㏎" */ { "L", "\xCE\x9B", "\xCE\xBB","\xE3\x8F\x92", "\xE3\x8F\x91", 0 }, /* "Λ", "λ","㏒", "㏑" */ { "M", "\xCE\x9C", "\xCE\xBC", "\xE2\x99\x82", "\xE2\x84\x93", "\xE3\x8E\x8E", "\xE3\x8F\x95", "\xE3\x8E\x9C","\xE3\x8E\xA1", 0 }, /* "Μ", "μ", "♂", "ℓ", "㎎", "㏕", "㎜","㎡" */ { "N", "\xCE\x9D", "\xCE\xBD","\xE2\x84\x96", 0 }, /* "Ν", "ν","№" */ { "O", "\xCE\x9F", "\xCE\xBF", 0 }, /* "Ο", "ο" */ { "P", "\xCE\xA0", "\xCF\x80", 0 }, /* "Π", "π" */ { "Q", "\xCE\x98", "\xCE\xB8","\xD0\x94","\xE2\x94\x8C", "\xE2\x95\xAD", "\xE2\x95\x94", "\xE2\x95\x93", "\xE2\x95\x92", 0 }, /* "Θ", "θ","Д","┌", "╭", "╔", "╓", "╒" */ { "R", "\xCE\xA1", "\xCF\x81", "\xE2\x94\x80", "\xE2\x95\x90" ,"\xC2\xAE" , 0 }, /* "Ρ", "ρ", "─", "═" ,"®" */ { "S", "\xCE\xA3", "\xCF\x83", "\xE2\x88\xB4", "\xE2\x96\xA1", "\xE2\x96\xA0", "\xE2\x94\xBC", "\xE2\x95\xAC", "\xE2\x95\xAA", "\xE2\x95\xAB", "\xE2\x88\xAB", "\xC2\xA7", "\xE2\x99\xA0", 0 }, /* "Σ", "σ", "∴", "□", "■", "┼", "╬", "╪", "╫" * "∫", "§", "♠" */ { "T", "\xCE\xA4", "\xCF\x84", "\xCE\xB8", "\xE2\x96\xB3", "\xE2\x96\xB2", "\xE2\x96\xBD", "\xE2\x96\xBC", "\xE2\x84\xA2", "\xE2\x8A\xBF", "\xE2\x84\xA2", 0 }, /* "Τ", "τ","θ","△","▲","▽","▼","™","⊿", "™" */ { "U", "\xCE\xA5", "\xCF\x85","\xCE\xBC","\xE2\x88\xAA", "\xE2\x88\xA9", 0 }, /* "Υ", "υ","μ","∪", "∩" */ { "V", "\xCE\xBD", 0 }, { "W", "\xE2\x84\xA6", "\xCF\x89", "\xE2\x94\xAC", "\xE2\x95\xA6", "\xE2\x95\xA4", "\xE2\x95\xA5", 0 }, /* "Ω", "ω", "┬", "╦", "╤", "╥" */ { "X", "\xCE\x9E", "\xCE\xBE", "\xE2\x94\xB4", "\xE2\x95\xA9", "\xE2\x95\xA7", "\xE2\x95\xA8", 0 }, /* "Ξ", "ξ", "┴", "╩", "╧", "╨" */ { "Y", "\xCE\xA8", 0 }, /* "Ψ" */ { "Z", "\xCE\x96", "\xCE\xB6", "\xE2\x94\x94", "\xE2\x95\xB0", "\xE2\x95\x9A", "\xE2\x95\x99", "\xE2\x95\x98", 0 }, /* "Ζ", "ζ", "└", "╰", "╚", "╙", "╘" */ }; int find_lookup_key (const String & symbol) { for (size_t i = 0; i < G_N_ELEMENTS (symbol_buf); ++i) { for (const char * const * buf = symbol_buf[i]; *buf; ++buf) { if (symbol == *buf) return *symbol_buf[i][0]; } } return 0; } int get_choice_list (const gint key, gchar ** & choices) { choices = NULL; GPtrArray * array = g_ptr_array_new (); for (size_t i = 0; i < G_N_ELEMENTS (symbol_buf); ++i) { const char * const * buf = symbol_buf[i]; if (key == *buf[0]) { /* skip lookup char. */ for (++buf; *buf; ++buf) { g_ptr_array_add (array, g_strdup (*buf)); } } } const guint len = array->len; if (array->len) { g_ptr_array_add (array, NULL); /* must be freed by g_strfreev. */ choices = (gchar **) g_ptr_array_free (array, FALSE); return len; } g_ptr_array_free (array, TRUE); return len; } bool is_half_punct (const gint key) { String punct; return half_punct_to_full_punct (key, punct); } bool half_punct_to_full_punct (const gint key, String & punct) { punct = ""; static const char keybuf[] = { '[', ']', '{', '}', '\'','<', ':', '\"', '>', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=','\\', '|', '?', ',', '.', ';', ' ', '\"', '\'', '/', '<', '>', '`', '[', ']', '{', '}', '+', '-' }; static const char * const chibuf[] = { "\xE3\x80\x8C", "\xE3\x80\x8D", "\xE3\x80\x8E", "\xE3\x80\x8F", /* "「", "」", "『", "』" */ "\xE3\x80\x81", "\xEF\xBC\x8C", "\xEF\xBC\x9A", "\xEF\xBC\x9B", /* "、", ",", ":", ";" */ "\xE3\x80\x82", "\xEF\xBD\x9E", "\xEF\xBC\x81", "\xEF\xBC\xA0", /* "。", "~", "!", "@" */ "\xEF\xBC\x83", "\xEF\xBC\x84", "\xEF\xBC\x85", "\xEF\xB8\xBF", /* "#", "$", "%", "︿" */ "\xEF\xBC\x86", "\xEF\xBC\x8A", "\xEF\xBC\x88", "\xEF\xBC\x89", /* "&", "*", "(", ")" */ "\xEF\xB9\x8D", "\xEF\xBC\x8B", "\xEF\xBC\x9D", "\xEF\xBC\xBC", /* "﹍", "+", "=", "\" */ "\xEF\xBD\x9C", "\xEF\xBC\x9F", "\xEF\xBC\x8C", "\xE3\x80\x82", /* "|", "?", ",", "。" */ "\xEF\xBC\x9B", /* ";" */ "\xE3\x80\x80","\xE2\x80\x9D", /* " ","”" */ "\xE2\x80\x99","\xEF\xBC\x8F","\xEF\xBC\x9C","\xEF\xBC\x9E", /* "’","/","<",">" */ "\xE2\x80\xB5","\xE3\x80\x94","\xE3\x80\x95","\xEF\xBD\x9B", /* "‵","〔""〕","{" */ "\xEF\xBD\x9D","\xEF\xBC\x8B","\xEF\xBC\x8D" /* "}","+","-" */ }; assert(G_N_ELEMENTS (keybuf) == G_N_ELEMENTS (chibuf)); for (size_t i = 0; i < G_N_ELEMENTS (keybuf); ++i) { if (key == keybuf[i]) { punct = chibuf[i]; return true; } } return false; } bool is_half_english (const gint key) { String english; return half_english_to_full_english (key, english); } bool half_english_to_full_english (const gint key, String & english) { english = ""; static char keybuf[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '\"', '\'', '/', '<', '>', '`', '[', ']', '{', '}', '+', '-' }; static const char *chibuf[] = { "\xEF\xBC\x90","\xEF\xBC\x91","\xEF\xBC\x92","\xEF\xBC\x93", /* "0","1","2","3" */ "\xEF\xBC\x94","\xEF\xBC\x95","\xEF\xBC\x96","\xEF\xBC\x97", /* "4","5","6","7" */ "\xEF\xBC\x98","\xEF\xBC\x99","\xEF\xBD\x81","\xEF\xBD\x82", /* "8","9","a","b" */ "\xEF\xBD\x83","\xEF\xBD\x84","\xEF\xBD\x85","\xEF\xBD\x86", /* "c","d","e","f" */ "\xEF\xBD\x87","\xEF\xBD\x88","\xEF\xBD\x89","\xEF\xBD\x8A", /* "g","h","i","j" */ "\xEF\xBD\x8B","\xEF\xBD\x8C","\xEF\xBD\x8D","\xEF\xBD\x8E", /* "k","l","m","n" */ "\xEF\xBD\x8F","\xEF\xBD\x90","\xEF\xBD\x91","\xEF\xBD\x92", /* "o","p","q","r" */ "\xEF\xBD\x93","\xEF\xBD\x94","\xEF\xBD\x95","\xEF\xBD\x96", /* "s","t","u","v" */ "\xEF\xBD\x97","\xEF\xBD\x98","\xEF\xBD\x99","\xEF\xBD\x9A", /* "w","x","y","z" */ "\xEF\xBC\xA1","\xEF\xBC\xA2","\xEF\xBC\xA3","\xEF\xBC\xA4", /* "A","B","C","D" */ "\xEF\xBC\xA5","\xEF\xBC\xA6","\xEF\xBC\xA7","\xEF\xBC\xA8", /* "E","F","G","H" */ "\xEF\xBC\xA9","\xEF\xBC\xAA","\xEF\xBC\xAB","\xEF\xBC\xAC", /* "I","J","K","L" */ "\xEF\xBC\xAD","\xEF\xBC\xAE","\xEF\xBC\xAF","\xEF\xBC\xB0", /* "M","N","O","P" */ "\xEF\xBC\xB1","\xEF\xBC\xB2","\xEF\xBC\xB3","\xEF\xBC\xB4", /* "Q","R","S","T" */ "\xEF\xBC\xB5","\xEF\xBC\xB6","\xEF\xBC\xB7","\xEF\xBC\xB8", /* "U","V","W","X" */ "\xEF\xBC\xB9","\xEF\xBC\xBA","\xE3\x80\x80","\xE2\x80\x9D", /* "Y","Z"," ","”" */ "\xE2\x80\x99","\xEF\xBC\x8F","\xEF\xBC\x9C","\xEF\xBC\x9E", /* "’","/","<",">" */ "\xE2\x80\xB5","\xE3\x80\x94","\xE3\x80\x95","\xEF\xBD\x9B", /* "‵","〔""〕","{" */ "\xEF\xBD\x9D","\xEF\xBC\x8B","\xEF\xBC\x8D" /* "}","+","-" */ }; assert(G_N_ELEMENTS (keybuf) == G_N_ELEMENTS (chibuf)); for (size_t i = 0; i < G_N_ELEMENTS (keybuf); ++i) { if (key == keybuf[i]) { english = chibuf[i]; return true; } } return false; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYSymbols.h000066400000000000000000000026111241117270600203620ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_SYMBOLS_H_ #define __ZY_SYMBOLS_H_ #include "ZYString.h" #include namespace ZY { bool is_easy_symbol(const gint key); int find_lookup_key (const String & symbol); int get_choice_list (const gint key, gchar ** & choices); bool is_half_punct (const gint key); bool half_punct_to_full_punct (const gint key, String & punct); bool is_half_english (const gint key); bool half_english_to_full_english (const gint key, String & english); #define BUILTIN_SYMBOL_TYPE "builtin" #define BOPOMOFO_SYMBOL_TYPE "bopomofo" }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYText.h000066400000000000000000000040511241117270600176560ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_TEXT_H_ #define __ZY_TEXT_H_ #include #include #include "ZYObject.h" namespace ZY { class Text : Object { public: Text (IBusText *text) : Object (text) { } Text (const gchar *str) : Object (ibus_text_new_from_string (str)) { } Text (const std::string & str) : Object (ibus_text_new_from_string (str.c_str ())) { } Text (gunichar ch) : Object (ibus_text_new_from_unichar (ch)) { } void appendAttribute (guint type, guint value, guint start, guint end) { ibus_text_append_attribute (get (), type, value, start, end); } const gchar *text (void) const { return get ()->text; } operator IBusText * (void) const { return get (); } }; class StaticText : public Text { public: StaticText (const gchar *str) : Text (ibus_text_new_from_static_string (str)) { } StaticText (const std::string & str) : Text (ibus_text_new_from_static_string (str.c_str ())) { } StaticText (gunichar ch) : Text (ch) { } operator IBusText * (void) const { return Text::operator IBusText * (); } }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYTradSimpConverter.cc000066400000000000000000000043231241117270600225050ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "ZYTradSimpConverter.h" #include #include "ZYTypes.h" #include "ZYString.h" namespace ZY { class opencc { static const int BUFFER_SIZE = 64; public: opencc (void) { m_cc = opencc_open (OPENCC_DEFAULT_CONFIG_TRAD_TO_SIMP); g_assert (m_cc != NULL); } ~opencc (void) { opencc_close (m_cc); } void convert (const gchar *in, String &out) { glong n_char; gunichar *in_ucs4 = g_utf8_to_ucs4_fast (in, -1, &n_char); ucs4_t *pinbuf = (ucs4_t *)in_ucs4; size_t inbuf_left = n_char; while (inbuf_left != 0) { ucs4_t *poutbuf = (ucs4_t *)m_buffer; size_t outbuf_left = BUFFER_SIZE; size_t retval = opencc_convert(m_cc, &pinbuf, &inbuf_left, &poutbuf, &outbuf_left); if (retval == (size_t) -1) { /* append left chars in pinbuf */ g_warning ("opencc_convert return failed"); out << (gunichar *) pinbuf; break; } *poutbuf = L'\0'; out << m_buffer; } g_free (in_ucs4); } private: opencc_t m_cc; gunichar m_buffer[BUFFER_SIZE + 1]; }; void TradSimpConverter::tradToSimp (const gchar *in, String &out) { static opencc cc; cc.convert (in, out); } }; ibus-libzhuyin-1.6.99.20140929/src/ZYTradSimpConverter.h000066400000000000000000000021071241117270600223450ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_TRAD_SIMP_CONVERTER_H_ #define __ZY_TRAD_SIMP_CONVERTER_H_ #include namespace ZY { class String; class TradSimpConverter { public: static void tradToSimp (const gchar * in, String &out); }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYTypes.h000066400000000000000000000017671241117270600200510ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_TYPES_H_ #define __ZY_TYPES_H_ #include namespace ZY { #define MAX_UTF8_LEN 6 #define MAX_PHRASE_LEN 16 }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYUtil.h000066400000000000000000000054511241117270600176540ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_UTIL_H_ #define __ZY_UTIL_H_ #ifdef HAVE_CONFIG_H # include #endif #include #include #ifdef __GXX_EXPERIMENTAL_CXX0X__ # include #else # include # include namespace std { // import boost::shared_ptr to std namespace using boost::shared_ptr; // import boost::scoped_ptr to std namespace, and rename to unique_ptr // XXX: the unique_ptr can transfer the pointer ownership, // but scoped_ptr cannot. template class unique_ptr : public boost::scoped_ptr {}; }; #endif #include namespace ZY { // mask for Ctrl, Alt, Super, Hyper, Meta const guint CMSHM_MASK = IBUS_CONTROL_MASK | IBUS_MOD1_MASK | IBUS_SUPER_MASK | IBUS_HYPER_MASK | IBUS_META_MASK; // mask for Shift, Ctrl, Alt, Super, Hyper, Meta const guint SCMSHM_MASK = CMSHM_MASK | IBUS_SHIFT_MASK; inline guint cmshm_filter (guint modifiers) { return modifiers & CMSHM_MASK; } inline guint scmshm_filter (guint modifiers) { return modifiers & SCMSHM_MASK; } inline gboolean cmshm_test (guint modifiers, guint mask) { return cmshm_filter (modifiers) == mask; } inline gboolean scmshm_test (guint modifiers, guint mask) { return scmshm_filter (modifiers) == mask; } #if 0 class Uname { public: Uname (void) { uname (&m_buf); } const gchar *hostname (void) const { return m_buf.nodename; } private: struct utsname m_buf; }; class Hostname : public Uname { public: operator const gchar * (void) const { return hostname (); } }; class Env : public std::string { public: Env (const gchar *name) { gchar *str; str = std::getenv (name); assign (str != NULL ? str : ""); } operator const gchar *(void) const { return c_str(); } }; #endif }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZBopomofoSymbolSection.cc000066400000000000000000000051621241117270600235210ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZBopomofoSymbolSection.h" #include #include #include "ZYSymbols.h" namespace ZY { BopomofoSymbolSection::BopomofoSymbolSection (PhoneticEditor & editor, ZhuyinProperties & props) : SymbolSection (editor, props) { m_type = BOPOMOFO_SYMBOL_TYPE; } BopomofoSymbolSection::~BopomofoSymbolSection () { } bool BopomofoSymbolSection::initCandidates (zhuyin_instance_t * instance, const String & lookup) { m_candidates.clear (); assert (1 == lookup.length ()); m_lookup = lookup; const char key = lookup[0]; /* cache the choices. */ gchar ** symbols = NULL; assert (zhuyin_in_chewing_keyboard (instance, key, &symbols)); size_t num = g_strv_length (symbols); assert (num > 0); for (size_t i = 0; i < num; ++i) { m_candidates.push_back (symbols[i]); } g_strfreev (symbols); return true; } bool BopomofoSymbolSection::fillLookupTableByPage () { LookupTable & lookup_table = getLookupTable (); guint len = m_candidates.size (); guint filled_nr = lookup_table.size (); guint page_size = lookup_table.pageSize (); /* fill lookup table by libzhuyin get candidates. */ guint need_nr = MIN (page_size, len - filled_nr); g_assert (need_nr >=0); if (need_nr == 0) return FALSE; for (guint i = filled_nr; i < filled_nr + need_nr; i++) { if (i >= len) /* no more candidates */ break; Text text (m_candidates[i]); lookup_table.appendCandidate (text); } return TRUE; } int BopomofoSymbolSection::selectCandidate (guint index) { if (index >= m_candidates.size ()) return 0; m_choice = m_candidates[index]; return 1; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZBopomofoSymbolSection.h000066400000000000000000000031011241117270600233520ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_BOPOMOFO_SYMBOL_SECTION_H_ #define __ZY_LIB_ZHUYIN_BOPOMOFO_SYMBOL_SECTION_H_ #include "ZYZSymbolSection.h" #include namespace ZY { class ZhuyinProperties; class BopomofoSymbolSection : public SymbolSection { typedef std::vector::iterator iterator_t; public: BopomofoSymbolSection (PhoneticEditor & editor, ZhuyinProperties & props); virtual ~BopomofoSymbolSection (); public: virtual bool initCandidates (zhuyin_instance_t * instance, const String & lookup); virtual bool fillLookupTableByPage (); virtual int selectCandidate (guint index); protected: std::vector m_candidates; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZBuiltinSymbolSection.cc000066400000000000000000000050141241117270600233430ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZBuiltinSymbolSection.h" #include #include "ZYSymbols.h" namespace ZY { BuiltinSymbolSection::BuiltinSymbolSection (PhoneticEditor & editor, ZhuyinProperties & props) : SymbolSection (editor, props) { m_type = BUILTIN_SYMBOL_TYPE; } BuiltinSymbolSection::~BuiltinSymbolSection () { } bool BuiltinSymbolSection::initCandidates (zhuyin_instance_t * instance, const String & lookup) { if (!lookup) return false; m_candidates.clear (); assert (1 == lookup.length ()); m_lookup = lookup; /* cache the choices. */ gchar ** choices = NULL; size_t num = get_choice_list (m_lookup[0], choices); assert (num > 0); for (size_t i = 0; i < num; ++i) { m_candidates.push_back (choices[i]); } return true; } bool BuiltinSymbolSection::fillLookupTableByPage () { LookupTable & lookup_table = getLookupTable (); guint len = m_candidates.size (); guint filled_nr = lookup_table.size (); guint page_size = lookup_table.pageSize (); /* fill lookup table by libzhuyin get candidates. */ guint need_nr = MIN (page_size, len - filled_nr); g_assert (need_nr >=0); if (need_nr == 0) return FALSE; for (guint i = filled_nr; i < filled_nr + need_nr; i++) { if (i >= len) /* no more candidates */ break; Text text (m_candidates[i]); lookup_table.appendCandidate (text); } return TRUE; } int BuiltinSymbolSection::selectCandidate (guint index) { if (index >= m_candidates.size ()) return 0; m_choice = m_candidates[index]; return 1; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZBuiltinSymbolSection.h000066400000000000000000000030731241117270600232100ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_BUILTIN_SYMBOL_SECTION_H_ #define __ZY_LIB_ZHUYIN_BUILTIN_SYMBOL_SECTION_H_ #include "ZYZSymbolSection.h" #include namespace ZY { class ZhuyinProperties; class BuiltinSymbolSection : public SymbolSection { typedef std::vector::iterator iterator_t; public: BuiltinSymbolSection (PhoneticEditor & editor, ZhuyinProperties & props); virtual ~BuiltinSymbolSection (); public: virtual bool initCandidates (zhuyin_instance_t * instance, const String & lookup); virtual bool fillLookupTableByPage (); virtual int selectCandidate (guint index); protected: std::vector m_candidates; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZConfig.cc000066400000000000000000000247551241117270600204440ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZConfig.h" #include #include "ZYLibZhuyin.h" #include namespace ZY { const gchar * const CONFIG_FUZZY_ZHUYIN = "fuzzyzhuyin"; const gchar * const CONFIG_ORIENTATION = "LookupTableOrientation"; const gchar * const CONFIG_PAGE_SIZE = "candidatenum"; const gchar * const CONFIG_INIT_CHINESE = "chinesemode"; const gchar * const CONFIG_INIT_FULL_ENGLISH = "fullhalfenglish"; const gchar * const CONFIG_INIT_FULL_PUNCT = "fullhalfpunct"; const gchar * const CONFIG_INIT_TRAD_CHINESE = "traditionalchinese"; const gchar * const CONFIG_ALWAYS_INPUT_NUMBERS = "alwaysinputnum"; const gchar * const CONFIG_KEYBOARD_LAYOUT = "keyboardlayout"; const gchar * const CONFIG_CANDIDATE_KEYS = "candidatekeys"; const gchar * const CONFIG_EASY_SYMBOL = "easysymbol"; const gchar * const CONFIG_USER_SYMBOL = "usersymbol"; const gchar * const CONFIG_IMPORT_DICTIONARY = "importdictionary"; const gchar * const CONFIG_CLEAR_USER_DATA = "clearuserdata"; const zhuyin_option_t ZHUYIN_DEFAULT_OPTION = USE_TONE | FORCE_TONE | ZHUYIN_CORRECT_ALL | 0; std::unique_ptr ZhuyinConfig::m_instance; ZhuyinConfig::ZhuyinConfig (Bus & bus) : Config (bus, "zhuyin") { initDefaultValues (); g_signal_connect (get (), "value-changed", G_CALLBACK (valueChangedCallback), this); } ZhuyinConfig::~ZhuyinConfig (void) { } void ZhuyinConfig::init (Bus & bus) { if (m_instance.get () == NULL) { m_instance.reset (new ZhuyinConfig (bus)); m_instance->readDefaultValues (); } } void ZhuyinConfig::initDefaultValues (void) { m_option = ZHUYIN_DEFAULT_OPTION; m_option_mask = USE_TONE | FORCE_TONE | ZHUYIN_CORRECT_ALL; m_orientation = IBUS_ORIENTATION_VERTICAL; m_page_size = 10; m_keyboard_layout = CHEWING_DEFAULT; m_init_chinese = TRUE; m_init_full_english = FALSE; m_init_full_punct = TRUE; m_init_trad_chinese = TRUE; m_always_input_numbers = FALSE; m_candidate_keys = "1234567890"; m_easy_symbol = TRUE; m_user_symbol = TRUE; } /* Here are the zhuyin keyboard layout mapping table. */ static const struct { gint layout; ZhuyinScheme scheme; } zhuyin_schemes [] = { {0, CHEWING_STANDARD}, {1, CHEWING_HSU}, {2, CHEWING_IBM}, {3, CHEWING_GINYIEH}, {4, CHEWING_ETEN}, {5, CHEWING_ETEN26}, {6, CHEWING_STANDARD_DVORAK}, {7, CHEWING_HSU_DVORAK}, {8, CHEWING_DACHEN_CP26}, {9, FULL_PINYIN_HANYU}, {10, FULL_PINYIN_LUOMA}, {11, FULL_PINYIN_SECONDARY_BOPOMOFO}, }; static const struct { const gchar * const name; guint option; } fuzzy_zhuyin_options [] = { /* fuzzy pinyin */ { "fuzzyzhuyin_c_ch", ZHUYIN_AMB_C_CH }, { "fuzzyzhuyin_z_zh", ZHUYIN_AMB_Z_ZH }, { "fuzzyzhuyin_s_sh", ZHUYIN_AMB_S_SH }, { "fuzzyzhuyin_l_n", ZHUYIN_AMB_L_N }, { "fuzzyzhuyin_f_h", ZHUYIN_AMB_F_H }, { "fuzzyzhuyin_l_r", ZHUYIN_AMB_L_R }, { "fuzzyzhuyin_g_k", ZHUYIN_AMB_G_K }, { "fuzzyzhuyin_an_ang", ZHUYIN_AMB_AN_ANG }, { "fuzzyzhuyin_en_eng", ZHUYIN_AMB_EN_ENG }, { "fuzzyzhuyin_in_ing", ZHUYIN_AMB_IN_ING }, }; void ZhuyinConfig::readDefaultValues (void) { #if defined(HAVE_IBUS_CONFIG_GET_VALUES) /* read all values together */ initDefaultValues (); GVariant *values = ibus_config_get_values (get (), m_section.c_str ()); g_return_if_fail (values != NULL); GVariantIter iter; gchar *name; GVariant *value; g_variant_iter_init (&iter, values); while (g_variant_iter_next (&iter, "{sv}", &name, &value)) { /* skip signals here. */ if (0 == strcmp(CONFIG_IMPORT_DICTIONARY, name)) continue; if (0 == strcmp(CONFIG_CLEAR_USER_DATA, name)) continue; valueChanged (m_section, name, value); g_free (name); g_variant_unref (value); } g_variant_unref (values); #else /* others */ m_orientation = read (CONFIG_ORIENTATION, IBUS_ORIENTATION_VERTICAL); if (m_orientation != IBUS_ORIENTATION_VERTICAL && m_orientation != IBUS_ORIENTATION_HORIZONTAL) { m_orientation = IBUS_ORIENTATION_VERTICAL; g_warn_if_reached (); } m_page_size = read (CONFIG_PAGE_SIZE, 10); if (m_page_size > 10) { m_page_size = 10; g_warn_if_reached (); } /* init states */ m_init_chinese = read (CONFIG_INIT_CHINESE, true); m_init_full_english = read (CONFIG_INIT_FULL_ENGLISH, false); m_init_full_punct = read (CONFIG_INIT_FULL_PUNCT, true); m_init_trad_chinese = read (CONFIG_INIT_TRAD_CHINESE, true); m_always_input_numbers = read (CONFIG_ALWAYS_INPUT_NUMBERS, false); gint layout = read (CONFIG_KEYBOARD_LAYOUT, 0); m_keyboard_layout = CHEWING_DEFAULT; for (guint i = 0; i < G_N_ELEMENTS (zhuyin_schemes); ++i) { if (zhuyin_schemes[i].layout == layout) { m_keyboard_layout = zhuyin_schemes[i].scheme; } } m_candidate_keys = read (CONFIG_CANDIDATE_KEYS, std::string ("1234567890")); m_easy_symbol = read (CONFIG_EASY_SYMBOL, true); m_user_symbol = read (CONFIG_USER_SYMBOL, true); /* fuzzy zhuyin */ if (read (CONFIG_FUZZY_ZHUYIN, false)) m_option_mask |= ZHUYIN_AMB_ALL; else m_option_mask &= ~ZHUYIN_AMB_ALL; /* read values */ for (guint i = 0; i < G_N_ELEMENTS (fuzzy_zhuyin_options); i++) { if (read (fuzzy_zhuyin_options[i].name, (fuzzy_zhuyin_options[i].option & PINYIN_DEFAULT_OPTION) != 0)) { m_option |= fuzzy_zhuyin_options[i].option; } else { m_option &= ~fuzzy_zhuyin_options[i].option; } } #endif } gboolean ZhuyinConfig::valueChanged (const std::string §ion, const std::string &name, GVariant *value) { if (m_section != section) return FALSE; if (Config::valueChanged (section, name, value)) return TRUE; /* init states */ if (CONFIG_INIT_CHINESE == name) m_init_chinese = normalizeGVariant (value, true); else if (CONFIG_INIT_FULL_ENGLISH == name) m_init_full_english = normalizeGVariant (value, false); else if (CONFIG_INIT_FULL_PUNCT == name) m_init_full_punct = normalizeGVariant (value, true); else if (CONFIG_INIT_TRAD_CHINESE == name) m_init_trad_chinese = normalizeGVariant (value, true); else if (CONFIG_ALWAYS_INPUT_NUMBERS == name) m_always_input_numbers = normalizeGVariant (value, false); else if (CONFIG_KEYBOARD_LAYOUT == name) { gint layout = normalizeGVariant (value, 0); m_keyboard_layout = CHEWING_DEFAULT; for (guint i = 0; i < G_N_ELEMENTS (zhuyin_schemes); ++i) { if (zhuyin_schemes[i].layout == layout) { m_keyboard_layout = zhuyin_schemes[i].scheme; } } } else if (CONFIG_CANDIDATE_KEYS == name) { m_candidate_keys = normalizeGVariant (value, std::string ("1234567890")); } /* lookup table page size */ else if (CONFIG_ORIENTATION == name) { m_orientation = normalizeGVariant (value, IBUS_ORIENTATION_VERTICAL); if (m_orientation != IBUS_ORIENTATION_VERTICAL && m_orientation != IBUS_ORIENTATION_HORIZONTAL) { m_orientation = IBUS_ORIENTATION_VERTICAL; g_warn_if_reached (); } } else if (CONFIG_PAGE_SIZE == name) { m_page_size = normalizeGVariant (value, 10); if (m_page_size > 10) { m_page_size = 10; g_warn_if_reached (); } } else if (CONFIG_EASY_SYMBOL == name) { m_easy_symbol = normalizeGVariant (value, true); } else if (CONFIG_USER_SYMBOL == name) { m_user_symbol = normalizeGVariant (value, true); } else if (CONFIG_IMPORT_DICTIONARY == name) { std::string filename = normalizeGVariant (value, std::string("")); LibZhuyinBackEnd::instance ().importZhuyinDictionary(filename.c_str ()); } else if (CONFIG_CLEAR_USER_DATA == name) { std::string target = normalizeGVariant (value, std::string("")); LibZhuyinBackEnd::instance ().clearZhuyinUserData(target.c_str ()); } /* fuzzy zhuyin */ else if (CONFIG_FUZZY_ZHUYIN == name) { if (normalizeGVariant (value, false)) m_option_mask |= ZHUYIN_AMB_ALL; else m_option_mask &= ~ZHUYIN_AMB_ALL; } else { for (guint i = 0; i < G_N_ELEMENTS (fuzzy_zhuyin_options); i++) { if (G_LIKELY (fuzzy_zhuyin_options[i].name != name)) continue; if (normalizeGVariant (value, (fuzzy_zhuyin_options[i].option & ZHUYIN_DEFAULT_OPTION) != 0)) m_option |= fuzzy_zhuyin_options[i].option; else m_option &= ~fuzzy_zhuyin_options[i].option; return TRUE; } return FALSE; } return TRUE; } void ZhuyinConfig::valueChangedCallback (IBusConfig *config, const gchar *section, const gchar *name, GVariant *value, ZhuyinConfig *self) { if (self->m_section != section) return; self->valueChanged (section, name, value); if (self->m_section == "engine/zhuyin") LibZhuyinBackEnd::instance ().setZhuyinOptions (self); } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZConfig.h000066400000000000000000000037001241117270600202710ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_ZHUYIN_CONFIG_H_ #define __ZY_LIB_ZHUYIN_ZHUYIN_CONFIG_H_ #ifdef HAVE_CONFIG_H # include #endif #include #include #include "ZYConfig.h" namespace ZY { class Bus; class ZhuyinConfig : public Config { public: static void init (Bus & bus); static ZhuyinConfig & instance (void) { return *m_instance; } protected: ZhuyinConfig (Bus & bus); public: virtual ~ZhuyinConfig (void); protected: void initDefaultValues (void); virtual void readDefaultValues (void); virtual gboolean valueChanged (const std::string §ion, const std::string &name, GVariant *value); private: static void valueChangedCallback (IBusConfig *config, const gchar *section, const gchar *name, GVariant *value, ZhuyinConfig *self); private: static std::unique_ptr m_instance; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZEnhancedEditor.cc000066400000000000000000000052731241117270600221050ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZEnhancedEditor.h" #include #include "ZYEnhancedText.h" namespace ZY { EnhancedEditor::EnhancedEditor (ZhuyinProperties & props, Config & config) : Editor (props, config) { } EnhancedEditor::~EnhancedEditor (void) { } gboolean EnhancedEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { modifiers &= (IBUS_CONTROL_MASK | IBUS_MOD1_MASK | IBUS_SUPER_MASK | IBUS_HYPER_MASK | IBUS_META_MASK); /* ignore key events with some masks */ if (modifiers != 0) return TRUE; #if 0 if (isPhonetic (keyval)) { /* zhuyin or pinyin key */ assert (insert_phonetic (m_text, m_cursor++, keyval)); update (); return TRUE; } else { /* control key */ if (!m_text) return FALSE; } #endif switch (keyval) { case IBUS_BackSpace: if (m_cursor > 0) { erase_input_sequence (m_text, --m_cursor, 1); update (); } return TRUE; case IBUS_Delete: case IBUS_KP_Delete: if (m_cursor < get_enhanced_text_length (m_text)) { erase_input_sequence (m_text, m_cursor, 1); update (); } return TRUE; case IBUS_Left: case IBUS_KP_Left: if (!m_text) return FALSE; if (m_cursor > 0) { m_cursor --; update (); } return TRUE; case IBUS_Right: case IBUS_KP_Right: if (m_cursor < m_text.length ()) { m_cursor ++; update (); } return TRUE; case IBUS_Escape: reset (); return TRUE; default: return TRUE; } } void EnhancedEditor::update (void) { Editor::update (); } void EnhancedEditor::reset (void) { Editor::reset (); } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZEnhancedEditor.h000066400000000000000000000026121241117270600217410ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_ENHANCED_EDITOR_H_ #define __ZY_LIB_ZHUYIN_ENHANCED_EDITOR_H_ #include #include "ZYLookupTable.h" #include "ZYEditor.h" namespace ZY { class EnhancedEditor : public Editor { /** * enhance the editor logicics to support enhanced text format. */ public: EnhancedEditor (ZhuyinProperties & prop, Config & config); virtual ~EnhancedEditor (void); virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void update (void); virtual void reset (void); }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZPhoneticEditor.cc000066400000000000000000000641551241117270600221550ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZPhoneticEditor.h" #include #include "ZYConfig.h" #include "ZYZhuyinProperties.h" #include "ZYZPhoneticSection.h" #include "ZYZBuiltinSymbolSection.h" #include "ZYZBopomofoSymbolSection.h" #include "ZYEnhancedText.h" #include "ZYLibZhuyin.h" #include "ZYSymbols.h" #include "ZYZUserSymbolListAllSection.h" #include "ZYZUserSymbolShownSection.h" namespace ZY { /** * Implementation Notes: * 1. support input editing; * 2. support phonetic candidates; * 3. support built-in symbols candidates; * 4. support list all user symbols; * 5. support show user symbols; * 6. support easy symbols input; */ /* init static members */ PhoneticEditor::PhoneticEditor (ZhuyinProperties & props, Config & config) : EnhancedEditor (props, config), m_lookup_table (m_config.pageSize ()) { /* alloc one instance. */ m_instance = LibZhuyinBackEnd::instance ().allocZhuyinInstance (); assert (NULL != m_instance); /* init symbols sections here. */ m_symbol_sections[STATE_BUILTIN_SYMBOL_SHOWN].reset (new BuiltinSymbolSection (*this, props)); m_symbol_sections[STATE_BOPOMOFO_SYMBOL_SHOWN].reset (new BopomofoSymbolSection (*this, props)); m_symbol_sections[STATE_USER_SYMBOL_LIST_ALL].reset (new UserSymbolListAllSection (*this, props)); m_symbol_sections[STATE_USER_SYMBOL_SHOWN].reset (new UserSymbolShownSection (*this, props)); m_phonetic_section.reset (new PhoneticSection (*this, props)); /* load easy symbols: easysymbol.txt */ gchar * path = g_build_filename (g_get_user_config_dir (), "ibus", "libzhuyin", "easysymbol.txt", NULL); loadEasySymbolFile (".." G_DIR_SEPARATOR_S "data" G_DIR_SEPARATOR_S "easysymbol.txt") || loadEasySymbolFile (path) || loadEasySymbolFile (PKGDATADIR G_DIR_SEPARATOR_S "easysymbol.txt"); g_free(path); } PhoneticEditor::~PhoneticEditor (void) { m_text = ""; m_cursor = 0; /* free m_instances */ resizeInstances (); LibZhuyinBackEnd::instance ().freeZhuyinInstance (m_instance); } gboolean PhoneticEditor::loadEasySymbolFile (const gchar * filename) { gboolean retval = m_easy_symbols.loadFromFile (filename); return retval; } gboolean PhoneticEditor::processEscape (guint keyval, guint keycode, guint modifiers) { if (IBUS_Escape != keyval) return FALSE; if (cmshm_filter (modifiers) != 0) return TRUE; reset (); return TRUE; } gboolean PhoneticEditor::processEnter (guint keyval, guint keycode, guint modifiers) { if (IBUS_Return != keyval && IBUS_KP_Enter != keyval) return FALSE; if (cmshm_filter (modifiers) != 0) return TRUE; if (!m_text) return FALSE; commit (); return TRUE; } gboolean PhoneticEditor::processSpace (guint keyval, guint keycode, guint modifiers) { if (IBUS_space != keyval && IBUS_KP_Space != keyval) return FALSE; if (cmshm_filter (modifiers) != 0) return TRUE; selectCandidate (m_lookup_table.cursorPos ()); updateZhuyin (); update (); return TRUE; } gboolean PhoneticEditor::processFunctionKey (guint keyval, guint keycode, guint modifiers) { if (m_text.empty ()) return FALSE; /* ignore numlock */ modifiers = cmshm_filter (modifiers); if (modifiers != 0) return TRUE; /* process some cursor control keys */ if (modifiers == 0) { /* no modifiers. */ switch (keyval) { case IBUS_BackSpace: removeCharBefore (); return TRUE; case IBUS_Delete: case IBUS_KP_Delete: removeCharAfter (); return TRUE; case IBUS_Left: case IBUS_KP_Left: moveCursorLeft (); return TRUE; case IBUS_Right: case IBUS_KP_Right: moveCursorRight (); return TRUE; case IBUS_Home: case IBUS_KP_Home: moveCursorToBegin (); return TRUE; case IBUS_End: case IBUS_KP_Enter: moveCursorToEnd (); return TRUE; case IBUS_Escape: reset (); return TRUE; default: return FALSE; } } return TRUE; } gboolean PhoneticEditor::processShowCandidateKey (guint keyval, guint keycode, guint modifiers) { if (m_text.empty ()) return FALSE; /* ignore numlock */ modifiers = cmshm_filter (modifiers); if (modifiers != 0) return TRUE; /* process some show candidate keys */ if (modifiers == 0) { /* no modifiers. */ switch (keyval) { case IBUS_Down: case IBUS_KP_Down: /* check phonetic or symbol section here */ prepareCandidates (); break; case IBUS_Up: case IBUS_KP_Up: m_lookup_table.clear (); m_input_state = STATE_INPUT; break; default: return FALSE; } } update (); return TRUE; } gboolean PhoneticEditor::processCandidateKey (guint keyval, guint keycode, guint modifiers) { if (!m_lookup_table.size ()) return FALSE; /* ignore numlock */ modifiers = cmshm_filter (modifiers); if (modifiers != 0) return TRUE; /* process some cursor control keys */ if (modifiers == 0) { /* no modifiers. */ switch (keyval) { case IBUS_Up: case IBUS_KP_Up: cursorUp (); return TRUE; case IBUS_Down: case IBUS_KP_Down: cursorDown (); return TRUE; case IBUS_Page_Up: case IBUS_KP_Page_Up: pageUp (); return TRUE; case IBUS_Page_Down: case IBUS_KP_Page_Down: pageDown (); return TRUE; default: break; } /* process candidate keys */ std::string keys = m_config.candidateKeys (); std::size_t found = keys.find (keyval); if (found != std::string::npos) { /* found. */ selectCandidateInPage (found); return TRUE; } } return FALSE; } gboolean PhoneticEditor::processEasySymbolKey (guint keyval, guint keycode, guint modifiers) { if (!m_config.easySymbol ()) return FALSE; if (! ('A' <= keyval && keyval <= 'Z')) return FALSE; String index = (gchar) keyval; String symbol = m_easy_symbols.find (index); if ("" == symbol) return FALSE; String lookup; int ch = find_lookup_key (symbol); if (ch != 0) lookup = (gchar) ch; insert_symbol (m_text, m_cursor++, BUILTIN_SYMBOL_TYPE, lookup, symbol); update (); return TRUE; } gboolean PhoneticEditor::processUserSymbolKey (guint keyval, guint keycode, guint modifiers) { if (!m_config.userSymbol ()) return FALSE; if ('`' != keyval) return FALSE; m_input_state = STATE_USER_SYMBOL_LIST_ALL; m_symbol_sections[m_input_state]->initCandidates (m_instance, "`"); update (); return TRUE; } gboolean PhoneticEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { return FALSE; } void PhoneticEditor::updateLookupTableFast (void) { Editor::updateLookupTableFast (m_lookup_table, TRUE); } void PhoneticEditor::updateLookupTable (void) { m_lookup_table.clear (); fillLookupTableByPage (); updateLookupTableLabel (); if (m_lookup_table.size ()) { Editor::updateLookupTable (m_lookup_table, TRUE); } else { hideLookupTable (); } } void PhoneticEditor::updateLookupTableLabel (void) { String labels = m_config.candidateKeys (); size_t len = MIN (labels.length (), m_config.pageSize ()); for (size_t i = 0; i < len; ++i) { String label = (gchar) labels[i]; Text text (label); m_lookup_table.setLabel (i, text); } } gboolean PhoneticEditor::fillLookupTableByPage (void) { if (STATE_CANDIDATE_SHOWN == m_input_state) return m_phonetic_section->fillLookupTableByPage (); if (STATE_BUILTIN_SYMBOL_SHOWN == m_input_state || STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state || STATE_USER_SYMBOL_LIST_ALL == m_input_state || STATE_USER_SYMBOL_SHOWN == m_input_state) { return m_symbol_sections[m_input_state]-> fillLookupTableByPage (); } return FALSE; } void PhoneticEditor::pageUp (void) { if (G_LIKELY (m_lookup_table.pageUp ())) { updateLookupTableFast (); updatePreeditText (); updateAuxiliaryText (); } } void PhoneticEditor::pageDown (void) { if (G_LIKELY ((m_lookup_table.pageDown ()) || (fillLookupTableByPage () && m_lookup_table.pageDown ()))) { updateLookupTableFast (); updatePreeditText (); updateAuxiliaryText (); } } void PhoneticEditor::cursorUp (void) { if (G_LIKELY (m_lookup_table.cursorUp ())) { updateLookupTableFast (); updatePreeditText (); updateAuxiliaryText (); } } void PhoneticEditor::cursorDown (void) { if (G_LIKELY ((m_lookup_table.cursorPos () == m_lookup_table.size() - 1) && (fillLookupTableByPage () == FALSE))) { return; } if (G_LIKELY (m_lookup_table.cursorDown ())) { updateLookupTableFast (); updatePreeditText (); updateAuxiliaryText (); } } void PhoneticEditor::candidateClicked (guint index, guint button, guint state) { selectCandidateInPage (index); } void PhoneticEditor::reset (void) { m_input_state = STATE_INPUT; m_lookup_table.clear (); m_buffer = ""; zhuyin_reset (m_instance); m_text = ""; resizeInstances (); EnhancedEditor::reset (); } void PhoneticEditor::update (void) { updateLookupTable (); updatePreeditText (); updateAuxiliaryText (); } void PhoneticEditor::commit (const gchar *str) { StaticText text(str); commitText (text); } gboolean PhoneticEditor::selectCandidate (guint index) { if (STATE_CANDIDATE_SHOWN == m_input_state) { int offset = m_phonetic_section->selectCandidate (index); if (0 == offset) return FALSE; m_cursor += offset; m_input_state = STATE_INPUT; updateZhuyin (); update (); return TRUE; } if (STATE_BUILTIN_SYMBOL_SHOWN == m_input_state || STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state) { SymbolSectionPtr symbols = m_symbol_sections[m_input_state]; int offset = symbols->selectCandidate (index); if (0 == offset) return FALSE; erase_input_sequence (m_text, m_cursor, 1); insert_symbol (m_text, m_cursor, symbols->getType (), symbols->getLookup (), symbols->getChoice ()); m_cursor += offset; m_input_state = STATE_INPUT; update (); return TRUE; } if (STATE_USER_SYMBOL_LIST_ALL == m_input_state || STATE_USER_SYMBOL_SHOWN == m_input_state) { SymbolSectionPtr symbols = m_symbol_sections[m_input_state]; int offset = symbols->selectCandidate (index); if (0 == offset) return FALSE; if (1 == offset) { /* direct commit. */ String choice = symbols->getChoice (); String lookup; int ch = find_lookup_key (choice); if (ch != 0) lookup = (gchar) ch; assert (BUILTIN_SYMBOL_TYPE == symbols->getType ()); erase_input_sequence (m_text, m_cursor, 1); insert_symbol (m_text, m_cursor, symbols->getType (), lookup, choice); m_cursor += offset; m_input_state = STATE_INPUT; update (); return TRUE; } if (1 < offset) { /* show candidate. */ String choice = symbols->getChoice (); m_input_state = STATE_USER_SYMBOL_SHOWN; m_symbol_sections[m_input_state]->initCandidates (m_instance, choice); update (); return TRUE; } } return FALSE; } gboolean PhoneticEditor::selectCandidateInPage (guint index) { guint page_size = m_lookup_table.pageSize (); guint cursor_pos = m_lookup_table.cursorPos (); if (G_UNLIKELY (index >= page_size)) return FALSE; index += (cursor_pos / page_size) * page_size; return selectCandidate (index); } gboolean PhoneticEditor::removeCharBefore (void) { if (G_UNLIKELY (m_cursor == 0)) return FALSE; m_cursor --; erase_input_sequence (m_text, m_cursor, 1); updateZhuyin (); update (); return TRUE; } gboolean PhoneticEditor::removeCharAfter (void) { if (G_UNLIKELY (m_cursor == get_enhanced_text_length (m_text))) return FALSE; erase_input_sequence (m_text, m_cursor, 1); updateZhuyin (); update (); return TRUE; } gboolean PhoneticEditor::moveCursorLeft (void) { if (G_UNLIKELY (m_cursor == 0)) return FALSE; /* NOTE: adjust cursor when in parsed phonetic section. */ const String & enhanced_text = m_text; guint cursor = m_cursor; size_t index = 0; size_t start_pos = 0, end_pos = 0; /* move cursor one character back. */ probe_section_start (enhanced_text, m_cursor - 1, cursor, index, start_pos); section_t type = probe_section_quick (enhanced_text, start_pos); /* only when in phonetic section, need adjustments. */ if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); size_t section_len = end_pos - start_pos; zhuyin_instance_t * instance = m_instances[index]; size_t parsed_len = zhuyin_get_parsed_input_length (instance); assert (cursor < section_len); assert (parsed_len <= section_len); /* only when in parsed phonetic section, need adjustments. */ if (cursor < parsed_len) { guint16 offset = 0; zhuyin_get_zhuyin_key_rest_offset (instance, cursor, &offset); /* move to the begin of current syllable. */ ChewingKeyRest * key_rest = NULL; zhuyin_get_zhuyin_key_rest (instance, offset, &key_rest); guint16 begin = 0; zhuyin_get_zhuyin_key_rest_positions (instance, key_rest, &begin, NULL); /* align to the begin of chewing key. */ /* restore cursor variable. */ m_cursor = m_cursor - (cursor + 1 - begin); update (); return TRUE; } } m_cursor --; update (); return TRUE; } gboolean PhoneticEditor::moveCursorRight (void) { if (G_UNLIKELY (m_cursor == get_enhanced_text_length (m_text))) return FALSE; /* NOTE: adjust cursor when in parsed phonetic section. */ const String & enhanced_text = m_text; guint cursor = m_cursor; size_t index = 0; size_t start_pos = 0, end_pos = 0; probe_section_start (enhanced_text, m_cursor, cursor, index, start_pos); section_t type = probe_section_quick (enhanced_text, start_pos); /* only when in phonetic section, need adjustments. */ if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); size_t section_len = end_pos - start_pos; zhuyin_instance_t * instance = m_instances[index]; size_t parsed_len = zhuyin_get_parsed_input_length (instance); assert (cursor < section_len); assert (parsed_len <= section_len); /* only when in parsed phonetic section, need adjustments. */ if (cursor < parsed_len) { guint16 offset = 0; zhuyin_get_zhuyin_key_rest_offset (instance, cursor, &offset); offset ++; guint len = 0; zhuyin_get_n_zhuyin (instance, &len); if (offset < len) { /* move to the begin of next syllable. */ ChewingKeyRest * key_rest = NULL; zhuyin_get_zhuyin_key_rest (instance, offset, &key_rest); guint16 begin = 0; zhuyin_get_zhuyin_key_rest_positions (instance, key_rest, &begin, NULL); /* align to the begin of chewing key. */ m_cursor = m_cursor + (begin - cursor); update (); return TRUE; } else { assert (offset == len); /* align to the end of parsed phonetic section. */ m_cursor = m_cursor + (parsed_len - cursor); update (); return TRUE; } } } m_cursor ++; update (); return TRUE; } gboolean PhoneticEditor::moveCursorToBegin (void) { if (G_UNLIKELY (m_cursor == 0)) return FALSE; m_cursor = 0; update (); return TRUE; } gboolean PhoneticEditor::moveCursorToEnd (void) { if (G_UNLIKELY (m_cursor == get_enhanced_text_length (m_text))) return FALSE; m_cursor = get_enhanced_text_length (m_text); update (); return TRUE; } void PhoneticEditor::resizeInstances (void) { size_t num = get_number_of_phonetic_sections (m_text); /* re-allocate the zhuyin instances */ if (num > m_instances.size ()) { /* need more instances. */ for (size_t i = m_instances.size (); i < num; ++i) { /* allocate one instance */ zhuyin_instance_t * instance = LibZhuyinBackEnd::instance (). allocZhuyinInstance (); assert (NULL != instance); m_instances.push_back (instance); } } if (num < m_instances.size ()) { /* free some instances. */ for (size_t i = num; i < m_instances.size (); ++i) { LibZhuyinBackEnd::instance ().freeZhuyinInstance (m_instances[i]); m_instances[i] = NULL; } m_instances.resize (num); } } guint PhoneticEditor::getZhuyinCursor (void) { /* decrement the cursor variable to calculate the zhuyin cursor. */ guint cursor = m_cursor; guint zhuyin_cursor = 0; const String & enhanced_text = m_text; size_t index = 0; size_t start_pos = 0, end_pos = 0; while (end_pos != enhanced_text.size ()) { if (0 == cursor) break; section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); size_t section_len = end_pos - start_pos; zhuyin_instance_t * instance = m_instances[index]; size_t parsed_len = zhuyin_get_parsed_input_length (instance); assert (parsed_len <= section_len); if (cursor >= parsed_len) { cursor -= parsed_len; guint len = 0; zhuyin_get_n_zhuyin (instance, &len); zhuyin_cursor += len; } else { guint16 inner_cursor = 0; zhuyin_get_zhuyin_key_rest_offset (instance, cursor, &inner_cursor); zhuyin_cursor += inner_cursor; cursor = 0; } if (0 == cursor) break; if (cursor >= section_len - parsed_len) { /* except for DaChen26 scheme here. */ cursor -= section_len - parsed_len; zhuyin_cursor += section_len - parsed_len; } else { zhuyin_cursor += cursor; cursor = 0; } ++ index; } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); --cursor; zhuyin_cursor += g_utf8_strlen (choice, -1); } start_pos = end_pos; } return zhuyin_cursor; } gboolean PhoneticEditor::insertPunct (guint ch) { /* for punctuations. */ if (is_half_punct (ch)) { if (m_props.modeFullPunct ()) { String choice; assert (half_punct_to_full_punct (ch, choice)); String lookup; int ch = find_lookup_key (choice); if (ch != 0) lookup = (gchar) ch; insert_symbol (m_text, m_cursor++, BUILTIN_SYMBOL_TYPE, lookup, choice); } else { String choice = (gchar)ch; insert_symbol (m_text, m_cursor++, BUILTIN_SYMBOL_TYPE, "", choice); } return TRUE; } return FALSE; } gboolean PhoneticEditor::insertEnglish (guint ch) { /* for English. */ if (is_half_english (ch)) { if (m_props.modeFullEnglish ()) { String choice; assert (half_english_to_full_english (ch, choice)); String lookup; int ch = find_lookup_key (choice); if (ch != 0) lookup = (gchar) ch; insert_symbol (m_text, m_cursor++, BUILTIN_SYMBOL_TYPE, lookup, choice); } else { String choice = (gchar) ch; insert_symbol (m_text, m_cursor++, BUILTIN_SYMBOL_TYPE, "", choice); } return TRUE; } return FALSE; } gboolean PhoneticEditor::insertNumbers (guint ch) { /* for input pad numbers. */ static const guint keyvals[] = {IBUS_KP_Delete, IBUS_KP_Insert, IBUS_KP_End, IBUS_KP_Down, IBUS_KP_Next, IBUS_KP_Left, IBUS_KP_Begin, IBUS_KP_Right, IBUS_KP_Home, IBUS_KP_Up, IBUS_KP_Prior}; static const char numbers[] = {'.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; assert (G_N_ELEMENTS (keyvals) == G_N_ELEMENTS (numbers)); if (!m_config.alwaysInputNumbers ()) return FALSE; for (size_t i = 0; i < G_N_ELEMENTS (keyvals); ++i) { if (keyvals[i] == ch) { String choice; choice += numbers[i]; insert_symbol (m_text, m_cursor++, BUILTIN_SYMBOL_TYPE, "", choice); return TRUE; } } return FALSE; } gboolean PhoneticEditor::prepareCandidates (void) { const String & enhanced_text = m_text; guint cursor = m_cursor; size_t index = 0; size_t start_pos = 0, end_pos = 0; probe_section_start (enhanced_text, m_cursor, cursor, index, start_pos); /* deal with candidates */ if (m_cursor < get_enhanced_text_length (enhanced_text)) { section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); size_t section_len = end_pos - start_pos; zhuyin_instance_t * instance = m_instances[index]; size_t parsed_len = zhuyin_get_parsed_input_length (instance); assert (cursor < section_len); assert (parsed_len <= section_len); if (cursor >= parsed_len) { String lookup; lookup += section[cursor]; m_input_state = STATE_BOPOMOFO_SYMBOL_SHOWN; m_symbol_sections[m_input_state]->initCandidates (m_instance, lookup); update (); return TRUE; } else { m_input_state = STATE_CANDIDATE_SHOWN; m_phonetic_section->initCandidates (instance, cursor); update (); return TRUE; } } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); if (BUILTIN_SYMBOL_TYPE == type) { m_input_state = STATE_BUILTIN_SYMBOL_SHOWN; bool retval = m_symbol_sections[m_input_state]->initCandidates (m_instance, lookup); if (!retval) { m_input_state = STATE_INPUT; return FALSE; } } else if (BOPOMOFO_SYMBOL_TYPE == type) { m_input_state = STATE_BOPOMOFO_SYMBOL_SHOWN; bool retval = m_symbol_sections[m_input_state]->initCandidates (m_instance, lookup); if (!retval) { m_input_state = STATE_INPUT; return FALSE; } } else assert (FALSE); update (); return TRUE; } } return FALSE; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZPhoneticEditor.h000066400000000000000000000110701241117270600220030ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_BASE_EDITOR_H_ #define __ZY_LIB_ZHUYIN_BASE_EDITOR_H_ #include #include "ZYLookupTable.h" #include "ZYZEnhancedEditor.h" #include "ZYSymbolLookup.h" #include namespace ZY { class PhoneticSection; typedef std::shared_ptr PhoneticSectionPtr; class SymbolSection; typedef std::shared_ptr SymbolSectionPtr; class PhoneticEditor : public EnhancedEditor { friend class SymbolSection; friend class PhoneticSection; protected: typedef std::vector zhuyin_instance_vec; public: PhoneticEditor (ZhuyinProperties & props, Config & config); virtual ~PhoneticEditor (void); public: /* virtual functions */ virtual void pageUp (void); virtual void pageDown (void); virtual void cursorUp (void); virtual void cursorDown (void); virtual void update (void); virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual gboolean processEscape (guint keyval, guint keycode, guint modifiers); virtual gboolean processEnter (guint keyval, guint keycode, guint modifiers); virtual gboolean processSpace (guint keyval, guint keycode, guint modifiers); virtual gboolean processFunctionKey (guint keyval, guint keycode, guint modifiers); virtual gboolean processShowCandidateKey (guint keyval, guint keycode, guint modifiers); virtual gboolean processCandidateKey (guint keyval, guint keycode, guint modifiers); virtual gboolean processEasySymbolKey (guint keyval, guint keycode, guint modifiers); virtual gboolean processUserSymbolKey (guint keyval, guint keycode, guint modifiers); virtual void updateLookupTable (); virtual void updateLookupTableFast (); virtual void updateLookupTableLabel (); virtual gboolean fillLookupTableByPage (); virtual gboolean insertPunct (guint ch); virtual gboolean insertEnglish (guint ch); virtual gboolean insertNumbers (guint ch); protected: gboolean prepareCandidates (void); gboolean selectCandidate (guint i); gboolean selectCandidateInPage (guint i); void commit (const gchar *str); /* pure virtual functions */ virtual gboolean insert (gint ch) = 0; virtual gboolean removeCharBefore (void); virtual gboolean removeCharAfter (void); virtual gboolean moveCursorLeft (void); virtual gboolean moveCursorRight (void); virtual gboolean moveCursorToBegin (void); virtual gboolean moveCursorToEnd (void); virtual void commit (void) = 0; virtual void updateAuxiliaryText (void) = 0; virtual void updatePreeditText (void) = 0; virtual void updateZhuyin (void) = 0; /* for class DaChen26Editor to override this. */ virtual guint getZhuyinCursor (void); void resizeInstances (void); gboolean loadEasySymbolFile (const gchar * filename); /* varibles */ LookupTable m_lookup_table; String m_buffer; /* use libzhuyin here. */ zhuyin_instance_t *m_instance; enum InputState { STATE_INPUT = 0, // input state STATE_CANDIDATE_SHOWN, // candidates shown state STATE_BUILTIN_SYMBOL_SHOWN, // built-in symbol shown state STATE_BOPOMOFO_SYMBOL_SHOWN, // bopomofo symbol shown state STATE_USER_SYMBOL_LIST_ALL, // user symbol input state STATE_USER_SYMBOL_SHOWN, // user symbol shown state STATE_LAST, } m_input_state; SymbolSectionPtr m_symbol_sections[STATE_LAST]; PhoneticSectionPtr m_phonetic_section; zhuyin_instance_vec m_instances; SymbolLookup m_easy_symbols; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZPhoneticSection.cc000066400000000000000000000070711241117270600223250ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZPhoneticSection.h" #include #include "ZYZhuyinProperties.h" #include "ZYTradSimpConverter.h" namespace ZY { PhoneticSection::PhoneticSection (PhoneticEditor & editor, ZhuyinProperties & props) : m_editor (editor), m_props (props) { } PhoneticSection::~PhoneticSection () { } bool PhoneticSection::initCandidates (zhuyin_instance_t * instance, int cursor) { m_instance = instance; m_cursor = cursor; guint16 offset = 0; zhuyin_get_zhuyin_key_rest_offset (instance, cursor, &offset); zhuyin_guess_candidates (m_instance, offset); return true; } bool PhoneticSection::fillLookupTableByPage () { LookupTable & lookup_table = getLookupTable (); guint len = 0; zhuyin_get_n_candidate (m_instance, &len); guint filled_nr = lookup_table.size (); guint page_size = lookup_table.pageSize (); /* fill lookup table by libzhuyin get candidates. */ guint need_nr = MIN (page_size, len - filled_nr); g_assert (need_nr >=0); if (need_nr == 0) return FALSE; String word; for (guint i = filled_nr; i < filled_nr + need_nr; i++) { if (i >= len) /* no more candidates */ break; lookup_candidate_t * candidate = NULL; zhuyin_get_candidate (m_instance, i, &candidate); const gchar * phrase_string = NULL; zhuyin_get_candidate_string (m_instance, candidate, &phrase_string); /* show get candidates. */ if (G_LIKELY (m_props.modeTrad ())) { word = phrase_string; } else { /* Simplified Chinese */ word.truncate (0); TradSimpConverter::tradToSimp (phrase_string, word); } Text text (word); lookup_table.appendCandidate (text); } return TRUE; } int PhoneticSection::selectCandidate (guint index) { guint16 prev_pos = m_cursor, cur_pos = 0; ChewingKeyRest * key_rest = NULL; guint len = 0; zhuyin_get_n_candidate (m_instance, &len); if (index >= len) return 0; lookup_candidate_t * candidate = NULL; zhuyin_get_candidate (m_instance, index, &candidate); guint16 offset = 0; zhuyin_get_zhuyin_key_rest_offset (m_instance, m_cursor, &offset); offset = zhuyin_choose_candidate (m_instance, offset, candidate); zhuyin_get_n_zhuyin (m_instance, &len); if (offset < len) { zhuyin_get_zhuyin_key_rest (m_instance, offset, &key_rest); zhuyin_get_zhuyin_key_rest_positions (m_instance, key_rest, &cur_pos, NULL); } else { assert (offset == len); cur_pos = zhuyin_get_parsed_input_length (m_instance); } return cur_pos - prev_pos; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZPhoneticSection.h000066400000000000000000000031541241117270600221650ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_PHONETIC_SECTION_H_ #define __ZY_LIB_ZHUYIN_PHONETIC_SECTION_H_ #include #include "ZYString.h" #include "ZYZPhoneticEditor.h" namespace ZY { class PhoneticSection { public: PhoneticSection (PhoneticEditor & editor, ZhuyinProperties & props); virtual ~PhoneticSection (); public: virtual bool initCandidates (zhuyin_instance_t * instance, int cursor); virtual bool fillLookupTableByPage (); virtual int selectCandidate (guint index); protected: LookupTable & getLookupTable () { return m_editor.m_lookup_table; } protected: PhoneticEditor & m_editor; ZhuyinProperties & m_props; /* other variables. */ zhuyin_instance_t * m_instance; int m_cursor; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZPinyinEditor.cc000066400000000000000000000147241241117270600216470ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZPinyinEditor.h" #include #include "ZYConfig.h" #include "ZYLibZhuyin.h" #include "ZYZhuyinProperties.h" #include "ZYTradSimpConverter.h" #include "ZYEnhancedText.h" using namespace ZY; #define IS_PINYIN(ch) (('a' <= ch && ch <= 'z')||('1'<=ch && ch <= '5')) PinyinEditor::PinyinEditor (ZhuyinProperties & props, Config & config) : PhoneticEditor (props, config) { m_instance = LibZhuyinBackEnd::instance ().allocZhuyinInstance (); } PinyinEditor::~PinyinEditor (void) { reset (); LibZhuyinBackEnd::instance ().freeZhuyinInstance (m_instance); m_instance = NULL; } void PinyinEditor::commit (void) { if (G_UNLIKELY (m_preedit_text.empty ())) return; for (size_t i = 0; i < m_instances.size (); ++i) { zhuyin_train (m_instances[i]); } LibZhuyinBackEnd::instance ().modified (); PhoneticEditor::commit (m_preedit_text.c_str ()); reset (); } void PinyinEditor::reset (void) { PhoneticEditor::reset (); } void PinyinEditor::updateZhuyin (void) { const String & enhanced_text = m_text; resizeInstances (); size_t index = 0; size_t start_pos = 0, end_pos = 0; while (end_pos != enhanced_text.size ()) { section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); zhuyin_instance_t * instance = m_instances[index]; zhuyin_parse_more_full_pinyins (instance, section.c_str ()); zhuyin_guess_sentence (instance); ++index; } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); } start_pos = end_pos; } return; } void PinyinEditor::updateAuxiliaryText (void) { /* libchewing doesn't use the auxiliary text, always hide. */ return; } void PinyinEditor::updatePreeditText (void) { if (G_UNLIKELY (m_text.empty ())) { hidePreeditText (); return; } const String & enhanced_text = m_text; m_preedit_text.clear (); size_t index = 0; size_t start_pos = 0, end_pos = 0; while (end_pos != enhanced_text.size ()) { section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); zhuyin_instance_t * instance = m_instances[index]; char * sentence = NULL; zhuyin_get_sentence (instance, &sentence); if (sentence) m_preedit_text += sentence; g_free (sentence); size_t len = zhuyin_get_parsed_input_length (instance); m_preedit_text += section.substr (len); ++index; } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); m_preedit_text += choice; } start_pos = end_pos; } m_buffer.clear (); if (m_props.modeTrad ()) { m_buffer = m_preedit_text; } else { TradSimpConverter::tradToSimp (m_preedit_text.c_str (), m_buffer); } m_preedit_text = m_buffer; StaticText preedit_text (m_preedit_text); /* underline */ preedit_text.appendAttribute (IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1); /* calcuate the cursor position. */ size_t cursor = getZhuyinCursor (); Editor::updatePreeditText (preedit_text, cursor, TRUE); return; } gboolean PinyinEditor::insert (gint ch) { if (IS_PINYIN (ch)) { insert_phonetic (m_text, m_cursor++, ch); updateZhuyin (); update (); return TRUE; } if (insertPunct (ch)) { updateZhuyin (); update (); return TRUE; } if (insertEnglish (ch)) { updateZhuyin (); update (); return TRUE; } if (insertNumbers (ch)) { updateZhuyin (); update (); return TRUE; } return FALSE; } gboolean PinyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { modifiers &= (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK | IBUS_SUPER_MASK | IBUS_HYPER_MASK | IBUS_META_MASK | IBUS_LOCK_MASK); if (processEscape (keyval, keycode, modifiers)) return TRUE; if (STATE_INPUT == m_input_state) { if (processEasySymbolKey (keyval, keycode, modifiers)) return TRUE; if (processUserSymbolKey (keyval, keycode, modifiers)) return TRUE; if (insert (keyval)) return TRUE; if (processEnter (keyval, keycode, modifiers)) return TRUE; if (processFunctionKey (keyval, keycode, modifiers)) return TRUE; if (processShowCandidateKey (keyval, keycode, modifiers)) return TRUE; } if (STATE_CANDIDATE_SHOWN == m_input_state || STATE_BUILTIN_SYMBOL_SHOWN == m_input_state || STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state || STATE_USER_SYMBOL_LIST_ALL == m_input_state || STATE_USER_SYMBOL_SHOWN == m_input_state) { if (processSpace (keyval, keycode, modifiers)) return TRUE; if (processCandidateKey (keyval, keycode, modifiers)) return TRUE; } return FALSE; } ibus-libzhuyin-1.6.99.20140929/src/ZYZPinyinEditor.h000066400000000000000000000027731241117270600215120ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_PINYIN_EDITOR_H_ #define __ZY_LIB_ZHUYIN_PINYIN_EDITOR_H_ #include "ZYZPhoneticEditor.h" namespace ZY { class Config; class PinyinEditor : public PhoneticEditor { using PhoneticEditor::InputState; public: PinyinEditor (ZhuyinProperties & props, Config & config); virtual ~PinyinEditor (void); protected: gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void updatePreeditText (); virtual void updateAuxiliaryText (); virtual void updateZhuyin (void); void commit (); void reset (); gboolean insert (gint ch); protected: String m_preedit_text; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZSymbolSection.h000066400000000000000000000035201241117270600216560ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_SYMBOL_SECTION_H_ #define __ZY_LIB_ZHUYIN_SYMBOL_SECTION_H_ #include "ZYString.h" #include "ZYZPhoneticEditor.h" #include namespace ZY { class ZhuyinProperties; class SymbolSection { public: SymbolSection (PhoneticEditor & editor, ZhuyinProperties & props) : m_editor (editor), m_props(props) {} virtual ~SymbolSection () {} public: virtual bool initCandidates (zhuyin_instance_t * instance, const String & hint) = 0; virtual bool fillLookupTableByPage () = 0; virtual int selectCandidate (guint index) = 0; public: String getType () {return m_type; } String getLookup () {return m_lookup; } String getChoice () {return m_choice; } protected: LookupTable & getLookupTable () { return m_editor.m_lookup_table; } protected: PhoneticEditor & m_editor; ZhuyinProperties & m_props; /* other variables. */ String m_type; String m_lookup; String m_choice; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZUserSymbolListAllSection.cc000066400000000000000000000062641241117270600241500ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZUserSymbolListAllSection.h" #include #include "ZYSymbols.h" namespace ZY { UserSymbolListAllSection::UserSymbolListAllSection (PhoneticEditor & editor, ZhuyinProperties & props) : SymbolSection (editor, props) { m_type = BUILTIN_SYMBOL_TYPE; /* load user symbol. */ gchar * path = g_build_filename (g_get_user_config_dir (), "ibus", "libzhuyin", "usersymbol.txt", NULL); loadUserSymbolFile (".." G_DIR_SEPARATOR_S "data" G_DIR_SEPARATOR_S "usersymbol.txt") || loadUserSymbolFile (path) || loadUserSymbolFile (PKGDATADIR G_DIR_SEPARATOR_S "usersymbol.txt"); g_free(path); } UserSymbolListAllSection::~UserSymbolListAllSection () { } gboolean UserSymbolListAllSection::loadUserSymbolFile (const gchar * filename) { gboolean retval = m_user_symbols.loadFromFile (filename); return retval; } bool UserSymbolListAllSection::initCandidates (zhuyin_instance_t * instance, const String & lookup) { if (!lookup) return false; m_candidates.clear (); assert ("`" == lookup); m_lookup = lookup; /* cache the symbols. */ const std::vector & indexes = m_user_symbols.getIndexes (); for (size_t i = 0; i < indexes.size (); ++i) { m_candidates.push_back (indexes[i]); } return true; } bool UserSymbolListAllSection::fillLookupTableByPage () { LookupTable & lookup_table = getLookupTable (); guint len = m_candidates.size (); guint filled_nr = lookup_table.size (); guint page_size = lookup_table.pageSize (); /* fill lookup table by libzhuyin get candidates. */ guint need_nr = MIN (page_size, len - filled_nr); g_assert (need_nr >=0); if (need_nr == 0) return FALSE; for (guint i = filled_nr; i < filled_nr + need_nr; i++) { if (i >= len) /* no more candidates */ break; Text text (m_candidates[i]); lookup_table.appendCandidate (text); } return TRUE; } int UserSymbolListAllSection::selectCandidate (guint index) { if (index >= m_candidates.size ()) return 0; m_choice = m_user_symbols.find (m_candidates[index]); return m_choice.utf8Length (); } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZUserSymbolListAllSection.h000066400000000000000000000033171241117270600240060ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_USER_SYMBOL_LIST_ALL_SECTION_H_ #define __ZY_LIB_ZHUYIN_USER_SYMBOL_LIST_ALL_SECTION_H_ #include "ZYZSymbolSection.h" #include #include "ZYSymbolLookup.h" namespace ZY { class ZhuyinProperties; class UserSymbolListAllSection : public SymbolSection { typedef std::vector::iterator iterator_t; public: UserSymbolListAllSection (PhoneticEditor & editor, ZhuyinProperties & props); virtual ~UserSymbolListAllSection (); public: virtual bool initCandidates (zhuyin_instance_t * instance, const String & lookup); virtual bool fillLookupTableByPage (); virtual int selectCandidate (guint index); protected: gboolean loadUserSymbolFile (const gchar * filename); std::vector m_candidates; SymbolLookup m_user_symbols; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZUserSymbolShownSection.cc000066400000000000000000000053271241117270600237010ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZUserSymbolShownSection.h" #include #include "ZYSymbols.h" namespace ZY { UserSymbolShownSection::UserSymbolShownSection (PhoneticEditor & editor, ZhuyinProperties & props) : SymbolSection (editor, props) { m_type = BUILTIN_SYMBOL_TYPE; } UserSymbolShownSection::~UserSymbolShownSection () { } bool UserSymbolShownSection::initCandidates (zhuyin_instance_t * instance, const String & lookup) { if (!lookup) return false; m_candidates.clear (); m_lookup = lookup; /* get the symbols from lookup string. */ const gchar * str = m_lookup.c_str (); gboolean valid = g_utf8_validate (str, -1, NULL); g_return_val_if_fail (valid, false); while (*str) { gunichar unichar = g_utf8_get_char (str); String utf8ch; utf8ch.appendUnichar (unichar); m_candidates.push_back (utf8ch); str = g_utf8_next_char (str); } return true; } bool UserSymbolShownSection::fillLookupTableByPage () { LookupTable & lookup_table = getLookupTable (); guint len = m_candidates.size (); guint filled_nr = lookup_table.size (); guint page_size = lookup_table.pageSize (); /* fill lookup table by libzhuyin get candidates. */ guint need_nr = MIN (page_size, len - filled_nr); g_assert (need_nr >=0); if (need_nr == 0) return FALSE; for (guint i = filled_nr; i < filled_nr + need_nr; i++) { if (i >= len) /* no more candidates */ break; Text text (m_candidates[i]); lookup_table.appendCandidate (text); } return TRUE; } int UserSymbolShownSection::selectCandidate (guint index) { if (index >= m_candidates.size ()) return 0; m_choice = m_candidates[index]; assert (1 == m_choice.utf8Length ()); return 1; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZUserSymbolShownSection.h000066400000000000000000000031101241117270600235270ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_USER_SYMBOL_SHOWN_SECTION_H_ #define __ZY_LIB_ZHUYIN_USER_SYMBOL_SHOWN_SECTION_H_ #include "ZYZSymbolSection.h" #include namespace ZY { class ZhuyinProperties; class UserSymbolShownSection: public SymbolSection { typedef std::vector::iterator iterator_t; public: UserSymbolShownSection (PhoneticEditor & editor, ZhuyinProperties & props); virtual ~UserSymbolShownSection (); public: virtual bool initCandidates (zhuyin_instance_t * instance, const String & lookup); virtual bool fillLookupTableByPage (); virtual int selectCandidate (guint index); protected: std::vector m_candidates; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZZhuyinEditor.cc000066400000000000000000000155431241117270600216670ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZZhuyinEditor.h" #include #include "ZYConfig.h" #include "ZYLibZhuyin.h" #include "ZYZhuyinProperties.h" #include "ZYTradSimpConverter.h" #include "ZYEnhancedText.h" using namespace ZY; ZhuyinEditor::ZhuyinEditor (ZhuyinProperties & props, Config & config) : PhoneticEditor (props, config) { m_instance = LibZhuyinBackEnd::instance ().allocZhuyinInstance (); } ZhuyinEditor::~ZhuyinEditor (void) { reset (); LibZhuyinBackEnd::instance ().freeZhuyinInstance (m_instance); m_instance = NULL; } void ZhuyinEditor::commit (void) { if (G_UNLIKELY (m_preedit_text.empty ())) return; for (size_t i = 0; i < m_instances.size (); ++i) { zhuyin_train (m_instances[i]); } LibZhuyinBackEnd::instance ().modified (); PhoneticEditor::commit (m_preedit_text.c_str ()); reset (); } void ZhuyinEditor::reset (void) { PhoneticEditor::reset (); } void ZhuyinEditor::updateZhuyin (void) { const String & enhanced_text = m_text; resizeInstances (); size_t index = 0; size_t start_pos = 0, end_pos = 0; while (end_pos != enhanced_text.size ()) { section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); zhuyin_instance_t * instance = m_instances[index]; zhuyin_parse_more_chewings (instance, section.c_str ()); zhuyin_guess_sentence (instance); ++index; } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); } start_pos = end_pos; } return; } void ZhuyinEditor::updateAuxiliaryText (void) { /* libchewing doesn't use the auxiliary text, always hide. */ return; } void ZhuyinEditor::updatePreeditText (void) { if (G_UNLIKELY (m_text.empty ())) { hidePreeditText (); return; } const String & enhanced_text = m_text; m_preedit_text.clear (); size_t index = 0; size_t start_pos = 0, end_pos = 0; while (end_pos != enhanced_text.size ()) { section_t type = probe_section_quick (enhanced_text, start_pos); if (PHONETIC_SECTION == type) { String section; get_phonetic_section (enhanced_text, start_pos, end_pos, section); zhuyin_instance_t * instance = m_instances[index]; char * sentence = NULL; zhuyin_get_sentence (instance, &sentence); if (sentence) m_preedit_text += sentence; g_free (sentence); size_t len = zhuyin_get_parsed_input_length (instance); for (size_t i = len; i < section.size (); ++i) { char sym = section[i]; gchar ** symbols = NULL; /* append bopomofo symbol except for DaChen26. */ assert (zhuyin_in_chewing_keyboard (m_instance, sym, &symbols)); assert (NULL != symbols[0]); m_preedit_text += symbols[0]; g_strfreev (symbols); } ++index; } if (SYMBOL_SECTION == type) { String type, lookup, choice; get_symbol_section (enhanced_text, start_pos, end_pos, type, lookup, choice); m_preedit_text += choice; } start_pos = end_pos; } m_buffer.clear (); if (m_props.modeTrad ()) { m_buffer = m_preedit_text; } else { TradSimpConverter::tradToSimp (m_preedit_text.c_str (), m_buffer); } m_preedit_text = m_buffer; StaticText preedit_text (m_preedit_text); /* underline */ preedit_text.appendAttribute (IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1); /* calcuate the cursor position. */ size_t cursor = getZhuyinCursor (); Editor::updatePreeditText (preedit_text, cursor, TRUE); return; } gboolean ZhuyinEditor::insert (gint ch) { gchar ** symbols = NULL; if (zhuyin_in_chewing_keyboard (m_instance, ch, &symbols)) { g_strfreev (symbols); insert_phonetic (m_text, m_cursor++, ch); updateZhuyin (); update (); return TRUE; } if (insertPunct (ch)) { updateZhuyin (); update (); return TRUE; } if (insertEnglish (ch)) { updateZhuyin (); update (); return TRUE; } if (insertNumbers (ch)) { updateZhuyin (); update (); return TRUE; } return FALSE; } gboolean ZhuyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { modifiers &= (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK | IBUS_SUPER_MASK | IBUS_HYPER_MASK | IBUS_META_MASK | IBUS_LOCK_MASK); if (processEscape (keyval, keycode, modifiers)) return TRUE; if (STATE_INPUT == m_input_state) { if (processEasySymbolKey (keyval, keycode, modifiers)) return TRUE; if (processUserSymbolKey (keyval, keycode, modifiers)) return TRUE; if (insert (keyval)) return TRUE; if (processEnter (keyval, keycode, modifiers)) return TRUE; if (processFunctionKey (keyval, keycode, modifiers)) return TRUE; if (processShowCandidateKey (keyval, keycode, modifiers)) return TRUE; } if (STATE_CANDIDATE_SHOWN == m_input_state || STATE_BUILTIN_SYMBOL_SHOWN == m_input_state || STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state || STATE_USER_SYMBOL_LIST_ALL == m_input_state || STATE_USER_SYMBOL_SHOWN == m_input_state) { if (processSpace (keyval, keycode, modifiers)) return TRUE; if (processCandidateKey (keyval, keycode, modifiers)) return TRUE; } return FALSE; } ibus-libzhuyin-1.6.99.20140929/src/ZYZZhuyinEditor.h000066400000000000000000000027731241117270600215320ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_ZHUYIN_EDITOR_H_ #define __ZY_LIB_ZHUYIN_ZHUYIN_EDITOR_H_ #include "ZYZPhoneticEditor.h" namespace ZY { class Config; class ZhuyinEditor : public PhoneticEditor { using PhoneticEditor::InputState; public: ZhuyinEditor (ZhuyinProperties & props, Config & config); virtual ~ZhuyinEditor (void); protected: gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void updatePreeditText (); virtual void updateAuxiliaryText (); virtual void updateZhuyin (void); void commit (); void reset (); gboolean insert (gint ch); protected: String m_preedit_text; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZZhuyinEngine.cc000066400000000000000000000170411241117270600216410ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2014 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZZhuyinEngine.h" #include #include #include "ZYConfig.h" #include "ZYZConfig.h" #include "ZYRawEditor.h" #include "ZYFallbackEditor.h" #include "ZYZZhuyinEditor.h" #include "ZYZPinyinEditor.h" using namespace ZY; /* constructor */ ZhuyinEngine::ZhuyinEngine (IBusEngine *engine) : Engine (engine), m_props (ZhuyinConfig::instance ()), m_prev_pressed_key (IBUS_VoidSymbol), m_input_mode (MODE_INIT), m_fallback_editor (new FallbackEditor (m_props, ZhuyinConfig::instance ())) { gint i; m_zhuyin_scheme = ZhuyinConfig::instance ().keyboardLayout (); switch (m_zhuyin_scheme) { case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: m_editors[MODE_INIT].reset (new ZhuyinEditor (m_props, ZhuyinConfig::instance ())); break; case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: m_editors[MODE_INIT].reset (new PinyinEditor (m_props, ZhuyinConfig::instance ())); break; default: assert (FALSE); } m_editors[MODE_RAW].reset (new RawEditor (m_props, ZhuyinConfig::instance ())); m_props.signalUpdateProperty ().connect (std::bind (&ZhuyinEngine::updateProperty, this, _1)); for (i = MODE_INIT; i < MODE_LAST; i ++) { connectEditorSignals (m_editors[i]); } connectEditorSignals (m_fallback_editor); } /* destructor */ ZhuyinEngine::~ZhuyinEngine (void) { } gboolean ZhuyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) { gboolean retval = FALSE; if (contentIsPassword ()) return retval; /* check Shift or Ctrl + Release hotkey, * and then ignore other Release key event */ if (modifiers & IBUS_RELEASE_MASK) { /* press and release keyval are same, * and no other key event between the press and release key event */ gboolean triggered = FALSE; if (m_prev_pressed_key == keyval) { if (keyval == IBUS_Shift_L || keyval == IBUS_Shift_R) triggered = TRUE; } if (triggered && m_editors[m_input_mode]->text ().empty ()) { /* switch input editor. */ m_props.toggleModeChinese (); switch (m_input_mode) { case MODE_INIT: m_input_mode = MODE_RAW; break; case MODE_RAW: m_input_mode = MODE_INIT; break; default: assert (FALSE); } return TRUE; } if (m_input_mode == MODE_INIT && m_editors[MODE_INIT]->text ().empty ()) { /* If it is init mode, and no any previous input text, * we will let client applications to handle release key event */ return FALSE; } else { return TRUE; } } if (m_props.modeChinese ()) { retval = m_editors[m_input_mode]->processKeyEvent (keyval, keycode, modifiers); } if (G_UNLIKELY (!retval)) retval = m_fallback_editor->processKeyEvent (keyval, keycode, modifiers); /* store ignored key event by editors */ m_prev_pressed_key = retval ? IBUS_VoidSymbol : keyval; return retval; } void ZhuyinEngine::focusIn (void) { /* TODO: check memory leak here.*/ const ZhuyinScheme scheme = ZhuyinConfig::instance ().keyboardLayout (); if (scheme != m_zhuyin_scheme) { switch (scheme) { case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: m_editors[MODE_INIT].reset (new ZhuyinEditor (m_props, ZhuyinConfig::instance ())); connectEditorSignals (m_editors[MODE_INIT]); break; case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: m_editors[MODE_INIT].reset (new PinyinEditor (m_props, ZhuyinConfig::instance ())); connectEditorSignals (m_editors[MODE_INIT]); break; default: assert (FALSE); } m_zhuyin_scheme = scheme; } registerProperties (m_props.properties ()); } void ZhuyinEngine::focusOut (void) { Engine::focusOut (); reset (); } void ZhuyinEngine::reset (void) { m_prev_pressed_key = IBUS_VoidSymbol; m_input_mode = MODE_INIT; for (gint i = 0; i < MODE_LAST; i++) { m_editors[i]->reset (); } } void ZhuyinEngine::enable (void) { m_props.reset (); } void ZhuyinEngine::disable (void) { } void ZhuyinEngine::pageUp (void) { m_editors[m_input_mode]->pageUp (); } void ZhuyinEngine::pageDown (void) { m_editors[m_input_mode]->pageDown (); } void ZhuyinEngine::cursorUp (void) { m_editors[m_input_mode]->cursorUp (); } void ZhuyinEngine::cursorDown (void) { m_editors[m_input_mode]->cursorDown (); } inline void ZhuyinEngine::showSetupDialog (void) { g_spawn_command_line_async (LIBEXECDIR"/ibus-setup-libzhuyin zhuyin", NULL); } gboolean ZhuyinEngine::propertyActivate (const char *prop_name, guint prop_state) { const static String setup ("setup"); if (m_props.propertyActivate (prop_name, prop_state)) { return TRUE; } else if (setup == prop_name) { showSetupDialog (); return TRUE; } return FALSE; } void ZhuyinEngine::candidateClicked (guint index, guint button, guint state) { m_editors[m_input_mode]->candidateClicked (index, button, state); } void ZhuyinEngine::commitText (Text & text) { Engine::commitText (text); } void ZhuyinEngine::connectEditorSignals (EditorPtr editor) { editor->signalCommitText ().connect ( std::bind (&ZhuyinEngine::commitText, this, _1)); editor->signalUpdatePreeditText ().connect ( std::bind (&ZhuyinEngine::updatePreeditText, this, _1, _2, _3)); editor->signalShowPreeditText ().connect ( std::bind (&ZhuyinEngine::showPreeditText, this)); editor->signalHidePreeditText ().connect ( std::bind (&ZhuyinEngine::hidePreeditText, this)); editor->signalUpdateAuxiliaryText ().connect ( std::bind (&ZhuyinEngine::updateAuxiliaryText, this, _1, _2)); editor->signalShowAuxiliaryText ().connect ( std::bind (&ZhuyinEngine::showAuxiliaryText, this)); editor->signalHideAuxiliaryText ().connect ( std::bind (&ZhuyinEngine::hideAuxiliaryText, this)); editor->signalUpdateLookupTable ().connect ( std::bind (&ZhuyinEngine::updateLookupTable, this, _1, _2)); editor->signalUpdateLookupTableFast ().connect ( std::bind (&ZhuyinEngine::updateLookupTableFast, this, _1, _2)); editor->signalShowLookupTable ().connect ( std::bind (&ZhuyinEngine::showLookupTable, this)); editor->signalHideLookupTable ().connect ( std::bind (&ZhuyinEngine::hideLookupTable, this)); } ibus-libzhuyin-1.6.99.20140929/src/ZYZZhuyinEngine.h000066400000000000000000000042471241117270600215070ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * Copyright (c) 2011 Peng Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_LIB_ZHUYIN_ZHUYIN_ENGINE_H_ #define __ZY_LIB_ZHUYIN_ZHUYIN_ENGINE_H_ #include #include "ZYEngine.h" #include "ZYZhuyinProperties.h" namespace ZY { class ZhuyinEngine : public Engine { public: ZhuyinEngine (IBusEngine *engine); ~ZhuyinEngine (void); //virtual functions gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); void focusIn (void); void focusOut (void); void reset (void); void enable (void); void disable (void); void pageUp (void); void pageDown (void); void cursorUp (void); void cursorDown (void); gboolean propertyActivate (const gchar *prop_name, guint prop_state); void candidateClicked (guint index, guint button, guint state); private: gboolean processPunct (guint keyval, guint keycode, guint modifiers); void showSetupDialog (void); void connectEditorSignals (EditorPtr editor); void commitText (Text & text); private: ZhuyinProperties m_props; guint m_prev_pressed_key; enum { MODE_INIT = 0, // init mode MODE_RAW, // raw mode MODE_LAST, } m_input_mode; ZhuyinScheme m_zhuyin_scheme; EditorPtr m_editors[MODE_LAST]; EditorPtr m_fallback_editor; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/ZYZhuyinProperties.cc000066400000000000000000000175011241117270600224370ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ZYZhuyinProperties.h" #include #include "ZYText.h" #include "ZYConfig.h" namespace ZY { #define _(text) (dgettext (GETTEXT_PACKAGE, text)) #define N_(text) text ZhuyinProperties::ZhuyinProperties (Config & config) : m_config (config), m_mode_chinese (m_config.initChinese ()), m_mode_full_english (m_config.initFullEnglish ()), m_mode_full_punct (m_config.initFullPunct ()), m_mode_trad (m_config.initTradChinese ()), m_prop_chinese ("InputMode", PROP_TYPE_NORMAL, StaticText (m_mode_chinese ? _("Chinese") : _("English")), m_mode_chinese ? PKGDATADIR"/icons/chinese.svg" : PKGDATADIR"/icons/english.svg", StaticText (m_mode_chinese ? _("Switch to English Mode") : _("Switch to Chinese Mode"))), m_prop_full_english ("mode.full", PROP_TYPE_NORMAL, StaticText (m_mode_full_english ? _("Full Width Letter") : _("Half Width Letter")), m_mode_full_english ? PKGDATADIR"/icons/full.svg" : PKGDATADIR"/icons/half.svg", StaticText (m_mode_full_english ? _("Switch to Half Width Letter Mode"): _("Switch to Full Width Letter Mode"))), m_prop_full_punct ("mode.full_punct", PROP_TYPE_NORMAL, StaticText (m_mode_full_punct ? _("Full Width Punct") : _("Half Width Punct")), m_mode_full_punct ? PKGDATADIR"/icons/full-punct.svg" : PKGDATADIR"/icons/half-punct.svg", StaticText (m_mode_full_punct ? _("Switch to Half Width Punctuation Mode"): _("Switch to Full Width Punctuation Mode"))), m_prop_trad ( "mode.trad", PROP_TYPE_NORMAL, StaticText (m_mode_trad ? _("Traditional Chinese") : _("Simplified Chinese")), m_mode_trad ? PKGDATADIR"/icons/trad-chinese.svg" : PKGDATADIR"/icons/simp-chinese.svg", StaticText (m_mode_trad ? _("Switch to Simplfied Chinese Mode"): _("Switch to Traditional Chinese Mode"))), m_prop_setup ("setup", PROP_TYPE_NORMAL, StaticText (_("Preferences")), "ibus-setup", StaticText (_("Preferences"))) { if (m_mode_chinese) m_prop_chinese.setSymbol(N_("中")); else m_prop_chinese.setSymbol(N_("英")); m_props.append (m_prop_chinese); m_props.append (m_prop_full_english); m_props.append (m_prop_full_punct); m_props.append (m_prop_trad); m_props.append (m_prop_setup); } void ZhuyinProperties::toggleModeChinese (void) { m_mode_chinese = ! m_mode_chinese; m_prop_chinese.setLabel (m_mode_chinese ? _("Chinese") : _("English")); if (m_mode_chinese) m_prop_chinese.setSymbol(N_("中")); else m_prop_chinese.setSymbol(N_("英")); m_prop_chinese.setIcon (m_mode_chinese ? PKGDATADIR"/icons/chinese.svg" : PKGDATADIR"/icons/english.svg"); m_prop_chinese.setTooltip (m_mode_chinese ? _("Switch to English Mode") : _("Switch to Chinese Mode")); updateProperty (m_prop_chinese); m_prop_full_punct.setSensitive (m_mode_chinese); updateProperty (m_prop_full_punct); } void ZhuyinProperties::toggleModeFullEnglish (void) { m_mode_full_english = !m_mode_full_english; m_prop_full_english.setLabel (m_mode_full_english ? _("Full Width Letter") : _("Half Width Letter")); m_prop_full_english.setIcon (m_mode_full_english ? PKGDATADIR"/icons/full.svg" : PKGDATADIR"/icons/half.svg"); m_prop_full_english.setTooltip (m_mode_full_english ? _("Switch to Half Width Letter Mode"): _("Switch to Full Width Letter Mode")); updateProperty (m_prop_full_english); } void ZhuyinProperties::toggleModeFullPunct (void) { m_mode_full_punct = !m_mode_full_punct; m_prop_full_punct.setLabel (m_mode_full_punct ? _("Full Width Punct") : _("Half Width Punct")); m_prop_full_punct.setIcon (m_mode_full_punct ? PKGDATADIR"/icons/full-punct.svg" : PKGDATADIR"/icons/half-punct.svg"); m_prop_full_punct.setTooltip(m_mode_full_punct ? _("Switch to Half Width Punctuation Mode"): _("Switch to Full Width Punctuation Mode")); updateProperty (m_prop_full_punct); } void ZhuyinProperties::toggleModeTrad (void) { m_mode_trad = ! m_mode_trad; m_prop_trad.setLabel (m_mode_trad ? _("Traditional Chinese") : _("Simplified Chinese")); m_prop_trad.setIcon (m_mode_trad ? PKGDATADIR"/icons/trad-chinese.svg" : PKGDATADIR"/icons/simp-chinese.svg"); m_prop_trad.setTooltip(m_mode_trad ? _("Switch to Simplfied Chinese Mode"): _("Switch to Traditional Chinese Mode")); updateProperty (m_prop_trad); } void ZhuyinProperties::reset (void) { if (modeChinese () != m_config.initChinese ()) { toggleModeChinese (); } if (modeFullEnglish () != m_config.initFullEnglish ()) { toggleModeFullEnglish (); } if (modeFullPunct () != m_config.initFullPunct ()) { toggleModeFullPunct (); } if (modeTrad () != m_config.initTradChinese ()) { toggleModeTrad (); } } gboolean ZhuyinProperties::propertyActivate (const gchar *prop_name, guint prop_state) { const static std::string mode_chinese ("InputMode"); const static std::string mode_full ("mode.full"); const static std::string mode_full_punct ("mode.full_punct"); const static std::string mode_trad ("mode.trad"); if (mode_chinese == prop_name) { toggleModeChinese (); return TRUE; } else if (mode_full == prop_name) { toggleModeFullEnglish (); return TRUE; } else if (mode_full_punct == prop_name) { toggleModeFullPunct (); return TRUE; } else if (mode_trad == prop_name) { toggleModeTrad (); return TRUE; } return FALSE; } }; ibus-libzhuyin-1.6.99.20140929/src/ZYZhuyinProperties.h000066400000000000000000000045121241117270600222770ustar00rootroot00000000000000/* vim:set et ts=4 sts=4: * * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus * * Copyright (c) 2008-2010 Peng Huang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __ZY_ZHUYIN_PROPERTIES_H_ #define __ZY_ZHUYIN_PROPERTIES_H_ #include "ZYSignal.h" #include "ZYProperty.h" namespace ZY { class Config; class ZhuyinProperties { public: ZhuyinProperties (Config & config); void toggleModeChinese (void); void toggleModeFullEnglish (void); void toggleModeFullPunct (void); void toggleModeTrad (void); void reset (void); gboolean modeChinese (void) const { return m_mode_chinese; } gboolean modeFullEnglish (void) const { return m_mode_full_english; } gboolean modeFullPunct (void) const { return m_mode_full_punct; } gboolean modeTrad (void) const { return m_mode_trad; } PropList & properties (void) { return m_props; } gboolean propertyActivate (const gchar *prop_name, guint prop_state); signal & signalUpdateProperty (void) { return m_signal_update_property; } private: void updateProperty (Property & prop) const { m_signal_update_property (prop); } signal m_signal_update_property; private: Config & m_config; gboolean m_mode_chinese; gboolean m_mode_full_english; gboolean m_mode_full_punct; gboolean m_mode_trad; /* properties */ Property m_prop_chinese; Property m_prop_full_english; Property m_prop_full_punct; Property m_prop_trad; Property m_prop_setup; PropList m_props; }; }; #endif ibus-libzhuyin-1.6.99.20140929/src/libzhuyin.xml.in.in000066400000000000000000000021371241117270600220520ustar00rootroot00000000000000 org.freedesktop.IBus.Libzhuyin Libzhuyin Component ${libexecdir}/ibus-engine-libzhuyin --ibus @VERSION@ Peng Wu <alexepico@gmail.com> GPL https://github.com/libzhuyin/ibus-libzhuyin ibus-libzhuyin libzhuyin zh_TW GPL Peng Wu <alexepico@gmail.com> Peng Huang <shawn.p.huang@gmail.com> ... ${pkgdatadir}/icons/ibus-zhuyin.svg default New Zhuyin New Zhuyin input method 99 ${libexecdir}/ibus-setup-libzhuyin zhuyin