Esempio n. 1
0
def update_fonts_cache():
    configure_fontconfig()
    subprocess.run(
        ["fc-cache"],
        env=get_clean_env(),
        check=True,
        capture_output=True,
    )
Esempio n. 2
0
 def test_cleanup(self):
     configure_fontconfig()
     cleanup_font_files()
     self.assert_font_files(0)
     font = self.add_font()
     self.assert_font_files(1)
     cleanup_font_files()
     self.assert_font_files(1)
     font.delete()
     self.assert_font_files(1)
     cleanup_font_files()
     self.assert_font_files(0)
Esempio n. 3
0
 def test_cleanup(self):
     configure_fontconfig()
     cleanup_font_files()
     # There should always be fonts.conf present
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 1)
     font = self.add_font()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 2)
     cleanup_font_files()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 2)
     font.delete()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 2)
     cleanup_font_files()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 1)
Esempio n. 4
0
    def render(self, response):
        """Render widget."""
        configure_fontconfig()
        surface = cairo.ImageSurface.create_from_png(self.get_filename())
        height = surface.get_height()
        ctx = cairo.Context(surface)

        columns = self.get_columns()
        column_width = self.get_column_width(surface, columns)

        fonts = self.get_column_fonts()

        for i, column in enumerate(columns):
            offset = self.offset
            for row, text in enumerate(column):
                layout = PangoCairo.create_layout(ctx)
                layout.set_font_description(fonts[row])

                # Set color and position
                ctx.move_to(self.column_offset + column_width * i, offset)
                ctx.set_source_rgb(*COLOR_DATA[self.color])

                # Add text
                layout.set_markup(text)
                layout.set_alignment(Pango.Alignment.CENTER)
                layout.set_width(column_width * Pango.SCALE)

                offset += layout.get_pixel_size().height

                # Render to cairo context
                PangoCairo.show_layout(ctx, layout)

            # Render column separators
            if self.lines and i > 0:
                ctx.new_path()
                ctx.set_source_rgb(*COLOR_DATA[self.color])
                ctx.set_line_width(0.5)
                ctx.move_to(column_width * i, self.offset)
                ctx.line_to(column_width * i, height - self.offset)
                ctx.stroke()

        self.render_additional(ctx)

        surface.write_to_png(response)