def _draw_arrow(self, ctx, cairo_surface, number, max_digit_number, reverse_text=False): arrow_edge = self.grayed_margin_pt * .6 ctx.save() ctx.set_source_rgb(0, 0, 0) ctx.translate(-arrow_edge / 2, -arrow_edge * 0.45) ctx.line_to(0, 0) ctx.line_to(0, arrow_edge) ctx.line_to(arrow_edge, arrow_edge) ctx.line_to(arrow_edge, 0) ctx.line_to(arrow_edge / 2, -arrow_edge * .25) ctx.close_path() ctx.fill() ctx.restore() ctx.save() if reverse_text: ctx.rotate(math.pi) draw_utils.draw_text_adjusted(ctx, unicode(number), 0, 0, arrow_edge, arrow_edge, max_char_number=max_digit_number, text_color=(1, 1, 1, 1), width_adjust=0.85, height_adjust=0.9) ctx.restore()
def _render_front_page_footer(self, ctx, w, h, osm_date): ctx.save() # Draw the footer ctx.translate(0, 0.8 * h + 2 * Renderer.PRINT_SAFE_MARGIN_PT) # Display a nice grey rectangle as the background of the # footer footer_w = w footer_h = 0.2 * h - 2 * Renderer.PRINT_SAFE_MARGIN_PT ctx.set_source_rgb(.80,.80,.80) ctx.rectangle(0, 0, footer_w, footer_h) ctx.fill() # Draw the OpenStreetMap logo to the right of the footer logo_height = footer_h / 2 grp, logo_width = self._get_osm_logo(ctx, logo_height) if grp: ctx.save() ctx.translate(w - logo_width - Renderer.PRINT_SAFE_MARGIN_PT, logo_height / 2) ctx.set_source(grp) ctx.paint_with_alpha(0.8) ctx.restore() # Prepare the text for the left of the footer today = datetime.date.today() notice = \ _(u'Copyright © %(year)d MapOSMatic/OCitySMap developers.\n' u'http://www.maposmatic.org\n\n' u'Map data © %(year)d OpenStreetMap.org ' u'and contributors (cc-by-sa).\n' u'http://www.openstreetmap.org\n\n' u'Map rendered on: %(date)s. OSM data updated on: %(osmdate)s.\n' u'The map may be incomplete or inaccurate. ' u'You can contribute to improve this map.\n' u'See http://wiki.openstreetmap.org') # We need the correct locale to be set for strftime(). prev_locale = locale.getlocale(locale.LC_TIME) locale.setlocale(locale.LC_TIME, self.rc.i18n.language_code()) try: if osm_date is None: osm_date_str = _(u'unknown') else: osm_date_str = osm_date.strftime("%d %B %Y %H:%M") notice = notice % {'year': today.year, 'date': today.strftime("%d %B %Y"), 'osmdate': osm_date_str} finally: locale.setlocale(locale.LC_TIME, prev_locale) draw_utils.draw_text_adjusted(ctx, notice, Renderer.PRINT_SAFE_MARGIN_PT, footer_h/2, footer_w, footer_h, align=pango.ALIGN_LEFT) ctx.restore()
def _render_front_page_header(self, ctx, w, h): # Draw a light blue block which will contain the name of the # city being rendered. blue_w = w blue_h = 0.3 * h ctx.set_source_rgb(.80, .80, .80) ctx.rectangle(0, 0, blue_w, blue_h) ctx.fill() draw_utils.draw_text_adjusted(ctx, self.rc.title, blue_w / 2, blue_h / 2, blue_w, blue_h)
def _render_front_page_header(self, ctx, w, h): # Draw a light blue block which will contain the name of the # city being rendered. blue_w = w blue_h = 0.3 * h ctx.set_source_rgb(.80,.80,.80) ctx.rectangle(0, 0, blue_w, blue_h) ctx.fill() draw_utils.draw_text_adjusted(ctx, self.rc.title, blue_w/2, blue_h/2, blue_w, blue_h)
def _render_front_page_header(self, ctx, w, h): # Draw a grey block which will contain the map title ctx.save() blue_w = w blue_h = 0.3 * h ctx.set_source_rgb(.80,.80,.80) ctx.rectangle(0, 0, blue_w, blue_h) ctx.fill() draw_utils.draw_text_adjusted(ctx, self.rc.title, blue_w/2, blue_h/2, blue_w, blue_h) ctx.restore()
def _draw_overview_labels(self, ctx, map_canvas, overview_grid, area_width_dots, area_height_dots): """ Draw the page numbers for the overview grid. Args: ctx (cairo.Context): The cairo context to use to draw. overview_grid (OverViewGrid): the overview grid object area_width_dots/area_height_dots (numbers): size of the drawing area (cairo units). """ ctx.save() ctx.set_font_size(14) bbox = map_canvas.get_actual_bounding_box() bottom_right, bottom_left, top_left, top_right = bbox.to_mercator() bottom, left = bottom_right.y, top_left.x coord_delta_y = top_left.y - bottom_right.y coord_delta_x = bottom_right.x - top_left.x w, h = None, None for idx, page_bb in enumerate(overview_grid._pages_bbox): p_bottom_right, p_bottom_left, p_top_left, p_top_right = \ page_bb.to_mercator() center_x = p_top_left.x+(p_top_right.x-p_top_left.x)/2 center_y = p_bottom_left.y+(p_top_right.y-p_bottom_right.y)/2 y_percent = 100 - 100.0*(center_y - bottom)/coord_delta_y y = int(area_height_dots*y_percent/100) x_percent = 100.0*(center_x - left)/coord_delta_x x = int(area_width_dots*x_percent/100) if not w or not h: w = area_width_dots*(p_bottom_right.x - p_bottom_left.x )/coord_delta_x h = area_height_dots*(p_top_right.y - p_bottom_right.y )/coord_delta_y draw_utils.draw_text_adjusted(ctx, str(idx + self._first_map_page_number), x, y, w, h, max_char_number=len(str(len(overview_grid._pages_bbox)+3)), text_color=(0, 0, 0, 0.6)) ctx.save() ctx.translate(x-w/2, y-h/2) ctx.set_source_rgba(0,0,0,0.1) draw_utils.begin_internal_link(ctx, "mypage%d" % (idx + self._first_map_page_number)) ctx.rectangle(0,0,w,h) ctx.stroke() draw_utils.end_link(ctx) ctx.restore() ctx.restore()
def _draw_overview_labels(cls, ctx, map_canvas, overview_grid, area_width_dots, area_height_dots): """ Draw the page numbers for the overview grid. Args: ctx (cairo.Context): The cairo context to use to draw. overview_grid (OverViewGrid): the overview grid object area_width_dots/area_height_dots (numbers): size of the drawing area (cairo units). """ ctx.save() ctx.set_font_size(14) bbox = map_canvas.get_actual_bounding_box() bottom_right, bottom_left, top_left, top_right = bbox.to_mercator() bottom, left = bottom_right.y, top_left.x coord_delta_y = top_left.y - bottom_right.y coord_delta_x = bottom_right.x - top_left.x w, h = None, None for idx, page_bb in enumerate(overview_grid._pages_bbox): p_bottom_right, p_bottom_left, p_top_left, p_top_right = \ page_bb.to_mercator() center_x = p_top_left.x+(p_top_right.x-p_top_left.x)/2 center_y = p_bottom_left.y+(p_top_right.y-p_bottom_right.y)/2 y_percent = 100 - 100.0*(center_y - bottom)/coord_delta_y y = int(area_height_dots*y_percent/100) x_percent = 100.0*(center_x - left)/coord_delta_x x = int(area_width_dots*x_percent/100) if not w or not h: w = area_width_dots*(p_bottom_right.x - p_bottom_left.x )/coord_delta_x h = area_height_dots*(p_top_right.y - p_bottom_right.y )/coord_delta_y draw_utils.draw_text_adjusted(ctx, unicode(idx+4), x, y, w, h, max_char_number=len(unicode(len(overview_grid._pages_bbox)+3)), text_color=(0, 0, 0, 0.6)) ctx.restore()
def _draw_arrow(self, ctx, cairo_surface, number, max_digit_number, reverse_text=False): arrow_edge = self.grayed_margin_pt*.6 ctx.save() ctx.set_source_rgb(0, 0, 0) ctx.translate(-arrow_edge/2, -arrow_edge*0.45) ctx.line_to(0, 0) ctx.line_to(0, arrow_edge) ctx.line_to(arrow_edge, arrow_edge) ctx.line_to(arrow_edge, 0) ctx.line_to(arrow_edge/2, -arrow_edge*.25) ctx.close_path() ctx.fill() ctx.restore() ctx.save() if reverse_text: ctx.rotate(math.pi) draw_utils.draw_text_adjusted(ctx, unicode(number), 0, 0, arrow_edge, arrow_edge, max_char_number=max_digit_number, text_color=(1, 1, 1, 1), width_adjust=0.85, height_adjust=0.9) ctx.restore()
def _render_front_page_footer(self, ctx, w, h, osm_date): ctx.save() # Draw the footer ctx.translate(0, 0.8 * h + 2 * Renderer.PRINT_SAFE_MARGIN_PT) # Display a nice grey rectangle as the background of the # footer footer_w = w footer_h = 0.2 * h - 2 * Renderer.PRINT_SAFE_MARGIN_PT ctx.set_source_rgb(.80, .80, .80) ctx.rectangle(0, 0, footer_w, footer_h) ctx.fill() # Draw the OpenStreetMap logo to the right of the footer logo_height = footer_h / 2 grp, logo_width = self._get_osm_logo(ctx, logo_height) if grp: ctx.save() ctx.translate(w - logo_width - Renderer.PRINT_SAFE_MARGIN_PT, logo_height / 2) ctx.set_source(grp) ctx.paint_with_alpha(0.8) ctx.restore() # Prepare the text for the left of the footer today = datetime.date.today() notice = \ _(u'Copyright © %(year)d MapOSMatic/OCitySMap developers.\n' u'http://www.maposmatic.org\n\n' u'Map data © %(year)d OpenStreetMap.org ' u'and contributors (cc-by-sa).\n' u'http://www.openstreetmap.org\n\n' u'Map rendered on: %(date)s. OSM data updated on: %(osmdate)s.\n' u'The map may be incomplete or inaccurate. ' u'You can contribute to improve this map.\n' u'See http://wiki.openstreetmap.org') # We need the correct locale to be set for strftime(). prev_locale = locale.getlocale(locale.LC_TIME) locale.setlocale(locale.LC_TIME, self.rc.i18n.language_code()) try: if osm_date is None: osm_date_str = _(u'unknown') else: osm_date_str = osm_date.strftime("%d %B %Y %H:%M") notice = notice % { 'year': today.year, 'date': today.strftime("%d %B %Y"), 'osmdate': osm_date_str } finally: locale.setlocale(locale.LC_TIME, prev_locale) draw_utils.draw_text_adjusted(ctx, notice, Renderer.PRINT_SAFE_MARGIN_PT, footer_h / 2, footer_w, footer_h, align=pango.ALIGN_LEFT) ctx.restore()
def _render_front_page_footer(self, ctx, w, h, osm_date): ctx.save() # Draw the footer ctx.translate(0, 0.8 * h + 2 * Renderer.PRINT_SAFE_MARGIN_PT) # Display a nice grey rectangle as the background of the # footer footer_w = w footer_h = 0.2 * h - 2 * Renderer.PRINT_SAFE_MARGIN_PT ctx.set_source_rgb(.80,.80,.80) ctx.rectangle(0, 0, footer_w, footer_h) ctx.fill() # Draw the OpenStreetMap logo to the right of the footer logo_height = footer_h / 2 grp, logo_width = self._get_osm_logo(ctx, logo_height) if grp: ctx.save() ctx.translate(w - logo_width - Renderer.PRINT_SAFE_MARGIN_PT, logo_height / 2) ctx.set_source(grp) ctx.paint_with_alpha(0.8) ctx.restore() # Prepare the text for the left of the footer today = datetime.date.today() notice = _(u'Copyright © %(year)d MapOSMatic/OCitySMap developers.') notice+= '\n\n' notice+= _(u'Map data © %(year)d OpenStreetMap contributors (see http://osm.org/copyright)') notice+= '\n' annotations = [] if self.rc.stylesheet.annotation != '': annotations.append(self.rc.stylesheet.annotation) for overlay in self._overlays: if overlay.annotation != '': annotations.append(overlay.annotation) if len(annotations) > 0: notice+= _(u'Map styles:') notice+= ' ' + '; '.join(annotations) + '\n' notice+= _(u'Map rendered on: %(date)s. OSM data updated on: %(osmdate)s.') notice+= '\n' notice+= _(u'The map may be incomplete or inaccurate.') # We need the correct locale to be set for strftime(). prev_locale = locale.getlocale(locale.LC_TIME) locale.setlocale(locale.LC_TIME, self.rc.i18n.language_code()) try: if osm_date is None: osm_date_str = _(u'unknown') else: osm_date_str = osm_date.strftime("%d %B %Y %H:%M") notice = notice % {'year': today.year, 'date': today.strftime("%d %B %Y"), 'osmdate': osm_date_str} finally: locale.setlocale(locale.LC_TIME, prev_locale) draw_utils.draw_text_adjusted(ctx, notice, Renderer.PRINT_SAFE_MARGIN_PT, footer_h/2, footer_w, footer_h, align=Pango.Alignment.LEFT) ctx.restore()
def _render_front_page_footer(self, ctx, w, h, osm_date): ctx.save() # Draw the footer ctx.translate(0, 0.8 * h + 2 * Renderer.PRINT_SAFE_MARGIN_PT) # Display a nice grey rectangle as the background of the # footer footer_w = w footer_h = 0.2 * h - 2 * Renderer.PRINT_SAFE_MARGIN_PT ctx.set_source_rgb(.80,.80,.80) ctx.rectangle(0, 0, footer_w, footer_h) ctx.fill() # Draw the OpenStreetMap logo to the right of the footer logo_height = footer_h / 2 grp, logo_width = self._get_osm_logo(ctx, logo_height) if grp: ctx.save() ctx.translate(w - logo_width - Renderer.PRINT_SAFE_MARGIN_PT, logo_height / 2) ctx.set_source(grp) ctx.paint_with_alpha(0.8) ctx.restore() # add QRcode if qrcode text is provided if self.rc.qrcode_text: qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(self.rc.qrcode_text); qr.make(fit=True) img = qr.make_image(image_factory=qrcode.image.svg.SvgPathFillImage, fill_color='lightblue') svgstr = BytesIO() img.save(svgstr); svg_val = svgstr.getvalue() rsvg = Rsvg.Handle() svg = rsvg.new_from_data(svg_val) svgstr.close() ctx.save() ctx.translate(w - 2*logo_width - 2*Renderer.PRINT_SAFE_MARGIN_PT, logo_height/2) ctx.move_to(0, 0) factor = logo_height / svg.props.height ctx.scale(factor, factor) svg.render_cairo(ctx) ctx.restore() # Prepare the text for the left of the footer today = datetime.date.today() notice = _(u'Copyright © %(year)d MapOSMatic/OCitySMap developers.') notice+= '\n\n' notice+= _(u'Map data © %(year)d OpenStreetMap contributors (see http://osm.org/copyright)') notice+= '\n' annotations = [] if self.rc.stylesheet.annotation != '': annotations.append(self.rc.stylesheet.annotation) for overlay in self._overlays: if overlay.annotation != '': annotations.append(overlay.annotation) if len(annotations) > 0: notice+= _(u'Map styles:') notice+= ' ' + '; '.join(annotations) + '\n' notice+= _(u'Map rendered on: %(date)s. OSM data updated on: %(osmdate)s.') notice+= '\n' notice+= _(u'The map may be incomplete or inaccurate.') # We need the correct locale to be set for strftime(). prev_locale = locale.getlocale(locale.LC_TIME) locale.setlocale(locale.LC_TIME, self.rc.i18n.language_code()) try: if osm_date is None: osm_date_str = _(u'unknown') else: osm_date_str = osm_date.strftime("%d %B %Y %H:%M") notice = notice % {'year': today.year, 'date': today.strftime("%d %B %Y"), 'osmdate': osm_date_str} finally: locale.setlocale(locale.LC_TIME, prev_locale) draw_utils.draw_text_adjusted(ctx, notice, Renderer.PRINT_SAFE_MARGIN_PT, footer_h/2, footer_w, footer_h, align=Pango.Alignment.LEFT) ctx.restore()