def _draw_title(self, ctx, w_dots, h_dots, font_face):
        """
        Draw the title at the current position inside a
        w_dots*h_dots rectangle.

        Args:
           ctx (cairo.Context): The Cairo context to use to draw.
           w_dots,h_dots (number): Rectangle dimension (ciaro units)
           font_face (str): Pango font specification.
        """

        # Title background
        ctx.save()
        ctx.set_source_rgb(0.8, 0.9, 0.96)
        ctx.rectangle(0, 0, w_dots, h_dots)
        ctx.fill()
        ctx.restore()

        # Retrieve and paint the OSM logo
        ctx.save()
        grp, logo_width = self._get_osm_logo(ctx, 0.8 * h_dots)
        if grp:
            ctx.translate(w_dots - logo_width - 0.1 * h_dots, 0.1 * h_dots)
            ctx.set_source(grp)
            ctx.paint_with_alpha(0.5)
        else:
            LOG.warning("OSM Logo not available.")
            logo_width = 0
        ctx.restore()

        # Prepare the title
        pc = pangocairo.CairoContext(ctx)
        layout = pc.create_layout()
        layout.set_width(int((w_dots - 0.1 * w_dots - logo_width) * pango.SCALE))
        if not self.rc.i18n.isrtl():
            layout.set_alignment(pango.ALIGN_LEFT)
        else:
            layout.set_alignment(pango.ALIGN_RIGHT)
        fd = pango.FontDescription(font_face)
        fd.set_size(pango.SCALE)
        layout.set_font_description(fd)
        layout.set_text(self.rc.title)
        draw_utils.adjust_font_size(layout, fd, layout.get_width(), 0.8 * h_dots)

        # Draw the title
        ctx.save()
        ctx.rectangle(0, 0, w_dots, h_dots)
        ctx.stroke()
        ctx.translate(0.1 * h_dots, (h_dots - (layout.get_size()[1] / pango.SCALE)) / 2.0)
        pc.show_layout(layout)
        ctx.restore()
    def _draw_title(self, ctx, w_dots, h_dots, font_face):
        """
        Draw the title at the current position inside a
        w_dots*h_dots rectangle.

        Args:
           ctx (cairo.Context): The Cairo context to use to draw.
           w_dots,h_dots (number): Rectangle dimension (ciaro units)
           font_face (str): Pango font specification.
        """

        # Title background
        ctx.save()
        ctx.set_source_rgb(0.8, 0.9, 0.96)
        ctx.rectangle(0, 0, w_dots, h_dots)
        ctx.fill()
        ctx.restore()

        # Retrieve and paint the OSM logo
        ctx.save()
        grp, logo_width = self._get_osm_logo(ctx, 0.8*h_dots)
        if grp:
            ctx.translate(w_dots - logo_width - 0.1*h_dots, 0.1*h_dots)
            ctx.set_source(grp)
            ctx.paint_with_alpha(0.5)
        else:
            LOG.warning("OSM Logo not available.")
            logo_width = 0
        ctx.restore()

        # Prepare the title
        pc = pangocairo.CairoContext(ctx)
        layout = pc.create_layout()
        layout.set_width(int((w_dots - 0.1*w_dots - logo_width) * pango.SCALE))
        if not self.rc.i18n.isrtl(): layout.set_alignment(pango.ALIGN_LEFT)
        else:                        layout.set_alignment(pango.ALIGN_RIGHT)
        fd = pango.FontDescription(font_face)
        fd.set_size(pango.SCALE)
        layout.set_font_description(fd)
        layout.set_text(self.rc.title)
        draw_utils.adjust_font_size(layout, fd, layout.get_width(), 0.8*h_dots)

        # Draw the title
        ctx.save()
        ctx.rectangle(0, 0, w_dots, h_dots)
        ctx.stroke()
        ctx.translate(0.1*h_dots,
                      (h_dots -
                       (layout.get_size()[1] / pango.SCALE)) / 2.0)
        pc.show_layout(layout)
        ctx.restore()
    def _draw_copyright_notice(self, ctx, w_dots, h_dots, notice=None,
                               osm_date=None):
        """
        Draw a copyright notice at current location and within the
        given w_dots*h_dots rectangle.

        Args:
           ctx (cairo.Context): The Cairo context to use to draw.
           w_dots,h_dots (number): Rectangle dimension (ciaro units).
           font_face (str): Pango font specification.
           notice (str): Optional notice to replace the default.
        """

        today = datetime.date.today()
        notice = notice or \
            _(u'Copyright © %(year)d MapOSMatic/OCitySMap developers. '
              u'Map data © %(year)d OpenStreetMap.org '
              u'and contributors (cc-by-sa).\n'
              u'Map rendered on: %(date)s. OSM data updated on: %(osmdate)s. '
              u'The map may be incomplete or inaccurate. '
              u'You can contribute to improve this map. '
              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)

        ctx.save()
        pc = pangocairo.CairoContext(ctx)
        fd = pango.FontDescription('DejaVu')
        fd.set_size(pango.SCALE)
        layout = pc.create_layout()
        layout.set_font_description(fd)
        layout.set_text(notice)
        draw_utils.adjust_font_size(layout, fd, w_dots, h_dots)
        pc.show_layout(layout)
        ctx.restore()
    def _draw_copyright_notice(self, ctx, w_dots, h_dots, notice=None,
                               osm_date=None):
        """
        Draw a copyright notice at current location and within the
        given w_dots*h_dots rectangle.

        Args:
           ctx (cairo.Context): The Cairo context to use to draw.
           w_dots,h_dots (number): Rectangle dimension (ciaro units).
           font_face (str): Pango font specification.
           notice (str): Optional notice to replace the default.
        """

        today = datetime.date.today()
        notice = notice or \
            _(u'Copyright © %(year)d MapOSMatic/OCitySMap developers. '
              u'Map data © %(year)d OpenStreetMap.org '
              u'and contributors (cc-by-sa).\n'
              u'Map rendered on: %(date)s. OSM data updated on: %(osmdate)s. '
              u'The map may be incomplete or inaccurate. '
              u'You can contribute to improve this map. '
              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)

        ctx.save()
        pc = pangocairo.CairoContext(ctx)
        fd = pango.FontDescription('DejaVu')
        fd.set_size(pango.SCALE)
        layout = pc.create_layout()
        layout.set_font_description(fd)
        layout.set_text(notice)
        draw_utils.adjust_font_size(layout, fd, w_dots, h_dots)
        pc.show_layout(layout)
        ctx.restore()
