IME // Reintroducing OpenCCBridge with CrossConvert support.

- This is only for cross-converting in-place user phrases.
This commit is contained in:
ShikiSuen 2022-03-10 17:02:05 +08:00
parent f6a34b61a9
commit aaee0a686b
2 changed files with 118 additions and 7 deletions

View File

@ -0,0 +1,52 @@
// Copyright (c) 2011 and onwards The OpenVanilla Project (MIT License).
// All possible vChewing-specific modifications are (c) 2021 and onwards The vChewing Project (MIT-NTL License).
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2. No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor,
except as required to fulfill notice requirements above.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import Foundation
import OpenCC
/// A bridge to let Objctive-C code to access SwiftyOpenCC.
///
/// Since SwiftyOpenCC only provide Swift classes, we create an NSObject subclass
/// in Swift in order to bridge the Swift classes into our Objective-C++ project.
public class OpenCCBridge: NSObject {
private static let shared = OpenCCBridge()
private var simplify: ChineseConverter?
private var traditionalize: ChineseConverter?
private override init() {
try? simplify = ChineseConverter(options: .simplify)
try? traditionalize = ChineseConverter(options: [.traditionalize, .twStandard])
super.init()
}
/// CrossConvert.
///
/// - Parameter string: Text in Original Script.
/// - Returns: Text converted to Different Script.
@objc public static func crossConvert(_ string: String) -> String? {
switch ctlInputMethod.currentKeyHandler.inputMode {
case InputMode.imeModeCHS:
return shared.traditionalize?.convert(string)
case InputMode.imeModeCHT:
return shared.simplify?.convert(string)
default:
return string
}
}
}

View File

