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


Python Pango.SCALE属性代码示例

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


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

示例1: fontstyle_to_fontdescription

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def fontstyle_to_fontdescription(font_style):
    """Convert a FontStyle instance to a Pango.FontDescription one.

    Font color and underline are not implemented in Pango.FontDescription,
    and have to be set with Pango.Layout.set_attributes(attrlist) method.

    """
    if font_style.get_bold():
        f_weight = Pango.Weight.BOLD
    else:
        f_weight = Pango.Weight.NORMAL

    if font_style.get_italic():
        f_style = Pango.Style.ITALIC
    else:
        f_style = Pango.Style.NORMAL

    font_description = Pango.FontDescription(font_families[font_style.face])
    font_description.set_size(int(round(font_style.get_size() * Pango.SCALE)))
    font_description.set_weight(f_weight)
    font_description.set_style(f_style)

    return font_description 
开发者ID:GenealogyCollective,项目名称:gprime,代码行数:25,代码来源:libcairodoc.py

示例2: getTextBounds

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def getTextBounds(self, spot):
        x_loc, y_loc, type, name, text = spot
        x_loc, y_loc = self.prcToPix(x_loc, y_loc)

        alloc = self.get_allocation()
        width = alloc.width
#        height = alloc.height

        extends = self.create_pango_layout(text).get_extents()
        scale = float(Pango.SCALE)
        x_bearing, y_bearing, twidth, theight = [extends[1].x / scale,
                                                 extends[1].y / scale,
                                                 extends[1].width / scale,
                                                 extends[1].height / scale]
        tx_loc = x_loc - x_bearing + dotLarge / 2.
        ty_loc = y_loc - y_bearing - theight - dotLarge / 2.

        if tx_loc + twidth > width and x_loc - x_bearing - twidth - dotLarge / 2. > alloc.x:
            tx_loc = x_loc - x_bearing - twidth - dotLarge / 2.
        if ty_loc < alloc.y:
            ty_loc = y_loc - y_bearing + dotLarge / 2.

        return (tx_loc, ty_loc, twidth, theight) 
开发者ID:pychess,项目名称:pychess,代码行数:25,代码来源:SpotGraph.py

示例3: __init__

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def __init__(self, day_text_view):
        super().__init__()
        self.day_text_view = day_text_view

        self._connect_undo_signals()

        self.search_text = ""

        # spell checker
        self._spell_checker = None
        self.enable_spell_check(False)

        # Enable drag&drop
        self.day_text_view.connect("drag-data-received", self.on_drag_data_received)

        # Sometimes making the editor window very small causes the program to freeze
        # So we forbid that behaviour, by setting a minimum width
        self.day_text_view.set_size_request(1, -1)

        self.font = Pango.FontDescription(DEFAULT_FONT)
        self.default_size = self.font.get_size() / Pango.SCALE
        logging.debug("Default font: %s" % self.font.to_string())
        logging.debug("Default size: %s" % self.default_size) 
开发者ID:jendrikseipp,项目名称:rednotebook,代码行数:25,代码来源:editor.py

示例4: draw_text

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def draw_text(x, y, text, font, text_color, spacing, c):
    c.save()
    c.set_source_rgba(*rgb_to_cairo(text_color))
    font = cairo_font(font)

    c.translate(x, y)
    
    if use_pygobject:
      status, attrs, plain_text, _ = pango.parse_markup(text, len(text), '\0')
      
      layout = pangocairo.create_layout(c)
      pctx = layout.get_context()
      fo = cairo.FontOptions()
      fo.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
      pangocairo.context_set_font_options(pctx, fo)
      layout.set_font_description(font)
      layout.set_spacing(spacing * pango.SCALE)
      layout.set_text(plain_text, len(plain_text))
      layout.set_attributes(attrs)
      pangocairo.update_layout(c, layout)
      pangocairo.show_layout(c, layout)

    else: # pyGtk
      attrs, plain_text, _ = pango.parse_markup(text)
      
      pctx = pangocairo.CairoContext(c)
      pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
      layout = pctx.create_layout()
      layout.set_font_description(font)
      layout.set_spacing(spacing * pango.SCALE)
      layout.set_text(plain_text)
      layout.set_attributes(attrs)
      pctx.update_layout(layout)
      pctx.show_layout(layout)
      
    c.restore() 
