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 _draw_labels(ctx, map_grid, map_area_width_dots, map_area_height_dots, grid_legend_margin_dots): """ Draw the Grid labels at current position. Args: ctx (cairo.Context): The cairo context to use to draw. map_grid (Grid): the grid objects whose labels we want to draw. map_area_width_dots/map_area_height_dots (numbers): size of the map (cairo units). grid_legend_margin_dots (number): margin between border of map and grid labels (cairo units). """ ctx.save() step_horiz = map_area_width_dots / map_grid.horiz_count last_horiz_portion = math.modf(map_grid.horiz_count)[0] step_vert = map_area_height_dots / map_grid.vert_count last_vert_portion = math.modf(map_grid.vert_count)[0] ctx.set_font_size(min(0.75 * grid_legend_margin_dots, 0.5 * step_horiz)) for i, label in enumerate(map_grid.horizontal_labels): x = i * step_horiz if i < len(map_grid.horizontal_labels) - 1: x += step_horiz/2.0 elif last_horiz_portion >= 0.3: x += step_horiz * last_horiz_portion/2.0 else: continue draw_utils.draw_simpletext_center(ctx, label, x, grid_legend_margin_dots/2.0) draw_utils.draw_simpletext_center(ctx, label, x, map_area_height_dots - grid_legend_margin_dots/2.0) for i, label in enumerate(map_grid.vertical_labels): y = i * step_vert if i < len(map_grid.vertical_labels) - 1: y += step_vert/2.0 elif last_vert_portion >= 0.3: y += step_vert * last_vert_portion/2.0 else: continue draw_utils.draw_simpletext_center(ctx, label, grid_legend_margin_dots/2.0, y) draw_utils.draw_simpletext_center(ctx, label, map_area_width_dots - grid_legend_margin_dots/2.0, y) ctx.restore()
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()
def _draw_labels(ctx, map_grid, map_area_width_dots, map_area_height_dots, grid_legend_margin_dots): """ Draw the Grid labels at current position. Args: ctx (cairo.Context): The cairo context to use to draw. map_grid (Grid): the grid objects whose labels we want to draw. map_area_width_dots/map_area_height_dots (numbers): size of the map (cairo units). grid_legend_margin_dots (number): margin between border of map and grid labels (cairo units). """ ctx.save() step_horiz = map_area_width_dots / map_grid.horiz_count last_horiz_portion = math.modf(map_grid.horiz_count)[0] step_vert = map_area_height_dots / map_grid.vert_count last_vert_portion = math.modf(map_grid.vert_count)[0] ctx.set_font_size(min(0.75 * grid_legend_margin_dots, 0.5 * step_horiz)) for i, label in enumerate(map_grid.horizontal_labels): x = i * step_horiz if i < len(map_grid.horizontal_labels) - 1: x += step_horiz / 2.0 elif last_horiz_portion >= 0.3: x += step_horiz * last_horiz_portion / 2.0 else: continue # At the top clear the right corner of the horizontal label if (i < map_grid.horiz_count - 1): draw_utils.draw_simpletext_center( ctx, label, x, grid_legend_margin_dots / 2.0) # At the bottom clear the left corner of the horizontal label if (i > 0): draw_utils.draw_simpletext_center( ctx, label, x, map_area_height_dots - grid_legend_margin_dots / 2.0) for i, label in enumerate(map_grid.vertical_labels): y = i * step_vert if i < len(map_grid.vertical_labels) - 1: y += step_vert / 2.0 elif last_vert_portion >= 0.3: y += step_vert * last_vert_portion / 2.0 else: continue # On the left clear the upper corner of the vertical label if (i > 0): draw_utils.draw_simpletext_center( ctx, label, grid_legend_margin_dots / 2.0, y) # On the right clear the bottom corner of the vertical label if (i < map_grid.vert_count - 1): draw_utils.draw_simpletext_center( ctx, label, map_area_width_dots - grid_legend_margin_dots / 2.0, y) ctx.restore()
def show_grid(lat1, lon1, lat2, lon2): # draw grid over given bounding box if (lat1 > 0 and lat2 < 0): # split into two grids when bbox crosses the equator show_grid(lat1, lon1, 0.000001, lon2) show_grid(-0.000001, lon1, lat2, lon2) return # determine default UTM coordinates for bounding box corners (west, north, zone1_number, zone1_letter) = utm.from_latlon(lat1, lon1) (east, south, zone2_number, zone2_letter) = utm.from_latlon(lat2, lon2) # exclude the polar zones for now # TODO: add support for polar zones polar_zones = ['A', 'B', 'Y', 'Z'] if zone1_letter in polar_zones or zone2_letter in polar_zones: LOG.warning('No support for UTM polar zones yet') return # split into two grids when bbox crosses a zone border if zone1_number != zone2_number: # TODO: handle special cases for Sweden/Norway and Spitzbergen # zone fileds 32N-V, 32N-X to 37N-X split_lon = int(math.floor(lon2 / 6)) * 6 show_grid(lat1, lon1, lat2, split_lon - 0.000001) show_grid(lat1, split_lon + 0.000001, lat2, lon2) return # determine grid bounding box pixel coordinates (x1, y1) = renderer._latlon2xy(lat1, lon1) (x2, y2) = renderer._latlon2xy(lat2, lon2) # clip to grid bounding box ctx.save() ctx.rectangle(x1, y1, x2, y2) ctx.clip() # we only need one line every kilometer, so we can round things up or down w_km = math.floor(west / 1000) e_km = math.ceil(east / 1000) n_km = math.ceil(north / 1000) s_km = math.floor(south / 1000) # draw the vertical grid lines for v in range(w_km, e_km): # calc line endings and draw line # TODO: the vertical lines are not really straight (lat1, lon1) = utm.to_latlon(v * 1000, n_km * 1000, zone1_number, zone1_letter) (lat2, lon2) = utm.to_latlon(v * 1000, s_km * 1000, zone1_number, zone1_letter) grid_line(lat1, lon1, lat2, lon2) # draw easting value right next to upper visible end of the grid line (x1, y1) = renderer._latlon2xy(lat1, lon1) ctx.save() ctx.set_source_rgba(0, 0, 0.5, 0.5) draw_simpletext_center(ctx, beautify_km(v), x1 + 12, 62.5) ctx.restore() # draw the horizontal grid lines for h in range(s_km, n_km): # calc line endings and draw line (lat1, lon1) = utm.to_latlon(w_km * 1000, h * 1000, zone1_number, zone1_letter) (lat2, lon2) = utm.to_latlon(e_km * 1000, h * 1000, zone1_number, zone1_letter) grid_line(lat1, lon1, lat2, lon2) # draw northing value right below left visible end of the line (x1, y1) = renderer._latlon2xy(lat1, lon1) ctx.save() ctx.set_source_rgba(0, 0, 0.5, 0.5) draw_simpletext_center(ctx, beautify_km(h), 27, y1 + 5) ctx.restore() # draw zone field info in upper left map corner # TODO avoid overlap with northing/easting values ctx.set_source_rgba(0, 0, 0.5, 0.5) draw_simpletext_center(ctx, ("%d%s" % (zone1_number, zone1_letter)), 27, 20) ctx.restore()