@ -3,7 +3,7 @@
archiveVersion = 1; archiveVersion = 1;
classes = { classes = {
}; };
objectVersion = 46; objectVersion = 52;
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
@ -31,6 +31,8 @@
5B62A34927AE7CD900A19448 /* TooltipController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34327AE7CD900A19448 /* TooltipController.swift */; }; 5B62A34927AE7CD900A19448 /* TooltipController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34327AE7CD900A19448 /* TooltipController.swift */; };
5B62A34A27AE7CD900A19448 /* NotifierController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34527AE7CD900A19448 /* NotifierController.swift */; }; 5B62A34A27AE7CD900A19448 /* NotifierController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34527AE7CD900A19448 /* NotifierController.swift */; };
5B62A35327AE89C400A19448 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */; }; 5B62A35327AE89C400A19448 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */; };
5B707CE827D9F4590099EF99 /* OpenCCBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B707CE727D9F4590099EF99 /* OpenCCBridge.swift */; };
5B707CEC27D9F4870099EF99 /* OpenCC in Frameworks */ = {isa = PBXBuildFile; productRef = 5B707CEB27D9F4870099EF99 /* OpenCC */; };
5B73FB5E27B2BE1300E9BF49 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5B73FB6027B2BE1300E9BF49 /* InfoPlist.strings */; }; 5B73FB5E27B2BE1300E9BF49 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5B73FB6027B2BE1300E9BF49 /* InfoPlist.strings */; };
5B7BC4B027AFFBE800F66C24 /* frmPrefWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B7BC4AE27AFFBE800F66C24 /* frmPrefWindow.xib */; }; 5B7BC4B027AFFBE800F66C24 /* frmPrefWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B7BC4AE27AFFBE800F66C24 /* frmPrefWindow.xib */; };
5BAD0CD527D701F6003D127F /* vChewingKeyLayout.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 5B30F11227BA568800484E24 /* vChewingKeyLayout.bundle */; }; 5BAD0CD527D701F6003D127F /* vChewingKeyLayout.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 5B30F11227BA568800484E24 /* vChewingKeyLayout.bundle */; };
@ -193,6 +195,8 @@
5B62A34127AE7CD900A19448 /* VerticalCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerticalCandidateController.swift; sourceTree = "<group>"; }; 5B62A34127AE7CD900A19448 /* VerticalCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerticalCandidateController.swift; sourceTree = "<group>"; };
5B62A34327AE7CD900A19448 /* TooltipController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TooltipController.swift; sourceTree = "<group>"; }; 5B62A34327AE7CD900A19448 /* TooltipController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TooltipController.swift; sourceTree = "<group>"; };
5B62A34527AE7CD900A19448 /* NotifierController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotifierController.swift; sourceTree = "<group>"; }; 5B62A34527AE7CD900A19448 /* NotifierController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotifierController.swift; sourceTree = "<group>"; };
5B707CE527D9F3A10099EF99 /* SwiftyOpenCC */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SwiftyOpenCC; path = Packages/SwiftyOpenCC; sourceTree = "<group>"; };
5B707CE727D9F4590099EF99 /* OpenCCBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenCCBridge.swift; sourceTree = "<group>"; };
5B73FB5427B2BD6900E9BF49 /* PhraseEditor-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "PhraseEditor-Info.plist"; path = "UserPhraseEditor/PhraseEditor-Info.plist"; sourceTree = SOURCE_ROOT; }; 5B73FB5427B2BD6900E9BF49 /* PhraseEditor-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "PhraseEditor-Info.plist"; path = "UserPhraseEditor/PhraseEditor-Info.plist"; sourceTree = SOURCE_ROOT; };
5B73FB5F27B2BE1300E9BF49 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; 5B73FB5F27B2BE1300E9BF49 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5B7BC4AF27AFFBE800F66C24 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Source/WindowNIBs/Base.lproj/frmPrefWindow.xib; sourceTree = "<group>"; }; 5B7BC4AF27AFFBE800F66C24 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Source/WindowNIBs/Base.lproj/frmPrefWindow.xib; sourceTree = "<group>"; };
@ -307,6 +311,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
5B707CEC27D9F4870099EF99 /* OpenCC in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -352,6 +357,7 @@
5B62A30127AE732800A19448 /* 3rdParty */ = { 5B62A30127AE732800A19448 /* 3rdParty */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
5B707CE627D9F43E0099EF99 /* OpenCCBridge */,
5B62A31427AE73A700A19448 /* AWFileHash */, 5B62A31427AE73A700A19448 /* AWFileHash */,
5B62A30727AE73A700A19448 /* SSZipArchive */, 5B62A30727AE73A700A19448 /* SSZipArchive */,
5B62A30227AE733500A19448 /* OVMandarin */, 5B62A30227AE733500A19448 /* OVMandarin */,
@ -582,6 +588,22 @@
name = Data; name = Data;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
5B707CE427D9F3A10099EF99 /* Packages */ = {
isa = PBXGroup;
children = (
5B707CE527D9F3A10099EF99 /* SwiftyOpenCC */,
);
name = Packages;
sourceTree = "<group>";
};
5B707CE627D9F43E0099EF99 /* OpenCCBridge */ = {
isa = PBXGroup;
children = (
5B707CE727D9F4590099EF99 /* OpenCCBridge.swift */,
);
path = OpenCCBridge;
sourceTree = "<group>";
};
5BBBB75C27AED54C0023B93A /* SoundFiles */ = { 5BBBB75C27AED54C0023B93A /* SoundFiles */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -651,6 +673,7 @@
6A0D4E9215FC0CFA00ABF4B3 = { 6A0D4E9215FC0CFA00ABF4B3 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
5B707CE427D9F3A10099EF99 /* Packages */,
5BBD627827B6C4D900271480 /* Update-Info.plist */, 5BBD627827B6C4D900271480 /* Update-Info.plist */,
5B18BA7027C7BD8B0056EB19 /* Makefile */, 5B18BA7027C7BD8B0056EB19 /* Makefile */,
5B0C5EDE27C7D94C0078037C /* DataCompiler */, 5B0C5EDE27C7D94C0078037C /* DataCompiler */,
@ -802,11 +825,13 @@
buildRules = ( buildRules = (
); );
dependencies = ( dependencies = (
5B707CEA27D9F47A0099EF99 /* PBXTargetDependency */,
5B0AF8B327B2C4E20096FE54 /* PBXTargetDependency */, 5B0AF8B327B2C4E20096FE54 /* PBXTargetDependency */,
6A38BC2615FC131100A8A51F /* PBXTargetDependency */, 6A38BC2615FC131100A8A51F /* PBXTargetDependency */,
); );
name = vChewing; name = vChewing;
packageProductDependencies = ( packageProductDependencies = (
5B707CEB27D9F4870099EF99 /* OpenCC */,
); );
productName = vChewing; productName = vChewing;
productReference = 6A0D4EA215FC0D2D00ABF4B3 /* vChewing.app */; productReference = 6A0D4EA215FC0D2D00ABF4B3 /* vChewing.app */;
@ -978,6 +1003,7 @@
files = ( files = (
5B62A31927AE73A700A19448 /* ioapi.m in Sources */, 5B62A31927AE73A700A19448 /* ioapi.m in Sources */,
5B62A31C27AE73A700A19448 /* AWFileHash.m in Sources */, 5B62A31C27AE73A700A19448 /* AWFileHash.m in Sources */,
5B707CE827D9F4590099EF99 /* OpenCCBridge.swift in Sources */,
D427F76C278CA2B0004A2160 /* AppDelegate.swift in Sources */, D427F76C278CA2B0004A2160 /* AppDelegate.swift in Sources */,
6ACC3D442793701600F1B140 /* ParselessPhraseDB.cpp in Sources */, 6ACC3D442793701600F1B140 /* ParselessPhraseDB.cpp in Sources */,
D461B792279DAC010070E734 /* InputState.swift in Sources */, D461B792279DAC010070E734 /* InputState.swift in Sources */,
@ -1037,6 +1063,10 @@
target = 5BD05BB727B2A429004C4F1D /* vChewingPhraseEditor */; target = 5BD05BB727B2A429004C4F1D /* vChewingPhraseEditor */;
targetProxy = 5B0AF8B227B2C4E20096FE54 /* PBXContainerItemProxy */; targetProxy = 5B0AF8B227B2C4E20096FE54 /* PBXContainerItemProxy */;
}; };
5B707CEA27D9F47A0099EF99 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 5B707CE927D9F47A0099EF99 /* OpenCC */;
};
6A38BC2615FC131100A8A51F /* PBXTargetDependency */ = { 6A38BC2615FC131100A8A51F /* PBXTargetDependency */ = {
isa = PBXTargetDependency; isa = PBXTargetDependency;
target = 6A38BC2115FC12FD00A8A51F /* Data */; target = 6A38BC2115FC12FD00A8A51F /* Data */;
@ -1223,7 +1253,10 @@
INFOPLIST_KEY_NSHumanReadableCopyright = "© 2021-2022 vChewing Project."; INFOPLIST_KEY_NSHumanReadableCopyright = "© 2021-2022 vChewing Project.";
INFOPLIST_KEY_NSMainStoryboardFile = Main; INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication; INFOPLIST_KEY_NSPrincipalClass = NSApplication;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11.5; MACOSX_DEPLOYMENT_TARGET = 10.11.5;
MARKETING_VERSION = 1.3.7; MARKETING_VERSION = 1.3.7;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
@ -1271,7 +1304,10 @@
INFOPLIST_KEY_NSHumanReadableCopyright = "© 2021-2022 vChewing Project."; INFOPLIST_KEY_NSHumanReadableCopyright = "© 2021-2022 vChewing Project.";
INFOPLIST_KEY_NSMainStoryboardFile = Main; INFOPLIST_KEY_NSMainStoryboardFile = Main;
INFOPLIST_KEY_NSPrincipalClass = NSApplication; INFOPLIST_KEY_NSPrincipalClass = NSApplication;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11.5; MACOSX_DEPLOYMENT_TARGET = 10.11.5;
MARKETING_VERSION = 1.3.7; MARKETING_VERSION = 1.3.7;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
@ -1418,7 +1454,10 @@
GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "Source/Resources/IME-Info.plist"; INFOPLIST_FILE = "Source/Resources/IME-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11.5; MACOSX_DEPLOYMENT_TARGET = 10.11.5;
MARKETING_VERSION = 1.3.7; MARKETING_VERSION = 1.3.7;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
@ -1477,7 +1516,10 @@
GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "Source/Resources/IME-Info.plist"; INFOPLIST_FILE = "Source/Resources/IME-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11.5; MACOSX_DEPLOYMENT_TARGET = 10.11.5;
MARKETING_VERSION = 1.3.7; MARKETING_VERSION = 1.3.7;
PRODUCT_BUNDLE_IDENTIFIER = org.atelierInmu.inputmethod.vChewing; PRODUCT_BUNDLE_IDENTIFIER = org.atelierInmu.inputmethod.vChewing;
@ -1582,7 +1624,10 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = ../; HEADER_SEARCH_PATHS = ../;
INFOPLIST_FILE = "Installer/Installer-Info.plist"; INFOPLIST_FILE = "Installer/Installer-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11.5; MACOSX_DEPLOYMENT_TARGET = 10.11.5;
MARKETING_VERSION = 1.3.7; MARKETING_VERSION = 1.3.7;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
@ -1626,7 +1671,10 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = ../; HEADER_SEARCH_PATHS = ../;
INFOPLIST_FILE = "Installer/Installer-Info.plist"; INFOPLIST_FILE = "Installer/Installer-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11.5; MACOSX_DEPLOYMENT_TARGET = 10.11.5;
MARKETING_VERSION = 1.3.7; MARKETING_VERSION = 1.3.7;
PRODUCT_BUNDLE_IDENTIFIER = "org.atelierInmu.vChewing.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_BUNDLE_IDENTIFIER = "org.atelierInmu.vChewing.${PRODUCT_NAME:rfc1034identifier}";
@ -1688,6 +1736,17 @@
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCSwiftPackageProductDependency section */
5B707CE927D9F47A0099EF99 /* OpenCC */ = {
isa = XCSwiftPackageProductDependency;
productName = OpenCC;
};
5B707CEB27D9F4870099EF99 /* OpenCC */ = {
isa = XCSwiftPackageProductDependency;
productName = OpenCC;
};
/* End XCSwiftPackageProductDependency section */
}; };
rootObject = 6A0D4E9415FC0CFA00ABF4B3 /* Project object */; rootObject = 6A0D4E9415FC0CFA00ABF4B3 /* Project object */;
} }