DesireHDで標準のフォントを差し替える

DesireHDの標準のフォントに特に不満を持っていなかったのだけれども、先日試しにNasuフォントを導入してみた。

Nasuフォント : 見た目が似ている文字を判別しやすくするフリーフォント - itouhiroはてなブログ

基本的には、fonts.xmlとfallback_fonts.xmlを書き換えて、フォントをpushする。 このとき、/systemがroなので、rwへremountしておかないといけない。

su
mount -o rw,remount -t ext4 /dev/block/platform/msm_sdcc.2/by-name/system /system 

あとは、adbでpushしてからrebootすれば置き換わる。

adb push update/system/etc/fallback_fonts.xml /system/etc/fallback_fonts.xml
adb push update/system/etc/fonts.xml /system/etc/fonts.xml
adb push update/system/fonts/Nasu-Regular.ttf /system/fonts/

fonts.xmlは該当エントリのフォントを変更するだけ。

% diff -u fonts.xml.orig fonts.xml
--- fonts.xml.orig      2015-09-19 12:51:02.658045246 +0900
+++ fonts.xml   2015-09-19 13:53:37.371494962 +0900
@@ -309,7 +309,7 @@
         <font weight="400" style="normal">NotoSansHant-Regular.otf</font>
     </family>
     <family lang="ja">
-        <font weight="400" style="normal">NotoSansJP-Regular.otf</font>
+        <font weight="400" style="normal">Nasu-Regular.ttf</font>
     </family>
     <family lang="ko">
         <font weight="400" style="normal">NotoSansKR-Regular.otf</font>

fallback_fonts.xmlも同様に変更しておく。

% diff -u fallback_fonts.xml.orig fallback_fonts.xml
--- fallback_fonts.xml.orig     2015-09-19 12:56:50.494825355 +0900
+++ fallback_fonts.xml  2015-09-19 13:54:01.747787026 +0900
@@ -370,7 +370,7 @@
     </family>
     <family>
         <fileset>
-            <file lang="ja">NotoSansJP-Regular.otf</file>
+            <file lang="ja">Nasu-Regular.ttf</file>
         </fileset>
     </family>
     <family>

ROMを焼くたびに再度置き換えるのは面倒なので、その場合にはZIPmeを使う。 ZIPmeでupdate.zipを作成すると、ROMを焼いたあと追加でリカバリから適用するだけでよい。

ZIPme - Google Play の Android アプリ

なろうにMechanizeでログイン

Rubyでログインするサンプルスクリプト

アカウントは別のYAMLに書いてあるとする。

% cat account.yaml
email: hoge@example.com
password: mypassword

実際のスクリプトはこんな感じ。

require 'mechanize'
require 'yaml'

agent = Mechanize.new
agent.user_agent = 'Narou Browser'

params = YAML.load_file('account.yaml')
  
#agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
agent.ca_file = 'ssl.syosetu.com.crt'
page = agent.get('https://ssl.syosetu.com/login/input/')
next_page = page.form_with do |form|
  form.id = params['email']
  form.pass = params['password']
end.submit
p next_page

事前にサイトの証明書をブラウザからエクスポートしておく。agent.ca_fileに指定しているのがそれ。

なろうのブックマークカテゴリ一覧を取得するには

favnovelmain/listに遷移すれば以下のようにして取得できる。

require 'mechanize'
require 'yaml'

agent = Mechanize.new
agent.user_agent = 'Narou Browser'

(ログインはできているものとして省略)

page = agent.get('http://syosetu.com/favnovelmain/list/')
page.search("div[id='sub']/ul[class='category_box']/li").each do |li|
  p li.text
end