Code Monkey home page Code Monkey logo

ssfconv's Introduction

简介

fcitx输入法框架能够自定义皮肤,然后有个很nb的作者开发了个搜狗皮肤转换成fcitx皮肤的,这是原项目地址 https://github.com/VOID001/ssf2fcitx

然后我亲自试了几个我喜欢的皮肤,居然真的可以转换,跟搜狗差不多了,不过一段时间后,发现一些bug:设置了皮肤之后,输入法菜单隔空而且透明,字都看不清。部分皮肤文字位置很奇怪。于是,我看了他的源码,发现逻辑还挺简单,然后看了下fcitx的自定义皮肤的各种格式,打算亲自研究研究这是怎么回事。

最终打算参考这个项目,自己用python写个。

由于 fcitx5 也支持主题,最终也实现了转换成 fcitx5 主题!

成果

最终两个函数实现,取名为转换器ssfconv,放到 github 托管 https://github.com/fkxxyz/ssfconv

在原作者的基础上进行了下面几方面改进:

  1. 部分皮肤文字位置重新计算,摆放更合理
  2. 将菜单的背景也设置成皮肤的主题色,文字大小和颜色均计算到合理
  3. 字体单位改成像素,和搜狗一致,完美还原
  4. 调整了翻页指示器的位置,自动生成指示器的图像
  5. 额外支持 fcitx5

参考图像在这里看

https://www.fkxxyz.com/d/ssfconv/

开始使用

下面直接举例吧。

在 archlinux 或 manjaro 下,可以在 aur 中直接安装 ssfconv

yay -S ssfconv

对于其它发行版下,请按照下面方法逐步安装。

下载此仓库

git clone https://github.com/fkxxyz/ssfconv.git
cd ssfconv

安装python依赖

该项目使用 python3 开发,依赖于 Crypto、pillow、numpy 库,最好使用相应的发行版的包管理器安装它们,或者使用 pip

下载皮肤

先从搜狗输入法的皮肤官网下载自己喜欢的皮肤,得到ssf格式的文件,例如 【雨欣】蒲公英的思念.ssf

转换为 fcitx 皮肤

转换皮肤

./ssfconv  【雨欣】蒲公英的思念.ssf  【雨欣】蒲公英的思念

复制到用户皮肤目录

mkdir -p ~/.config/fcitx/skin/
cp -r 【雨欣】蒲公英的思念  ~/.config/fcitx/skin/

使用该皮肤

右键输入法托盘图表,选中皮肤,这款皮肤是不是出现在列表里了呢,尽情享用吧。

转换为 fcitx5 主题

转换皮肤

./ssfconv  -t fcitx5  【雨欣】蒲公英的思念.ssf  【雨欣】蒲公英的思念

复制到用户主题目录

mkdir -p ~/.local/share/fcitx5/themes/
cp -r 【雨欣】蒲公英的思念  ~/.local/share/fcitx5/themes/

使用该皮肤

打开 fcitx5 的配置,附加组件标签,经典用户界面,点配置,在主题的下拉列表里,选择这款皮肤。

或者你也可以直接修改配置文件 ~/.config/fcitx5/conf/classicui.conf,将 Theme 的值改成这个皮肤的名称即可。

用下面这条命令可以看到该皮肤的名称:

grep Name ~/.local/share/fcitx5/themes/【雨欣】蒲公英的思念/theme.conf

详细介绍

使用方法被封装得非常简单,像个转换器,可以在下面四种格式之间任意转换:

  1. ssf格式(加密)
  2. ssf格式(未加密,本质是zip)
  3. 文件夹(解密或解压ssf格式得到)
  4. fcitx格式(在文件夹的基础上多了fcitx_skin.conf,可用于fcitx)
  5. fcitx5格式(在文件夹的基础上多了theme.conf,可用于fcitx5)

命令行参数

ssfconv <src> [dest] [-t type]

源文件是必选参数,目标文件可选,转换的目标类型 -t 是可选参数,type值是下面四个值之一:

fcitx			可直接用于fcitx的文件夹
fcitx5			可直接用于fcitx5的文件夹
dir				解包后的文件夹
encrypted		加密的ssf皮肤
zip				未加密的ssf皮肤(zip)

默认是转换为 fcitx 格式。

注意,源文件的格式可以是以上任意五个格式之一,不需要指定,程序已经可以智能识别格式。

已知缺陷

fcitx

因为 fcitx 的限制,输入框里只能对文字的外边距进行设置,无法像搜狗拼音输入法一样任意调整坐标,导致部分皮肤只能在图片拉升和文件位置靠右来二选一的取舍。不过大多数皮肤都能挺不错的转换,只有少数皮肤实在是没办法了,只好用图片拉升代替(原作者是将文字调整到靠右,留了很多空白)。

fcitx5

  • fcitx5 能够完美地像搜狗输入法一样调整,但是主题中所设置的字体是无效的,需要手动设置字体,经过我反复的实验,将字体设置为 "Sans 10" 似乎是大多数皮肤的最佳体验。
  • 菜单字体颜色无法通过主题调整,只能为黑色高亮白色,所以在背景比较黑或者比较白的皮肤下,菜单可能体验不理想。
  • 部分皮肤可能转换效果不太好,需要寻找原因,欢迎提出 issues 帮助我改进,最好说明皮肤的下载链接便于排查。

致谢

该项目的思路,以及解密的过程和密钥,完全参考了 VOID001/ssf2fcitx 在此表示感谢!

ssfconv's People

Contributors

fkxxyz avatar zxeoc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ssfconv's Issues

IndexError

转换fcitx5皮肤的时候出现错误