开发者ID:kevinpt,项目名称:symbolator,代码行数:38,代码来源:cairo_backend.py

示例5: tabstops_to_tabarray

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def tabstops_to_tabarray(tab_stops, dpi):
    """Convert a list of tabs given in cm to a Pango.TabArray.
    """
    tab_array = Pango.TabArray.new(initial_size=len(tab_stops),
                                            positions_in_pixels=False)

    for index in range(len(tab_stops)):
        location = tab_stops[index] * dpi * Pango.SCALE / 2.54
        tab_array.set_tab(index, Pango.TabAlign.LEFT, int(location))

    return tab_array 
开发者ID:GenealogyCollective,项目名称:gprime,代码行数:13,代码来源:libcairodoc.py

示例6: config_change_font

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def config_change_font(self, font_button):
        """
        Called when font is change.
        """
        font_family = font_button.get_font_family()
        if font_family is not None:
            font_name = font_family.get_name()
        else:
            font_name = ''
        # apply Pango.SCALE=1024 to font size
        font_size = int(font_button.get_font_size() / 1024)
        self._config.set('interface.graphview-font', [font_name, font_size])
        self.graph_widget.retest_font = True
        self.graph_widget.populate(self.get_active()) 
开发者ID:gramps-project,项目名称:addons-source,代码行数:16,代码来源:graphview.py

示例7: _draw_symbol

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def _draw_symbol(self, context, symbol, color, transparency=0.):
        c = context.cairo
        cairo_context = c
        if isinstance(c, CairoBoundingBoxContext):
            cairo_context = c._cairo
        width = self.width
        height = self.height

        # c.set_antialias(Antialias.GOOD)

        layout = PangoCairo.create_layout(cairo_context)

        def set_font_description():
            set_label_markup(layout, symbol, is_icon=True, size=font_size)

        if symbol in self.__symbol_size_cache and \
                self.__symbol_size_cache[symbol]['width'] == width and \
                self.__symbol_size_cache[symbol]['height'] == height:
            font_size = self.__symbol_size_cache[symbol]['size']
            set_font_description()

        else:
            font_size = 30
            set_font_description()

            pango_size = (width * SCALE, height * SCALE)
            while layout.get_size()[0] > pango_size[0] * constants.ICON_STATE_FILL_FACTOR or \
                    layout.get_size()[1] > pango_size[1] * constants.ICON_STATE_FILL_FACTOR:
                font_size *= 0.9
                set_font_description()

            self.__symbol_size_cache[symbol] = {'width': width, 'height': height, 'size': font_size}

        c.move_to(width / 2. - layout.get_size()[0] / float(SCALE) / 2.,
                  height / 2. - layout.get_size()[1] / float(SCALE) / 2.)

        c.set_source_rgba(*gap_draw_helper.get_col_rgba(color, transparency))
        PangoCairo.update_layout(cairo_context, layout)
        PangoCairo.show_layout(cairo_context, layout) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:41,代码来源:state.py

示例8: set_font

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def set_font(self, font_name):
        self.day_text_field.set_font(font_name)
        self.html_editor.set_font_size(
            Pango.FontDescription(font_name).get_size() / Pango.SCALE
        ) 
开发者ID:jendrikseipp,项目名称:rednotebook,代码行数:7,代码来源:main_window.py

