def _render_blank_page(self, ctx, cairo_surface, dpi):
        """
        Render a blank page with a nice "intentionally blank" notice
        """
        ctx.save()
        ctx.translate(
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT),
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT))

        # footer notice
        w = self._usable_area_width_pt
        h = self._usable_area_height_pt
        ctx.set_source_rgb(.6,.6,.6)
        draw_utils.draw_simpletext_center(ctx, _('This page is intentionally left '\
                                            'blank.'), w/2.0, 0.95*h)
        draw_utils.render_page_number(ctx, 2,
                                      self._usable_area_width_pt,
                                      self._usable_area_height_pt,
                                      self.grayed_margin_pt,
                                      transparent_background=False)
        try: # set_page_label() does not exist in older pycairo versions
            cairo_surface.set_page_label(_(u'Blank'))
        except:
            pass
        cairo_surface.show_page()
        ctx.restore()
    def render(self, cairo_surface, dpi, osm_date):
        ctx = cairo.Context(cairo_surface)

        self._render_front_page(ctx, cairo_surface, dpi, osm_date)
        self._render_blank_page(ctx, cairo_surface, dpi)

        ctx.save()

        # Prepare to draw the map at the right location
        ctx.translate(
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT),
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT))

        self._render_overview_page(ctx, cairo_surface, dpi)

        for map_number, (canvas, grid) in enumerate(self.pages):

            rendered_map = canvas.get_rendered_map()
            LOG.debug('Mapnik scale: 1/%f' % rendered_map.scale_denominator())
            LOG.debug('Actual scale: 1/%f' % canvas.get_actual_scale())
            mapnik.render(rendered_map, ctx)

            # Place the vertical and horizontal square labels
            ctx.save()
            ctx.translate(commons.convert_pt_to_dots(self.grayed_margin_pt),
                      commons.convert_pt_to_dots(self.grayed_margin_pt))
            self._draw_labels(ctx, grid,
                  commons.convert_pt_to_dots(self._usable_area_width_pt) \
                        - 2 * commons.convert_pt_to_dots(self.grayed_margin_pt),
                  commons.convert_pt_to_dots(self._usable_area_height_pt) \
                        - 2 * commons.convert_pt_to_dots(self.grayed_margin_pt),
                  commons.convert_pt_to_dots(self._grid_legend_margin_pt))

            ctx.restore()

            # Render the page number
            draw_utils.render_page_number(ctx, map_number+4,
                                          self._usable_area_width_pt,
                                          self._usable_area_height_pt,
                                          self.grayed_margin_pt,
                                          transparent_background = True)
            self._render_neighbour_arrows(ctx, cairo_surface, map_number,
                                          len(unicode(len(self.pages)+4)))

            cairo_surface.show_page()
        ctx.restore()

        mpsir = MultiPageStreetIndexRenderer(self.rc.i18n,
                                             ctx, cairo_surface,
                                             self.index_categories,
                                             (Renderer.PRINT_SAFE_MARGIN_PT,
                                              Renderer.PRINT_SAFE_MARGIN_PT,
                                              self._usable_area_width_pt,
                                              self._usable_area_height_pt),
                                              map_number+5)

        mpsir.render()

        cairo_surface.flush()
