├── LICENSE ├── README.md └── ssfconv /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | fcitx输入法框架能够自定义皮肤,然后有个很nb的作者开发了个搜狗皮肤转换成fcitx皮肤的,这是原项目地址 https://github.com/VOID001/ssf2fcitx 3 | 4 | 然后我亲自试了几个我喜欢的皮肤,居然真的可以转换,跟搜狗差不多了,不过一段时间后,发现一些bug:设置了皮肤之后,输入法菜单隔空而且透明,字都看不清。部分皮肤文字位置很奇怪。于是,我看了他的源码,发现逻辑还挺简单,然后看了下fcitx的自定义皮肤的各种格式,打算亲自研究研究这是怎么回事。 5 | 6 | 最终打算参考这个项目,自己用python写个。 7 | 8 | 由于 fcitx5 也支持主题,最终也实现了转换成 fcitx5 主题! 9 | 10 | ## 成果 11 | 12 | 最终两个函数实现,取名为转换器ssfconv,放到 github 托管 https://github.com/fkxxyz/ssfconv 13 | 14 | 在原作者的基础上进行了下面几方面改进: 15 | 16 | 1. 部分皮肤文字位置重新计算,摆放更合理 17 | 2. 将菜单的背景也设置成皮肤的主题色,文字大小和颜色均计算到合理 18 | 3. 字体单位改成像素,和搜狗一致,完美还原 19 | 4. 调整了翻页指示器的位置,自动生成指示器的图像 20 | 5. 额外支持 fcitx5 21 | 22 | 参考图像在这里看 23 | 24 | https://www.fkxxyz.com/d/ssfconv/ 25 | 26 | ## 开始使用 27 | 28 | 下面直接举例吧。 29 | 30 | 在 archlinux 或 manjaro 下,可以在 aur 中直接安装 ssfconv 31 | 32 | ```shell 33 | yay -S ssfconv 34 | ``` 35 | 36 | 对于其它发行版下,请按照下面方法逐步安装。 37 | 38 | ### 下载此仓库 39 | 40 | ```shell 41 | git clone https://github.com/fkxxyz/ssfconv.git 42 | cd ssfconv 43 | ``` 44 | 45 | ### 安装python依赖 46 | 47 | 该项目使用 python3 开发,依赖于 Crypto、pillow、numpy 库,最好使用相应的发行版的包管理器安装它们,或者使用 pip 48 | 49 | ### 下载皮肤 50 | 51 | 先从[搜狗输入法的皮肤官网](https://pinyin.sogou.com/skins/)下载自己喜欢的皮肤,得到ssf格式的文件,例如 【雨欣】蒲公英的思念.ssf 52 | 53 | ### 转换为 fcitx 皮肤 54 | 55 | 转换皮肤 56 | 57 | ```shell 58 | ./ssfconv 【雨欣】蒲公英的思念.ssf 【雨欣】蒲公英的思念 59 | ``` 60 | 61 | 复制到用户皮肤目录 62 | 63 | ```shell 64 | mkdir -p ~/.config/fcitx/skin/ 65 | cp -r 【雨欣】蒲公英的思念 ~/.config/fcitx/skin/ 66 | ``` 67 | 68 | 使用该皮肤 69 | 70 | 右键输入法托盘图表,选中皮肤,这款皮肤是不是出现在列表里了呢,尽情享用吧。 71 | 72 | ### 转换为 fcitx5 主题 73 | 74 | 转换皮肤 75 | 76 | ```shell 77 | ./ssfconv -t fcitx5 【雨欣】蒲公英的思念.ssf 【雨欣】蒲公英的思念 78 | ``` 79 | 80 | 复制到用户主题目录 81 | 82 | ```shell 83 | mkdir -p ~/.local/share/fcitx5/themes/ 84 | cp -r 【雨欣】蒲公英的思念 ~/.local/share/fcitx5/themes/ 85 | ``` 86 | 87 | 使用该皮肤 88 | 89 | 打开 fcitx5 的配置,附加组件标签,经典用户界面,点配置,在主题的下拉列表里,选择这款皮肤。 90 | 91 | 或者你也可以直接修改配置文件 ~/.config/fcitx5/conf/classicui.conf,将 Theme 的值改成这个皮肤的名称即可。 92 | 93 | 用下面这条命令可以看到该皮肤的名称: 94 | 95 | ```shell 96 | grep Name ~/.local/share/fcitx5/themes/【雨欣】蒲公英的思念/theme.conf 97 | ``` 98 | 99 | ## 详细介绍 100 | 101 | 使用方法被封装得非常简单,像个转换器,可以在下面四种格式之间任意转换: 102 | 103 | 1. ssf格式(加密) 104 | 2. ssf格式(未加密,本质是zip) 105 | 3. 文件夹(解密或解压ssf格式得到) 106 | 4. fcitx格式(在文件夹的基础上多了fcitx_skin.conf,可用于fcitx) 107 | 5. fcitx5格式(在文件夹的基础上多了theme.conf,可用于fcitx5) 108 | 109 | 命令行参数 110 | 111 | ```shell 112 | ssfconv [dest] [-t type] 113 | ``` 114 | 115 | 源文件是必选参数,目标文件可选,转换的目标类型 -t 是可选参数,type值是下面四个值之一: 116 | 117 | ``` 118 | fcitx 可直接用于fcitx的文件夹 119 | fcitx5 可直接用于fcitx5的文件夹 120 | dir 解包后的文件夹 121 | encrypted 加密的ssf皮肤 122 | zip 未加密的ssf皮肤(zip) 123 | ``` 124 | 125 | 默认是转换为 fcitx 格式。 126 | 127 | 注意,源文件的格式可以是以上任意五个格式之一,不需要指定,程序已经可以智能识别格式。 128 | 129 | ## 已知缺陷 130 | 131 | ### fcitx 132 | 133 | 因为 fcitx 的限制,输入框里只能对文字的外边距进行设置,无法像搜狗拼音输入法一样任意调整坐标,导致部分皮肤只能在图片拉升和文件位置靠右来二选一的取舍。不过大多数皮肤都能挺不错的转换,只有少数皮肤实在是没办法了,只好用图片拉升代替(原作者是将文字调整到靠右,留了很多空白)。 134 | 135 | ### fcitx5 136 | 137 | - fcitx5 能够完美地像搜狗输入法一样调整,但是主题中所设置的字体是无效的,需要手动设置字体,经过我反复的实验,将字体设置为 "Sans 10" 似乎是大多数皮肤的最佳体验。 138 | - 菜单字体颜色无法通过主题调整,只能为黑色高亮白色,所以在背景比较黑或者比较白的皮肤下,菜单可能体验不理想。 139 | - 部分皮肤可能转换效果不太好,需要寻找原因,欢迎提出 issues 帮助我改进,最好说明皮肤的下载链接便于排查。 140 | 141 | ## 致谢 142 | 143 | 该项目的思路,以及解密的过程和密钥,完全参考了 [VOID001/ssf2fcitx](VOID001/ssf2fcitx) 在此表示感谢! 144 | 145 | -------------------------------------------------------------------------------- /ssfconv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | #-*- encoding:utf-8 -*- 3 | 4 | from Crypto.Cipher import AES 5 | import zlib 6 | import struct 7 | import zipfile 8 | import io 9 | import os 10 | import sys 11 | import configparser 12 | from PIL import Image, ImageDraw 13 | import numpy as np 14 | import argparse 15 | import tempfile 16 | import shutil 17 | 18 | def extractSsf(ssf_file_path, dest_dir): 19 | """ 20 | 解压ssf文件到指定文件夹,文件夹不存在会自动创建 21 | ssf 文件格式目前有两种,一种是加密过后,一种未加密的zip 22 | """ 23 | 24 | # 读取文件的二进制内容 25 | ssfbin = open(ssf_file_path, 'rb').read() 26 | 27 | if ssfbin[:4] == b'Skin': # 通过头四字节判断是否被加密 28 | # AES 解密内容 29 | aesKey = b'\x52\x36\x46\x1A\xD3\x85\x03\x66' + \ 30 | b'\x90\x45\x16\x28\x79\x03\x36\x23' + \ 31 | b'\xDD\xBE\x6F\x03\xFF\x04\xE3\xCA' + \ 32 | b'\xD5\x7F\xFC\xA3\x50\xE4\x9E\xD9' 33 | iv = b'\xE0\x7A\xAD\x35\xE0\x90\xAA\x03' + \ 34 | b'\x8A\x51\xFD\x05\xDF\x8C\x5D\x0F' 35 | ssfAES = AES.new(aesKey, AES.MODE_CBC, iv) 36 | decrypted_ssfbin = ssfAES.decrypt(ssfbin[8:]) 37 | 38 | # zlib 解压内容 39 | data = zlib.decompress(decrypted_ssfbin[4:]) # 注意要跳过头四字节 40 | 41 | def readUint(offset): 42 | return struct.unpack('I', data[offset:offset+4])[0] 43 | 44 | # 整个内容的大小 45 | size = readUint(0) 46 | 47 | # 得到若干个偏移量 48 | offsets_size = readUint(4) 49 | offsets = struct.unpack('I'*(offsets_size//4), 50 | data[8:8+offsets_size]) 51 | 52 | # 创建文件夹 53 | if not os.path.isdir(dest_dir): 54 | os.mkdir(dest_dir) 55 | 56 | for offset in offsets: 57 | # 得到文件名 58 | name_len = readUint(offset) 59 | filename = data[offset+4:offset+4+name_len].decode('utf-16') 60 | 61 | # 得到文件内容 62 | content_len = readUint(offset+4+name_len) 63 | content = data[offset+8+name_len:offset+8+name_len+content_len] 64 | 65 | # 写入文件 66 | open(dest_dir.rstrip(os.sep)+os.sep+filename, 'wb').write(content) 67 | 68 | else: 69 | 70 | # 直接 zip 解压 71 | with zipfile.ZipFile(ssf_file_path) as zf: 72 | zf.extractall(dest_dir) 73 | 74 | 75 | def getImageAvg(image_path, area = (0, 0, 0, 0)): 76 | """ 77 | 获取图片的像素平均值 78 | image_path 图片的路径 79 | aria 是需要求的平均值的区域,默认整幅图 80 | 格式 area = (x1,x2,y1,y2) 81 | 当 x2 或 y2 为零表示最大值直到边界 82 | 为负时表示距离最大边界多少的坐标 83 | 返回 (r,g,b) 三元组 84 | """ 85 | # 读取到图片 86 | image = Image.open(image_path) 87 | size = image.size 88 | 89 | # 确定区域 90 | x1 = area[0] % size[0] 91 | x2 = area[1] % size[0] 92 | y1 = area[2] % size[1] 93 | y2 = area[3] % size[1] 94 | if x2 == 0: x2 = size[0] 95 | if y2 == 0: y2 = size[1] 96 | 97 | if x1 > x2: 98 | t = x1; x1 = x2; x2 = t 99 | if y1 > y2: 100 | t = y1; y1 = y2; y2 = t 101 | if x1 == x2: 102 | if x2 != size[0]: 103 | x2 += 1 104 | else: 105 | x1 -= 1 106 | if y1 == y2: 107 | if y2 != size[1]: 108 | y2 += 1 109 | else: 110 | y1 -= 1 111 | 112 | # 算出区域内所有象素点的平均值 113 | a = np.asarray(image) 114 | r = g = b = 0 115 | count = 0 116 | if a.shape[2] == 4: 117 | for y in range(y1, y2): 118 | for x in range(x1, x2): 119 | if a[y][x][3] > 0: 120 | r += a[y][x][0] 121 | g += a[y][x][1] 122 | b += a[y][x][2] 123 | count += 1 124 | else: 125 | for y in range(y1, y2): 126 | for x in range(x1, x2): 127 | r += a[y][x][0] 128 | g += a[y][x][1] 129 | b += a[y][x][2] 130 | count += 1 131 | if count == 0: 132 | count = 1 133 | r //= count 134 | g //= count 135 | b //= count 136 | return (r, g, b) 137 | 138 | def rgbDist(c1, c2): 139 | """ 140 | 简单的计算两个颜色之间的距离 141 | """ 142 | dr = c1[0]-c2[0] 143 | dg = c1[1]-c2[1] 144 | db = c1[2]-c2[2] 145 | return dr*dr+dg*dg+db*db 146 | 147 | def rgbDistMax(color, *colors): 148 | """ 149 | 求 colors 中与 color 的距离最大的颜色 150 | """ 151 | max_d = 0 152 | max_d_color = colors[0] 153 | for c in colors: 154 | cur_d = rgbDist(color, c) 155 | if max_d < cur_d: 156 | max_d = cur_d 157 | max_d_color = c 158 | return max_d_color 159 | 160 | default_menu_img_path = io.BytesIO(b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00<\x00\x00\x00<\x08\x06\x00\x00\x00:\xfc\xd9r\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00\tpHYs\x00\x00\x1b\xaf\x00\x00\x1b\xaf\x01^\x1a\x91\x1c\x00\x00\x00\x19tEXtSoftware\x00www.inkscape.org\x9b\xee<\x1a\x00\x00\x01\xdaIDATh\x81\xed\x9b\xc1N\xdb@\x10@\xdf\x80\x15R\x08R\x10\xa4\x12\xbd\x84\x037\xbe\xa0\x9f\xd2/\xec\'\xf0\t|\x04\x1c\xc8\t\t\x88\x9a\x127AHdz\x98\xdd\xd6\nI$\xa4\x10\xd8a\x9e\xb4\xb2\xec\xb5\xady\x1e{}\x99\x11U\xa5\x89\x88\xec\x02-@(\x1b\x05\x9eTu\xd2<(Y8\x89\x1e\x02\xfb@\x1b\x1f\xc2\x8f\xc0\x18\x18f\xf1\n\xfe\xc9\x1e\x03_\x81\x03\xe0\x0b>\x84\xa7\xc0/\xa0%"7\xaa:\xa9\xd2\xe4!&\xfb\r\xe8\x01\x1d`\xeb]\xc2\\\x1f3\xa0\xc6\x92\x07\xf0\x04L\xaa\x94\xdd},\xb3=L\xfa\x18\xf8\x0e\xf41\xf9\x92\xa8\x81\x01p\x01\xdc\xa4cS\xe0\xb7\x88\xecV\xd8\x02\xd5\xc6\x9eD\x07\x93\xfd\x01\xecm>\xd6\xb5\xd0\x01\xce\x80\x13\xe0\'\xf0\x80\xb9\xb5\x81V\x85}\xabyla\x99\xdd\x03\xae\x80.\xf6j\xe8\xfc]?(\xd9a\x04\x9cb.\x974\x1c\xab\x05\x17\xf5\xd3\xb6\x0b[+\xde_\xdfNz_\xa1?jm\x00\x00\x00\x00IEND\xaeB`\x82') 161 | default_radio_img_path = io.BytesIO(b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x18\x00\x00\x00\x18\x08\x06\x00\x00\x00\xe0w=\xf8\x00\x00\x00\tpHYs\x00\x00\r\xd7\x00\x00\r\xd7\x01B(\x9bx\x00\x00\x00\x19tEXtSoftware\x00www.inkscape.org\x9b\xee<\x1a\x00\x00\x00\x9dIDATH\x89\xed\x91\xc1\n\x830\x10Dg\x1a\xd0\x1f*\xbdfIoJ?\xb7-\xeda!G\xc1\x1fR\x88\xdb\x8b\xd2\x1e\x84\x08zk\xde1\xbb\x93\x07\xb3@\xa1P\xe0\xd6EUm\x9dsg\x00H)\xf5!\x84\xfba\x82\x18\xe3\xcb\xcc\x04@5?\r$\xd5{\xdf\xe4\xb2\xa7\xdc\x82\xaa\xb6f\xe6\x7f>\x07\x80\xda\xcc\xae1\xc6\xfd\x82\xb9\x96zeTM\xd3t\xd9-\xd8KV\x90R\xeaI\x8e+\xa3\x81d\x97\xcbo=\xf2\xc3\xcc\x02\xbeU\x8d\x00\xde"r;D0K\x9a\xa5s\x92\x9d\x88<\xb7f\x0b\x85\x7f\xe7\x03\xc2\x8b7\xa7\xab\xe8\x14\xb1\x00\x00\x00\x00IEND\xaeB`\x82') 162 | 163 | 164 | # 获取图片大小的函数 165 | def getImageSize(image_file): 166 | assert image_file 167 | size = Image.open(image_file).size 168 | assert size[0] > 0 and size[0] < 65536 and \ 169 | size[1] > 0 and size[1] < 65536 170 | return size 171 | 172 | # 保存一个多边形到 png 文件里 173 | def savePolygon(size, points, color, out_file): 174 | img = Image.new('RGBA', size) 175 | draw = ImageDraw.Draw(img) 176 | draw.polygon(points, fill = color) 177 | img.save(out_file) 178 | 179 | 180 | 181 | def ssf2fcitx(skin_dir): 182 | """ 183 | 转换为 fcitx 格式 184 | 将解压后的 ssf 皮肤,在里面创建出 fcitx_skin.conf 185 | """ 186 | 187 | skin_dir = skin_dir.rstrip(os.sep) 188 | 189 | # 确保 skin.ini 文件的存在 190 | skin_ini = skin_dir + os.sep + 'skin.ini' 191 | if not os.path.isfile(skin_ini): 192 | sys.stderr.write('找不到 skin.ini\n') 193 | return 1 194 | 195 | # 为了使其区分大小写,重载 ConfigParser 196 | class CaseSensitiveConfigParser(configparser.ConfigParser): 197 | def optionxform(self, optionstr): 198 | return optionstr 199 | 200 | # 读取 skin.ini 文件 201 | try: 202 | ssf = CaseSensitiveConfigParser(allow_no_value = True) 203 | ssf.read(skin_ini, encoding = 'utf-16') 204 | except: 205 | sys.stderr.write('读取 skin.ini 失败\n') 206 | return 2 207 | 208 | # 建立 conf 的对象 209 | skin = CaseSensitiveConfigParser(allow_no_value = True) 210 | 211 | skin['SkinInfo'] = { 212 | # 皮肤名称 213 | 'Name': ssf['General']['skin_name'], 214 | 215 | # 皮肤版本 216 | 'Version': ssf['General']['skin_version'], 217 | 218 | # 皮肤作者 219 | 'Author': ssf['General']['skin_author'], 220 | 221 | # 描述 222 | 'Desc': ssf['General']['skin_info'], 223 | } 224 | 225 | # 将 skin.ini 的颜色转换成 (r,g,b) 三元组 226 | def colorConv(ssf_color): 227 | color_int = int(ssf_color, 16) 228 | r = color_int % 256 229 | g = (color_int % 65536) // 256 230 | b = color_int // 65536 231 | return (r, g, b) 232 | 233 | # 获取图片文件名的函数(获取失败则返回空字符串) 234 | def getImageConfig(section, key, index = 0): 235 | if key in ssf[section]: 236 | image_name_list = ssf[section][key].split(',') 237 | if index < len(image_name_list): 238 | image_name = image_name_list[index] 239 | if os.path.isfile(skin_dir + os.sep + image_name): 240 | return image_name 241 | return '' 242 | 243 | # 尝试获取值的函数 244 | def tryGetValue(section, key): 245 | if key in ssf[section]: 246 | return ssf[section][key].strip() 247 | return '' 248 | 249 | # 根据里面所有的图片,根据所设置的拉伸区域确定合适的背景色 250 | def findBackgroundColor(): 251 | for key in (('Scheme_V1','pic'), 252 | ('Scheme_V2','pinyin_pic'), 253 | ('Scheme_V2','zhongwen_pic'), 254 | ('Scheme_H1','pic'), 255 | ('Scheme_H2','pinyin_pic'), 256 | ('Scheme_H2','zhongwen_pic'), 257 | ): 258 | # 排除不存在的键值 259 | image_name = getImageConfig(key[0], key[1]) 260 | if not image_name : continue 261 | 262 | # 排除区域不存在 263 | h_str = tryGetValue(key[0], key[1][:-3] + 'layout_horizontal') 264 | if not h_str : continue 265 | v_str = tryGetValue(key[0], key[1][:-3] + 'layout_vertical') 266 | if not v_str : continue 267 | 268 | # 得出区域 269 | h = h_str.split(',') 270 | v = v_str.split(',') 271 | if len(h) != 3 or len(v) != 3: continue 272 | 273 | # 排除平铺模式(筛选出是拉伸区域) 274 | #if int(h[0]) != 0 or int(v[0]) != 0: 275 | # continue 276 | 277 | return getImageAvg(skin_dir + os.sep + image_name, 278 | (int(h[1]), 279 | -int(h[2]), 280 | int(v[1]), 281 | -int(v[2]))) 282 | else: 283 | return (0, 0, 0) 284 | 285 | # 输入框输入的拼音颜色 286 | input_color = colorConv(ssf['Display']['pinyin_color']) 287 | 288 | # 列表中第一个词的颜色 289 | first_color = colorConv(ssf['Display']['zhongwen_first_color']) 290 | 291 | # 列表中其他词的颜色 292 | other_color = colorConv(ssf['Display']['zhongwen_color']) 293 | 294 | # 根据里面所有的图片,根据所设置的拉伸区域确定合适的背景色 295 | back_color = findBackgroundColor() 296 | 297 | # 字体大小(像素) 298 | font_size = int(ssf['Display']['font_size']) 299 | 300 | # 状态栏背景图 301 | static_bar_image = getImageConfig('StatusBar', 'pic') 302 | 303 | # 中/英文状态 304 | cn_status_image = getImageConfig('StatusBar', 'cn_en', 0) 305 | en_status_image = getImageConfig('StatusBar', 'cn_en', 1) 306 | 307 | # 全半角状态 308 | quan_status_image = getImageConfig('StatusBar', 'quan_ban', 0) 309 | ban_status_image = getImageConfig('StatusBar', 'quan_ban', 1) 310 | 311 | # 中/英文标点状态 312 | cn_p_status_image = getImageConfig('StatusBar', 'biaodian', 0) 313 | en_p_status_image = getImageConfig('StatusBar', 'biaodian', 1) 314 | 315 | # 繁/简状态 316 | simp_status_image = getImageConfig('StatusBar', 'fan_jian', 1) 317 | trad_status_image = getImageConfig('StatusBar', 'fan_jian', 0) 318 | 319 | # 虚拟键盘状态 320 | vk_inactive_status_image = getImageConfig('StatusBar', 'softkeyboard') 321 | for mouse_status in ('down','in','out','downing'): 322 | vk_active_status_image = getImageConfig('StatusBar', 'softkeyboard_' + mouse_status) 323 | if vk_active_status_image: 324 | break 325 | 326 | icons = (cn_status_image, simp_status_image, trad_status_image, 327 | quan_status_image, ban_status_image, 328 | cn_p_status_image, en_p_status_image, 329 | vk_inactive_status_image, vk_active_status_image) 330 | 331 | # 求图标的前景色(任意一个即可) 332 | for image in icons: 333 | if image: 334 | icon_color = getImageAvg(skin_dir + os.sep + image) 335 | break 336 | else: 337 | icon_color = other_color 338 | 339 | skin['SkinFont'] = { 340 | # 字体大小 341 | 'FontSize': font_size, 342 | 343 | # 菜单字体大小 344 | 'MenuFontSize': 14, 345 | 346 | # 字体大小遵守dpi设置 347 | 'RespectDPI': 'False', 348 | 349 | # 提示信息颜色 350 | 'TipColor': '%d %d %d' % first_color, 351 | 352 | # 输入信息颜色 353 | 'InputColor': '%d %d %d' % other_color, 354 | 355 | # 候选词索引颜色 356 | 'IndexColor': '%d %d %d' % other_color, 357 | 358 | # 第一候选词颜色 359 | 'FirstCandColor': '%d %d %d' % first_color, 360 | 361 | # 用户词组颜色 362 | 'UserPhraseColor': '%d %d %d' % first_color, 363 | 364 | # 码表提示颜色 365 | 'CodeColor': '%d %d %d' % input_color, 366 | 367 | # 其他颜色 368 | 'OtherColor': '%d %d %d' % other_color, 369 | 370 | # 活动菜单项颜色 371 | 'ActiveMenuColor': '%d %d %d' % \ 372 | rgbDistMax(other_color, 373 | first_color, input_color, back_color, icon_color), 374 | 375 | # 非活动菜单项颜色+状态栏图标文字颜色 376 | 'InactiveMenuColor': '%d %d %d' % \ 377 | rgbDistMax(back_color, 378 | first_color, input_color, other_color, icon_color), 379 | } 380 | 381 | # 创建符号链接的函数(若存在则覆盖) 382 | def symlinkF(src, dst): 383 | if os.path.isfile(dst): 384 | os.remove(dst) 385 | return os.symlink(src, dst) 386 | 387 | # 创建中文拼音状态图 pinyin.png 388 | if cn_status_image: 389 | symlinkF(cn_status_image, skin_dir + os.sep + 'pinyin.png') 390 | 391 | # 创建全/半角状态图 fullwidth_active.png / fullwidth_inactive.png 392 | if quan_status_image: 393 | symlinkF(quan_status_image, skin_dir + os.sep + 'fullwidth_active.png') 394 | if ban_status_image: 395 | symlinkF(ban_status_image, skin_dir + os.sep + 'fullwidth_inactive.png') 396 | 397 | # 创建中/英文标点状态图 punc_active.png / punc_inactive.png 398 | if cn_p_status_image: 399 | symlinkF(cn_p_status_image, skin_dir + os.sep + 'punc_active.png') 400 | if en_p_status_image: 401 | symlinkF(en_p_status_image, skin_dir + os.sep + 'punc_inactive.png') 402 | 403 | # 创建繁/简状态图 chttrans_inactive.png / chttrans_active.png 404 | if simp_status_image: 405 | symlinkF(simp_status_image, skin_dir + os.sep + 'chttrans_inactive.png') 406 | if trad_status_image: 407 | symlinkF(trad_status_image, skin_dir + os.sep + 'chttrans_active.png') 408 | 409 | # 创建虚拟键盘状态图 vk_inactive.png / vk_active.png 410 | if vk_inactive_status_image: 411 | symlinkF(vk_inactive_status_image, skin_dir + os.sep + 'vk_inactive.png') 412 | if vk_active_status_image: 413 | symlinkF(vk_active_status_image, skin_dir + os.sep + 'vk_active.png') 414 | 415 | # 求搜狗状态栏上几个按钮的坐标的最值 416 | x_min = y_min = 65536 417 | x_max = y_max = 0 418 | for button in ('cn_en', 419 | 'biaodian', 420 | 'quan_ban', 421 | 'quan_shuang', 422 | 'fan_jian', 423 | 'softkeyboard', 424 | 'menu', 425 | 'sogousearch', 426 | 'passport', 427 | 'skinmanager'): 428 | display = tryGetValue('StatusBar', button + '_display') 429 | if display != '1': continue 430 | pos = tryGetValue('StatusBar', button + '_pos').split(',') 431 | if len(pos) != 2: continue 432 | 433 | # 取最值 434 | if int(pos[0]) < x_min: x_min = int(pos[0]) 435 | if int(pos[1]) < y_min: y_min = int(pos[1]) 436 | 437 | # 得到图标尺寸 438 | icon_image = getImageConfig('StatusBar', button, 0) 439 | if not icon_image: continue 440 | size = getImageSize(skin_dir + os.sep + icon_image) 441 | 442 | # 取最右值 443 | x = int(pos[0]) + size[0] 444 | if x > x_max: x_max = x 445 | 446 | y = int(pos[1]) + size[1] 447 | if y > y_max: y_max = y 448 | 449 | # 得出合适的右边距和下边距 450 | if static_bar_image: 451 | size = getImageSize(skin_dir + os.sep + static_bar_image) 452 | MarginRight = size[0] - x_max + 4 453 | MarginBottom = size[1] - y_max + 4 454 | else: 455 | MarginRight = 4 456 | MarginBottom = 4 457 | 458 | skin['SkinMainBar'] = { 459 | # 背景图片 460 | 'BackImg': static_bar_image, 461 | 462 | # Logo图标 463 | 'Logo': '', 464 | 465 | # 英文模式图标 466 | 'Eng': en_status_image, 467 | 468 | # 激活状态输入法图标 469 | 'Active': cn_status_image, 470 | 471 | # 左边距 472 | 'MarginLeft': x_min+4, 473 | 474 | # 右边距 475 | 'MarginRight': MarginRight, 476 | 477 | # 上边距 478 | 'MarginTop': y_min+4, 479 | 480 | # 下边距 481 | 'MarginBottom': MarginBottom, 482 | 483 | # 可点击区域的左边距 484 | #ClickMarginLeft=0 485 | # 可点击区域的右边距 486 | #ClickMarginRight=0 487 | # 可点击区域的上边距 488 | #ClickMarginTop=0 489 | # 可点击区域的下边距 490 | #ClickMarginBottom=0 491 | # 覆盖图片 492 | #Overlay= 493 | # 覆盖图片停靠位置 494 | # Available Value: 495 | # TopLeft 496 | # TopCenter 497 | # TopRight 498 | # CenterLeft 499 | # Center 500 | # CenterRight 501 | # BottomLeft 502 | # BottomCenter 503 | # BottomRight 504 | #OverlayDock=TopLeft 505 | # 覆盖图片 X 偏移 506 | #OverlayOffsetX=0 507 | # 覆盖图片 Y 偏移 508 | #OverlayOffsetY=0 509 | # 纵向填充规则 510 | # Available Value: 511 | # Copy 512 | # Resize 513 | #FillVertical=Resize 514 | # 横向填充规则 515 | # Available Value: 516 | # Copy 517 | # Resize 518 | #FillHorizontal=Resize 519 | # 使用自定的文本图标颜色 520 | # Available Value: 521 | # True False 522 | #UseCustomTextIconColor=True 523 | # 活动的文本图标颜色 524 | #ActiveTextIconColor=101 153 209 525 | # 非活动的文本图标颜色 526 | #InactiveTextIconColor=101 153 209 527 | # 特殊图标位置 528 | #Placement= 529 | } 530 | 531 | 532 | # 输入框背景图 533 | input_bar_image = getImageConfig('Scheme_H1', 'pic') 534 | input_bar_image_size = getImageSize(skin_dir + os.sep + input_bar_image) 535 | 536 | # 绘制 prev.png 和 next.png 颜色为 '%d %d %d' % other_color 537 | savePolygon((6,12), ((0,0),(6,6),(0,12)), other_color, skin_dir + os.sep + 'next.png') 538 | savePolygon((6,12), ((0,6),(6,0),(6,12)), other_color, skin_dir + os.sep + 'prev.png') 539 | 540 | # 水平边距 541 | lh = tryGetValue('Scheme_H1', 'layout_horizontal') 542 | if lh: 543 | lh = tuple(map(lambda s:int(s), ssf['Scheme_H1']['layout_horizontal'].split(','))) 544 | else: 545 | lh = (0, 0, 0) 546 | 547 | # 竖直边距 548 | pinyin_marge = tryGetValue('Scheme_H1', 'pinyin_marge') 549 | if pinyin_marge: 550 | pinyin_marge = tuple(map(lambda s:int(s), pinyin_marge.split(','))) 551 | else: 552 | assert False 553 | zhongwen_marge = tryGetValue('Scheme_H1', 'zhongwen_marge') 554 | if zhongwen_marge: 555 | zhongwen_marge = tuple(map(lambda s:int(s), zhongwen_marge.split(','))) 556 | else: 557 | assert False 558 | separator = tryGetValue('Scheme_H1', 'separator') 559 | sep = 1 if separator else 0 560 | InputPos = pinyin_marge[0] + font_size 561 | OutputPos = pinyin_marge[0] + pinyin_marge[1] + font_size + \ 562 | sep + zhongwen_marge[0] + font_size 563 | MarginBottom = input_bar_image_size[1] - OutputPos 564 | if lh[1] - pinyin_marge[2] > 32: 565 | MarginLeft = pinyin_marge[2] 566 | else: 567 | MarginLeft = lh[1] 568 | 569 | skin['SkinInputBar'] = { 570 | # 背景图片 571 | 'BackImg': input_bar_image, 572 | 573 | # 左边距 574 | 'MarginLeft': MarginLeft, 575 | 576 | # 右边距 577 | 'MarginRight': lh[2], 578 | 579 | # 上边距 580 | 'MarginTop': 0, 581 | 582 | # 下边距 583 | 'MarginBottom': MarginBottom, 584 | 585 | # 可点击区域的左边距 586 | #ClickMarginLeft=0 587 | # 可点击区域的右边距 588 | #ClickMarginRight=0 589 | # 可点击区域的上边距 590 | #ClickMarginTop=0 591 | # 可点击区域的下边距 592 | #ClickMarginBottom=0 593 | # 覆盖图片 594 | #Overlay=hangul.png 595 | # 覆盖图片停靠位置 596 | # Available Value: 597 | # TopLeft 598 | # TopCenter 599 | # TopRight 600 | # CenterLeft 601 | # Center 602 | # CenterRight 603 | # BottomLeft 604 | # BottomCenter 605 | # BottomRight 606 | #OverlayDock=TopRight 607 | # 覆盖图片 X 偏移 608 | #OverlayOffsetX=-26 609 | # 覆盖图片 Y 偏移 610 | #OverlayOffsetY=2 611 | 612 | # 光标颜色 613 | 'CursorColor': '%d %d %d' % first_color, 614 | 615 | # 预编辑文本的位置或偏移 616 | 'InputPos': InputPos, 617 | 618 | # 候选词表的位置或偏移 619 | 'OutputPos': OutputPos, 620 | 621 | # 上一页图标 622 | 'BackArrow': 'prev.png', 623 | 624 | # 下一页图标 625 | 'ForwardArrow': 'next.png', 626 | 627 | # 上一页图标的横坐标 628 | 'BackArrowX': lh[2] - lh[1] + 10, 629 | 630 | # 上一页图标的纵坐标 631 | 'BackArrowY': pinyin_marge[0], 632 | 633 | # 下一页图标的横坐标 634 | 'ForwardArrowX': lh[2] - lh[1], 635 | 636 | # 下一页图标的纵坐标 637 | 'ForwardArrowY': pinyin_marge[0], 638 | 639 | # 纵向填充规则 640 | # Available Value: 641 | # Copy 642 | # Resize 643 | #FillVertical=Resize 644 | # 横向填充规则 645 | # Available Value: 646 | # Copy 647 | # Resize 648 | #FillHorizontal=Resize 649 | } 650 | 651 | # 使用系统默认的 active.png 和 inactive.png 652 | symlinkF('/usr/share/fcitx/skin/default/active.png', 653 | skin_dir + os.sep + 'active.png') 654 | symlinkF('/usr/share/fcitx/skin/default/inactive.png', 655 | skin_dir + os.sep + 'inactive.png') 656 | 657 | skin['SkinTrayIcon'] = { 658 | # 活动输入法图标 659 | 'Active': 'active.png', 660 | 661 | # 非活动输入法图标 662 | 'Inactive': 'inactive.png', 663 | } 664 | 665 | # 用纯背景色构建出本主题的 menu.png 666 | img = Image.open(default_menu_img_path) 667 | a = np.array(img) 668 | for i in range(len(a)): 669 | for j in range(len(a[0])): 670 | if a[i][j][3]: 671 | a[i][j][0] = back_color[0] 672 | a[i][j][1] = back_color[1] 673 | a[i][j][2] = back_color[2] 674 | img = Image.fromarray(a) 675 | img.save(skin_dir + os.sep + 'menu.png') 676 | 677 | skin['SkinMenu'] = { 678 | # 背景图片 679 | 'BackImg': 'menu.png', 680 | 681 | # 上边距 682 | 'MarginTop': 8, 683 | 684 | # 下边距 685 | 'MarginBottom': 8, 686 | 687 | # 左边距 688 | 'MarginLeft': 8, 689 | 690 | # 右边距 691 | 'MarginRight': 8, 692 | 693 | # 活动菜单项颜色 694 | 'ActiveColor': '%d %d %d' % other_color, 695 | 696 | # 分隔线颜色 697 | 'LineColor': '%d %d %d' % other_color, 698 | } 699 | 700 | skin['SkinKeyboard'] = { 701 | # 虚拟键盘图片 702 | #BackImg=keyboard.png 703 | 704 | # 软键盘按键文字颜色 705 | #'KeyColor': '%d %d %d' % first_color, 706 | } 707 | 708 | skin.write(open(skin_dir + os.sep + 'fcitx_skin.conf', 'w', encoding="utf-8"), False) 709 | 710 | def ssf2fcitx5(skin_dir): 711 | """ 712 | 转换为 fcitx5 格式 713 | 将解压后的 ssf 皮肤,在里面创建出 theme.conf 714 | """ 715 | 716 | skin_dir = skin_dir.rstrip(os.sep) 717 | 718 | # 确保 skin.ini 文件的存在 719 | skin_ini = skin_dir + os.sep + 'skin.ini' 720 | if not os.path.isfile(skin_ini): 721 | sys.stderr.write('找不到 skin.ini\n') 722 | return 1 723 | 724 | # 为了使其区分大小写,重载 ConfigParser 725 | class CaseSensitiveConfigParser(configparser.ConfigParser): 726 | def optionxform(self, optionstr): 727 | return optionstr 728 | 729 | # 读取 skin.ini 文件 730 | try: 731 | ssf = CaseSensitiveConfigParser(allow_no_value = True) 732 | ssf.read(skin_ini, encoding = 'utf-16') 733 | except: 734 | sys.stderr.write('读取 skin.ini 失败\n') 735 | return 2 736 | 737 | # 建立 conf 的对象 738 | skin = CaseSensitiveConfigParser(allow_no_value = True) 739 | 740 | skin['Metadata'] = { 741 | # 皮肤名称 742 | 'Name': ssf['General']['skin_name'], 743 | 744 | # 皮肤版本 745 | 'Version': ssf['General']['skin_version'], 746 | 747 | # 皮肤作者 748 | 'Author': ssf['General']['skin_author'], 749 | 750 | # 描述 751 | 'Description': ssf['General']['skin_info'], 752 | 753 | # 用 DPI 缩放 754 | 'ScaleWithDPI': 'False', 755 | } 756 | 757 | # 将 skin.ini 的颜色转换成 (r,g,b) 三元组 758 | def colorConv(ssf_color): 759 | color_int = int(ssf_color, 16) 760 | r = color_int % 256 761 | g = (color_int % 65536) // 256 762 | b = color_int // 65536 763 | return (r, g, b) 764 | 765 | # 获取图片文件名的函数(获取失败则返回空字符串) 766 | def getImageConfig(section, key, index = 0): 767 | if key in ssf[section]: 768 | image_name_list = ssf[section][key].split(',') 769 | if index < len(image_name_list): 770 | image_name = image_name_list[index] 771 | if os.path.isfile(skin_dir + os.sep + image_name): 772 | return image_name 773 | return '' 774 | 775 | # 尝试获取值的函数 776 | def tryGetValue(section, key): 777 | if key in ssf[section]: 778 | return ssf[section][key].strip() 779 | return '' 780 | 781 | # 根据里面所有的图片,根据所设置的拉伸区域确定合适的背景色 782 | def findBackgroundColor(): 783 | for key in (('Scheme_V1','pic'), 784 | ('Scheme_V2','pinyin_pic'), 785 | ('Scheme_V2','zhongwen_pic'), 786 | ('Scheme_H1','pic'), 787 | ('Scheme_H2','pinyin_pic'), 788 | ('Scheme_H2','zhongwen_pic'), 789 | ): 790 | # 排除不存在的键值 791 | image_name = getImageConfig(key[0], key[1]) 792 | if not image_name : continue 793 | 794 | # 排除区域不存在 795 | h_str = tryGetValue(key[0], key[1][:-3] + 'layout_horizontal') 796 | if not h_str : continue 797 | v_str = tryGetValue(key[0], key[1][:-3] + 'layout_vertical') 798 | if not v_str : continue 799 | 800 | # 得出区域 801 | h = h_str.split(',') 802 | v = v_str.split(',') 803 | if len(h) != 3 or len(v) != 3: continue 804 | 805 | # 排除平铺模式(筛选出是拉伸区域) 806 | #if int(h[0]) != 0 or int(v[0]) != 0: 807 | # continue 808 | 809 | return getImageAvg(skin_dir + os.sep + image_name, 810 | (int(h[1]), 811 | -int(h[2]), 812 | int(v[1]), 813 | -int(v[2]))) 814 | else: 815 | return (0, 0, 0) 816 | 817 | # 输入框输入的拼音颜色 818 | input_color = colorConv(ssf['Display']['pinyin_color']) 819 | 820 | # 列表中第一个词的颜色 821 | first_color = colorConv(ssf['Display']['zhongwen_first_color']) 822 | 823 | # 列表中其他词的颜色 824 | other_color = colorConv(ssf['Display']['zhongwen_color']) 825 | 826 | # 根据里面所有的图片,根据所设置的拉伸区域确定合适的背景色 827 | back_color = findBackgroundColor() 828 | 829 | # 字体大小(像素) 830 | font_size = int(ssf['Display']['font_size']) 831 | 832 | skin['InputPanel'] = { 833 | # 字体及其大小 834 | 'Font': 'Sans %d' % font_size, 835 | 836 | # 非选中候选字颜色 837 | 'NormalColor': '#%02x%02x%02x' % other_color, 838 | 839 | # 选中候选字颜色 840 | 'HighlightCandidateColor': '#%02x%02x%02x' % first_color, 841 | 842 | # 高亮前景颜色(输入字符颜色) 843 | 'HighlightColor': '#%02x%02x%02x' % input_color, 844 | 845 | # 输入字符背景颜色 846 | 'HighlightBackgroundColor': '#%02x%02x%02x' % back_color, 847 | 848 | # 849 | 'Spacing': 3, 850 | } 851 | 852 | # 输入框背景图 853 | input_bar_image = getImageConfig('Scheme_H1', 'pic') 854 | input_bar_image_size = getImageSize(skin_dir + os.sep + input_bar_image) 855 | 856 | # 水平拉升区域 857 | lh = tryGetValue('Scheme_H1', 'layout_horizontal') 858 | if lh: 859 | lh = tuple(map(lambda s:int(s), lh.split(','))) 860 | else: 861 | lh = (0, 2, 2) 862 | 863 | # 垂直拉升区域 864 | lv = tryGetValue('Scheme_H1', 'layout_vertical') 865 | if lv: 866 | lv = tuple(map(lambda s:int(s), lv.split(','))) 867 | else: 868 | lv = (0, 2, 2) 869 | 870 | # 拼音边距 871 | pinyin_marge = tryGetValue('Scheme_H1', 'pinyin_marge') 872 | if pinyin_marge: 873 | pinyin_marge = tuple(map(lambda s:int(s), pinyin_marge.split(','))) 874 | else: 875 | assert False 876 | 877 | # 候选词边距 878 | zhongwen_marge = tryGetValue('Scheme_H1', 'zhongwen_marge') 879 | if zhongwen_marge: 880 | zhongwen_marge = tuple(map(lambda s:int(s), zhongwen_marge.split(','))) 881 | else: 882 | assert False 883 | 884 | # 分隔符长度 885 | sep = 1 if tryGetValue('Scheme_H1', 'separator') else 0 886 | 887 | # 恒等式: 888 | # 输入的拼音下方到候选词上方的距离: 889 | # pinyin_marge[1] + sep + zhongwen_marge[0] = TextMargin.Bottom + TextMargin.Top 890 | # 输入的拼音上方到上方边界的距离: 891 | # pinyin_marge[0] = ContentMargin.Top + TextMargin.Top 892 | # 候选词下方到下方边界的距离: 893 | # zhongwen_marge[1] = ContentMargin.Bottom + TextMargin.Bottom 894 | # 895 | # 896 | # 这是四元一次方程组,由于只有三个方程,那么随便确定其中一个即可解得其它未知数。 897 | # 增加的方程: 898 | # TextMargin.Bottom = (pinyin_marge[1] + sep + zhongwen_marge[0]) // 2 899 | 900 | distant_pinyin_zhongwen = pinyin_marge[1] + sep + zhongwen_marge[0] 901 | 902 | # 解得: 903 | TextMargin_Bottom = distant_pinyin_zhongwen // 2 904 | TextMargin_Top = distant_pinyin_zhongwen - TextMargin_Bottom 905 | ContentMargin_Top = pinyin_marge[0] - TextMargin_Top 906 | #ContentMargin_Bottom = zhongwen_marge[1] - TextMargin_Bottom 907 | ContentMargin_Bottom = input_bar_image_size[1] - \ 908 | ContentMargin_Top - TextMargin_Top - font_size - TextMargin_Bottom - \ 909 | TextMargin_Top - font_size - TextMargin_Bottom 910 | 911 | TextMargin_Top_Left = 5 912 | TextMargin_Top_Right = 5 913 | 914 | # 文字边距 915 | skin['InputPanel/TextMargin'] = { 916 | 'Left': TextMargin_Top_Left, 917 | 'Right': TextMargin_Top_Right, 918 | 'Top': TextMargin_Top, 919 | 'Bottom': TextMargin_Bottom, 920 | } 921 | 922 | # 输入框内容边距 923 | skin['InputPanel/ContentMargin'] = { 924 | 'Left': max(pinyin_marge[2], zhongwen_marge[2]) - TextMargin_Top_Left, 925 | 'Right': max(pinyin_marge[3], zhongwen_marge[3]) - TextMargin_Top_Right, 926 | 'Top': ContentMargin_Top, 927 | 'Bottom': ContentMargin_Bottom, 928 | } 929 | 930 | # 输入框背景图 931 | skin['InputPanel/Background'] = { 932 | 'Image': input_bar_image, 933 | } 934 | 935 | # 输入框背景图的拉升区域 936 | skin['InputPanel/Background/Margin'] = { 937 | 'Left': lh[1], 938 | 'Right': lh[2], 939 | 'Top': lv[1], 940 | 'Bottom': lv[2], 941 | } 942 | 943 | 944 | # 绘制高亮的纯色图片 945 | # menu_highlight_color = rgbDistMax(first_color, input_color, other_color, back_color) 946 | Image.new('RGBA', (38,23), (0,0,0,0)).save(skin_dir + os.sep + 'highlight.png') 947 | 948 | # 高亮背景 949 | skin['InputPanel/Highlight'] = { 950 | 'Image': 'highlight.png', 951 | } 952 | # 高亮背景边距 953 | skin['InputPanel/Highlight/Margin'] = { 954 | 'Left': 5, 955 | 'Right': 5, 956 | 'Top': 5, 957 | 'Bottom': 5, 958 | } 959 | 960 | 961 | # 绘制 prev.png 和 next.png 颜色为 '%d %d %d' % other_color 962 | savePolygon((16,24), ((5,6),(5,18),(11,12)), other_color, skin_dir + os.sep + 'next.png') 963 | savePolygon((16,24), ((11,6),(11,18),(5,12)), other_color, skin_dir + os.sep + 'prev.png') 964 | 965 | 966 | # 前一页的箭头 967 | skin['InputPanel/PrevPage'] = { 968 | 'Image': 'prev.png', 969 | } 970 | skin['InputPanel/PrevPage/ClickMargin'] = { 971 | 'Left': 5, 972 | 'Right': 5, 973 | 'Top': 4, 974 | 'Bottom': 4, 975 | } 976 | # 后一页的箭头 977 | skin['InputPanel/NextPage'] = { 978 | 'Image': 'next.png', 979 | } 980 | skin['InputPanel/NextPage/ClickMargin'] = { 981 | 'Left': 5, 982 | 'Right': 5, 983 | 'Top': 4, 984 | 'Bottom': 4, 985 | } 986 | 987 | # 竖排合窗口设置 988 | Scheme_V1_pic = tryGetValue('Scheme_V1', 'pic') 989 | 990 | # 水平拉升区域 991 | lh = tryGetValue('Scheme_V1', 'layout_horizontal') 992 | if lh: 993 | lh = tuple(map(lambda s:int(s), lh.split(','))) 994 | else: 995 | lh = None 996 | 997 | # 垂直拉升区域 998 | lv = tryGetValue('Scheme_V1', 'layout_vertical') 999 | if lv: 1000 | lv = tuple(map(lambda s:int(s), lv.split(','))) 1001 | else: 1002 | lv = None 1003 | 1004 | # 拼音边距 1005 | pinyin_marge = tryGetValue('Scheme_V1', 'pinyin_marge') 1006 | if pinyin_marge: 1007 | pinyin_marge = tuple(map(lambda s:int(s), pinyin_marge.split(','))) 1008 | else: 1009 | pinyin_marge = None 1010 | 1011 | # 候选词边距 1012 | zhongwen_marge = tryGetValue('Scheme_V1', 'zhongwen_marge') 1013 | if zhongwen_marge: 1014 | zhongwen_marge = tuple(map(lambda s:int(s), zhongwen_marge.split(','))) 1015 | else: 1016 | zhongwen_marge = None 1017 | 1018 | if Scheme_V1_pic and lh and lv and pinyin_marge and zhongwen_marge: 1019 | # 背景图片 1020 | skin['Menu/Background'] = { 1021 | 'Image': Scheme_V1_pic, 1022 | } 1023 | 1024 | # 背景图片拉升边距 1025 | skin['Menu/Background/Margin'] = { 1026 | 'Left': lh[1], 1027 | 'Right': lh[2], 1028 | 'Top': lv[1], 1029 | 'Bottom': lv[2], 1030 | } 1031 | 1032 | sep = 1 if tryGetValue('Scheme_V1', 'separator') else 0 1033 | 1034 | # 背景图片内容边距 1035 | horizontal_margin = min(zhongwen_marge[2], zhongwen_marge[3]) 1036 | skin['Menu/ContentMargin'] = { 1037 | # 左边距 1038 | 'Left': horizontal_margin, 1039 | 1040 | # 右边距 1041 | 'Right': horizontal_margin, 1042 | 1043 | # 上边距 1044 | 'Top': pinyin_marge[0] + pinyin_marge[1] + sep + zhongwen_marge[0], 1045 | 1046 | # 下边距 1047 | 'Bottom': zhongwen_marge[1], 1048 | } 1049 | else: 1050 | # 构建纯色背景 1051 | 1052 | # 用纯背景色构建出本主题的 menu.png 1053 | img = Image.open(default_menu_img_path) 1054 | a = np.array(img) 1055 | for i in range(len(a)): 1056 | for j in range(len(a[0])): 1057 | if a[i][j][3]: 1058 | a[i][j][0] = back_color[0] 1059 | a[i][j][1] = back_color[1] 1060 | a[i][j][2] = back_color[2] 1061 | img = Image.fromarray(a) 1062 | img.save(skin_dir + os.sep + 'menu.png') 1063 | 1064 | # 背景图片 1065 | skin['Menu/Background'] = { 1066 | 'Image': 'menu.png', 1067 | } 1068 | 1069 | # 背景图片拉升边距 1070 | skin['Menu/Background/Margin'] = { 1071 | 'Left': 20, 1072 | 'Right': 20, 1073 | 'Top': 20, 1074 | 'Bottom': 20, 1075 | } 1076 | 1077 | # 背景图片内容边距 1078 | skin['Menu/ContentMargin'] = { 1079 | # 左边距 1080 | 'Left': 8, 1081 | 1082 | # 右边距 1083 | 'Right': 8, 1084 | 1085 | # 上边距 1086 | 'Top': 8, 1087 | 1088 | # 下边距 1089 | 'Bottom': 8, 1090 | } 1091 | 1092 | # 绘制高亮的透明图片 1093 | #menu_highlight_color = rgbDistMax((255,255,255), back_color, input_color, first_color, other_color) 1094 | Image.new('RGBA', (38,23), (0,0,0,0)).save(skin_dir + os.sep + 'menu_highlight.png') 1095 | 1096 | # 高亮背景 1097 | skin['Menu/Highlight'] = { 1098 | 'Image': 'menu_highlight.png', 1099 | } 1100 | # 高亮背景边距 1101 | skin['Menu/Highlight/Margin'] = { 1102 | 'Left': 10, 1103 | 'Right': 10, 1104 | 'Top': 5, 1105 | 'Bottom': 5, 1106 | } 1107 | 1108 | # 分隔符颜色 1109 | skin['Menu/Separator'] = { 1110 | 'Color': '#%02x%02x%02x' % other_color, 1111 | } 1112 | 1113 | # 用纯背景色构建出本主题的 radio.png 1114 | img = Image.open(default_radio_img_path) 1115 | a = np.array(img) 1116 | for i in range(len(a)): 1117 | for j in range(len(a[0])): 1118 | if a[i][j][3]: 1119 | a[i][j][0] = other_color[0] 1120 | a[i][j][1] = other_color[1] 1121 | a[i][j][2] = other_color[2] 1122 | img = Image.fromarray(a) 1123 | img.save(skin_dir + os.sep + 'radio.png') 1124 | 1125 | # 复选框图片 1126 | skin['Menu/CheckBox'] = { 1127 | 'Image': 'radio.png', 1128 | } 1129 | 1130 | # 绘制箭头图片 1131 | savePolygon((6,12), ((0,0),(6,6),(0,12)), other_color, skin_dir + os.sep + 'arrow.png') 1132 | 1133 | # 箭头图片 1134 | skin['Menu/SubMenu'] = { 1135 | 'Image': 'arrow.png', 1136 | } 1137 | 1138 | # 菜单文字项边距 1139 | skin['Menu/TextMargin'] = { 1140 | # 左边距 1141 | 'Left': 5, 1142 | 1143 | # 右边距 1144 | 'Right': 5, 1145 | 1146 | # 上边距 1147 | 'Top': 5, 1148 | 1149 | # 下边距 1150 | 'Bottom': 5, 1151 | } 1152 | 1153 | skin.write(open(skin_dir + os.sep + 'theme.conf', 'w', encoding="utf-8"), False) 1154 | return 0 1155 | 1156 | def main(args): 1157 | 1158 | # 先从源文件转换成文件夹,如果已经是文件夹了则跳过 1159 | tmp_dir = None 1160 | if os.path.isfile(args.src): 1161 | 1162 | # 确定目标目录 1163 | if args.type == 'encrypted' or args.type == 'zip': 1164 | tmp_dir = tempfile.mkdtemp() 1165 | dest_dir = tmp_dir 1166 | else: 1167 | dest_dir = args.dest 1168 | 1169 | # 开始解压 1170 | extractSsf(args.src, dest_dir) 1171 | 1172 | skin_dir = dest_dir 1173 | elif os.path.isdir(args.src): 1174 | skin_dir = args.src 1175 | else: 1176 | sys.stderr.write('找不到 %s\n' % args.src) 1177 | return 1 1178 | 1179 | result = 255 1180 | if args.type == 'fcitx': 1181 | result = ssf2fcitx(skin_dir) 1182 | elif args.type == 'fcitx5': 1183 | result = ssf2fcitx5(skin_dir) 1184 | elif args.type == 'zip': 1185 | file_list = os.listdir(skin_dir) 1186 | with zipfile.ZipFile(args.dest, 'w') as zf: 1187 | for file in file_list: 1188 | zf.write(skin_dir + os.sep + file, file) 1189 | result = 0 1190 | elif args.type == 'encrypted': 1191 | assert False 1192 | # TODO 还没实现转换成加密的 ssf 1193 | 1194 | if tmp_dir: 1195 | shutil.rmtree(tmp_dir) 1196 | 1197 | return result 1198 | 1199 | if __name__ == '__main__': 1200 | parser = argparse.ArgumentParser(description = \ 1201 | 'Sogou input method skin file (.ssf file) converter.') 1202 | parser.add_argument('src', help = 'Input path') 1203 | parser.add_argument('dest', help = 'Output path') 1204 | parser.add_argument('--type', '-t', 1205 | help = 'The type of destination path file (folder).' + \ 1206 | 'The default is fcitx.', 1207 | default = 'fcitx', 1208 | choices = ['fcitx', 'fcitx5', 'dir', 'encrypted', 'zip']) 1209 | args = parser.parse_args() 1210 | 1211 | exit(main(args)) 1212 | 1213 | extractSsf(sys.argv[1], sys.argv[2]) 1214 | ssf2fcitx(sys.argv[2]) 1215 | 1216 | --------------------------------------------------------------------------------