From 9860c8eaf0b97a7ea828e965661c00056e571432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kom=D1=8Fpa?= Date: Thu, 17 Mar 2011 02:49:19 +0200 Subject: [PATCH] CJK support --- src/komap.py | 5 +++++ src/libkomapnik.py | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/komap.py b/src/komap.py index 8875fc2..f17224c 100644 --- a/src/komap.py +++ b/src/komap.py @@ -71,6 +71,7 @@ mapniksheet = {} # {zoom: {z-index: [{sql:sql_hint, cond: mapnikfiltercondition, subject: subj, style: {a:b,c:d..}},{r2}...]...}...} coast = {} +fonts = set() for zoom in range (minzoom, maxzoom): mapniksheet[zoom] = {} zsheet = mapniksheet[zoom] @@ -84,6 +85,7 @@ for zoom in range (minzoom, maxzoom): chooser_entry = {} chooser_entry["sql"] = "("+ chooser.get_sql_hints(chooser.ruleChains[0][0].subject,zoom)[1] +")" chooser_entry["style"] = styles + fonts.add(styles.get("font-family","DejaVu Sans Book")) chooser_entry["type"] = chooser.ruleChains[0][0].subject chooser_entry["rule"] = [i.conditions for i in chooser.ruleChains[0] if i.test_zoom(zoom)] numerics.update(chooser.get_numerics()) @@ -119,6 +121,9 @@ def add_numerics_to_itags(itags): mfile.write(xml_start(style.get_style("canvas", {}, maxzoom)[0].get("fill-color", "#000000"))) +for font in fonts: + mfile.write(xml_fontset(font, True)) + for zoom, zsheet in mapniksheet.iteritems(): x_scale = xml_scaledenominator(zoom) ta = zsheet.keys() diff --git a/src/libkomapnik.py b/src/libkomapnik.py index 5dc541a..41a1f13 100644 --- a/src/libkomapnik.py +++ b/src/libkomapnik.py @@ -60,6 +60,16 @@ def pixel_size_at_zoom(z, l): Converts l pixels on tiles into length on zoom z """ return l* 20037508.342789244 / 256 * 2 / (2**z) + + +def xml_fontset(name, unicode=True): + if unicode: + unicode = '' + return """ + + + %s + """%(name, name, unicode) def xml_pointsymbolizer(path="", width="", height="", opacity=1, overlap="false"): @@ -117,7 +127,7 @@ def xml_textsymbolizer(text="name",face="DejaVu Sans Book",size="10",color="#000 align = {"center": "middle"}.get(align.lower(), align) return """ - + """%(text,face,int(float(size)),color,halo_color,halo_radius,placement,offset,overlap,wrap_width,distance,align,opacity) def xml_shieldsymbolizer(path="", width="", height="",text="name",face="DejaVu Sans Book",size="10",color="#000000", halo_color="#ffffff", halo_radius="0", placement="line", offset="0", overlap="false", distance="26", wrap_width=256, align="center", opacity="1"): @@ -130,10 +140,15 @@ def xml_shieldsymbolizer(path="", width="", height="",text="name",face="DejaVu S width =' width="%s" '%width if height: height =' height="%s" '%height + vertical_alignment = "middle" + if float(offset) > 0: + vertical_alignment = "bottom" + if float(offset) < 0: + vertical_alignment = "top" return """ - + """%(icons_path, \ - path, width, height,text,face,int(float(size)),color,halo_color,halo_radius,placement,offset,overlap,wrap_width,distance,align,opacity) + path, width, height,text,face,int(float(size)),color,halo_color,halo_radius,placement,offset,overlap,wrap_width,distance,align,vertical_alignment,opacity) def xml_filter(string): return """