forked from mapnik/mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
UsingCustomFonts
ThomasG77 edited this page Jan 21, 2012
·
4 revisions
Doing this requires three steps:
Find the location of Mapnik's special font folder and place new fonts in it:
$ python -c "import mapnik;print mapnik.fontscollectionpath"
Or register a custom location:
import mapnik
custom_fonts_dir = '/Library/Fonts/'
mapnik.register_fonts(custom_fonts_dir)
We are planning to add registration support within XML in #168
- Also, the Nik2Img allows you to pass the
--fonts
argument to register custom fonts when reading and XML
mapnik::freetype_engine::register_font(std::string const& file_name)
...where file_name is the full path to the directory where the font is located (e.g., "/home/user/mapnik/fonts/unifont-Medium.ttf"). The c++ demo (source:trunk/demo/c++/rundemo) also provides an good example of how to add additional fonts.
- Ask Mapnik to print all registered face names (note: this only will show fonts already auto-registered in the
fontscollectionpath
):
python -c "from mapnik import FontEngine as e;print '\n'.join(e.instance().face_names())"
DejaVu Sans Bold
DejaVu Sans Bold Oblique
DejaVu Sans Book
DejaVu Sans Condensed
DejaVu Sans Condensed Bold
[..snip..]
- Or, register custom fonts and then show their face names:
from mapnik import register_fonts, FontEngine
custom_fonts_dir = '/Library/Fonts/'
register_fonts(custom_fonts_dir)
for face in FontEngine.face_names(): print face
...
Al Bayan Bold
Al Bayan Plain
Andale Mono Regular
Arial Black Regular
[...snip...]
<TextSymbolizer name="FIELD_NAME" face_name="DejaVu Sans Condensed Bold" size="10" fill="black" />
- Nice Summary at: http://weait.com/content/add-fonts-your-openstreetmap-server
-
load_fonts()
recursive C++ function in http://trac.openstreetmap.org/browser/applications/utils/mod_tile/gen_tile.cpp#L111