From: Thomas Petazzoni <[email protected]> We introduce a isrtl() method in the i18n classes. By default, this method returns False (for non-RTL languages), but RTL languages can return True to enable the RTL rendering mode for the map and the index.
For now, the RTL mode : * Changes the rendering of the index columns: the first column is on the right. * Changes on index entries are rendered: the street name is on the right while the location on the map squares is on the left. We must ask Arabic person to know whether the square on the map should also be rendered from right to left (i.e column A on the right). Signed-off-by: Thomas Petazzoni <[email protected]> --- ocitysmap/i18n.py | 9 ++++++ ocitysmap/street_index.py | 66 ++++++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/ocitysmap/i18n.py b/ocitysmap/i18n.py index 23e85e8..18e54fa 100644 --- a/ocitysmap/i18n.py +++ b/ocitysmap/i18n.py @@ -43,6 +43,9 @@ class i18n: def first_letter_equal(self, a, b): pass + def isrtl(self): + return False + class i18n_template_code_CODE(i18n): def __init__(self, language, locale_path): """Install the _() function for the chosen locale other @@ -65,6 +68,9 @@ class i18n_template_code_CODE(i18n): e.g. à and E are equals in French map index""" return a == b + def isrtl(self): + return False + class i18n_fr_generic(i18n): APPELLATIONS = [ u"Allée", u"Allées", u"Avenue", u"Boulevard", u"Carrefour", @@ -422,6 +428,9 @@ class i18n_ar_generic(i18n): def first_letter_equal(self, a, b): return self._upper_unaccent_string(a) == self._upper_unaccent_string(b) + def isrtl(self): + return True + class i18n_ru_generic(i18n): APPELLATIONS = [ u"Ñл", u"бÑл", u"пеÑ", u"пÑ", u"ÑлиÑа", u"бÑлÑваÑ", u"пÑоезд", u"пÑоÑпекÑ", u"плоÑадÑ", u"ÑквеÑ", u"паÑк" ] diff --git a/ocitysmap/street_index.py b/ocitysmap/street_index.py index 9978296..ea65a76 100644 --- a/ocitysmap/street_index.py +++ b/ocitysmap/street_index.py @@ -193,7 +193,12 @@ class IndexPageGenerator: colwidth += (remaining / int(paperwidth / colwidth)) y = 0 - x = em + + if self.i18n.isrtl(): + x = paperwidth - colwidth + em + else: + x = em + prevletter = u'' for street in self.streets: # Letter label @@ -203,7 +208,11 @@ class IndexPageGenerator: # end of a column if y + heading_fheight + fheight > paperheight: y = 0 - x += colwidth + + if self.i18n.isrtl(): + x -= colwidth + else: + x += colwidth # Reserve height for the heading letter label y += heading_fheight @@ -241,25 +250,46 @@ class IndexPageGenerator: squares_label_width = layout.get_size()[0] / pango.SCALE line_width = colwidth - street_name_width - squares_label_width - 2 * em - # Draw street name - cr.move_to(x, y - fascent) - layout.set_text(street[1]) - pc.show_layout(layout) - # Draw dashed line - strokewidth = max(fontsize / 12, 1) - cr.set_line_width(strokewidth) - cr.set_dash([ strokewidth, strokewidth * 2 ]) - cr.move_to(x + street_name_width + em / 2, y - 0.1 * em) - cr.rel_line_to(line_width, 0) - cr.stroke() - # Draw squares label - cr.move_to(x + colwidth - em - squares_label_width, y - fascent) - layout.set_text(street[2]) - pc.show_layout(layout) + if self.i18n.isrtl(): + # Draw squares label + cr.move_to(x, y - fascent) + layout.set_text(street[2]) + pc.show_layout(layout) + # Draw dashed line + strokewidth = max(fontsize / 12, 1) + cr.set_line_width(strokewidth) + cr.set_dash([ strokewidth, strokewidth * 2 ]) + cr.move_to(x + squares_label_width + em / 2, y - 0.1 * em) + cr.rel_line_to(line_width, 0) + cr.stroke() + # Draw street label + cr.move_to(x + colwidth - em - street_name_width, y - fascent) + layout.set_text(street[1]) + pc.show_layout(layout) + else: + # Draw street name + cr.move_to(x, y - fascent) + layout.set_text(street[1]) + pc.show_layout(layout) + # Draw dashed line + strokewidth = max(fontsize / 12, 1) + cr.set_line_width(strokewidth) + cr.set_dash([ strokewidth, strokewidth * 2 ]) + cr.move_to(x + street_name_width + em / 2, y - 0.1 * em) + cr.rel_line_to(line_width, 0) + cr.stroke() + # Draw squares label + cr.move_to(x + colwidth - em - squares_label_width, y - fascent) + layout.set_text(street[2]) + pc.show_layout(layout) if y + fheight > paperheight: y = 0 - x += colwidth + + if self.i18n.isrtl(): + x -= colwidth + else: + x += colwidth class OCitySMap: def __init__(self, config_file=None, city_name=None, boundingbox=None, -- 1.6.3.3
