当前位置: 首页>>代码示例>>Python>>正文


Python Context.set_font_size方法代码示例

本文整理汇总了Python中cairo.Context.set_font_size方法的典型用法代码示例。如果您正苦于以下问题:Python Context.set_font_size方法的具体用法?Python Context.set_font_size怎么用?Python Context.set_font_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cairo.Context的用法示例。


在下文中一共展示了Context.set_font_size方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):
        if not self.is_shape_set:
            self.layout(context)

        context.set_font_size(self.font_size)

        self.shape.draw_on_context(context)
        context.set_source_rgb(1, 1, 1)
        context.fill_preserve()
        context.set_source_rgb(0, 0, 0)
        context.stroke()
        shape = self.shape

        label = self.label
        if len(label) > 0 and label[-1] == ' ':
            label += '.'
        xb, yb, w, h, xa, ya = context.text_extents(label)
        context.rectangle(shape.start.x + self.padding,
                          shape.start.y,
                          shape.width - self.padding,
                          shape.height)
        context.clip()
        context.move_to(shape.start.x + (shape.width - self.padding - w)/2,
                        shape.start.y + shape.height - self.padding)
        context.show_text(self.label)
开发者ID:gcali,项目名称:crucipixel,代码行数:27,代码来源:input.py

示例2: layout

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]
    def layout(self, context: cairo.Context):
        super().layout(context)
        context.set_font_size(self.font_size)
        xb, yb, w, h, xa, ya = context.text_extents(self.title)
        font_shape = Rectangle(Point(h/2 + self.distance, self.distance), xa, h)
        self.__title_start_point = Point(font_shape.start.x,
                                         font_shape.start.y + h)
        outer_font_box = DrawableRectangle(
            Point(font_shape.start.x - self.distance,
                  font_shape.start.y - self.distance),
            font_shape.width + 2 * self.distance,
            font_shape.height + 2 * self.distance
        )
        self.__outer_font_box = outer_font_box
        wrapper_shape = DrawableRectangle(
            Point(0, outer_font_box.start.y + outer_font_box.height / 2),
            outer_font_box.start.x + max(
                outer_font_box.width,
                self.widget.shape.width
            ) + self.distance,
            outer_font_box.height/2 + 2*self.distance +
                self.widget.shape.height
        )

        self.widget.set_translate(
            outer_font_box.start.x,
            outer_font_box.start.y + outer_font_box.height + self.distance
        )

        self.__wrapper_shape = wrapper_shape
        self.shape = DrawableRectangle(
            Point(0, 0),
            wrapper_shape.width,
            wrapper_shape.start.y + wrapper_shape.height
        )
开发者ID:gcali,项目名称:crucipixel,代码行数:37,代码来源:input.py

示例3: set_shape_from_context

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]
    def set_shape_from_context(self, context: cairo.Context):
        label = self.label
        padding = self.padding
        context.set_font_size(self.font_size)
        xb, yb, w, h, xa, ya = context.text_extents(label)
        width = padding * 2 + xa
        height = padding * 2 + h
        height = max(height, self.min_height)

        if self.origin == self.LEFT:
            start = Point(0, 0)
        elif self.origin == self.CENTER:
            start = Point(-width/2, 0)
        else:
            start = Point(-width, 0)
        self.shape = DrawableRoundedRectangle(start, width, height)
开发者ID:gcali,项目名称:crucipixel,代码行数:18,代码来源:buttons.py

示例4: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):

        start_x, start_y = context.get_current_point()
        context.set_font_size(self.font_size)

        context.move_to(0, 0)

        if not self.is_shape_set:
            self.set_shape_from_context(context)
        shape = self.shape
        start = shape.start
        padding = self.padding
        h = shape.height - 2 * padding
        label = self.label

        context.set_source_rgb(*self.background_color)
        shape.draw_on_context(context)
        context.fill_preserve()

        context.set_line_width(1)
        context.set_source_rgb(*self.label_color)
        context.stroke()

        if self.disabled:
            context.set_source_rgba(1, 1, 1, .7)
            context.move_to(start.x + padding-1,
                            start.y + padding + h+1)
            context.show_text(label)
            context.set_source_rgba(*self.label_color, .9)
        else:
            context.set_source_rgb(*self.label_color)
        context.move_to(start.x + padding,
                        start.y + padding + h)
        context.show_text(label)

        if self.disabled:
            context.set_source_rgba(1, 1, 1, .7)
            context.move_to(0, 0)
            shape.draw_on_context(context)
            context.fill()
开发者ID:gcali,项目名称:crucipixel,代码行数:42,代码来源:buttons.py

示例5: __init__

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]

