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


Python PangoCairo.create_layout方法代码示例

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


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

示例1: do_render

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [as 别名]
def do_render(self, context, widget, background_area, cell_area, flags):
        if not self.data:
            return
        text, widthfrac, goodness = self.data
        if widthfrac:
            paintGraph(context, widthfrac, stoplightColor(goodness), cell_area)
        if text:
            layout = PangoCairo.create_layout(context)
            layout.set_text(text, -1)

            fd = Pango.font_description_from_string("Sans 10")
            layout.set_font_description(fd)

            w, h = layout.get_pixel_size()
            context.move_to(cell_area.x, cell_area.y)
            context.rel_move_to(70 - w, (height - h) / 2)

            PangoCairo.show_layout(context, layout) 
开发者ID:pychess,项目名称:pychess,代码行数:20,代码来源:bookPanel.py

示例2: draw_text

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [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

示例3: cairo_text_bbox

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [as 别名]
def cairo_text_bbox(text, font_params, 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:
    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_text(text, len(text))
    re = layout.get_pixel_extents()[1]
    extents = (re.x, re.y, re.x + re.width, re.y + re.height)

  else: # pyGtk
    pctx = pangocairo.CairoContext(ctx)
    pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
    layout = pctx.create_layout()
    layout.set_font_description(font)
    layout.set_text(text)

    #print('@@ EXTENTS:', layout.get_pixel_extents()[1])
    extents = layout.get_pixel_extents()[1]
  w = extents[2] - extents[0]
  h = extents[3] - extents[1]
  x0 = - w // 2.0
  y0 = - h // 2.0
  return [x0,y0, x0+w,y0+h] 
开发者ID:kevinpt,项目名称:syntrax,代码行数:38,代码来源:syntrax.py

示例4: cairo_draw_text

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [as 别名]
def cairo_draw_text(x, y, text, font, text_color, c):
  c.save()
  #print('## TEXT COLOR:', text_color)
  c.set_source_rgba(*rgb_to_cairo(text_color))
  font = cairo_font(font)

  c.translate(x, y)

  if use_pygobject:
    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_text(text, len(text))
    pangocairo.update_layout(c, layout)
    pangocairo.show_layout(c, layout)

  else: # pyGtk
    pctx = pangocairo.CairoContext(c)
    pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
    layout = pctx.create_layout()
    layout.set_font_description(font)
    layout.set_text(text)
    pctx.update_layout(layout)
    pctx.show_layout(layout)

  c.restore() 
开发者ID:kevinpt,项目名称:syntrax,代码行数:31,代码来源:syntrax.py

示例5: _nvim_resize

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [as 别名]
def _nvim_resize(self, columns, rows):
        da = self._drawing_area
        # create FontDescription object for the selected font/size
        font_str = '{0} {1}'.format(self._font_name, self._font_size)
        self._font, pixels, normal_width, bold_width = _parse_font(font_str)
        # calculate the letter_spacing required to make bold have the same
        # width as normal
        self._bold_spacing = normal_width - bold_width
        cell_pixel_width, cell_pixel_height = pixels
        # calculate the total pixel width/height of the drawing area
        pixel_width = cell_pixel_width * columns
        pixel_height = cell_pixel_height * rows
        gdkwin = da.get_window()
        content = cairo.CONTENT_COLOR
        self._cairo_surface = gdkwin.create_similar_surface(content,
                                                            pixel_width,
                                                            pixel_height)
        self._cairo_context = cairo.Context(self._cairo_surface)
        self._pango_layout = PangoCairo.create_layout(self._cairo_context)
        self._pango_layout.set_alignment(Pango.Alignment.LEFT)
        self._pango_layout.set_font_description(self._font)
        self._pixel_width, self._pixel_height = pixel_width, pixel_height
        self._cell_pixel_width = cell_pixel_width
        self._cell_pixel_height = cell_pixel_height
        self._screen = Screen(columns, rows)
        self._window.resize(pixel_width, pixel_height) 
开发者ID:neovim,项目名称:python-gui,代码行数:28,代码来源:gtk_ui.py

示例6: _parse_font

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [as 别名]
def _parse_font(font, cr=None):
    if not cr:
        ims = cairo.ImageSurface(cairo.FORMAT_RGB24, 300, 300)
        cr = cairo.Context(ims)
    fd = Pango.font_description_from_string(font)
    layout = PangoCairo.create_layout(cr)
    layout.set_font_description(fd)
    layout.set_alignment(Pango.Alignment.LEFT)
    layout.set_markup('<span font_weight="bold">A</span>')
    bold_width, _ = layout.get_size()
    layout.set_markup('<span>A</span>')
    pixels = layout.get_pixel_size()
    normal_width, _ = layout.get_size()
    return fd, pixels, normal_width, bold_width 
开发者ID:neovim,项目名称:python-gui,代码行数:16,代码来源:gtk_ui.py

示例7: get_text_layout

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [as 别名]
def get_text_layout(cairo_context, text, size):
    c = cairo_context
    layout = PangoCairo.create_layout(c)
    layout.set_text(text, -1)

    font_name = constants.INTERFACE_FONT

    font = FontDescription(font_name + " " + str(size))
    layout.set_font_description(font)

    return layout 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:13,代码来源:gap_draw_helper.py

示例8: _draw_symbol

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [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

示例9: do_draw_cb

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [as 别名]
def do_draw_cb(self, widget, cr):
        # The do_draw_cb is called when the widget is asked to draw itself
        # with the 'draw' as opposed to old function 'expose event'
        # Remember that this will be called a lot of times, so it's usually
        # a good idea to write this code as optimized as it can be, don't
        # Create any resources in here.

        cr.translate ( RADIUS, RADIUS)

        layout = PangoCairo.create_layout (cr)
        layout.set_text("శ్రీమదాంధ్రమహాభారతము", -1)
        desc = Pango.font_description_from_string (FONT)
        layout.set_font_description( desc)

        rangec = range(0, N_WORDS)
        for i in rangec:
            width, height = 0,0
            angle = (360. * i) / N_WORDS;

            cr.save ()

            red   = (1 + math.cos ((angle - 60) * math.pi / 180.)) / 2
            cr.set_source_rgb ( red, 0, 1.0 - red)
            cr.rotate ( angle * math.pi / 180.)
            #/* Inform Pango to re-layout the text with the new transformation */
            PangoCairo.update_layout (cr, layout)
            width, height = layout.get_size()
            cr.move_to ( - (float(width) / 1024.) / 2, - RADIUS)
            PangoCairo.show_layout (cr, layout)
            cr.restore() 
开发者ID:rakeshvar,项目名称:chamanti_ocr,代码行数:32,代码来源:draw_text.py

示例10: cairo_text_bbox

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [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

示例11: draw_name

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [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

示例12: __paint_txt

# 需要导入模块: from gi.repository import PangoCairo [as 别名]
# 或者: from gi.repository.PangoCairo import create_layout [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.PangoCairo.create_layout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。