追記2015-12-25
現在使ってゐる新しい手段。
新字を舊字に (ほぼ) 自動で変換する - c4se記:さっちゃんですよ☆
Unicode舊字をAndroidで表示する為に、Notoフォントの部分フォントを作りWebフォントにする - c4se記:さっちゃんですよ☆
はい、convApp自体に変更は一切ありません。convApp.jsの更新です。裏方ですね。
change log
0.4 - 20100413
es5.jsをconvApp.jsから分離
uu.font.js, detectFont.js追加
convApp.jsに、「指定のフォントにグリフが存在しない文字のみ正字→俗字に変換」する関数を追加:convApp.str_ortho2simplByFont(str, font)
detectFont.jsも、convApp.jsの変更も、イリア戰記?での使用の為です。
附属のuu.font.jsは、uupaa.jsの、uu.jsとuu.font.jsをくっつけた丈の物です。
detectFont.js
新顔ですね。
//depend: uu.font.js (function(){ //export: detectFont.detectFontByElement, detectFont.detectCharByFont, detectFont.detectCharByElement var _cashe = {}; /* * @paran char :String * @param font :String * @return :Boolean */ var detectCharByFont = function(char, font){ var cashe_font, zenkaku; if(char.length !== 1){throw Error('detectCharByFont(): <char> must be 1 charactor (not charactors or blank)')}; if(char.charCodeAt(0) < 2000){return true}; if(!_cashe.font){_cashe.font = {infont:[], nofont:[]}}; cashe_font = _cashe.font; if(cashe_font.infont.indexOf(char) !== -1){return true} else if(cashe_font.nofont.indexOf(char) !== -1){return false} else{ zenkaku = uu.font.metric('144pt '+font, 'あ').w; //return window.getComputedStyle(detectElm).width; if(uu.font.metric('144pt '+font, char).w <= zenkaku/2){ cashe_font.nofont.push(char); return false; }else{ cashe_font.infont.push(char); return true; }; }; }; /* * @paran char :String * @param element :Element * @return :Boolean */ var detectCharByElement = function(char, element){ return detectCharCodeByFont(char, uu.font.detect(element)); }; detectFont = { detectFontByElement: uu.font.detect, detectCharByFont: detectCharByFont, detectCharByElement: detectCharByElement }; })();
detectFont.detectCharByFont(文字, フォント名)で、指定のフォントに欲しいグリフが存在しないと見做された場合にfalse、存在するらしい場合はtrueを返します。
飽くまで「漢字」のグリフが存在するかを探る物です。unicodeコードポイント0x2000以下は、英数文字と見做して無理矢理trueを返します。何か勘違いしてるに違いないので、宜しく御願いします。
detectFont.detectFontByElement(ElementNode)はuu.font.detect()のコピーですが、指定の要素ノードで実際描画に使われているフォント名を返します。
前バージョン
convApp 0.3
俗字←→正字、相互変換出来る様にしたよ! #c4se - c4se記 - http://d.hatena.ne.jp/Kureduki_Maari/20100212/1265937568
後書き
- uupaa.js好きですよ
- uu.font.jsの解説は[レンダリングに使われているフォントと、ブラウザで使えるフォントを取得する - latest log - http://d.hatena.ne.jp/uupaa/20100128/1264630442 ]