Skip to content

Commit

Permalink
✨ 演示字体支持自定义
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Jun 17, 2022
1 parent a875a62 commit f42f466
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 deletions.
39 changes: 39 additions & 0 deletions Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,17 @@ CA
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="V00-bE-URD">
<rect key="frame" x="302" y="141" width="141" height="16"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="100" id="sZz-t0-sEw"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="clipping" title="Presentation FontSize:" id="AOs-Fb-J09">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AY8-g1-9tW">
<rect key="frame" x="31" y="103" width="55" height="25"/>
<popUpButtonCell key="cell" type="push" title="12" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="CIa-Sz-unx" id="JPv-4n-4vL">
Expand Down Expand Up @@ -670,10 +681,34 @@ CA
<action selector="previewFontSizeClick:" target="NHv-lG-vxt" id="zi5-DZ-PAI"/>
</connections>
</popUpButton>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2dj-xM-00O">
<rect key="frame" x="301" y="103" width="56" height="25"/>
<popUpButtonCell key="cell" type="push" title="24" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="1bt-aZ-3KY" id="JP4-I0-tZP">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="CDY-TD-T6s">
<items>
<menuItem title="22" id="fjz-Rn-O5O"/>
<menuItem title="23" id="vbn-FE-ciC"/>
<menuItem title="24" state="on" id="1bt-aZ-3KY"/>
<menuItem title="25" id="Id5-oZ-Md0"/>
<menuItem title="26" id="f5H-KF-hxw"/>
<menuItem title="27" id="OgB-0o-dCE"/>
<menuItem title="28" id="fNR-Rx-1mp"/>
<menuItem title="29" id="HMx-8U-9lC"/>
<menuItem title="30" id="mWi-Br-Aor"/>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="presentationFontSizeClick:" target="NHv-lG-vxt" id="siN-zO-TDu"/>
</connections>
</popUpButton>
</subviews>
<constraints>
<constraint firstItem="nLz-A7-TaR" firstAttribute="leading" secondItem="hGy-RZ-sE8" secondAttribute="trailing" constant="20" id="0FN-d9-jY7"/>
<constraint firstItem="hU4-gw-1Hb" firstAttribute="top" secondItem="JmF-Jk-1fQ" secondAttribute="bottom" constant="14" id="1DF-SK-Scj"/>
<constraint firstItem="2dj-xM-00O" firstAttribute="leading" secondItem="V00-bE-URD" secondAttribute="leading" id="449-bR-VBq"/>
<constraint firstItem="quk-zT-1KE" firstAttribute="top" secondItem="sK1-7b-9Ux" secondAttribute="bottom" constant="34" id="675-gw-kpl"/>
<constraint firstItem="hU4-gw-1Hb" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="AY8-g1-9tW" secondAttribute="trailing" constant="8" symbolic="YES" id="6Zr-iN-AtA"/>
<constraint firstItem="6PF-7C-RLR" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="O4C-hp-wJQ" secondAttribute="leading" id="8Ko-bY-tJ0"/>
Expand All @@ -686,8 +721,10 @@ CA
<constraint firstItem="AY8-g1-9tW" firstAttribute="leading" secondItem="TrE-Qn-Cw5" secondAttribute="leading" id="KgP-rr-spn"/>
<constraint firstItem="dkg-Hb-c1w" firstAttribute="top" secondItem="81L-hB-Mc1" secondAttribute="bottom" constant="14" id="Noe-WT-11M"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="31i-Dr-RID" secondAttribute="trailing" constant="20" symbolic="YES" id="Q1W-oQ-9ie"/>
<constraint firstItem="2dj-xM-00O" firstAttribute="centerY" secondItem="hU4-gw-1Hb" secondAttribute="centerY" id="RIX-Ay-tao"/>
<constraint firstItem="dkg-Hb-c1w" firstAttribute="leading" secondItem="81L-hB-Mc1" secondAttribute="leading" id="RlF-el-Kxn"/>
<constraint firstItem="XZf-Ag-G2L" firstAttribute="leading" secondItem="dkg-Hb-c1w" secondAttribute="trailing" constant="8" symbolic="YES" id="S1k-c8-fHN"/>
<constraint firstItem="V00-bE-URD" firstAttribute="centerY" secondItem="JmF-Jk-1fQ" secondAttribute="centerY" id="SZ0-c4-UVr"/>
<constraint firstItem="TrE-Qn-Cw5" firstAttribute="top" secondItem="4Xk-4f-czc" secondAttribute="top" constant="48" id="TLP-yP-rrg"/>
<constraint firstItem="JmF-Jk-1fQ" firstAttribute="leading" secondItem="nLz-A7-TaR" secondAttribute="leading" id="V6c-0f-4yO"/>
<constraint firstItem="sK1-7b-9Ux" firstAttribute="leading" secondItem="hGy-RZ-sE8" secondAttribute="leading" id="VaD-VC-h92"/>
Expand All @@ -713,6 +750,7 @@ CA
<constraint firstItem="I8N-rL-amz" firstAttribute="top" secondItem="31i-Dr-RID" secondAttribute="bottom" constant="14" id="pAF-B2-dJc"/>
<constraint firstItem="EMH-T5-er6" firstAttribute="firstBaseline" secondItem="sK1-7b-9Ux" secondAttribute="firstBaseline" id="rBQ-zG-H5i"/>
<constraint firstItem="hU4-gw-1Hb" firstAttribute="centerY" secondItem="AY8-g1-9tW" secondAttribute="centerY" id="rS5-Xr-HLs"/>
<constraint firstItem="V00-bE-URD" firstAttribute="leading" secondItem="O4C-hp-wJQ" secondAttribute="leading" id="uXk-tR-Ckb"/>
<constraint firstItem="nbv-Zo-swV" firstAttribute="top" secondItem="TrE-Qn-Cw5" secondAttribute="bottom" constant="14" id="vVs-W0-jfN"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="81L-hB-Mc1" secondAttribute="trailing" constant="20" symbolic="YES" id="xeI-6p-Xx2"/>
<constraint firstItem="hGy-RZ-sE8" firstAttribute="top" secondItem="dkg-Hb-c1w" secondAttribute="bottom" constant="34" id="y0J-mO-XOp"/>
Expand All @@ -731,6 +769,7 @@ CA
<outlet property="editorFontName" destination="sK1-7b-9Ux" id="t31-SO-Rp7"/>
<outlet property="editorFontSize" destination="JPv-4n-4vL" id="meJ-LQ-abo"/>
<outlet property="languagePopUp" destination="I8N-rL-amz" id="47F-nH-5hW"/>
<outlet property="presentationFontSize" destination="2dj-xM-00O" id="hWn-td-ZHW"/>
<outlet property="previewFontName" destination="EMH-T5-er6" id="eM2-ad-fay"/>
<outlet property="previewFontSize" destination="hU4-gw-1Hb" id="Awy-QD-lry"/>
<outlet property="windowFontName" destination="6PF-7C-RLR" id="oVB-yw-PFN"/>
Expand Down
13 changes: 13 additions & 0 deletions Mac/Helpers/UserDefaultsManagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class UserDefaultsManagement {
static let Preview = "preview"
static let Presentation = "presentation"
static let PreviewFontSize = "previewFontSize"
static let PresentationFontSize = "presentationFontSize"
static let ProjectsKey = "projects"
static let RestoreCursorPosition = "restoreCursorPosition"
static let SaveInKeychain = "saveInKeychain"
Expand Down Expand Up @@ -148,6 +149,18 @@ public class UserDefaultsManagement {
UserDefaults.standard.set(newValue, forKey: Constants.PreviewFontSize)
}
}

