Geography : bug #06451 : Don't see chinese characters in the geography view.
svn: r21363
This commit is contained in:
parent
5bb9581b15
commit
657d8e233f
@ -47,6 +47,7 @@ _LOG = logging.getLogger("maps.messagelayer")
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
import cairo
|
import cairo
|
||||||
|
from gi.repository import Pango, PangoCairo
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -76,23 +77,22 @@ class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
|
|||||||
GObject.GObject.__init__(self)
|
GObject.GObject.__init__(self)
|
||||||
self.message = []
|
self.message = []
|
||||||
self.color = "black"
|
self.color = "black"
|
||||||
self.font = "Arial"
|
self.font = "Sans"
|
||||||
self.size = 18
|
self.size = 13
|
||||||
#families = font_map.list_families()
|
|
||||||
|
|
||||||
def clear_messages(self):
|
def clear_messages(self):
|
||||||
"""
|
"""
|
||||||
reset the layer attributes.
|
reset the layer attributes.
|
||||||
"""
|
"""
|
||||||
self.message = []
|
self.message = ""
|
||||||
|
|
||||||
def clear_font_attributes(self):
|
def clear_font_attributes(self):
|
||||||
"""
|
"""
|
||||||
reset the font attributes.
|
reset the font attributes.
|
||||||
"""
|
"""
|
||||||
self.color = "black"
|
self.color = "black"
|
||||||
self.font = "Arial"
|
self.font = "Sans"
|
||||||
self.size = 18
|
self.size = 13
|
||||||
|
|
||||||
def set_font_attributes(self, font, size, color):
|
def set_font_attributes(self, font, size, color):
|
||||||
"""
|
"""
|
||||||
@ -109,43 +109,36 @@ class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
|
|||||||
"""
|
"""
|
||||||
Add a message
|
Add a message
|
||||||
"""
|
"""
|
||||||
self.message.append(message)
|
self.message += "\n%s" % message if self.message is not "" else message
|
||||||
|
|
||||||
def do_draw(self, gpsmap, ctx):
|
def do_draw(self, gpsmap, ctx):
|
||||||
"""
|
"""
|
||||||
Draw the two extreme dates
|
Draw all the messages
|
||||||
"""
|
"""
|
||||||
ctx.select_font_face(self.font,
|
ctx.save()
|
||||||
cairo.FONT_SLANT_NORMAL,
|
font_size = "%s %d" % (self.font, self.size)
|
||||||
cairo.FONT_WEIGHT_NORMAL)
|
font = Pango.FontDescription(font_size)
|
||||||
ctx.set_font_size(int(self.size))
|
descr = Pango.font_description_from_string(self.font)
|
||||||
|
descr.set_size(self.size * Pango.SCALE)
|
||||||
color = Gdk.color_parse(self.color)
|
color = Gdk.color_parse(self.color)
|
||||||
ctx.set_source_rgba(float(color.red / 65535.0),
|
ctx.set_source_rgba(float(color.red / 65535.0),
|
||||||
float(color.green / 65535.0),
|
float(color.green / 65535.0),
|
||||||
float(color.blue / 65535.0),
|
float(color.blue / 65535.0),
|
||||||
0.9) # transparency
|
0.9) # transparency
|
||||||
coord_x = 100
|
|
||||||
coord_y = int(self.size) # Show the first line under the zoom button
|
|
||||||
d_width = gpsmap.get_allocation().width
|
d_width = gpsmap.get_allocation().width
|
||||||
gpsmap.set_size_request(300,400)
|
|
||||||
d_width -= 100
|
d_width -= 100
|
||||||
for line in self.message:
|
ctx.save()
|
||||||
line_to_print = line
|
ctx.move_to(100, 5)
|
||||||
(x_bearing, y_bearing, width, height, x_advance, y_advance) = ctx.text_extents(line_to_print)
|
layout = PangoCairo.create_layout(ctx)
|
||||||
while ( width > d_width ):
|
layout.set_font_description(descr)
|
||||||
line_length = len(line_to_print)
|
layout.set_indent(Pango.SCALE * 0)
|
||||||
character_length = int(width/line_length) + 1
|
layout.set_alignment(Pango.Alignment.LEFT)
|
||||||
max_length = int(d_width / character_length) - 1
|
layout.set_wrap(Pango.WrapMode.WORD_CHAR)
|
||||||
while line_to_print[max_length] != ' ':
|
layout.set_spacing(Pango.SCALE * 3)
|
||||||
max_length -= 1 # cut the line at a new word
|
layout.set_width(d_width * Pango.SCALE)
|
||||||
ctx.move_to(coord_x, coord_y)
|
layout.set_text(self.message, -1)
|
||||||
ctx.show_text(line_to_print[:max_length])
|
PangoCairo.show_layout(ctx, layout)
|
||||||
line_to_print = line_to_print[max_length:]
|
ctx.restore()
|
||||||
(x_bearing, y_bearing, width, height, x_advance, y_advance) = ctx.text_extents(line_to_print)
|
|
||||||
coord_y += int(self.size) # calculate the next line position
|
|
||||||
ctx.move_to(coord_x, coord_y)
|
|
||||||
ctx.show_text(line_to_print)
|
|
||||||
coord_y += int(self.size) # calculate the next line position
|
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
|
|
||||||
def do_render(self, gpsmap):
|
def do_render(self, gpsmap):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user