2 ;; http://coldnew.github.io/blog/2013/11/16_d2f3a.html
3 (defvar emacs-english-font "Source Code Pro for Powerline:weigth:light"
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 ;(if (display-graphic-p)
42 ; (set-font emacs-english-font emacs-cjk-font emacs-font-size-pair))
45 (defun emacs-step-font-size (step)
46 "Increase/Decrease emacs's font size."
47 (let ((scale-steps emacs-font-size-pair-list))
48 (if (< step 0) (setq scale-steps (reverse scale-steps)))
49 (setq emacs-font-size-pair
50 (or (cadr (member emacs-font-size-pair scale-steps))
51 emacs-font-size-pair))
52 (when emacs-font-size-pair
53 (message "emacs font size set to %.1f" (car emacs-font-size-pair))
54 (set-font emacs-english-font emacs-cjk-font emacs-font-size-pair))))
57 (defun increase-emacs-font-size ()
58 "Decrease emacs's font-size acording emacs-font-size-pair-list."
59 (interactive) (emacs-step-font-size 1))
61 (defun decrease-emacs-font-size ()
62 "Increase emacs's font-size acording emacs-font-size-pair-list."
63 (interactive) (emacs-step-font-size -1))
66 ;(global-set-key (kbd "C-=") 'increase-emacs-font-size)
67 ;(global-set-key (kbd "C--") 'decrease-emacs-font-size)
69 (global-set-key (kbd "C-=") 'text-scale-increase)
70 (global-set-key (kbd "C--") 'text-scale-decrease)