static var presentationFontSize: Int {
get {
if let result = UserDefaults.standard.object(forKey: Constants.PresentationFontSize) as? Int {
return result
}
return 24
}
set {
UserDefaults.standard.set(newValue, forKey: Constants.PresentationFontSize)
}
}

static var fontName: String {
get {
Expand Down
14 changes: 14 additions & 0 deletions Mac/Preferences/PreferencesGeneralViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PreferencesGeneralViewController: NSViewController {
@IBOutlet var appearanceLabel: NSTextField!
@IBOutlet var editorFontSize: NSPopUpButton!
@IBOutlet var previewFontSize: NSPopUpButton!
@IBOutlet var presentationFontSize: NSPopUpButton!

// MARK: global variables

Expand Down Expand Up @@ -94,6 +95,18 @@ class PreferencesGeneralViewController: NSViewController {
vc.enablePreview()
}

@IBAction func presentationFontSizeClick(_ sender: NSPopUpButton) {
guard let vc = ViewController.shared() else { return }
guard let item = sender.selectedItem else {
return
}

UserDefaultsManagement.presentationFontSize = Int(item.title) ?? 24

vc.disablePresentation()
vc.enablePresentation()
}

@IBAction func appearanceClick(_ sender: NSPopUpButton) {
if let type = AppearanceType(rawValue: sender.indexOfSelectedItem) {
if UserDefaultsManagement.appearanceType == type {
Expand Down Expand Up @@ -153,6 +166,7 @@ class PreferencesGeneralViewController: NSViewController {

editorFontSize.selectItem(withTitle: String(UserDefaultsManagement.fontSize))
previewFontSize.selectItem(withTitle: String(UserDefaultsManagement.previewFontSize))
presentationFontSize.selectItem(withTitle: String(UserDefaultsManagement.presentationFontSize))
editorFontName.selectItem(withTitle: String(UserDefaultsManagement.fontName))
windowFontName.selectItem(withTitle: String(UserDefaultsManagement.windowFontName))
previewFontName.selectItem(withTitle: String(UserDefaultsManagement.previewFontName))
Expand Down
2 changes: 1 addition & 1 deletion Mac/View/MarkdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ open class MarkdownView: WKWebView {

public static func getPreviewStyle() -> String {
if UserDefaultsManagement.presentation {
return "html {font-size: 24px} :root { --text-font: \(UserDefaultsManagement.previewFontName), sans-serif;} #write { max-width: 1200px;}"
return "html {font-size: \(UserDefaultsManagement.presentationFontSize)px} :root { --text-font: \(UserDefaultsManagement.previewFontName), sans-serif;} #write { max-width: 1200px;}"
} else {
return "html {font-size: \(UserDefaultsManagement.previewFontSize)px} :root { --text-font: \(UserDefaultsManagement.previewFontName), sans-serif; }"
}
Expand Down
2 changes: 2 additions & 0 deletions Mac/en.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@
/* Class = "NSTextFieldCell"; title = "Preview FontSize:"; ObjectID = "euf-Xu-FDz"; */
"euf-Xu-FDz.title" = "Preview FontSize:";

/* Class = "NSTextField"; title = "Presentation FontSize:"; ObjectID = "AOs-Fb-J09"; */
"AOs-Fb-J09.title" = "演示字号:";

/* Class = "NSButton"; ibShadowedToolTip = "Format"; ObjectID = "Adc-zl-sqX"; */
"Adc-zl-sqX.ibShadowedToolTip" = "Format";
Expand Down
8 changes: 4 additions & 4 deletions MiaoYan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.4.0;
CURRENT_PROJECT_VERSION = 0.5.0;
DEVELOPMENT_TEAM = 5EH69Y5X38;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -1180,7 +1180,7 @@
INFOPLIST_FILE = Mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 0.4.0;
MARKETING_VERSION = 0.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.tw93.MiaoYan;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1201,7 +1201,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.4.0;
CURRENT_PROJECT_VERSION = 0.5.0;
DEPLOYMENT_LOCATION = NO;
DEVELOPMENT_TEAM = 5EH69Y5X38;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
Expand All @@ -1215,7 +1215,7 @@
INFOPLIST_FILE = Mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 0.4.0;
MARKETING_VERSION = 0.5.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tw93.MiaoYan;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
5 changes: 4 additions & 1 deletion zh-Hans.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,12 @@
/* Class = "NSTextField"; title = "Editor FontSize:"; ObjectID = "Mhq-eB-UoB"; */
"Mhq-eB-UoB.title" = "编辑器字号:";

/* Class = "NSTextField"; title = "Preview FontSize:"; ObjectID = "euf-Xu-FDz"; */
/* Class = "NSTextField"; title = "Presentation FontSize:"; ObjectID = "euf-Xu-FDz"; */
"euf-Xu-FDz.title" = "预览字号:";

/* Class = "NSTextField"; title = "Preview FontSize:"; ObjectID = "AOs-Fb-J09"; */
"AOs-Fb-J09.title" = "演示字号:";

/* Class = "NSMenuItem"; title = "System"; ObjectID = "fQA-b2-fKr"; */
"fQA-b2-fKr.title" = "自动";

Expand Down

0 comments on commit f42f466

Please sign in to comment.