Traceback (most recent call last):
  File "/usr/bin/ssfconv", line 1203, in <module>
    exit(main(args))
  File "/usr/bin/ssfconv", line 1175, in main
    result = ssr2fcitx5(skin_dir)
  File "/usr/bin/ssfconv", line 819, in ssr2fcitx5
    back_color = findBackgroundColor()
  File "/usr/bin/ssfconv", line 801, in findBackgroundColor
    return getImageAvg(skin_dir + os.sep + image_name,
  File "/usr/bin/ssfconv", line 118, in getImageAvg
    if a[y][x][3] > 0:
IndexError: index 3 is out of bounds for axis 0 with size 3

转换使用的文件:
1.zip

更详细的教程?

很喜欢你的项目,但不会用🤒️
能不能出一个更详细的小白教程……有视频会更好。
谢谢啦!🙏🏻️

運行失敗,提示沒有Crypto模塊

我不太懂程序,現在用您的rime輸入法,挺好用的,感谢,想进一步用用皮肤,但按教程轉換皮膚失敗。
我用的是manjaro KDE系統,我查了,安裝的有python3.8,系統包管理器中沒有需要的Crypto、pillow、numpy 库,所以就用的pip安裝這些庫,不過安装的时候提示Crypto和numpy库已有,pillow没找到,我查看文件夹下也确实有,但进行到第一步就提示:
File "./ssfconv", line 4, in
from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'
所以不知道怎么办了,能帮忙解决下吗?谢谢!

出错了

ModuleNotFoundError: No module named 'Crypto'

貌似Crypto有破坏性更新

报错日志

Traceback (most recent call last):
File "/run/media/frozon/manjaro home/frozon/下载/rime/ssfconv/./ssfconv", line 1211, in
exit(main(args))
File "/run/media/frozon/manjaro home/frozon/下载/rime/ssfconv/./ssfconv", line 1170, in main
extractSsf(args.src, dest_dir)
File "/run/media/frozon/manjaro home/frozon/下载/rime/ssfconv/./ssfconv", line 35, in extractSsf
ssfAES = AES.new(aesKey, AES.MODE_CBC, iv)
File "/run/media/frozon/manjaro home/frozon/下载/rime/ssfconv/venv/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 95, in new
return AESCipher(key, *args, **kwargs)
File "/run/media/frozon/manjaro home/frozon/下载/rime/ssfconv/venv/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 59, in init
blockalgo.BlockAlgo.init(self, _AES, key, *args, **kwargs)
File "/run/media/frozon/manjaro home/frozon/下载/rime/ssfconv/venv/lib/python3.10/site-packages/Crypto/Cipher/blockalgo.py", line 141, in init
self._cipher = factory.new(key, *args, **kwargs)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

环境

python 版本

Python 3.10.5

pip list

numpy 1.22.4
Pillow 9.1.1
pip 22.0.4
pycrypto 2.6.1
setuptools 58.1.0

转换报错了, 可能是依赖的库 API 有重大更新

环境信息

python --version
Python 3.9.1
pip list
Package                 Version
----------------------- ---------
astroid                 2.5.6
autopep8                1.5.7
beautifulsoup4          4.9.3
bs4                     0.0.1
certifi                 2020.12.5
cffi                    1.14.5
chardet                 4.0.0
colorama                0.4.4
cycler                  0.10.0
dlib                    19.22.0
face-recognition        1.3.0
face-recognition-models 0.3.0
greenlet                1.0.0
idna                    2.10
isort                   5.8.0
kiwisolver              1.3.1
lazy-object-proxy       1.6.0
matplotlib              3.4.2
mccabe                  0.6.1
mpv-remote-app          0.0.3
msgpack                 1.0.2
numpy                   1.20.2
opencv-python           4.3.0.38
Pillow                  8.2.0
pip                     21.1.2
prettytable             2.1.0
psutil                  5.8.0
pycodestyle             2.7.0
pycparser               2.20
pycryptodome            3.10.1
pylint                  2.8.2
pynvim                  0.4.3
pyparsing               2.4.7
PySocks                 1.7.1
python-bidi             0.4.2
python-dateutil         2.8.1
PyYAML                  5.4.1
qrcode                  6.1
requests                2.25.1
setuptools              49.2.1
shadowsocksr-cli        2.1.2
six                     1.15.0
soupsieve               2.2.1
toml                    0.10.2
urllib3                 1.26.4
wcwidth                 0.2.5
wrapt                   1.12.1

重现步骤

cd ~
git clone https://github.com/fkxxyz/ssfconv.git
git clone https://github.com/xiaochunjimmy/Sogou-Input-Skin.gi
./ssfconv -t fcitx5 ./Sogou-Input-Skin/for_windows/Boundary.ssf ./Boundary

报错日志

image_path ./Boundary/skin2_2.png
size (22, 22)
a.shape (22, 22)
Traceback (most recent call last):
File "/home/backtolife/git.workspace/fork.workspace/ssfconv/./ssfconv", line 1214, in
exit(main(args))
File "/home/backtolife/git.workspace/fork.workspace/ssfconv/./ssfconv", line 1186, in main
result = ssf2fcitx5(skin_dir)
File "/home/backtolife/git.workspace/fork.workspace/ssfconv/./ssfconv", line 830, in ssf2fcitx5
back_color = findBackgroundColor()
File "/home/backtolife/git.workspace/fork.workspace/ssfconv/./ssfconv", line 812, in findBackgroundColor
return getImageAvg(skin_dir + os.sep + image_name,
File "/home/backtolife/git.workspace/fork.workspace/ssfconv/./ssfconv", line 119, in getImageAvg
if a.shape[2] == 4:
IndexError: tuple index out of range

合成提示TypeError

报错,代码如下:
File "./ssfconv", line 1211, in
exit(main(args))
File "./ssfconv", line 1181, in main
result = ssf2fcitx(skin_dir)
File "./ssfconv", line 708, in ssf2fcitx
skin.write(open(skin_dir + os.sep + 'fcitx_skin.conf', 'w', encoding="utf-8"), False)
TypeError: 'encoding' is an invalid keyword argument for this function

BUG:global name 'cicon_image' is not defined

报错:

  File "./ssfconv", line 431, in ssr2fcitx
    size = getImageSize(skin_dir + os.sep + cicon_image)
NameError: global name 'cicon_image' is not defined

解决:
cicon_image应该是icon_image,多打了1个c,删掉就正常了。

话说,作者上传前忘了运行一遍吧:smile:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.