#.........这里部分代码省略.........
        self.stack.append(self.affine.terms())
        self.command('q')

    def restore(self):
        self.affine = Affine(*self.stack.pop())
        self.command('Q')

    def user_to_device(self, x, y):
        user = Point(x, y)
        device = self.affine(user)
        return (device.x, device.y)

    def device_to_user(self, x, y):
        device = Point(x, y)
        user = self.affine.inverse()(device)
        return (user.x, user.y)

    def move_to(self, x, y):
        self.point = Point(x, y)
        self.command('%.3f %.3f m' % (x, y))

    def rel_line_to(self, x, y):
        end = Point(x, y).add(self.point)
        self.point = end
        self.command('%.3f %.3f l' % (end.x, end.y))

    def set_source_rgb(self, r, g, b):
        self.command('%.3f %.3f %.3f rg' % (r, g, b))

    def fill(self):
        self.command('f')

    def set_source_surface(self, surf, x, y):
        """
        """
        dim = surf.get_width(), surf.get_height()
        img = Image.fromstring('RGBA', dim, surf.get_data())
        
        # weird channel order
        blue, green, red, alpha = img.split()
        img = Image.merge('RGB', (red, green, blue))

        png_buf = StringIO()
        img.save(png_buf, 'PNG')
        
        jpg_buf = StringIO()
        img.save(jpg_buf, 'JPEG', quality=75)
        
        if len(jpg_buf.getvalue()) < len(png_buf.getvalue()):
            method, buffer, suffix = 'raw_jpeg', jpg_buf, '.jpg'
        
        else:
            method, buffer, suffix = 'raw_png', png_buf, '.png'
        
        handle, filename = mkstemp(prefix='cairoutils-', suffix=suffix)
        self.command(method, filename)
        self.garbage.append(filename)

        write(handle, buffer.getvalue())
        close(handle)

    def paint(self):
        pass

    def set_line_width(self, w):
        self.command('%.3f w' % w)

    def set_dash(self, a):
        a = ' '.join(['%.3f' % v for v in a])
        self.command('[%s] 0 d' % a)

    def stroke(self):
        self.command('S')

    def rel_curve_to(self, a, b, c, d, e, f):
        p1 = Point(a, b).add(self.point)
        p2 = Point(c, d).add(self.point)
        p3 = Point(e, f).add(self.point)
        self.point = p3
        self.command('%.3f %.3f %.3f %.3f %.3f %.3f c' % (p1.x, p1.y, p2.x, p2.y, p3.x, p3.y))

    def set_font_face(self, font):
        self.context.set_font_face(font)

    def set_font_size(self, size):
        self.context.set_font_size(size)
        
        # SetFont here because only the size gives a clue to the correct weight
        self.command('SetFont', 'Liberation Sans', (size > 14) and 'B' or '')
        self.command('SetFontSize', size)

    def show_text(self, text):
        x, y = self.point.x, self.point.y
        text = text.decode('utf8')
        
        # invert the vertical flip in self.show_page() before showing text.
        self.command('q 1 0 0 -1 0 0 cm BT %.3f %.3f Td (%s) Tj ET Q' % (x, -y, text))

    def text_extents(self, text):
        return self.context.text_extents(text)
开发者ID:migurski,项目名称:paperwalking,代码行数:104,代码来源:cairoutils.py

示例6: set_shape_from_context

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]
    def set_shape_from_context(self, context: cairo.Context):

        widths_heights = []

        done = False

        while not done:
            max_width = 0
            max_height = 0
            context.set_font_size(self.font_size)

            for e in reversed(self._elements):
                xb, yb, w, h, xa, ya = context.text_extents(e.label)
                widths_heights.append((xa, h))
                e.width = xa
                e.height = h
                max_width = max(max_width, xa)
                max_height = max(max_height, h)


            # adjust font size in case it's too big
            if self.max_size is None:
                done = True
            else:
                if self.orientation == Orientation.HORIZONTAL:
                    reference = max_height
                else:
                    reference = max_width
                if reference + 2 * self.line_distance <= self.max_size:
                    done = True
                else:
                    self.font_size -= 1

        positions = []
        width = self.element_distance
        height = self.element_distance

        def get_padding(actual_size):
            if self.max_size is not None:
                return (self.max_size - actual_size) / 2
            else:
                return self.line_distance

        if self.orientation == Orientation.HORIZONTAL:
            def handle_extents(e: _GuideElement):
                nonlocal width, height, positions, max_height
                width += e.width
                e.position = (-width,
                              max_height + get_padding(max_height))
                width += self.element_distance
        else:
            def handle_extents(e: _GuideElement):
                nonlocal width, height, positions, max_width
                e.position = (get_padding(e.width),
                              -height)
                height += e.height + self.element_distance

        # for w, h in widths_heights:
        #     handle_extents(w, h)

        for element in reversed(self._elements):
            handle_extents(element)

        if self.orientation == Orientation.HORIZONTAL:
            height = max_height + get_padding(max_height) * 2
            width = width - self.element_distance + self.line_distance
            base_point = Point(-width, 0)
        else:
            width = max_width + get_padding(max_width) * 2
            height = height - self.element_distance + self.line_distance
            base_point = Point(0, -height)

        self.shape = Rectangle(base_point, width, height)