示例9: cairo_text_bbox

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def cairo_text_bbox(text, font_params, spacing=0, scale=1.0):
    surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 8, 8)
    ctx = cairo.Context(surf)

    # The scaling must match the final context.
    # If not there can be a mismatch between the computed extents here
    # and those generated for the final render.
    ctx.scale(scale, scale)
    
    font = cairo_font(font_params)


    if use_pygobject:
      status, attrs, plain_text, _ = pango.parse_markup(text, len(text), '\0')
      
      layout = pangocairo.create_layout(ctx)
      pctx = layout.get_context()
      fo = cairo.FontOptions()
      fo.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
      pangocairo.context_set_font_options(pctx, fo)
      layout.set_font_description(font)
      layout.set_spacing(spacing * pango.SCALE)
      layout.set_text(plain_text, len(plain_text))
      layout.set_attributes(attrs)

      li = layout.get_iter() # Get first line of text
      baseline = li.get_baseline() / pango.SCALE

      re = layout.get_pixel_extents()[1] # Get logical extents
      extents = (re.x, re.y, re.x + re.width, re.y + re.height)

    else: # pyGtk
      attrs, plain_text, _ = pango.parse_markup(text)

      pctx = pangocairo.CairoContext(ctx)
      pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
      layout = pctx.create_layout()
      layout.set_font_description(font)
      layout.set_spacing(spacing * pango.SCALE)
      layout.set_text(plain_text)
      layout.set_attributes(attrs)

      li = layout.get_iter() # Get first line of text
      baseline = li.get_baseline() / pango.SCALE

      #print('@@ EXTENTS:', layout.get_pixel_extents()[1], spacing)
      extents = layout.get_pixel_extents()[1] # Get logical extents

    return [extents[0], extents[1], extents[2], extents[3], baseline] 
开发者ID:kevinpt,项目名称:symbolator,代码行数:51,代码来源:cairo_backend.py

示例10: draw_name

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def draw_name(self, context, transparency, only_calculate_size=False):
        """Draws the name of the port

        Offers the option to only calculate the size of the name.

        :param context: The context to draw on
        :param transparency: The transparency of the text
        :param only_calculate_size: Whether to only calculate the size
        :return: Size of the name
        :rtype: float, float
        """
        c = context
        cairo_context = c
        if isinstance(c, CairoBoundingBoxContext):
            cairo_context = c._cairo
        # c.set_antialias(Antialias.GOOD)

        side_length = self.port_side_size

        layout = PangoCairo.create_layout(cairo_context)
        font_name = constants.INTERFACE_FONT
        font_size = gap_draw_helper.FONT_SIZE
        font = FontDescription(font_name + " " + str(font_size))
        layout.set_font_description(font)
        layout.set_text(self.name, -1)

        ink_extents, logical_extents = layout.get_extents()
        extents = [extent / float(SCALE) for extent in [logical_extents.x, logical_extents.y,
                                                        logical_extents.width, logical_extents.height]]
        real_name_size = extents[2], extents[3]
        desired_height = side_length * 0.75
        scale_factor = real_name_size[1] / desired_height

        # Determine the size of the text, increase the width to have more margin left and right of the text
        margin = side_length / 4.
        name_size = real_name_size[0] / scale_factor, desired_height
        name_size_with_margin = name_size[0] + margin * 2, name_size[1] + margin * 2

        # Only the size is required, stop here
        if only_calculate_size:
            return name_size_with_margin

        # Current position is the center of the port rectangle
        c.save()
        if self.side is SnappedSide.RIGHT or self.side is SnappedSide.LEFT:
            c.rotate(deg2rad(-90))
        c.rel_move_to(-name_size[0] / 2, -name_size[1] / 2)
        c.scale(1. / scale_factor, 1. / scale_factor)
        c.rel_move_to(-extents[0], -extents[1])

        c.set_source_rgba(*gap_draw_helper.get_col_rgba(self.text_color, transparency))
        PangoCairo.update_layout(cairo_context, layout)
        PangoCairo.show_layout(cairo_context, layout)
        c.restore()

        return name_size_with_margin 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:58,代码来源:ports.py

