diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index c40ad2434..4bdb66825 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 03008B2B2940D3230062B821 /* EZDeepLTranslate.m in Sources */ = {isa = PBXBuildFile; fileRef = 03008B2A2940D3230062B821 /* EZDeepLTranslate.m */; }; 03008B2E2941956D0062B821 /* EZURLSchemeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 03008B2D2941956D0062B821 /* EZURLSchemeHandler.m */; }; 03008B3F29444B0A0062B821 /* NSView+EZAnimatedHidden.m in Sources */ = {isa = PBXBuildFile; fileRef = 03008B3E29444B0A0062B821 /* NSView+EZAnimatedHidden.m */; }; + 03022F1C2B35DEBA00B63209 /* Hue in Frameworks */ = {isa = PBXBuildFile; productRef = 03022F1B2B35DEBA00B63209 /* Hue */; }; 030570E22ADB919900C9905E /* EZAppleScriptManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 030570E12ADB919900C9905E /* EZAppleScriptManager.m */; }; 0309E1ED292B439A00AFB76A /* EZTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0309E1EC292B439A00AFB76A /* EZTextView.m */; }; 0309E1F0292B4A5E00AFB76A /* NSView+EZGetViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0309E1EF292B4A5E00AFB76A /* NSView+EZGetViewController.m */; }; @@ -229,6 +230,8 @@ C4DD01ED2B12BE9B0025EE8E /* TencentTranslateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01EC2B12BE9B0025EE8E /* TencentTranslateType.swift */; }; C4DE3D6D2AC00EB500C2B85D /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = C4DE3D6C2AC00EB500C2B85D /* Localizable.xcstrings */; }; C98CAE75239F4619005F7DCA /* EasydictHelper.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = C90BE309239F38EB00ADE88B /* EasydictHelper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + DC3C643F2B187119008EEDD8 /* ChangeFontSizeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */; }; + DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -676,6 +679,8 @@ C4DE3D6E2AC00EB500C2B85D /* mul */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; name = mul; path = mul.lproj/Main.xcstrings; sourceTree = ""; }; C90BE309239F38EB00ADE88B /* EasydictHelper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EasydictHelper.app; sourceTree = BUILT_PRODUCTS_DIR; }; C99EEB182385796700FEE666 /* Easydict-debug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Easydict-debug.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeFontSizeView.swift; sourceTree = ""; }; + DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontSizeHintView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -701,6 +706,7 @@ 2721E4D02AFE920700A059AC /* Alamofire in Frameworks */, 03FD68BB2B1DC59600FD388E /* CryptoSwift in Frameworks */, B87AC7E36367075BA5D13234 /* Pods_Easydict.framework in Frameworks */, + 03022F1C2B35DEBA00B63209 /* Hue in Frameworks */, 03B63ABF2A86967800E155ED /* CoreServices.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1274,6 +1280,7 @@ isa = PBXGroup; children = ( 62ED299F2B15F1BE00901F51 /* EZWrapView */, + DC3C643D2B18710D008EEDD8 /* ChangeFontSizeView */, 03E3E7BF2ADE313400812C84 /* EZQueryMenuTextView */, 03DC7C632A3CA465000BF7C9 /* EZSegmentedControl */, 03247E37296AE8C800AFCD67 /* LoadingAnimationView */, @@ -1983,6 +1990,15 @@ name = Products; sourceTree = ""; }; + DC3C643D2B18710D008EEDD8 /* ChangeFontSizeView */ = { + isa = PBXGroup; + children = ( + DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */, + DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */, + ); + path = ChangeFontSizeView; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -2043,6 +2059,7 @@ packageProductDependencies = ( 2721E4CF2AFE920700A059AC /* Alamofire */, 03FD68BA2B1DC59600FD388E /* CryptoSwift */, + 03022F1B2B35DEBA00B63209 /* Hue */, ); productName = Bob; productReference = C99EEB182385796700FEE666 /* Easydict-debug.app */; @@ -2085,6 +2102,7 @@ packageReferences = ( 2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */, 03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */, + 03022F1A2B35DEBA00B63209 /* XCRemoteSwiftPackageReference "Hue" */, ); productRefGroup = C99EEB192385796700FEE666 /* Products */; projectDirPath = ""; @@ -2396,6 +2414,7 @@ 039D119929D5E26300C93F46 /* EZAudioUtils.m in Sources */, 03B0231729231FA6001C7E63 /* Snip.m in Sources */, 03BFFC6E295FE59C004E033E /* EZQueryResult+EZYoudaoDictModel.m in Sources */, + DC3C643F2B187119008EEDD8 /* ChangeFontSizeView.swift in Sources */, 03B0232829231FA6001C7E63 /* NSTextView+Height.m in Sources */, 03B0232129231FA6001C7E63 /* NSPasteboard+MM.m in Sources */, 03D043522928935300E7559E /* EZMainQueryWindow.m in Sources */, @@ -2441,6 +2460,7 @@ 03D8A6592A42A1A300D9A968 /* EZAppModel.m in Sources */, 036E7D7B293F4FC8002675DF /* EZOpenLinkButton.m in Sources */, 03008B2E2941956D0062B821 /* EZURLSchemeHandler.m in Sources */, + DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */, 03B0232429231FA6001C7E63 /* NSUserDefaults+MM.m in Sources */, 03542A5E2938F05B00C34C33 /* EZLanguageModel.m in Sources */, 03F639952AA6CFBB009B9914 /* EZBingConfig.m in Sources */, @@ -2839,6 +2859,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 03022F1A2B35DEBA00B63209 /* XCRemoteSwiftPackageReference "Hue" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/zenangst/Hue"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.0.1; + }; + }; 03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/krzyzanowskim/CryptoSwift"; @@ -2858,6 +2886,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 03022F1B2B35DEBA00B63209 /* Hue */ = { + isa = XCSwiftPackageProductDependency; + package = 03022F1A2B35DEBA00B63209 /* XCRemoteSwiftPackageReference "Hue" */; + productName = Hue; + }; 03FD68BA2B1DC59600FD388E /* CryptoSwift */ = { isa = XCSwiftPackageProductDependency; package = 03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */; diff --git a/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved index a099cf05a..c9a157cf7 100644 --- a/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -17,6 +17,15 @@ "revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e", "version" : "1.8.0" } + }, + { + "identity" : "hue", + "kind" : "remoteSourceControl", + "location" : "https://github.com/zenangst/Hue", + "state" : { + "revision" : "b9d920cee4ba795fefb828d130744eee1e3d2feb", + "version" : "5.0.1" + } } ], "version" : 2 diff --git a/Easydict/App/Base.lproj/Main.storyboard b/Easydict/App/Base.lproj/Main.storyboard index 29c5caf1f..9df59d2cb 100644 --- a/Easydict/App/Base.lproj/Main.storyboard +++ b/Easydict/App/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -308,9 +308,9 @@ - + - + @@ -363,6 +363,16 @@ + + + + + + + + + + diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 6f8004469..d88690ec7 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -1050,6 +1050,23 @@ } } }, + "font_size" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Font Size:" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "字体大小:" + } + } + } + }, "force_auto_get_selected_text" : { "localizations" : { "en" : { @@ -1199,6 +1216,23 @@ } } }, + "hints_keyboard_shortcuts_font_size" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Font size can be changed using the ⌘ +/- shortcut in the Translation windows." + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "支持在翻译窗口通过快捷键 ⌘ +/- 修改字体大小" + } + } + } + }, "Illegal parameter supplied to encryption/decryption algorithm" : { "comment" : "Error reason", "localizations" : { @@ -1339,6 +1373,23 @@ } } }, + "large" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Large" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "大" + } + } + } + }, "lastest_version" : { "localizations" : { "en" : { @@ -2115,6 +2166,23 @@ } } }, + "small" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Small" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "小" + } + } + } + }, "snip_translate" : { "localizations" : { "en" : { diff --git a/Easydict/App/mul.lproj/Main.xcstrings b/Easydict/App/mul.lproj/Main.xcstrings index 06697df8d..f39988433 100644 --- a/Easydict/App/mul.lproj/Main.xcstrings +++ b/Easydict/App/mul.lproj/Main.xcstrings @@ -384,6 +384,18 @@ } } }, + "525-TU-MBZ.title" : { + "comment" : "Class = \"NSMenuItem\"; title = \"Increase Font Size\"; ObjectID = \"525-TU-MBZ\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Increase Font Size" + } + } + } + }, "a4o-M9-LLq.title" : { "comment" : "Class = \"NSMenuItem\"; title = \"Paste Ruler\"; ObjectID = \"a4o-M9-LLq\";", "extractionState" : "extracted_with_value", @@ -958,19 +970,19 @@ } }, "eIi-Yp-9Iw.title" : { - "comment" : "Class = \"NSMenu\"; title = \"Shortcut\"; ObjectID = \"eIi-Yp-9Iw\";", + "comment" : "Class = \"NSMenu\"; title = \"Shortcuts\"; ObjectID = \"eIi-Yp-9Iw\";", "extractionState" : "extracted_with_value", "localizations" : { "en" : { "stringUnit" : { "state" : "new", - "value" : "Shortcut" + "value" : "Shortcuts" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "Shortcut" + "value" : "Shortcuts" } } } @@ -1475,6 +1487,18 @@ } } }, + "K7d-rE-hVh.title" : { + "comment" : "Class = \"NSMenuItem\"; title = \"Decrease Font Size\"; ObjectID = \"K7d-rE-hVh\";", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Decrease Font Size" + } + } + } + }, "KbN-5H-9z5.ibShadowedToolTip" : { "comment" : "Class = \"NSMenuItem\"; ibShadowedToolTip = \"Open in Eudic\"; ObjectID = \"KbN-5H-9z5\";", "extractionState" : "extracted_with_value", @@ -2816,19 +2840,19 @@ } }, "YF0-bI-c58.title" : { - "comment" : "Class = \"NSMenuItem\"; title = \"Shortcut\"; ObjectID = \"YF0-bI-c58\";", + "comment" : "Class = \"NSMenuItem\"; title = \"Shortcuts\"; ObjectID = \"YF0-bI-c58\";", "extractionState" : "extracted_with_value", "localizations" : { "en" : { "stringUnit" : { "state" : "new", - "value" : "Shortcut" + "value" : "Shortcuts" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "Shortcut" + "value" : "Shortcuts" } } } diff --git a/Easydict/Feature/Configuration/EZConfiguration.h b/Easydict/Feature/Configuration/EZConfiguration.h index b2263d479..0c669b702 100644 --- a/Easydict/Feature/Configuration/EZConfiguration.h +++ b/Easydict/Feature/Configuration/EZConfiguration.h @@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN static NSString *const EZQuickLinkButtonUpdateNotification = @"EZQuickLinkButtonUpdateNotification"; +static NSString *const EZFontSizeUpdateNotification = @"EZFontSizeUpdateNotification"; + static NSString *const EZIntelligentQueryModeKey = @"IntelligentQueryMode"; typedef NS_ENUM(NSUInteger, EZLanguageDetectOptimize) { @@ -63,6 +65,9 @@ typedef NS_ENUM(NSUInteger, EZLanguageDetectOptimize) { @property (nonatomic, assign) BOOL disabledAutoSelect; @property (nonatomic, assign) BOOL isRecordingSelectTextShortcutKey; +@property (nonatomic, copy) NSArray *fontSizes; +@property (nonatomic, assign, readonly) CGFloat fontSizeRatio; +@property (nonatomic, assign) NSInteger fontSizeIndex; + (instancetype)shared; + (void)destroySharedInstance; diff --git a/Easydict/Feature/Configuration/EZConfiguration.m b/Easydict/Feature/Configuration/EZConfiguration.m index 49e38ac7b..6ed611589 100644 --- a/Easydict/Feature/Configuration/EZConfiguration.m +++ b/Easydict/Feature/Configuration/EZConfiguration.m @@ -16,6 +16,7 @@ #import "EZLog.h" #import "EZLanguageManager.h" #import "AppDelegate.h" +#import "Easydict-Swift.h" static NSString *const kEasydictHelperBundleId = @"com.izual.EasydictHelper"; @@ -53,6 +54,7 @@ static NSString *const kAllowCrashLogKey = @"EZConfiguration_kAllowCrashLogKey"; static NSString *const kAllowAnalyticsKey = @"EZConfiguration_kAllowAnalyticsKey"; static NSString *const kClearInputKey = @"EZConfiguration_kClearInputKey"; +static NSString *const kTranslationControllerFontKey = @"EZConfiguration_kTranslationControllerFontKey"; @interface EZConfiguration () @@ -121,6 +123,12 @@ - (void)setup { self.allowCrashLog = [NSUserDefaults mm_readBool:kAllowCrashLogKey defaultValue:YES]; self.allowAnalytics = [NSUserDefaults mm_readBool:kAllowAnalyticsKey defaultValue:YES]; self.clearInput = [NSUserDefaults mm_readBool:kClearInputKey defaultValue:NO]; + + self.fontSizes = @[@(1), @(1.1), @(1.2), @(1.3), @(1.4)]; + [[NSUserDefaults standardUserDefaults]registerDefaults:@{kTranslationControllerFontKey: @(0)}]; + + _fontSizeIndex = [[NSUserDefaults standardUserDefaults]integerForKey:kTranslationControllerFontKey]; + } #pragma mark - getter @@ -412,6 +420,23 @@ - (void)setClearInput:(BOOL)clearInput { [self logSettings:@{@"clear_input" : @(clearInput)}]; } +- (void)setFontSizeIndex:(NSInteger)fontSizeIndex { + NSInteger targetIndex = MIN(_fontSizes.count-1, MAX(fontSizeIndex, 0)); + + if (_fontSizeIndex == targetIndex) { + return; + } + + _fontSizeIndex = targetIndex; + + [NSUserDefaults mm_write:@(targetIndex) forKey:kTranslationControllerFontKey]; + + [[NSNotificationCenter defaultCenter]postNotificationName:ChangeFontSizeView.changeFontSizeNotificationName object:@(targetIndex)]; +} + +- (CGFloat)fontSizeRatio { + return _fontSizes[_fontSizeIndex].floatValue; +} #pragma mark - Window Frame diff --git a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m index 87c499b5c..2f19f8bb0 100644 --- a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m @@ -13,6 +13,7 @@ #import "EZMenuItemManager.h" #import "EZEnumTypes.h" #import +#import "Easydict-Swift.h" @interface EZSettingViewController () @@ -99,6 +100,10 @@ @interface EZSettingViewController () @property (nonatomic, strong) NSTextField *menuBarIconLabel; @property (nonatomic, strong) NSButton *hideMenuBarIconButton; +@property (nonatomic, strong) NSTextField *fontSizeLabel; +@property (nonatomic, strong) ChangeFontSizeView *changeFontSizeView; +@property (nonatomic, strong) FontSizeHintView *fontSizeHintView; + @property (nonatomic, strong) NSArray *enabledTTSServiceTypes; @end @@ -473,6 +478,24 @@ - (void)setupUI { self.hideMenuBarIconButton = [NSButton checkboxWithTitle:hideMenuBarIcon target:self action:@selector(hideMenuBarIconButtonClicked:)]; [self.contentView addSubview:self.hideMenuBarIconButton]; + NSTextField *fontSizeLabel = [NSTextField labelWithString:NSLocalizedString(@"font_size", nil)]; + fontSizeLabel.font = font; + [self.contentView addSubview:fontSizeLabel]; + self.fontSizeLabel = fontSizeLabel; + + ChangeFontSizeView *changeFontSizeView = [[ChangeFontSizeView alloc]initWithFontSizes:self.config.fontSizes initialIndex:self.config.fontSizeIndex]; + + mm_weakify(self); + changeFontSizeView.didSelectIndex = ^(NSInteger index) { + mm_strongify(self); + self.config.fontSizeIndex = index; + }; + + [self.contentView addSubview:changeFontSizeView]; + self.changeFontSizeView = changeFontSizeView; + + self.fontSizeHintView = [FontSizeHintView new]; + [self.contentView addSubview:self.fontSizeHintView]; [self updatePreferredLanguagesPopUpButton]; @@ -747,9 +770,27 @@ - (void)updateViewConstraints { make.top.equalTo(self.showEudicQuickLinkButton.mas_bottom).offset(self.verticalPadding); }]; + [self.fontSizeLabel mas_remakeConstraints:^(MASConstraintMaker *make) { + make.right.equalTo(self.autoGetSelectedTextLabel); + make.top.equalTo(self.showAppleDictionaryQuickLinkButton.mas_bottom).offset(self.verticalPadding); + }]; + + [self.changeFontSizeView mas_remakeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.fontSizeLabel.mas_right).offset(self.horizontalPadding + 2); + make.centerY.equalTo(self.fontSizeLabel); + make.width.mas_equalTo(200); + make.height.mas_equalTo(30); + }]; + + [self.fontSizeHintView mas_remakeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.fontSizeLabel.mas_right).offset(self.horizontalPadding); + make.top.equalTo(self.changeFontSizeView.mas_bottom).mas_offset(5); + make.width.mas_equalTo(300); + }]; + [self.separatorView2 mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.separatorView); - make.top.equalTo(self.showAppleDictionaryQuickLinkButton.mas_bottom).offset(1.5 * self.verticalPadding); + make.top.equalTo(self.fontSizeHintView.mas_bottom).offset(1.5 * self.verticalPadding); make.height.equalTo(self.separatorView); }]; diff --git a/Easydict/Feature/Service/Apple/AppleDictionary/apple-dictionary.html b/Easydict/Feature/Service/Apple/AppleDictionary/apple-dictionary.html index 11a7ccbf7..e0672d72b 100644 --- a/Easydict/Feature/Service/Apple/AppleDictionary/apple-dictionary.html +++ b/Easydict/Feature/Service/Apple/AppleDictionary/apple-dictionary.html @@ -21,6 +21,9 @@ --iframe-right-margin: 6px; --iframe-bottom-margin: 12px; --iframe-left-margin: 6px; + + --big-word-title-font-size: 24px; + --details-summary-font-size: 18px; } body { @@ -33,7 +36,7 @@ .big-word-title { margin: 8px 0px 0px 8px; font-weight: 550; - font-size: 24px; + font-size: var(--big-word-title-font-size); } .custom-iframe-container { @@ -58,7 +61,7 @@