フォントの設定
Meadow 2 (2.00 / 2.10 ~) のフォント設定
IMEからの入力、ファイルの文字コードの認識のためには初期設定が必要です。
(set-language-environment "Japanese") (mw32-ime-initialize) (setq default-input-method "MW32-IME")
以下では、どの言語版のWindowsでも共通して使えるよう、フォント名を英語で指定しています。
上の初期設定が正しく行われていれば、日本語版Windowsではフォント名を日本語で指定出来ます。
まずは日本語をきちんと表示できるようにします。
(w32-add-font
"MS Gothic 16"
'((spec
((:char-spec ascii :height any)
strict
(w32-logfont "MS Gothic" 0 -16 400 0 nil nil nil 0 1 3 0))
((:char-spec ascii :height any :weight bold)
strict
(w32-logfont "MS Gothic" 0 -16 700 0 nil nil nil 0 1 3 0)
((spacing . -1)))
((:char-spec ascii :height any :slant italic)
strict
(w32-logfont "MS Gothic" 0 -16 400 0 t nil nil 0 1 3 0))
((:char-spec ascii :height any :weight bold :slant italic)
strict
(w32-logfont "MS Gothic" 0 -16 700 0 t nil nil 0 1 3 0)
((spacing . -1)))
((:char-spec japanese-jisx0208 :height any)
strict
(w32-logfont "MS Gothic" 0 -16 400 0 nil nil nil 128 1 3 0))
((:char-spec japanese-jisx0208 :height any :weight bold)
strict
(w32-logfont "MS Gothic" 0 -16 700 0 nil nil nil 128 1 3 0)
((spacing . -1)))
((:char-spec japanese-jisx0208 :height any :slant italic)
strict
(w32-logfont "MS Gothic" 0 -16 400 0 t nil nil 128 1 3 0))
((:char-spec japanese-jisx0208 :height any :weight bold :slant italic)
strict
(w32-logfont "MS Gothic" 0 -16 700 0 t nil nil 128 1 3 0)
((spacing . -1))))))
; 起動時およびnew-frame時のフレーム(ウィンドウ)の設定。
(add-to-list 'default-frame-alist '(font . "MS Gothic 16"))
; 現在のフレームの設定(.emacs中では省略可)
(set-frame-font "MS Gothic 16")
; IMEのフォントを設定。こういう書式でないとだめらしい。
(let ((logfont '(w32-logfont "MS Gothic" 0 0 400 0 nil nil nil 128 1 3 0)))
(modify-frame-parameters (selected-frame) (list (cons 'ime-font logfont)))
(add-to-list 'default-frame-alist (cons 'ime-font logfont))
)
この設定では、行間が空かず罫線の縦線が隙間なく繋がります。
また、半角と全角 , ボールドと非ボールドが混ざってもずれが生じません。
ascii のバックスラッシュは、¥ で表示されます。
多言語フォント(BDFフォント)
setup.exe で intlfonts パッケージをインストールしてあれば、
- M-x set-frame-font
または、
- S-down-mouse-1 (Shiftキー + マウスの左ボタン)
で intlfonts16 を選択出来ます。
- M-x view-hello-file
として正しく表示される事を確認しましょう。
MS ゴシック と BDFフォントの混用
asciiと日本語には"MS ゴシック"を、それ以外の文字セットにはBDFフォントを使用する方法を示します。
http://applause.elfmimi.jp/meadow/add-intlfonts.el をダウンロードして、
適切な場所に保存します。(C:/Program Files/Meadow/site-lisp 等)
- ファイルの添付 をしてありますが文字化けが見苦しいので外部のファイルをリンクしています。
.emacs に、以下の2行を足します。"MS Gothic 16" の部分は上で設定したものです。
(load "add-intlfonts") (add-intlfonts "MS Gothic 16")
TrueType?フォントを CJK に適用
Windows XP が標準で備えているフォントを使ってみます。
TrueType ならサイズも自由に選べます。
※1 Windows XP 英語版では、"Control Panel" → "Regional and Language Options" → "Languages" から、
"Install files for East Asian languages" をするとフォントも追加されます。(約230MB使用、要再起動)
※2 Windows 2000 (日本語版)では、コントロールパネル → 地域のオプション → システムの言語設定 から、
韓国語, 簡体字中国語, 繁体字中国語をインストールするとフォントも追加されます。(要再起動)
(let ((make-spec
(function
(lambda (size charset fontname &optional windows-charset)
(setq size (- size))
(if (not windows-charset)
(setq windows-charset
(cadr (assq charset mw32-charset-windows-font-info-alist))))
`(((:char-spec ,charset :height any)
strict
(w32-logfont ,fontname 0 ,size 400 0 nil nil nil ,windows-charset 1 3 0))
((:char-spec ,charset :height any :weight bold)
strict
(w32-logfont ,fontname 0 ,size 700 0 nil nil nil ,windows-charset 1 3 0)
((spacing . -1)))
((:char-spec ,charset :height any :slant italic)
strict
(w32-logfont ,fontname 0 ,size 400 0 t nil nil ,windows-charset 1 3 0))
((:char-spec ,charset :height any :weight bold :slant italic)
strict
(w32-logfont ,fontname 0 ,size 700 0 t nil nil ,windows-charset 1 3 0)
((spacing . -1)))))))
(make-spec-list
(function
(lambda (size params-list)
(list (cons 'spec
(apply 'append
(mapcar (lambda (params)
(apply make-spec (cons size params)))
params-list))))
)))
(define-fontset
(function
(lambda (fontname size fontset-list)
(let ((spec (funcall make-spec-list size fontset-list)))
(if (w32-list-fonts fontname)
(w32-change-font fontname spec)
(w32-add-font fontname spec)
)))))
(serif-fontset-list
'(
(ascii "MS Mincho")
(katakana-jisx0201 "MS Mincho")
(japanese-jisx0208 "MS Mincho")
(korean-ksc5601 "Batang")
(chinese-gb2312 "SimSun")
(chinese-big5-1 "MingLiU")
(chinese-big5-2 "MingLiU")
))
(sans-serif-fontset-list
'(
(ascii "MS Gothic")
(katakana-jisx0201 "MS Gothic")
(japanese-jisx0208 "MS Gothic")
(korean-ksc5601 "Dotum")
(chinese-gb2312 "SimHei")
(chinese-big5-1 "MingLiU")
(chinese-big5-2 "MingLiU")
))
)
(funcall define-fontset "Serif 10" 10 serif-fontset-list)
(funcall define-fontset "Serif 12" 12 serif-fontset-list)
(funcall define-fontset "Serif 14" 14 serif-fontset-list)
(funcall define-fontset "Serif 16" 16 serif-fontset-list)
(funcall define-fontset "Serif 18" 18 serif-fontset-list)
(funcall define-fontset "Serif 20" 20 serif-fontset-list)
(funcall define-fontset "Serif 22" 22 serif-fontset-list)
(funcall define-fontset "Serif 24" 24 serif-fontset-list)
(funcall define-fontset "Serif 36" 36 serif-fontset-list)
(funcall define-fontset "Serif 48" 48 serif-fontset-list)
(funcall define-fontset "Sans Serif 10" 10 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 12" 12 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 14" 14 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 16" 16 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 18" 18 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 20" 20 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 22" 22 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 24" 24 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 36" 36 sans-serif-fontset-list)
(funcall define-fontset "Sans Serif 48" 48 sans-serif-fontset-list)
)
フォントの切り替えは、Shift + マウス左ボタン で出来ます。
- M-x list-charset-chars [RET] korean-ksc5601 [RET]
等として日本語以外もうまく表示出来る事を確認しましょう。
- OpenType なら全言語に対応できそうに思いますが、まだそこまでは出来ない様です。
function を用いたフォント設定の例
以下に列挙する様な多数の要件を同時に満たす事を考えた場合、 strict による設定では、困難になってきます。
- face による文字サイズの変更
- 等幅とプロポーショナル
- bold, 非bold でのフォントを選択
- 言語毎のフォントの対応
- intlfonts の使用、不使用
そこで function の登場となります。
;; ffunc が mw32-load-font() から呼ばれる場合、
;; char に -1 が、:height を含む全ての属性に unspecified が与えられる。
;; この場合にここで決定した値が実際のフォントを介して間接的に
;; default face の height を指定する事になる。
;; default face の height の元の値を尊重するには
;; ややこしい計算が必要になる。
(let ((fname "function")
(ffunc
(function
(lambda (char attr frame)
(let (size charset w32-charset fixed-pitch fontname italic weight
logfont option)
(setq size (plist-get attr :height))
(if (eq size 'unspecified)
(setq size (face-attribute 'default :height)))
(setq size (floor (+ (/ (* size 96) 72.27 10) 0.5)))
;(setq size (- size))
(setq charset (char-charset char))
(setq w32-charset
(cadr (assq charset mw32-charset-windows-font-info-alist)))
(unless w32-charset
(setq w32-charset 0))
(setq fixed-pitch
(member (plist-get attr :family)
'("courier" "fixed" "fixed-pitch")))
(setq fontname "MS Gothic")
;; 非ボールドには、"ヒラギノ角ゴ Pro W3" を
;; ボールドには、 "ヒラギノ角ゴ Pro W6" を
;; 等幅のファミリーには、"MS Gothic" を使う例。
; (setq fontname
; (cond
; (fixed-pitch "MS Gothic")
; ((eq 'bold (plist-get attr :weight)) "HiraKakuPro-W6")
; (t "HiraKakuPro-W3")))
(setq weight (if (eq 'bold (plist-get attr :weight)) 700 400))
(if (and (member fontname '("MS Gothic")) (>= weight 700))
(add-to-list 'option '(spacing . -1)))
(setq italic (eq 'italic (plist-get attr :slant)))
(setq logfont
(list 'w32-logfont fontname
0 size weight 0 italic nil nil w32-charset 1 3 0))
;; IMEのフォント設定も変更する。
(if (and (< char 0) (eq 'unspecified (plist-get attr :height)))
(modify-frame-parameters frame (list (cons 'ime-font logfont))))
(list logfont option)
)
)
)
)
)
(funcall
(if (w32-list-fonts fname) 'w32-change-font 'w32-add-font)
fname
`((spec
((:char-spec any :width any :height any :family any :weight any :slant any)
function
,ffunc
)
))
)
)
;; 既知の問題は、default face の文字の大きさが変わってもタブ幅に反映されないこと。
- customize-face で default face の Height を設定する。
- (set-face-attribute 'default nil :height 120) 等として設定する。
事ができます。
以下のようなキーバインドを用意してもおもしろいでしょう。
(define-key global-map [?\C-\M-\;]
(lambda ()(interactive)
(set-face-attribute 'default nil :height
(floor (+ (* (face-attribute 'default :height) 1.1) 0.5)))))
(define-key global-map [?\C-\M--]
(lambda ()(interactive)
(set-face-attribute 'default nil :height
(floor (+ (/ (face-attribute 'default :height) 1.1) 0.5)))))
- Ctrl + Alt + ; ……… 文字を大きく
- Ctrl + Alt + - ……… 文字を小さく
Attachments
- add-intlfonts.el (3.5 kB) -
フォント(セット)にBDFフォントを加えるelisp
, added by applause@elfmimi.jp on 2005年09月26日 11時57分36秒.



