PyGobject(八十八)Pango系列——简介&简单示例

Pango

Pango是一个开放源代码的自由函数库,用于高质量地渲染国际化的文字。Pango可以使用不同的后端字体,并提供了跨平台支持。

Pango已经被整合到多数Linux发行版中,并在Fedora Core 6被用于Firefox网页浏览器和Thunderbird邮件客户端的文字渲染。虽然在Mozilla的源代码里并没有包含Pango,但Fedora Core得到了Mozilla基金会的特别许可。同样,Debian的Iceweasel、IceDove和IceApe也使用了Pango。

在与Cairo融合后,Pango可以完全进行文字处理和图形渲染。(来自百度百科)

在开始我们的第一个例子之前,我们先来了解一下Pango.FontDescription这个结构体

Pango.FontDescription

Methods

方法修饰词方法名及参数
staticfrom_string (str)
staticnew ()
better_match (old_match, new_match)
copy ()
copy_static ()
equal (desc2)
free ()
get_family ()
get_gravity ()
get_set_fields ()
get_size ()
get_size_is_absolute ()
get_stretch ()
get_style ()
get_variant ()
get_weight ()
hash ()
merge (desc_to_merge, replace_existing)
merge_static (desc_to_merge, replace_existing)
set_absolute_size (size)
set_family (family)
set_family_static (family)
set_gravity (gravity)
set_size (size)
set_stretch (stretch)
set_style (style)
set_variant (variant)
set_weight (weight)
to_filename ()
to_string ()
unset_fields (to_unset)

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/6
# section 138
TITLE = "Set Font"
DESCRIPTION = """
This example shows how to modify the font of a label
"""

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, Pango

quotes = """Excess of joy is harder to bear than any amount of sorrow.
The more one judges, the less one loves.
There is no such thing as a great talent without great will power.
"""


class PyApp(Gtk.Window):
    def __init__(self):
        super(PyApp, self).__init__()
        self.connect("destroy", Gtk.main_quit)
        self.set_title("Quotes")
        label = Gtk.Label(quotes)
        # Gdk.beep()
        fontdesc = Pango.FontDescription("Papyrus Oblique 12")
        label.modify_font(fontdesc)
        fix = Gtk.Fixed()
        fix.put(label, 5, 5)
        self.add(fix)
        self.show_all()


def main():
    PyApp()
    Gtk.main()


if __name__ == "__main__":
    main()





代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值