Esempio n. 5
0
    def _draw_copyright_notice(self, ctx, w_dots, h_dots, notice=None,
                               osm_date=None):
        """
        Draw a copyright notice at current location and within the
        given w_dots*h_dots rectangle.

        Args:
           ctx (cairo.Context): The Cairo context to use to draw.
           w_dots,h_dots (number): Rectangle dimension (ciaro units).
           font_face (str): Pango font specification.
           notice (str): Optional notice to replace the default.
        """

        today = datetime.date.today()
        if notice is None: 
            notice = _(u'Copyright © %(year)d MapOSMatic/OCitySMap developers.')
            notice+= ' '
            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'

            datasources = set()
            if self.rc.stylesheet.datasource != '':
                datasources.add(self.rc.stylesheet.datasource)
            for overlay in self._overlays:
                if overlay.datasource != '':
                    datasources.add(overlay.datasource)
            if len(datasources) > 0:
                notice+= _(u'Additional data sources:')
                notice+= ' ' + '; '.join(list(datasources)) + '\n'

            notice+= _(u'Map rendered on: %(date)s. OSM data updated on: %(osmdate)s.')
            notice+= ' '
            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)
        try:
            locale.setlocale(locale.LC_TIME, self.rc.i18n.language_code())
        except Exception:
            LOG.warning('error while setting LC_COLLATE to "%s"' % 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)

        ctx.save()
        pc = PangoCairo.create_context(ctx)
        fd = Pango.FontDescription('DejaVu')
        fd.set_size(Pango.SCALE)
        layout = PangoCairo.create_layout(ctx)
        layout.set_font_description(fd)
        layout.set_text(notice, -1)
        draw_utils.adjust_font_size(layout, fd, w_dots, h_dots)
        PangoCairo.update_layout(ctx, layout)
        PangoCairo.show_layout(ctx, layout)
        ctx.restore()
Esempio n. 6
0
    def _draw_title(self, ctx, w_dots, h_dots, font_face):
        """
        Draw the title at the current position inside a
        w_dots*h_dots rectangle.

        Args:
           ctx (cairo.Context): The Cairo context to use to draw.
           w_dots,h_dots (number): Rectangle dimension (ciaro units)
           font_face (str): Pango font specification.
        """

        # Title background
        ctx.save()
        ctx.set_source_rgb(0.8, 0.9, 0.96) # TODO: make title bar color configurable?
        ctx.rectangle(0, 0, w_dots, h_dots)
        ctx.fill()
        ctx.restore()

        # Retrieve and paint the OSM logo
        ctx.save()
        grp, logo_width = self._get_osm_logo(ctx, 0.8*h_dots)
        if grp:
            ctx.translate(w_dots - logo_width - 0.1*h_dots, 0.1*h_dots)
            ctx.set_source(grp)
            ctx.paint_with_alpha(0.5)
        else:
            LOG.warning("OSM Logo not available.")
            logo_width = 0
        ctx.restore()

        # Retrieve and paint the extra logo
        # TODO: 
        logo_width2 = 0
        if self.rc.poi_file:
            ctx.save()
            grp, logo_width2 = self._get_extra_logo(ctx, 0.8*h_dots)
            if grp:
                ctx.translate(0.4*h_dots, 0.1*h_dots)
                ctx.set_source(grp)
                ctx.paint_with_alpha(0.5)
                logo_width2 += 0.4*h_dots
            else:
                LOG.warning("Extra Logo not available.")
                logo_width2 = 0
            ctx.restore()

        # Prepare the title
        pc = PangoCairo.create_context(ctx)
        layout = PangoCairo.create_layout(ctx)
        layout.set_width(int((w_dots - 0.1*w_dots - logo_width - logo_width2) * Pango.SCALE))
        if not self.rc.i18n.isrtl():
            layout.set_alignment(Pango.Alignment.LEFT)
        else:
            layout.set_alignment(Pango.Alignment.RIGHT)
        fd = Pango.FontDescription(font_face)
        fd.set_size(Pango.SCALE)
        layout.set_font_description(fd)
        layout.set_text(self.rc.title, -1)
        draw_utils.adjust_font_size(layout, fd, layout.get_width(), 0.8*h_dots)

        # Draw the title
        ctx.save()
        ctx.set_line_width(1)
        ctx.rectangle(0, 0, w_dots, h_dots)
        ctx.stroke()
        ctx.translate(0.4*h_dots + logo_width2,
                      (h_dots -
                       (layout.get_size()[1] / Pango.SCALE)) / 2.0)
        PangoCairo.update_layout(ctx, layout)
        PangoCairo.show_layout(ctx, layout)
        ctx.restore()