开发者ID:gcali,项目名称:crucipixel,代码行数:75,代码来源:guides.py

示例7: __init__

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]

#.........这里部分代码省略.........

    def device_to_user(self, x, y):
        device = Point(x, y)
        user = self.affine.inverse()(device)
        return (user.x, user.y)

    def move_to(self, x, y):
        self.point = Point(x, y)
        self.command("%.3f %.3f m" % (x, y))

    def line_to(self, x, y):
        self.point = Point(x, y)
        self.command("%.3f %.3f l" % (x, y))

    def rel_move_to(self, x, y):
        end = Point(x, y).add(self.point)
        self.point = end
        self.command("%.3f %.3f m" % (end.x, end.y))

    def rel_line_to(self, x, y):
        end = Point(x, y).add(self.point)
        self.point = end
        self.command("%.3f %.3f l" % (end.x, end.y))

    def set_source_rgb(self, r, g, b):
        self.command("%.3f %.3f %.3f rg" % (r, g, b))

    def fill(self):
        self.command("f")

    def set_source_surface(self, surf, x, y):
        """
        """
        dim = surf.get_width(), surf.get_height()
        img = Image.fromstring("RGBA", dim, surf.get_data())

        # weird channel order
        blue, green, red, alpha = img.split()
        img = Image.merge("RGB", (red, green, blue))

        png_buf = StringIO()
        img.save(png_buf, "PNG")

        jpg_buf = StringIO()
        img.save(jpg_buf, "JPEG", quality=75)

        if len(jpg_buf.getvalue()) < len(png_buf.getvalue()):
            method, buffer, suffix = "raw_jpeg", jpg_buf, ".jpg"

        else:
            method, buffer, suffix = "raw_png", png_buf, ".png"

        handle, filename = mkstemp(prefix="cairoutils-", suffix=suffix)
        self.command(method, filename)
        self.garbage.append(filename)

        write(handle, buffer.getvalue())
        close(handle)

    def paint(self):
        pass

    def set_line_width(self, w):
        self.command("%.3f w" % w)

    def set_dash(self, a):
        a = " ".join(["%.3f" % v for v in a])
        self.command("[%s] 0 d" % a)

    def stroke(self):
        self.command("S")

    def rel_curve_to(self, a, b, c, d, e, f):
        p1 = Point(a, b).add(self.point)
        p2 = Point(c, d).add(self.point)
        p3 = Point(e, f).add(self.point)
        self.point = p3
        self.command("%.3f %.3f %.3f %.3f %.3f %.3f c" % (p1.x, p1.y, p2.x, p2.y, p3.x, p3.y))

    def set_font_face(self, font):
        self.context.set_font_face(font)

    def set_font_size(self, size):
        self.context.set_font_size(size)

        # SetFont here because only the size gives a clue to the correct weight
        self.command("SetFont", "Helvetica", (size > 14) and "B" or "")
        self.command("SetFontSize", size)

    def show_text(self, text):
        x, y = self.point.x, self.point.y
        text = text.decode("utf8")

        # invert the vertical flip in self.show_page() before showing text.
        self.command("q 1 0 0 -1 0 0 cm BT %.3f %.3f Td (%s) Tj ET Q" % (x, -y, text))

    def text_extents(self, text):
        """ Width is the third element of the returned array.
        """
        return self.context.text_extents(text)
开发者ID:ndpgroup,项目名称:fp-legacy,代码行数:104,代码来源:cairoutils.py

示例8: _set_font

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]
 def _set_font(self, context: cairo.Context):
     context.set_font_size(self.font_size)
     slant = cairo.FONT_SLANT_NORMAL if not self.italic else cairo.FONT_SLANT_ITALIC
     weight = cairo.FONT_WEIGHT_NORMAL if not self.bold else cairo.FONT_WEIGHT_BOLD
     context.select_font_face("", slant, weight)
开发者ID:gcali,项目名称:crucipixel,代码行数:7,代码来源:text.py

