Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit f208e9eeed817f5e1a648a53337a662941453bc1

finished gtk3 conversion
exportpdf.py
(24 / 22)
  
2020import time
2121import cairo
2222from gi.repository import Pango
23import pangocairo
23from gi.repository import PangoCairo
2424from gettext import gettext as _
2525
2626from utils import get_pixbuf_from_journal
6565 show_text(cr, fd, _('untitled'), HEAD, LEFT_MARGIN,
6666 TOP_MARGIN)
6767
68 try:
69 w = int(PAGE_WIDTH - LEFT_MARGIN * 2)
70 h = int(w * 3 / 4)
71 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(dsobj.file_path,
72 w, h)
73 except(GError, IOError):
68 w = 0
69 h = 0
70 pixbuf = None
71 if os.path.exists(dsobj.file_path):
72 print dsobj.file_path
7473 try:
75 w = 300
76 h = 225
77 pixbuf = get_pixbuf_from_journal(dsobj, w, h)
78 except(GError, IOError):
79 w = 0
80 h = 0
81 pixbuf = None
74 w = int(PAGE_WIDTH - LEFT_MARGIN * 2)
75 h = int(w * 3 / 4)
76 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
77 dsobj.file_path, w, h)
78 except: # (GError, IOError):
79 try:
80 w = 300
81 h = 225
82 pixbuf = get_pixbuf_from_journal(dsobj, w, h)
83 except: # (GError, IOError):
84 pass
8285
8386 if pixbuf is not None:
8487 cr.save()
85 cr = Gdk.CairoContext(cr)
86 cr.set_source_pixbuf(pixbuf, LEFT_MARGIN, TOP_MARGIN + 150)
88 Gdk.cairo_set_source_pixbuf(
89 cr, pixbuf, LEFT_MARGIN, TOP_MARGIN + 150)
8790 cr.rectangle(LEFT_MARGIN, TOP_MARGIN + 150, w, h)
8891 cr.fill()
8992 cr.restore()
100100
101101
102102def show_text(cr, fd, label, size, x, y):
103 cr = pangocairo.CairoContext(cr)
104 pl = cr.create_layout()
103 pl = PangoCairo.create_layout(cr)
105104 fd.set_size(int(size * Pango.SCALE))
106105 pl.set_font_description(fd)
107106 if type(label) == str or type(label) == unicode:
108 pl.set_text(label.replace('', ' ')
107 pl.set_text(label.replace('', ' ')
109108 else:
110 pl.set_text(str(label))
109 pl.set_text(str(label), -1)
111110 pl.set_width((PAGE_WIDTH - LEFT_MARGIN * 2) * Pango.SCALE)
112111 cr.save()
113112 cr.translate(x, y)
114 cr.update_layout(pl)
115 cr.show_layout(pl)
113 PangoCairo.update_layout(cr, pl)
114 PangoCairo.show_layout(cr, pl)
116115 cr.restore()