示例11: drawCords

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def drawCords(self, context, rectangle):
        thickness = 0.01
        signsize = 0.02

        if (not self.show_cords) and (not self.setup_position):
            return

        xc_loc, yc_loc, square, side = self.square

        if rectangle is not None and contains(rect((xc_loc, yc_loc, square)), rectangle):
            return

        thick = thickness * square
        sign_size = signsize * square

        pangoScale = float(Pango.SCALE)
        if self.no_frame:
            context.set_source_rgb(0.0, 0.0, 0.0)
        else:
            context.set_source_rgb(1.0, 1.0, 1.0)

        def paint(inv):
            for num in range(self.RANKS):
                rank = inv and num + 1 or self.RANKS - num
                layout = self.create_pango_layout("%d" % rank)
                layout.set_font_description(
                    Pango.FontDescription("bold %d" % sign_size))
                width = layout.get_extents()[1].width / pangoScale
                height = layout.get_extents()[0].height / pangoScale

                # Draw left side
                context.move_to(xc_loc - thick - width, side * num + yc_loc + height / 2 + thick * 3)
                PangoCairo.show_layout(context, layout)

                file = inv and self.FILES - num or num + 1
                layout = self.create_pango_layout(chr(file + ord("A") - 1))
                layout.set_font_description(
                    Pango.FontDescription("bold %d" % sign_size))

                # Draw bottom
                context.move_to(xc_loc + side * num + side / 2 - width / 2, yc_loc + square)
                PangoCairo.show_layout(context, layout)

        matrix, invmatrix = matrixAround(self.matrix_pi, xc_loc + square / 2, yc_loc + square / 2)
        if self.rotation == 0:
            paint(False)
        else:
            context.transform(matrix)
            paint(True)
            context.transform(invmatrix)

        if self.faceToFace:
            if self.rotation == 0:
                context.transform(matrix)
                paint(True)
                context.transform(invmatrix)
            else:
                paint(False) 
开发者ID:pychess,项目名称:pychess,代码行数:60,代码来源:BoardView.py

示例12: formatHeader

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def formatHeader(self):
        LINE_HEIGHT = 2 * (share.config.namefont)
        # MARGIN = self.page_margin
        # cwidth = context.get_width()
        cwidth = self.page_setup.get_page_width(Gtk.Unit.POINTS)
        logging.info("Paper width: " + str(cwidth))
        cr = self.cairo_context

        fontsize = share.config.namefont
        fdesc = Pango.FontDescription("Sans")
        fdesc.set_size(fontsize * Pango.SCALE)
        self.pangolayout.set_font_description(fdesc)

        if self.title != "":
            self.pangolayout.set_text(self.title, -1)
            (width, height) = self.pangolayout.get_size()
            self.pangolayout.set_alignment(Pango.Alignment.CENTER)
            cr.move_to((cwidth - width / Pango.SCALE) / 2,
                       (LINE_HEIGHT - (height / Pango.SCALE))/2)
            PangoCairo.show_layout(cr, self.pangolayout)

            # cr.move_to((cwidth + width / Pango.SCALE) / 2, LINE_HEIGHT + config.topmargin)
            # cr.line_to((cwidth - width / Pango.SCALE) / 2, LINE_HEIGHT + config.topmargin)
            cr.move_to((cwidth + width / Pango.SCALE) /
                       2, LINE_HEIGHT + self.cell_margin)
            cr.line_to((cwidth - width / Pango.SCALE) /
                       2, LINE_HEIGHT + self.cell_margin)

        addh = LINE_HEIGHT + self.cell_margin
        LINE_HEIGHT = 2 * share.config.headerfont
        fontsize = share.config.headerfont
        fdesc.set_size(fontsize * Pango.SCALE)
        self.pangolayout.set_font_description(fdesc)

        flag = 1
        for k, v in self.fields.items():
            self.pangolayout.set_text(k + ": " + v, -1)
            (width, height) = self.pangolayout.get_size()
            self.pangolayout.set_alignment(Pango.Alignment.CENTER)
            if flag == 1:
                addh += LINE_HEIGHT
                cr.move_to(cwidth - (width / Pango.SCALE) -
                           share.config.rightmargin, addh - (height / Pango.SCALE)/2)
                flag = 0
            else:
                cr.move_to((width / Pango.SCALE) + share.config.leftmargin,
                           addh - (height / Pango.SCALE)/2)
                flag = 1
            PangoCairo.show_layout(cr, self.pangolayout)

        cr.stroke()
        self.header_height = addh + 8 
开发者ID:Jooyeshgar,项目名称:amir,代码行数:54,代码来源:printreport.py

