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
方法修饰词 | 方法名及参数 |
---|---|
static | from_string (str) |
static | new () |
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()