71abad6b6a
Merge my work on trunk to gramps40 now that 4.0.1 is out, as this fix is targeted for 4.0.2. svn: r22588
88 lines
2.7 KiB
Python
88 lines
2.7 KiB
Python
#
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
#
|
|
# Copyright (C) 2001-2007 Donald N. Allingham, Martin Hawlisch
|
|
# Copyright (C) 2009 Douglas S. Blank
|
|
# Copyright (C) 2012 Benny Malengier
|
|
# Copyright (C) 2013 Vassilii Khachaturov
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
|
|
# $Id$
|
|
|
|
from __future__ import division
|
|
|
|
#-------------------------------------------------------------------------
|
|
#
|
|
# Python modules
|
|
#
|
|
#-------------------------------------------------------------------------
|
|
#from gi.repository import Pango
|
|
#from gi.repository import GObject
|
|
#from gi.repository import Gdk
|
|
#from gi.repository import Gtk
|
|
#from gi.repository import PangoCairo
|
|
import cairo
|
|
#import math
|
|
#import colorsys
|
|
#import sys
|
|
#if sys.version_info[0] < 3:
|
|
# import cPickle as pickle
|
|
#else:
|
|
# import pickle
|
|
|
|
#-------------------------------------------------------------------------
|
|
#
|
|
# Functions
|
|
#
|
|
#-------------------------------------------------------------------------
|
|
def warpPath(ctx, function):
|
|
"""Transform a path given a 2D transformation function.
|
|
|
|
ctx -- a cairo.Context, on which the path is set
|
|
function -- a 2D transform (x,y) |-> (x_new,y_new)
|
|
|
|
The transformed path replaces the original one on the context.
|
|
|
|
Taken from /usr/share/doc/python-cairo/examples/warpedtext.py
|
|
According to /usr/share/doc/python-cairo/copyright, licensed
|
|
under MOZILLA PUBLIC LICENSE 1.1, see that file for more detail.
|
|
"""
|
|
|
|
first = True
|
|
|
|
for type, points in ctx.copy_path():
|
|
if type == cairo.PATH_MOVE_TO:
|
|
if first:
|
|
ctx.new_path()
|
|
first = False
|
|
x, y = function(*points)
|
|
ctx.move_to(x, y)
|
|
|
|
elif type == cairo.PATH_LINE_TO:
|
|
x, y = function(*points)
|
|
ctx.line_to(x, y)
|
|
|
|
elif type == cairo.PATH_CURVE_TO:
|
|
x1, y1, x2, y2, x3, y3 = points
|
|
x1, y1 = function(x1, y1)
|
|
x2, y2 = function(x2, y2)
|
|
x3, y3 = function(x3, y3)
|
|
ctx.curve_to(x1, y1, x2, y2, x3, y3)
|
|
|
|
elif type == cairo.PATH_CLOSE_PATH:
|
|
ctx.close_path()
|