Exemple #3
0
    def render(self, cairo_surface, dpi, osm_date):
        ctx = cairo.Context(cairo_surface)

        self._render_front_page(ctx, cairo_surface, dpi, osm_date)
        self._render_blank_page(ctx, cairo_surface, dpi)

        ctx.save()

        # Prepare to draw the map at the right location
        ctx.translate(
            commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT),
            commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT))

        self._render_overview_page(ctx, cairo_surface, dpi)

        for map_number, (canvas, grid) in enumerate(self.pages):

            rendered_map = canvas.get_rendered_map()
            LOG.debug('Mapnik scale: 1/%f' % rendered_map.scale_denominator())
            LOG.debug('Actual scale: 1/%f' % canvas.get_actual_scale())
            mapnik.render(rendered_map, ctx)

            # Place the vertical and horizontal square labels
            ctx.save()
            ctx.translate(commons.convert_pt_to_dots(self.grayed_margin_pt),
                          commons.convert_pt_to_dots(self.grayed_margin_pt))
            self._draw_labels(ctx, grid,
                  commons.convert_pt_to_dots(self._usable_area_width_pt) \
                        - 2 * commons.convert_pt_to_dots(self.grayed_margin_pt),
                  commons.convert_pt_to_dots(self._usable_area_height_pt) \
                        - 2 * commons.convert_pt_to_dots(self.grayed_margin_pt),
                  commons.convert_pt_to_dots(self._grid_legend_margin_pt))

            ctx.restore()

            # Render the page number
            draw_utils.render_page_number(ctx,
                                          map_number + 4,
                                          self._usable_area_width_pt,
                                          self._usable_area_height_pt,
                                          self.grayed_margin_pt,
                                          transparent_background=True)
            self._render_neighbour_arrows(ctx, cairo_surface, map_number,
                                          len(unicode(len(self.pages) + 4)))

            cairo_surface.show_page()
        ctx.restore()

        mpsir = MultiPageStreetIndexRenderer(
            self.rc.i18n, ctx, cairo_surface, self.index_categories,
            (Renderer.PRINT_SAFE_MARGIN_PT, Renderer.PRINT_SAFE_MARGIN_PT,
             self._usable_area_width_pt, self._usable_area_height_pt),
            map_number + 5)

        mpsir.render()

        cairo_surface.flush()
    def _render_overview_page(self, ctx, cairo_surface, dpi):
        rendered_map = self.overview_canvas.get_rendered_map()
        mapnik.render(rendered_map, ctx)

        # draw pages numbers
        self._draw_overview_labels(ctx, self.overview_canvas, self.overview_grid,
              commons.convert_pt_to_dots(self._usable_area_width_pt),
              commons.convert_pt_to_dots(self._usable_area_height_pt))
        # Render the page number
        draw_utils.render_page_number(ctx, 3,
                                      self._usable_area_width_pt,
                                      self._usable_area_height_pt,
                                      self.grayed_margin_pt,
                                      transparent_background = True)

        cairo_surface.show_page()
    def _render_overview_page(self, ctx, cairo_surface, dpi):
        rendered_map = self.overview_canvas.get_rendered_map()
        mapnik.render(rendered_map, ctx)

        # draw pages numbers
        self._draw_overview_labels(
            ctx, self.overview_canvas, self.overview_grid,
            commons.convert_pt_to_dots(self._usable_area_width_pt),
            commons.convert_pt_to_dots(self._usable_area_height_pt))
        # Render the page number
        draw_utils.render_page_number(ctx,
                                      3,
                                      self._usable_area_width_pt,
                                      self._usable_area_height_pt,
                                      self.grayed_margin_pt,
                                      transparent_background=True)

        cairo_surface.show_page()
    def _render_overview_page(self, ctx, cairo_surface, dpi):
        rendered_map = self.overview_canvas.get_rendered_map()
        mapnik.render(rendered_map, ctx)

        for ov_canvas in self.overview_overlay_canvases:
            rendered_map = ov_canvas.get_rendered_map()
            mapnik.render(rendered_map, ctx)

        # apply effect overlays
        ctx.save()
        # we have to undo border adjustments here
        ctx.translate(
                -commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT),
                -commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT))
        self._map_canvas = self.overview_canvas;
        for plugin_name, effect in self.overview_overlay_effects.items():
            try:
                effect.render(self, ctx)
            except Exception as e:
                # TODO better logging
                LOG.warning("Error while rendering overlay: %s\n%s" % (plugin_name, e))

        ctx.restore()
            
        # draw pages numbers
        self._draw_overview_labels(ctx, self.overview_canvas, self.overview_grid,
              commons.convert_pt_to_dots(self._usable_area_width_pt),
              commons.convert_pt_to_dots(self._usable_area_height_pt))
        # Render the page number
        draw_utils.render_page_number(ctx, 3,
                                      self._usable_area_width_pt,
                                      self._usable_area_height_pt,
                                      self.grayed_margin_pt,
                                      transparent_background = True)

        try: # set_page_label() does not exist in older pycairo versions
            cairo_surface.set_page_label(_(u'Overview'))
        except:
            pass
        cairo_surface.show_page()
    def _render_blank_page(self, ctx, cairo_surface, dpi):
        """
        Render a blank page with a nice "intentionally blank" notice
        """
        ctx.save()
        ctx.translate(
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT),
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT))

        # footer notice
        w = self._usable_area_width_pt
        h = self._usable_area_height_pt
        ctx.set_source_rgb(.6,.6,.6)
        draw_utils.draw_simpletext_center(ctx, _('This page is intentionally left '\
                                            'blank.'), w/2.0, 0.95*h)
        draw_utils.render_page_number(ctx, 2,
                                      self._usable_area_width_pt,
                                      self._usable_area_height_pt,
                                      self.grayed_margin_pt,
                                      transparent_background=False)
        cairo_surface.show_page()
        ctx.restore()
