示例#1
0
 def set(self, ctx: Context):
     """
     Set this font to get used on the given context.
     :param ctx:
     """
     ctx.select_font_face(self.name,
                          cairo.FONT_SLANT_ITALIC if self.italic else cairo.FONT_SLANT_NORMAL,
                          cairo.FONT_WEIGHT_BOLD if self.bold else cairo.FONT_WEIGHT_NORMAL)
     ctx.set_font_size(self.size)
示例#2
0
        ctx.fill()

        if True:
            canvas.write_to_png(f"{board_name}_bg.png")
            canvas = None

            from PIL import Image
            Image.open(f"{board_name}_bg.png").save(f"{board_name}_bg.jpg")

            canvas = ImageSurface(bg.get_format(), w_p, h)
            ctx = Context(canvas)

        # add labels
        ctx.set_operator(OPERATOR_OVER)

        ctx.select_font_face("Roboto", FONT_SLANT_NORMAL, FONT_WEIGHT_BOLD)
        ctx.set_font_size(FONT_SIZE)

        labels = base_labels + variant_info

        for pass_ in range(2):
            for pin_list, type, note in labels:
                text = f"{pin_list}: {note}" if note else pin_list

                pin_names = pin_list.split("+")

                # calculate label size
                (x_bearing, y_bearing, width, height, x_advance,
                 y_advance) = ctx.text_extents(text)

                label_width = width + 2 * label_pad[0]