示例13: drawTrialReport

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def drawTrialReport(self, page_nr):
        self.formatHeader()
        RIGHT_EDGE = self.page_setup.get_page_width(
            Gtk.Unit.POINTS) - share.config.rightmargin
        HEADER_HEIGHT = self.header_height
        HEADING_HEIGHT = self.heading_height
        MARGIN = self.cell_margin
        TABLE_TOP = HEADER_HEIGHT + HEADING_HEIGHT + self.cell_margin
        ROW_HEIGHT = self.row_height
        LINE = self.line

        cr = self.cairo_context
        fontsize = share.config.contentfont
        fdesc = Pango.FontDescription("Sans")
        fdesc.set_size(fontsize * Pango.SCALE)
        self.pangolayout.set_font_description(fdesc)

        self.drawTableHeading()

        # Draw table data
        rindex = page_nr * self.lines_per_page
        offset = 0
        addh = TABLE_TOP

        try:
            while offset < self.lines_per_page:
                row = self.content[rindex + offset]

                cr.move_to(RIGHT_EDGE, addh)
                cr.line_to(RIGHT_EDGE, addh+ROW_HEIGHT)

                right_txt = RIGHT_EDGE
                dindex = 0
                for data in row:
                    right_txt -= MARGIN+LINE
                    self.pangolayout.set_text(data, -1)
                    (width, height) = self.pangolayout.get_size()
                    self.pangolayout.set_alignment(Pango.Alignment.RIGHT)
                    cr.move_to(right_txt - (width / Pango.SCALE),
                               addh + (ROW_HEIGHT-(height / Pango.SCALE))/2)
                    PangoCairo.show_layout(cr, self.pangolayout)

                    right_txt -= self.cols_width[dindex]
                    cr.move_to(right_txt, addh)
                    cr.line_to(right_txt, addh + ROW_HEIGHT)
                    dindex += 1

                addh += ROW_HEIGHT
                offset += 1
        except IndexError:
            pass

        # Table top line
        cr.move_to(right_txt, TABLE_TOP)
        cr.line_to(RIGHT_EDGE, TABLE_TOP)

        # Table bottom line
        cr.move_to(right_txt, addh)
        cr.line_to(RIGHT_EDGE, addh)

        cr.stroke() 
开发者ID:Jooyeshgar,项目名称:amir,代码行数:63,代码来源:printreport.py

示例14: __paint_txt

# 需要导入模块: from gi.repository import Pango [as 别名]
# 或者: from gi.repository.Pango import SCALE [as 别名]
def __paint_txt(self, pdf_surface, pdf_size, pdf_context, page):
        if not PANGO_AVAILABLE:
            return

        img = page.img

        scale_factor_x = pdf_size[0] / img.size[0]
        scale_factor_y = pdf_size[1] / img.size[1]
        scale_factor = min(scale_factor_x, scale_factor_y)

        for line in page.boxes:
            for word in line.word_boxes:
                box_size = (
                    (word.position[1][0] - word.position[0][0]) * scale_factor,
                    (word.position[1][1] - word.position[0][1]) * scale_factor
                )

                layout = PangoCairo.create_layout(pdf_context)
                layout.set_text(word.content, -1)

                txt_size = layout.get_size()
                if 0 in txt_size or 0 in box_size:
                    continue

                txt_factors = (
                    float(box_size[0]) * Pango.SCALE / txt_size[0],
                    float(box_size[1]) * Pango.SCALE / txt_size[1],
                )

                pdf_context.save()
                try:
                    pdf_context.set_source_rgb(0, 0, 0)
                    pdf_context.translate(
                        word.position[0][0] * scale_factor,
                        word.position[0][1] * scale_factor
                    )

                    # make the text use the whole box space
                    pdf_context.scale(txt_factors[0], txt_factors[1])

                    PangoCairo.update_layout(pdf_context, layout)
                    PangoCairo.show_layout(pdf_context, layout)
                finally:
                    pdf_context.restore() 
开发者ID:openpaperwork,项目名称:paperwork-backend,代码行数:46,代码来源:doc.py


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