Exemple #8
0
    def render(self, cairo_surface, dpi, osm_date):
        ctx = cairo.Context(cairo_surface)

        self._render_front_page(ctx, cairo_surface, dpi, osm_date)
        self._render_blank_page(ctx, cairo_surface, dpi)

        ctx.save()

        # Prepare to draw the map at the right location
        ctx.translate(
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT),
                commons.convert_pt_to_dots(Renderer.PRINT_SAFE_MARGIN_PT))
        ctx.rectangle(0, 0, self._usable_area_width_pt, self._usable_area_height_pt)
        ctx.clip()

        self._render_overview_page(ctx, cairo_surface, dpi)

        for map_number, (canvas, grid, overlay_canvases, overlay_effects) in enumerate(self.pages):
            LOG.info('Map page %d of %d' % (map_number + 1, len(self.pages)))
            rendered_map = canvas.get_rendered_map()
            LOG.debug('Mapnik scale: 1/%f' % rendered_map.scale_denominator())
            LOG.debug('Actual scale: 1/%f' % canvas.get_actual_scale())

            dest_tag = "mypage%d" % (map_number + self._first_map_page_number)
            draw_utils.anchor(ctx, dest_tag)

            mapnik.render(rendered_map, ctx)

            for overlay_canvas in overlay_canvases:
                rendered_overlay = overlay_canvas.get_rendered_map()
                mapnik.render(rendered_overlay, ctx)

            # Place the vertical and horizontal square labels
            ctx.save()
            ctx.translate(commons.convert_pt_to_dots(self.grayed_margin_pt),
                      commons.convert_pt_to_dots(self.grayed_margin_pt))
            self._draw_labels(ctx, grid,
                  commons.convert_pt_to_dots(self._usable_area_width_pt) \
                        - 2 * commons.convert_pt_to_dots(self.grayed_margin_pt),
                  commons.convert_pt_to_dots(self._usable_area_height_pt) \
                        - 2 * commons.convert_pt_to_dots(self.grayed_margin_pt),
                  commons.convert_pt_to_dots(self._grid_legend_margin_pt))
            ctx.restore()


            # apply effect overlays
            ctx.save()
            # we have to undo border adjustments here
            ctx.translate(-commons.convert_pt_to_dots(self.grayed_margin_pt)/2,
                      -commons.convert_pt_to_dots(self.grayed_margin_pt)/2)
            self._map_canvas = canvas;
            for plugin_name, effect in overlay_effects.items():
                self.grid = grid
                try:
                    effect.render(self, ctx)
                except Exception as e:
                    # TODO better logging
                    LOG.warning("Error while rendering overlay: %s\n%s" % (plugin_name, e))
                    effect.render(self, ctx)
            ctx.restore()


            # Render the page number
            draw_utils.render_page_number(ctx, map_number + self._first_map_page_number,
                                          self._usable_area_width_pt,
                                          self._usable_area_height_pt,
                                          self.grayed_margin_pt,
                                          transparent_background = True)
            self._render_neighbour_arrows(ctx, cairo_surface, map_number,
                                          len(str(len(self.pages) + self._first_map_page_number)))

            cairo_surface.set_page_label('Map page %d' % (map_number + self._first_map_page_number))
            cairo_surface.show_page()
        ctx.restore()

        mpsir = MultiPageStreetIndexRenderer(self.rc.i18n,
                                             ctx, cairo_surface,
                                             self.index_categories,
                                             (Renderer.PRINT_SAFE_MARGIN_PT,
                                              Renderer.PRINT_SAFE_MARGIN_PT,
                                              self._usable_area_width_pt,
                                              self._usable_area_height_pt),
                                              map_number+5)

        mpsir.render()

        cairo_surface.flush()