示例9: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):
        self.min_size = 200, 150
        super().on_draw(widget, context)

        context.save()
        context.set_font_size(self.font_size)

        if self._table_extents is None:
            self._update_table_extents(context)

        skip = max(self.skip, 0)
        how_many = self.how_many

        table_extents = self._table_extents
        title_extents = self._table_extents.title_extents

        expected_height = title_extents.total_height + self.margin

        entries = self.entries

        base = skip
        up_to = skip
        over = False
        while up_to < len(entries) and not over:
            expected_height += table_extents[up_to].total_height
            over = expected_height >= self._max_height
            if not over:
                up_to += 1

        while base > 0 and not over:
            expected_height += table_extents[base-1].total_height
            over = expected_height >= self._max_height
            if not over:
                base -= 1

        how_many = up_to - base
        skip = base
        self.base = base

        entries = self.entries[skip:skip + how_many]

        def table_extents_iterator():
            return table_extents.iter_over(
                skip, how_many
            )

        start_x, start_y = context.get_current_point()

        start_y += title_extents.total_height
        h = title_extents.total_height
        self.title_height = h
        for (index, cell), data in zip(enumerate(title_extents), self.title):
            context.save()
            offset = title_extents.get_cell_data_left(index)
            context.rectangle(start_x + offset, start_y - h, cell.width, 2*h)
            context.clip()
            context.move_to(
                start_x + offset,
                start_y
            )
            context.show_text(data)
            context.restore()
        # start_y += self.margin

        curr_x, curr_y = start_x, start_y# + title_extents.total_height

        for line_index, (line_extent, entry) in enumerate(zip(table_extents_iterator(), entries)):
            h = line_extent.total_height
            curr_y += h
            if curr_y + self.margin >= self._max_height:
                break
            for (cell_index, cell), data in zip(enumerate(line_extent), entry):
                context.save()
                offset = line_extent.get_cell_data_left(cell_index)
                context.rectangle(curr_x + offset, curr_y - h, cell.width, 2*h)
                context.clip()
                context.move_to(
                    curr_x + offset,
                    curr_y
                )
                context.show_text(data)
                context.restore()

        curr_x = start_x
        end_x = table_extents.entries_width
        curr_y = start_y + self.margin
        end_y = table_extents.get_height_up_to(skip, how_many) + start_y + self.margin + 1

        self.table_height = end_y
        self.table_width = end_x

        for line in table_extents_iterator():
            context.move_to(curr_x, curr_y)
            context.line_to(end_x, curr_y)
            context.stroke()
            curr_y += line.total_height
        context.move_to(curr_x, curr_y)
        context.line_to(end_x, curr_y)
        context.stroke()

#.........这里部分代码省略.........
开发者ID:gcali,项目名称:crucipixel,代码行数:103,代码来源:chooser_table.py

示例10: _paint_panel

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_size [as 别名]

#.........这里部分代码省略.........

        min_y = math.floor(min_y)
        max_y = math.ceil(max_y)

        if typ == 2:
            if min_y < 0 and max_y < 0:
                max_y = 0
            elif min_y > 0 and max_y > 0:
                min_y = 0

        # Определяем цвета
        colors = [[1, 0, 0], [0, 0.65, 0.31], [0, 0, 1], [1, 0, 1]]

        off_y = (max_y - min_y) / 10
        min_y -= off_y
        max_y += off_y

        try:
            kx = (max_x - min_x) / (width - left - right)
            ky = (max_y - min_y) / (height - bottom)
            if ky == 0:
                ky = 1
        except:
            kx, ky = 1, 1

        img = ImageSurface(FORMAT_ARGB32, width, height)
        ctx = Context(img)

        width -= right
        ctx.set_line_width(1)

        # Рисуем сетку

        ctx.set_font_size(12)
        try:
            b_w, b_h = ctx.text_extents("00-00-0000")[2:4]

            # Метки на оси Y
            count = math.ceil(max_y) - math.ceil(min_y)
            space_count = math.ceil(count / ((height - bottom) / (b_h * 1.5)))
            sc = 0
            for i in range(math.ceil(min_y), math.ceil(max_y)):
                if sc == 0:
                    y = height - bottom + (min_y - i) / ky
                    ctx.set_source_rgb(*(color_x_line))
                    ctx.move_to(left, y)
                    ctx.line_to(width, y)
                    ctx.stroke()
                    ctx.set_source_rgb(0, 0, 0)
                    num = str(i)
                    tw, th = ctx.text_extents(num)[2:4]
                    ctx.move_to(left - 5 - tw, y + th // 2)
                    ctx.show_text(num)
                    sc = space_count
                sc -= 1

            # Метки на оси Х

            x_step = 3600
            if interval == "-6 hour" or interval == "-12 hour" or interval == "-1 day":
                # Дополнительно метки часов
                x_step = 3600
                for i in range(math.ceil(min_x / x_step), math.ceil(max_x / x_step)):
                    x = (i * x_step - min_x) / kx + left
                    ctx.set_source_rgb(*(color_x_line_2))
                    ctx.move_to(x, 0)
开发者ID:SolitonNew,项目名称:pyhome,代码行数:70,代码来源:page5_1.py


注:本文中的cairo.Context.set_font_size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。