この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
|
android:viewのフォント追加 [2019/11/15 07:46] ips 作成 |
android:viewのフォント追加 [2019/11/16 00:28] (現在) ips [ビルドツールのインストール] |
||
|---|---|---|---|
| ライン 6: | ライン 6: | ||
| {{:android:pasted:20191115-074608.png}} | {{:android:pasted:20191115-074608.png}} | ||
| + | |||
| + | |||
| + | ====== bdfフォントttfに変換してをAndroidに追加する ====== | ||
| + | |||
| + | ===== ビルドツールのインストール ===== | ||
| + | |||
| + | <code cmd> | ||
| + | |||
| + | wslのubuntです | ||
| + | |||
| + | # ビルドツールのインストール | ||
| + | $ sudo apt install build-essential | ||
| + | ... | ||
| + | Do you want to continue? [Y/n] y | ||
| + | Ign:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 binutils-common amd64 2.30-20ubuntu2~18.04 | ||
| + | Err:1 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 binutils-common amd64 2.30-20ubuntu2~18.04 | ||
| + | 404 Not Found [IP: 2001:67c:1560:8001::11 80] | ||
| + | ... | ||
| + | |||
| + | # リポジトリ更新 | ||
| + | $ sudo sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list | ||
| + | |||
| + | # やっぱりエラー | ||
| + | $ sudo apt install build-essential | ||
| + | Reading package lists... Done | ||
| + | Building dependency tree | ||
| + | Reading state information... Done | ||
| + | E: Unable to locate package build-essential | ||
| + | |||
| + | |||
| + | # aptアップデートが必要だった(これをしないとaptできない) | ||
| + | $ sudo apt update | ||
| + | |||
| + | # ビルドツールのインストール | ||
| + | $ sudo apt install build-essential | ||
| + | |||
| + | # 確認 | ||
| + | $ gcc -version | ||
| + | gcc: error: unrecognized command line option ‘-version’ | ||
| + | gcc: fatal error: no input files | ||
| + | compilation terminated. | ||
| + | </code> | ||
| + | |||
| + | <code> | ||
| + | bdf2ttfをcloneしてコンパイルする | ||
| + | $ git clone git@github.com:koron/bdf2ttf.git | ||
| + | $ cd bdf2ttf | ||
| + | $ cp compile/Make_gcc.mak makefile | ||
| + | $ make | ||
| + | |||
| + | // dbf を ttfに変換 | ||
| + | $ ./bdf2ttf ayu20gothic-1.7a.ttf ./sample.ini ./ayu20gothic-1.7a/10x20grkm.bdf | ||
| + | </code> | ||
| + | |||
| + | ↓ttfファイルができあがる | ||
| + | {{:android:pasted:20191115-232102.png}} | ||
| + | |||
| + | ↓appにassetsフォルダを作成する。 | ||
| + | Target Source Set が「main」になっていることを確認して Finish。 | ||
| + | {{:android:pasted:20191115-222111.png}} | ||
| + | |||
| + | ↓assetsの中にfontディレクトリを作成する | ||
| + | {{:android:pasted:20191115-233159.png}} | ||
| + | |||
| + | ↓ttfを貼り付ける。 | ||
| + | {{:android:pasted:20191115-233318.png}} | ||
| + | |||
| + | # app.gradleに追加 | ||
| + | implementation 'uk.co.chrisjenx:calligraphy:2.3.0' | ||
| + | |||
| + | |||
| + | <code> | ||
| + | val am = this.getApplicationContext().getAssets() | ||
| + | val typeface = Typeface.createFromAsset(am,String.format(Locale.US, "font/%s", "shnm6x12a.ttf")) | ||
| + | |||
| + | もしくは | ||
| + | |||
| + | val custom_font = Typeface.createFromAsset(assets, "font/shnm6x12a.ttf") | ||
| + | |||
| + | ↓ | ||
| + | |||
| + | holder.textTitle?.typeface=typeface | ||
| + | holder.textSub?.typeface=typeface | ||
| + | </code> | ||
| + | |||