LoginSignup
14

More than 5 years have passed since last update.

Mapnik styleのフォント変更

Last updated at Posted at 2013-05-31

Mapnikの設定は、XML形式の設定ファイルを中心に行われます。

設定ファイルのパス

前回紹介した、パッケージでの導入の場合、以下のディレクトリに存在します。

/etc/mapnik-osm-data

このディレクトリ内には、以下のファイルとディレクトリが存在します。

  • osm.xml
  • inc
  • symbols

osm.xmlが設定ファイルです。
incと symbolsはディレクトリになっており、以下の内容が格納されています。

  • inc : 設定ファイルのinclude一式
  • symbols : 地図上に配置されるアイコン一式

fontset-settings.xml.inc設定

inc配下のXMLファイルは、osm.xmlからincludeされて読み込まれます。
ここではフォントの設定を行いますので、inc配下にあるfontset-settings.xml.incを変更します。

ファイル内の記述ですが、例えば僕の環境では以下のようになっています。
<!-- -->で囲まれている部分はコメントです。

$ cat ./fontset-settings.xml.inc
<!--Settings for Mapnik Fonts
Uncomment the unifont entries if you have that font installed
in your mapnik fonts dir, and want to use it as a fallback font.
Mapnik includes this font by default since r1328.
To see the fonts you have installed with Mapnik do:
ls `python -c "import mapnik;print mapnik.fontscollectionpath"`-->

<FontSet name="book-fonts">
  <Font face-name="DejaVu Sans Book" />
  <Font face-name="mikachan Regular" />
  <!--Font face-name="VL Gothic regular" /-->
</FontSet>
<FontSet name="bold-fonts">
  <Font face-name="DejaVu Sans Bold" />
  <Font face-name="VL Gothic regular" />
  <!--Font face-name="unifont Medium" /-->
</FontSet>
<FontSet name="oblique-fonts">
  <Font face-name="DejaVu Sans Oblique" />
  <Font face-name="VL Gothic regular" />
  <!--Font face-name="unifont Medium" /-->
</FontSet>

大きく、3つの分類になっていることがわかります。

book-fonts
bold-fonts
oblique-fonts

それぞれに対して、使用するフォントの名称を割り振ります。
Mapnikから利用可能なフォントへのパスは、/etc/renderd.confで指定されています。

$ cat /etc/renderd.conf 
<snip>
[mapnik]
plugins_dir=/usr/lib/mapnik/2.0/input
font_dir=/usr/share/fonts/truetype
font_dir_recurse=1

参考までに、僕の/usr/share/fonts/truetypeは以下のようになっています。

$ ls -la /usr/share/fonts/truetype/
total 20
drwxr-xr-x 5 root root 4096 May 27 20:11 .
drwxr-xr-x 3 root root 4096 May 27 13:05 ..
lrwxrwxrwx 1 root root   43 May 27 18:30 fonts-japanese-gothic.ttf -> /etc/alternatives/fonts-japanese-gothic.ttf
drwxr-xr-x 2 root root 4096 May 27 20:11 mikachan
drwxr-xr-x 2 root root 4096 May 27 13:05 ttf-dejavu
drwxr-xr-x 2 root root 4096 May 27 18:30 vlgothic

font face-nameで指定する値

ここで悩ましいのが、fontの face-nameで設定するべき値です。
本来は、python でmapnikをimportして調べることができます。

Github: Mapnik Wiki

python -c "from mapnik import FontEngine as e;print '\n'.join(e.instance().face_names())"

しかし、パッケージ版ではPythonにmapnikモジュールをインポートすることができないようです。(現在調査中)
しょうがないので、別の環境で調べた、日本語としてよく使いそうなフォントの face-nameを置いておきます。
どのフォントがどのface-nameなのかは、察してください。

Sawarabi Gothic Medium
Sazanami Gothic Gothic-Regular
TakaoExGothic Regular
TakaoExMincho Regular
TakaoGothic Regular
TakaoMincho Regular
TakaoPGothic Regular
TakaoPMincho Regular
VL Gothic regular
VL PGothic regular
mikachan Regular
mikachan-P Regular
mikachan-PB Regular
mikachan-PS Regular
mikachan-puchi Regular

Ubuntuであれば、aptでインストールされるフォントのインストール先は、mapnikから参照される/usr/share/fonts/truetypeです。
インストールに際して、特段気にすることは無いかと思います。

sudo apt-cache search font | grep [Jj]apanese

とかで好きなフォントを探してインストールしてください。

renderd再起動

設定が終わったら、renderdを再起動します。

sudo /etc/init.d/renderd restart

キャッシュのファイルを削除するか、まだレンダリングされていない地域を表示するなどしてテストしてください。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14