Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/squirrel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ style:
#label_font_point: 12
#comment_font_face: 'Avenir'
#comment_font_point: 16
#preedit_font_face: 'Avenir'
#preedit_font_point: 16

preset_color_schemes:
native:
Expand Down
21 changes: 19 additions & 2 deletions sources/SquirrelTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ final class SquirrelTheme {
private var fonts = [NSFont]()
private var labelFonts = [NSFont]()
private var commentFonts = [NSFont]()
private var preeditFonts = [NSFont]()
private var fontSize: CGFloat?
private var labelFontSize: CGFloat?
private var commentFontSize: CGFloat?
private var preeditFontSize: CGFloat?

private var _candidateFormat = "[label]. [candidate] [comment]"
private(set) var statusMessageType: StatusMessageType = .mix
Expand Down Expand Up @@ -107,6 +109,15 @@ final class SquirrelTheme {
return self.font
}
}()
private(set) lazy var preeditFont: NSFont = {
if let font = combineFonts(preeditFonts, size: preeditFontSize ?? fontSize) {
return font
} else if let size = preeditFontSize {
return self.font.withSize(size)
} else {
return self.font
}
}()
private(set) lazy var attrs: [NSAttributedString.Key: Any] = [
.foregroundColor: candidateTextColor,
.font: font,
Expand Down Expand Up @@ -139,12 +150,12 @@ final class SquirrelTheme {
]
private(set) lazy var preeditAttrs: [NSAttributedString.Key: Any] = [
.foregroundColor: textColor,
.font: font,
.font: preeditFont,
.baselineOffset: baseOffset
]
private(set) lazy var preeditHighlightedAttrs: [NSAttributedString.Key: Any] = [
.foregroundColor: highlightedTextColor,
.font: font,
.font: preeditFont,
.baselineOffset: baseOffset
]

Expand Down Expand Up @@ -224,6 +235,8 @@ final class SquirrelTheme {
var labelFontSize = config.getDouble("style/label_font_point")
var commentFontName = config.getString("style/comment_font_face")
var commentFontSize = config.getDouble("style/comment_font_point")
var preeditFontName = config.getString("style/preedit_font_face")
var preeditFontSize = config.getDouble("style/preedit_font_point")

let colorSchemeOption = dark ? "style/color_scheme_dark" : "style/color_scheme"
if let colorScheme = config.getString(colorSchemeOption) {
Expand Down Expand Up @@ -264,6 +277,8 @@ final class SquirrelTheme {
labelFontSize ?= config.getDouble("\(prefix)/label_font_point")
commentFontName ?= config.getString("\(prefix)/comment_font_face")
commentFontSize ?= config.getDouble("\(prefix)/comment_font_point")
preeditFontName ?= config.getString("\(prefix)/preedit_font_face")
preeditFontSize ?= config.getDouble("\(prefix)/preedit_font_point")

alpha ?= config.getDouble("\(prefix)/alpha").map { max(0, min(1, $0)) }
cornerRadius ?= config.getDouble("\(prefix)/corner_radius")
Expand All @@ -286,6 +301,8 @@ final class SquirrelTheme {
self.labelFontSize = labelFontSize
commentFonts = decodeFonts(from: commentFontName ?? fontName)
self.commentFontSize = commentFontSize
preeditFonts = decodeFonts(from: preeditFontName ?? fontName)
self.preeditFontSize = preeditFontSize
}
}

Expand Down
Loading