2 ;; http://coldnew.github.io/blog/2013/11/16_d2f3a.html
3 (defvar emacs-english-font "Source Code Pro for Powerline"
4 "The font name of English.")
6 (defvar emacs-cjk-font "Heiti SC"
7 "The font name for CJK.")
10 (defvar emacs-font-size-pair '(12 . 14)
11 "Default font size pair for (english . chinese)")
13 (defvar emacs-font-size-pair-list
14 '(( 5 . 6) (10 . 12) (12 . 14)
15 (13 . 16) (15 . 18) (17 . 20)
16 (19 . 22) (20 . 24) (21 . 26)
17 (24 . 28) (26 . 32) (28 . 34)
18 (30 . 36) (34 . 40) (36 . 44))
19 "This list is used to store matching (englis . chinese) font-size.")
22 (defun font-exist-p (fontname)
23 "Test if this font is exist or not."
24 (if (or (not fontname) (string= fontname ""))
26 (if (not (x-list-fonts fontname)) nil t)))
28 (defun set-font (english chinese size-pair)
29 "Setup emacs English and Chinese font on x window-system."
31 (if (font-exist-p english)
32 (set-frame-font (format "%s:pixelsize=%d" english (car size-pair)) t))
34 (if (font-exist-p chinese)
35 (dolist (charset '(kana han symbol cjk-misc bopomofo))
36 (set-fontset-font (frame-parameter nil 'font) charset
37 (font-spec :family chinese :size (cdr size-pair))))))
40 ;; Setup font size based on emacs-font-size-pair
41 (set-font emacs-english-font emacs-cjk-font emacs-font-size-pair)
44 (defun emacs-step-font-size (step)
45 "Increase/Decrease emacs's font size."
46 (let ((scale-steps emacs-font-size-pair-list))
47 (if (< step 0) (setq scale-steps (reverse scale-steps)))
48 (setq emacs-font-size-pair
49 (or (cadr (member emacs-font-size-pair scale-steps))
50 emacs-font-size-pair))
51 (when emacs-font-size-pair
52 (message "emacs font size set to %.1f" (car emacs-font-size-pair))
53 (set-font emacs-english-font emacs-cjk-font emacs-font-size-pair))))
56 (defun increase-emacs-font-size ()
57 "Decrease emacs's font-size acording emacs-font-size-pair-list."
58 (interactive) (emacs-step-font-size 1))
60 (defun decrease-emacs-font-size ()
61 "Increase emacs's font-size acording emacs-font-size-pair-list."
62 (interactive) (emacs-step-font-size -1))
65 (global-set-key (kbd "C-=") 'increase-emacs-font-size)
66 (global-set-key (kbd "C--") 'decrease-emacs-font-size)